blob: 1d93cc17648202a5425f19df939707e8bbdc2ee7 [file] [log] [blame]
Damjan Marion7cd468a2016-12-19 23:05:39 +01001/*
2 *------------------------------------------------------------------
3 * api_format.c
4 *
5 * Copyright (c) 2014-2016 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
18 */
19
20#include <vat/vat.h>
Neale Ranns86327be2018-11-02 09:14:01 -070021#include <vpp/api/types.h>
Dave Barach59b25652017-09-10 15:04:27 -040022#include <vppinfra/socket.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010023#include <vlibapi/api.h>
24#include <vlibmemory/api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010025#include <vnet/ip/ip.h>
John Lo7f358b32018-04-28 01:19:24 -040026#include <vnet/ip/ip_neighbor.h>
Neale Ranns37029302018-08-10 05:30:06 -070027#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010028#include <vnet/l2/l2_input.h>
29#include <vnet/l2tp/l2tp.h>
30#include <vnet/vxlan/vxlan.h>
Marco Varleseb598f1d2017-09-19 14:25:28 +020031#include <vnet/geneve/geneve.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010032#include <vnet/gre/gre.h>
33#include <vnet/vxlan-gpe/vxlan_gpe.h>
34#include <vnet/lisp-gpe/lisp_gpe.h>
35
36#include <vpp/api/vpe_msg_enum.h>
37#include <vnet/l2/l2_classify.h>
38#include <vnet/l2/l2_vtr.h>
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010039#include <vnet/classify/in_out_acl.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010040#include <vnet/classify/policer_classify.h>
41#include <vnet/classify/flow_classify.h>
42#include <vnet/mpls/mpls.h>
43#include <vnet/ipsec/ipsec.h>
44#include <vnet/ipsec/ikev2.h>
45#include <inttypes.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010046#include <vnet/cop/cop.h>
47#include <vnet/ip/ip6_hop_by_hop.h>
48#include <vnet/ip/ip_source_and_port_range_check.h>
49#include <vnet/policer/xlate.h>
50#include <vnet/span/span.h>
51#include <vnet/policer/policer.h>
52#include <vnet/policer/police.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000053#include <vnet/mfib/mfib_types.h>
John Lo70bfcaf2017-11-14 13:19:26 -050054#include <vnet/dhcp/dhcp_proxy.h>
Steven9cd2d7a2017-12-20 12:43:01 -080055#include <vnet/bonding/node.h>
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070056#include <vnet/qos/qos_types.h>
Neale Ranns37029302018-08-10 05:30:06 -070057#include <vnet/ethernet/ethernet_types_api.h>
58#include <vnet/ip/ip_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010059#include "vat/json_format.h"
Neale Ranns86327be2018-11-02 09:14:01 -070060#include <vnet/ip/ip_types_api.h>
61#include <vnet/ethernet/ethernet_types_api.h>
Damjan Marion7cd468a2016-12-19 23:05:39 +010062
63#include <inttypes.h>
64#include <sys/stat.h>
65
66#define vl_typedefs /* define message structures */
67#include <vpp/api/vpe_all_api_h.h>
68#undef vl_typedefs
69
70/* declare message handlers for each api */
71
72#define vl_endianfun /* define message structures */
73#include <vpp/api/vpe_all_api_h.h>
74#undef vl_endianfun
75
76/* instantiate all the print functions we know about */
77#define vl_print(handle, ...)
78#define vl_printfun
79#include <vpp/api/vpe_all_api_h.h>
80#undef vl_printfun
81
Dave Barach2d6b2d62017-01-25 16:32:08 -050082#define __plugin_msg_base 0
Dave Barachfe6bdfd2017-01-20 19:50:09 -050083#include <vlibapi/vat_helper_macros.h>
84
Dave Barach59b25652017-09-10 15:04:27 -040085#if VPP_API_TEST_BUILTIN == 0
86#include <netdb.h>
87
88u32
89vl (void *p)
90{
91 return vec_len (p);
92}
93
94int
95vat_socket_connect (vat_main_t * vam)
96{
Florin Coras66a10032018-12-21 16:23:09 -080097 int rv;
Florin Coras90a63982017-12-19 04:50:01 -080098 vam->socket_client_main = &socket_client_main;
Florin Coras66a10032018-12-21 16:23:09 -080099 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
100 "vpp_api_test",
101 0 /* default socket rx, tx buffer */ )))
102 return rv;
103 /* vpp expects the client index in network order */
104 vam->my_client_index = htonl (socket_client_main.client_index);
105 return 0;
Dave Barach59b25652017-09-10 15:04:27 -0400106}
107#else /* vpp built-in case, we don't do sockets... */
108int
109vat_socket_connect (vat_main_t * vam)
110{
111 return 0;
112}
113
Florin Coras90a63982017-12-19 04:50:01 -0800114int
115vl_socket_client_read (int wait)
Dave Barach59b25652017-09-10 15:04:27 -0400116{
Florin Coras90a63982017-12-19 04:50:01 -0800117 return -1;
Dave Barach59b25652017-09-10 15:04:27 -0400118};
Florin Coras90a63982017-12-19 04:50:01 -0800119
120int
121vl_socket_client_write ()
122{
123 return -1;
124};
125
126void *
127vl_socket_client_msg_alloc (int nbytes)
128{
129 return 0;
130}
Dave Barach59b25652017-09-10 15:04:27 -0400131#endif
132
133
Dave Barachfe6bdfd2017-01-20 19:50:09 -0500134f64
135vat_time_now (vat_main_t * vam)
136{
137#if VPP_API_TEST_BUILTIN
138 return vlib_time_now (vam->vlib_main);
139#else
140 return clib_time_now (&vam->clib_time);
141#endif
142}
143
144void
145errmsg (char *fmt, ...)
146{
147 vat_main_t *vam = &vat_main;
148 va_list va;
149 u8 *s;
150
151 va_start (va, fmt);
152 s = va_format (0, fmt, &va);
153 va_end (va);
154
155 vec_add1 (s, 0);
156
157#if VPP_API_TEST_BUILTIN
158 vlib_cli_output (vam->vlib_main, (char *) s);
159#else
160 {
161 if (vam->ifp != stdin)
162 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
163 vam->input_line_number);
164 fformat (vam->ofp, (char *) s);
165 fflush (vam->ofp);
166 }
167#endif
168
169 vec_free (s);
170}
171
Dave Barach4a3f69c2017-02-22 12:44:56 -0500172#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +0100173static uword
174api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
175{
176 vat_main_t *vam = va_arg (*args, vat_main_t *);
177 u32 *result = va_arg (*args, u32 *);
178 u8 *if_name;
179 uword *p;
180
181 if (!unformat (input, "%s", &if_name))
182 return 0;
183
184 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
185 if (p == 0)
186 return 0;
187 *result = p[0];
188 return 1;
189}
190
eyal bariaf86a482018-04-17 11:20:27 +0300191static uword
192api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
193{
194 return 0;
195}
196
Damjan Marion7cd468a2016-12-19 23:05:39 +0100197/* Parse an IP4 address %d.%d.%d.%d. */
198uword
199unformat_ip4_address (unformat_input_t * input, va_list * args)
200{
201 u8 *result = va_arg (*args, u8 *);
202 unsigned a[4];
203
204 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
205 return 0;
206
207 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
208 return 0;
209
210 result[0] = a[0];
211 result[1] = a[1];
212 result[2] = a[2];
213 result[3] = a[3];
214
215 return 1;
216}
217
218uword
219unformat_ethernet_address (unformat_input_t * input, va_list * args)
220{
221 u8 *result = va_arg (*args, u8 *);
222 u32 i, a[6];
223
224 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
225 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
226 return 0;
227
228 /* Check range. */
229 for (i = 0; i < 6; i++)
230 if (a[i] >= (1 << 8))
231 return 0;
232
233 for (i = 0; i < 6; i++)
234 result[i] = a[i];
235
236 return 1;
237}
238
239/* Returns ethernet type as an int in host byte order. */
240uword
241unformat_ethernet_type_host_byte_order (unformat_input_t * input,
242 va_list * args)
243{
244 u16 *result = va_arg (*args, u16 *);
245 int type;
246
247 /* Numeric type. */
248 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
249 {
250 if (type >= (1 << 16))
251 return 0;
252 *result = type;
253 return 1;
254 }
255 return 0;
256}
257
258/* Parse an IP6 address. */
259uword
260unformat_ip6_address (unformat_input_t * input, va_list * args)
261{
262 ip6_address_t *result = va_arg (*args, ip6_address_t *);
263 u16 hex_quads[8];
264 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
265 uword c, n_colon, double_colon_index;
266
267 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
268 double_colon_index = ARRAY_LEN (hex_quads);
269 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
270 {
271 hex_digit = 16;
272 if (c >= '0' && c <= '9')
273 hex_digit = c - '0';
274 else if (c >= 'a' && c <= 'f')
275 hex_digit = c + 10 - 'a';
276 else if (c >= 'A' && c <= 'F')
277 hex_digit = c + 10 - 'A';
278 else if (c == ':' && n_colon < 2)
279 n_colon++;
280 else
281 {
282 unformat_put_input (input);
283 break;
284 }
285
286 /* Too many hex quads. */
287 if (n_hex_quads >= ARRAY_LEN (hex_quads))
288 return 0;
289
290 if (hex_digit < 16)
291 {
292 hex_quad = (hex_quad << 4) | hex_digit;
293
294 /* Hex quad must fit in 16 bits. */
295 if (n_hex_digits >= 4)
296 return 0;
297
298 n_colon = 0;
299 n_hex_digits++;
300 }
301
302 /* Save position of :: */
303 if (n_colon == 2)
304 {
305 /* More than one :: ? */
306 if (double_colon_index < ARRAY_LEN (hex_quads))
307 return 0;
308 double_colon_index = n_hex_quads;
309 }
310
311 if (n_colon > 0 && n_hex_digits > 0)
312 {
313 hex_quads[n_hex_quads++] = hex_quad;
314 hex_quad = 0;
315 n_hex_digits = 0;
316 }
317 }
318
319 if (n_hex_digits > 0)
320 hex_quads[n_hex_quads++] = hex_quad;
321
322 {
323 word i;
324
325 /* Expand :: to appropriate number of zero hex quads. */
326 if (double_colon_index < ARRAY_LEN (hex_quads))
327 {
328 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
329
330 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
331 hex_quads[n_zero + i] = hex_quads[i];
332
333 for (i = 0; i < n_zero; i++)
334 hex_quads[double_colon_index + i] = 0;
335
336 n_hex_quads = ARRAY_LEN (hex_quads);
337 }
338
339 /* Too few hex quads given. */
340 if (n_hex_quads < ARRAY_LEN (hex_quads))
341 return 0;
342
343 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
344 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
345
346 return 1;
347 }
348}
349
350uword
351unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
352{
353 u32 *r = va_arg (*args, u32 *);
354
355 if (0);
356#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
357 foreach_ipsec_policy_action
358#undef _
359 else
360 return 0;
361 return 1;
362}
363
Damjan Marion7cd468a2016-12-19 23:05:39 +0100364u8 *
365format_ipsec_crypto_alg (u8 * s, va_list * args)
366{
367 u32 i = va_arg (*args, u32);
368 u8 *t = 0;
369
370 switch (i)
371 {
372#define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
373 foreach_ipsec_crypto_alg
374#undef _
375 default:
376 return format (s, "unknown");
377 }
378 return format (s, "%s", t);
379}
380
Damjan Marion7cd468a2016-12-19 23:05:39 +0100381u8 *
382format_ipsec_integ_alg (u8 * s, va_list * args)
383{
384 u32 i = va_arg (*args, u32);
385 u8 *t = 0;
386
387 switch (i)
388 {
389#define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
390 foreach_ipsec_integ_alg
391#undef _
392 default:
393 return format (s, "unknown");
394 }
395 return format (s, "%s", t);
396}
397
398uword
399unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
400{
401 u32 *r = va_arg (*args, u32 *);
402
403 if (0);
404#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
405 foreach_ikev2_auth_method
406#undef _
407 else
408 return 0;
409 return 1;
410}
411
412uword
413unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
414{
415 u32 *r = va_arg (*args, u32 *);
416
417 if (0);
418#define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
419 foreach_ikev2_id_type
420#undef _
421 else
422 return 0;
423 return 1;
424}
Dave Barach4a3f69c2017-02-22 12:44:56 -0500425#else /* VPP_API_TEST_BUILTIN == 1 */
426static uword
427api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
428{
429 vat_main_t *vam __attribute__ ((unused)) = va_arg (*args, vat_main_t *);
430 vnet_main_t *vnm = vnet_get_main ();
431 u32 *result = va_arg (*args, u32 *);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500432
eyal bariaf86a482018-04-17 11:20:27 +0300433 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
Dave Barach4a3f69c2017-02-22 12:44:56 -0500434}
eyal bariaf86a482018-04-17 11:20:27 +0300435
436static uword
437api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
438{
439 vat_main_t *vam __attribute__ ((unused)) = va_arg (*args, vat_main_t *);
440 vnet_main_t *vnm = vnet_get_main ();
441 u32 *result = va_arg (*args, u32 *);
442
443 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
444}
445
Damjan Marion7cd468a2016-12-19 23:05:39 +0100446#endif /* VPP_API_TEST_BUILTIN */
447
Neale Ranns17dcec02019-01-09 21:22:20 -0800448uword
449unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
450{
451 u32 *r = va_arg (*args, u32 *);
452
453 if (0);
454#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
455 foreach_ipsec_crypto_alg
456#undef _
457 else
458 return 0;
459 return 1;
460}
461
462uword
463unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
464{
465 u32 *r = va_arg (*args, u32 *);
466
467 if (0);
468#define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
469 foreach_ipsec_integ_alg
470#undef _
471 else
472 return 0;
473 return 1;
474}
475
Damjan Marion7cd468a2016-12-19 23:05:39 +0100476static uword
477unformat_policer_rate_type (unformat_input_t * input, va_list * args)
478{
479 u8 *r = va_arg (*args, u8 *);
480
481 if (unformat (input, "kbps"))
482 *r = SSE2_QOS_RATE_KBPS;
483 else if (unformat (input, "pps"))
484 *r = SSE2_QOS_RATE_PPS;
485 else
486 return 0;
487 return 1;
488}
489
490static uword
491unformat_policer_round_type (unformat_input_t * input, va_list * args)
492{
493 u8 *r = va_arg (*args, u8 *);
494
495 if (unformat (input, "closest"))
496 *r = SSE2_QOS_ROUND_TO_CLOSEST;
497 else if (unformat (input, "up"))
498 *r = SSE2_QOS_ROUND_TO_UP;
499 else if (unformat (input, "down"))
500 *r = SSE2_QOS_ROUND_TO_DOWN;
501 else
502 return 0;
503 return 1;
504}
505
506static uword
507unformat_policer_type (unformat_input_t * input, va_list * args)
508{
509 u8 *r = va_arg (*args, u8 *);
510
511 if (unformat (input, "1r2c"))
512 *r = SSE2_QOS_POLICER_TYPE_1R2C;
513 else if (unformat (input, "1r3c"))
514 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
515 else if (unformat (input, "2r3c-2698"))
516 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
517 else if (unformat (input, "2r3c-4115"))
518 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
519 else if (unformat (input, "2r3c-mef5cf1"))
520 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
521 else
522 return 0;
523 return 1;
524}
525
526static uword
527unformat_dscp (unformat_input_t * input, va_list * va)
528{
529 u8 *r = va_arg (*va, u8 *);
530
531 if (0);
532#define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
533 foreach_vnet_dscp
534#undef _
535 else
536 return 0;
537 return 1;
538}
539
540static uword
541unformat_policer_action_type (unformat_input_t * input, va_list * va)
542{
543 sse2_qos_pol_action_params_st *a
544 = va_arg (*va, sse2_qos_pol_action_params_st *);
545
546 if (unformat (input, "drop"))
547 a->action_type = SSE2_QOS_ACTION_DROP;
548 else if (unformat (input, "transmit"))
549 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
550 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
551 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
552 else
553 return 0;
554 return 1;
555}
556
557static uword
558unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
559{
560 u32 *r = va_arg (*va, u32 *);
561 u32 tid;
562
563 if (unformat (input, "ip4"))
564 tid = POLICER_CLASSIFY_TABLE_IP4;
565 else if (unformat (input, "ip6"))
566 tid = POLICER_CLASSIFY_TABLE_IP6;
567 else if (unformat (input, "l2"))
568 tid = POLICER_CLASSIFY_TABLE_L2;
569 else
570 return 0;
571
572 *r = tid;
573 return 1;
574}
575
576static uword
577unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
578{
579 u32 *r = va_arg (*va, u32 *);
580 u32 tid;
581
582 if (unformat (input, "ip4"))
583 tid = FLOW_CLASSIFY_TABLE_IP4;
584 else if (unformat (input, "ip6"))
585 tid = FLOW_CLASSIFY_TABLE_IP6;
586 else
587 return 0;
588
589 *r = tid;
590 return 1;
591}
592
Neale Ranns32e1c012016-11-22 17:07:28 +0000593static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
594static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
595static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
596static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
597
Dave Barach4a3f69c2017-02-22 12:44:56 -0500598#if (VPP_API_TEST_BUILTIN==0)
Neale Ranns32e1c012016-11-22 17:07:28 +0000599uword
600unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
601{
602 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
603 mfib_itf_attribute_t attr;
604
605 old = *iflags;
606 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
607 {
608 if (unformat (input, mfib_itf_flag_long_names[attr]))
609 *iflags |= (1 << attr);
610 }
611 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
612 {
613 if (unformat (input, mfib_itf_flag_names[attr]))
614 *iflags |= (1 << attr);
615 }
616
617 return (old == *iflags ? 0 : 1);
618}
619
620uword
621unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
622{
623 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
624 mfib_entry_attribute_t attr;
625
626 old = *eflags;
627 FOR_EACH_MFIB_ATTRIBUTE (attr)
628 {
629 if (unformat (input, mfib_flag_long_names[attr]))
630 *eflags |= (1 << attr);
631 }
632 FOR_EACH_MFIB_ATTRIBUTE (attr)
633 {
634 if (unformat (input, mfib_flag_names[attr]))
635 *eflags |= (1 << attr);
636 }
637
638 return (old == *eflags ? 0 : 1);
639}
640
Damjan Marion7cd468a2016-12-19 23:05:39 +0100641u8 *
642format_ip4_address (u8 * s, va_list * args)
643{
644 u8 *a = va_arg (*args, u8 *);
645 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
646}
647
648u8 *
649format_ip6_address (u8 * s, va_list * args)
650{
651 ip6_address_t *a = va_arg (*args, ip6_address_t *);
652 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
653
654 i_max_n_zero = ARRAY_LEN (a->as_u16);
655 max_n_zeros = 0;
656 i_first_zero = i_max_n_zero;
657 n_zeros = 0;
658 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
659 {
660 u32 is_zero = a->as_u16[i] == 0;
661 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
662 {
663 i_first_zero = i;
664 n_zeros = 0;
665 }
666 n_zeros += is_zero;
667 if ((!is_zero && n_zeros > max_n_zeros)
668 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
669 {
670 i_max_n_zero = i_first_zero;
671 max_n_zeros = n_zeros;
672 i_first_zero = ARRAY_LEN (a->as_u16);
673 n_zeros = 0;
674 }
675 }
676
677 last_double_colon = 0;
678 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
679 {
680 if (i == i_max_n_zero && max_n_zeros > 1)
681 {
682 s = format (s, "::");
683 i += max_n_zeros - 1;
684 last_double_colon = 1;
685 }
686 else
687 {
688 s = format (s, "%s%x",
689 (last_double_colon || i == 0) ? "" : ":",
690 clib_net_to_host_u16 (a->as_u16[i]));
691 last_double_colon = 0;
692 }
693 }
694
695 return s;
696}
697
698/* Format an IP46 address. */
699u8 *
700format_ip46_address (u8 * s, va_list * args)
701{
702 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
703 ip46_type_t type = va_arg (*args, ip46_type_t);
704 int is_ip4 = 1;
705
706 switch (type)
707 {
708 case IP46_TYPE_ANY:
709 is_ip4 = ip46_address_is_ip4 (ip46);
710 break;
711 case IP46_TYPE_IP4:
712 is_ip4 = 1;
713 break;
714 case IP46_TYPE_IP6:
715 is_ip4 = 0;
716 break;
717 }
718
719 return is_ip4 ?
720 format (s, "%U", format_ip4_address, &ip46->ip4) :
721 format (s, "%U", format_ip6_address, &ip46->ip6);
722}
723
724u8 *
725format_ethernet_address (u8 * s, va_list * args)
726{
727 u8 *a = va_arg (*args, u8 *);
728
729 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
730 a[0], a[1], a[2], a[3], a[4], a[5]);
731}
732#endif
733
734static void
735increment_v4_address (ip4_address_t * a)
736{
737 u32 v;
738
739 v = ntohl (a->as_u32) + 1;
740 a->as_u32 = ntohl (v);
741}
742
743static void
744increment_v6_address (ip6_address_t * a)
745{
746 u64 v0, v1;
747
748 v0 = clib_net_to_host_u64 (a->as_u64[0]);
749 v1 = clib_net_to_host_u64 (a->as_u64[1]);
750
751 v1 += 1;
752 if (v1 == 0)
753 v0 += 1;
754 a->as_u64[0] = clib_net_to_host_u64 (v0);
755 a->as_u64[1] = clib_net_to_host_u64 (v1);
756}
757
758static void
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200759increment_mac_address (u8 * mac)
Damjan Marion7cd468a2016-12-19 23:05:39 +0100760{
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200761 u64 tmp = *((u64 *) mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100762 tmp = clib_net_to_host_u64 (tmp);
763 tmp += 1 << 16; /* skip unused (least significant) octets */
764 tmp = clib_host_to_net_u64 (tmp);
Mohsin Kazmi57938f62017-10-27 21:28:07 +0200765
766 clib_memcpy (mac, &tmp, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +0100767}
768
769static void vl_api_create_loopback_reply_t_handler
770 (vl_api_create_loopback_reply_t * mp)
771{
772 vat_main_t *vam = &vat_main;
773 i32 retval = ntohl (mp->retval);
774
775 vam->retval = retval;
776 vam->regenerate_interface_table = 1;
777 vam->sw_if_index = ntohl (mp->sw_if_index);
778 vam->result_ready = 1;
779}
780
781static void vl_api_create_loopback_reply_t_handler_json
782 (vl_api_create_loopback_reply_t * mp)
783{
784 vat_main_t *vam = &vat_main;
785 vat_json_node_t node;
786
787 vat_json_init_object (&node);
788 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
789 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
790
791 vat_json_print (vam->ofp, &node);
792 vat_json_free (&node);
793 vam->retval = ntohl (mp->retval);
794 vam->result_ready = 1;
795}
796
Jon Loeligerc83c3b72017-02-23 13:57:35 -0600797static void vl_api_create_loopback_instance_reply_t_handler
798 (vl_api_create_loopback_instance_reply_t * mp)
799{
800 vat_main_t *vam = &vat_main;
801 i32 retval = ntohl (mp->retval);
802
803 vam->retval = retval;
804 vam->regenerate_interface_table = 1;
805 vam->sw_if_index = ntohl (mp->sw_if_index);
806 vam->result_ready = 1;
807}
808
809static void vl_api_create_loopback_instance_reply_t_handler_json
810 (vl_api_create_loopback_instance_reply_t * mp)
811{
812 vat_main_t *vam = &vat_main;
813 vat_json_node_t node;
814
815 vat_json_init_object (&node);
816 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
817 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
818
819 vat_json_print (vam->ofp, &node);
820 vat_json_free (&node);
821 vam->retval = ntohl (mp->retval);
822 vam->result_ready = 1;
823}
824
Damjan Marion7cd468a2016-12-19 23:05:39 +0100825static void vl_api_af_packet_create_reply_t_handler
826 (vl_api_af_packet_create_reply_t * mp)
827{
828 vat_main_t *vam = &vat_main;
829 i32 retval = ntohl (mp->retval);
830
831 vam->retval = retval;
832 vam->regenerate_interface_table = 1;
833 vam->sw_if_index = ntohl (mp->sw_if_index);
834 vam->result_ready = 1;
835}
836
837static void vl_api_af_packet_create_reply_t_handler_json
838 (vl_api_af_packet_create_reply_t * mp)
839{
840 vat_main_t *vam = &vat_main;
841 vat_json_node_t node;
842
843 vat_json_init_object (&node);
844 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
845 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
846
847 vat_json_print (vam->ofp, &node);
848 vat_json_free (&node);
849
850 vam->retval = ntohl (mp->retval);
851 vam->result_ready = 1;
852}
853
854static void vl_api_create_vlan_subif_reply_t_handler
855 (vl_api_create_vlan_subif_reply_t * mp)
856{
857 vat_main_t *vam = &vat_main;
858 i32 retval = ntohl (mp->retval);
859
860 vam->retval = retval;
861 vam->regenerate_interface_table = 1;
862 vam->sw_if_index = ntohl (mp->sw_if_index);
863 vam->result_ready = 1;
864}
865
866static void vl_api_create_vlan_subif_reply_t_handler_json
867 (vl_api_create_vlan_subif_reply_t * mp)
868{
869 vat_main_t *vam = &vat_main;
870 vat_json_node_t node;
871
872 vat_json_init_object (&node);
873 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
874 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
875
876 vat_json_print (vam->ofp, &node);
877 vat_json_free (&node);
878
879 vam->retval = ntohl (mp->retval);
880 vam->result_ready = 1;
881}
882
883static void vl_api_create_subif_reply_t_handler
884 (vl_api_create_subif_reply_t * mp)
885{
886 vat_main_t *vam = &vat_main;
887 i32 retval = ntohl (mp->retval);
888
889 vam->retval = retval;
890 vam->regenerate_interface_table = 1;
891 vam->sw_if_index = ntohl (mp->sw_if_index);
892 vam->result_ready = 1;
893}
894
895static void vl_api_create_subif_reply_t_handler_json
896 (vl_api_create_subif_reply_t * mp)
897{
898 vat_main_t *vam = &vat_main;
899 vat_json_node_t node;
900
901 vat_json_init_object (&node);
902 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
903 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
904
905 vat_json_print (vam->ofp, &node);
906 vat_json_free (&node);
907
908 vam->retval = ntohl (mp->retval);
909 vam->result_ready = 1;
910}
911
912static void vl_api_interface_name_renumber_reply_t_handler
913 (vl_api_interface_name_renumber_reply_t * mp)
914{
915 vat_main_t *vam = &vat_main;
916 i32 retval = ntohl (mp->retval);
917
918 vam->retval = retval;
919 vam->regenerate_interface_table = 1;
920 vam->result_ready = 1;
921}
922
923static void vl_api_interface_name_renumber_reply_t_handler_json
924 (vl_api_interface_name_renumber_reply_t * mp)
925{
926 vat_main_t *vam = &vat_main;
927 vat_json_node_t node;
928
929 vat_json_init_object (&node);
930 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
931
932 vat_json_print (vam->ofp, &node);
933 vat_json_free (&node);
934
935 vam->retval = ntohl (mp->retval);
936 vam->result_ready = 1;
937}
938
939/*
940 * Special-case: build the interface table, maintain
941 * the next loopback sw_if_index vbl.
942 */
943static void vl_api_sw_interface_details_t_handler
944 (vl_api_sw_interface_details_t * mp)
945{
946 vat_main_t *vam = &vat_main;
947 u8 *s = format (0, "%s%c", mp->interface_name, 0);
948
949 hash_set_mem (vam->sw_if_index_by_interface_name, s,
950 ntohl (mp->sw_if_index));
951
952 /* In sub interface case, fill the sub interface table entry */
953 if (mp->sw_if_index != mp->sup_sw_if_index)
954 {
955 sw_interface_subif_t *sub = NULL;
956
957 vec_add2 (vam->sw_if_subif_table, sub, 1);
958
959 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
960 strncpy ((char *) sub->interface_name, (char *) s,
961 vec_len (sub->interface_name));
962 sub->sw_if_index = ntohl (mp->sw_if_index);
963 sub->sub_id = ntohl (mp->sub_id);
964
965 sub->sub_dot1ad = mp->sub_dot1ad;
966 sub->sub_number_of_tags = mp->sub_number_of_tags;
967 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
968 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
969 sub->sub_exact_match = mp->sub_exact_match;
970 sub->sub_default = mp->sub_default;
971 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
972 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
973
974 /* vlan tag rewrite */
975 sub->vtr_op = ntohl (mp->vtr_op);
976 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
977 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
978 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
979 }
980}
981
982static void vl_api_sw_interface_details_t_handler_json
983 (vl_api_sw_interface_details_t * mp)
984{
985 vat_main_t *vam = &vat_main;
986 vat_json_node_t *node = NULL;
987
988 if (VAT_JSON_ARRAY != vam->json_tree.type)
989 {
990 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
991 vat_json_init_array (&vam->json_tree);
992 }
993 node = vat_json_array_add (&vam->json_tree);
994
995 vat_json_init_object (node);
996 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
997 vat_json_object_add_uint (node, "sup_sw_if_index",
998 ntohl (mp->sup_sw_if_index));
999 vat_json_object_add_uint (node, "l2_address_length",
1000 ntohl (mp->l2_address_length));
1001 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1002 sizeof (mp->l2_address));
1003 vat_json_object_add_string_copy (node, "interface_name",
1004 mp->interface_name);
1005 vat_json_object_add_uint (node, "admin_up_down", mp->admin_up_down);
1006 vat_json_object_add_uint (node, "link_up_down", mp->link_up_down);
1007 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1008 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001009 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001010 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1011 vat_json_object_add_uint (node, "sub_dot1ad", mp->sub_dot1ad);
1012 vat_json_object_add_uint (node, "sub_number_of_tags",
1013 mp->sub_number_of_tags);
1014 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1015 ntohs (mp->sub_outer_vlan_id));
1016 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1017 ntohs (mp->sub_inner_vlan_id));
1018 vat_json_object_add_uint (node, "sub_exact_match", mp->sub_exact_match);
1019 vat_json_object_add_uint (node, "sub_default", mp->sub_default);
1020 vat_json_object_add_uint (node, "sub_outer_vlan_id_any",
1021 mp->sub_outer_vlan_id_any);
1022 vat_json_object_add_uint (node, "sub_inner_vlan_id_any",
1023 mp->sub_inner_vlan_id_any);
1024 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1025 vat_json_object_add_uint (node, "vtr_push_dot1q",
1026 ntohl (mp->vtr_push_dot1q));
1027 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1028 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
Pavel Kotucek65e84572017-01-16 17:01:56 +01001029 if (mp->sub_dot1ah)
1030 {
1031 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1032 format (0, "%U",
1033 format_ethernet_address,
1034 &mp->b_dmac));
1035 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1036 format (0, "%U",
1037 format_ethernet_address,
1038 &mp->b_smac));
1039 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1040 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1041 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001042}
1043
Dave Baracha1a093d2017-03-02 13:13:23 -05001044#if VPP_API_TEST_BUILTIN == 0
Neale Rannsa07bd702017-08-07 07:53:49 -07001045static void vl_api_sw_interface_event_t_handler
1046 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001047{
1048 vat_main_t *vam = &vat_main;
1049 if (vam->interface_event_display)
1050 errmsg ("interface flags: sw_if_index %d %s %s",
1051 ntohl (mp->sw_if_index),
1052 mp->admin_up_down ? "admin-up" : "admin-down",
1053 mp->link_up_down ? "link-up" : "link-down");
1054}
Dave Baracha1a093d2017-03-02 13:13:23 -05001055#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +01001056
Neale Rannsa07bd702017-08-07 07:53:49 -07001057static void vl_api_sw_interface_event_t_handler_json
1058 (vl_api_sw_interface_event_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01001059{
1060 /* JSON output not supported */
1061}
1062
1063static void
1064vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1065{
1066 vat_main_t *vam = &vat_main;
1067 i32 retval = ntohl (mp->retval);
1068
1069 vam->retval = retval;
Damjan Marion7bee80c2017-04-26 15:32:12 +02001070 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001071 vam->result_ready = 1;
1072}
1073
1074static void
1075vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1076{
1077 vat_main_t *vam = &vat_main;
1078 vat_json_node_t node;
1079 api_main_t *am = &api_main;
1080 void *oldheap;
1081 u8 *reply;
1082
1083 vat_json_init_object (&node);
1084 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1085 vat_json_object_add_uint (&node, "reply_in_shmem",
1086 ntohl (mp->reply_in_shmem));
1087 /* Toss the shared-memory original... */
1088 pthread_mutex_lock (&am->vlib_rp->mutex);
1089 oldheap = svm_push_data_heap (am->vlib_rp);
1090
Damjan Marion7bee80c2017-04-26 15:32:12 +02001091 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001092 vec_free (reply);
1093
1094 svm_pop_heap (oldheap);
1095 pthread_mutex_unlock (&am->vlib_rp->mutex);
1096
1097 vat_json_print (vam->ofp, &node);
1098 vat_json_free (&node);
1099
1100 vam->retval = ntohl (mp->retval);
1101 vam->result_ready = 1;
1102}
1103
1104static void
1105vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1106{
1107 vat_main_t *vam = &vat_main;
1108 i32 retval = ntohl (mp->retval);
Ole Troan413f4a52018-11-28 11:36:05 +01001109 u32 length = vl_api_string_len (&mp->reply);
Dave Barach59b25652017-09-10 15:04:27 -04001110
1111 vec_reset_length (vam->cmd_reply);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001112
1113 vam->retval = retval;
Dave Barach59b25652017-09-10 15:04:27 -04001114 if (retval == 0)
1115 {
1116 vec_validate (vam->cmd_reply, length);
Ole Troan413f4a52018-11-28 11:36:05 +01001117 clib_memcpy ((char *) (vam->cmd_reply),
1118 vl_api_from_api_string (&mp->reply), length);
Dave Barach59b25652017-09-10 15:04:27 -04001119 vam->cmd_reply[length] = 0;
1120 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001121 vam->result_ready = 1;
1122}
1123
1124static void
1125vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1126{
1127 vat_main_t *vam = &vat_main;
1128 vat_json_node_t node;
1129
Dave Barach59b25652017-09-10 15:04:27 -04001130 vec_reset_length (vam->cmd_reply);
1131
Damjan Marion7cd468a2016-12-19 23:05:39 +01001132 vat_json_init_object (&node);
1133 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troan413f4a52018-11-28 11:36:05 +01001134 vat_json_object_add_string_copy (&node, "reply",
1135 vl_api_from_api_string (&mp->reply));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001136
1137 vat_json_print (vam->ofp, &node);
1138 vat_json_free (&node);
1139
1140 vam->retval = ntohl (mp->retval);
1141 vam->result_ready = 1;
1142}
1143
1144static void vl_api_classify_add_del_table_reply_t_handler
1145 (vl_api_classify_add_del_table_reply_t * mp)
1146{
1147 vat_main_t *vam = &vat_main;
1148 i32 retval = ntohl (mp->retval);
1149 if (vam->async_mode)
1150 {
1151 vam->async_errors += (retval < 0);
1152 }
1153 else
1154 {
1155 vam->retval = retval;
1156 if (retval == 0 &&
1157 ((mp->new_table_index != 0xFFFFFFFF) ||
1158 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1159 (mp->match_n_vectors != 0xFFFFFFFF)))
1160 /*
1161 * Note: this is just barely thread-safe, depends on
1162 * the main thread spinning waiting for an answer...
1163 */
1164 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1165 ntohl (mp->new_table_index),
1166 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1167 vam->result_ready = 1;
1168 }
1169}
1170
1171static void vl_api_classify_add_del_table_reply_t_handler_json
1172 (vl_api_classify_add_del_table_reply_t * mp)
1173{
1174 vat_main_t *vam = &vat_main;
1175 vat_json_node_t node;
1176
1177 vat_json_init_object (&node);
1178 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1179 vat_json_object_add_uint (&node, "new_table_index",
1180 ntohl (mp->new_table_index));
1181 vat_json_object_add_uint (&node, "skip_n_vectors",
1182 ntohl (mp->skip_n_vectors));
1183 vat_json_object_add_uint (&node, "match_n_vectors",
1184 ntohl (mp->match_n_vectors));
1185
1186 vat_json_print (vam->ofp, &node);
1187 vat_json_free (&node);
1188
1189 vam->retval = ntohl (mp->retval);
1190 vam->result_ready = 1;
1191}
1192
1193static void vl_api_get_node_index_reply_t_handler
1194 (vl_api_get_node_index_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 errmsg ("node index %d", ntohl (mp->node_index));
1207 vam->result_ready = 1;
1208 }
1209}
1210
1211static void vl_api_get_node_index_reply_t_handler_json
1212 (vl_api_get_node_index_reply_t * mp)
1213{
1214 vat_main_t *vam = &vat_main;
1215 vat_json_node_t node;
1216
1217 vat_json_init_object (&node);
1218 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1219 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1220
1221 vat_json_print (vam->ofp, &node);
1222 vat_json_free (&node);
1223
1224 vam->retval = ntohl (mp->retval);
1225 vam->result_ready = 1;
1226}
1227
1228static void vl_api_get_next_index_reply_t_handler
1229 (vl_api_get_next_index_reply_t * mp)
1230{
1231 vat_main_t *vam = &vat_main;
1232 i32 retval = ntohl (mp->retval);
1233 if (vam->async_mode)
1234 {
1235 vam->async_errors += (retval < 0);
1236 }
1237 else
1238 {
1239 vam->retval = retval;
1240 if (retval == 0)
1241 errmsg ("next node index %d", ntohl (mp->next_index));
1242 vam->result_ready = 1;
1243 }
1244}
1245
1246static void vl_api_get_next_index_reply_t_handler_json
1247 (vl_api_get_next_index_reply_t * mp)
1248{
1249 vat_main_t *vam = &vat_main;
1250 vat_json_node_t node;
1251
1252 vat_json_init_object (&node);
1253 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1254 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1255
1256 vat_json_print (vam->ofp, &node);
1257 vat_json_free (&node);
1258
1259 vam->retval = ntohl (mp->retval);
1260 vam->result_ready = 1;
1261}
1262
1263static void vl_api_add_node_next_reply_t_handler
1264 (vl_api_add_node_next_reply_t * mp)
1265{
1266 vat_main_t *vam = &vat_main;
1267 i32 retval = ntohl (mp->retval);
1268 if (vam->async_mode)
1269 {
1270 vam->async_errors += (retval < 0);
1271 }
1272 else
1273 {
1274 vam->retval = retval;
1275 if (retval == 0)
1276 errmsg ("next index %d", ntohl (mp->next_index));
1277 vam->result_ready = 1;
1278 }
1279}
1280
1281static void vl_api_add_node_next_reply_t_handler_json
1282 (vl_api_add_node_next_reply_t * mp)
1283{
1284 vat_main_t *vam = &vat_main;
1285 vat_json_node_t node;
1286
1287 vat_json_init_object (&node);
1288 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1289 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1290
1291 vat_json_print (vam->ofp, &node);
1292 vat_json_free (&node);
1293
1294 vam->retval = ntohl (mp->retval);
1295 vam->result_ready = 1;
1296}
1297
1298static void vl_api_show_version_reply_t_handler
1299 (vl_api_show_version_reply_t * mp)
1300{
1301 vat_main_t *vam = &vat_main;
1302 i32 retval = ntohl (mp->retval);
1303
1304 if (retval >= 0)
1305 {
Ole Troand6e9aec2018-12-16 23:44:54 +01001306 char *s;
Ole Troan413f4a52018-11-28 11:36:05 +01001307 char *p = (char *) &mp->program;
Ole Troand6e9aec2018-12-16 23:44:54 +01001308
1309 s = vl_api_from_api_string_c ((vl_api_string_t *) p);
1310 errmsg (" program: %s\n", s);
1311 free (s);
1312
1313 p +=
1314 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
1315 s = vl_api_from_api_string_c ((vl_api_string_t *) p);
1316 errmsg (" version: %s\n", s);
1317 free (s);
1318
1319 p +=
1320 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
1321 s = vl_api_from_api_string_c ((vl_api_string_t *) p);
1322 errmsg (" build date: %s\n", s);
1323 free (s);
1324
1325 p +=
1326 vl_api_string_len ((vl_api_string_t *) p) + sizeof (vl_api_string_t);
1327 s = vl_api_from_api_string_c ((vl_api_string_t *) p);
1328 errmsg ("build directory: %s\n", s);
1329 free (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001330 }
1331 vam->retval = retval;
1332 vam->result_ready = 1;
1333}
1334
1335static void vl_api_show_version_reply_t_handler_json
1336 (vl_api_show_version_reply_t * mp)
1337{
1338 vat_main_t *vam = &vat_main;
1339 vat_json_node_t node;
1340
1341 vat_json_init_object (&node);
1342 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
Ole Troan413f4a52018-11-28 11:36:05 +01001343 char *p = (char *) &mp->program;
1344 vat_json_object_add_string_copy (&node, "program",
1345 vl_api_from_api_string ((vl_api_string_t *)
1346 p));
1347 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
1348 vat_json_object_add_string_copy (&node, "version",
1349 vl_api_from_api_string ((vl_api_string_t *)
1350 p));
1351 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
1352 vat_json_object_add_string_copy (&node, "build_date",
1353 vl_api_from_api_string ((vl_api_string_t *)
1354 p));
1355 p += vl_api_string_len ((vl_api_string_t *) p) + sizeof (u32);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001356 vat_json_object_add_string_copy (&node, "build_directory",
Ole Troan413f4a52018-11-28 11:36:05 +01001357 vl_api_from_api_string ((vl_api_string_t *)
1358 p));
Damjan Marion7cd468a2016-12-19 23:05:39 +01001359
1360 vat_json_print (vam->ofp, &node);
1361 vat_json_free (&node);
1362
1363 vam->retval = ntohl (mp->retval);
1364 vam->result_ready = 1;
1365}
1366
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001367static void vl_api_show_threads_reply_t_handler
1368 (vl_api_show_threads_reply_t * mp)
1369{
1370 vat_main_t *vam = &vat_main;
1371 i32 retval = ntohl (mp->retval);
1372 int i, count = 0;
1373
1374 if (retval >= 0)
1375 count = ntohl (mp->count);
1376
1377 for (i = 0; i < count; i++)
1378 print (vam->ofp,
1379 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1380 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1381 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1382 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1383 ntohl (mp->thread_data[i].cpu_socket));
1384
1385 vam->retval = retval;
1386 vam->result_ready = 1;
1387}
1388
1389static void vl_api_show_threads_reply_t_handler_json
1390 (vl_api_show_threads_reply_t * mp)
1391{
1392 vat_main_t *vam = &vat_main;
1393 vat_json_node_t node;
1394 vl_api_thread_data_t *td;
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001395 i32 retval = ntohl (mp->retval);
1396 int i, count = 0;
1397
1398 if (retval >= 0)
1399 count = ntohl (mp->count);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001400
1401 vat_json_init_object (&node);
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001402 vat_json_object_add_int (&node, "retval", retval);
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001403 vat_json_object_add_uint (&node, "count", count);
1404
1405 for (i = 0; i < count; i++)
1406 {
1407 td = &mp->thread_data[i];
1408 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1409 vat_json_object_add_string_copy (&node, "name", td->name);
1410 vat_json_object_add_string_copy (&node, "type", td->type);
1411 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1412 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1413 vat_json_object_add_int (&node, "core", ntohl (td->id));
1414 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1415 }
1416
1417 vat_json_print (vam->ofp, &node);
1418 vat_json_free (&node);
1419
Mohsin Kazmi5df628b2018-10-01 17:41:08 +02001420 vam->retval = retval;
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02001421 vam->result_ready = 1;
1422}
1423
1424static int
1425api_show_threads (vat_main_t * vam)
1426{
1427 vl_api_show_threads_t *mp;
1428 int ret;
1429
1430 print (vam->ofp,
1431 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1432 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1433
1434 M (SHOW_THREADS, mp);
1435
1436 S (mp);
1437 W (ret);
1438 return ret;
1439}
1440
Damjan Marion7cd468a2016-12-19 23:05:39 +01001441static void
1442vl_api_ip4_arp_event_t_handler (vl_api_ip4_arp_event_t * mp)
1443{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001444 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001445 errmsg ("arp %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001446 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001447 ntohl (mp->pid), format_ip4_address, mp->ip,
1448 format_vl_api_mac_address, &mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001449}
1450
1451static void
1452vl_api_ip4_arp_event_t_handler_json (vl_api_ip4_arp_event_t * mp)
1453{
1454 /* JSON output not supported */
1455}
1456
1457static void
1458vl_api_ip6_nd_event_t_handler (vl_api_ip6_nd_event_t * mp)
1459{
Wojciech Dec09a38a62017-03-07 19:30:39 +01001460 u32 sw_if_index = ntohl (mp->sw_if_index);
John Lo20e1f2a2017-03-29 13:35:43 -04001461 errmsg ("ip6 nd %s event: pid %d address %U new mac %U sw_if_index %d\n",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001462 mp->mac_ip ? "mac/ip binding" : "address resolution",
Neale Ranns37029302018-08-10 05:30:06 -07001463 ntohl (mp->pid), format_vl_api_ip6_address, mp->ip,
1464 format_vl_api_mac_address, mp->mac, sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001465}
1466
1467static void
1468vl_api_ip6_nd_event_t_handler_json (vl_api_ip6_nd_event_t * mp)
1469{
1470 /* JSON output not supported */
1471}
1472
John Lo8d00fff2017-08-03 00:35:36 -04001473static void
1474vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1475{
1476 u32 n_macs = ntohl (mp->n_macs);
Paul Vinciguerraec11b132018-09-24 05:25:00 -07001477 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
John Lo8d00fff2017-08-03 00:35:36 -04001478 ntohl (mp->pid), mp->client_index, n_macs);
1479 int i;
1480 for (i = 0; i < n_macs; i++)
1481 {
1482 vl_api_mac_entry_t *mac = &mp->mac[i];
John Loe23c99e2018-03-13 21:53:18 -04001483 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
John Lo8d00fff2017-08-03 00:35:36 -04001484 i + 1, ntohl (mac->sw_if_index),
John Loe23c99e2018-03-13 21:53:18 -04001485 format_ethernet_address, mac->mac_addr, mac->action);
John Lo8d00fff2017-08-03 00:35:36 -04001486 if (i == 1000)
1487 break;
1488 }
1489}
1490
1491static void
1492vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1493{
1494 /* JSON output not supported */
1495}
1496
Ole Troan01384fe2017-05-12 11:55:35 +02001497#define vl_api_bridge_domain_details_t_endian vl_noop_handler
1498#define vl_api_bridge_domain_details_t_print vl_noop_handler
1499
Damjan Marion7cd468a2016-12-19 23:05:39 +01001500/*
1501 * Special-case: build the bridge domain table, maintain
1502 * the next bd id vbl.
1503 */
1504static void vl_api_bridge_domain_details_t_handler
1505 (vl_api_bridge_domain_details_t * mp)
1506{
1507 vat_main_t *vam = &vat_main;
1508 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Ole Troan01384fe2017-05-12 11:55:35 +02001509 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001510
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001511 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1512 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
Damjan Marion7cd468a2016-12-19 23:05:39 +01001513
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001514 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
Damjan Marion7cd468a2016-12-19 23:05:39 +01001515 ntohl (mp->bd_id), mp->learn, mp->forward,
Mohsin Kazmi762d83c2018-09-27 15:00:32 +02001516 mp->flood, ntohl (mp->bvi_sw_if_index),
1517 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001518
1519 if (n_sw_ifs)
Ole Troan01384fe2017-05-12 11:55:35 +02001520 {
1521 vl_api_bridge_domain_sw_if_t *sw_ifs;
1522 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1523 "Interface Name");
1524
1525 sw_ifs = mp->sw_if_details;
1526 for (i = 0; i < n_sw_ifs; i++)
1527 {
1528 u8 *sw_if_name = 0;
1529 u32 sw_if_index;
1530 hash_pair_t *p;
1531
1532 sw_if_index = ntohl (sw_ifs->sw_if_index);
1533
1534 /* *INDENT-OFF* */
1535 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1536 ({
1537 if ((u32) p->value[0] == sw_if_index)
1538 {
1539 sw_if_name = (u8 *)(p->key);
1540 break;
1541 }
1542 }));
1543 /* *INDENT-ON* */
1544 print (vam->ofp, "%7d %3d %s", sw_if_index,
1545 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1546 "sw_if_index not found!");
1547
1548 sw_ifs++;
1549 }
1550 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001551}
1552
1553static void vl_api_bridge_domain_details_t_handler_json
1554 (vl_api_bridge_domain_details_t * mp)
1555{
1556 vat_main_t *vam = &vat_main;
1557 vat_json_node_t *node, *array = NULL;
Ole Troan01384fe2017-05-12 11:55:35 +02001558 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001559
1560 if (VAT_JSON_ARRAY != vam->json_tree.type)
1561 {
1562 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1563 vat_json_init_array (&vam->json_tree);
1564 }
1565 node = vat_json_array_add (&vam->json_tree);
1566
1567 vat_json_init_object (node);
1568 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1569 vat_json_object_add_uint (node, "flood", mp->flood);
1570 vat_json_object_add_uint (node, "forward", mp->forward);
1571 vat_json_object_add_uint (node, "learn", mp->learn);
1572 vat_json_object_add_uint (node, "bvi_sw_if_index",
1573 ntohl (mp->bvi_sw_if_index));
Ole Troan01384fe2017-05-12 11:55:35 +02001574 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001575 array = vat_json_object_add (node, "sw_if");
1576 vat_json_init_array (array);
Damjan Marion7cd468a2016-12-19 23:05:39 +01001577
Damjan Marion7cd468a2016-12-19 23:05:39 +01001578
Damjan Marion7cd468a2016-12-19 23:05:39 +01001579
Ole Troan01384fe2017-05-12 11:55:35 +02001580 if (n_sw_ifs)
1581 {
1582 vl_api_bridge_domain_sw_if_t *sw_ifs;
1583 int i;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001584
Ole Troan01384fe2017-05-12 11:55:35 +02001585 sw_ifs = mp->sw_if_details;
1586 for (i = 0; i < n_sw_ifs; i++)
1587 {
1588 node = vat_json_array_add (array);
1589 vat_json_init_object (node);
1590 vat_json_object_add_uint (node, "sw_if_index",
1591 ntohl (sw_ifs->sw_if_index));
1592 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1593 sw_ifs++;
1594 }
1595 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01001596}
1597
1598static void vl_api_control_ping_reply_t_handler
1599 (vl_api_control_ping_reply_t * mp)
1600{
1601 vat_main_t *vam = &vat_main;
1602 i32 retval = ntohl (mp->retval);
1603 if (vam->async_mode)
1604 {
1605 vam->async_errors += (retval < 0);
1606 }
1607 else
1608 {
1609 vam->retval = retval;
1610 vam->result_ready = 1;
1611 }
Florin Coras90a63982017-12-19 04:50:01 -08001612 if (vam->socket_client_main)
1613 vam->socket_client_main->control_pings_outstanding--;
Damjan Marion7cd468a2016-12-19 23:05:39 +01001614}
1615
1616static void vl_api_control_ping_reply_t_handler_json
1617 (vl_api_control_ping_reply_t * mp)
1618{
1619 vat_main_t *vam = &vat_main;
1620 i32 retval = ntohl (mp->retval);
1621
1622 if (VAT_JSON_NONE != vam->json_tree.type)
1623 {
1624 vat_json_print (vam->ofp, &vam->json_tree);
1625 vat_json_free (&vam->json_tree);
1626 vam->json_tree.type = VAT_JSON_NONE;
1627 }
1628 else
1629 {
1630 /* just print [] */
1631 vat_json_init_array (&vam->json_tree);
1632 vat_json_print (vam->ofp, &vam->json_tree);
1633 vam->json_tree.type = VAT_JSON_NONE;
1634 }
1635
1636 vam->retval = retval;
1637 vam->result_ready = 1;
1638}
1639
1640static void
Eyal Barifead6702017-04-04 04:46:32 +03001641 vl_api_bridge_domain_set_mac_age_reply_t_handler
1642 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1643{
1644 vat_main_t *vam = &vat_main;
1645 i32 retval = ntohl (mp->retval);
1646 if (vam->async_mode)
1647 {
1648 vam->async_errors += (retval < 0);
1649 }
1650 else
1651 {
1652 vam->retval = retval;
1653 vam->result_ready = 1;
1654 }
1655}
1656
1657static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1658 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1659{
1660 vat_main_t *vam = &vat_main;
1661 vat_json_node_t node;
1662
1663 vat_json_init_object (&node);
1664 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1665
1666 vat_json_print (vam->ofp, &node);
1667 vat_json_free (&node);
1668
1669 vam->retval = ntohl (mp->retval);
1670 vam->result_ready = 1;
1671}
1672
1673static void
Damjan Marion7cd468a2016-12-19 23:05:39 +01001674vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1675{
1676 vat_main_t *vam = &vat_main;
1677 i32 retval = ntohl (mp->retval);
1678 if (vam->async_mode)
1679 {
1680 vam->async_errors += (retval < 0);
1681 }
1682 else
1683 {
1684 vam->retval = retval;
1685 vam->result_ready = 1;
1686 }
1687}
1688
1689static void vl_api_l2_flags_reply_t_handler_json
1690 (vl_api_l2_flags_reply_t * mp)
1691{
1692 vat_main_t *vam = &vat_main;
1693 vat_json_node_t node;
1694
1695 vat_json_init_object (&node);
1696 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1697 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1698 ntohl (mp->resulting_feature_bitmap));
1699
1700 vat_json_print (vam->ofp, &node);
1701 vat_json_free (&node);
1702
1703 vam->retval = ntohl (mp->retval);
1704 vam->result_ready = 1;
1705}
1706
1707static void vl_api_bridge_flags_reply_t_handler
1708 (vl_api_bridge_flags_reply_t * mp)
1709{
1710 vat_main_t *vam = &vat_main;
1711 i32 retval = ntohl (mp->retval);
1712 if (vam->async_mode)
1713 {
1714 vam->async_errors += (retval < 0);
1715 }
1716 else
1717 {
1718 vam->retval = retval;
1719 vam->result_ready = 1;
1720 }
1721}
1722
1723static void vl_api_bridge_flags_reply_t_handler_json
1724 (vl_api_bridge_flags_reply_t * mp)
1725{
1726 vat_main_t *vam = &vat_main;
1727 vat_json_node_t node;
1728
1729 vat_json_init_object (&node);
1730 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1731 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1732 ntohl (mp->resulting_feature_bitmap));
1733
1734 vat_json_print (vam->ofp, &node);
1735 vat_json_free (&node);
1736
1737 vam->retval = ntohl (mp->retval);
1738 vam->result_ready = 1;
1739}
1740
Damjan Marion8389fb92017-10-13 18:29:53 +02001741static void
1742vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1743{
1744 vat_main_t *vam = &vat_main;
1745 i32 retval = ntohl (mp->retval);
1746 if (vam->async_mode)
1747 {
1748 vam->async_errors += (retval < 0);
1749 }
1750 else
1751 {
1752 vam->retval = retval;
1753 vam->sw_if_index = ntohl (mp->sw_if_index);
1754 vam->result_ready = 1;
1755 }
1756
1757}
1758
1759static void vl_api_tap_create_v2_reply_t_handler_json
1760 (vl_api_tap_create_v2_reply_t * mp)
1761{
1762 vat_main_t *vam = &vat_main;
1763 vat_json_node_t node;
1764
1765 vat_json_init_object (&node);
1766 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1767 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1768
1769 vat_json_print (vam->ofp, &node);
1770 vat_json_free (&node);
1771
1772 vam->retval = ntohl (mp->retval);
1773 vam->result_ready = 1;
1774
1775}
1776
1777static void
1778vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1779{
1780 vat_main_t *vam = &vat_main;
1781 i32 retval = ntohl (mp->retval);
1782 if (vam->async_mode)
1783 {
1784 vam->async_errors += (retval < 0);
1785 }
1786 else
1787 {
1788 vam->retval = retval;
1789 vam->result_ready = 1;
1790 }
1791}
1792
1793static void vl_api_tap_delete_v2_reply_t_handler_json
1794 (vl_api_tap_delete_v2_reply_t * mp)
1795{
1796 vat_main_t *vam = &vat_main;
1797 vat_json_node_t node;
1798
1799 vat_json_init_object (&node);
1800 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1801
1802 vat_json_print (vam->ofp, &node);
1803 vat_json_free (&node);
1804
1805 vam->retval = ntohl (mp->retval);
1806 vam->result_ready = 1;
1807}
1808
Steven9cd2d7a2017-12-20 12:43:01 -08001809static void
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01001810vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1811 mp)
1812{
1813 vat_main_t *vam = &vat_main;
1814 i32 retval = ntohl (mp->retval);
1815 if (vam->async_mode)
1816 {
1817 vam->async_errors += (retval < 0);
1818 }
1819 else
1820 {
1821 vam->retval = retval;
1822 vam->sw_if_index = ntohl (mp->sw_if_index);
1823 vam->result_ready = 1;
1824 }
1825}
1826
1827static void vl_api_virtio_pci_create_reply_t_handler_json
1828 (vl_api_virtio_pci_create_reply_t * mp)
1829{
1830 vat_main_t *vam = &vat_main;
1831 vat_json_node_t node;
1832
1833 vat_json_init_object (&node);
1834 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1835 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1836
1837 vat_json_print (vam->ofp, &node);
1838 vat_json_free (&node);
1839
1840 vam->retval = ntohl (mp->retval);
1841 vam->result_ready = 1;
1842
1843}
1844
1845static void
1846vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1847 mp)
1848{
1849 vat_main_t *vam = &vat_main;
1850 i32 retval = ntohl (mp->retval);
1851 if (vam->async_mode)
1852 {
1853 vam->async_errors += (retval < 0);
1854 }
1855 else
1856 {
1857 vam->retval = retval;
1858 vam->result_ready = 1;
1859 }
1860}
1861
1862static void vl_api_virtio_pci_delete_reply_t_handler_json
1863 (vl_api_virtio_pci_delete_reply_t * mp)
1864{
1865 vat_main_t *vam = &vat_main;
1866 vat_json_node_t node;
1867
1868 vat_json_init_object (&node);
1869 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1870
1871 vat_json_print (vam->ofp, &node);
1872 vat_json_free (&node);
1873
1874 vam->retval = ntohl (mp->retval);
1875 vam->result_ready = 1;
1876}
1877
1878static void
Steven9cd2d7a2017-12-20 12:43:01 -08001879vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1880{
1881 vat_main_t *vam = &vat_main;
1882 i32 retval = ntohl (mp->retval);
1883
1884 if (vam->async_mode)
1885 {
1886 vam->async_errors += (retval < 0);
1887 }
1888 else
1889 {
1890 vam->retval = retval;
1891 vam->sw_if_index = ntohl (mp->sw_if_index);
1892 vam->result_ready = 1;
1893 }
1894}
1895
1896static void vl_api_bond_create_reply_t_handler_json
1897 (vl_api_bond_create_reply_t * mp)
1898{
1899 vat_main_t *vam = &vat_main;
1900 vat_json_node_t node;
1901
1902 vat_json_init_object (&node);
1903 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1904 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1905
1906 vat_json_print (vam->ofp, &node);
1907 vat_json_free (&node);
1908
1909 vam->retval = ntohl (mp->retval);
1910 vam->result_ready = 1;
1911}
1912
1913static void
1914vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1915{
1916 vat_main_t *vam = &vat_main;
1917 i32 retval = ntohl (mp->retval);
1918
1919 if (vam->async_mode)
1920 {
1921 vam->async_errors += (retval < 0);
1922 }
1923 else
1924 {
1925 vam->retval = retval;
1926 vam->result_ready = 1;
1927 }
1928}
1929
1930static void vl_api_bond_delete_reply_t_handler_json
1931 (vl_api_bond_delete_reply_t * mp)
1932{
1933 vat_main_t *vam = &vat_main;
1934 vat_json_node_t node;
1935
1936 vat_json_init_object (&node);
1937 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1938
1939 vat_json_print (vam->ofp, &node);
1940 vat_json_free (&node);
1941
1942 vam->retval = ntohl (mp->retval);
1943 vam->result_ready = 1;
1944}
1945
1946static void
1947vl_api_bond_enslave_reply_t_handler (vl_api_bond_enslave_reply_t * mp)
1948{
1949 vat_main_t *vam = &vat_main;
1950 i32 retval = ntohl (mp->retval);
1951
1952 if (vam->async_mode)
1953 {
1954 vam->async_errors += (retval < 0);
1955 }
1956 else
1957 {
1958 vam->retval = retval;
1959 vam->result_ready = 1;
1960 }
1961}
1962
1963static void vl_api_bond_enslave_reply_t_handler_json
1964 (vl_api_bond_enslave_reply_t * mp)
1965{
1966 vat_main_t *vam = &vat_main;
1967 vat_json_node_t node;
1968
1969 vat_json_init_object (&node);
1970 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1971
1972 vat_json_print (vam->ofp, &node);
1973 vat_json_free (&node);
1974
1975 vam->retval = ntohl (mp->retval);
1976 vam->result_ready = 1;
1977}
1978
1979static void
1980vl_api_bond_detach_slave_reply_t_handler (vl_api_bond_detach_slave_reply_t *
1981 mp)
1982{
1983 vat_main_t *vam = &vat_main;
1984 i32 retval = ntohl (mp->retval);
1985
1986 if (vam->async_mode)
1987 {
1988 vam->async_errors += (retval < 0);
1989 }
1990 else
1991 {
1992 vam->retval = retval;
1993 vam->result_ready = 1;
1994 }
1995}
1996
1997static void vl_api_bond_detach_slave_reply_t_handler_json
1998 (vl_api_bond_detach_slave_reply_t * mp)
1999{
2000 vat_main_t *vam = &vat_main;
2001 vat_json_node_t node;
2002
2003 vat_json_init_object (&node);
2004 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2005
2006 vat_json_print (vam->ofp, &node);
2007 vat_json_free (&node);
2008
2009 vam->retval = ntohl (mp->retval);
2010 vam->result_ready = 1;
2011}
2012
2013static void vl_api_sw_interface_bond_details_t_handler
2014 (vl_api_sw_interface_bond_details_t * mp)
2015{
2016 vat_main_t *vam = &vat_main;
2017
2018 print (vam->ofp,
2019 "%-16s %-12d %-12U %-13U %-14u %-14u",
2020 mp->interface_name, ntohl (mp->sw_if_index),
2021 format_bond_mode, mp->mode, format_bond_load_balance, mp->lb,
2022 ntohl (mp->active_slaves), ntohl (mp->slaves));
2023}
2024
2025static void vl_api_sw_interface_bond_details_t_handler_json
2026 (vl_api_sw_interface_bond_details_t * mp)
2027{
2028 vat_main_t *vam = &vat_main;
2029 vat_json_node_t *node = NULL;
2030
2031 if (VAT_JSON_ARRAY != vam->json_tree.type)
2032 {
2033 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2034 vat_json_init_array (&vam->json_tree);
2035 }
2036 node = vat_json_array_add (&vam->json_tree);
2037
2038 vat_json_init_object (node);
2039 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2040 vat_json_object_add_string_copy (node, "interface_name",
2041 mp->interface_name);
2042 vat_json_object_add_uint (node, "mode", mp->mode);
2043 vat_json_object_add_uint (node, "load_balance", mp->lb);
2044 vat_json_object_add_uint (node, "active_slaves", ntohl (mp->active_slaves));
2045 vat_json_object_add_uint (node, "slaves", ntohl (mp->slaves));
2046}
2047
2048static int
2049api_sw_interface_bond_dump (vat_main_t * vam)
2050{
2051 vl_api_sw_interface_bond_dump_t *mp;
2052 vl_api_control_ping_t *mp_ping;
2053 int ret;
2054
2055 print (vam->ofp,
2056 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2057 "interface name", "sw_if_index", "mode", "load balance",
2058 "active slaves", "slaves");
2059
2060 /* Get list of bond interfaces */
2061 M (SW_INTERFACE_BOND_DUMP, mp);
2062 S (mp);
2063
2064 /* Use a control ping for synchronization */
2065 MPING (CONTROL_PING, mp_ping);
2066 S (mp_ping);
2067
2068 W (ret);
2069 return ret;
2070}
2071
2072static void vl_api_sw_interface_slave_details_t_handler
2073 (vl_api_sw_interface_slave_details_t * mp)
2074{
2075 vat_main_t *vam = &vat_main;
2076
2077 print (vam->ofp,
2078 "%-25s %-12d %-12d %d", mp->interface_name,
2079 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout);
2080}
2081
2082static void vl_api_sw_interface_slave_details_t_handler_json
2083 (vl_api_sw_interface_slave_details_t * mp)
2084{
2085 vat_main_t *vam = &vat_main;
2086 vat_json_node_t *node = NULL;
2087
2088 if (VAT_JSON_ARRAY != vam->json_tree.type)
2089 {
2090 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2091 vat_json_init_array (&vam->json_tree);
2092 }
2093 node = vat_json_array_add (&vam->json_tree);
2094
2095 vat_json_init_object (node);
2096 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2097 vat_json_object_add_string_copy (node, "interface_name",
2098 mp->interface_name);
2099 vat_json_object_add_uint (node, "passive", mp->is_passive);
2100 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2101}
2102
2103static int
2104api_sw_interface_slave_dump (vat_main_t * vam)
2105{
2106 unformat_input_t *i = vam->input;
2107 vl_api_sw_interface_slave_dump_t *mp;
2108 vl_api_control_ping_t *mp_ping;
2109 u32 sw_if_index = ~0;
2110 u8 sw_if_index_set = 0;
2111 int ret;
2112
2113 /* Parse args required to build the message */
2114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2115 {
2116 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2117 sw_if_index_set = 1;
2118 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2119 sw_if_index_set = 1;
2120 else
2121 break;
2122 }
2123
2124 if (sw_if_index_set == 0)
2125 {
2126 errmsg ("missing vpp interface name. ");
2127 return -99;
2128 }
2129
2130 print (vam->ofp,
2131 "\n%-25s %-12s %-12s %s",
2132 "slave interface name", "sw_if_index", "passive", "long_timeout");
2133
2134 /* Get list of bond interfaces */
2135 M (SW_INTERFACE_SLAVE_DUMP, mp);
2136 mp->sw_if_index = ntohl (sw_if_index);
2137 S (mp);
2138
2139 /* Use a control ping for synchronization */
2140 MPING (CONTROL_PING, mp_ping);
2141 S (mp_ping);
2142
2143 W (ret);
2144 return ret;
2145}
2146
Damjan Marion7cd468a2016-12-19 23:05:39 +01002147static void vl_api_mpls_tunnel_add_del_reply_t_handler
2148 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2149{
2150 vat_main_t *vam = &vat_main;
2151 i32 retval = ntohl (mp->retval);
2152 if (vam->async_mode)
2153 {
2154 vam->async_errors += (retval < 0);
2155 }
2156 else
2157 {
2158 vam->retval = retval;
John Lo06fda9c2018-10-03 16:32:44 -04002159 vam->sw_if_index = ntohl (mp->sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002160 vam->result_ready = 1;
2161 }
John Lo06fda9c2018-10-03 16:32:44 -04002162 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002163}
2164
2165static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2166 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2167{
2168 vat_main_t *vam = &vat_main;
2169 vat_json_node_t node;
2170
2171 vat_json_init_object (&node);
2172 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2173 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2174 ntohl (mp->sw_if_index));
2175
2176 vat_json_print (vam->ofp, &node);
2177 vat_json_free (&node);
2178
2179 vam->retval = ntohl (mp->retval);
2180 vam->result_ready = 1;
2181}
2182
2183static void vl_api_l2tpv3_create_tunnel_reply_t_handler
2184 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2185{
2186 vat_main_t *vam = &vat_main;
2187 i32 retval = ntohl (mp->retval);
2188 if (vam->async_mode)
2189 {
2190 vam->async_errors += (retval < 0);
2191 }
2192 else
2193 {
2194 vam->retval = retval;
2195 vam->sw_if_index = ntohl (mp->sw_if_index);
2196 vam->result_ready = 1;
2197 }
2198}
2199
2200static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
2201 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
2202{
2203 vat_main_t *vam = &vat_main;
2204 vat_json_node_t node;
2205
2206 vat_json_init_object (&node);
2207 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2208 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2209
2210 vat_json_print (vam->ofp, &node);
2211 vat_json_free (&node);
2212
2213 vam->retval = ntohl (mp->retval);
2214 vam->result_ready = 1;
2215}
2216
Filip Tehlar560274d2017-06-05 13:40:13 +02002217static void vl_api_gpe_add_del_fwd_entry_reply_t_handler
2218 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2219{
2220 vat_main_t *vam = &vat_main;
2221 i32 retval = ntohl (mp->retval);
2222 if (vam->async_mode)
2223 {
2224 vam->async_errors += (retval < 0);
2225 }
2226 else
2227 {
2228 vam->retval = retval;
2229 vam->result_ready = 1;
2230 }
2231}
2232
2233static void vl_api_gpe_add_del_fwd_entry_reply_t_handler_json
2234 (vl_api_gpe_add_del_fwd_entry_reply_t * mp)
2235{
2236 vat_main_t *vam = &vat_main;
2237 vat_json_node_t node;
2238
2239 vat_json_init_object (&node);
2240 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2241 vat_json_object_add_uint (&node, "fwd_entry_index",
2242 clib_net_to_host_u32 (mp->fwd_entry_index));
2243
2244 vat_json_print (vam->ofp, &node);
2245 vat_json_free (&node);
2246
2247 vam->retval = ntohl (mp->retval);
2248 vam->result_ready = 1;
2249}
Damjan Marion7cd468a2016-12-19 23:05:39 +01002250
Filip Tehlara4980b82017-09-27 14:32:02 +02002251u8 *
2252format_lisp_transport_protocol (u8 * s, va_list * args)
2253{
2254 u32 proto = va_arg (*args, u32);
2255
2256 switch (proto)
2257 {
2258 case 1:
2259 return format (s, "udp");
2260 case 2:
2261 return format (s, "api");
2262 default:
2263 return 0;
2264 }
2265 return 0;
2266}
2267
2268static void vl_api_one_get_transport_protocol_reply_t_handler
2269 (vl_api_one_get_transport_protocol_reply_t * mp)
2270{
2271 vat_main_t *vam = &vat_main;
2272 i32 retval = ntohl (mp->retval);
2273 if (vam->async_mode)
2274 {
2275 vam->async_errors += (retval < 0);
2276 }
2277 else
2278 {
2279 u32 proto = mp->protocol;
2280 print (vam->ofp, "Transport protocol: %U",
2281 format_lisp_transport_protocol, proto);
2282 vam->retval = retval;
2283 vam->result_ready = 1;
2284 }
2285}
2286
2287static void vl_api_one_get_transport_protocol_reply_t_handler_json
2288 (vl_api_one_get_transport_protocol_reply_t * mp)
2289{
2290 vat_main_t *vam = &vat_main;
2291 vat_json_node_t node;
2292 u8 *s;
2293
2294 s = format (0, "%U", format_lisp_transport_protocol, mp->protocol);
2295 vec_add1 (s, 0);
2296
2297 vat_json_init_object (&node);
2298 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2299 vat_json_object_add_string_copy (&node, "transport-protocol", s);
2300
2301 vec_free (s);
2302 vat_json_print (vam->ofp, &node);
2303 vat_json_free (&node);
2304
2305 vam->retval = ntohl (mp->retval);
2306 vam->result_ready = 1;
2307}
2308
Filip Tehlar694396d2017-02-17 14:29:11 +01002309static void vl_api_one_add_del_locator_set_reply_t_handler
2310 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002311{
2312 vat_main_t *vam = &vat_main;
2313 i32 retval = ntohl (mp->retval);
2314 if (vam->async_mode)
2315 {
2316 vam->async_errors += (retval < 0);
2317 }
2318 else
2319 {
2320 vam->retval = retval;
2321 vam->result_ready = 1;
2322 }
2323}
2324
Filip Tehlar694396d2017-02-17 14:29:11 +01002325static void vl_api_one_add_del_locator_set_reply_t_handler_json
2326 (vl_api_one_add_del_locator_set_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002327{
2328 vat_main_t *vam = &vat_main;
2329 vat_json_node_t node;
2330
2331 vat_json_init_object (&node);
2332 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2333 vat_json_object_add_uint (&node, "locator_set_index", ntohl (mp->ls_index));
2334
2335 vat_json_print (vam->ofp, &node);
2336 vat_json_free (&node);
2337
2338 vam->retval = ntohl (mp->retval);
2339 vam->result_ready = 1;
2340}
2341
2342static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2343 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2344{
2345 vat_main_t *vam = &vat_main;
2346 i32 retval = ntohl (mp->retval);
2347 if (vam->async_mode)
2348 {
2349 vam->async_errors += (retval < 0);
2350 }
2351 else
2352 {
2353 vam->retval = retval;
2354 vam->sw_if_index = ntohl (mp->sw_if_index);
2355 vam->result_ready = 1;
2356 }
Dave Barachf72212e2018-01-11 10:25:07 -05002357 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002358}
2359
2360static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2361 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2362{
2363 vat_main_t *vam = &vat_main;
2364 vat_json_node_t node;
2365
2366 vat_json_init_object (&node);
2367 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2368 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2369
2370 vat_json_print (vam->ofp, &node);
2371 vat_json_free (&node);
2372
2373 vam->retval = ntohl (mp->retval);
2374 vam->result_ready = 1;
2375}
2376
eyal bariaf86a482018-04-17 11:20:27 +03002377static void vl_api_vxlan_offload_rx_reply_t_handler
2378 (vl_api_vxlan_offload_rx_reply_t * mp)
2379{
2380 vat_main_t *vam = &vat_main;
2381 i32 retval = ntohl (mp->retval);
2382 if (vam->async_mode)
2383 {
2384 vam->async_errors += (retval < 0);
2385 }
2386 else
2387 {
2388 vam->retval = retval;
2389 vam->result_ready = 1;
2390 }
2391}
2392
2393static void vl_api_vxlan_offload_rx_reply_t_handler_json
2394 (vl_api_vxlan_offload_rx_reply_t * mp)
2395{
2396 vat_main_t *vam = &vat_main;
2397 vat_json_node_t node;
2398
2399 vat_json_init_object (&node);
2400 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2401
2402 vat_json_print (vam->ofp, &node);
2403 vat_json_free (&node);
2404
2405 vam->retval = ntohl (mp->retval);
2406 vam->result_ready = 1;
2407}
2408
Marco Varleseb598f1d2017-09-19 14:25:28 +02002409static void vl_api_geneve_add_del_tunnel_reply_t_handler
2410 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2411{
2412 vat_main_t *vam = &vat_main;
2413 i32 retval = ntohl (mp->retval);
2414 if (vam->async_mode)
2415 {
2416 vam->async_errors += (retval < 0);
2417 }
2418 else
2419 {
2420 vam->retval = retval;
2421 vam->sw_if_index = ntohl (mp->sw_if_index);
2422 vam->result_ready = 1;
2423 }
2424}
2425
2426static void vl_api_geneve_add_del_tunnel_reply_t_handler_json
2427 (vl_api_geneve_add_del_tunnel_reply_t * mp)
2428{
2429 vat_main_t *vam = &vat_main;
2430 vat_json_node_t node;
2431
2432 vat_json_init_object (&node);
2433 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2434 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2435
2436 vat_json_print (vam->ofp, &node);
2437 vat_json_free (&node);
2438
2439 vam->retval = ntohl (mp->retval);
2440 vam->result_ready = 1;
2441}
2442
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002443static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2444 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2445{
2446 vat_main_t *vam = &vat_main;
2447 i32 retval = ntohl (mp->retval);
2448 if (vam->async_mode)
2449 {
2450 vam->async_errors += (retval < 0);
2451 }
2452 else
2453 {
2454 vam->retval = retval;
2455 vam->sw_if_index = ntohl (mp->sw_if_index);
2456 vam->result_ready = 1;
2457 }
Dave Barachf72212e2018-01-11 10:25:07 -05002458 vam->regenerate_interface_table = 1;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08002459}
2460
2461static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2462 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2463{
2464 vat_main_t *vam = &vat_main;
2465 vat_json_node_t node;
2466
2467 vat_json_init_object (&node);
2468 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2469 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2470
2471 vat_json_print (vam->ofp, &node);
2472 vat_json_free (&node);
2473
2474 vam->retval = ntohl (mp->retval);
2475 vam->result_ready = 1;
2476}
2477
Damjan Marion7cd468a2016-12-19 23:05:39 +01002478static void vl_api_gre_add_del_tunnel_reply_t_handler
2479 (vl_api_gre_add_del_tunnel_reply_t * mp)
2480{
2481 vat_main_t *vam = &vat_main;
2482 i32 retval = ntohl (mp->retval);
2483 if (vam->async_mode)
2484 {
2485 vam->async_errors += (retval < 0);
2486 }
2487 else
2488 {
2489 vam->retval = retval;
2490 vam->sw_if_index = ntohl (mp->sw_if_index);
2491 vam->result_ready = 1;
2492 }
2493}
2494
2495static void vl_api_gre_add_del_tunnel_reply_t_handler_json
2496 (vl_api_gre_add_del_tunnel_reply_t * mp)
2497{
2498 vat_main_t *vam = &vat_main;
2499 vat_json_node_t node;
2500
2501 vat_json_init_object (&node);
2502 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2503 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2504
2505 vat_json_print (vam->ofp, &node);
2506 vat_json_free (&node);
2507
2508 vam->retval = ntohl (mp->retval);
2509 vam->result_ready = 1;
2510}
2511
2512static void vl_api_create_vhost_user_if_reply_t_handler
2513 (vl_api_create_vhost_user_if_reply_t * mp)
2514{
2515 vat_main_t *vam = &vat_main;
2516 i32 retval = ntohl (mp->retval);
2517 if (vam->async_mode)
2518 {
2519 vam->async_errors += (retval < 0);
2520 }
2521 else
2522 {
2523 vam->retval = retval;
2524 vam->sw_if_index = ntohl (mp->sw_if_index);
2525 vam->result_ready = 1;
2526 }
Dave Barachf72212e2018-01-11 10:25:07 -05002527 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01002528}
2529
2530static void vl_api_create_vhost_user_if_reply_t_handler_json
2531 (vl_api_create_vhost_user_if_reply_t * mp)
2532{
2533 vat_main_t *vam = &vat_main;
2534 vat_json_node_t node;
2535
2536 vat_json_init_object (&node);
2537 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2538 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2539
2540 vat_json_print (vam->ofp, &node);
2541 vat_json_free (&node);
2542
2543 vam->retval = ntohl (mp->retval);
2544 vam->result_ready = 1;
2545}
2546
Dave Barach65457162017-10-10 17:53:14 -04002547static void vl_api_dns_resolve_name_reply_t_handler
2548 (vl_api_dns_resolve_name_reply_t * mp)
2549{
2550 vat_main_t *vam = &vat_main;
2551 i32 retval = ntohl (mp->retval);
2552 if (vam->async_mode)
2553 {
2554 vam->async_errors += (retval < 0);
2555 }
2556 else
2557 {
2558 vam->retval = retval;
2559 vam->result_ready = 1;
2560
2561 if (retval == 0)
2562 {
2563 if (mp->ip4_set)
2564 clib_warning ("ip4 address %U", format_ip4_address,
2565 (ip4_address_t *) mp->ip4_address);
2566 if (mp->ip6_set)
2567 clib_warning ("ip6 address %U", format_ip6_address,
2568 (ip6_address_t *) mp->ip6_address);
2569 }
2570 else
2571 clib_warning ("retval %d", retval);
2572 }
2573}
2574
2575static void vl_api_dns_resolve_name_reply_t_handler_json
2576 (vl_api_dns_resolve_name_reply_t * mp)
2577{
Dave Barachd2080152017-10-20 09:21:35 -04002578 clib_warning ("not implemented");
Dave Barach65457162017-10-10 17:53:14 -04002579}
Dave Barach59b25652017-09-10 15:04:27 -04002580
Dave Barachd2080152017-10-20 09:21:35 -04002581static void vl_api_dns_resolve_ip_reply_t_handler
2582 (vl_api_dns_resolve_ip_reply_t * mp)
2583{
2584 vat_main_t *vam = &vat_main;
2585 i32 retval = ntohl (mp->retval);
2586 if (vam->async_mode)
2587 {
2588 vam->async_errors += (retval < 0);
2589 }
2590 else
2591 {
2592 vam->retval = retval;
2593 vam->result_ready = 1;
2594
2595 if (retval == 0)
2596 {
2597 clib_warning ("canonical name %s", mp->name);
2598 }
2599 else
2600 clib_warning ("retval %d", retval);
2601 }
2602}
2603
2604static void vl_api_dns_resolve_ip_reply_t_handler_json
2605 (vl_api_dns_resolve_ip_reply_t * mp)
2606{
2607 clib_warning ("not implemented");
2608}
2609
2610
Damjan Marion7cd468a2016-12-19 23:05:39 +01002611static void vl_api_ip_address_details_t_handler
2612 (vl_api_ip_address_details_t * mp)
2613{
2614 vat_main_t *vam = &vat_main;
2615 static ip_address_details_t empty_ip_address_details = { {0} };
2616 ip_address_details_t *address = NULL;
2617 ip_details_t *current_ip_details = NULL;
2618 ip_details_t *details = NULL;
2619
2620 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2621
2622 if (!details || vam->current_sw_if_index >= vec_len (details)
2623 || !details[vam->current_sw_if_index].present)
2624 {
2625 errmsg ("ip address details arrived but not stored");
2626 errmsg ("ip_dump should be called first");
2627 return;
2628 }
2629
2630 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2631
2632#define addresses (current_ip_details->addr)
2633
2634 vec_validate_init_empty (addresses, vec_len (addresses),
2635 empty_ip_address_details);
2636
2637 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2638
2639 clib_memcpy (&address->ip, &mp->ip, sizeof (address->ip));
2640 address->prefix_length = mp->prefix_length;
2641#undef addresses
2642}
2643
2644static void vl_api_ip_address_details_t_handler_json
2645 (vl_api_ip_address_details_t * mp)
2646{
2647 vat_main_t *vam = &vat_main;
2648 vat_json_node_t *node = NULL;
2649 struct in6_addr ip6;
2650 struct in_addr ip4;
2651
2652 if (VAT_JSON_ARRAY != vam->json_tree.type)
2653 {
2654 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2655 vat_json_init_array (&vam->json_tree);
2656 }
2657 node = vat_json_array_add (&vam->json_tree);
2658
2659 vat_json_init_object (node);
2660 if (vam->is_ipv6)
2661 {
2662 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
2663 vat_json_object_add_ip6 (node, "ip", ip6);
2664 }
2665 else
2666 {
2667 clib_memcpy (&ip4, mp->ip, sizeof (ip4));
2668 vat_json_object_add_ip4 (node, "ip", ip4);
2669 }
2670 vat_json_object_add_uint (node, "prefix_length", mp->prefix_length);
2671}
2672
2673static void
2674vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2675{
2676 vat_main_t *vam = &vat_main;
2677 static ip_details_t empty_ip_details = { 0 };
2678 ip_details_t *ip = NULL;
2679 u32 sw_if_index = ~0;
2680
2681 sw_if_index = ntohl (mp->sw_if_index);
2682
2683 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2684 sw_if_index, empty_ip_details);
2685
2686 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2687 sw_if_index);
2688
2689 ip->present = 1;
2690}
2691
2692static void
2693vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2694{
2695 vat_main_t *vam = &vat_main;
2696
2697 if (VAT_JSON_ARRAY != vam->json_tree.type)
2698 {
2699 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2700 vat_json_init_array (&vam->json_tree);
2701 }
2702 vat_json_array_add_uint (&vam->json_tree,
2703 clib_net_to_host_u32 (mp->sw_if_index));
2704}
2705
Damjan Marion7cd468a2016-12-19 23:05:39 +01002706static void
2707vl_api_dhcp_compl_event_t_handler (vl_api_dhcp_compl_event_t * mp)
2708{
2709 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
2710 "router_addr %U host_mac %U",
Neale Rannsdaff1782018-05-16 04:12:18 -07002711 ntohl (mp->pid), mp->lease.is_ipv6 ? "ipv6" : "ipv4",
2712 mp->lease.hostname,
2713 format_ip4_address, &mp->lease.host_address,
2714 format_ip4_address, &mp->lease.router_address,
2715 format_ethernet_address, mp->lease.host_mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002716}
2717
2718static void vl_api_dhcp_compl_event_t_handler_json
2719 (vl_api_dhcp_compl_event_t * mp)
2720{
2721 /* JSON output not supported */
2722}
2723
Damjan Marion7cd468a2016-12-19 23:05:39 +01002724static void vl_api_get_first_msg_id_reply_t_handler
2725 (vl_api_get_first_msg_id_reply_t * mp)
2726{
2727 vat_main_t *vam = &vat_main;
2728 i32 retval = ntohl (mp->retval);
2729
2730 if (vam->async_mode)
2731 {
2732 vam->async_errors += (retval < 0);
2733 }
2734 else
2735 {
2736 vam->retval = retval;
2737 vam->result_ready = 1;
2738 }
2739 if (retval >= 0)
2740 {
2741 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2742 }
2743}
2744
2745static void vl_api_get_first_msg_id_reply_t_handler_json
2746 (vl_api_get_first_msg_id_reply_t * mp)
2747{
2748 vat_main_t *vam = &vat_main;
2749 vat_json_node_t node;
2750
2751 vat_json_init_object (&node);
2752 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2753 vat_json_object_add_uint (&node, "first_msg_id",
2754 (uint) ntohs (mp->first_msg_id));
2755
2756 vat_json_print (vam->ofp, &node);
2757 vat_json_free (&node);
2758
2759 vam->retval = ntohl (mp->retval);
2760 vam->result_ready = 1;
2761}
2762
2763static void vl_api_get_node_graph_reply_t_handler
2764 (vl_api_get_node_graph_reply_t * mp)
2765{
2766 vat_main_t *vam = &vat_main;
2767 api_main_t *am = &api_main;
2768 i32 retval = ntohl (mp->retval);
2769 u8 *pvt_copy, *reply;
2770 void *oldheap;
2771 vlib_node_t *node;
2772 int i;
2773
2774 if (vam->async_mode)
2775 {
2776 vam->async_errors += (retval < 0);
2777 }
2778 else
2779 {
2780 vam->retval = retval;
2781 vam->result_ready = 1;
2782 }
2783
2784 /* "Should never happen..." */
2785 if (retval != 0)
2786 return;
2787
Damjan Marion7bee80c2017-04-26 15:32:12 +02002788 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002789 pvt_copy = vec_dup (reply);
2790
2791 /* Toss the shared-memory original... */
2792 pthread_mutex_lock (&am->vlib_rp->mutex);
2793 oldheap = svm_push_data_heap (am->vlib_rp);
2794
2795 vec_free (reply);
2796
2797 svm_pop_heap (oldheap);
2798 pthread_mutex_unlock (&am->vlib_rp->mutex);
2799
2800 if (vam->graph_nodes)
2801 {
2802 hash_free (vam->graph_node_index_by_name);
2803
Dave Barach1ddbc012018-06-13 09:26:05 -04002804 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002805 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002806 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002807 vec_free (node->name);
2808 vec_free (node->next_nodes);
2809 vec_free (node);
2810 }
Dave Barach1ddbc012018-06-13 09:26:05 -04002811 vec_free (vam->graph_nodes[0]);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002812 vec_free (vam->graph_nodes);
2813 }
2814
2815 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2816 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2817 vec_free (pvt_copy);
2818
Dave Barach1ddbc012018-06-13 09:26:05 -04002819 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002820 {
Dave Barach1ddbc012018-06-13 09:26:05 -04002821 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +01002822 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2823 }
2824}
2825
2826static void vl_api_get_node_graph_reply_t_handler_json
2827 (vl_api_get_node_graph_reply_t * mp)
2828{
2829 vat_main_t *vam = &vat_main;
2830 api_main_t *am = &api_main;
2831 void *oldheap;
2832 vat_json_node_t node;
2833 u8 *reply;
2834
2835 /* $$$$ make this real? */
2836 vat_json_init_object (&node);
2837 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2838 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2839
Damjan Marion7bee80c2017-04-26 15:32:12 +02002840 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002841
2842 /* Toss the shared-memory original... */
2843 pthread_mutex_lock (&am->vlib_rp->mutex);
2844 oldheap = svm_push_data_heap (am->vlib_rp);
2845
2846 vec_free (reply);
2847
2848 svm_pop_heap (oldheap);
2849 pthread_mutex_unlock (&am->vlib_rp->mutex);
2850
2851 vat_json_print (vam->ofp, &node);
2852 vat_json_free (&node);
2853
2854 vam->retval = ntohl (mp->retval);
2855 vam->result_ready = 1;
2856}
2857
2858static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002859vl_api_one_locator_details_t_handler (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002860{
2861 vat_main_t *vam = &vat_main;
2862 u8 *s = 0;
2863
2864 if (mp->local)
2865 {
2866 s = format (s, "%=16d%=16d%=16d",
2867 ntohl (mp->sw_if_index), mp->priority, mp->weight);
2868 }
2869 else
2870 {
2871 s = format (s, "%=16U%=16d%=16d",
2872 mp->is_ipv6 ? format_ip6_address :
2873 format_ip4_address,
2874 mp->ip_address, mp->priority, mp->weight);
2875 }
2876
2877 print (vam->ofp, "%v", s);
2878 vec_free (s);
2879}
2880
2881static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002882vl_api_one_locator_details_t_handler_json (vl_api_one_locator_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002883{
2884 vat_main_t *vam = &vat_main;
2885 vat_json_node_t *node = NULL;
2886 struct in6_addr ip6;
2887 struct in_addr ip4;
2888
2889 if (VAT_JSON_ARRAY != vam->json_tree.type)
2890 {
2891 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2892 vat_json_init_array (&vam->json_tree);
2893 }
2894 node = vat_json_array_add (&vam->json_tree);
2895 vat_json_init_object (node);
2896
2897 vat_json_object_add_uint (node, "local", mp->local ? 1 : 0);
2898 vat_json_object_add_uint (node, "priority", mp->priority);
2899 vat_json_object_add_uint (node, "weight", mp->weight);
2900
2901 if (mp->local)
2902 vat_json_object_add_uint (node, "sw_if_index",
2903 clib_net_to_host_u32 (mp->sw_if_index));
2904 else
2905 {
2906 if (mp->is_ipv6)
2907 {
2908 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
2909 vat_json_object_add_ip6 (node, "address", ip6);
2910 }
2911 else
2912 {
2913 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
2914 vat_json_object_add_ip4 (node, "address", ip4);
2915 }
2916 }
2917}
2918
2919static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002920vl_api_one_locator_set_details_t_handler (vl_api_one_locator_set_details_t *
2921 mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002922{
2923 vat_main_t *vam = &vat_main;
2924 u8 *ls_name = 0;
2925
2926 ls_name = format (0, "%s", mp->ls_name);
2927
2928 print (vam->ofp, "%=10d%=15v", clib_net_to_host_u32 (mp->ls_index),
2929 ls_name);
2930 vec_free (ls_name);
2931}
2932
2933static void
Filip Tehlar694396d2017-02-17 14:29:11 +01002934 vl_api_one_locator_set_details_t_handler_json
2935 (vl_api_one_locator_set_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01002936{
2937 vat_main_t *vam = &vat_main;
2938 vat_json_node_t *node = 0;
2939 u8 *ls_name = 0;
2940
2941 ls_name = format (0, "%s", mp->ls_name);
2942 vec_add1 (ls_name, 0);
2943
2944 if (VAT_JSON_ARRAY != vam->json_tree.type)
2945 {
2946 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2947 vat_json_init_array (&vam->json_tree);
2948 }
2949 node = vat_json_array_add (&vam->json_tree);
2950
2951 vat_json_init_object (node);
2952 vat_json_object_add_string_copy (node, "ls_name", ls_name);
2953 vat_json_object_add_uint (node, "ls_index",
2954 clib_net_to_host_u32 (mp->ls_index));
2955 vec_free (ls_name);
2956}
2957
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002958typedef struct
2959{
2960 u32 spi;
2961 u8 si;
2962} __attribute__ ((__packed__)) lisp_nsh_api_t;
2963
2964uword
2965unformat_nsh_address (unformat_input_t * input, va_list * args)
2966{
2967 lisp_nsh_api_t *nsh = va_arg (*args, lisp_nsh_api_t *);
2968 return unformat (input, "SPI:%d SI:%d", &nsh->spi, &nsh->si);
2969}
2970
2971u8 *
2972format_nsh_address_vat (u8 * s, va_list * args)
2973{
2974 nsh_t *a = va_arg (*args, nsh_t *);
2975 return format (s, "SPI:%d SI:%d", clib_net_to_host_u32 (a->spi), a->si);
2976}
2977
Damjan Marion7cd468a2016-12-19 23:05:39 +01002978static u8 *
2979format_lisp_flat_eid (u8 * s, va_list * args)
2980{
2981 u32 type = va_arg (*args, u32);
2982 u8 *eid = va_arg (*args, u8 *);
2983 u32 eid_len = va_arg (*args, u32);
2984
2985 switch (type)
2986 {
2987 case 0:
2988 return format (s, "%U/%d", format_ip4_address, eid, eid_len);
2989 case 1:
2990 return format (s, "%U/%d", format_ip6_address, eid, eid_len);
2991 case 2:
2992 return format (s, "%U", format_ethernet_address, eid);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02002993 case 3:
2994 return format (s, "%U", format_nsh_address_vat, eid);
Damjan Marion7cd468a2016-12-19 23:05:39 +01002995 }
2996 return 0;
2997}
2998
2999static u8 *
3000format_lisp_eid_vat (u8 * s, va_list * args)
3001{
3002 u32 type = va_arg (*args, u32);
3003 u8 *eid = va_arg (*args, u8 *);
3004 u32 eid_len = va_arg (*args, u32);
3005 u8 *seid = va_arg (*args, u8 *);
3006 u32 seid_len = va_arg (*args, u32);
3007 u32 is_src_dst = va_arg (*args, u32);
3008
3009 if (is_src_dst)
3010 s = format (s, "%U|", format_lisp_flat_eid, type, seid, seid_len);
3011
3012 s = format (s, "%U", format_lisp_flat_eid, type, eid, eid_len);
3013
3014 return s;
3015}
3016
3017static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003018vl_api_one_eid_table_details_t_handler (vl_api_one_eid_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003019{
3020 vat_main_t *vam = &vat_main;
3021 u8 *s = 0, *eid = 0;
3022
3023 if (~0 == mp->locator_set_index)
3024 s = format (0, "action: %d", mp->action);
3025 else
3026 s = format (0, "%d", clib_net_to_host_u32 (mp->locator_set_index));
3027
3028 eid = format (0, "%U", format_lisp_eid_vat,
3029 mp->eid_type,
3030 mp->eid,
3031 mp->eid_prefix_len,
3032 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3033 vec_add1 (eid, 0);
3034
3035 print (vam->ofp, "[%d] %-35s%-20s%-30s%-20d%-20d%-10d%-20s",
3036 clib_net_to_host_u32 (mp->vni),
3037 eid,
3038 mp->is_local ? "local" : "remote",
3039 s, clib_net_to_host_u32 (mp->ttl), mp->authoritative,
3040 clib_net_to_host_u16 (mp->key_id), mp->key);
3041
3042 vec_free (s);
3043 vec_free (eid);
3044}
3045
3046static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003047vl_api_one_eid_table_details_t_handler_json (vl_api_one_eid_table_details_t
3048 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003049{
3050 vat_main_t *vam = &vat_main;
3051 vat_json_node_t *node = 0;
3052 u8 *eid = 0;
3053
3054 if (VAT_JSON_ARRAY != vam->json_tree.type)
3055 {
3056 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3057 vat_json_init_array (&vam->json_tree);
3058 }
3059 node = vat_json_array_add (&vam->json_tree);
3060
3061 vat_json_init_object (node);
3062 if (~0 == mp->locator_set_index)
3063 vat_json_object_add_uint (node, "action", mp->action);
3064 else
3065 vat_json_object_add_uint (node, "locator_set_index",
3066 clib_net_to_host_u32 (mp->locator_set_index));
3067
3068 vat_json_object_add_uint (node, "is_local", mp->is_local ? 1 : 0);
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02003069 if (mp->eid_type == 3)
3070 {
3071 vat_json_node_t *nsh_json = vat_json_object_add (node, "eid");
3072 vat_json_init_object (nsh_json);
3073 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) mp->eid;
3074 vat_json_object_add_uint (nsh_json, "spi",
3075 clib_net_to_host_u32 (nsh->spi));
3076 vat_json_object_add_uint (nsh_json, "si", nsh->si);
3077 }
3078 else
3079 {
3080 eid = format (0, "%U", format_lisp_eid_vat,
3081 mp->eid_type,
3082 mp->eid,
3083 mp->eid_prefix_len,
3084 mp->seid, mp->seid_prefix_len, mp->is_src_dst);
3085 vec_add1 (eid, 0);
3086 vat_json_object_add_string_copy (node, "eid", eid);
3087 vec_free (eid);
3088 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003089 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3090 vat_json_object_add_uint (node, "ttl", clib_net_to_host_u32 (mp->ttl));
3091 vat_json_object_add_uint (node, "authoritative", (mp->authoritative));
3092
3093 if (mp->key_id)
3094 {
3095 vat_json_object_add_uint (node, "key_id",
3096 clib_net_to_host_u16 (mp->key_id));
3097 vat_json_object_add_string_copy (node, "key", mp->key);
3098 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01003099}
3100
3101static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003102vl_api_one_stats_details_t_handler (vl_api_one_stats_details_t * mp)
3103{
3104 vat_main_t *vam = &vat_main;
3105 u8 *seid = 0, *deid = 0;
3106 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3107
3108 deid = format (0, "%U", format_lisp_eid_vat,
3109 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3110
3111 seid = format (0, "%U", format_lisp_eid_vat,
3112 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3113
3114 vec_add1 (deid, 0);
3115 vec_add1 (seid, 0);
3116
3117 if (mp->is_ip4)
3118 format_ip_address_fcn = format_ip4_address;
3119 else
3120 format_ip_address_fcn = format_ip6_address;
3121
3122
3123 print (vam->ofp, "([%d] %s %s) (%U %U) %u %u",
3124 clib_net_to_host_u32 (mp->vni),
3125 seid, deid,
3126 format_ip_address_fcn, mp->lloc,
3127 format_ip_address_fcn, mp->rloc,
3128 clib_net_to_host_u32 (mp->pkt_count),
3129 clib_net_to_host_u32 (mp->bytes));
3130
3131 vec_free (deid);
3132 vec_free (seid);
3133}
3134
3135static void
3136vl_api_one_stats_details_t_handler_json (vl_api_one_stats_details_t * mp)
3137{
3138 struct in6_addr ip6;
3139 struct in_addr ip4;
3140 vat_main_t *vam = &vat_main;
3141 vat_json_node_t *node = 0;
3142 u8 *deid = 0, *seid = 0;
3143
3144 if (VAT_JSON_ARRAY != vam->json_tree.type)
3145 {
3146 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3147 vat_json_init_array (&vam->json_tree);
3148 }
3149 node = vat_json_array_add (&vam->json_tree);
3150
3151 vat_json_init_object (node);
3152 deid = format (0, "%U", format_lisp_eid_vat,
3153 mp->eid_type, mp->deid, mp->deid_pref_len, 0, 0, 0);
3154
3155 seid = format (0, "%U", format_lisp_eid_vat,
3156 mp->eid_type, mp->seid, mp->seid_pref_len, 0, 0, 0);
3157
3158 vec_add1 (deid, 0);
3159 vec_add1 (seid, 0);
3160
3161 vat_json_object_add_string_copy (node, "seid", seid);
3162 vat_json_object_add_string_copy (node, "deid", deid);
3163 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3164
3165 if (mp->is_ip4)
3166 {
3167 clib_memcpy (&ip4, mp->lloc, sizeof (ip4));
3168 vat_json_object_add_ip4 (node, "lloc", ip4);
3169 clib_memcpy (&ip4, mp->rloc, sizeof (ip4));
3170 vat_json_object_add_ip4 (node, "rloc", ip4);
3171 }
3172 else
3173 {
3174 clib_memcpy (&ip6, mp->lloc, sizeof (ip6));
3175 vat_json_object_add_ip6 (node, "lloc", ip6);
3176 clib_memcpy (&ip6, mp->rloc, sizeof (ip6));
3177 vat_json_object_add_ip6 (node, "rloc", ip6);
3178 }
3179 vat_json_object_add_uint (node, "pkt_count",
3180 clib_net_to_host_u32 (mp->pkt_count));
3181 vat_json_object_add_uint (node, "bytes", clib_net_to_host_u32 (mp->bytes));
3182
3183 vec_free (deid);
3184 vec_free (seid);
3185}
3186
3187static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003188 vl_api_one_eid_table_map_details_t_handler
3189 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003190{
3191 vat_main_t *vam = &vat_main;
3192
3193 u8 *line = format (0, "%=10d%=10d",
3194 clib_net_to_host_u32 (mp->vni),
3195 clib_net_to_host_u32 (mp->dp_table));
3196 print (vam->ofp, "%v", line);
3197 vec_free (line);
3198}
3199
3200static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003201 vl_api_one_eid_table_map_details_t_handler_json
3202 (vl_api_one_eid_table_map_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003203{
3204 vat_main_t *vam = &vat_main;
3205 vat_json_node_t *node = NULL;
3206
3207 if (VAT_JSON_ARRAY != vam->json_tree.type)
3208 {
3209 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3210 vat_json_init_array (&vam->json_tree);
3211 }
3212 node = vat_json_array_add (&vam->json_tree);
3213 vat_json_init_object (node);
3214 vat_json_object_add_uint (node, "dp_table",
3215 clib_net_to_host_u32 (mp->dp_table));
3216 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3217}
3218
3219static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003220 vl_api_one_eid_table_vni_details_t_handler
3221 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003222{
3223 vat_main_t *vam = &vat_main;
3224
3225 u8 *line = format (0, "%d", clib_net_to_host_u32 (mp->vni));
3226 print (vam->ofp, "%v", line);
3227 vec_free (line);
3228}
3229
3230static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003231 vl_api_one_eid_table_vni_details_t_handler_json
3232 (vl_api_one_eid_table_vni_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003233{
3234 vat_main_t *vam = &vat_main;
3235 vat_json_node_t *node = NULL;
3236
3237 if (VAT_JSON_ARRAY != vam->json_tree.type)
3238 {
3239 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3240 vat_json_init_array (&vam->json_tree);
3241 }
3242 node = vat_json_array_add (&vam->json_tree);
3243 vat_json_init_object (node);
3244 vat_json_object_add_uint (node, "vni", clib_net_to_host_u32 (mp->vni));
3245}
3246
Damjan Marion7cd468a2016-12-19 23:05:39 +01003247static void
Filip Tehlar7048ff12017-07-27 08:09:14 +02003248 vl_api_show_one_map_register_fallback_threshold_reply_t_handler
3249 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3250{
3251 vat_main_t *vam = &vat_main;
3252 int retval = clib_net_to_host_u32 (mp->retval);
3253
3254 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3255 print (vam->ofp, "fallback threshold value: %d", mp->value);
3256
3257 vam->retval = retval;
3258 vam->result_ready = 1;
3259}
3260
3261static void
3262 vl_api_show_one_map_register_fallback_threshold_reply_t_handler_json
3263 (vl_api_show_one_map_register_fallback_threshold_reply_t * mp)
3264{
3265 vat_main_t *vam = &vat_main;
3266 vat_json_node_t _node, *node = &_node;
3267 int retval = clib_net_to_host_u32 (mp->retval);
3268
3269 vl_api_show_one_map_register_fallback_threshold_reply_t_endian (mp);
3270 vat_json_init_object (node);
3271 vat_json_object_add_uint (node, "value", mp->value);
3272
3273 vat_json_print (vam->ofp, node);
3274 vat_json_free (node);
3275
3276 vam->retval = retval;
3277 vam->result_ready = 1;
3278}
3279
3280static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003281 vl_api_show_one_map_register_state_reply_t_handler
3282 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003283{
3284 vat_main_t *vam = &vat_main;
3285 int retval = clib_net_to_host_u32 (mp->retval);
3286
3287 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3288
3289 vam->retval = retval;
3290 vam->result_ready = 1;
3291}
3292
3293static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003294 vl_api_show_one_map_register_state_reply_t_handler_json
3295 (vl_api_show_one_map_register_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003296{
3297 vat_main_t *vam = &vat_main;
3298 vat_json_node_t _node, *node = &_node;
3299 int retval = clib_net_to_host_u32 (mp->retval);
3300
3301 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3302
3303 vat_json_init_object (node);
3304 vat_json_object_add_string_copy (node, "state", s);
3305
3306 vat_json_print (vam->ofp, node);
3307 vat_json_free (node);
3308
3309 vam->retval = retval;
3310 vam->result_ready = 1;
3311 vec_free (s);
3312}
3313
3314static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003315 vl_api_show_one_rloc_probe_state_reply_t_handler
3316 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003317{
3318 vat_main_t *vam = &vat_main;
3319 int retval = clib_net_to_host_u32 (mp->retval);
3320
3321 if (retval)
3322 goto end;
3323
3324 print (vam->ofp, "%s", mp->is_enabled ? "enabled" : "disabled");
3325end:
3326 vam->retval = retval;
3327 vam->result_ready = 1;
3328}
3329
3330static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003331 vl_api_show_one_rloc_probe_state_reply_t_handler_json
3332 (vl_api_show_one_rloc_probe_state_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003333{
3334 vat_main_t *vam = &vat_main;
3335 vat_json_node_t _node, *node = &_node;
3336 int retval = clib_net_to_host_u32 (mp->retval);
3337
3338 u8 *s = format (0, "%s", mp->is_enabled ? "enabled" : "disabled");
3339 vat_json_init_object (node);
3340 vat_json_object_add_string_copy (node, "state", s);
3341
3342 vat_json_print (vam->ofp, node);
3343 vat_json_free (node);
3344
3345 vam->retval = retval;
3346 vam->result_ready = 1;
3347 vec_free (s);
3348}
3349
3350static void
Filip Tehlar4868ff62017-03-09 16:48:39 +01003351 vl_api_show_one_stats_enable_disable_reply_t_handler
3352 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3353{
3354 vat_main_t *vam = &vat_main;
3355 int retval = clib_net_to_host_u32 (mp->retval);
3356
3357 if (retval)
3358 goto end;
3359
3360 print (vam->ofp, "%s", mp->is_en ? "enabled" : "disabled");
3361end:
3362 vam->retval = retval;
3363 vam->result_ready = 1;
3364}
3365
3366static void
3367 vl_api_show_one_stats_enable_disable_reply_t_handler_json
3368 (vl_api_show_one_stats_enable_disable_reply_t * mp)
3369{
3370 vat_main_t *vam = &vat_main;
3371 vat_json_node_t _node, *node = &_node;
3372 int retval = clib_net_to_host_u32 (mp->retval);
3373
3374 u8 *s = format (0, "%s", mp->is_en ? "enabled" : "disabled");
3375 vat_json_init_object (node);
3376 vat_json_object_add_string_copy (node, "state", s);
3377
3378 vat_json_print (vam->ofp, node);
3379 vat_json_free (node);
3380
3381 vam->retval = retval;
3382 vam->result_ready = 1;
3383 vec_free (s);
3384}
3385
3386static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003387api_gpe_fwd_entry_net_to_host (vl_api_gpe_fwd_entry_t * e)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003388{
3389 e->dp_table = clib_net_to_host_u32 (e->dp_table);
3390 e->fwd_entry_index = clib_net_to_host_u32 (e->fwd_entry_index);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003391 e->vni = clib_net_to_host_u32 (e->vni);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003392}
3393
3394static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003395 gpe_fwd_entries_get_reply_t_net_to_host
3396 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003397{
3398 u32 i;
3399
3400 mp->count = clib_net_to_host_u32 (mp->count);
3401 for (i = 0; i < mp->count; i++)
3402 {
Filip Tehlar82786c42017-02-20 15:20:37 +01003403 api_gpe_fwd_entry_net_to_host (&mp->entries[i]);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003404 }
3405}
3406
Filip Tehlar3e7b56932017-02-21 18:28:34 +01003407static u8 *
3408format_gpe_encap_mode (u8 * s, va_list * args)
3409{
3410 u32 mode = va_arg (*args, u32);
3411
3412 switch (mode)
3413 {
3414 case 0:
3415 return format (s, "lisp");
3416 case 1:
3417 return format (s, "vxlan");
3418 }
3419 return 0;
3420}
3421
3422static void
3423 vl_api_gpe_get_encap_mode_reply_t_handler
3424 (vl_api_gpe_get_encap_mode_reply_t * mp)
3425{
3426 vat_main_t *vam = &vat_main;
3427
3428 print (vam->ofp, "gpe mode: %U", format_gpe_encap_mode, mp->encap_mode);
3429 vam->retval = ntohl (mp->retval);
3430 vam->result_ready = 1;
3431}
3432
3433static void
3434 vl_api_gpe_get_encap_mode_reply_t_handler_json
3435 (vl_api_gpe_get_encap_mode_reply_t * mp)
3436{
3437 vat_main_t *vam = &vat_main;
3438 vat_json_node_t node;
3439
3440 u8 *encap_mode = format (0, "%U", format_gpe_encap_mode, mp->encap_mode);
3441 vec_add1 (encap_mode, 0);
3442
3443 vat_json_init_object (&node);
3444 vat_json_object_add_string_copy (&node, "gpe_mode", encap_mode);
3445
3446 vec_free (encap_mode);
3447 vat_json_print (vam->ofp, &node);
3448 vat_json_free (&node);
3449
3450 vam->retval = ntohl (mp->retval);
3451 vam->result_ready = 1;
3452}
3453
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003454static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003455 vl_api_gpe_fwd_entry_path_details_t_handler
3456 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003457{
3458 vat_main_t *vam = &vat_main;
3459 u8 *(*format_ip_address_fcn) (u8 *, va_list *) = 0;
3460
3461 if (mp->lcl_loc.is_ip4)
3462 format_ip_address_fcn = format_ip4_address;
3463 else
3464 format_ip_address_fcn = format_ip6_address;
3465
3466 print (vam->ofp, "w:%d %30U %30U", mp->rmt_loc.weight,
3467 format_ip_address_fcn, &mp->lcl_loc,
3468 format_ip_address_fcn, &mp->rmt_loc);
3469}
3470
3471static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003472lisp_fill_locator_node (vat_json_node_t * n, vl_api_gpe_locator_t * loc)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003473{
3474 struct in6_addr ip6;
3475 struct in_addr ip4;
3476
3477 if (loc->is_ip4)
3478 {
3479 clib_memcpy (&ip4, loc->addr, sizeof (ip4));
3480 vat_json_object_add_ip4 (n, "address", ip4);
3481 }
3482 else
3483 {
3484 clib_memcpy (&ip6, loc->addr, sizeof (ip6));
3485 vat_json_object_add_ip6 (n, "address", ip6);
3486 }
3487 vat_json_object_add_uint (n, "weight", loc->weight);
3488}
3489
3490static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003491 vl_api_gpe_fwd_entry_path_details_t_handler_json
3492 (vl_api_gpe_fwd_entry_path_details_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003493{
3494 vat_main_t *vam = &vat_main;
3495 vat_json_node_t *node = NULL;
3496 vat_json_node_t *loc_node;
3497
3498 if (VAT_JSON_ARRAY != vam->json_tree.type)
3499 {
3500 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3501 vat_json_init_array (&vam->json_tree);
3502 }
3503 node = vat_json_array_add (&vam->json_tree);
3504 vat_json_init_object (node);
3505
3506 loc_node = vat_json_object_add (node, "local_locator");
3507 vat_json_init_object (loc_node);
3508 lisp_fill_locator_node (loc_node, &mp->lcl_loc);
3509
3510 loc_node = vat_json_object_add (node, "remote_locator");
3511 vat_json_init_object (loc_node);
3512 lisp_fill_locator_node (loc_node, &mp->rmt_loc);
3513}
3514
3515static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003516 vl_api_gpe_fwd_entries_get_reply_t_handler
3517 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003518{
3519 vat_main_t *vam = &vat_main;
3520 u32 i;
3521 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003522 vl_api_gpe_fwd_entry_t *e;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003523
3524 if (retval)
3525 goto end;
3526
Filip Tehlar82786c42017-02-20 15:20:37 +01003527 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003528
3529 for (i = 0; i < mp->count; i++)
3530 {
3531 e = &mp->entries[i];
3532 print (vam->ofp, "%10d %10d %U %40U", e->fwd_entry_index, e->dp_table,
3533 format_lisp_flat_eid, e->eid_type, e->leid, e->leid_prefix_len,
3534 format_lisp_flat_eid, e->eid_type, e->reid, e->reid_prefix_len);
3535 }
3536
3537end:
3538 vam->retval = retval;
3539 vam->result_ready = 1;
3540}
3541
3542static void
Filip Tehlar82786c42017-02-20 15:20:37 +01003543 vl_api_gpe_fwd_entries_get_reply_t_handler_json
3544 (vl_api_gpe_fwd_entries_get_reply_t * mp)
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003545{
3546 u8 *s = 0;
3547 vat_main_t *vam = &vat_main;
3548 vat_json_node_t *e = 0, root;
3549 u32 i;
3550 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar82786c42017-02-20 15:20:37 +01003551 vl_api_gpe_fwd_entry_t *fwd;
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003552
3553 if (retval)
3554 goto end;
3555
Filip Tehlar82786c42017-02-20 15:20:37 +01003556 gpe_fwd_entries_get_reply_t_net_to_host (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003557 vat_json_init_array (&root);
3558
3559 for (i = 0; i < mp->count; i++)
3560 {
3561 e = vat_json_array_add (&root);
3562 fwd = &mp->entries[i];
3563
3564 vat_json_init_object (e);
3565 vat_json_object_add_int (e, "fwd_entry_index", fwd->fwd_entry_index);
3566 vat_json_object_add_int (e, "dp_table", fwd->dp_table);
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003567 vat_json_object_add_int (e, "vni", fwd->vni);
3568 vat_json_object_add_int (e, "action", fwd->action);
Filip Tehlar5fae99c2017-01-18 12:57:37 +01003569
3570 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->leid,
3571 fwd->leid_prefix_len);
3572 vec_add1 (s, 0);
3573 vat_json_object_add_string_copy (e, "leid", s);
3574 vec_free (s);
3575
3576 s = format (0, "%U", format_lisp_flat_eid, fwd->eid_type, fwd->reid,
3577 fwd->reid_prefix_len);
3578 vec_add1 (s, 0);
3579 vat_json_object_add_string_copy (e, "reid", s);
3580 vec_free (s);
3581 }
3582
3583 vat_json_print (vam->ofp, &root);
3584 vat_json_free (&root);
3585
3586end:
3587 vam->retval = retval;
3588 vam->result_ready = 1;
3589}
3590
3591static void
Filip Tehlarb4243aa2017-06-14 14:39:42 +02003592 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler
3593 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3594{
3595 vat_main_t *vam = &vat_main;
3596 u32 i, n;
3597 int retval = clib_net_to_host_u32 (mp->retval);
3598 vl_api_gpe_native_fwd_rpath_t *r;
3599
3600 if (retval)
3601 goto end;
3602
3603 n = clib_net_to_host_u32 (mp->count);
3604
3605 for (i = 0; i < n; i++)
3606 {
3607 r = &mp->entries[i];
3608 print (vam->ofp, "fib_index: %d sw_if_index %d nh %U",
3609 clib_net_to_host_u32 (r->fib_index),
3610 clib_net_to_host_u32 (r->nh_sw_if_index),
3611 r->is_ip4 ? format_ip4_address : format_ip6_address, r->nh_addr);
3612 }
3613
3614end:
3615 vam->retval = retval;
3616 vam->result_ready = 1;
3617}
3618
3619static void
3620 vl_api_gpe_native_fwd_rpaths_get_reply_t_handler_json
3621 (vl_api_gpe_native_fwd_rpaths_get_reply_t * mp)
3622{
3623 vat_main_t *vam = &vat_main;
3624 vat_json_node_t root, *e;
3625 u32 i, n;
3626 int retval = clib_net_to_host_u32 (mp->retval);
3627 vl_api_gpe_native_fwd_rpath_t *r;
3628 u8 *s;
3629
3630 if (retval)
3631 goto end;
3632
3633 n = clib_net_to_host_u32 (mp->count);
3634 vat_json_init_array (&root);
3635
3636 for (i = 0; i < n; i++)
3637 {
3638 e = vat_json_array_add (&root);
3639 vat_json_init_object (e);
3640 r = &mp->entries[i];
3641 s =
3642 format (0, "%U", r->is_ip4 ? format_ip4_address : format_ip6_address,
3643 r->nh_addr);
3644 vec_add1 (s, 0);
3645 vat_json_object_add_string_copy (e, "ip4", s);
3646 vec_free (s);
3647
3648 vat_json_object_add_uint (e, "fib_index",
3649 clib_net_to_host_u32 (r->fib_index));
3650 vat_json_object_add_uint (e, "nh_sw_if_index",
3651 clib_net_to_host_u32 (r->nh_sw_if_index));
3652 }
3653
3654 vat_json_print (vam->ofp, &root);
3655 vat_json_free (&root);
3656
3657end:
3658 vam->retval = retval;
3659 vam->result_ready = 1;
3660}
3661
3662static void
Filip Tehlar0eb874e2017-05-18 14:23:32 +02003663 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler
3664 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3665{
3666 vat_main_t *vam = &vat_main;
3667 u32 i, n;
3668 int retval = clib_net_to_host_u32 (mp->retval);
3669
3670 if (retval)
3671 goto end;
3672
3673 n = clib_net_to_host_u32 (mp->count);
3674
3675 for (i = 0; i < n; i++)
3676 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->vnis[i]));
3677
3678end:
3679 vam->retval = retval;
3680 vam->result_ready = 1;
3681}
3682
3683static void
3684 vl_api_gpe_fwd_entry_vnis_get_reply_t_handler_json
3685 (vl_api_gpe_fwd_entry_vnis_get_reply_t * mp)
3686{
3687 vat_main_t *vam = &vat_main;
3688 vat_json_node_t root;
3689 u32 i, n;
3690 int retval = clib_net_to_host_u32 (mp->retval);
3691
3692 if (retval)
3693 goto end;
3694
3695 n = clib_net_to_host_u32 (mp->count);
3696 vat_json_init_array (&root);
3697
3698 for (i = 0; i < n; i++)
3699 vat_json_array_add_uint (&root, clib_net_to_host_u32 (mp->vnis[i]));
3700
3701 vat_json_print (vam->ofp, &root);
3702 vat_json_free (&root);
3703
3704end:
3705 vam->retval = retval;
3706 vam->result_ready = 1;
3707}
3708
3709static void
Filip Tehlar05879992017-09-05 15:46:09 +02003710 vl_api_one_ndp_entries_get_reply_t_handler
3711 (vl_api_one_ndp_entries_get_reply_t * mp)
3712{
3713 vat_main_t *vam = &vat_main;
3714 u32 i, n;
3715 int retval = clib_net_to_host_u32 (mp->retval);
3716
3717 if (retval)
3718 goto end;
3719
3720 n = clib_net_to_host_u32 (mp->count);
3721
3722 for (i = 0; i < n; i++)
3723 print (vam->ofp, "%U -> %U", format_ip6_address, &mp->entries[i].ip6,
3724 format_ethernet_address, mp->entries[i].mac);
3725
3726end:
3727 vam->retval = retval;
3728 vam->result_ready = 1;
3729}
3730
3731static void
3732 vl_api_one_ndp_entries_get_reply_t_handler_json
3733 (vl_api_one_ndp_entries_get_reply_t * mp)
3734{
3735 u8 *s = 0;
3736 vat_main_t *vam = &vat_main;
3737 vat_json_node_t *e = 0, root;
3738 u32 i, n;
3739 int retval = clib_net_to_host_u32 (mp->retval);
3740 vl_api_one_ndp_entry_t *arp_entry;
3741
3742 if (retval)
3743 goto end;
3744
3745 n = clib_net_to_host_u32 (mp->count);
3746 vat_json_init_array (&root);
3747
3748 for (i = 0; i < n; i++)
3749 {
3750 e = vat_json_array_add (&root);
3751 arp_entry = &mp->entries[i];
3752
3753 vat_json_init_object (e);
3754 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3755 vec_add1 (s, 0);
3756
3757 vat_json_object_add_string_copy (e, "mac", s);
3758 vec_free (s);
3759
3760 s = format (0, "%U", format_ip6_address, &arp_entry->ip6);
3761 vec_add1 (s, 0);
3762 vat_json_object_add_string_copy (e, "ip6", s);
3763 vec_free (s);
3764 }
3765
3766 vat_json_print (vam->ofp, &root);
3767 vat_json_free (&root);
3768
3769end:
3770 vam->retval = retval;
3771 vam->result_ready = 1;
3772}
3773
3774static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003775 vl_api_one_l2_arp_entries_get_reply_t_handler
3776 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3777{
3778 vat_main_t *vam = &vat_main;
3779 u32 i, n;
3780 int retval = clib_net_to_host_u32 (mp->retval);
3781
3782 if (retval)
3783 goto end;
3784
3785 n = clib_net_to_host_u32 (mp->count);
3786
3787 for (i = 0; i < n; i++)
3788 print (vam->ofp, "%U -> %U", format_ip4_address, &mp->entries[i].ip4,
3789 format_ethernet_address, mp->entries[i].mac);
3790
3791end:
3792 vam->retval = retval;
3793 vam->result_ready = 1;
3794}
3795
3796static void
3797 vl_api_one_l2_arp_entries_get_reply_t_handler_json
3798 (vl_api_one_l2_arp_entries_get_reply_t * mp)
3799{
3800 u8 *s = 0;
3801 vat_main_t *vam = &vat_main;
3802 vat_json_node_t *e = 0, root;
3803 u32 i, n;
3804 int retval = clib_net_to_host_u32 (mp->retval);
3805 vl_api_one_l2_arp_entry_t *arp_entry;
3806
3807 if (retval)
3808 goto end;
3809
3810 n = clib_net_to_host_u32 (mp->count);
3811 vat_json_init_array (&root);
3812
3813 for (i = 0; i < n; i++)
3814 {
3815 e = vat_json_array_add (&root);
3816 arp_entry = &mp->entries[i];
3817
3818 vat_json_init_object (e);
3819 s = format (0, "%U", format_ethernet_address, arp_entry->mac);
3820 vec_add1 (s, 0);
3821
3822 vat_json_object_add_string_copy (e, "mac", s);
3823 vec_free (s);
3824
3825 s = format (0, "%U", format_ip4_address, &arp_entry->ip4);
3826 vec_add1 (s, 0);
3827 vat_json_object_add_string_copy (e, "ip4", s);
3828 vec_free (s);
3829 }
3830
3831 vat_json_print (vam->ofp, &root);
3832 vat_json_free (&root);
3833
3834end:
3835 vam->retval = retval;
3836 vam->result_ready = 1;
3837}
3838
3839static void
Filip Tehlar05879992017-09-05 15:46:09 +02003840vl_api_one_ndp_bd_get_reply_t_handler (vl_api_one_ndp_bd_get_reply_t * mp)
3841{
3842 vat_main_t *vam = &vat_main;
3843 u32 i, n;
3844 int retval = clib_net_to_host_u32 (mp->retval);
3845
3846 if (retval)
3847 goto end;
3848
3849 n = clib_net_to_host_u32 (mp->count);
3850
3851 for (i = 0; i < n; i++)
3852 {
3853 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3854 }
3855
3856end:
3857 vam->retval = retval;
3858 vam->result_ready = 1;
3859}
3860
3861static void
3862 vl_api_one_ndp_bd_get_reply_t_handler_json
3863 (vl_api_one_ndp_bd_get_reply_t * mp)
3864{
3865 vat_main_t *vam = &vat_main;
3866 vat_json_node_t root;
3867 u32 i, n;
3868 int retval = clib_net_to_host_u32 (mp->retval);
3869
3870 if (retval)
3871 goto end;
3872
3873 n = clib_net_to_host_u32 (mp->count);
3874 vat_json_init_array (&root);
3875
3876 for (i = 0; i < n; i++)
3877 {
3878 vat_json_array_add_uint (&root,
3879 clib_net_to_host_u32 (mp->bridge_domains[i]));
3880 }
3881
3882 vat_json_print (vam->ofp, &root);
3883 vat_json_free (&root);
3884
3885end:
3886 vam->retval = retval;
3887 vam->result_ready = 1;
3888}
3889
3890static void
Filip Tehlard5a65db2017-05-17 17:21:10 +02003891 vl_api_one_l2_arp_bd_get_reply_t_handler
3892 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3893{
3894 vat_main_t *vam = &vat_main;
3895 u32 i, n;
3896 int retval = clib_net_to_host_u32 (mp->retval);
3897
3898 if (retval)
3899 goto end;
3900
3901 n = clib_net_to_host_u32 (mp->count);
3902
3903 for (i = 0; i < n; i++)
3904 {
3905 print (vam->ofp, "%d", clib_net_to_host_u32 (mp->bridge_domains[i]));
3906 }
3907
3908end:
3909 vam->retval = retval;
3910 vam->result_ready = 1;
3911}
3912
3913static void
3914 vl_api_one_l2_arp_bd_get_reply_t_handler_json
3915 (vl_api_one_l2_arp_bd_get_reply_t * mp)
3916{
3917 vat_main_t *vam = &vat_main;
3918 vat_json_node_t root;
3919 u32 i, n;
3920 int retval = clib_net_to_host_u32 (mp->retval);
3921
3922 if (retval)
3923 goto end;
3924
3925 n = clib_net_to_host_u32 (mp->count);
3926 vat_json_init_array (&root);
3927
3928 for (i = 0; i < n; i++)
3929 {
3930 vat_json_array_add_uint (&root,
3931 clib_net_to_host_u32 (mp->bridge_domains[i]));
3932 }
3933
3934 vat_json_print (vam->ofp, &root);
3935 vat_json_free (&root);
3936
3937end:
3938 vam->retval = retval;
3939 vam->result_ready = 1;
3940}
3941
3942static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003943 vl_api_one_adjacencies_get_reply_t_handler
3944 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003945{
3946 vat_main_t *vam = &vat_main;
3947 u32 i, n;
3948 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003949 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003950
3951 if (retval)
3952 goto end;
3953
3954 n = clib_net_to_host_u32 (mp->count);
3955
3956 for (i = 0; i < n; i++)
3957 {
3958 a = &mp->adjacencies[i];
3959 print (vam->ofp, "%U %40U",
3960 format_lisp_flat_eid, a->eid_type, a->leid, a->leid_prefix_len,
3961 format_lisp_flat_eid, a->eid_type, a->reid, a->reid_prefix_len);
3962 }
3963
3964end:
3965 vam->retval = retval;
3966 vam->result_ready = 1;
3967}
3968
3969static void
Filip Tehlar694396d2017-02-17 14:29:11 +01003970 vl_api_one_adjacencies_get_reply_t_handler_json
3971 (vl_api_one_adjacencies_get_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01003972{
3973 u8 *s = 0;
3974 vat_main_t *vam = &vat_main;
3975 vat_json_node_t *e = 0, root;
3976 u32 i, n;
3977 int retval = clib_net_to_host_u32 (mp->retval);
Filip Tehlar694396d2017-02-17 14:29:11 +01003978 vl_api_one_adjacency_t *a;
Damjan Marion7cd468a2016-12-19 23:05:39 +01003979
3980 if (retval)
3981 goto end;
3982
3983 n = clib_net_to_host_u32 (mp->count);
3984 vat_json_init_array (&root);
3985
3986 for (i = 0; i < n; i++)
3987 {
3988 e = vat_json_array_add (&root);
3989 a = &mp->adjacencies[i];
3990
3991 vat_json_init_object (e);
3992 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->leid,
3993 a->leid_prefix_len);
3994 vec_add1 (s, 0);
3995 vat_json_object_add_string_copy (e, "leid", s);
3996 vec_free (s);
3997
3998 s = format (0, "%U", format_lisp_flat_eid, a->eid_type, a->reid,
3999 a->reid_prefix_len);
4000 vec_add1 (s, 0);
4001 vat_json_object_add_string_copy (e, "reid", s);
4002 vec_free (s);
4003 }
4004
4005 vat_json_print (vam->ofp, &root);
4006 vat_json_free (&root);
4007
4008end:
4009 vam->retval = retval;
4010 vam->result_ready = 1;
4011}
4012
4013static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004014vl_api_one_map_server_details_t_handler (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004015{
4016 vat_main_t *vam = &vat_main;
4017
4018 print (vam->ofp, "%=20U",
4019 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
4020 mp->ip_address);
4021}
4022
4023static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004024 vl_api_one_map_server_details_t_handler_json
4025 (vl_api_one_map_server_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004026{
4027 vat_main_t *vam = &vat_main;
4028 vat_json_node_t *node = NULL;
4029 struct in6_addr ip6;
4030 struct in_addr ip4;
4031
4032 if (VAT_JSON_ARRAY != vam->json_tree.type)
4033 {
4034 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4035 vat_json_init_array (&vam->json_tree);
4036 }
4037 node = vat_json_array_add (&vam->json_tree);
4038
4039 vat_json_init_object (node);
4040 if (mp->is_ipv6)
4041 {
4042 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4043 vat_json_object_add_ip6 (node, "map-server", ip6);
4044 }
4045 else
4046 {
4047 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4048 vat_json_object_add_ip4 (node, "map-server", ip4);
4049 }
4050}
4051
4052static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004053vl_api_one_map_resolver_details_t_handler (vl_api_one_map_resolver_details_t
4054 * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004055{
4056 vat_main_t *vam = &vat_main;
4057
4058 print (vam->ofp, "%=20U",
4059 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
4060 mp->ip_address);
4061}
4062
4063static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004064 vl_api_one_map_resolver_details_t_handler_json
4065 (vl_api_one_map_resolver_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004066{
4067 vat_main_t *vam = &vat_main;
4068 vat_json_node_t *node = NULL;
4069 struct in6_addr ip6;
4070 struct in_addr ip4;
4071
4072 if (VAT_JSON_ARRAY != vam->json_tree.type)
4073 {
4074 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4075 vat_json_init_array (&vam->json_tree);
4076 }
4077 node = vat_json_array_add (&vam->json_tree);
4078
4079 vat_json_init_object (node);
4080 if (mp->is_ipv6)
4081 {
4082 clib_memcpy (&ip6, mp->ip_address, sizeof (ip6));
4083 vat_json_object_add_ip6 (node, "map resolver", ip6);
4084 }
4085 else
4086 {
4087 clib_memcpy (&ip4, mp->ip_address, sizeof (ip4));
4088 vat_json_object_add_ip4 (node, "map resolver", ip4);
4089 }
4090}
4091
4092static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004093vl_api_show_one_status_reply_t_handler (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004094{
4095 vat_main_t *vam = &vat_main;
4096 i32 retval = ntohl (mp->retval);
4097
4098 if (0 <= retval)
4099 {
4100 print (vam->ofp, "feature: %s\ngpe: %s",
4101 mp->feature_status ? "enabled" : "disabled",
4102 mp->gpe_status ? "enabled" : "disabled");
4103 }
4104
4105 vam->retval = retval;
4106 vam->result_ready = 1;
4107}
4108
4109static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004110 vl_api_show_one_status_reply_t_handler_json
4111 (vl_api_show_one_status_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004112{
4113 vat_main_t *vam = &vat_main;
4114 vat_json_node_t node;
4115 u8 *gpe_status = NULL;
4116 u8 *feature_status = NULL;
4117
4118 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
4119 feature_status = format (0, "%s",
4120 mp->feature_status ? "enabled" : "disabled");
4121 vec_add1 (gpe_status, 0);
4122 vec_add1 (feature_status, 0);
4123
4124 vat_json_init_object (&node);
4125 vat_json_object_add_string_copy (&node, "gpe_status", gpe_status);
4126 vat_json_object_add_string_copy (&node, "feature_status", feature_status);
4127
4128 vec_free (gpe_status);
4129 vec_free (feature_status);
4130
4131 vat_json_print (vam->ofp, &node);
4132 vat_json_free (&node);
4133
4134 vam->retval = ntohl (mp->retval);
4135 vam->result_ready = 1;
4136}
4137
4138static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004139 vl_api_one_get_map_request_itr_rlocs_reply_t_handler
4140 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004141{
4142 vat_main_t *vam = &vat_main;
4143 i32 retval = ntohl (mp->retval);
4144
4145 if (retval >= 0)
4146 {
4147 print (vam->ofp, "%=20s", mp->locator_set_name);
4148 }
4149
4150 vam->retval = retval;
4151 vam->result_ready = 1;
4152}
4153
4154static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004155 vl_api_one_get_map_request_itr_rlocs_reply_t_handler_json
4156 (vl_api_one_get_map_request_itr_rlocs_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004157{
4158 vat_main_t *vam = &vat_main;
4159 vat_json_node_t *node = NULL;
4160
4161 if (VAT_JSON_ARRAY != vam->json_tree.type)
4162 {
4163 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4164 vat_json_init_array (&vam->json_tree);
4165 }
4166 node = vat_json_array_add (&vam->json_tree);
4167
4168 vat_json_init_object (node);
4169 vat_json_object_add_string_copy (node, "itr-rlocs", mp->locator_set_name);
4170
4171 vat_json_print (vam->ofp, node);
4172 vat_json_free (node);
4173
4174 vam->retval = ntohl (mp->retval);
4175 vam->result_ready = 1;
4176}
4177
4178static u8 *
4179format_lisp_map_request_mode (u8 * s, va_list * args)
4180{
4181 u32 mode = va_arg (*args, u32);
4182
4183 switch (mode)
4184 {
4185 case 0:
4186 return format (0, "dst-only");
4187 case 1:
4188 return format (0, "src-dst");
4189 }
4190 return 0;
4191}
4192
4193static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004194 vl_api_show_one_map_request_mode_reply_t_handler
4195 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004196{
4197 vat_main_t *vam = &vat_main;
4198 i32 retval = ntohl (mp->retval);
4199
4200 if (0 <= retval)
4201 {
4202 u32 mode = mp->mode;
4203 print (vam->ofp, "map_request_mode: %U",
4204 format_lisp_map_request_mode, mode);
4205 }
4206
4207 vam->retval = retval;
4208 vam->result_ready = 1;
4209}
4210
4211static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004212 vl_api_show_one_map_request_mode_reply_t_handler_json
4213 (vl_api_show_one_map_request_mode_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004214{
4215 vat_main_t *vam = &vat_main;
4216 vat_json_node_t node;
4217 u8 *s = 0;
4218 u32 mode;
4219
4220 mode = mp->mode;
4221 s = format (0, "%U", format_lisp_map_request_mode, mode);
4222 vec_add1 (s, 0);
4223
4224 vat_json_init_object (&node);
4225 vat_json_object_add_string_copy (&node, "map_request_mode", s);
4226 vat_json_print (vam->ofp, &node);
4227 vat_json_free (&node);
4228
4229 vec_free (s);
4230 vam->retval = ntohl (mp->retval);
4231 vam->result_ready = 1;
4232}
4233
4234static void
Filip Tehlar0a8840d2017-10-16 05:48:23 -07004235 vl_api_one_show_xtr_mode_reply_t_handler
4236 (vl_api_one_show_xtr_mode_reply_t * mp)
4237{
4238 vat_main_t *vam = &vat_main;
4239 i32 retval = ntohl (mp->retval);
4240
4241 if (0 <= retval)
4242 {
4243 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4244 }
4245
4246 vam->retval = retval;
4247 vam->result_ready = 1;
4248}
4249
4250static void
4251 vl_api_one_show_xtr_mode_reply_t_handler_json
4252 (vl_api_one_show_xtr_mode_reply_t * mp)
4253{
4254 vat_main_t *vam = &vat_main;
4255 vat_json_node_t node;
4256 u8 *status = 0;
4257
4258 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4259 vec_add1 (status, 0);
4260
4261 vat_json_init_object (&node);
4262 vat_json_object_add_string_copy (&node, "status", status);
4263
4264 vec_free (status);
4265
4266 vat_json_print (vam->ofp, &node);
4267 vat_json_free (&node);
4268
4269 vam->retval = ntohl (mp->retval);
4270 vam->result_ready = 1;
4271}
4272
4273static void
4274 vl_api_one_show_pitr_mode_reply_t_handler
4275 (vl_api_one_show_pitr_mode_reply_t * mp)
4276{
4277 vat_main_t *vam = &vat_main;
4278 i32 retval = ntohl (mp->retval);
4279
4280 if (0 <= retval)
4281 {
4282 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4283 }
4284
4285 vam->retval = retval;
4286 vam->result_ready = 1;
4287}
4288
4289static void
4290 vl_api_one_show_pitr_mode_reply_t_handler_json
4291 (vl_api_one_show_pitr_mode_reply_t * mp)
4292{
4293 vat_main_t *vam = &vat_main;
4294 vat_json_node_t node;
4295 u8 *status = 0;
4296
4297 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4298 vec_add1 (status, 0);
4299
4300 vat_json_init_object (&node);
4301 vat_json_object_add_string_copy (&node, "status", status);
4302
4303 vec_free (status);
4304
4305 vat_json_print (vam->ofp, &node);
4306 vat_json_free (&node);
4307
4308 vam->retval = ntohl (mp->retval);
4309 vam->result_ready = 1;
4310}
4311
4312static void
4313 vl_api_one_show_petr_mode_reply_t_handler
4314 (vl_api_one_show_petr_mode_reply_t * mp)
4315{
4316 vat_main_t *vam = &vat_main;
4317 i32 retval = ntohl (mp->retval);
4318
4319 if (0 <= retval)
4320 {
4321 print (vam->ofp, "%s\n", mp->is_en ? "enabled" : "disabled");
4322 }
4323
4324 vam->retval = retval;
4325 vam->result_ready = 1;
4326}
4327
4328static void
4329 vl_api_one_show_petr_mode_reply_t_handler_json
4330 (vl_api_one_show_petr_mode_reply_t * mp)
4331{
4332 vat_main_t *vam = &vat_main;
4333 vat_json_node_t node;
4334 u8 *status = 0;
4335
4336 status = format (0, "%s", mp->is_en ? "enabled" : "disabled");
4337 vec_add1 (status, 0);
4338
4339 vat_json_init_object (&node);
4340 vat_json_object_add_string_copy (&node, "status", status);
4341
4342 vec_free (status);
4343
4344 vat_json_print (vam->ofp, &node);
4345 vat_json_free (&node);
4346
4347 vam->retval = ntohl (mp->retval);
4348 vam->result_ready = 1;
4349}
4350
4351static void
Filip Tehlar67a99f82017-03-10 13:18:02 +01004352 vl_api_show_one_use_petr_reply_t_handler
4353 (vl_api_show_one_use_petr_reply_t * mp)
4354{
4355 vat_main_t *vam = &vat_main;
4356 i32 retval = ntohl (mp->retval);
4357
4358 if (0 <= retval)
4359 {
4360 print (vam->ofp, "%s\n", mp->status ? "enabled" : "disabled");
4361 if (mp->status)
4362 {
4363 print (vam->ofp, "Proxy-ETR address; %U",
4364 mp->is_ip4 ? format_ip4_address : format_ip6_address,
4365 mp->address);
4366 }
4367 }
4368
4369 vam->retval = retval;
4370 vam->result_ready = 1;
4371}
4372
4373static void
4374 vl_api_show_one_use_petr_reply_t_handler_json
4375 (vl_api_show_one_use_petr_reply_t * mp)
4376{
4377 vat_main_t *vam = &vat_main;
4378 vat_json_node_t node;
4379 u8 *status = 0;
4380 struct in_addr ip4;
4381 struct in6_addr ip6;
4382
4383 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4384 vec_add1 (status, 0);
4385
4386 vat_json_init_object (&node);
4387 vat_json_object_add_string_copy (&node, "status", status);
4388 if (mp->status)
4389 {
4390 if (mp->is_ip4)
4391 {
4392 clib_memcpy (&ip6, mp->address, sizeof (ip6));
4393 vat_json_object_add_ip6 (&node, "address", ip6);
4394 }
4395 else
4396 {
4397 clib_memcpy (&ip4, mp->address, sizeof (ip4));
4398 vat_json_object_add_ip4 (&node, "address", ip4);
4399 }
4400 }
4401
4402 vec_free (status);
4403
4404 vat_json_print (vam->ofp, &node);
4405 vat_json_free (&node);
4406
4407 vam->retval = ntohl (mp->retval);
4408 vam->result_ready = 1;
4409}
4410
4411static void
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02004412 vl_api_show_one_nsh_mapping_reply_t_handler
4413 (vl_api_show_one_nsh_mapping_reply_t * mp)
4414{
4415 vat_main_t *vam = &vat_main;
4416 i32 retval = ntohl (mp->retval);
4417
4418 if (0 <= retval)
4419 {
4420 print (vam->ofp, "%-20s%-16s",
4421 mp->is_set ? "set" : "not-set",
4422 mp->is_set ? (char *) mp->locator_set_name : "");
4423 }
4424
4425 vam->retval = retval;
4426 vam->result_ready = 1;
4427}
4428
4429static void
4430 vl_api_show_one_nsh_mapping_reply_t_handler_json
4431 (vl_api_show_one_nsh_mapping_reply_t * mp)
4432{
4433 vat_main_t *vam = &vat_main;
4434 vat_json_node_t node;
4435 u8 *status = 0;
4436
4437 status = format (0, "%s", mp->is_set ? "yes" : "no");
4438 vec_add1 (status, 0);
4439
4440 vat_json_init_object (&node);
4441 vat_json_object_add_string_copy (&node, "is_set", status);
4442 if (mp->is_set)
4443 {
4444 vat_json_object_add_string_copy (&node, "locator_set",
4445 mp->locator_set_name);
4446 }
4447
4448 vec_free (status);
4449
4450 vat_json_print (vam->ofp, &node);
4451 vat_json_free (&node);
4452
4453 vam->retval = ntohl (mp->retval);
4454 vam->result_ready = 1;
4455}
4456
4457static void
Filip Tehlar1e553a02017-08-02 12:45:07 +02004458 vl_api_show_one_map_register_ttl_reply_t_handler
4459 (vl_api_show_one_map_register_ttl_reply_t * mp)
4460{
4461 vat_main_t *vam = &vat_main;
4462 i32 retval = ntohl (mp->retval);
4463
4464 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4465
4466 if (0 <= retval)
4467 {
4468 print (vam->ofp, "ttl: %u", mp->ttl);
4469 }
4470
4471 vam->retval = retval;
4472 vam->result_ready = 1;
4473}
4474
4475static void
4476 vl_api_show_one_map_register_ttl_reply_t_handler_json
4477 (vl_api_show_one_map_register_ttl_reply_t * mp)
4478{
4479 vat_main_t *vam = &vat_main;
4480 vat_json_node_t node;
4481
4482 vl_api_show_one_map_register_ttl_reply_t_endian (mp);
4483 vat_json_init_object (&node);
4484 vat_json_object_add_uint (&node, "ttl", mp->ttl);
4485
4486 vat_json_print (vam->ofp, &node);
4487 vat_json_free (&node);
4488
4489 vam->retval = ntohl (mp->retval);
4490 vam->result_ready = 1;
4491}
4492
4493static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004494vl_api_show_one_pitr_reply_t_handler (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004495{
4496 vat_main_t *vam = &vat_main;
4497 i32 retval = ntohl (mp->retval);
4498
4499 if (0 <= retval)
4500 {
4501 print (vam->ofp, "%-20s%-16s",
4502 mp->status ? "enabled" : "disabled",
4503 mp->status ? (char *) mp->locator_set_name : "");
4504 }
4505
4506 vam->retval = retval;
4507 vam->result_ready = 1;
4508}
4509
4510static void
Filip Tehlar694396d2017-02-17 14:29:11 +01004511vl_api_show_one_pitr_reply_t_handler_json (vl_api_show_one_pitr_reply_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01004512{
4513 vat_main_t *vam = &vat_main;
4514 vat_json_node_t node;
4515 u8 *status = 0;
4516
4517 status = format (0, "%s", mp->status ? "enabled" : "disabled");
4518 vec_add1 (status, 0);
4519
4520 vat_json_init_object (&node);
4521 vat_json_object_add_string_copy (&node, "status", status);
4522 if (mp->status)
4523 {
4524 vat_json_object_add_string_copy (&node, "locator_set",
4525 mp->locator_set_name);
4526 }
4527
4528 vec_free (status);
4529
4530 vat_json_print (vam->ofp, &node);
4531 vat_json_free (&node);
4532
4533 vam->retval = ntohl (mp->retval);
4534 vam->result_ready = 1;
4535}
4536
4537static u8 *
4538format_policer_type (u8 * s, va_list * va)
4539{
4540 u32 i = va_arg (*va, u32);
4541
4542 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
4543 s = format (s, "1r2c");
4544 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
4545 s = format (s, "1r3c");
4546 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
4547 s = format (s, "2r3c-2698");
4548 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
4549 s = format (s, "2r3c-4115");
4550 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
4551 s = format (s, "2r3c-mef5cf1");
4552 else
4553 s = format (s, "ILLEGAL");
4554 return s;
4555}
4556
4557static u8 *
4558format_policer_rate_type (u8 * s, va_list * va)
4559{
4560 u32 i = va_arg (*va, u32);
4561
4562 if (i == SSE2_QOS_RATE_KBPS)
4563 s = format (s, "kbps");
4564 else if (i == SSE2_QOS_RATE_PPS)
4565 s = format (s, "pps");
4566 else
4567 s = format (s, "ILLEGAL");
4568 return s;
4569}
4570
4571static u8 *
4572format_policer_round_type (u8 * s, va_list * va)
4573{
4574 u32 i = va_arg (*va, u32);
4575
4576 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
4577 s = format (s, "closest");
4578 else if (i == SSE2_QOS_ROUND_TO_UP)
4579 s = format (s, "up");
4580 else if (i == SSE2_QOS_ROUND_TO_DOWN)
4581 s = format (s, "down");
4582 else
4583 s = format (s, "ILLEGAL");
4584 return s;
4585}
4586
4587static u8 *
4588format_policer_action_type (u8 * s, va_list * va)
4589{
4590 u32 i = va_arg (*va, u32);
4591
4592 if (i == SSE2_QOS_ACTION_DROP)
4593 s = format (s, "drop");
4594 else if (i == SSE2_QOS_ACTION_TRANSMIT)
4595 s = format (s, "transmit");
4596 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4597 s = format (s, "mark-and-transmit");
4598 else
4599 s = format (s, "ILLEGAL");
4600 return s;
4601}
4602
4603static u8 *
4604format_dscp (u8 * s, va_list * va)
4605{
4606 u32 i = va_arg (*va, u32);
4607 char *t = 0;
4608
4609 switch (i)
4610 {
4611#define _(v,f,str) case VNET_DSCP_##f: t = str; break;
4612 foreach_vnet_dscp
4613#undef _
4614 default:
4615 return format (s, "ILLEGAL");
4616 }
4617 s = format (s, "%s", t);
4618 return s;
4619}
4620
4621static void
4622vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
4623{
4624 vat_main_t *vam = &vat_main;
4625 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
4626
4627 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4628 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4629 else
4630 conform_dscp_str = format (0, "");
4631
4632 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4633 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4634 else
4635 exceed_dscp_str = format (0, "");
4636
4637 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4638 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4639 else
4640 violate_dscp_str = format (0, "");
4641
4642 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
4643 "rate type %U, round type %U, %s rate, %s color-aware, "
4644 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
4645 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
4646 "conform action %U%s, exceed action %U%s, violate action %U%s",
4647 mp->name,
4648 format_policer_type, mp->type,
4649 ntohl (mp->cir),
4650 ntohl (mp->eir),
4651 clib_net_to_host_u64 (mp->cb),
4652 clib_net_to_host_u64 (mp->eb),
4653 format_policer_rate_type, mp->rate_type,
4654 format_policer_round_type, mp->round_type,
4655 mp->single_rate ? "single" : "dual",
4656 mp->color_aware ? "is" : "not",
4657 ntohl (mp->cir_tokens_per_period),
4658 ntohl (mp->pir_tokens_per_period),
4659 ntohl (mp->scale),
4660 ntohl (mp->current_limit),
4661 ntohl (mp->current_bucket),
4662 ntohl (mp->extended_limit),
4663 ntohl (mp->extended_bucket),
4664 clib_net_to_host_u64 (mp->last_update_time),
4665 format_policer_action_type, mp->conform_action_type,
4666 conform_dscp_str,
4667 format_policer_action_type, mp->exceed_action_type,
4668 exceed_dscp_str,
4669 format_policer_action_type, mp->violate_action_type,
4670 violate_dscp_str);
4671
4672 vec_free (conform_dscp_str);
4673 vec_free (exceed_dscp_str);
4674 vec_free (violate_dscp_str);
4675}
4676
4677static void vl_api_policer_details_t_handler_json
4678 (vl_api_policer_details_t * mp)
4679{
4680 vat_main_t *vam = &vat_main;
4681 vat_json_node_t *node;
4682 u8 *rate_type_str, *round_type_str, *type_str;
4683 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
4684
4685 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
4686 round_type_str =
4687 format (0, "%U", format_policer_round_type, mp->round_type);
4688 type_str = format (0, "%U", format_policer_type, mp->type);
4689 conform_action_str = format (0, "%U", format_policer_action_type,
4690 mp->conform_action_type);
4691 exceed_action_str = format (0, "%U", format_policer_action_type,
4692 mp->exceed_action_type);
4693 violate_action_str = format (0, "%U", format_policer_action_type,
4694 mp->violate_action_type);
4695
4696 if (VAT_JSON_ARRAY != vam->json_tree.type)
4697 {
4698 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4699 vat_json_init_array (&vam->json_tree);
4700 }
4701 node = vat_json_array_add (&vam->json_tree);
4702
4703 vat_json_init_object (node);
4704 vat_json_object_add_string_copy (node, "name", mp->name);
4705 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
4706 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
Marek Gradzki59ed4902017-03-21 11:51:54 +01004707 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
4708 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
Damjan Marion7cd468a2016-12-19 23:05:39 +01004709 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
4710 vat_json_object_add_string_copy (node, "round_type", round_type_str);
4711 vat_json_object_add_string_copy (node, "type", type_str);
4712 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
4713 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
4714 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
4715 vat_json_object_add_uint (node, "cir_tokens_per_period",
4716 ntohl (mp->cir_tokens_per_period));
4717 vat_json_object_add_uint (node, "eir_tokens_per_period",
4718 ntohl (mp->pir_tokens_per_period));
4719 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
4720 vat_json_object_add_uint (node, "current_bucket",
4721 ntohl (mp->current_bucket));
4722 vat_json_object_add_uint (node, "extended_limit",
4723 ntohl (mp->extended_limit));
4724 vat_json_object_add_uint (node, "extended_bucket",
4725 ntohl (mp->extended_bucket));
4726 vat_json_object_add_uint (node, "last_update_time",
4727 ntohl (mp->last_update_time));
4728 vat_json_object_add_string_copy (node, "conform_action",
4729 conform_action_str);
4730 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4731 {
4732 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_dscp);
4733 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
4734 vec_free (dscp_str);
4735 }
4736 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
4737 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4738 {
4739 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_dscp);
4740 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
4741 vec_free (dscp_str);
4742 }
4743 vat_json_object_add_string_copy (node, "violate_action",
4744 violate_action_str);
4745 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
4746 {
4747 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_dscp);
4748 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
4749 vec_free (dscp_str);
4750 }
4751
4752 vec_free (rate_type_str);
4753 vec_free (round_type_str);
4754 vec_free (type_str);
4755 vec_free (conform_action_str);
4756 vec_free (exceed_action_str);
4757 vec_free (violate_action_str);
4758}
4759
4760static void
4761vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
4762 mp)
4763{
4764 vat_main_t *vam = &vat_main;
4765 int i, count = ntohl (mp->count);
4766
4767 if (count > 0)
4768 print (vam->ofp, "classify table ids (%d) : ", count);
4769 for (i = 0; i < count; i++)
4770 {
4771 print (vam->ofp, "%d", ntohl (mp->ids[i]));
4772 print (vam->ofp, (i < count - 1) ? "," : "");
4773 }
4774 vam->retval = ntohl (mp->retval);
4775 vam->result_ready = 1;
4776}
4777
4778static void
4779 vl_api_classify_table_ids_reply_t_handler_json
4780 (vl_api_classify_table_ids_reply_t * mp)
4781{
4782 vat_main_t *vam = &vat_main;
4783 int i, count = ntohl (mp->count);
4784
4785 if (count > 0)
4786 {
4787 vat_json_node_t node;
4788
4789 vat_json_init_object (&node);
4790 for (i = 0; i < count; i++)
4791 {
4792 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
4793 }
4794 vat_json_print (vam->ofp, &node);
4795 vat_json_free (&node);
4796 }
4797 vam->retval = ntohl (mp->retval);
4798 vam->result_ready = 1;
4799}
4800
4801static void
4802 vl_api_classify_table_by_interface_reply_t_handler
4803 (vl_api_classify_table_by_interface_reply_t * mp)
4804{
4805 vat_main_t *vam = &vat_main;
4806 u32 table_id;
4807
4808 table_id = ntohl (mp->l2_table_id);
4809 if (table_id != ~0)
4810 print (vam->ofp, "l2 table id : %d", table_id);
4811 else
4812 print (vam->ofp, "l2 table id : No input ACL tables configured");
4813 table_id = ntohl (mp->ip4_table_id);
4814 if (table_id != ~0)
4815 print (vam->ofp, "ip4 table id : %d", table_id);
4816 else
4817 print (vam->ofp, "ip4 table id : No input ACL tables configured");
4818 table_id = ntohl (mp->ip6_table_id);
4819 if (table_id != ~0)
4820 print (vam->ofp, "ip6 table id : %d", table_id);
4821 else
4822 print (vam->ofp, "ip6 table id : No input ACL tables configured");
4823 vam->retval = ntohl (mp->retval);
4824 vam->result_ready = 1;
4825}
4826
4827static void
4828 vl_api_classify_table_by_interface_reply_t_handler_json
4829 (vl_api_classify_table_by_interface_reply_t * mp)
4830{
4831 vat_main_t *vam = &vat_main;
4832 vat_json_node_t node;
4833
4834 vat_json_init_object (&node);
4835
4836 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
4837 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
4838 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
4839
4840 vat_json_print (vam->ofp, &node);
4841 vat_json_free (&node);
4842
4843 vam->retval = ntohl (mp->retval);
4844 vam->result_ready = 1;
4845}
4846
4847static void vl_api_policer_add_del_reply_t_handler
4848 (vl_api_policer_add_del_reply_t * mp)
4849{
4850 vat_main_t *vam = &vat_main;
4851 i32 retval = ntohl (mp->retval);
4852 if (vam->async_mode)
4853 {
4854 vam->async_errors += (retval < 0);
4855 }
4856 else
4857 {
4858 vam->retval = retval;
4859 vam->result_ready = 1;
4860 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
4861 /*
4862 * Note: this is just barely thread-safe, depends on
4863 * the main thread spinning waiting for an answer...
4864 */
4865 errmsg ("policer index %d", ntohl (mp->policer_index));
4866 }
4867}
4868
4869static void vl_api_policer_add_del_reply_t_handler_json
4870 (vl_api_policer_add_del_reply_t * mp)
4871{
4872 vat_main_t *vam = &vat_main;
4873 vat_json_node_t node;
4874
4875 vat_json_init_object (&node);
4876 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4877 vat_json_object_add_uint (&node, "policer_index",
4878 ntohl (mp->policer_index));
4879
4880 vat_json_print (vam->ofp, &node);
4881 vat_json_free (&node);
4882
4883 vam->retval = ntohl (mp->retval);
4884 vam->result_ready = 1;
4885}
4886
4887/* Format hex dump. */
4888u8 *
4889format_hex_bytes (u8 * s, va_list * va)
4890{
4891 u8 *bytes = va_arg (*va, u8 *);
4892 int n_bytes = va_arg (*va, int);
4893 uword i;
4894
4895 /* Print short or long form depending on byte count. */
4896 uword short_form = n_bytes <= 32;
Christophe Fontained3c008d2017-10-02 18:10:54 +02004897 u32 indent = format_get_indent (s);
Damjan Marion7cd468a2016-12-19 23:05:39 +01004898
4899 if (n_bytes == 0)
4900 return s;
4901
4902 for (i = 0; i < n_bytes; i++)
4903 {
4904 if (!short_form && (i % 32) == 0)
4905 s = format (s, "%08x: ", i);
4906 s = format (s, "%02x", bytes[i]);
4907 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
4908 s = format (s, "\n%U", format_white_space, indent);
4909 }
4910
4911 return s;
4912}
4913
4914static void
4915vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
4916 * mp)
4917{
4918 vat_main_t *vam = &vat_main;
4919 i32 retval = ntohl (mp->retval);
4920 if (retval == 0)
4921 {
4922 print (vam->ofp, "classify table info :");
4923 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
4924 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
4925 ntohl (mp->miss_next_index));
4926 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
4927 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
4928 ntohl (mp->match_n_vectors));
4929 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
4930 ntohl (mp->mask_length));
4931 }
4932 vam->retval = retval;
4933 vam->result_ready = 1;
4934}
4935
4936static void
4937 vl_api_classify_table_info_reply_t_handler_json
4938 (vl_api_classify_table_info_reply_t * mp)
4939{
4940 vat_main_t *vam = &vat_main;
4941 vat_json_node_t node;
4942
4943 i32 retval = ntohl (mp->retval);
4944 if (retval == 0)
4945 {
4946 vat_json_init_object (&node);
4947
4948 vat_json_object_add_int (&node, "sessions",
4949 ntohl (mp->active_sessions));
4950 vat_json_object_add_int (&node, "nexttbl",
4951 ntohl (mp->next_table_index));
4952 vat_json_object_add_int (&node, "nextnode",
4953 ntohl (mp->miss_next_index));
4954 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
4955 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
4956 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
4957 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
4958 ntohl (mp->mask_length), 0);
4959 vat_json_object_add_string_copy (&node, "mask", s);
4960
4961 vat_json_print (vam->ofp, &node);
4962 vat_json_free (&node);
4963 }
4964 vam->retval = ntohl (mp->retval);
4965 vam->result_ready = 1;
4966}
4967
4968static void
4969vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
4970 mp)
4971{
4972 vat_main_t *vam = &vat_main;
4973
4974 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
4975 ntohl (mp->hit_next_index), ntohl (mp->advance),
4976 ntohl (mp->opaque_index));
4977 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
4978 ntohl (mp->match_length));
4979}
4980
4981static void
4982 vl_api_classify_session_details_t_handler_json
4983 (vl_api_classify_session_details_t * mp)
4984{
4985 vat_main_t *vam = &vat_main;
4986 vat_json_node_t *node = NULL;
4987
4988 if (VAT_JSON_ARRAY != vam->json_tree.type)
4989 {
4990 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4991 vat_json_init_array (&vam->json_tree);
4992 }
4993 node = vat_json_array_add (&vam->json_tree);
4994
4995 vat_json_init_object (node);
4996 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
4997 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
4998 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
4999 u8 *s =
5000 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
5001 0);
5002 vat_json_object_add_string_copy (node, "match", s);
5003}
5004
5005static void vl_api_pg_create_interface_reply_t_handler
5006 (vl_api_pg_create_interface_reply_t * mp)
5007{
5008 vat_main_t *vam = &vat_main;
5009
5010 vam->retval = ntohl (mp->retval);
5011 vam->result_ready = 1;
5012}
5013
5014static void vl_api_pg_create_interface_reply_t_handler_json
5015 (vl_api_pg_create_interface_reply_t * mp)
5016{
5017 vat_main_t *vam = &vat_main;
5018 vat_json_node_t node;
5019
5020 i32 retval = ntohl (mp->retval);
5021 if (retval == 0)
5022 {
5023 vat_json_init_object (&node);
5024
5025 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
5026
5027 vat_json_print (vam->ofp, &node);
5028 vat_json_free (&node);
5029 }
5030 vam->retval = ntohl (mp->retval);
5031 vam->result_ready = 1;
5032}
5033
5034static void vl_api_policer_classify_details_t_handler
5035 (vl_api_policer_classify_details_t * mp)
5036{
5037 vat_main_t *vam = &vat_main;
5038
5039 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5040 ntohl (mp->table_index));
5041}
5042
5043static void vl_api_policer_classify_details_t_handler_json
5044 (vl_api_policer_classify_details_t * mp)
5045{
5046 vat_main_t *vam = &vat_main;
5047 vat_json_node_t *node;
5048
5049 if (VAT_JSON_ARRAY != vam->json_tree.type)
5050 {
5051 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5052 vat_json_init_array (&vam->json_tree);
5053 }
5054 node = vat_json_array_add (&vam->json_tree);
5055
5056 vat_json_init_object (node);
5057 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5058 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5059}
5060
5061static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler
5062 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
5063{
5064 vat_main_t *vam = &vat_main;
5065 i32 retval = ntohl (mp->retval);
5066 if (vam->async_mode)
5067 {
5068 vam->async_errors += (retval < 0);
5069 }
5070 else
5071 {
5072 vam->retval = retval;
5073 vam->sw_if_index = ntohl (mp->sw_if_index);
5074 vam->result_ready = 1;
5075 }
Dave Barachf72212e2018-01-11 10:25:07 -05005076 vam->regenerate_interface_table = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005077}
5078
5079static void vl_api_ipsec_gre_add_del_tunnel_reply_t_handler_json
5080 (vl_api_ipsec_gre_add_del_tunnel_reply_t * mp)
5081{
5082 vat_main_t *vam = &vat_main;
5083 vat_json_node_t node;
5084
5085 vat_json_init_object (&node);
5086 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
5087 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
5088
5089 vat_json_print (vam->ofp, &node);
5090 vat_json_free (&node);
5091
5092 vam->retval = ntohl (mp->retval);
5093 vam->result_ready = 1;
5094}
5095
5096static void vl_api_flow_classify_details_t_handler
5097 (vl_api_flow_classify_details_t * mp)
5098{
5099 vat_main_t *vam = &vat_main;
5100
5101 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
5102 ntohl (mp->table_index));
5103}
5104
5105static void vl_api_flow_classify_details_t_handler_json
5106 (vl_api_flow_classify_details_t * mp)
5107{
5108 vat_main_t *vam = &vat_main;
5109 vat_json_node_t *node;
5110
5111 if (VAT_JSON_ARRAY != vam->json_tree.type)
5112 {
5113 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5114 vat_json_init_array (&vam->json_tree);
5115 }
5116 node = vat_json_array_add (&vam->json_tree);
5117
5118 vat_json_init_object (node);
5119 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
5120 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
5121}
5122
Filip Tehlar694396d2017-02-17 14:29:11 +01005123#define vl_api_one_adjacencies_get_reply_t_endian vl_noop_handler
5124#define vl_api_one_adjacencies_get_reply_t_print vl_noop_handler
Filip Tehlard5a65db2017-05-17 17:21:10 +02005125#define vl_api_one_l2_arp_bd_get_reply_t_print vl_noop_handler
5126#define vl_api_one_l2_arp_entries_get_reply_t_endian vl_noop_handler
5127#define vl_api_one_l2_arp_entries_get_reply_t_print vl_noop_handler
5128#define vl_api_one_l2_arp_bd_get_reply_t_endian vl_noop_handler
Filip Tehlar05879992017-09-05 15:46:09 +02005129#define vl_api_one_ndp_bd_get_reply_t_endian vl_noop_handler
5130#define vl_api_one_ndp_bd_get_reply_t_print vl_noop_handler
5131#define vl_api_one_ndp_entries_get_reply_t_print vl_noop_handler
5132#define vl_api_one_ndp_entries_get_reply_t_endian vl_noop_handler
Damjan Marion7cd468a2016-12-19 23:05:39 +01005133
5134/*
5135 * Generate boilerplate reply handlers, which
5136 * dig the return value out of the xxx_reply_t API message,
5137 * stick it into vam->retval, and set vam->result_ready
5138 *
5139 * Could also do this by pointing N message decode slots at
5140 * a single function, but that could break in subtle ways.
5141 */
5142
5143#define foreach_standard_reply_retval_handler \
5144_(sw_interface_set_flags_reply) \
5145_(sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005146_(sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005147_(sw_interface_set_rx_placement_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005148_(sw_interface_set_table_reply) \
5149_(sw_interface_set_mpls_enable_reply) \
5150_(sw_interface_set_vpath_reply) \
5151_(sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005152_(sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005153_(sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005154_(sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005155_(bridge_domain_add_del_reply) \
5156_(sw_interface_set_l2_xconnect_reply) \
5157_(l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005158_(l2fib_flush_int_reply) \
5159_(l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005160_(ip_add_del_route_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005161_(ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005162_(ip_mroute_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005163_(mpls_route_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005164_(mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005165_(mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005166_(bier_route_add_del_reply) \
5167_(bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005168_(proxy_arp_add_del_reply) \
5169_(proxy_arp_intfc_enable_disable_reply) \
5170_(sw_interface_set_unnumbered_reply) \
5171_(ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005172_(oam_add_del_reply) \
5173_(reset_fib_reply) \
5174_(dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005175_(dhcp_proxy_set_vss_reply) \
5176_(dhcp_client_config_reply) \
5177_(set_ip_flow_hash_reply) \
5178_(sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005179_(ip6nd_proxy_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005180_(sw_interface_ip6nd_ra_prefix_reply) \
5181_(sw_interface_ip6nd_ra_config_reply) \
5182_(set_arp_neighbor_limit_reply) \
5183_(l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005184_(sr_mpls_policy_add_reply) \
5185_(sr_mpls_policy_mod_reply) \
5186_(sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005187_(sr_policy_add_reply) \
5188_(sr_policy_mod_reply) \
5189_(sr_policy_del_reply) \
5190_(sr_localsid_add_del_reply) \
5191_(sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005192_(classify_add_del_session_reply) \
5193_(classify_set_interface_ip_table_reply) \
5194_(classify_set_interface_l2_tables_reply) \
5195_(l2tpv3_set_tunnel_cookies_reply) \
5196_(l2tpv3_interface_enable_disable_reply) \
5197_(l2tpv3_set_lookup_key_reply) \
5198_(l2_fib_clear_table_reply) \
5199_(l2_interface_efp_filter_reply) \
5200_(l2_interface_vlan_tag_rewrite_reply) \
5201_(modify_vhost_user_if_reply) \
5202_(delete_vhost_user_if_reply) \
John Loc7b43042018-04-13 16:46:22 -04005203_(ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005204_(ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005205_(want_ip4_arp_events_reply) \
5206_(want_ip6_nd_events_reply) \
John Lo8d00fff2017-08-03 00:35:36 -04005207_(want_l2_macs_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005208_(input_acl_set_interface_reply) \
5209_(ipsec_spd_add_del_reply) \
5210_(ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005211_(ipsec_spd_entry_add_del_reply) \
5212_(ipsec_sad_entry_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005213_(ipsec_sa_set_key_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005214_(ipsec_tunnel_if_add_del_reply) \
Matthew Smith75d85602017-10-05 19:03:05 -05005215_(ipsec_tunnel_if_set_key_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005216_(ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005217_(ikev2_profile_add_del_reply) \
5218_(ikev2_profile_set_auth_reply) \
5219_(ikev2_profile_set_id_reply) \
5220_(ikev2_profile_set_ts_reply) \
5221_(ikev2_set_local_key_reply) \
Radu Nicolaucb33dc22017-02-16 16:49:46 +00005222_(ikev2_set_responder_reply) \
5223_(ikev2_set_ike_transforms_reply) \
5224_(ikev2_set_esp_transforms_reply) \
5225_(ikev2_set_sa_lifetime_reply) \
5226_(ikev2_initiate_sa_init_reply) \
5227_(ikev2_initiate_del_ike_sa_reply) \
5228_(ikev2_initiate_del_child_sa_reply) \
5229_(ikev2_initiate_rekey_child_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005230_(delete_loopback_reply) \
5231_(bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005232_(bd_ip_mac_flush_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005233_(want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005234_(cop_interface_enable_disable_reply) \
5235_(cop_whitelist_enable_disable_reply) \
5236_(sw_interface_clear_stats_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005237_(ioam_enable_reply) \
5238_(ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005239_(one_add_del_locator_reply) \
5240_(one_add_del_local_eid_reply) \
5241_(one_add_del_remote_mapping_reply) \
5242_(one_add_del_adjacency_reply) \
5243_(one_add_del_map_resolver_reply) \
5244_(one_add_del_map_server_reply) \
5245_(one_enable_disable_reply) \
5246_(one_rloc_probe_enable_disable_reply) \
5247_(one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005248_(one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005249_(one_set_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005250_(one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005251_(one_pitr_set_locator_set_reply) \
5252_(one_map_request_mode_reply) \
5253_(one_add_del_map_request_itr_rlocs_reply) \
5254_(one_eid_table_add_del_map_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005255_(one_use_petr_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005256_(one_stats_enable_disable_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005257_(one_add_del_l2_arp_entry_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005258_(one_add_del_ndp_entry_reply) \
Filip Tehlar21511912017-04-07 10:41:42 +02005259_(one_stats_flush_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005260_(one_enable_disable_xtr_mode_reply) \
5261_(one_enable_disable_pitr_mode_reply) \
5262_(one_enable_disable_petr_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005263_(gpe_enable_disable_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005264_(gpe_set_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005265_(gpe_add_del_iface_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005266_(gpe_add_del_native_fwd_rpath_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005267_(af_packet_delete_reply) \
5268_(policer_classify_set_interface_reply) \
5269_(netmap_create_reply) \
5270_(netmap_delete_reply) \
5271_(set_ipfix_exporter_reply) \
5272_(set_ipfix_classify_stream_reply) \
5273_(ipfix_classify_table_add_del_reply) \
5274_(flow_classify_set_interface_reply) \
5275_(sw_interface_span_enable_disable_reply) \
5276_(pg_capture_reply) \
5277_(pg_enable_disable_reply) \
5278_(ip_source_and_port_range_check_add_del_reply) \
5279_(ip_source_and_port_range_check_interface_add_del_reply)\
5280_(delete_subif_reply) \
5281_(l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005282_(set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005283_(feature_enable_disable_reply) \
5284_(sw_interface_tag_add_del_reply) \
Ole Troand7231612018-06-07 10:17:57 +02005285_(hw_interface_set_mtu_reply) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005286_(p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005287_(p2p_ethernet_del_reply) \
5288_(lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005289_(sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005290_(tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005291_(dns_enable_disable_reply) \
Florin Coras1c710452017-10-17 00:03:13 -07005292_(dns_name_server_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005293_(session_rule_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005294_(ip_container_proxy_add_del_reply) \
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -07005295_(output_acl_set_interface_reply) \
5296_(qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005297
5298#define _(n) \
5299 static void vl_api_##n##_t_handler \
5300 (vl_api_##n##_t * mp) \
5301 { \
5302 vat_main_t * vam = &vat_main; \
5303 i32 retval = ntohl(mp->retval); \
5304 if (vam->async_mode) { \
5305 vam->async_errors += (retval < 0); \
5306 } else { \
5307 vam->retval = retval; \
5308 vam->result_ready = 1; \
5309 } \
5310 }
5311foreach_standard_reply_retval_handler;
5312#undef _
5313
5314#define _(n) \
5315 static void vl_api_##n##_t_handler_json \
5316 (vl_api_##n##_t * mp) \
5317 { \
5318 vat_main_t * vam = &vat_main; \
5319 vat_json_node_t node; \
5320 vat_json_init_object(&node); \
5321 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
5322 vat_json_print(vam->ofp, &node); \
5323 vam->retval = ntohl(mp->retval); \
5324 vam->result_ready = 1; \
5325 }
5326foreach_standard_reply_retval_handler;
5327#undef _
5328
5329/*
5330 * Table of message reply handlers, must include boilerplate handlers
5331 * we just generated
5332 */
5333
5334#define foreach_vpe_api_reply_msg \
5335_(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005336_(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005337_(SW_INTERFACE_DETAILS, sw_interface_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005338_(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
5339_(CONTROL_PING_REPLY, control_ping_reply) \
5340_(CLI_REPLY, cli_reply) \
5341_(CLI_INBAND_REPLY, cli_inband_reply) \
5342_(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
5343 sw_interface_add_del_address_reply) \
Stevenad8015b2017-10-29 22:10:46 -07005344_(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02005345_(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02005346_(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005347_(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
5348_(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
5349_(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
5350_(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005351_(SW_INTERFACE_SET_GENEVE_BYPASS_REPLY, sw_interface_set_geneve_bypass_reply) \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08005352_(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005353_(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
5354 sw_interface_set_l2_xconnect_reply) \
5355_(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
5356 sw_interface_set_l2_bridge_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005357_(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
5358_(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
Eyal Barifead6702017-04-04 04:46:32 +03005359_(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005360_(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
Eyal Barif24991c2017-04-05 05:33:21 +03005361_(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
5362_(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005363_(L2_FLAGS_REPLY, l2_flags_reply) \
5364_(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
Damjan Marion8389fb92017-10-13 18:29:53 +02005365_(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
5366_(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
5367_(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01005368_(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
5369_(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
5370_(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
Steven9cd2d7a2017-12-20 12:43:01 -08005371_(BOND_CREATE_REPLY, bond_create_reply) \
5372_(BOND_DELETE_REPLY, bond_delete_reply) \
5373_(BOND_ENSLAVE_REPLY, bond_enslave_reply) \
5374_(BOND_DETACH_SLAVE_REPLY, bond_detach_slave_reply) \
5375_(SW_INTERFACE_BOND_DETAILS, sw_interface_bond_details) \
5376_(SW_INTERFACE_SLAVE_DETAILS, sw_interface_slave_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005377_(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005378_(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
Neale Ranns32e1c012016-11-22 17:07:28 +00005379_(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
Neale Ranns28ab9cc2017-08-14 07:18:42 -07005380_(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005381_(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
5382_(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
Neale Rannsd792d9c2017-10-21 10:53:20 -07005383_(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
5384_(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005385_(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
5386_(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
5387 proxy_arp_intfc_enable_disable_reply) \
5388_(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
5389_(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
5390 sw_interface_set_unnumbered_reply) \
5391_(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005392_(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
5393_(CREATE_SUBIF_REPLY, create_subif_reply) \
5394_(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
5395_(RESET_FIB_REPLY, reset_fib_reply) \
5396_(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005397_(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
Neale Ranns20a175a2017-02-14 07:28:41 -08005398_(DHCP_PROXY_DETAILS, dhcp_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005399_(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
5400_(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
5401_(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
5402 sw_interface_ip6_enable_disable_reply) \
Neale Ranns3f844d02017-02-18 00:03:54 -08005403_(IP6ND_PROXY_ADD_DEL_REPLY, ip6nd_proxy_add_del_reply) \
5404_(IP6ND_PROXY_DETAILS, ip6nd_proxy_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005405_(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
5406 sw_interface_ip6nd_ra_prefix_reply) \
5407_(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
5408 sw_interface_ip6nd_ra_config_reply) \
5409_(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
5410_(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
John Loe166fd92018-09-13 14:08:59 -04005411_(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
5412_(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
5413_(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
Pablo Camarillofb380952016-12-07 18:34:18 +01005414_(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
5415_(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
5416_(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
5417_(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
5418_(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005419_(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
5420_(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
5421_(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
5422classify_set_interface_ip_table_reply) \
5423_(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
5424 classify_set_interface_l2_tables_reply) \
5425_(GET_NODE_INDEX_REPLY, get_node_index_reply) \
5426_(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
5427_(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
5428_(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
5429_(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
5430 l2tpv3_interface_enable_disable_reply) \
5431_(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
5432_(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
5433_(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
eyal bariaf86a482018-04-17 11:20:27 +03005434_(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005435_(GENEVE_ADD_DEL_TUNNEL_REPLY, geneve_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005436_(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
Marco Varleseb598f1d2017-09-19 14:25:28 +02005437_(GENEVE_TUNNEL_DETAILS, geneve_tunnel_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005438_(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
5439_(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
5440_(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
5441_(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
5442_(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
5443_(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
5444_(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
5445_(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
5446_(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
5447_(SHOW_VERSION_REPLY, show_version_reply) \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +02005448_(SHOW_THREADS_REPLY, show_threads_reply) \
Ole Troan01384fe2017-05-12 11:55:35 +02005449_(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
John Loc7b43042018-04-13 16:46:22 -04005450_(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005451_(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
5452_(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
John Loc7b43042018-04-13 16:46:22 -04005453_(IP_PROBE_NEIGHBOR_REPLY, ip_probe_neighbor_reply) \
John Lo7f358b32018-04-28 01:19:24 -04005454_(IP_SCAN_NEIGHBOR_ENABLE_DISABLE_REPLY, ip_scan_neighbor_enable_disable_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005455_(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
5456_(IP4_ARP_EVENT, ip4_arp_event) \
5457_(WANT_IP6_ND_EVENTS_REPLY, want_ip6_nd_events_reply) \
5458_(IP6_ND_EVENT, ip6_nd_event) \
John Lo8d00fff2017-08-03 00:35:36 -04005459_(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
5460_(L2_MACS_EVENT, l2_macs_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005461_(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
5462_(IP_ADDRESS_DETAILS, ip_address_details) \
5463_(IP_DETAILS, ip_details) \
5464_(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
5465_(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
Neale Ranns17dcec02019-01-09 21:22:20 -08005466_(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
5467_(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
Matthew Smith28029532017-09-26 13:33:44 -05005468_(IPSEC_SA_DETAILS, ipsec_sa_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005469_(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
Matthew Smithb0972cb2017-05-02 16:20:41 -05005470_(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
Matthew Smith75d85602017-10-05 19:03:05 -05005471_(IPSEC_TUNNEL_IF_SET_KEY_REPLY, ipsec_tunnel_if_set_key_reply) \
Matthew Smithca514fd2017-10-12 12:06:59 -05005472_(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005473_(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
5474_(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
5475_(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
5476_(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
5477_(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
Radu Nicolaucb33dc22017-02-16 16:49:46 +00005478_(IKEV2_SET_RESPONDER_REPLY, ikev2_set_responder_reply) \
5479_(IKEV2_SET_IKE_TRANSFORMS_REPLY, ikev2_set_ike_transforms_reply) \
5480_(IKEV2_SET_ESP_TRANSFORMS_REPLY, ikev2_set_esp_transforms_reply) \
5481_(IKEV2_SET_SA_LIFETIME_REPLY, ikev2_set_sa_lifetime_reply) \
5482_(IKEV2_INITIATE_SA_INIT_REPLY, ikev2_initiate_sa_init_reply) \
5483_(IKEV2_INITIATE_DEL_IKE_SA_REPLY, ikev2_initiate_del_ike_sa_reply) \
5484_(IKEV2_INITIATE_DEL_CHILD_SA_REPLY, ikev2_initiate_del_child_sa_reply) \
5485_(IKEV2_INITIATE_REKEY_CHILD_SA_REPLY, ikev2_initiate_rekey_child_sa_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005486_(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
5487_(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
John Loe26c81f2019-01-07 15:16:33 -05005488_(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02005489_(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005490_(DHCP_COMPL_EVENT, dhcp_compl_event) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005491_(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005492_(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
5493_(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
5494_(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
5495_(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
5496_(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
5497_(IOAM_ENABLE_REPLY, ioam_enable_reply) \
5498_(IOAM_DISABLE_REPLY, ioam_disable_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005499_(ONE_ADD_DEL_LOCATOR_SET_REPLY, one_add_del_locator_set_reply) \
5500_(ONE_ADD_DEL_LOCATOR_REPLY, one_add_del_locator_reply) \
5501_(ONE_ADD_DEL_LOCAL_EID_REPLY, one_add_del_local_eid_reply) \
5502_(ONE_ADD_DEL_REMOTE_MAPPING_REPLY, one_add_del_remote_mapping_reply) \
5503_(ONE_ADD_DEL_ADJACENCY_REPLY, one_add_del_adjacency_reply) \
5504_(ONE_ADD_DEL_MAP_RESOLVER_REPLY, one_add_del_map_resolver_reply) \
5505_(ONE_ADD_DEL_MAP_SERVER_REPLY, one_add_del_map_server_reply) \
5506_(ONE_ENABLE_DISABLE_REPLY, one_enable_disable_reply) \
5507_(ONE_MAP_REGISTER_ENABLE_DISABLE_REPLY, \
5508 one_map_register_enable_disable_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005509_(ONE_MAP_REGISTER_SET_TTL_REPLY, one_map_register_set_ttl_reply) \
Filip Tehlara4980b82017-09-27 14:32:02 +02005510_(ONE_SET_TRANSPORT_PROTOCOL_REPLY, one_set_transport_protocol_reply) \
5511_(ONE_GET_TRANSPORT_PROTOCOL_REPLY, one_get_transport_protocol_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005512_(ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5513 one_map_register_fallback_threshold_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005514_(ONE_RLOC_PROBE_ENABLE_DISABLE_REPLY, \
5515 one_rloc_probe_enable_disable_reply) \
5516_(ONE_PITR_SET_LOCATOR_SET_REPLY, one_pitr_set_locator_set_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005517_(ONE_USE_PETR_REPLY, one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005518_(ONE_MAP_REQUEST_MODE_REPLY, one_map_request_mode_reply) \
5519_(ONE_EID_TABLE_ADD_DEL_MAP_REPLY, one_eid_table_add_del_map_reply) \
5520_(ONE_LOCATOR_SET_DETAILS, one_locator_set_details) \
5521_(ONE_LOCATOR_DETAILS, one_locator_details) \
5522_(ONE_EID_TABLE_DETAILS, one_eid_table_details) \
5523_(ONE_EID_TABLE_MAP_DETAILS, one_eid_table_map_details) \
5524_(ONE_EID_TABLE_VNI_DETAILS, one_eid_table_vni_details) \
5525_(ONE_MAP_RESOLVER_DETAILS, one_map_resolver_details) \
5526_(ONE_MAP_SERVER_DETAILS, one_map_server_details) \
5527_(ONE_ADJACENCIES_GET_REPLY, one_adjacencies_get_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005528_(ONE_STATS_DETAILS, one_stats_details) \
Filip Tehlar21511912017-04-07 10:41:42 +02005529_(ONE_STATS_FLUSH_REPLY, one_stats_flush_reply) \
Filip Tehlar4868ff62017-03-09 16:48:39 +01005530_(ONE_STATS_ENABLE_DISABLE_REPLY, one_stats_enable_disable_reply) \
5531_(SHOW_ONE_STATS_ENABLE_DISABLE_REPLY, \
5532 show_one_stats_enable_disable_reply) \
Filip Tehlar05879992017-09-05 15:46:09 +02005533_(ONE_ADD_DEL_NDP_ENTRY_REPLY, one_add_del_ndp_entry_reply) \
5534_(ONE_NDP_BD_GET_REPLY, one_ndp_bd_get_reply) \
5535_(ONE_NDP_ENTRIES_GET_REPLY, one_ndp_entries_get_reply) \
Filip Tehlard5a65db2017-05-17 17:21:10 +02005536_(ONE_ADD_DEL_L2_ARP_ENTRY_REPLY, one_add_del_l2_arp_entry_reply) \
5537_(ONE_L2_ARP_BD_GET_REPLY, one_l2_arp_bd_get_reply) \
5538_(ONE_L2_ARP_ENTRIES_GET_REPLY, one_l2_arp_entries_get_reply) \
Filip Tehlar0a8840d2017-10-16 05:48:23 -07005539_(ONE_ENABLE_DISABLE_XTR_MODE_REPLY, one_enable_disable_xtr_mode_reply) \
5540_(ONE_ENABLE_DISABLE_PITR_MODE_REPLY, \
5541 one_enable_disable_pitr_mode_reply) \
5542_(ONE_ENABLE_DISABLE_PETR_MODE_REPLY, \
5543 one_enable_disable_petr_mode_reply) \
5544_(ONE_SHOW_XTR_MODE_REPLY, one_show_xtr_mode_reply) \
5545_(ONE_SHOW_PITR_MODE_REPLY, one_show_pitr_mode_reply) \
5546_(ONE_SHOW_PETR_MODE_REPLY, one_show_petr_mode_reply) \
Filip Tehlar3e7b56932017-02-21 18:28:34 +01005547_(GPE_SET_ENCAP_MODE_REPLY, gpe_set_encap_mode_reply) \
5548_(GPE_GET_ENCAP_MODE_REPLY, gpe_get_encap_mode_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005549_(GPE_ADD_DEL_IFACE_REPLY, gpe_add_del_iface_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005550_(GPE_ENABLE_DISABLE_REPLY, gpe_enable_disable_reply) \
5551_(GPE_ADD_DEL_FWD_ENTRY_REPLY, gpe_add_del_fwd_entry_reply) \
Filip Tehlar0eb874e2017-05-18 14:23:32 +02005552_(GPE_FWD_ENTRY_VNIS_GET_REPLY, gpe_fwd_entry_vnis_get_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005553_(GPE_FWD_ENTRIES_GET_REPLY, gpe_fwd_entries_get_reply) \
Filip Tehlarb4243aa2017-06-14 14:39:42 +02005554_(GPE_NATIVE_FWD_RPATHS_GET_REPLY, gpe_native_fwd_rpaths_get_reply) \
5555_(GPE_ADD_DEL_NATIVE_FWD_RPATH_REPLY, \
5556 gpe_add_del_native_fwd_rpath_reply) \
Filip Tehlar82786c42017-02-20 15:20:37 +01005557_(GPE_FWD_ENTRY_PATH_DETAILS, \
5558 gpe_fwd_entry_path_details) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005559_(SHOW_ONE_STATUS_REPLY, show_one_status_reply) \
5560_(ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
5561 one_add_del_map_request_itr_rlocs_reply) \
5562_(ONE_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
5563 one_get_map_request_itr_rlocs_reply) \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +02005564_(SHOW_ONE_NSH_MAPPING_REPLY, show_one_nsh_mapping_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005565_(SHOW_ONE_PITR_REPLY, show_one_pitr_reply) \
Filip Tehlar67a99f82017-03-10 13:18:02 +01005566_(SHOW_ONE_USE_PETR_REPLY, show_one_use_petr_reply) \
Filip Tehlar694396d2017-02-17 14:29:11 +01005567_(SHOW_ONE_MAP_REQUEST_MODE_REPLY, show_one_map_request_mode_reply) \
5568_(SHOW_ONE_RLOC_PROBE_STATE_REPLY, show_one_rloc_probe_state_reply) \
5569_(SHOW_ONE_MAP_REGISTER_STATE_REPLY, \
5570 show_one_map_register_state_reply) \
Filip Tehlar1e553a02017-08-02 12:45:07 +02005571_(SHOW_ONE_MAP_REGISTER_TTL_REPLY, show_one_map_register_ttl_reply) \
Filip Tehlar7048ff12017-07-27 08:09:14 +02005572_(SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD_REPLY, \
5573 show_one_map_register_fallback_threshold_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005574_(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
5575_(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +02005576_(AF_PACKET_DETAILS, af_packet_details) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005577_(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
5578_(POLICER_DETAILS, policer_details) \
5579_(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
5580_(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
5581_(NETMAP_CREATE_REPLY, netmap_create_reply) \
5582_(NETMAP_DELETE_REPLY, netmap_delete_reply) \
5583_(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
5584_(MPLS_FIB_DETAILS, mpls_fib_details) \
5585_(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
5586_(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
5587_(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
5588_(CLASSIFY_SESSION_DETAILS, classify_session_details) \
5589_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
5590_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
5591_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
5592_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
5593_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
5594_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
5595_(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
5596_(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
5597_(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
5598_(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
5599_(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
5600_(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
5601_(PG_CAPTURE_REPLY, pg_capture_reply) \
5602_(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
5603_(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
5604 ip_source_and_port_range_check_add_del_reply) \
5605_(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
5606 ip_source_and_port_range_check_interface_add_del_reply) \
5607_(IPSEC_GRE_ADD_DEL_TUNNEL_REPLY, ipsec_gre_add_del_tunnel_reply) \
5608_(IPSEC_GRE_TUNNEL_DETAILS, ipsec_gre_tunnel_details) \
5609_(DELETE_SUBIF_REPLY, delete_subif_reply) \
5610_(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
Pavel Kotuceke88865d2018-11-28 07:42:11 +01005611_(SET_PUNT_REPLY, set_punt_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005612_(IP_FIB_DETAILS, ip_fib_details) \
5613_(IP6_FIB_DETAILS, ip6_fib_details) \
5614_(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
5615_(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
5616_(L2_XCONNECT_DETAILS, l2_xconnect_details) \
Ole Troand7231612018-06-07 10:17:57 +02005617_(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
Damjan Marion7cd468a2016-12-19 23:05:39 +01005618_(IP_NEIGHBOR_DETAILS, ip_neighbor_details) \
Pavel Kotucek6899a302017-06-08 08:46:10 +02005619_(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
5620_(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
Steve Shin99a0e602017-07-01 04:16:20 +00005621_(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
5622_(LLDP_CONFIG_REPLY, lldp_config_reply) \
Dave Barach3bbcfab2017-08-15 19:03:44 -04005623_(SW_INTERFACE_SET_LLDP_REPLY, sw_interface_set_lldp_reply) \
Florin Corascea194d2017-10-02 00:18:51 -07005624_(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
Dave Barach65457162017-10-10 17:53:14 -04005625_(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
5626_(DNS_ENABLE_DISABLE_REPLY, dns_enable_disable_reply) \
5627_(DNS_NAME_SERVER_ADD_DEL_REPLY, dns_name_server_add_del_reply) \
Dave Barachd2080152017-10-20 09:21:35 -04005628_(DNS_RESOLVE_NAME_REPLY, dns_resolve_name_reply) \
Florin Coras1c710452017-10-17 00:03:13 -07005629_(DNS_RESOLVE_IP_REPLY, dns_resolve_ip_reply) \
Florin Coras6c36f532017-11-03 18:32:34 -07005630_(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
Florin Coras595992c2017-11-06 17:17:08 -08005631_(SESSION_RULES_DETAILS, session_rules_details) \
5632_(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +01005633_(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
Ole Troane906aac2018-06-14 14:42:14 +02005634_(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply)
Damjan Marion7cd468a2016-12-19 23:05:39 +01005635
Dave Baracha1a093d2017-03-02 13:13:23 -05005636#define foreach_standalone_reply_msg \
Ole Troanf49ba0e2018-11-13 14:04:50 +01005637_(SW_INTERFACE_EVENT, sw_interface_event)
Dave Baracha1a093d2017-03-02 13:13:23 -05005638
Damjan Marion7cd468a2016-12-19 23:05:39 +01005639typedef struct
5640{
5641 u8 *name;
5642 u32 value;
5643} name_sort_t;
5644
Damjan Marion7cd468a2016-12-19 23:05:39 +01005645#define STR_VTR_OP_CASE(op) \
5646 case L2_VTR_ ## op: \
5647 return "" # op;
5648
5649static const char *
5650str_vtr_op (u32 vtr_op)
5651{
5652 switch (vtr_op)
5653 {
5654 STR_VTR_OP_CASE (DISABLED);
5655 STR_VTR_OP_CASE (PUSH_1);
5656 STR_VTR_OP_CASE (PUSH_2);
5657 STR_VTR_OP_CASE (POP_1);
5658 STR_VTR_OP_CASE (POP_2);
5659 STR_VTR_OP_CASE (TRANSLATE_1_1);
5660 STR_VTR_OP_CASE (TRANSLATE_1_2);
5661 STR_VTR_OP_CASE (TRANSLATE_2_1);
5662 STR_VTR_OP_CASE (TRANSLATE_2_2);
5663 }
5664
5665 return "UNKNOWN";
5666}
5667
5668static int
5669dump_sub_interface_table (vat_main_t * vam)
5670{
5671 const sw_interface_subif_t *sub = NULL;
5672
5673 if (vam->json_output)
5674 {
5675 clib_warning
5676 ("JSON output supported only for VPE API calls and dump_stats_table");
5677 return -99;
5678 }
5679
5680 print (vam->ofp,
5681 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
5682 "Interface", "sw_if_index",
5683 "sub id", "dot1ad", "tags", "outer id",
5684 "inner id", "exact", "default", "outer any", "inner any");
5685
5686 vec_foreach (sub, vam->sw_if_subif_table)
5687 {
5688 print (vam->ofp,
5689 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
5690 sub->interface_name,
5691 sub->sw_if_index,
5692 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
5693 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
5694 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
5695 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
5696 if (sub->vtr_op != L2_VTR_DISABLED)
5697 {
5698 print (vam->ofp,
5699 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
5700 "tag1: %d tag2: %d ]",
5701 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
5702 sub->vtr_tag1, sub->vtr_tag2);
5703 }
5704 }
5705
5706 return 0;
5707}
5708
5709static int
5710name_sort_cmp (void *a1, void *a2)
5711{
5712 name_sort_t *n1 = a1;
5713 name_sort_t *n2 = a2;
5714
5715 return strcmp ((char *) n1->name, (char *) n2->name);
5716}
5717
5718static int
5719dump_interface_table (vat_main_t * vam)
5720{
5721 hash_pair_t *p;
5722 name_sort_t *nses = 0, *ns;
5723
5724 if (vam->json_output)
5725 {
5726 clib_warning
5727 ("JSON output supported only for VPE API calls and dump_stats_table");
5728 return -99;
5729 }
5730
5731 /* *INDENT-OFF* */
5732 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5733 ({
5734 vec_add2 (nses, ns, 1);
5735 ns->name = (u8 *)(p->key);
5736 ns->value = (u32) p->value[0];
5737 }));
5738 /* *INDENT-ON* */
5739
5740 vec_sort_with_function (nses, name_sort_cmp);
5741
5742 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
5743 vec_foreach (ns, nses)
5744 {
5745 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
5746 }
5747 vec_free (nses);
5748 return 0;
5749}
5750
5751static int
5752dump_ip_table (vat_main_t * vam, int is_ipv6)
5753{
5754 const ip_details_t *det = NULL;
5755 const ip_address_details_t *address = NULL;
5756 u32 i = ~0;
5757
5758 print (vam->ofp, "%-12s", "sw_if_index");
5759
5760 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
5761 {
5762 i++;
5763 if (!det->present)
5764 {
5765 continue;
5766 }
5767 print (vam->ofp, "%-12d", i);
5768 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
5769 if (!det->addr)
5770 {
5771 continue;
5772 }
5773 vec_foreach (address, det->addr)
5774 {
5775 print (vam->ofp,
5776 " %-30U%-13d",
5777 is_ipv6 ? format_ip6_address : format_ip4_address,
5778 address->ip, address->prefix_length);
5779 }
5780 }
5781
5782 return 0;
5783}
5784
5785static int
5786dump_ipv4_table (vat_main_t * vam)
5787{
5788 if (vam->json_output)
5789 {
5790 clib_warning
5791 ("JSON output supported only for VPE API calls and dump_stats_table");
5792 return -99;
5793 }
5794
5795 return dump_ip_table (vam, 0);
5796}
5797
5798static int
5799dump_ipv6_table (vat_main_t * vam)
5800{
5801 if (vam->json_output)
5802 {
5803 clib_warning
5804 ("JSON output supported only for VPE API calls and dump_stats_table");
5805 return -99;
5806 }
5807
5808 return dump_ip_table (vam, 1);
5809}
5810
Damjan Marion7cd468a2016-12-19 23:05:39 +01005811/*
Dave Barach59b25652017-09-10 15:04:27 -04005812 * Pass CLI buffers directly in the CLI_INBAND API message,
5813 * instead of an additional shared memory area.
Damjan Marion7cd468a2016-12-19 23:05:39 +01005814 */
5815static int
5816exec_inband (vat_main_t * vam)
5817{
5818 vl_api_cli_inband_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005819 unformat_input_t *i = vam->input;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005820 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005821
5822 if (vec_len (i->buffer) == 0)
5823 return -1;
5824
5825 if (vam->exec_mode == 0 && unformat (i, "mode"))
5826 {
5827 vam->exec_mode = 1;
5828 return 0;
5829 }
5830 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
5831 {
5832 vam->exec_mode = 0;
5833 return 0;
5834 }
5835
5836 /*
5837 * In order for the CLI command to work, it
5838 * must be a vector ending in \n, not a C-string ending
5839 * in \n\0.
5840 */
5841 u32 len = vec_len (vam->input->buffer);
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005842 M2 (CLI_INBAND, mp, len);
Ole Troan884f0af2018-12-14 20:34:29 +01005843 vl_api_to_api_string (len - 1, (const char *) vam->input->buffer, &mp->cmd);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005844
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005845 S (mp);
Dave Barach59b25652017-09-10 15:04:27 -04005846 W (ret);
5847 /* json responses may or may not include a useful reply... */
5848 if (vec_len (vam->cmd_reply))
Dave Barachcf5e8482017-10-17 11:48:29 -04005849 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
Jon Loeliger56c7b012017-02-01 12:31:41 -06005850 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005851}
5852
Dave Barach59b25652017-09-10 15:04:27 -04005853int
5854exec (vat_main_t * vam)
5855{
5856 return exec_inband (vam);
5857}
5858
Damjan Marion7cd468a2016-12-19 23:05:39 +01005859static int
5860api_create_loopback (vat_main_t * vam)
5861{
5862 unformat_input_t *i = vam->input;
5863 vl_api_create_loopback_t *mp;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005864 vl_api_create_loopback_instance_t *mp_lbi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005865 u8 mac_address[6];
5866 u8 mac_set = 0;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005867 u8 is_specified = 0;
5868 u32 user_instance = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005869 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005870
Dave Barachb7b92992018-10-17 10:38:51 -04005871 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01005872
5873 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5874 {
5875 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
5876 mac_set = 1;
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005877 if (unformat (i, "instance %d", &user_instance))
5878 is_specified = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005879 else
5880 break;
5881 }
5882
Jon Loeligerc83c3b72017-02-23 13:57:35 -06005883 if (is_specified)
5884 {
5885 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
5886 mp_lbi->is_specified = is_specified;
5887 if (is_specified)
5888 mp_lbi->user_instance = htonl (user_instance);
5889 if (mac_set)
5890 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
5891 S (mp_lbi);
5892 }
5893 else
5894 {
5895 /* Construct the API message */
5896 M (CREATE_LOOPBACK, mp);
5897 if (mac_set)
5898 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
5899 S (mp);
5900 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01005901
Jon Loeliger56c7b012017-02-01 12:31:41 -06005902 W (ret);
5903 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005904}
5905
5906static int
5907api_delete_loopback (vat_main_t * vam)
5908{
5909 unformat_input_t *i = vam->input;
5910 vl_api_delete_loopback_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005911 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005912 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005913
5914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5915 {
5916 if (unformat (i, "sw_if_index %d", &sw_if_index))
5917 ;
5918 else
5919 break;
5920 }
5921
5922 if (sw_if_index == ~0)
5923 {
5924 errmsg ("missing sw_if_index");
5925 return -99;
5926 }
5927
5928 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005929 M (DELETE_LOOPBACK, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005930 mp->sw_if_index = ntohl (sw_if_index);
5931
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005932 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005933 W (ret);
5934 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005935}
5936
5937static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01005938api_want_interface_events (vat_main_t * vam)
5939{
5940 unformat_input_t *i = vam->input;
5941 vl_api_want_interface_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005942 int enable = -1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005943 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005944
5945 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5946 {
5947 if (unformat (i, "enable"))
5948 enable = 1;
5949 else if (unformat (i, "disable"))
5950 enable = 0;
5951 else
5952 break;
5953 }
5954
5955 if (enable == -1)
5956 {
5957 errmsg ("missing enable|disable");
5958 return -99;
5959 }
5960
Jon Loeliger8a2aea32017-01-31 13:19:40 -06005961 M (WANT_INTERFACE_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01005962 mp->enable_disable = enable;
5963
5964 vam->interface_event_display = enable;
5965
Jon Loeliger7bc770c2017-01-31 14:03:33 -06005966 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06005967 W (ret);
5968 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005969}
5970
5971
5972/* Note: non-static, called once to set up the initial intfc table */
5973int
5974api_sw_interface_dump (vat_main_t * vam)
5975{
5976 vl_api_sw_interface_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06005977 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005978 hash_pair_t *p;
5979 name_sort_t *nses = 0, *ns;
5980 sw_interface_subif_t *sub = NULL;
Jon Loeliger56c7b012017-02-01 12:31:41 -06005981 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01005982
5983 /* Toss the old name table */
5984 /* *INDENT-OFF* */
5985 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
5986 ({
5987 vec_add2 (nses, ns, 1);
5988 ns->name = (u8 *)(p->key);
5989 ns->value = (u32) p->value[0];
5990 }));
5991 /* *INDENT-ON* */
5992
5993 hash_free (vam->sw_if_index_by_interface_name);
5994
5995 vec_foreach (ns, nses) vec_free (ns->name);
5996
5997 vec_free (nses);
5998
5999 vec_foreach (sub, vam->sw_if_subif_table)
6000 {
6001 vec_free (sub->interface_name);
6002 }
6003 vec_free (vam->sw_if_subif_table);
6004
6005 /* recreate the interface name hash table */
6006 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
6007
Dave Barachf72212e2018-01-11 10:25:07 -05006008 /*
6009 * Ask for all interface names. Otherwise, the epic catalog of
6010 * name filters becomes ridiculously long, and vat ends up needing
6011 * to be taught about new interface types.
6012 */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006013 M (SW_INTERFACE_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006014 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006015
6016 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006017 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006018 S (mp_ping);
6019
Jon Loeliger56c7b012017-02-01 12:31:41 -06006020 W (ret);
6021 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006022}
6023
6024static int
6025api_sw_interface_set_flags (vat_main_t * vam)
6026{
6027 unformat_input_t *i = vam->input;
6028 vl_api_sw_interface_set_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006029 u32 sw_if_index;
6030 u8 sw_if_index_set = 0;
Neale Rannsa07bd702017-08-07 07:53:49 -07006031 u8 admin_up = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006032 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006033
6034 /* Parse args required to build the message */
6035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6036 {
6037 if (unformat (i, "admin-up"))
6038 admin_up = 1;
6039 else if (unformat (i, "admin-down"))
6040 admin_up = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006041 else
6042 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6043 sw_if_index_set = 1;
6044 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6045 sw_if_index_set = 1;
6046 else
6047 break;
6048 }
6049
6050 if (sw_if_index_set == 0)
6051 {
6052 errmsg ("missing interface name or sw_if_index");
6053 return -99;
6054 }
6055
6056 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006057 M (SW_INTERFACE_SET_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006058 mp->sw_if_index = ntohl (sw_if_index);
6059 mp->admin_up_down = admin_up;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006060
6061 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006062 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006063
6064 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006065 W (ret);
6066 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006067}
6068
6069static int
Stevenad8015b2017-10-29 22:10:46 -07006070api_sw_interface_set_rx_mode (vat_main_t * vam)
6071{
6072 unformat_input_t *i = vam->input;
6073 vl_api_sw_interface_set_rx_mode_t *mp;
6074 u32 sw_if_index;
6075 u8 sw_if_index_set = 0;
6076 int ret;
6077 u8 queue_id_valid = 0;
6078 u32 queue_id;
6079 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
6080
6081 /* Parse args required to build the message */
6082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6083 {
6084 if (unformat (i, "queue %d", &queue_id))
6085 queue_id_valid = 1;
6086 else if (unformat (i, "polling"))
6087 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
6088 else if (unformat (i, "interrupt"))
6089 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
6090 else if (unformat (i, "adaptive"))
6091 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
6092 else
6093 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6094 sw_if_index_set = 1;
6095 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6096 sw_if_index_set = 1;
6097 else
6098 break;
6099 }
6100
6101 if (sw_if_index_set == 0)
6102 {
6103 errmsg ("missing interface name or sw_if_index");
6104 return -99;
6105 }
6106 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
6107 {
6108 errmsg ("missing rx-mode");
6109 return -99;
6110 }
6111
6112 /* Construct the API message */
6113 M (SW_INTERFACE_SET_RX_MODE, mp);
6114 mp->sw_if_index = ntohl (sw_if_index);
6115 mp->mode = mode;
6116 mp->queue_id_valid = queue_id_valid;
6117 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
6118
6119 /* send it... */
6120 S (mp);
6121
6122 /* Wait for a reply, return the good/bad news... */
6123 W (ret);
6124 return ret;
6125}
6126
6127static int
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006128api_sw_interface_set_rx_placement (vat_main_t * vam)
6129{
6130 unformat_input_t *i = vam->input;
6131 vl_api_sw_interface_set_rx_placement_t *mp;
6132 u32 sw_if_index;
6133 u8 sw_if_index_set = 0;
6134 int ret;
6135 u8 is_main = 0;
6136 u32 queue_id, thread_index;
6137
6138 /* Parse args required to build the message */
6139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6140 {
6141 if (unformat (i, "queue %d", &queue_id))
6142 ;
6143 else if (unformat (i, "main"))
6144 is_main = 1;
6145 else if (unformat (i, "worker %d", &thread_index))
6146 ;
6147 else
6148 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6149 sw_if_index_set = 1;
6150 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6151 sw_if_index_set = 1;
6152 else
6153 break;
6154 }
6155
6156 if (sw_if_index_set == 0)
6157 {
6158 errmsg ("missing interface name or sw_if_index");
6159 return -99;
6160 }
6161
6162 if (is_main)
6163 thread_index = 0;
6164 /* Construct the API message */
6165 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
6166 mp->sw_if_index = ntohl (sw_if_index);
6167 mp->worker_id = ntohl (thread_index);
6168 mp->queue_id = ntohl (queue_id);
6169 mp->is_main = is_main;
6170
6171 /* send it... */
6172 S (mp);
6173 /* Wait for a reply, return the good/bad news... */
6174 W (ret);
6175 return ret;
6176}
6177
Mohsin Kazmif0b42f42018-09-10 18:11:00 +02006178static void vl_api_sw_interface_rx_placement_details_t_handler
6179 (vl_api_sw_interface_rx_placement_details_t * mp)
6180{
6181 vat_main_t *vam = &vat_main;
6182 u32 worker_id = ntohl (mp->worker_id);
6183
6184 print (vam->ofp,
6185 "\n%-11d %-11s %-6d %-5d %-9s",
6186 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
6187 worker_id, ntohl (mp->queue_id),
6188 (mp->mode ==
6189 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
6190}
6191
6192static void vl_api_sw_interface_rx_placement_details_t_handler_json
6193 (vl_api_sw_interface_rx_placement_details_t * mp)
6194{
6195 vat_main_t *vam = &vat_main;
6196 vat_json_node_t *node = NULL;
6197
6198 if (VAT_JSON_ARRAY != vam->json_tree.type)
6199 {
6200 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6201 vat_json_init_array (&vam->json_tree);
6202 }
6203 node = vat_json_array_add (&vam->json_tree);
6204
6205 vat_json_init_object (node);
6206 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6207 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
6208 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
6209 vat_json_object_add_uint (node, "mode", mp->mode);
6210}
6211
6212static int
6213api_sw_interface_rx_placement_dump (vat_main_t * vam)
6214{
6215 unformat_input_t *i = vam->input;
6216 vl_api_sw_interface_rx_placement_dump_t *mp;
6217 vl_api_control_ping_t *mp_ping;
6218 int ret;
6219 u32 sw_if_index;
6220 u8 sw_if_index_set = 0;
6221
6222 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6223 {
6224 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6225 sw_if_index_set++;
6226 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6227 sw_if_index_set++;
6228 else
6229 break;
6230 }
6231
6232 print (vam->ofp,
6233 "\n%-11s %-11s %-6s %-5s %-4s",
6234 "sw_if_index", "main/worker", "thread", "queue", "mode");
6235
6236 /* Dump Interface rx placement */
6237 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
6238
6239 if (sw_if_index_set)
6240 mp->sw_if_index = htonl (sw_if_index);
6241 else
6242 mp->sw_if_index = ~0;
6243
6244 S (mp);
6245
6246 /* Use a control ping for synchronization */
6247 MPING (CONTROL_PING, mp_ping);
6248 S (mp_ping);
6249
6250 W (ret);
6251 return ret;
6252}
6253
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02006254static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006255api_sw_interface_clear_stats (vat_main_t * vam)
6256{
6257 unformat_input_t *i = vam->input;
6258 vl_api_sw_interface_clear_stats_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006259 u32 sw_if_index;
6260 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006261 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006262
6263 /* Parse args required to build the message */
6264 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6265 {
6266 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6267 sw_if_index_set = 1;
6268 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6269 sw_if_index_set = 1;
6270 else
6271 break;
6272 }
6273
6274 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006275 M (SW_INTERFACE_CLEAR_STATS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006276
6277 if (sw_if_index_set == 1)
6278 mp->sw_if_index = ntohl (sw_if_index);
6279 else
6280 mp->sw_if_index = ~0;
6281
6282 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006283 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006284
6285 /* Wait for a reply, return the good/bad news... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006286 W (ret);
6287 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006288}
6289
Damjan Marion7cd468a2016-12-19 23:05:39 +01006290static int
6291api_sw_interface_add_del_address (vat_main_t * vam)
6292{
6293 unformat_input_t *i = vam->input;
6294 vl_api_sw_interface_add_del_address_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006295 u32 sw_if_index;
6296 u8 sw_if_index_set = 0;
6297 u8 is_add = 1, del_all = 0;
6298 u32 address_length = 0;
6299 u8 v4_address_set = 0;
6300 u8 v6_address_set = 0;
6301 ip4_address_t v4address;
6302 ip6_address_t v6address;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006303 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006304
6305 /* Parse args required to build the message */
6306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6307 {
6308 if (unformat (i, "del-all"))
6309 del_all = 1;
6310 else if (unformat (i, "del"))
6311 is_add = 0;
6312 else
6313 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6314 sw_if_index_set = 1;
6315 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6316 sw_if_index_set = 1;
6317 else if (unformat (i, "%U/%d",
6318 unformat_ip4_address, &v4address, &address_length))
6319 v4_address_set = 1;
6320 else if (unformat (i, "%U/%d",
6321 unformat_ip6_address, &v6address, &address_length))
6322 v6_address_set = 1;
6323 else
6324 break;
6325 }
6326
6327 if (sw_if_index_set == 0)
6328 {
6329 errmsg ("missing interface name or sw_if_index");
6330 return -99;
6331 }
6332 if (v4_address_set && v6_address_set)
6333 {
6334 errmsg ("both v4 and v6 addresses set");
6335 return -99;
6336 }
6337 if (!v4_address_set && !v6_address_set && !del_all)
6338 {
6339 errmsg ("no addresses set");
6340 return -99;
6341 }
6342
6343 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006344 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006345
6346 mp->sw_if_index = ntohl (sw_if_index);
6347 mp->is_add = is_add;
6348 mp->del_all = del_all;
6349 if (v6_address_set)
6350 {
6351 mp->is_ipv6 = 1;
6352 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6353 }
6354 else
6355 {
6356 clib_memcpy (mp->address, &v4address, sizeof (v4address));
6357 }
6358 mp->address_length = address_length;
6359
6360 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006361 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006362
6363 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006364 W (ret);
6365 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006366}
6367
6368static int
6369api_sw_interface_set_mpls_enable (vat_main_t * vam)
6370{
6371 unformat_input_t *i = vam->input;
6372 vl_api_sw_interface_set_mpls_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006373 u32 sw_if_index;
6374 u8 sw_if_index_set = 0;
6375 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006376 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006377
6378 /* Parse args required to build the message */
6379 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6380 {
6381 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6382 sw_if_index_set = 1;
6383 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6384 sw_if_index_set = 1;
6385 else if (unformat (i, "disable"))
6386 enable = 0;
6387 else if (unformat (i, "dis"))
6388 enable = 0;
6389 else
6390 break;
6391 }
6392
6393 if (sw_if_index_set == 0)
6394 {
6395 errmsg ("missing interface name or sw_if_index");
6396 return -99;
6397 }
6398
6399 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006400 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006401
6402 mp->sw_if_index = ntohl (sw_if_index);
6403 mp->enable = enable;
6404
6405 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006406 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006407
6408 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006409 W (ret);
6410 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006411}
6412
6413static int
6414api_sw_interface_set_table (vat_main_t * vam)
6415{
6416 unformat_input_t *i = vam->input;
6417 vl_api_sw_interface_set_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006418 u32 sw_if_index, vrf_id = 0;
6419 u8 sw_if_index_set = 0;
6420 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006421 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006422
6423 /* Parse args required to build the message */
6424 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6425 {
6426 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6427 sw_if_index_set = 1;
6428 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6429 sw_if_index_set = 1;
6430 else if (unformat (i, "vrf %d", &vrf_id))
6431 ;
6432 else if (unformat (i, "ipv6"))
6433 is_ipv6 = 1;
6434 else
6435 break;
6436 }
6437
6438 if (sw_if_index_set == 0)
6439 {
6440 errmsg ("missing interface name or sw_if_index");
6441 return -99;
6442 }
6443
6444 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006445 M (SW_INTERFACE_SET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006446
6447 mp->sw_if_index = ntohl (sw_if_index);
6448 mp->is_ipv6 = is_ipv6;
6449 mp->vrf_id = ntohl (vrf_id);
6450
6451 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006452 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006453
6454 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006455 W (ret);
6456 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006457}
6458
6459static void vl_api_sw_interface_get_table_reply_t_handler
6460 (vl_api_sw_interface_get_table_reply_t * mp)
6461{
6462 vat_main_t *vam = &vat_main;
6463
6464 print (vam->ofp, "%d", ntohl (mp->vrf_id));
6465
6466 vam->retval = ntohl (mp->retval);
6467 vam->result_ready = 1;
6468
6469}
6470
6471static void vl_api_sw_interface_get_table_reply_t_handler_json
6472 (vl_api_sw_interface_get_table_reply_t * mp)
6473{
6474 vat_main_t *vam = &vat_main;
6475 vat_json_node_t node;
6476
6477 vat_json_init_object (&node);
6478 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
6479 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
6480
6481 vat_json_print (vam->ofp, &node);
6482 vat_json_free (&node);
6483
6484 vam->retval = ntohl (mp->retval);
6485 vam->result_ready = 1;
6486}
6487
6488static int
6489api_sw_interface_get_table (vat_main_t * vam)
6490{
6491 unformat_input_t *i = vam->input;
6492 vl_api_sw_interface_get_table_t *mp;
6493 u32 sw_if_index;
6494 u8 sw_if_index_set = 0;
6495 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006496 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006497
6498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6499 {
6500 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6501 sw_if_index_set = 1;
6502 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6503 sw_if_index_set = 1;
6504 else if (unformat (i, "ipv6"))
6505 is_ipv6 = 1;
6506 else
6507 break;
6508 }
6509
6510 if (sw_if_index_set == 0)
6511 {
6512 errmsg ("missing interface name or sw_if_index");
6513 return -99;
6514 }
6515
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006516 M (SW_INTERFACE_GET_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006517 mp->sw_if_index = htonl (sw_if_index);
6518 mp->is_ipv6 = is_ipv6;
6519
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006520 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006521 W (ret);
6522 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006523}
6524
6525static int
6526api_sw_interface_set_vpath (vat_main_t * vam)
6527{
6528 unformat_input_t *i = vam->input;
6529 vl_api_sw_interface_set_vpath_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006530 u32 sw_if_index = 0;
6531 u8 sw_if_index_set = 0;
6532 u8 is_enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006533 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006534
6535 /* Parse args required to build the message */
6536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6537 {
6538 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6539 sw_if_index_set = 1;
6540 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6541 sw_if_index_set = 1;
6542 else if (unformat (i, "enable"))
6543 is_enable = 1;
6544 else if (unformat (i, "disable"))
6545 is_enable = 0;
6546 else
6547 break;
6548 }
6549
6550 if (sw_if_index_set == 0)
6551 {
6552 errmsg ("missing interface name or sw_if_index");
6553 return -99;
6554 }
6555
6556 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006557 M (SW_INTERFACE_SET_VPATH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006558
6559 mp->sw_if_index = ntohl (sw_if_index);
6560 mp->enable = is_enable;
6561
6562 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006563 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006564
6565 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006566 W (ret);
6567 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006568}
6569
6570static int
6571api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
6572{
6573 unformat_input_t *i = vam->input;
6574 vl_api_sw_interface_set_vxlan_bypass_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006575 u32 sw_if_index = 0;
6576 u8 sw_if_index_set = 0;
John Lo2b81eb82017-01-30 13:12:10 -05006577 u8 is_enable = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006578 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006579 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006580
6581 /* Parse args required to build the message */
6582 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6583 {
6584 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6585 sw_if_index_set = 1;
6586 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6587 sw_if_index_set = 1;
6588 else if (unformat (i, "enable"))
6589 is_enable = 1;
6590 else if (unformat (i, "disable"))
6591 is_enable = 0;
6592 else if (unformat (i, "ip4"))
6593 is_ipv6 = 0;
6594 else if (unformat (i, "ip6"))
6595 is_ipv6 = 1;
6596 else
6597 break;
6598 }
6599
6600 if (sw_if_index_set == 0)
6601 {
6602 errmsg ("missing interface name or sw_if_index");
6603 return -99;
6604 }
6605
6606 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006607 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006608
6609 mp->sw_if_index = ntohl (sw_if_index);
6610 mp->enable = is_enable;
6611 mp->is_ipv6 = is_ipv6;
6612
6613 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006614 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006615
6616 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06006617 W (ret);
6618 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006619}
6620
Marco Varleseb598f1d2017-09-19 14:25:28 +02006621static int
6622api_sw_interface_set_geneve_bypass (vat_main_t * vam)
6623{
6624 unformat_input_t *i = vam->input;
6625 vl_api_sw_interface_set_geneve_bypass_t *mp;
6626 u32 sw_if_index = 0;
6627 u8 sw_if_index_set = 0;
6628 u8 is_enable = 1;
6629 u8 is_ipv6 = 0;
6630 int ret;
6631
6632 /* Parse args required to build the message */
6633 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6634 {
6635 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6636 sw_if_index_set = 1;
6637 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6638 sw_if_index_set = 1;
6639 else if (unformat (i, "enable"))
6640 is_enable = 1;
6641 else if (unformat (i, "disable"))
6642 is_enable = 0;
6643 else if (unformat (i, "ip4"))
6644 is_ipv6 = 0;
6645 else if (unformat (i, "ip6"))
6646 is_ipv6 = 1;
6647 else
6648 break;
6649 }
6650
6651 if (sw_if_index_set == 0)
6652 {
6653 errmsg ("missing interface name or sw_if_index");
6654 return -99;
6655 }
6656
6657 /* Construct the API message */
6658 M (SW_INTERFACE_SET_GENEVE_BYPASS, mp);
6659
6660 mp->sw_if_index = ntohl (sw_if_index);
6661 mp->enable = is_enable;
6662 mp->is_ipv6 = is_ipv6;
6663
6664 /* send it... */
6665 S (mp);
6666
6667 /* Wait for a reply... */
6668 W (ret);
6669 return ret;
6670}
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +08006671
Damjan Marion7cd468a2016-12-19 23:05:39 +01006672static int
6673api_sw_interface_set_l2_xconnect (vat_main_t * vam)
6674{
6675 unformat_input_t *i = vam->input;
6676 vl_api_sw_interface_set_l2_xconnect_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006677 u32 rx_sw_if_index;
6678 u8 rx_sw_if_index_set = 0;
6679 u32 tx_sw_if_index;
6680 u8 tx_sw_if_index_set = 0;
6681 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006682 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006683
6684 /* Parse args required to build the message */
6685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6686 {
6687 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6688 rx_sw_if_index_set = 1;
6689 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6690 tx_sw_if_index_set = 1;
6691 else if (unformat (i, "rx"))
6692 {
6693 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6694 {
6695 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6696 &rx_sw_if_index))
6697 rx_sw_if_index_set = 1;
6698 }
6699 else
6700 break;
6701 }
6702 else if (unformat (i, "tx"))
6703 {
6704 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6705 {
6706 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6707 &tx_sw_if_index))
6708 tx_sw_if_index_set = 1;
6709 }
6710 else
6711 break;
6712 }
6713 else if (unformat (i, "enable"))
6714 enable = 1;
6715 else if (unformat (i, "disable"))
6716 enable = 0;
6717 else
6718 break;
6719 }
6720
6721 if (rx_sw_if_index_set == 0)
6722 {
6723 errmsg ("missing rx interface name or rx_sw_if_index");
6724 return -99;
6725 }
6726
6727 if (enable && (tx_sw_if_index_set == 0))
6728 {
6729 errmsg ("missing tx interface name or tx_sw_if_index");
6730 return -99;
6731 }
6732
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006733 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006734
6735 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6736 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6737 mp->enable = enable;
6738
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006739 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006740 W (ret);
6741 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006742}
6743
6744static int
6745api_sw_interface_set_l2_bridge (vat_main_t * vam)
6746{
6747 unformat_input_t *i = vam->input;
6748 vl_api_sw_interface_set_l2_bridge_t *mp;
Neale Rannsb4743802018-09-05 09:13:57 -07006749 vl_api_l2_port_type_t port_type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006750 u32 rx_sw_if_index;
6751 u8 rx_sw_if_index_set = 0;
6752 u32 bd_id;
6753 u8 bd_id_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006754 u32 shg = 0;
6755 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006756 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006757
Neale Rannsb4743802018-09-05 09:13:57 -07006758 port_type = L2_API_PORT_TYPE_NORMAL;
6759
Damjan Marion7cd468a2016-12-19 23:05:39 +01006760 /* Parse args required to build the message */
6761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6762 {
6763 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
6764 rx_sw_if_index_set = 1;
6765 else if (unformat (i, "bd_id %d", &bd_id))
6766 bd_id_set = 1;
6767 else
6768 if (unformat
6769 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
6770 rx_sw_if_index_set = 1;
6771 else if (unformat (i, "shg %d", &shg))
6772 ;
6773 else if (unformat (i, "bvi"))
Neale Rannsb4743802018-09-05 09:13:57 -07006774 port_type = L2_API_PORT_TYPE_BVI;
6775 else if (unformat (i, "uu-fwd"))
6776 port_type = L2_API_PORT_TYPE_UU_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006777 else if (unformat (i, "enable"))
6778 enable = 1;
6779 else if (unformat (i, "disable"))
6780 enable = 0;
6781 else
6782 break;
6783 }
6784
6785 if (rx_sw_if_index_set == 0)
6786 {
6787 errmsg ("missing rx interface name or sw_if_index");
6788 return -99;
6789 }
6790
6791 if (enable && (bd_id_set == 0))
6792 {
6793 errmsg ("missing bridge domain");
6794 return -99;
6795 }
6796
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006797 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006798
6799 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6800 mp->bd_id = ntohl (bd_id);
6801 mp->shg = (u8) shg;
Neale Rannsb4743802018-09-05 09:13:57 -07006802 mp->port_type = ntohl (port_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006803 mp->enable = enable;
6804
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006805 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006806 W (ret);
6807 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006808}
6809
6810static int
6811api_bridge_domain_dump (vat_main_t * vam)
6812{
6813 unformat_input_t *i = vam->input;
6814 vl_api_bridge_domain_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006815 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006816 u32 bd_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006817 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006818
6819 /* Parse args required to build the message */
6820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6821 {
6822 if (unformat (i, "bd_id %d", &bd_id))
6823 ;
6824 else
6825 break;
6826 }
6827
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006828 M (BRIDGE_DOMAIN_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006829 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006830 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006831
6832 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04006833 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06006834 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006835
Jon Loeliger56c7b012017-02-01 12:31:41 -06006836 W (ret);
6837 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006838}
6839
6840static int
6841api_bridge_domain_add_del (vat_main_t * vam)
6842{
6843 unformat_input_t *i = vam->input;
6844 vl_api_bridge_domain_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006845 u32 bd_id = ~0;
6846 u8 is_add = 1;
6847 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006848 u8 *bd_tag = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006849 u32 mac_age = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06006850 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006851
6852 /* Parse args required to build the message */
6853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6854 {
6855 if (unformat (i, "bd_id %d", &bd_id))
6856 ;
6857 else if (unformat (i, "flood %d", &flood))
6858 ;
6859 else if (unformat (i, "uu-flood %d", &uu_flood))
6860 ;
6861 else if (unformat (i, "forward %d", &forward))
6862 ;
6863 else if (unformat (i, "learn %d", &learn))
6864 ;
6865 else if (unformat (i, "arp-term %d", &arp_term))
6866 ;
6867 else if (unformat (i, "mac-age %d", &mac_age))
6868 ;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006869 else if (unformat (i, "bd-tag %s", &bd_tag))
6870 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006871 else if (unformat (i, "del"))
6872 {
6873 is_add = 0;
6874 flood = uu_flood = forward = learn = 0;
6875 }
6876 else
6877 break;
6878 }
6879
6880 if (bd_id == ~0)
6881 {
6882 errmsg ("missing bridge domain");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006883 ret = -99;
6884 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006885 }
6886
6887 if (mac_age > 255)
6888 {
6889 errmsg ("mac age must be less than 256 ");
Jerome Tollet50570ec2017-09-14 12:53:56 +01006890 ret = -99;
6891 goto done;
6892 }
6893
John Lo70bfcaf2017-11-14 13:19:26 -05006894 if ((bd_tag) && (vec_len (bd_tag) > 63))
Jerome Tollet50570ec2017-09-14 12:53:56 +01006895 {
6896 errmsg ("bd-tag cannot be longer than 63");
6897 ret = -99;
6898 goto done;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006899 }
6900
Jon Loeliger8a2aea32017-01-31 13:19:40 -06006901 M (BRIDGE_DOMAIN_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01006902
6903 mp->bd_id = ntohl (bd_id);
6904 mp->flood = flood;
6905 mp->uu_flood = uu_flood;
6906 mp->forward = forward;
6907 mp->learn = learn;
6908 mp->arp_term = arp_term;
6909 mp->is_add = is_add;
6910 mp->mac_age = (u8) mac_age;
Jerome Tollet50570ec2017-09-14 12:53:56 +01006911 if (bd_tag)
John Lo70bfcaf2017-11-14 13:19:26 -05006912 {
6913 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
6914 mp->bd_tag[vec_len (bd_tag)] = 0;
6915 }
Jon Loeliger7bc770c2017-01-31 14:03:33 -06006916 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006917 W (ret);
Jerome Tollet50570ec2017-09-14 12:53:56 +01006918
6919done:
6920 vec_free (bd_tag);
Jon Loeliger56c7b012017-02-01 12:31:41 -06006921 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006922}
6923
6924static int
Eyal Barif24991c2017-04-05 05:33:21 +03006925api_l2fib_flush_bd (vat_main_t * vam)
6926{
6927 unformat_input_t *i = vam->input;
6928 vl_api_l2fib_flush_bd_t *mp;
6929 u32 bd_id = ~0;
6930 int ret;
6931
6932 /* Parse args required to build the message */
6933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6934 {
6935 if (unformat (i, "bd_id %d", &bd_id));
6936 else
6937 break;
6938 }
6939
6940 if (bd_id == ~0)
6941 {
6942 errmsg ("missing bridge domain");
6943 return -99;
6944 }
6945
6946 M (L2FIB_FLUSH_BD, mp);
6947
6948 mp->bd_id = htonl (bd_id);
6949
6950 S (mp);
6951 W (ret);
6952 return ret;
6953}
6954
6955static int
6956api_l2fib_flush_int (vat_main_t * vam)
6957{
6958 unformat_input_t *i = vam->input;
6959 vl_api_l2fib_flush_int_t *mp;
6960 u32 sw_if_index = ~0;
6961 int ret;
6962
6963 /* Parse args required to build the message */
6964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6965 {
6966 if (unformat (i, "sw_if_index %d", &sw_if_index));
6967 else
6968 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
6969 else
6970 break;
6971 }
6972
6973 if (sw_if_index == ~0)
6974 {
6975 errmsg ("missing interface name or sw_if_index");
6976 return -99;
6977 }
6978
6979 M (L2FIB_FLUSH_INT, mp);
6980
6981 mp->sw_if_index = ntohl (sw_if_index);
6982
6983 S (mp);
6984 W (ret);
6985 return ret;
6986}
6987
6988static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01006989api_l2fib_add_del (vat_main_t * vam)
6990{
6991 unformat_input_t *i = vam->input;
6992 vl_api_l2fib_add_del_t *mp;
6993 f64 timeout;
Mohsin Kazmi57938f62017-10-27 21:28:07 +02006994 u8 mac[6] = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01006995 u8 mac_set = 0;
6996 u32 bd_id;
6997 u8 bd_id_set = 0;
John Lo7dbd7262018-05-31 10:25:18 -04006998 u32 sw_if_index = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01006999 u8 sw_if_index_set = 0;
7000 u8 is_add = 1;
7001 u8 static_mac = 0;
7002 u8 filter_mac = 0;
7003 u8 bvi_mac = 0;
7004 int count = 1;
7005 f64 before = 0;
7006 int j;
7007
7008 /* Parse args required to build the message */
7009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7010 {
Mohsin Kazmi57938f62017-10-27 21:28:07 +02007011 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007012 mac_set = 1;
7013 else if (unformat (i, "bd_id %d", &bd_id))
7014 bd_id_set = 1;
7015 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7016 sw_if_index_set = 1;
7017 else if (unformat (i, "sw_if"))
7018 {
7019 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7020 {
7021 if (unformat
7022 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7023 sw_if_index_set = 1;
7024 }
7025 else
7026 break;
7027 }
7028 else if (unformat (i, "static"))
7029 static_mac = 1;
7030 else if (unformat (i, "filter"))
7031 {
7032 filter_mac = 1;
7033 static_mac = 1;
7034 }
7035 else if (unformat (i, "bvi"))
7036 {
7037 bvi_mac = 1;
7038 static_mac = 1;
7039 }
7040 else if (unformat (i, "del"))
7041 is_add = 0;
7042 else if (unformat (i, "count %d", &count))
7043 ;
7044 else
7045 break;
7046 }
7047
7048 if (mac_set == 0)
7049 {
7050 errmsg ("missing mac address");
7051 return -99;
7052 }
7053
7054 if (bd_id_set == 0)
7055 {
7056 errmsg ("missing bridge domain");
7057 return -99;
7058 }
7059
7060 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
7061 {
7062 errmsg ("missing interface name or sw_if_index");
7063 return -99;
7064 }
7065
7066 if (count > 1)
7067 {
7068 /* Turn on async mode */
7069 vam->async_mode = 1;
7070 vam->async_errors = 0;
7071 before = vat_time_now (vam);
7072 }
7073
7074 for (j = 0; j < count; j++)
7075 {
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007076 M (L2FIB_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007077
Mohsin Kazmi57938f62017-10-27 21:28:07 +02007078 clib_memcpy (mp->mac, mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007079 mp->bd_id = ntohl (bd_id);
7080 mp->is_add = is_add;
John Lo7dbd7262018-05-31 10:25:18 -04007081 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007082
7083 if (is_add)
7084 {
Damjan Marion7cd468a2016-12-19 23:05:39 +01007085 mp->static_mac = static_mac;
7086 mp->filter_mac = filter_mac;
7087 mp->bvi_mac = bvi_mac;
7088 }
Mohsin Kazmi57938f62017-10-27 21:28:07 +02007089 increment_mac_address (mac);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007090 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007091 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007092 }
7093
7094 if (count > 1)
7095 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06007096 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007097 f64 after;
7098
7099 /* Shut off async mode */
7100 vam->async_mode = 0;
7101
Dave Barach59b25652017-09-10 15:04:27 -04007102 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06007103 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007104
7105 timeout = vat_time_now (vam) + 1.0;
7106 while (vat_time_now (vam) < timeout)
7107 if (vam->result_ready == 1)
7108 goto out;
7109 vam->retval = -99;
7110
7111 out:
7112 if (vam->retval == -99)
7113 errmsg ("timeout");
7114
7115 if (vam->async_errors > 0)
7116 {
7117 errmsg ("%d asynchronous errors", vam->async_errors);
7118 vam->retval = -98;
7119 }
7120 vam->async_errors = 0;
7121 after = vat_time_now (vam);
7122
7123 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
7124 count, after - before, count / (after - before));
7125 }
7126 else
7127 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06007128 int ret;
7129
Damjan Marion7cd468a2016-12-19 23:05:39 +01007130 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06007131 W (ret);
7132 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007133 }
7134 /* Return the good/bad news */
7135 return (vam->retval);
7136}
7137
7138static int
Eyal Barifead6702017-04-04 04:46:32 +03007139api_bridge_domain_set_mac_age (vat_main_t * vam)
7140{
7141 unformat_input_t *i = vam->input;
7142 vl_api_bridge_domain_set_mac_age_t *mp;
7143 u32 bd_id = ~0;
7144 u32 mac_age = 0;
7145 int ret;
7146
7147 /* Parse args required to build the message */
7148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7149 {
7150 if (unformat (i, "bd_id %d", &bd_id));
7151 else if (unformat (i, "mac-age %d", &mac_age));
7152 else
7153 break;
7154 }
7155
7156 if (bd_id == ~0)
7157 {
7158 errmsg ("missing bridge domain");
7159 return -99;
7160 }
7161
7162 if (mac_age > 255)
7163 {
7164 errmsg ("mac age must be less than 256 ");
7165 return -99;
7166 }
7167
7168 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
7169
7170 mp->bd_id = htonl (bd_id);
7171 mp->mac_age = (u8) mac_age;
7172
7173 S (mp);
7174 W (ret);
7175 return ret;
7176}
7177
7178static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01007179api_l2_flags (vat_main_t * vam)
7180{
7181 unformat_input_t *i = vam->input;
7182 vl_api_l2_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007183 u32 sw_if_index;
John Lo8d00fff2017-08-03 00:35:36 -04007184 u32 flags = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007185 u8 sw_if_index_set = 0;
John Lo8d00fff2017-08-03 00:35:36 -04007186 u8 is_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007187 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007188
7189 /* Parse args required to build the message */
7190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7191 {
7192 if (unformat (i, "sw_if_index %d", &sw_if_index))
7193 sw_if_index_set = 1;
7194 else if (unformat (i, "sw_if"))
7195 {
7196 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7197 {
7198 if (unformat
7199 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7200 sw_if_index_set = 1;
7201 }
7202 else
7203 break;
7204 }
7205 else if (unformat (i, "learn"))
John Lo8d00fff2017-08-03 00:35:36 -04007206 flags |= L2_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007207 else if (unformat (i, "forward"))
John Lo8d00fff2017-08-03 00:35:36 -04007208 flags |= L2_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007209 else if (unformat (i, "flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007210 flags |= L2_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007211 else if (unformat (i, "uu-flood"))
John Lo8d00fff2017-08-03 00:35:36 -04007212 flags |= L2_UU_FLOOD;
7213 else if (unformat (i, "arp-term"))
7214 flags |= L2_ARP_TERM;
7215 else if (unformat (i, "off"))
7216 is_set = 0;
7217 else if (unformat (i, "disable"))
7218 is_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007219 else
7220 break;
7221 }
7222
7223 if (sw_if_index_set == 0)
7224 {
7225 errmsg ("missing interface name or sw_if_index");
7226 return -99;
7227 }
7228
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007229 M (L2_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007230
7231 mp->sw_if_index = ntohl (sw_if_index);
John Lo8d00fff2017-08-03 00:35:36 -04007232 mp->feature_bitmap = ntohl (flags);
7233 mp->is_set = is_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007234
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007235 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007236 W (ret);
7237 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007238}
7239
7240static int
7241api_bridge_flags (vat_main_t * vam)
7242{
7243 unformat_input_t *i = vam->input;
7244 vl_api_bridge_flags_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007245 u32 bd_id;
7246 u8 bd_id_set = 0;
7247 u8 is_set = 1;
Neale Rannsb4743802018-09-05 09:13:57 -07007248 bd_flags_t flags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06007249 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007250
7251 /* Parse args required to build the message */
7252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7253 {
7254 if (unformat (i, "bd_id %d", &bd_id))
7255 bd_id_set = 1;
7256 else if (unformat (i, "learn"))
Neale Rannsb4743802018-09-05 09:13:57 -07007257 flags |= BRIDGE_API_FLAG_LEARN;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007258 else if (unformat (i, "forward"))
Neale Rannsb4743802018-09-05 09:13:57 -07007259 flags |= BRIDGE_API_FLAG_FWD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007260 else if (unformat (i, "flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007261 flags |= BRIDGE_API_FLAG_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007262 else if (unformat (i, "uu-flood"))
Neale Rannsb4743802018-09-05 09:13:57 -07007263 flags |= BRIDGE_API_FLAG_UU_FLOOD;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007264 else if (unformat (i, "arp-term"))
Neale Rannsb4743802018-09-05 09:13:57 -07007265 flags |= BRIDGE_API_FLAG_ARP_TERM;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007266 else if (unformat (i, "off"))
7267 is_set = 0;
7268 else if (unformat (i, "disable"))
7269 is_set = 0;
7270 else
7271 break;
7272 }
7273
7274 if (bd_id_set == 0)
7275 {
7276 errmsg ("missing bridge domain");
7277 return -99;
7278 }
7279
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007280 M (BRIDGE_FLAGS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007281
7282 mp->bd_id = ntohl (bd_id);
Neale Rannsb4743802018-09-05 09:13:57 -07007283 mp->flags = ntohl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007284 mp->is_set = is_set;
7285
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007286 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007287 W (ret);
7288 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007289}
7290
7291static int
7292api_bd_ip_mac_add_del (vat_main_t * vam)
7293{
Neale Ranns4d5b9172018-10-24 02:57:49 -07007294 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
Ole Troan8006c6a2018-12-17 12:02:26 +01007295 vl_api_mac_address_t mac = { 0 };
Damjan Marion7cd468a2016-12-19 23:05:39 +01007296 unformat_input_t *i = vam->input;
7297 vl_api_bd_ip_mac_add_del_t *mp;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007298 ip46_type_t type;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007299 u32 bd_id;
7300 u8 is_ipv6 = 0;
7301 u8 is_add = 1;
7302 u8 bd_id_set = 0;
7303 u8 ip_set = 0;
7304 u8 mac_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007305 u8 macaddr[6];
Jon Loeliger56c7b012017-02-01 12:31:41 -06007306 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007307
7308
7309 /* Parse args required to build the message */
7310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7311 {
7312 if (unformat (i, "bd_id %d", &bd_id))
7313 {
7314 bd_id_set++;
7315 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007316 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007317 {
7318 ip_set++;
7319 }
Neale Ranns4d5b9172018-10-24 02:57:49 -07007320 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
Damjan Marion7cd468a2016-12-19 23:05:39 +01007321 {
7322 mac_set++;
7323 }
7324 else if (unformat (i, "del"))
7325 is_add = 0;
7326 else
7327 break;
7328 }
7329
7330 if (bd_id_set == 0)
7331 {
7332 errmsg ("missing bridge domain");
7333 return -99;
7334 }
7335 else if (ip_set == 0)
7336 {
7337 errmsg ("missing IP address");
7338 return -99;
7339 }
7340 else if (mac_set == 0)
7341 {
7342 errmsg ("missing MAC address");
7343 return -99;
7344 }
7345
Jon Loeliger8a2aea32017-01-31 13:19:40 -06007346 M (BD_IP_MAC_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007347
7348 mp->bd_id = ntohl (bd_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01007349 mp->is_add = is_add;
Neale Ranns4d5b9172018-10-24 02:57:49 -07007350
7351 clib_memcpy (&mp->ip, &ip, sizeof (ip));
7352 clib_memcpy (&mp->mac, &mac, sizeof (mac));
7353
Jon Loeliger7bc770c2017-01-31 14:03:33 -06007354 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06007355 W (ret);
7356 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01007357}
7358
John Loe26c81f2019-01-07 15:16:33 -05007359static int
7360api_bd_ip_mac_flush (vat_main_t * vam)
7361{
7362 unformat_input_t *i = vam->input;
7363 vl_api_bd_ip_mac_flush_t *mp;
7364 u32 bd_id;
7365 u8 bd_id_set = 0;
7366 int ret;
7367
7368 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7369 {
7370 if (unformat (i, "bd_id %d", &bd_id))
7371 {
7372 bd_id_set++;
7373 }
7374 else
7375 break;
7376 }
7377
7378 if (bd_id_set == 0)
7379 {
7380 errmsg ("missing bridge domain");
7381 return -99;
7382 }
7383
7384 M (BD_IP_MAC_FLUSH, mp);
7385
7386 mp->bd_id = ntohl (bd_id);
7387
7388 S (mp);
7389 W (ret);
7390 return ret;
7391}
7392
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007393static void vl_api_bd_ip_mac_details_t_handler
7394 (vl_api_bd_ip_mac_details_t * mp)
7395{
7396 vat_main_t *vam = &vat_main;
7397 u8 *ip = 0;
7398
7399 if (!mp->is_ipv6)
7400 ip =
7401 format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address);
7402 else
7403 ip =
7404 format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address);
7405
7406 print (vam->ofp,
7407 "\n%-5d %-7s %-20U %-30s",
7408 ntohl (mp->bd_id), mp->is_ipv6 ? "ip6" : "ip4",
7409 format_ethernet_address, mp->mac_address, ip);
7410
7411 vec_free (ip);
7412}
7413
7414static void vl_api_bd_ip_mac_details_t_handler_json
7415 (vl_api_bd_ip_mac_details_t * mp)
7416{
7417 vat_main_t *vam = &vat_main;
7418 vat_json_node_t *node = NULL;
7419
7420 if (VAT_JSON_ARRAY != vam->json_tree.type)
7421 {
7422 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7423 vat_json_init_array (&vam->json_tree);
7424 }
7425 node = vat_json_array_add (&vam->json_tree);
7426
7427 vat_json_init_object (node);
7428 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi0d8cbc12018-09-11 13:06:42 +02007429 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6);
Mohsin Kazmi5d82d2f2018-08-13 19:17:54 +02007430 vat_json_object_add_string_copy (node, "mac_address",
7431 format (0, "%U", format_ethernet_address,
7432 &mp->mac_address));
7433 u8 *ip = 0;
7434
7435 if (!mp->is_ipv6)
7436 ip =
7437 format (0, "%U", format_ip4_address, (ip4_address_t *) mp->ip_address);
7438 else
7439 ip =
7440 format (0, "%U", format_ip6_address, (ip6_address_t *) mp->ip_address);
7441 vat_json_object_add_string_copy (node, "ip_address", ip);
7442 vec_free (ip);
7443}
7444
7445static int
7446api_bd_ip_mac_dump (vat_main_t * vam)
7447{
7448 unformat_input_t *i = vam->input;
7449 vl_api_bd_ip_mac_dump_t *mp;
7450 vl_api_control_ping_t *mp_ping;
7451 int ret;
7452 u32 bd_id;
7453 u8 bd_id_set = 0;
7454
7455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7456 {
7457 if (unformat (i, "bd_id %d", &bd_id))
7458 {
7459 bd_id_set++;
7460 }
7461 else
7462 break;
7463 }
7464
7465 print (vam->ofp,
7466 "\n%-5s %-7s %-20s %-30s",
7467 "bd_id", "is_ipv6", "mac_address", "ip_address");
7468
7469 /* Dump Bridge Domain Ip to Mac entries */
7470 M (BD_IP_MAC_DUMP, mp);
7471
7472 if (bd_id_set)
7473 mp->bd_id = htonl (bd_id);
7474 else
7475 mp->bd_id = ~0;
7476
7477 S (mp);
7478
7479 /* Use a control ping for synchronization */
7480 MPING (CONTROL_PING, mp_ping);
7481 S (mp_ping);
7482
7483 W (ret);
7484 return ret;
7485}
7486
Damjan Marion7cd468a2016-12-19 23:05:39 +01007487static int
Damjan Marion8389fb92017-10-13 18:29:53 +02007488api_tap_create_v2 (vat_main_t * vam)
7489{
7490 unformat_input_t *i = vam->input;
7491 vl_api_tap_create_v2_t *mp;
7492 u8 mac_address[6];
7493 u8 random_mac = 1;
Damjan Marion2df39092017-12-04 20:03:37 +01007494 u32 id = ~0;
7495 u8 *host_if_name = 0;
7496 u8 *host_ns = 0;
7497 u8 host_mac_addr[6];
7498 u8 host_mac_addr_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007499 u8 *host_bridge = 0;
7500 ip4_address_t host_ip4_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007501 ip4_address_t host_ip4_gw;
7502 u8 host_ip4_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007503 u32 host_ip4_prefix_len = 0;
7504 ip6_address_t host_ip6_addr;
Damjan Marion7866c452018-01-18 13:35:11 +01007505 ip6_address_t host_ip6_gw;
7506 u8 host_ip6_gw_set = 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007507 u32 host_ip6_prefix_len = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007508 int ret;
Steven9e635692018-03-01 09:36:01 -08007509 u32 rx_ring_sz = 0, tx_ring_sz = 0;
Damjan Marion8389fb92017-10-13 18:29:53 +02007510
Dave Barachb7b92992018-10-17 10:38:51 -04007511 clib_memset (mac_address, 0, sizeof (mac_address));
Damjan Marion8389fb92017-10-13 18:29:53 +02007512
7513 /* Parse args required to build the message */
7514 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7515 {
7516 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7517 {
7518 random_mac = 0;
7519 }
Steven9e635692018-03-01 09:36:01 -08007520 else if (unformat (i, "id %u", &id))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007521 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007522 else if (unformat (i, "host-if-name %s", &host_if_name))
Damjan Marion91c6ef72017-12-01 13:34:24 +01007523 ;
Damjan Marion2df39092017-12-04 20:03:37 +01007524 else if (unformat (i, "host-ns %s", &host_ns))
7525 ;
7526 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
7527 host_mac_addr))
7528 host_mac_addr_set = 1;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007529 else if (unformat (i, "host-bridge %s", &host_bridge))
7530 ;
7531 else if (unformat (i, "host-ip4-addr %U/%d", unformat_ip4_address,
7532 &host_ip4_addr, &host_ip4_prefix_len))
7533 ;
7534 else if (unformat (i, "host-ip6-addr %U/%d", unformat_ip6_address,
7535 &host_ip6_addr, &host_ip6_prefix_len))
7536 ;
Damjan Marion7866c452018-01-18 13:35:11 +01007537 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
7538 &host_ip4_gw))
7539 host_ip4_gw_set = 1;
7540 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
7541 &host_ip6_gw))
7542 host_ip6_gw_set = 1;
Damjan Marion8389fb92017-10-13 18:29:53 +02007543 else if (unformat (i, "rx-ring-size %d", &rx_ring_sz))
7544 ;
7545 else if (unformat (i, "tx-ring-size %d", &tx_ring_sz))
7546 ;
7547 else
7548 break;
7549 }
7550
Damjan Marion2df39092017-12-04 20:03:37 +01007551 if (vec_len (host_if_name) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007552 {
7553 errmsg ("tap name too long. ");
7554 return -99;
7555 }
Damjan Marion2df39092017-12-04 20:03:37 +01007556 if (vec_len (host_ns) > 63)
Damjan Marion8389fb92017-10-13 18:29:53 +02007557 {
7558 errmsg ("host name space too long. ");
7559 return -99;
7560 }
Damjan Marion91c6ef72017-12-01 13:34:24 +01007561 if (vec_len (host_bridge) > 63)
7562 {
7563 errmsg ("host bridge name too long. ");
7564 return -99;
7565 }
7566 if (host_ip4_prefix_len > 32)
7567 {
7568 errmsg ("host ip4 prefix length not valid. ");
7569 return -99;
7570 }
7571 if (host_ip6_prefix_len > 128)
7572 {
7573 errmsg ("host ip6 prefix length not valid. ");
7574 return -99;
7575 }
Damjan Marion8389fb92017-10-13 18:29:53 +02007576 if (!is_pow2 (rx_ring_sz))
7577 {
7578 errmsg ("rx ring size must be power of 2. ");
7579 return -99;
7580 }
7581 if (rx_ring_sz > 32768)
7582 {
7583 errmsg ("rx ring size must be 32768 or lower. ");
7584 return -99;
7585 }
7586 if (!is_pow2 (tx_ring_sz))
7587 {
7588 errmsg ("tx ring size must be power of 2. ");
7589 return -99;
7590 }
7591 if (tx_ring_sz > 32768)
7592 {
7593 errmsg ("tx ring size must be 32768 or lower. ");
7594 return -99;
7595 }
7596
Damjan Marion8389fb92017-10-13 18:29:53 +02007597 /* Construct the API message */
7598 M (TAP_CREATE_V2, mp);
7599
7600 mp->use_random_mac = random_mac;
Damjan Marion2df39092017-12-04 20:03:37 +01007601
Steven9e635692018-03-01 09:36:01 -08007602 mp->id = ntohl (id);
Damjan Marion2df39092017-12-04 20:03:37 +01007603 mp->host_namespace_set = host_ns != 0;
Damjan Marion91c6ef72017-12-01 13:34:24 +01007604 mp->host_bridge_set = host_bridge != 0;
7605 mp->host_ip4_addr_set = host_ip4_prefix_len != 0;
7606 mp->host_ip6_addr_set = host_ip6_prefix_len != 0;
Steven9e635692018-03-01 09:36:01 -08007607 mp->rx_ring_sz = ntohs (rx_ring_sz);
7608 mp->tx_ring_sz = ntohs (tx_ring_sz);
Damjan Marion2df39092017-12-04 20:03:37 +01007609
Steven9e635692018-03-01 09:36:01 -08007610 if (random_mac == 0)
Damjan Marion2df39092017-12-04 20:03:37 +01007611 clib_memcpy (mp->mac_address, mac_address, 6);
7612 if (host_mac_addr_set)
7613 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
7614 if (host_if_name)
7615 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7616 if (host_ns)
7617 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
Damjan Marion91c6ef72017-12-01 13:34:24 +01007618 if (host_bridge)
7619 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
7620 if (host_ip4_prefix_len)
7621 clib_memcpy (mp->host_ip4_addr, &host_ip4_addr, 4);
Michal Cmarada87460d02018-10-17 13:40:32 +02007622 if (host_ip6_prefix_len)
Damjan Marion91c6ef72017-12-01 13:34:24 +01007623 clib_memcpy (mp->host_ip6_addr, &host_ip6_addr, 16);
Damjan Marion7866c452018-01-18 13:35:11 +01007624 if (host_ip4_gw_set)
7625 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
7626 if (host_ip6_gw_set)
7627 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
Damjan Marion8389fb92017-10-13 18:29:53 +02007628
Damjan Marion2df39092017-12-04 20:03:37 +01007629 vec_free (host_ns);
7630 vec_free (host_if_name);
7631 vec_free (host_bridge);
Damjan Marion8389fb92017-10-13 18:29:53 +02007632
7633 /* send it... */
7634 S (mp);
7635
7636 /* Wait for a reply... */
7637 W (ret);
7638 return ret;
7639}
7640
7641static int
7642api_tap_delete_v2 (vat_main_t * vam)
7643{
7644 unformat_input_t *i = vam->input;
7645 vl_api_tap_delete_v2_t *mp;
7646 u32 sw_if_index = ~0;
7647 u8 sw_if_index_set = 0;
7648 int ret;
7649
7650 /* Parse args required to build the message */
7651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7652 {
7653 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7654 sw_if_index_set = 1;
7655 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7656 sw_if_index_set = 1;
7657 else
7658 break;
7659 }
7660
7661 if (sw_if_index_set == 0)
7662 {
7663 errmsg ("missing vpp interface name. ");
7664 return -99;
7665 }
7666
7667 /* Construct the API message */
7668 M (TAP_DELETE_V2, mp);
7669
7670 mp->sw_if_index = ntohl (sw_if_index);
7671
7672 /* send it... */
7673 S (mp);
7674
7675 /* Wait for a reply... */
7676 W (ret);
7677 return ret;
7678}
7679
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +01007680uword
7681unformat_pci_addr (unformat_input_t * input, va_list * args)
7682{
7683 struct pci_addr_t
7684 {
7685 u16 domain;
7686 u8 bus;
7687 u8 slot:5;
7688 u8 function:3;
7689 } *addr;
7690 addr = va_arg (*args, struct pci_addr_t *);
7691 u32 x[4];
7692
7693 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
7694 return 0;
7695
7696 addr->domain = x[0];
7697 addr->bus = x[1];
7698 addr->slot = x[2];
7699 addr->function = x[3];
7700
7701 return 1;
7702}
7703
7704static int
7705api_virtio_pci_create (vat_main_t * vam)
7706{
7707 unformat_input_t *i = vam->input;
7708 vl_api_virtio_pci_create_t *mp;
7709 u8 mac_address[6];
7710 u8 random_mac = 1;
7711 u32 pci_addr = 0;
7712 u64 features = (u64) ~ (0ULL);
7713 u32 rx_ring_sz = 0, tx_ring_sz = 0;
7714 int ret;
7715
7716 clib_memset (mac_address, 0, sizeof (mac_address));
7717
7718 /* Parse args required to build the message */
7719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7720 {
7721 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
7722 {
7723 random_mac = 0;
7724 }
7725 else if (unformat (i, "pci-addr %U", unformat_pci_addr, &pci_addr))
7726 ;
7727 else if (unformat (i, "features 0x%llx", &features))
7728 ;
7729 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
7730 ;
7731 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
7732 ;
7733 else
7734 break;
7735 }
7736
7737 if (pci_addr == 0)
7738 {
7739 errmsg ("pci address must be non zero. ");
7740 return -99;
7741 }
7742 if (!is_pow2 (rx_ring_sz))
7743 {
7744 errmsg ("rx ring size must be power of 2. ");
7745 return -99;
7746 }
7747 if (rx_ring_sz > 32768)
7748 {
7749 errmsg ("rx ring size must be 32768 or lower. ");
7750 return -99;
7751 }
7752 if (!is_pow2 (tx_ring_sz))
7753 {
7754 errmsg ("tx ring size must be power of 2. ");
7755 return -99;
7756 }
7757 if (tx_ring_sz > 32768)
7758 {
7759 errmsg ("tx ring size must be 32768 or lower. ");
7760 return -99;
7761 }
7762
7763 /* Construct the API message */
7764 M (VIRTIO_PCI_CREATE, mp);
7765
7766 mp->use_random_mac = random_mac;
7767
7768 mp->pci_addr = htonl (pci_addr);
7769 mp->features = clib_host_to_net_u64 (features);
7770 mp->rx_ring_sz = htons (rx_ring_sz);
7771 mp->tx_ring_sz = htons (tx_ring_sz);
7772
7773 if (random_mac == 0)
7774 clib_memcpy (mp->mac_address, mac_address, 6);
7775
7776 /* send it... */
7777 S (mp);
7778
7779 /* Wait for a reply... */
7780 W (ret);
7781 return ret;
7782}
7783
7784static int
7785api_virtio_pci_delete (vat_main_t * vam)
7786{
7787 unformat_input_t *i = vam->input;
7788 vl_api_virtio_pci_delete_t *mp;
7789 u32 sw_if_index = ~0;
7790 u8 sw_if_index_set = 0;
7791 int ret;
7792
7793 /* Parse args required to build the message */
7794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7795 {
7796 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7797 sw_if_index_set = 1;
7798 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7799 sw_if_index_set = 1;
7800 else
7801 break;
7802 }
7803
7804 if (sw_if_index_set == 0)
7805 {
7806 errmsg ("missing vpp interface name. ");
7807 return -99;
7808 }
7809
7810 /* Construct the API message */
7811 M (VIRTIO_PCI_DELETE, mp);
7812
7813 mp->sw_if_index = htonl (sw_if_index);
7814
7815 /* send it... */
7816 S (mp);
7817
7818 /* Wait for a reply... */
7819 W (ret);
7820 return ret;
7821}
7822
Damjan Marion8389fb92017-10-13 18:29:53 +02007823static int
Steven9cd2d7a2017-12-20 12:43:01 -08007824api_bond_create (vat_main_t * vam)
7825{
7826 unformat_input_t *i = vam->input;
7827 vl_api_bond_create_t *mp;
7828 u8 mac_address[6];
7829 u8 custom_mac = 0;
7830 int ret;
7831 u8 mode;
7832 u8 lb;
7833 u8 mode_is_set = 0;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007834 u32 id = ~0;
Steven9cd2d7a2017-12-20 12:43:01 -08007835
Dave Barachb7b92992018-10-17 10:38:51 -04007836 clib_memset (mac_address, 0, sizeof (mac_address));
Steven9cd2d7a2017-12-20 12:43:01 -08007837 lb = BOND_LB_L2;
7838
7839 /* Parse args required to build the message */
7840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7841 {
7842 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
7843 mode_is_set = 1;
7844 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
7845 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
7846 ;
7847 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
7848 mac_address))
7849 custom_mac = 1;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007850 else if (unformat (i, "id %u", &id))
7851 ;
Steven9cd2d7a2017-12-20 12:43:01 -08007852 else
7853 break;
7854 }
7855
7856 if (mode_is_set == 0)
7857 {
7858 errmsg ("Missing bond mode. ");
7859 return -99;
7860 }
7861
7862 /* Construct the API message */
7863 M (BOND_CREATE, mp);
7864
7865 mp->use_custom_mac = custom_mac;
7866
7867 mp->mode = mode;
7868 mp->lb = lb;
Alexander Chernavinad9d5282018-12-13 09:08:09 -05007869 mp->id = htonl (id);
Steven9cd2d7a2017-12-20 12:43:01 -08007870
7871 if (custom_mac)
7872 clib_memcpy (mp->mac_address, mac_address, 6);
7873
7874 /* send it... */
7875 S (mp);
7876
7877 /* Wait for a reply... */
7878 W (ret);
7879 return ret;
7880}
7881
7882static int
7883api_bond_delete (vat_main_t * vam)
7884{
7885 unformat_input_t *i = vam->input;
7886 vl_api_bond_delete_t *mp;
7887 u32 sw_if_index = ~0;
7888 u8 sw_if_index_set = 0;
7889 int ret;
7890
7891 /* Parse args required to build the message */
7892 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7893 {
7894 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7895 sw_if_index_set = 1;
7896 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7897 sw_if_index_set = 1;
7898 else
7899 break;
7900 }
7901
7902 if (sw_if_index_set == 0)
7903 {
7904 errmsg ("missing vpp interface name. ");
7905 return -99;
7906 }
7907
7908 /* Construct the API message */
7909 M (BOND_DELETE, mp);
7910
7911 mp->sw_if_index = ntohl (sw_if_index);
7912
7913 /* send it... */
7914 S (mp);
7915
7916 /* Wait for a reply... */
7917 W (ret);
7918 return ret;
7919}
7920
7921static int
7922api_bond_enslave (vat_main_t * vam)
7923{
7924 unformat_input_t *i = vam->input;
7925 vl_api_bond_enslave_t *mp;
7926 u32 bond_sw_if_index;
7927 int ret;
7928 u8 is_passive;
7929 u8 is_long_timeout;
7930 u32 bond_sw_if_index_is_set = 0;
7931 u32 sw_if_index;
7932 u8 sw_if_index_is_set = 0;
7933
7934 /* Parse args required to build the message */
7935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7936 {
7937 if (unformat (i, "sw_if_index %d", &sw_if_index))
7938 sw_if_index_is_set = 1;
7939 else if (unformat (i, "bond %u", &bond_sw_if_index))
7940 bond_sw_if_index_is_set = 1;
7941 else if (unformat (i, "passive %d", &is_passive))
7942 ;
7943 else if (unformat (i, "long-timeout %d", &is_long_timeout))
7944 ;
7945 else
7946 break;
7947 }
7948
7949 if (bond_sw_if_index_is_set == 0)
7950 {
7951 errmsg ("Missing bond sw_if_index. ");
7952 return -99;
7953 }
7954 if (sw_if_index_is_set == 0)
7955 {
7956 errmsg ("Missing slave sw_if_index. ");
7957 return -99;
7958 }
7959
7960 /* Construct the API message */
7961 M (BOND_ENSLAVE, mp);
7962
7963 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
7964 mp->sw_if_index = ntohl (sw_if_index);
7965 mp->is_long_timeout = is_long_timeout;
7966 mp->is_passive = is_passive;
7967
7968 /* send it... */
7969 S (mp);
7970
7971 /* Wait for a reply... */
7972 W (ret);
7973 return ret;
7974}
7975
7976static int
7977api_bond_detach_slave (vat_main_t * vam)
7978{
7979 unformat_input_t *i = vam->input;
7980 vl_api_bond_detach_slave_t *mp;
7981 u32 sw_if_index = ~0;
7982 u8 sw_if_index_set = 0;
7983 int ret;
7984
7985 /* Parse args required to build the message */
7986 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7987 {
7988 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7989 sw_if_index_set = 1;
7990 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7991 sw_if_index_set = 1;
7992 else
7993 break;
7994 }
7995
7996 if (sw_if_index_set == 0)
7997 {
7998 errmsg ("missing vpp interface name. ");
7999 return -99;
8000 }
8001
8002 /* Construct the API message */
8003 M (BOND_DETACH_SLAVE, mp);
8004
8005 mp->sw_if_index = ntohl (sw_if_index);
8006
8007 /* send it... */
8008 S (mp);
8009
8010 /* Wait for a reply... */
8011 W (ret);
8012 return ret;
8013}
8014
8015static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008016api_ip_table_add_del (vat_main_t * vam)
8017{
8018 unformat_input_t *i = vam->input;
8019 vl_api_ip_table_add_del_t *mp;
8020 u32 table_id = ~0;
8021 u8 is_ipv6 = 0;
8022 u8 is_add = 1;
8023 int ret = 0;
8024
8025 /* Parse args required to build the message */
8026 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8027 {
8028 if (unformat (i, "ipv6"))
8029 is_ipv6 = 1;
8030 else if (unformat (i, "del"))
8031 is_add = 0;
8032 else if (unformat (i, "add"))
8033 is_add = 1;
8034 else if (unformat (i, "table %d", &table_id))
8035 ;
8036 else
8037 {
8038 clib_warning ("parse error '%U'", format_unformat_error, i);
8039 return -99;
8040 }
8041 }
8042
8043 if (~0 == table_id)
8044 {
8045 errmsg ("missing table-ID");
8046 return -99;
8047 }
8048
8049 /* Construct the API message */
8050 M (IP_TABLE_ADD_DEL, mp);
8051
8052 mp->table_id = ntohl (table_id);
8053 mp->is_ipv6 = is_ipv6;
8054 mp->is_add = is_add;
8055
8056 /* send it... */
8057 S (mp);
8058
8059 /* Wait for a reply... */
8060 W (ret);
8061
8062 return ret;
8063}
8064
8065static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008066api_ip_add_del_route (vat_main_t * vam)
8067{
8068 unformat_input_t *i = vam->input;
8069 vl_api_ip_add_del_route_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008070 u32 sw_if_index = ~0, vrf_id = 0;
8071 u8 is_ipv6 = 0;
8072 u8 is_local = 0, is_drop = 0;
8073 u8 is_unreach = 0, is_prohibit = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008074 u8 is_add = 1;
8075 u32 next_hop_weight = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008076 u8 is_multipath = 0;
8077 u8 address_set = 0;
8078 u8 address_length_set = 0;
8079 u32 next_hop_table_id = 0;
8080 u32 resolve_attempts = 0;
8081 u32 dst_address_length = 0;
8082 u8 next_hop_set = 0;
8083 ip4_address_t v4_dst_address, v4_next_hop_address;
8084 ip6_address_t v6_dst_address, v6_next_hop_address;
8085 int count = 1;
8086 int j;
8087 f64 before = 0;
8088 u32 random_add_del = 0;
8089 u32 *random_vector = 0;
8090 uword *random_hash;
8091 u32 random_seed = 0xdeaddabe;
8092 u32 classify_table_index = ~0;
8093 u8 is_classify = 0;
8094 u8 resolve_host = 0, resolve_attached = 0;
John Loe166fd92018-09-13 14:08:59 -04008095 vl_api_fib_mpls_label_t *next_hop_out_label_stack = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008096 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
8097 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
8098
Dave Barachb7b92992018-10-17 10:38:51 -04008099 clib_memset (&v4_next_hop_address, 0, sizeof (ip4_address_t));
8100 clib_memset (&v6_next_hop_address, 0, sizeof (ip6_address_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008101 /* Parse args required to build the message */
8102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8103 {
8104 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8105 ;
8106 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8107 ;
8108 else if (unformat (i, "%U", unformat_ip4_address, &v4_dst_address))
8109 {
8110 address_set = 1;
8111 is_ipv6 = 0;
8112 }
8113 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address))
8114 {
8115 address_set = 1;
8116 is_ipv6 = 1;
8117 }
8118 else if (unformat (i, "/%d", &dst_address_length))
8119 {
8120 address_length_set = 1;
8121 }
8122
8123 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
8124 &v4_next_hop_address))
8125 {
8126 next_hop_set = 1;
8127 }
8128 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
8129 &v6_next_hop_address))
8130 {
8131 next_hop_set = 1;
8132 }
John Lo22030432018-09-20 16:07:00 -04008133 else
8134 if (unformat
8135 (i, "via %U", api_unformat_sw_if_index, vam, &sw_if_index))
8136 {
8137 next_hop_set = 1;
8138 }
8139 else if (unformat (i, "via sw_if_index %d", &sw_if_index))
8140 {
8141 next_hop_set = 1;
8142 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008143 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
8144 ;
8145 else if (unformat (i, "weight %d", &next_hop_weight))
8146 ;
8147 else if (unformat (i, "drop"))
8148 {
8149 is_drop = 1;
8150 }
8151 else if (unformat (i, "null-send-unreach"))
8152 {
8153 is_unreach = 1;
8154 }
8155 else if (unformat (i, "null-send-prohibit"))
8156 {
8157 is_prohibit = 1;
8158 }
8159 else if (unformat (i, "local"))
8160 {
8161 is_local = 1;
8162 }
8163 else if (unformat (i, "classify %d", &classify_table_index))
8164 {
8165 is_classify = 1;
8166 }
8167 else if (unformat (i, "del"))
8168 is_add = 0;
8169 else if (unformat (i, "add"))
8170 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008171 else if (unformat (i, "resolve-via-host"))
8172 resolve_host = 1;
8173 else if (unformat (i, "resolve-via-attached"))
8174 resolve_attached = 1;
8175 else if (unformat (i, "multipath"))
8176 is_multipath = 1;
8177 else if (unformat (i, "vrf %d", &vrf_id))
8178 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008179 else if (unformat (i, "count %d", &count))
8180 ;
8181 else if (unformat (i, "lookup-in-vrf %d", &next_hop_table_id))
8182 ;
8183 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
8184 ;
8185 else if (unformat (i, "out-label %d", &next_hop_out_label))
John Loe166fd92018-09-13 14:08:59 -04008186 {
8187 vl_api_fib_mpls_label_t fib_label = {
8188 .label = ntohl (next_hop_out_label),
8189 .ttl = 64,
8190 .exp = 0,
8191 };
8192 vec_add1 (next_hop_out_label_stack, fib_label);
8193 }
8194 else if (unformat (i, "via via-label %d", &next_hop_via_label))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008195 ;
8196 else if (unformat (i, "random"))
8197 random_add_del = 1;
8198 else if (unformat (i, "seed %d", &random_seed))
8199 ;
8200 else
8201 {
8202 clib_warning ("parse error '%U'", format_unformat_error, i);
8203 return -99;
8204 }
8205 }
8206
8207 if (!next_hop_set && !is_drop && !is_local &&
8208 !is_classify && !is_unreach && !is_prohibit &&
8209 MPLS_LABEL_INVALID == next_hop_via_label)
8210 {
8211 errmsg
8212 ("next hop / local / drop / unreach / prohibit / classify not set");
8213 return -99;
8214 }
8215
8216 if (next_hop_set && MPLS_LABEL_INVALID != next_hop_via_label)
8217 {
8218 errmsg ("next hop and next-hop via label set");
8219 return -99;
8220 }
8221 if (address_set == 0)
8222 {
8223 errmsg ("missing addresses");
8224 return -99;
8225 }
8226
8227 if (address_length_set == 0)
8228 {
8229 errmsg ("missing address length");
8230 return -99;
8231 }
8232
8233 /* Generate a pile of unique, random routes */
8234 if (random_add_del)
8235 {
8236 u32 this_random_address;
8237 random_hash = hash_create (count, sizeof (uword));
8238
8239 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
8240 for (j = 0; j <= count; j++)
8241 {
8242 do
8243 {
8244 this_random_address = random_u32 (&random_seed);
8245 this_random_address =
8246 clib_host_to_net_u32 (this_random_address);
8247 }
8248 while (hash_get (random_hash, this_random_address));
8249 vec_add1 (random_vector, this_random_address);
8250 hash_set (random_hash, this_random_address, 1);
8251 }
8252 hash_free (random_hash);
8253 v4_dst_address.as_u32 = random_vector[0];
8254 }
8255
8256 if (count > 1)
8257 {
8258 /* Turn on async mode */
8259 vam->async_mode = 1;
8260 vam->async_errors = 0;
8261 before = vat_time_now (vam);
8262 }
8263
8264 for (j = 0; j < count; j++)
8265 {
8266 /* Construct the API message */
John Loe166fd92018-09-13 14:08:59 -04008267 M2 (IP_ADD_DEL_ROUTE, mp, sizeof (vl_api_fib_mpls_label_t) *
8268 vec_len (next_hop_out_label_stack));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008269
8270 mp->next_hop_sw_if_index = ntohl (sw_if_index);
8271 mp->table_id = ntohl (vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008272
8273 mp->is_add = is_add;
8274 mp->is_drop = is_drop;
8275 mp->is_unreach = is_unreach;
8276 mp->is_prohibit = is_prohibit;
8277 mp->is_ipv6 = is_ipv6;
8278 mp->is_local = is_local;
8279 mp->is_classify = is_classify;
8280 mp->is_multipath = is_multipath;
8281 mp->is_resolve_host = resolve_host;
8282 mp->is_resolve_attached = resolve_attached;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008283 mp->next_hop_weight = next_hop_weight;
John Lo06fda9c2018-10-03 16:32:44 -04008284 mp->next_hop_preference = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008285 mp->dst_address_length = dst_address_length;
8286 mp->next_hop_table_id = ntohl (next_hop_table_id);
8287 mp->classify_table_index = ntohl (classify_table_index);
8288 mp->next_hop_via_label = ntohl (next_hop_via_label);
8289 mp->next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
8290 if (0 != mp->next_hop_n_out_labels)
8291 {
8292 memcpy (mp->next_hop_out_label_stack,
8293 next_hop_out_label_stack,
John Loe166fd92018-09-13 14:08:59 -04008294 (vec_len (next_hop_out_label_stack) *
8295 sizeof (vl_api_fib_mpls_label_t)));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008296 vec_free (next_hop_out_label_stack);
8297 }
8298
8299 if (is_ipv6)
8300 {
8301 clib_memcpy (mp->dst_address, &v6_dst_address,
8302 sizeof (v6_dst_address));
8303 if (next_hop_set)
8304 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
8305 sizeof (v6_next_hop_address));
8306 increment_v6_address (&v6_dst_address);
8307 }
8308 else
8309 {
8310 clib_memcpy (mp->dst_address, &v4_dst_address,
8311 sizeof (v4_dst_address));
8312 if (next_hop_set)
8313 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
8314 sizeof (v4_next_hop_address));
8315 if (random_add_del)
8316 v4_dst_address.as_u32 = random_vector[j + 1];
8317 else
8318 increment_v4_address (&v4_dst_address);
8319 }
8320 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008321 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008322 /* If we receive SIGTERM, stop now... */
8323 if (vam->do_exit)
8324 break;
8325 }
8326
8327 /* When testing multiple add/del ops, use a control-ping to sync */
8328 if (count > 1)
8329 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008330 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008331 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008332 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008333
8334 /* Shut off async mode */
8335 vam->async_mode = 0;
8336
Dave Barach59b25652017-09-10 15:04:27 -04008337 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008338 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008339
8340 timeout = vat_time_now (vam) + 1.0;
8341 while (vat_time_now (vam) < timeout)
8342 if (vam->result_ready == 1)
8343 goto out;
8344 vam->retval = -99;
8345
8346 out:
8347 if (vam->retval == -99)
8348 errmsg ("timeout");
8349
8350 if (vam->async_errors > 0)
8351 {
8352 errmsg ("%d asynchronous errors", vam->async_errors);
8353 vam->retval = -98;
8354 }
8355 vam->async_errors = 0;
8356 after = vat_time_now (vam);
8357
8358 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8359 if (j > 0)
8360 count = j;
8361
8362 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8363 count, after - before, count / (after - before));
8364 }
8365 else
8366 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008367 int ret;
8368
Damjan Marion7cd468a2016-12-19 23:05:39 +01008369 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008370 W (ret);
8371 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008372 }
8373
8374 /* Return the good/bad news */
8375 return (vam->retval);
8376}
8377
8378static int
Neale Ranns32e1c012016-11-22 17:07:28 +00008379api_ip_mroute_add_del (vat_main_t * vam)
8380{
8381 unformat_input_t *i = vam->input;
8382 vl_api_ip_mroute_add_del_t *mp;
Neale Ranns32e1c012016-11-22 17:07:28 +00008383 u32 sw_if_index = ~0, vrf_id = 0;
8384 u8 is_ipv6 = 0;
8385 u8 is_local = 0;
Neale Ranns32e1c012016-11-22 17:07:28 +00008386 u8 is_add = 1;
8387 u8 address_set = 0;
8388 u32 grp_address_length = 0;
8389 ip4_address_t v4_grp_address, v4_src_address;
8390 ip6_address_t v6_grp_address, v6_src_address;
8391 mfib_itf_flags_t iflags = 0;
8392 mfib_entry_flags_t eflags = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008393 int ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008394
8395 /* Parse args required to build the message */
8396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8397 {
8398 if (unformat (i, "sw_if_index %d", &sw_if_index))
8399 ;
8400 else if (unformat (i, "%U %U",
8401 unformat_ip4_address, &v4_src_address,
8402 unformat_ip4_address, &v4_grp_address))
8403 {
8404 grp_address_length = 64;
8405 address_set = 1;
8406 is_ipv6 = 0;
8407 }
8408 else if (unformat (i, "%U %U",
8409 unformat_ip6_address, &v6_src_address,
8410 unformat_ip6_address, &v6_grp_address))
8411 {
8412 grp_address_length = 256;
8413 address_set = 1;
8414 is_ipv6 = 1;
8415 }
8416 else if (unformat (i, "%U", unformat_ip4_address, &v4_grp_address))
8417 {
Dave Barachb7b92992018-10-17 10:38:51 -04008418 clib_memset (&v4_src_address, 0, sizeof (v4_src_address));
Neale Ranns32e1c012016-11-22 17:07:28 +00008419 grp_address_length = 32;
8420 address_set = 1;
8421 is_ipv6 = 0;
8422 }
8423 else if (unformat (i, "%U", unformat_ip6_address, &v6_grp_address))
8424 {
Dave Barachb7b92992018-10-17 10:38:51 -04008425 clib_memset (&v6_src_address, 0, sizeof (v6_src_address));
Neale Ranns32e1c012016-11-22 17:07:28 +00008426 grp_address_length = 128;
8427 address_set = 1;
8428 is_ipv6 = 1;
8429 }
8430 else if (unformat (i, "/%d", &grp_address_length))
8431 ;
8432 else if (unformat (i, "local"))
8433 {
8434 is_local = 1;
8435 }
8436 else if (unformat (i, "del"))
8437 is_add = 0;
8438 else if (unformat (i, "add"))
8439 is_add = 1;
8440 else if (unformat (i, "vrf %d", &vrf_id))
8441 ;
Neale Ranns32e1c012016-11-22 17:07:28 +00008442 else if (unformat (i, "%U", unformat_mfib_itf_flags, &iflags))
8443 ;
8444 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
8445 ;
8446 else
8447 {
8448 clib_warning ("parse error '%U'", format_unformat_error, i);
8449 return -99;
8450 }
8451 }
8452
8453 if (address_set == 0)
8454 {
8455 errmsg ("missing addresses\n");
8456 return -99;
8457 }
8458
8459 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008460 M (IP_MROUTE_ADD_DEL, mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008461
8462 mp->next_hop_sw_if_index = ntohl (sw_if_index);
8463 mp->table_id = ntohl (vrf_id);
Neale Ranns32e1c012016-11-22 17:07:28 +00008464
8465 mp->is_add = is_add;
8466 mp->is_ipv6 = is_ipv6;
8467 mp->is_local = is_local;
8468 mp->itf_flags = ntohl (iflags);
8469 mp->entry_flags = ntohl (eflags);
8470 mp->grp_address_length = grp_address_length;
8471 mp->grp_address_length = ntohs (mp->grp_address_length);
8472
8473 if (is_ipv6)
8474 {
8475 clib_memcpy (mp->grp_address, &v6_grp_address, sizeof (v6_grp_address));
8476 clib_memcpy (mp->src_address, &v6_src_address, sizeof (v6_src_address));
8477 }
8478 else
8479 {
8480 clib_memcpy (mp->grp_address, &v4_grp_address, sizeof (v4_grp_address));
8481 clib_memcpy (mp->src_address, &v4_src_address, sizeof (v4_src_address));
8482
8483 }
8484
8485 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008486 S (mp);
Neale Ranns32e1c012016-11-22 17:07:28 +00008487 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008488 W (ret);
8489 return ret;
Neale Ranns32e1c012016-11-22 17:07:28 +00008490}
8491
8492static int
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008493api_mpls_table_add_del (vat_main_t * vam)
8494{
8495 unformat_input_t *i = vam->input;
8496 vl_api_mpls_table_add_del_t *mp;
8497 u32 table_id = ~0;
8498 u8 is_add = 1;
8499 int ret = 0;
8500
8501 /* Parse args required to build the message */
8502 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8503 {
Florin Corasd0a59722017-10-15 17:41:21 +00008504 if (unformat (i, "table %d", &table_id))
8505 ;
8506 else if (unformat (i, "del"))
Neale Ranns28ab9cc2017-08-14 07:18:42 -07008507 is_add = 0;
8508 else if (unformat (i, "add"))
8509 is_add = 1;
8510 else
8511 {
8512 clib_warning ("parse error '%U'", format_unformat_error, i);
8513 return -99;
8514 }
8515 }
8516
8517 if (~0 == table_id)
8518 {
8519 errmsg ("missing table-ID");
8520 return -99;
8521 }
8522
8523 /* Construct the API message */
8524 M (MPLS_TABLE_ADD_DEL, mp);
8525
8526 mp->mt_table_id = ntohl (table_id);
8527 mp->mt_is_add = is_add;
8528
8529 /* send it... */
8530 S (mp);
8531
8532 /* Wait for a reply... */
8533 W (ret);
8534
8535 return ret;
8536}
8537
8538static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01008539api_mpls_route_add_del (vat_main_t * vam)
8540{
8541 unformat_input_t *i = vam->input;
8542 vl_api_mpls_route_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008543 u32 sw_if_index = ~0, table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008544 u8 is_add = 1;
8545 u32 next_hop_weight = 1;
8546 u8 is_multipath = 0;
8547 u32 next_hop_table_id = 0;
8548 u8 next_hop_set = 0;
8549 ip4_address_t v4_next_hop_address = {
8550 .as_u32 = 0,
8551 };
8552 ip6_address_t v6_next_hop_address = { {0} };
8553 int count = 1;
8554 int j;
8555 f64 before = 0;
8556 u32 classify_table_index = ~0;
8557 u8 is_classify = 0;
8558 u8 resolve_host = 0, resolve_attached = 0;
John Loe166fd92018-09-13 14:08:59 -04008559 u8 is_interface_rx = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008560 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
8561 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
John Loe166fd92018-09-13 14:08:59 -04008562 vl_api_fib_mpls_label_t *next_hop_out_label_stack = NULL;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008563 mpls_label_t local_label = MPLS_LABEL_INVALID;
8564 u8 is_eos = 0;
John Loe166fd92018-09-13 14:08:59 -04008565 dpo_proto_t next_hop_proto = DPO_PROTO_MPLS;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008566
8567 /* Parse args required to build the message */
8568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8569 {
8570 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8571 ;
8572 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8573 ;
8574 else if (unformat (i, "%d", &local_label))
8575 ;
8576 else if (unformat (i, "eos"))
8577 is_eos = 1;
8578 else if (unformat (i, "non-eos"))
8579 is_eos = 0;
8580 else if (unformat (i, "via %U", unformat_ip4_address,
8581 &v4_next_hop_address))
8582 {
8583 next_hop_set = 1;
Neale Rannsda78f952017-05-24 09:15:43 -07008584 next_hop_proto = DPO_PROTO_IP4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008585 }
8586 else if (unformat (i, "via %U", unformat_ip6_address,
8587 &v6_next_hop_address))
8588 {
8589 next_hop_set = 1;
Neale Rannsda78f952017-05-24 09:15:43 -07008590 next_hop_proto = DPO_PROTO_IP6;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008591 }
8592 else if (unformat (i, "weight %d", &next_hop_weight))
8593 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008594 else if (unformat (i, "classify %d", &classify_table_index))
8595 {
8596 is_classify = 1;
8597 }
8598 else if (unformat (i, "del"))
8599 is_add = 0;
8600 else if (unformat (i, "add"))
8601 is_add = 1;
8602 else if (unformat (i, "resolve-via-host"))
8603 resolve_host = 1;
8604 else if (unformat (i, "resolve-via-attached"))
8605 resolve_attached = 1;
8606 else if (unformat (i, "multipath"))
8607 is_multipath = 1;
8608 else if (unformat (i, "count %d", &count))
8609 ;
John Loe166fd92018-09-13 14:08:59 -04008610 else if (unformat (i, "via lookup-in-ip4-table %d", &next_hop_table_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008611 {
8612 next_hop_set = 1;
Neale Rannsda78f952017-05-24 09:15:43 -07008613 next_hop_proto = DPO_PROTO_IP4;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008614 }
John Loe166fd92018-09-13 14:08:59 -04008615 else if (unformat (i, "via lookup-in-ip6-table %d", &next_hop_table_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01008616 {
8617 next_hop_set = 1;
Neale Rannsda78f952017-05-24 09:15:43 -07008618 next_hop_proto = DPO_PROTO_IP6;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008619 }
John Loe166fd92018-09-13 14:08:59 -04008620 else
8621 if (unformat
8622 (i, "via l2-input-on %U", api_unformat_sw_if_index, vam,
8623 &sw_if_index))
8624 {
8625 next_hop_set = 1;
8626 next_hop_proto = DPO_PROTO_ETHERNET;
8627 is_interface_rx = 1;
8628 }
8629 else if (unformat (i, "via l2-input-on sw_if_index %d", &sw_if_index))
8630 {
8631 next_hop_set = 1;
8632 next_hop_proto = DPO_PROTO_ETHERNET;
8633 is_interface_rx = 1;
8634 }
8635 else if (unformat (i, "via next-hop-table %d", &next_hop_table_id))
8636 next_hop_set = 1;
8637 else if (unformat (i, "via via-label %d", &next_hop_via_label))
8638 next_hop_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008639 else if (unformat (i, "out-label %d", &next_hop_out_label))
John Loe166fd92018-09-13 14:08:59 -04008640 {
8641 vl_api_fib_mpls_label_t fib_label = {
8642 .label = ntohl (next_hop_out_label),
8643 .ttl = 64,
8644 .exp = 0,
8645 };
8646 vec_add1 (next_hop_out_label_stack, fib_label);
8647 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01008648 else
8649 {
8650 clib_warning ("parse error '%U'", format_unformat_error, i);
8651 return -99;
8652 }
8653 }
8654
8655 if (!next_hop_set && !is_classify)
8656 {
8657 errmsg ("next hop / classify not set");
8658 return -99;
8659 }
8660
8661 if (MPLS_LABEL_INVALID == local_label)
8662 {
8663 errmsg ("missing label");
8664 return -99;
8665 }
8666
8667 if (count > 1)
8668 {
8669 /* Turn on async mode */
8670 vam->async_mode = 1;
8671 vam->async_errors = 0;
8672 before = vat_time_now (vam);
8673 }
8674
8675 for (j = 0; j < count; j++)
8676 {
8677 /* Construct the API message */
John Loe166fd92018-09-13 14:08:59 -04008678 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_mpls_label_t) *
8679 vec_len (next_hop_out_label_stack));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008680
8681 mp->mr_next_hop_sw_if_index = ntohl (sw_if_index);
8682 mp->mr_table_id = ntohl (table_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008683
8684 mp->mr_is_add = is_add;
Neale Rannsda78f952017-05-24 09:15:43 -07008685 mp->mr_next_hop_proto = next_hop_proto;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008686 mp->mr_is_classify = is_classify;
8687 mp->mr_is_multipath = is_multipath;
8688 mp->mr_is_resolve_host = resolve_host;
8689 mp->mr_is_resolve_attached = resolve_attached;
John Loe166fd92018-09-13 14:08:59 -04008690 mp->mr_is_interface_rx = is_interface_rx;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008691 mp->mr_next_hop_weight = next_hop_weight;
John Lo06fda9c2018-10-03 16:32:44 -04008692 mp->mr_next_hop_preference = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008693 mp->mr_next_hop_table_id = ntohl (next_hop_table_id);
8694 mp->mr_classify_table_index = ntohl (classify_table_index);
8695 mp->mr_next_hop_via_label = ntohl (next_hop_via_label);
8696 mp->mr_label = ntohl (local_label);
8697 mp->mr_eos = is_eos;
8698
8699 mp->mr_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
8700 if (0 != mp->mr_next_hop_n_out_labels)
8701 {
8702 memcpy (mp->mr_next_hop_out_label_stack,
8703 next_hop_out_label_stack,
John Loe166fd92018-09-13 14:08:59 -04008704 vec_len (next_hop_out_label_stack) *
8705 sizeof (vl_api_fib_mpls_label_t));
Damjan Marion7cd468a2016-12-19 23:05:39 +01008706 vec_free (next_hop_out_label_stack);
8707 }
8708
8709 if (next_hop_set)
8710 {
Neale Rannsda78f952017-05-24 09:15:43 -07008711 if (DPO_PROTO_IP4 == next_hop_proto)
Damjan Marion7cd468a2016-12-19 23:05:39 +01008712 {
8713 clib_memcpy (mp->mr_next_hop,
8714 &v4_next_hop_address,
8715 sizeof (v4_next_hop_address));
8716 }
Neale Rannsda78f952017-05-24 09:15:43 -07008717 else if (DPO_PROTO_IP6 == next_hop_proto)
8718
Damjan Marion7cd468a2016-12-19 23:05:39 +01008719 {
8720 clib_memcpy (mp->mr_next_hop,
8721 &v6_next_hop_address,
8722 sizeof (v6_next_hop_address));
8723 }
8724 }
8725 local_label++;
8726
8727 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008728 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008729 /* If we receive SIGTERM, stop now... */
8730 if (vam->do_exit)
8731 break;
8732 }
8733
8734 /* When testing multiple add/del ops, use a control-ping to sync */
8735 if (count > 1)
8736 {
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008737 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008738 f64 after;
Jon Loeliger1f9191f2017-01-31 15:27:19 -06008739 f64 timeout;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008740
8741 /* Shut off async mode */
8742 vam->async_mode = 0;
8743
Dave Barach59b25652017-09-10 15:04:27 -04008744 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -06008745 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008746
8747 timeout = vat_time_now (vam) + 1.0;
8748 while (vat_time_now (vam) < timeout)
8749 if (vam->result_ready == 1)
8750 goto out;
8751 vam->retval = -99;
8752
8753 out:
8754 if (vam->retval == -99)
8755 errmsg ("timeout");
8756
8757 if (vam->async_errors > 0)
8758 {
8759 errmsg ("%d asynchronous errors", vam->async_errors);
8760 vam->retval = -98;
8761 }
8762 vam->async_errors = 0;
8763 after = vat_time_now (vam);
8764
8765 /* slim chance, but we might have eaten SIGTERM on the first iteration */
8766 if (j > 0)
8767 count = j;
8768
8769 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
8770 count, after - before, count / (after - before));
8771 }
8772 else
8773 {
Jon Loeliger56c7b012017-02-01 12:31:41 -06008774 int ret;
8775
Damjan Marion7cd468a2016-12-19 23:05:39 +01008776 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008777 W (ret);
8778 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008779 }
8780
8781 /* Return the good/bad news */
8782 return (vam->retval);
8783}
8784
8785static int
8786api_mpls_ip_bind_unbind (vat_main_t * vam)
8787{
8788 unformat_input_t *i = vam->input;
8789 vl_api_mpls_ip_bind_unbind_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008790 u32 ip_table_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008791 u8 is_bind = 1;
8792 u8 is_ip4 = 1;
8793 ip4_address_t v4_address;
8794 ip6_address_t v6_address;
8795 u32 address_length;
8796 u8 address_set = 0;
8797 mpls_label_t local_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06008798 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008799
8800 /* Parse args required to build the message */
8801 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8802 {
8803 if (unformat (i, "%U/%d", unformat_ip4_address,
8804 &v4_address, &address_length))
8805 {
8806 is_ip4 = 1;
8807 address_set = 1;
8808 }
8809 else if (unformat (i, "%U/%d", unformat_ip6_address,
8810 &v6_address, &address_length))
8811 {
8812 is_ip4 = 0;
8813 address_set = 1;
8814 }
8815 else if (unformat (i, "%d", &local_label))
8816 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008817 else if (unformat (i, "table-id %d", &ip_table_id))
8818 ;
8819 else if (unformat (i, "unbind"))
8820 is_bind = 0;
8821 else if (unformat (i, "bind"))
8822 is_bind = 1;
8823 else
8824 {
8825 clib_warning ("parse error '%U'", format_unformat_error, i);
8826 return -99;
8827 }
8828 }
8829
8830 if (!address_set)
8831 {
Paul Vinciguerraec11b132018-09-24 05:25:00 -07008832 errmsg ("IP address not set");
Damjan Marion7cd468a2016-12-19 23:05:39 +01008833 return -99;
8834 }
8835
8836 if (MPLS_LABEL_INVALID == local_label)
8837 {
8838 errmsg ("missing label");
8839 return -99;
8840 }
8841
8842 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06008843 M (MPLS_IP_BIND_UNBIND, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008844
Damjan Marion7cd468a2016-12-19 23:05:39 +01008845 mp->mb_is_bind = is_bind;
8846 mp->mb_is_ip4 = is_ip4;
8847 mp->mb_ip_table_id = ntohl (ip_table_id);
8848 mp->mb_mpls_table_id = 0;
8849 mp->mb_label = ntohl (local_label);
8850 mp->mb_address_length = address_length;
8851
8852 if (is_ip4)
8853 clib_memcpy (mp->mb_address, &v4_address, sizeof (v4_address));
8854 else
8855 clib_memcpy (mp->mb_address, &v6_address, sizeof (v6_address));
8856
8857 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06008858 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01008859
8860 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -06008861 W (ret);
8862 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01008863}
8864
8865static int
John Loe166fd92018-09-13 14:08:59 -04008866api_sr_mpls_policy_add (vat_main_t * vam)
8867{
8868 unformat_input_t *i = vam->input;
8869 vl_api_sr_mpls_policy_add_t *mp;
8870 u32 bsid = 0;
8871 u32 weight = 1;
8872 u8 type = 0;
8873 u8 n_segments = 0;
8874 u32 sid;
8875 u32 *segments = NULL;
8876 int ret;
8877
8878 /* Parse args required to build the message */
8879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8880 {
8881 if (unformat (i, "bsid %d", &bsid))
8882 ;
8883 else if (unformat (i, "weight %d", &weight))
8884 ;
8885 else if (unformat (i, "spray"))
8886 type = 1;
8887 else if (unformat (i, "next %d", &sid))
8888 {
8889 n_segments += 1;
8890 vec_add1 (segments, htonl (sid));
8891 }
8892 else
8893 {
8894 clib_warning ("parse error '%U'", format_unformat_error, i);
8895 return -99;
8896 }
8897 }
8898
8899 if (bsid == 0)
8900 {
8901 errmsg ("bsid not set");
8902 return -99;
8903 }
8904
8905 if (n_segments == 0)
8906 {
8907 errmsg ("no sid in segment stack");
8908 return -99;
8909 }
8910
8911 /* Construct the API message */
8912 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
8913
8914 mp->bsid = htonl (bsid);
8915 mp->weight = htonl (weight);
8916 mp->type = type;
8917 mp->n_segments = n_segments;
8918 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
8919 vec_free (segments);
8920
8921 /* send it... */
8922 S (mp);
8923
8924 /* Wait for a reply... */
8925 W (ret);
8926 return ret;
8927}
8928
8929static int
8930api_sr_mpls_policy_del (vat_main_t * vam)
8931{
8932 unformat_input_t *i = vam->input;
8933 vl_api_sr_mpls_policy_del_t *mp;
8934 u32 bsid = 0;
8935 int ret;
8936
8937 /* Parse args required to build the message */
8938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8939 {
8940 if (unformat (i, "bsid %d", &bsid))
8941 ;
8942 else
8943 {
8944 clib_warning ("parse error '%U'", format_unformat_error, i);
8945 return -99;
8946 }
8947 }
8948
8949 if (bsid == 0)
8950 {
8951 errmsg ("bsid not set");
8952 return -99;
8953 }
8954
8955 /* Construct the API message */
8956 M (SR_MPLS_POLICY_DEL, mp);
8957
8958 mp->bsid = htonl (bsid);
8959
8960 /* send it... */
8961 S (mp);
8962
8963 /* Wait for a reply... */
8964 W (ret);
8965 return ret;
8966}
8967
8968static int
Neale Rannsd792d9c2017-10-21 10:53:20 -07008969api_bier_table_add_del (vat_main_t * vam)
8970{
8971 unformat_input_t *i = vam->input;
8972 vl_api_bier_table_add_del_t *mp;
8973 u8 is_add = 1;
8974 u32 set = 0, sub_domain = 0, hdr_len = 3;
8975 mpls_label_t local_label = MPLS_LABEL_INVALID;
8976 int ret;
8977
8978 /* Parse args required to build the message */
8979 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8980 {
8981 if (unformat (i, "sub-domain %d", &sub_domain))
8982 ;
8983 else if (unformat (i, "set %d", &set))
8984 ;
8985 else if (unformat (i, "label %d", &local_label))
8986 ;
8987 else if (unformat (i, "hdr-len %d", &hdr_len))
8988 ;
8989 else if (unformat (i, "add"))
8990 is_add = 1;
8991 else if (unformat (i, "del"))
8992 is_add = 0;
8993 else
8994 {
8995 clib_warning ("parse error '%U'", format_unformat_error, i);
8996 return -99;
8997 }
8998 }
8999
9000 if (MPLS_LABEL_INVALID == local_label)
9001 {
9002 errmsg ("missing label\n");
9003 return -99;
9004 }
9005
9006 /* Construct the API message */
9007 M (BIER_TABLE_ADD_DEL, mp);
9008
9009 mp->bt_is_add = is_add;
9010 mp->bt_label = ntohl (local_label);
9011 mp->bt_tbl_id.bt_set = set;
9012 mp->bt_tbl_id.bt_sub_domain = sub_domain;
9013 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
9014
9015 /* send it... */
9016 S (mp);
9017
9018 /* Wait for a reply... */
9019 W (ret);
9020
9021 return (ret);
9022}
9023
9024static int
9025api_bier_route_add_del (vat_main_t * vam)
9026{
9027 unformat_input_t *i = vam->input;
9028 vl_api_bier_route_add_del_t *mp;
9029 u8 is_add = 1;
9030 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
9031 ip4_address_t v4_next_hop_address;
9032 ip6_address_t v6_next_hop_address;
9033 u8 next_hop_set = 0;
9034 u8 next_hop_proto_is_ip4 = 1;
9035 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
9036 int ret;
9037
9038 /* Parse args required to build the message */
9039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9040 {
9041 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
9042 {
9043 next_hop_proto_is_ip4 = 1;
9044 next_hop_set = 1;
9045 }
9046 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
9047 {
9048 next_hop_proto_is_ip4 = 0;
9049 next_hop_set = 1;
9050 }
9051 if (unformat (i, "sub-domain %d", &sub_domain))
9052 ;
9053 else if (unformat (i, "set %d", &set))
9054 ;
9055 else if (unformat (i, "hdr-len %d", &hdr_len))
9056 ;
9057 else if (unformat (i, "bp %d", &bp))
9058 ;
9059 else if (unformat (i, "add"))
9060 is_add = 1;
9061 else if (unformat (i, "del"))
9062 is_add = 0;
9063 else if (unformat (i, "out-label %d", &next_hop_out_label))
9064 ;
9065 else
9066 {
9067 clib_warning ("parse error '%U'", format_unformat_error, i);
9068 return -99;
9069 }
9070 }
9071
9072 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
9073 {
9074 errmsg ("next hop / label set\n");
9075 return -99;
9076 }
9077 if (0 == bp)
9078 {
9079 errmsg ("bit=position not set\n");
9080 return -99;
9081 }
9082
9083 /* Construct the API message */
Neale Ranns31ed7442018-02-23 05:29:09 -08009084 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
Neale Rannsd792d9c2017-10-21 10:53:20 -07009085
9086 mp->br_is_add = is_add;
9087 mp->br_tbl_id.bt_set = set;
9088 mp->br_tbl_id.bt_sub_domain = sub_domain;
9089 mp->br_tbl_id.bt_hdr_len_id = hdr_len;
9090 mp->br_bp = ntohs (bp);
9091 mp->br_n_paths = 1;
9092 mp->br_paths[0].n_labels = 1;
Neale Ranns31ed7442018-02-23 05:29:09 -08009093 mp->br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
Neale Rannsd792d9c2017-10-21 10:53:20 -07009094 mp->br_paths[0].afi = (next_hop_proto_is_ip4 ? 0 : 1);
9095
9096 if (next_hop_proto_is_ip4)
9097 {
9098 clib_memcpy (mp->br_paths[0].next_hop,
9099 &v4_next_hop_address, sizeof (v4_next_hop_address));
9100 }
9101 else
9102 {
9103 clib_memcpy (mp->br_paths[0].next_hop,
9104 &v6_next_hop_address, sizeof (v6_next_hop_address));
9105 }
9106
9107 /* send it... */
9108 S (mp);
9109
9110 /* Wait for a reply... */
9111 W (ret);
9112
9113 return (ret);
9114}
9115
9116static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009117api_proxy_arp_add_del (vat_main_t * vam)
9118{
9119 unformat_input_t *i = vam->input;
9120 vl_api_proxy_arp_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009121 u32 vrf_id = 0;
9122 u8 is_add = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009123 vl_api_ip4_address_t lo, hi;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009124 u8 range_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009125 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009126
9127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9128 {
9129 if (unformat (i, "vrf %d", &vrf_id))
9130 ;
Neale Ranns37029302018-08-10 05:30:06 -07009131 else if (unformat (i, "%U - %U", unformat_vl_api_ip4_address, &lo,
9132 unformat_vl_api_ip4_address, &hi))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009133 range_set = 1;
9134 else if (unformat (i, "del"))
9135 is_add = 0;
9136 else
9137 {
9138 clib_warning ("parse error '%U'", format_unformat_error, i);
9139 return -99;
9140 }
9141 }
9142
9143 if (range_set == 0)
9144 {
9145 errmsg ("address range not set");
9146 return -99;
9147 }
9148
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009149 M (PROXY_ARP_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009150
Neale Ranns37029302018-08-10 05:30:06 -07009151 mp->proxy.table_id = ntohl (vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009152 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07009153 clib_memcpy (mp->proxy.low, &lo, sizeof (lo));
9154 clib_memcpy (mp->proxy.hi, &hi, sizeof (hi));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009155
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009156 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009157 W (ret);
9158 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009159}
9160
9161static int
9162api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
9163{
9164 unformat_input_t *i = vam->input;
9165 vl_api_proxy_arp_intfc_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009166 u32 sw_if_index;
9167 u8 enable = 1;
9168 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009169 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009170
9171 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9172 {
9173 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9174 sw_if_index_set = 1;
9175 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9176 sw_if_index_set = 1;
9177 else if (unformat (i, "enable"))
9178 enable = 1;
9179 else if (unformat (i, "disable"))
9180 enable = 0;
9181 else
9182 {
9183 clib_warning ("parse error '%U'", format_unformat_error, i);
9184 return -99;
9185 }
9186 }
9187
9188 if (sw_if_index_set == 0)
9189 {
9190 errmsg ("missing interface name or sw_if_index");
9191 return -99;
9192 }
9193
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009194 M (PROXY_ARP_INTFC_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009195
9196 mp->sw_if_index = ntohl (sw_if_index);
9197 mp->enable_disable = enable;
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_mpls_tunnel_add_del (vat_main_t * vam)
9206{
9207 unformat_input_t *i = vam->input;
9208 vl_api_mpls_tunnel_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009209
9210 u8 is_add = 1;
9211 u8 l2_only = 0;
9212 u32 sw_if_index = ~0;
9213 u32 next_hop_sw_if_index = ~0;
9214 u32 next_hop_proto_is_ip4 = 1;
9215
9216 u32 next_hop_table_id = 0;
9217 ip4_address_t v4_next_hop_address = {
9218 .as_u32 = 0,
9219 };
9220 ip6_address_t v6_next_hop_address = { {0} };
John Lo06fda9c2018-10-03 16:32:44 -04009221 vl_api_fib_mpls_label_t *next_hop_out_label_stack = NULL;
John Loe166fd92018-09-13 14:08:59 -04009222 mpls_label_t next_hop_via_label = MPLS_LABEL_INVALID;
John Lo06fda9c2018-10-03 16:32:44 -04009223 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009224 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009225
9226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9227 {
9228 if (unformat (i, "add"))
9229 is_add = 1;
John Lo06fda9c2018-10-03 16:32:44 -04009230 else
9231 if (unformat
9232 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
9233 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009234 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
9235 is_add = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009236 else if (unformat (i, "via %U",
9237 unformat_ip4_address, &v4_next_hop_address))
9238 {
9239 next_hop_proto_is_ip4 = 1;
9240 }
9241 else if (unformat (i, "via %U",
9242 unformat_ip6_address, &v6_next_hop_address))
9243 {
9244 next_hop_proto_is_ip4 = 0;
9245 }
John Loe166fd92018-09-13 14:08:59 -04009246 else if (unformat (i, "via-label %d", &next_hop_via_label))
9247 ;
John Lo06fda9c2018-10-03 16:32:44 -04009248 else
9249 if (unformat
9250 (i, "%U", api_unformat_sw_if_index, vam, &next_hop_sw_if_index))
9251 ;
9252 else if (unformat (i, "sw_if_index %d", &next_hop_sw_if_index))
9253 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009254 else if (unformat (i, "l2-only"))
9255 l2_only = 1;
9256 else if (unformat (i, "next-hop-table %d", &next_hop_table_id))
9257 ;
9258 else if (unformat (i, "out-label %d", &next_hop_out_label))
John Lo06fda9c2018-10-03 16:32:44 -04009259 {
9260 vl_api_fib_mpls_label_t fib_label = {
9261 .label = ntohl (next_hop_out_label),
9262 .ttl = 64,
9263 .exp = 0,
9264 };
9265 vec_add1 (next_hop_out_label_stack, fib_label);
9266 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009267 else
9268 {
9269 clib_warning ("parse error '%U'", format_unformat_error, i);
9270 return -99;
9271 }
9272 }
9273
John Lo06fda9c2018-10-03 16:32:44 -04009274 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_mpls_label_t) *
9275 vec_len (next_hop_out_label_stack));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009276
9277 mp->mt_next_hop_sw_if_index = ntohl (next_hop_sw_if_index);
9278 mp->mt_sw_if_index = ntohl (sw_if_index);
9279 mp->mt_is_add = is_add;
9280 mp->mt_l2_only = l2_only;
9281 mp->mt_next_hop_table_id = ntohl (next_hop_table_id);
9282 mp->mt_next_hop_proto_is_ip4 = next_hop_proto_is_ip4;
John Loe166fd92018-09-13 14:08:59 -04009283 mp->mt_next_hop_via_label = ntohl (next_hop_via_label);
John Lo06fda9c2018-10-03 16:32:44 -04009284 mp->mt_next_hop_weight = 1;
9285 mp->mt_next_hop_preference = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009286
John Lo06fda9c2018-10-03 16:32:44 -04009287 mp->mt_next_hop_n_out_labels = vec_len (next_hop_out_label_stack);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009288
9289 if (0 != mp->mt_next_hop_n_out_labels)
9290 {
John Lo06fda9c2018-10-03 16:32:44 -04009291 clib_memcpy (mp->mt_next_hop_out_label_stack,
9292 next_hop_out_label_stack,
9293 (vec_len (next_hop_out_label_stack) *
9294 sizeof (vl_api_fib_mpls_label_t)));
9295 vec_free (next_hop_out_label_stack);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009296 }
9297
9298 if (next_hop_proto_is_ip4)
9299 {
9300 clib_memcpy (mp->mt_next_hop,
9301 &v4_next_hop_address, sizeof (v4_next_hop_address));
9302 }
9303 else
9304 {
9305 clib_memcpy (mp->mt_next_hop,
9306 &v6_next_hop_address, sizeof (v6_next_hop_address));
9307 }
9308
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009309 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009310 W (ret);
9311 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009312}
9313
9314static int
9315api_sw_interface_set_unnumbered (vat_main_t * vam)
9316{
9317 unformat_input_t *i = vam->input;
9318 vl_api_sw_interface_set_unnumbered_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009319 u32 sw_if_index;
9320 u32 unnum_sw_index = ~0;
9321 u8 is_add = 1;
9322 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009323 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009324
9325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9326 {
9327 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9328 sw_if_index_set = 1;
9329 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9330 sw_if_index_set = 1;
9331 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
9332 ;
9333 else if (unformat (i, "del"))
9334 is_add = 0;
9335 else
9336 {
9337 clib_warning ("parse error '%U'", format_unformat_error, i);
9338 return -99;
9339 }
9340 }
9341
9342 if (sw_if_index_set == 0)
9343 {
9344 errmsg ("missing interface name or sw_if_index");
9345 return -99;
9346 }
9347
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009348 M (SW_INTERFACE_SET_UNNUMBERED, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009349
9350 mp->sw_if_index = ntohl (sw_if_index);
9351 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
9352 mp->is_add = is_add;
9353
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009354 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009355 W (ret);
9356 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009357}
9358
9359static int
9360api_ip_neighbor_add_del (vat_main_t * vam)
9361{
Neale Ranns37029302018-08-10 05:30:06 -07009362 vl_api_mac_address_t mac_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009363 unformat_input_t *i = vam->input;
9364 vl_api_ip_neighbor_add_del_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -07009365 vl_api_address_t ip_address;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009366 u32 sw_if_index;
9367 u8 sw_if_index_set = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009368 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009369 u8 mac_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -07009370 u8 address_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009371 int ret;
Neale Ranns37029302018-08-10 05:30:06 -07009372 ip_neighbor_flags_t flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009373
Neale Ranns37029302018-08-10 05:30:06 -07009374 flags = IP_NEIGHBOR_FLAG_NONE;
9375 clib_memset (&ip_address, 0, sizeof (ip_address));
9376 clib_memset (&mac_address, 0, sizeof (mac_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009377 /* Parse args required to build the message */
9378 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9379 {
Neale Ranns37029302018-08-10 05:30:06 -07009380 if (unformat (i, "mac %U", unformat_vl_api_mac_address, &mac_address))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009381 {
9382 mac_set = 1;
9383 }
9384 else if (unformat (i, "del"))
9385 is_add = 0;
9386 else
9387 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9388 sw_if_index_set = 1;
9389 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9390 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -07009391 else if (unformat (i, "static"))
9392 flags |= IP_NEIGHBOR_FLAG_STATIC;
Neale Rannsb3b2de72017-03-08 05:17:22 -08009393 else if (unformat (i, "no-fib-entry"))
Neale Ranns37029302018-08-10 05:30:06 -07009394 flags |= IP_NEIGHBOR_FLAG_NO_FIB_ENTRY;
9395 else if (unformat (i, "dst %U", unformat_vl_api_address, &ip_address))
9396 address_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009397 else
9398 {
9399 clib_warning ("parse error '%U'", format_unformat_error, i);
9400 return -99;
9401 }
9402 }
9403
9404 if (sw_if_index_set == 0)
9405 {
9406 errmsg ("missing interface name or sw_if_index");
9407 return -99;
9408 }
Neale Ranns37029302018-08-10 05:30:06 -07009409 if (!address_set)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009410 {
9411 errmsg ("no address set");
9412 return -99;
9413 }
9414
9415 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009416 M (IP_NEIGHBOR_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009417
Neale Ranns37029302018-08-10 05:30:06 -07009418 mp->neighbor.sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009419 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -07009420 mp->neighbor.flags = htonl (flags);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009421 if (mac_set)
Neale Ranns37029302018-08-10 05:30:06 -07009422 clib_memcpy (&mp->neighbor.mac_address, &mac_address,
9423 sizeof (mac_address));
9424 if (address_set)
9425 clib_memcpy (&mp->neighbor.ip_address, &ip_address, sizeof (ip_address));
Damjan Marion7cd468a2016-12-19 23:05:39 +01009426
9427 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009428 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009429
9430 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009431 W (ret);
9432 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009433}
9434
9435static int
Damjan Marion7cd468a2016-12-19 23:05:39 +01009436api_create_vlan_subif (vat_main_t * vam)
9437{
9438 unformat_input_t *i = vam->input;
9439 vl_api_create_vlan_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009440 u32 sw_if_index;
9441 u8 sw_if_index_set = 0;
9442 u32 vlan_id;
9443 u8 vlan_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009444 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009445
9446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9447 {
9448 if (unformat (i, "sw_if_index %d", &sw_if_index))
9449 sw_if_index_set = 1;
9450 else
9451 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9452 sw_if_index_set = 1;
9453 else if (unformat (i, "vlan %d", &vlan_id))
9454 vlan_id_set = 1;
9455 else
9456 {
9457 clib_warning ("parse error '%U'", format_unformat_error, i);
9458 return -99;
9459 }
9460 }
9461
9462 if (sw_if_index_set == 0)
9463 {
9464 errmsg ("missing interface name or sw_if_index");
9465 return -99;
9466 }
9467
9468 if (vlan_id_set == 0)
9469 {
9470 errmsg ("missing vlan_id");
9471 return -99;
9472 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009473 M (CREATE_VLAN_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009474
9475 mp->sw_if_index = ntohl (sw_if_index);
9476 mp->vlan_id = ntohl (vlan_id);
9477
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009478 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009479 W (ret);
9480 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009481}
9482
9483#define foreach_create_subif_bit \
9484_(no_tags) \
9485_(one_tag) \
9486_(two_tags) \
9487_(dot1ad) \
9488_(exact_match) \
9489_(default_sub) \
9490_(outer_vlan_id_any) \
9491_(inner_vlan_id_any)
9492
9493static int
9494api_create_subif (vat_main_t * vam)
9495{
9496 unformat_input_t *i = vam->input;
9497 vl_api_create_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009498 u32 sw_if_index;
9499 u8 sw_if_index_set = 0;
9500 u32 sub_id;
9501 u8 sub_id_set = 0;
9502 u32 no_tags = 0;
9503 u32 one_tag = 0;
9504 u32 two_tags = 0;
9505 u32 dot1ad = 0;
9506 u32 exact_match = 0;
9507 u32 default_sub = 0;
9508 u32 outer_vlan_id_any = 0;
9509 u32 inner_vlan_id_any = 0;
9510 u32 tmp;
9511 u16 outer_vlan_id = 0;
9512 u16 inner_vlan_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009513 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009514
9515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9516 {
9517 if (unformat (i, "sw_if_index %d", &sw_if_index))
9518 sw_if_index_set = 1;
9519 else
9520 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9521 sw_if_index_set = 1;
9522 else if (unformat (i, "sub_id %d", &sub_id))
9523 sub_id_set = 1;
9524 else if (unformat (i, "outer_vlan_id %d", &tmp))
9525 outer_vlan_id = tmp;
9526 else if (unformat (i, "inner_vlan_id %d", &tmp))
9527 inner_vlan_id = tmp;
9528
9529#define _(a) else if (unformat (i, #a)) a = 1 ;
9530 foreach_create_subif_bit
9531#undef _
9532 else
9533 {
9534 clib_warning ("parse error '%U'", format_unformat_error, i);
9535 return -99;
9536 }
9537 }
9538
9539 if (sw_if_index_set == 0)
9540 {
9541 errmsg ("missing interface name or sw_if_index");
9542 return -99;
9543 }
9544
9545 if (sub_id_set == 0)
9546 {
9547 errmsg ("missing sub_id");
9548 return -99;
9549 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009550 M (CREATE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009551
9552 mp->sw_if_index = ntohl (sw_if_index);
9553 mp->sub_id = ntohl (sub_id);
9554
9555#define _(a) mp->a = a;
9556 foreach_create_subif_bit;
9557#undef _
9558
9559 mp->outer_vlan_id = ntohs (outer_vlan_id);
9560 mp->inner_vlan_id = ntohs (inner_vlan_id);
9561
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009562 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009563 W (ret);
9564 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009565}
9566
9567static int
9568api_oam_add_del (vat_main_t * vam)
9569{
9570 unformat_input_t *i = vam->input;
9571 vl_api_oam_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009572 u32 vrf_id = 0;
9573 u8 is_add = 1;
9574 ip4_address_t src, dst;
9575 u8 src_set = 0;
9576 u8 dst_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009577 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009578
9579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9580 {
9581 if (unformat (i, "vrf %d", &vrf_id))
9582 ;
9583 else if (unformat (i, "src %U", unformat_ip4_address, &src))
9584 src_set = 1;
9585 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
9586 dst_set = 1;
9587 else if (unformat (i, "del"))
9588 is_add = 0;
9589 else
9590 {
9591 clib_warning ("parse error '%U'", format_unformat_error, i);
9592 return -99;
9593 }
9594 }
9595
9596 if (src_set == 0)
9597 {
9598 errmsg ("missing src addr");
9599 return -99;
9600 }
9601
9602 if (dst_set == 0)
9603 {
9604 errmsg ("missing dst addr");
9605 return -99;
9606 }
9607
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009608 M (OAM_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009609
9610 mp->vrf_id = ntohl (vrf_id);
9611 mp->is_add = is_add;
9612 clib_memcpy (mp->src_address, &src, sizeof (mp->src_address));
9613 clib_memcpy (mp->dst_address, &dst, sizeof (mp->dst_address));
9614
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009615 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009616 W (ret);
9617 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009618}
9619
9620static int
9621api_reset_fib (vat_main_t * vam)
9622{
9623 unformat_input_t *i = vam->input;
9624 vl_api_reset_fib_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009625 u32 vrf_id = 0;
9626 u8 is_ipv6 = 0;
9627 u8 vrf_id_set = 0;
9628
Jon Loeliger56c7b012017-02-01 12:31:41 -06009629 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9631 {
9632 if (unformat (i, "vrf %d", &vrf_id))
9633 vrf_id_set = 1;
9634 else if (unformat (i, "ipv6"))
9635 is_ipv6 = 1;
9636 else
9637 {
9638 clib_warning ("parse error '%U'", format_unformat_error, i);
9639 return -99;
9640 }
9641 }
9642
9643 if (vrf_id_set == 0)
9644 {
9645 errmsg ("missing vrf id");
9646 return -99;
9647 }
9648
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009649 M (RESET_FIB, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009650
9651 mp->vrf_id = ntohl (vrf_id);
9652 mp->is_ipv6 = is_ipv6;
9653
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009654 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009655 W (ret);
9656 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009657}
9658
9659static int
9660api_dhcp_proxy_config (vat_main_t * vam)
9661{
9662 unformat_input_t *i = vam->input;
9663 vl_api_dhcp_proxy_config_t *mp;
Neale Ranns20a175a2017-02-14 07:28:41 -08009664 u32 rx_vrf_id = 0;
9665 u32 server_vrf_id = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009666 u8 is_add = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009667 u8 v4_address_set = 0;
9668 u8 v6_address_set = 0;
9669 ip4_address_t v4address;
9670 ip6_address_t v6address;
9671 u8 v4_src_address_set = 0;
9672 u8 v6_src_address_set = 0;
9673 ip4_address_t v4srcaddress;
9674 ip6_address_t v6srcaddress;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009675 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009676
9677 /* Parse args required to build the message */
9678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9679 {
9680 if (unformat (i, "del"))
9681 is_add = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -08009682 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009683 ;
Neale Ranns20a175a2017-02-14 07:28:41 -08009684 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009685 ;
9686 else if (unformat (i, "svr %U", unformat_ip4_address, &v4address))
9687 v4_address_set = 1;
9688 else if (unformat (i, "svr %U", unformat_ip6_address, &v6address))
9689 v6_address_set = 1;
9690 else if (unformat (i, "src %U", unformat_ip4_address, &v4srcaddress))
9691 v4_src_address_set = 1;
9692 else if (unformat (i, "src %U", unformat_ip6_address, &v6srcaddress))
9693 v6_src_address_set = 1;
9694 else
9695 break;
9696 }
9697
9698 if (v4_address_set && v6_address_set)
9699 {
9700 errmsg ("both v4 and v6 server addresses set");
9701 return -99;
9702 }
9703 if (!v4_address_set && !v6_address_set)
9704 {
9705 errmsg ("no server addresses set");
9706 return -99;
9707 }
9708
9709 if (v4_src_address_set && v6_src_address_set)
9710 {
9711 errmsg ("both v4 and v6 src addresses set");
9712 return -99;
9713 }
9714 if (!v4_src_address_set && !v6_src_address_set)
9715 {
9716 errmsg ("no src addresses set");
9717 return -99;
9718 }
9719
9720 if (!(v4_src_address_set && v4_address_set) &&
9721 !(v6_src_address_set && v6_address_set))
9722 {
9723 errmsg ("no matching server and src addresses set");
9724 return -99;
9725 }
9726
9727 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009728 M (DHCP_PROXY_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009729
Damjan Marion7cd468a2016-12-19 23:05:39 +01009730 mp->is_add = is_add;
Neale Ranns20a175a2017-02-14 07:28:41 -08009731 mp->rx_vrf_id = ntohl (rx_vrf_id);
9732 mp->server_vrf_id = ntohl (server_vrf_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009733 if (v6_address_set)
9734 {
9735 mp->is_ipv6 = 1;
9736 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
9737 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
9738 }
9739 else
9740 {
9741 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
9742 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
9743 }
9744
9745 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009746 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009747
9748 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -06009749 W (ret);
9750 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009751}
9752
Neale Ranns20a175a2017-02-14 07:28:41 -08009753#define vl_api_dhcp_proxy_details_t_endian vl_noop_handler
9754#define vl_api_dhcp_proxy_details_t_print vl_noop_handler
9755
9756static void
9757vl_api_dhcp_proxy_details_t_handler (vl_api_dhcp_proxy_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009758{
Neale Ranns20a175a2017-02-14 07:28:41 -08009759 vat_main_t *vam = &vat_main;
Neale Ranns3466c302017-02-16 07:45:03 -08009760 u32 i, count = mp->count;
9761 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009762
Neale Ranns20a175a2017-02-14 07:28:41 -08009763 if (mp->is_ipv6)
9764 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009765 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009766 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009767 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009768 format_ip6_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009769 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009770 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
9771 else
9772 print (vam->ofp,
John Lo70bfcaf2017-11-14 13:19:26 -05009773 "RX Table-ID %d, Source Address %U, VSS Type %d, "
Igor Mikhailov (imichail)26f341a2018-02-12 13:45:51 -08009774 "VSS ASCII VPN-ID '%s', VSS RFC2685 VPN-ID (oui:id) %d:%d",
Neale Ranns20a175a2017-02-14 07:28:41 -08009775 ntohl (mp->rx_vrf_id),
Neale Ranns20a175a2017-02-14 07:28:41 -08009776 format_ip4_address, mp->dhcp_src_address,
John Lo70bfcaf2017-11-14 13:19:26 -05009777 mp->vss_type, mp->vss_vpn_ascii_id,
Neale Ranns20a175a2017-02-14 07:28:41 -08009778 ntohl (mp->vss_oui), ntohl (mp->vss_fib_id));
Neale Ranns3466c302017-02-16 07:45:03 -08009779
9780 for (i = 0; i < count; i++)
9781 {
9782 s = &mp->servers[i];
9783
9784 if (mp->is_ipv6)
9785 print (vam->ofp,
9786 " Server Table-ID %d, Server Address %U",
9787 ntohl (s->server_vrf_id), format_ip6_address, s->dhcp_server);
9788 else
9789 print (vam->ofp,
9790 " Server Table-ID %d, Server Address %U",
9791 ntohl (s->server_vrf_id), format_ip4_address, s->dhcp_server);
9792 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009793}
Damjan Marion7cd468a2016-12-19 23:05:39 +01009794
Neale Ranns20a175a2017-02-14 07:28:41 -08009795static void vl_api_dhcp_proxy_details_t_handler_json
9796 (vl_api_dhcp_proxy_details_t * mp)
9797{
9798 vat_main_t *vam = &vat_main;
9799 vat_json_node_t *node = NULL;
Neale Ranns3466c302017-02-16 07:45:03 -08009800 u32 i, count = mp->count;
Neale Ranns20a175a2017-02-14 07:28:41 -08009801 struct in_addr ip4;
9802 struct in6_addr ip6;
Neale Ranns3466c302017-02-16 07:45:03 -08009803 vl_api_dhcp_server_t *s;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009804
Neale Ranns20a175a2017-02-14 07:28:41 -08009805 if (VAT_JSON_ARRAY != vam->json_tree.type)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009806 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009807 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9808 vat_json_init_array (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009809 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009810 node = vat_json_array_add (&vam->json_tree);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009811
Neale Ranns20a175a2017-02-14 07:28:41 -08009812 vat_json_init_object (node);
9813 vat_json_object_add_uint (node, "rx-table-id", ntohl (mp->rx_vrf_id));
John Lo70bfcaf2017-11-14 13:19:26 -05009814 vat_json_object_add_bytes (node, "vss-type", &mp->vss_type,
9815 sizeof (mp->vss_type));
9816 vat_json_object_add_string_copy (node, "vss-vpn-ascii-id",
9817 mp->vss_vpn_ascii_id);
Neale Ranns3466c302017-02-16 07:45:03 -08009818 vat_json_object_add_uint (node, "vss-fib-id", ntohl (mp->vss_fib_id));
9819 vat_json_object_add_uint (node, "vss-oui", ntohl (mp->vss_oui));
9820
Neale Ranns20a175a2017-02-14 07:28:41 -08009821 if (mp->is_ipv6)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009822 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009823 clib_memcpy (&ip6, &mp->dhcp_src_address, sizeof (ip6));
9824 vat_json_object_add_ip6 (node, "src_address", ip6);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009825 }
9826 else
9827 {
Neale Ranns20a175a2017-02-14 07:28:41 -08009828 clib_memcpy (&ip4, &mp->dhcp_src_address, sizeof (ip4));
9829 vat_json_object_add_ip4 (node, "src_address", ip4);
9830 }
Neale Ranns3466c302017-02-16 07:45:03 -08009831
9832 for (i = 0; i < count; i++)
9833 {
9834 s = &mp->servers[i];
9835
9836 vat_json_object_add_uint (node, "server-table-id",
9837 ntohl (s->server_vrf_id));
9838
9839 if (mp->is_ipv6)
9840 {
9841 clib_memcpy (&ip4, &s->dhcp_server, sizeof (ip4));
9842 vat_json_object_add_ip4 (node, "src_address", ip4);
9843 }
9844 else
9845 {
9846 clib_memcpy (&ip6, &s->dhcp_server, sizeof (ip6));
9847 vat_json_object_add_ip6 (node, "server_address", ip6);
9848 }
9849 }
Neale Ranns20a175a2017-02-14 07:28:41 -08009850}
9851
9852static int
9853api_dhcp_proxy_dump (vat_main_t * vam)
9854{
9855 unformat_input_t *i = vam->input;
9856 vl_api_control_ping_t *mp_ping;
9857 vl_api_dhcp_proxy_dump_t *mp;
9858 u8 is_ipv6 = 0;
9859 int ret;
9860
9861 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9862 {
9863 if (unformat (i, "ipv6"))
9864 is_ipv6 = 1;
9865 else
9866 {
9867 clib_warning ("parse error '%U'", format_unformat_error, i);
9868 return -99;
9869 }
Damjan Marion7cd468a2016-12-19 23:05:39 +01009870 }
9871
Neale Ranns20a175a2017-02-14 07:28:41 -08009872 M (DHCP_PROXY_DUMP, mp);
9873
9874 mp->is_ip6 = is_ipv6;
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009875 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009876
Neale Ranns20a175a2017-02-14 07:28:41 -08009877 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -04009878 MPING (CONTROL_PING, mp_ping);
Neale Ranns20a175a2017-02-14 07:28:41 -08009879 S (mp_ping);
9880
Jon Loeliger56c7b012017-02-01 12:31:41 -06009881 W (ret);
9882 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009883}
9884
9885static int
9886api_dhcp_proxy_set_vss (vat_main_t * vam)
9887{
9888 unformat_input_t *i = vam->input;
9889 vl_api_dhcp_proxy_set_vss_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009890 u8 is_ipv6 = 0;
9891 u8 is_add = 1;
John Lo70bfcaf2017-11-14 13:19:26 -05009892 u32 tbl_id = ~0;
9893 u8 vss_type = VSS_TYPE_DEFAULT;
9894 u8 *vpn_ascii_id = 0;
9895 u32 oui = 0;
9896 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009897 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009898
9899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9900 {
9901 if (unformat (i, "tbl_id %d", &tbl_id))
John Lo70bfcaf2017-11-14 13:19:26 -05009902 ;
9903 else if (unformat (i, "vpn_ascii_id %s", &vpn_ascii_id))
9904 vss_type = VSS_TYPE_ASCII;
9905 else if (unformat (i, "fib_id %d", &fib_id))
9906 vss_type = VSS_TYPE_VPN_ID;
9907 else if (unformat (i, "oui %d", &oui))
9908 vss_type = VSS_TYPE_VPN_ID;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009909 else if (unformat (i, "ipv6"))
9910 is_ipv6 = 1;
9911 else if (unformat (i, "del"))
9912 is_add = 0;
9913 else
John Lo70bfcaf2017-11-14 13:19:26 -05009914 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009915 }
9916
John Lo70bfcaf2017-11-14 13:19:26 -05009917 if (tbl_id == ~0)
Damjan Marion7cd468a2016-12-19 23:05:39 +01009918 {
John Lo70bfcaf2017-11-14 13:19:26 -05009919 errmsg ("missing tbl_id ");
9920 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009921 return -99;
9922 }
9923
John Lo70bfcaf2017-11-14 13:19:26 -05009924 if ((vpn_ascii_id) && (vec_len (vpn_ascii_id) > 128))
Damjan Marion7cd468a2016-12-19 23:05:39 +01009925 {
John Lo70bfcaf2017-11-14 13:19:26 -05009926 errmsg ("vpn_ascii_id cannot be longer than 128 ");
9927 vec_free (vpn_ascii_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009928 return -99;
9929 }
9930
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009931 M (DHCP_PROXY_SET_VSS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009932 mp->tbl_id = ntohl (tbl_id);
John Lo70bfcaf2017-11-14 13:19:26 -05009933 mp->vss_type = vss_type;
9934 if (vpn_ascii_id)
9935 {
9936 clib_memcpy (mp->vpn_ascii_id, vpn_ascii_id, vec_len (vpn_ascii_id));
9937 mp->vpn_ascii_id[vec_len (vpn_ascii_id)] = 0;
9938 }
9939 mp->vpn_index = ntohl (fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009940 mp->oui = ntohl (oui);
9941 mp->is_ipv6 = is_ipv6;
9942 mp->is_add = is_add;
9943
Jon Loeliger7bc770c2017-01-31 14:03:33 -06009944 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009945 W (ret);
John Lo70bfcaf2017-11-14 13:19:26 -05009946
9947 vec_free (vpn_ascii_id);
Jon Loeliger56c7b012017-02-01 12:31:41 -06009948 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009949}
9950
9951static int
9952api_dhcp_client_config (vat_main_t * vam)
9953{
9954 unformat_input_t *i = vam->input;
9955 vl_api_dhcp_client_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009956 u32 sw_if_index;
9957 u8 sw_if_index_set = 0;
9958 u8 is_add = 1;
9959 u8 *hostname = 0;
9960 u8 disable_event = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -06009961 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +01009962
9963 /* Parse args required to build the message */
9964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9965 {
9966 if (unformat (i, "del"))
9967 is_add = 0;
9968 else
9969 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9970 sw_if_index_set = 1;
9971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9972 sw_if_index_set = 1;
9973 else if (unformat (i, "hostname %s", &hostname))
9974 ;
9975 else if (unformat (i, "disable_event"))
9976 disable_event = 1;
9977 else
9978 break;
9979 }
9980
9981 if (sw_if_index_set == 0)
9982 {
9983 errmsg ("missing interface name or sw_if_index");
9984 return -99;
9985 }
9986
9987 if (vec_len (hostname) > 63)
9988 {
9989 errmsg ("hostname too long");
9990 }
9991 vec_add1 (hostname, 0);
9992
9993 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -06009994 M (DHCP_CLIENT_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +01009995
Damjan Marion7cd468a2016-12-19 23:05:39 +01009996 mp->is_add = is_add;
Neale Rannsdaff1782018-05-16 04:12:18 -07009997 mp->client.sw_if_index = htonl (sw_if_index);
9998 clib_memcpy (mp->client.hostname, hostname, vec_len (hostname));
9999 vec_free (hostname);
10000 mp->client.want_dhcp_event = disable_event ? 0 : 1;
10001 mp->client.pid = htonl (getpid ());
Damjan Marion7cd468a2016-12-19 23:05:39 +010010002
10003 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010004 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010005
10006 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -060010007 W (ret);
10008 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010009}
10010
10011static int
10012api_set_ip_flow_hash (vat_main_t * vam)
10013{
10014 unformat_input_t *i = vam->input;
10015 vl_api_set_ip_flow_hash_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010016 u32 vrf_id = 0;
10017 u8 is_ipv6 = 0;
10018 u8 vrf_id_set = 0;
10019 u8 src = 0;
10020 u8 dst = 0;
10021 u8 sport = 0;
10022 u8 dport = 0;
10023 u8 proto = 0;
10024 u8 reverse = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010025 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010026
10027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10028 {
10029 if (unformat (i, "vrf %d", &vrf_id))
10030 vrf_id_set = 1;
10031 else if (unformat (i, "ipv6"))
10032 is_ipv6 = 1;
10033 else if (unformat (i, "src"))
10034 src = 1;
10035 else if (unformat (i, "dst"))
10036 dst = 1;
10037 else if (unformat (i, "sport"))
10038 sport = 1;
10039 else if (unformat (i, "dport"))
10040 dport = 1;
10041 else if (unformat (i, "proto"))
10042 proto = 1;
10043 else if (unformat (i, "reverse"))
10044 reverse = 1;
10045
10046 else
10047 {
10048 clib_warning ("parse error '%U'", format_unformat_error, i);
10049 return -99;
10050 }
10051 }
10052
10053 if (vrf_id_set == 0)
10054 {
10055 errmsg ("missing vrf id");
10056 return -99;
10057 }
10058
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010059 M (SET_IP_FLOW_HASH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010060 mp->src = src;
10061 mp->dst = dst;
10062 mp->sport = sport;
10063 mp->dport = dport;
10064 mp->proto = proto;
10065 mp->reverse = reverse;
10066 mp->vrf_id = ntohl (vrf_id);
10067 mp->is_ipv6 = is_ipv6;
10068
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010069 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010070 W (ret);
10071 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010072}
10073
10074static int
10075api_sw_interface_ip6_enable_disable (vat_main_t * vam)
10076{
10077 unformat_input_t *i = vam->input;
10078 vl_api_sw_interface_ip6_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010079 u32 sw_if_index;
10080 u8 sw_if_index_set = 0;
10081 u8 enable = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010082 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010083
10084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10085 {
10086 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10087 sw_if_index_set = 1;
10088 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10089 sw_if_index_set = 1;
10090 else if (unformat (i, "enable"))
10091 enable = 1;
10092 else if (unformat (i, "disable"))
10093 enable = 0;
10094 else
10095 {
10096 clib_warning ("parse error '%U'", format_unformat_error, i);
10097 return -99;
10098 }
10099 }
10100
10101 if (sw_if_index_set == 0)
10102 {
10103 errmsg ("missing interface name or sw_if_index");
10104 return -99;
10105 }
10106
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010107 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010108
10109 mp->sw_if_index = ntohl (sw_if_index);
10110 mp->enable = enable;
10111
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010112 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010113 W (ret);
10114 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010115}
10116
10117static int
Neale Ranns3f844d02017-02-18 00:03:54 -080010118api_ip6nd_proxy_add_del (vat_main_t * vam)
10119{
10120 unformat_input_t *i = vam->input;
10121 vl_api_ip6nd_proxy_add_del_t *mp;
10122 u32 sw_if_index = ~0;
10123 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -070010124 vl_api_ip6_address_t v6address;
Neale Ranns3f844d02017-02-18 00:03:54 -080010125 u8 is_del = 0;
10126 int ret;
10127
10128 /* Parse args required to build the message */
10129 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10130 {
10131 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10132 ;
10133 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10134 ;
Neale Ranns37029302018-08-10 05:30:06 -070010135 else if (unformat (i, "%U", unformat_vl_api_ip6_address, &v6address))
Neale Ranns3f844d02017-02-18 00:03:54 -080010136 v6_address_set = 1;
10137 if (unformat (i, "del"))
10138 is_del = 1;
10139 else
10140 {
10141 clib_warning ("parse error '%U'", format_unformat_error, i);
10142 return -99;
10143 }
10144 }
10145
10146 if (sw_if_index == ~0)
10147 {
10148 errmsg ("missing interface name or sw_if_index");
10149 return -99;
10150 }
10151 if (!v6_address_set)
10152 {
10153 errmsg ("no address set");
10154 return -99;
10155 }
10156
10157 /* Construct the API message */
10158 M (IP6ND_PROXY_ADD_DEL, mp);
10159
10160 mp->is_del = is_del;
10161 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -070010162 clib_memcpy (mp->ip, v6address, sizeof (v6address));
Neale Ranns3f844d02017-02-18 00:03:54 -080010163
10164 /* send it... */
10165 S (mp);
10166
10167 /* Wait for a reply, return good/bad news */
10168 W (ret);
10169 return ret;
10170}
10171
10172static int
10173api_ip6nd_proxy_dump (vat_main_t * vam)
10174{
10175 vl_api_ip6nd_proxy_dump_t *mp;
10176 vl_api_control_ping_t *mp_ping;
10177 int ret;
10178
10179 M (IP6ND_PROXY_DUMP, mp);
10180
10181 S (mp);
10182
10183 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040010184 MPING (CONTROL_PING, mp_ping);
Neale Ranns3f844d02017-02-18 00:03:54 -080010185 S (mp_ping);
10186
10187 W (ret);
10188 return ret;
10189}
10190
10191static void vl_api_ip6nd_proxy_details_t_handler
10192 (vl_api_ip6nd_proxy_details_t * mp)
10193{
10194 vat_main_t *vam = &vat_main;
10195
10196 print (vam->ofp, "host %U sw_if_index %d",
Neale Ranns37029302018-08-10 05:30:06 -070010197 format_vl_api_ip6_address, mp->ip, ntohl (mp->sw_if_index));
Neale Ranns3f844d02017-02-18 00:03:54 -080010198}
10199
10200static void vl_api_ip6nd_proxy_details_t_handler_json
10201 (vl_api_ip6nd_proxy_details_t * mp)
10202{
10203 vat_main_t *vam = &vat_main;
10204 struct in6_addr ip6;
10205 vat_json_node_t *node = NULL;
10206
10207 if (VAT_JSON_ARRAY != vam->json_tree.type)
10208 {
10209 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10210 vat_json_init_array (&vam->json_tree);
10211 }
10212 node = vat_json_array_add (&vam->json_tree);
10213
10214 vat_json_init_object (node);
10215 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10216
Neale Ranns37029302018-08-10 05:30:06 -070010217 clib_memcpy (&ip6, mp->ip, sizeof (ip6));
Neale Ranns3f844d02017-02-18 00:03:54 -080010218 vat_json_object_add_ip6 (node, "host", ip6);
10219}
Damjan Marion7cd468a2016-12-19 23:05:39 +010010220
10221static int
10222api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
10223{
10224 unformat_input_t *i = vam->input;
10225 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010226 u32 sw_if_index;
10227 u8 sw_if_index_set = 0;
10228 u32 address_length = 0;
10229 u8 v6_address_set = 0;
Neale Ranns37029302018-08-10 05:30:06 -070010230 vl_api_prefix_t pfx;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010231 u8 use_default = 0;
10232 u8 no_advertise = 0;
10233 u8 off_link = 0;
10234 u8 no_autoconfig = 0;
10235 u8 no_onlink = 0;
10236 u8 is_no = 0;
10237 u32 val_lifetime = 0;
10238 u32 pref_lifetime = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010239 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010240
10241 /* Parse args required to build the message */
10242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10243 {
10244 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10245 sw_if_index_set = 1;
10246 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10247 sw_if_index_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -070010248 else if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
Damjan Marion7cd468a2016-12-19 23:05:39 +010010249 v6_address_set = 1;
10250 else if (unformat (i, "val_life %d", &val_lifetime))
10251 ;
10252 else if (unformat (i, "pref_life %d", &pref_lifetime))
10253 ;
10254 else if (unformat (i, "def"))
10255 use_default = 1;
10256 else if (unformat (i, "noadv"))
10257 no_advertise = 1;
10258 else if (unformat (i, "offl"))
10259 off_link = 1;
10260 else if (unformat (i, "noauto"))
10261 no_autoconfig = 1;
10262 else if (unformat (i, "nolink"))
10263 no_onlink = 1;
10264 else if (unformat (i, "isno"))
10265 is_no = 1;
10266 else
10267 {
10268 clib_warning ("parse error '%U'", format_unformat_error, i);
10269 return -99;
10270 }
10271 }
10272
10273 if (sw_if_index_set == 0)
10274 {
10275 errmsg ("missing interface name or sw_if_index");
10276 return -99;
10277 }
10278 if (!v6_address_set)
10279 {
10280 errmsg ("no address set");
10281 return -99;
10282 }
10283
10284 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010285 M (SW_INTERFACE_IP6ND_RA_PREFIX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010286
10287 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -070010288 clib_memcpy (&mp->prefix, &pfx, sizeof (pfx));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010289 mp->use_default = use_default;
10290 mp->no_advertise = no_advertise;
10291 mp->off_link = off_link;
10292 mp->no_autoconfig = no_autoconfig;
10293 mp->no_onlink = no_onlink;
10294 mp->is_no = is_no;
10295 mp->val_lifetime = ntohl (val_lifetime);
10296 mp->pref_lifetime = ntohl (pref_lifetime);
10297
10298 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010299 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010300
10301 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -060010302 W (ret);
10303 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010304}
10305
10306static int
10307api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
10308{
10309 unformat_input_t *i = vam->input;
10310 vl_api_sw_interface_ip6nd_ra_config_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010311 u32 sw_if_index;
10312 u8 sw_if_index_set = 0;
10313 u8 suppress = 0;
10314 u8 managed = 0;
10315 u8 other = 0;
10316 u8 ll_option = 0;
10317 u8 send_unicast = 0;
10318 u8 cease = 0;
10319 u8 is_no = 0;
10320 u8 default_router = 0;
10321 u32 max_interval = 0;
10322 u32 min_interval = 0;
10323 u32 lifetime = 0;
10324 u32 initial_count = 0;
10325 u32 initial_interval = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010326 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010327
10328
10329 /* Parse args required to build the message */
10330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10331 {
10332 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10333 sw_if_index_set = 1;
10334 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10335 sw_if_index_set = 1;
10336 else if (unformat (i, "maxint %d", &max_interval))
10337 ;
10338 else if (unformat (i, "minint %d", &min_interval))
10339 ;
10340 else if (unformat (i, "life %d", &lifetime))
10341 ;
10342 else if (unformat (i, "count %d", &initial_count))
10343 ;
10344 else if (unformat (i, "interval %d", &initial_interval))
10345 ;
10346 else if (unformat (i, "suppress") || unformat (i, "surpress"))
10347 suppress = 1;
10348 else if (unformat (i, "managed"))
10349 managed = 1;
10350 else if (unformat (i, "other"))
10351 other = 1;
10352 else if (unformat (i, "ll"))
10353 ll_option = 1;
10354 else if (unformat (i, "send"))
10355 send_unicast = 1;
10356 else if (unformat (i, "cease"))
10357 cease = 1;
10358 else if (unformat (i, "isno"))
10359 is_no = 1;
10360 else if (unformat (i, "def"))
10361 default_router = 1;
10362 else
10363 {
10364 clib_warning ("parse error '%U'", format_unformat_error, i);
10365 return -99;
10366 }
10367 }
10368
10369 if (sw_if_index_set == 0)
10370 {
10371 errmsg ("missing interface name or sw_if_index");
10372 return -99;
10373 }
10374
10375 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010376 M (SW_INTERFACE_IP6ND_RA_CONFIG, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010377
10378 mp->sw_if_index = ntohl (sw_if_index);
10379 mp->max_interval = ntohl (max_interval);
10380 mp->min_interval = ntohl (min_interval);
10381 mp->lifetime = ntohl (lifetime);
10382 mp->initial_count = ntohl (initial_count);
10383 mp->initial_interval = ntohl (initial_interval);
10384 mp->suppress = suppress;
10385 mp->managed = managed;
10386 mp->other = other;
10387 mp->ll_option = ll_option;
10388 mp->send_unicast = send_unicast;
10389 mp->cease = cease;
10390 mp->is_no = is_no;
10391 mp->default_router = default_router;
10392
10393 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010394 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010395
10396 /* Wait for a reply, return good/bad news */
Jon Loeliger56c7b012017-02-01 12:31:41 -060010397 W (ret);
10398 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010399}
10400
10401static int
10402api_set_arp_neighbor_limit (vat_main_t * vam)
10403{
10404 unformat_input_t *i = vam->input;
10405 vl_api_set_arp_neighbor_limit_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010406 u32 arp_nbr_limit;
10407 u8 limit_set = 0;
10408 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010409 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010410
10411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10412 {
10413 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
10414 limit_set = 1;
10415 else if (unformat (i, "ipv6"))
10416 is_ipv6 = 1;
10417 else
10418 {
10419 clib_warning ("parse error '%U'", format_unformat_error, i);
10420 return -99;
10421 }
10422 }
10423
10424 if (limit_set == 0)
10425 {
10426 errmsg ("missing limit value");
10427 return -99;
10428 }
10429
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010430 M (SET_ARP_NEIGHBOR_LIMIT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010431
10432 mp->arp_neighbor_limit = ntohl (arp_nbr_limit);
10433 mp->is_ipv6 = is_ipv6;
10434
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010435 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010436 W (ret);
10437 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010438}
10439
10440static int
10441api_l2_patch_add_del (vat_main_t * vam)
10442{
10443 unformat_input_t *i = vam->input;
10444 vl_api_l2_patch_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010445 u32 rx_sw_if_index;
10446 u8 rx_sw_if_index_set = 0;
10447 u32 tx_sw_if_index;
10448 u8 tx_sw_if_index_set = 0;
10449 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010450 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010451
10452 /* Parse args required to build the message */
10453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10454 {
10455 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
10456 rx_sw_if_index_set = 1;
10457 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
10458 tx_sw_if_index_set = 1;
10459 else if (unformat (i, "rx"))
10460 {
10461 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10462 {
10463 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10464 &rx_sw_if_index))
10465 rx_sw_if_index_set = 1;
10466 }
10467 else
10468 break;
10469 }
10470 else if (unformat (i, "tx"))
10471 {
10472 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10473 {
10474 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
10475 &tx_sw_if_index))
10476 tx_sw_if_index_set = 1;
10477 }
10478 else
10479 break;
10480 }
10481 else if (unformat (i, "del"))
10482 is_add = 0;
10483 else
10484 break;
10485 }
10486
10487 if (rx_sw_if_index_set == 0)
10488 {
10489 errmsg ("missing rx interface name or rx_sw_if_index");
10490 return -99;
10491 }
10492
10493 if (tx_sw_if_index_set == 0)
10494 {
10495 errmsg ("missing tx interface name or tx_sw_if_index");
10496 return -99;
10497 }
10498
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010499 M (L2_PATCH_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010500
10501 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
10502 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
10503 mp->is_add = is_add;
10504
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010505 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010506 W (ret);
10507 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010508}
10509
Pablo Camarillofb380952016-12-07 18:34:18 +010010510u8 is_del;
10511u8 localsid_addr[16];
10512u8 end_psp;
10513u8 behavior;
10514u32 sw_if_index;
10515u32 vlan_index;
10516u32 fib_table;
10517u8 nh_addr[16];
10518
10519static int
10520api_sr_localsid_add_del (vat_main_t * vam)
10521{
10522 unformat_input_t *i = vam->input;
10523 vl_api_sr_localsid_add_del_t *mp;
10524
10525 u8 is_del;
10526 ip6_address_t localsid;
10527 u8 end_psp = 0;
10528 u8 behavior = ~0;
10529 u32 sw_if_index;
10530 u32 fib_table = ~(u32) 0;
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010531 ip6_address_t nh_addr6;
10532 ip4_address_t nh_addr4;
Dave Barachb7b92992018-10-17 10:38:51 -040010533 clib_memset (&nh_addr6, 0, sizeof (ip6_address_t));
10534 clib_memset (&nh_addr4, 0, sizeof (ip4_address_t));
Pablo Camarillofb380952016-12-07 18:34:18 +010010535
10536 bool nexthop_set = 0;
10537
10538 int ret;
10539
10540 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10541 {
10542 if (unformat (i, "del"))
10543 is_del = 1;
10544 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010545 else if (unformat (i, "next-hop %U", unformat_ip4_address, &nh_addr4))
10546 nexthop_set = 1;
10547 else if (unformat (i, "next-hop %U", unformat_ip6_address, &nh_addr6))
Pablo Camarillofb380952016-12-07 18:34:18 +010010548 nexthop_set = 1;
10549 else if (unformat (i, "behavior %u", &behavior));
10550 else if (unformat (i, "sw_if_index %u", &sw_if_index));
10551 else if (unformat (i, "fib-table %u", &fib_table));
10552 else if (unformat (i, "end.psp %u", &behavior));
10553 else
10554 break;
10555 }
10556
10557 M (SR_LOCALSID_ADD_DEL, mp);
10558
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010559 clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid));
Pablo Camarillofb380952016-12-07 18:34:18 +010010560 if (nexthop_set)
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010561 {
Lijian Zhangec2a9bb2018-08-28 10:18:24 +080010562 clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6));
10563 clib_memcpy (mp->nh_addr4, &nh_addr4, sizeof (mp->nh_addr4));
Pablo Camarillo3337bd22018-06-19 15:49:02 +020010564 }
Pablo Camarillofb380952016-12-07 18:34:18 +010010565 mp->behavior = behavior;
10566 mp->sw_if_index = ntohl (sw_if_index);
10567 mp->fib_table = ntohl (fib_table);
10568 mp->end_psp = end_psp;
10569 mp->is_del = is_del;
10570
10571 S (mp);
10572 W (ret);
10573 return ret;
10574}
10575
Damjan Marion7cd468a2016-12-19 23:05:39 +010010576static int
10577api_ioam_enable (vat_main_t * vam)
10578{
10579 unformat_input_t *input = vam->input;
10580 vl_api_ioam_enable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010581 u32 id = 0;
10582 int has_trace_option = 0;
10583 int has_pot_option = 0;
10584 int has_seqno_option = 0;
10585 int has_analyse_option = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010586 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010587
10588 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10589 {
10590 if (unformat (input, "trace"))
10591 has_trace_option = 1;
10592 else if (unformat (input, "pot"))
10593 has_pot_option = 1;
10594 else if (unformat (input, "seqno"))
10595 has_seqno_option = 1;
10596 else if (unformat (input, "analyse"))
10597 has_analyse_option = 1;
10598 else
10599 break;
10600 }
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010601 M (IOAM_ENABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010602 mp->id = htons (id);
10603 mp->seqno = has_seqno_option;
10604 mp->analyse = has_analyse_option;
10605 mp->pot_enable = has_pot_option;
10606 mp->trace_enable = has_trace_option;
10607
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010608 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010609 W (ret);
10610 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010611}
10612
10613
10614static int
10615api_ioam_disable (vat_main_t * vam)
10616{
10617 vl_api_ioam_disable_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060010618 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010619
Jon Loeliger8a2aea32017-01-31 13:19:40 -060010620 M (IOAM_DISABLE, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060010621 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060010622 W (ret);
10623 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010010624}
10625
Damjan Marion7cd468a2016-12-19 23:05:39 +010010626#define foreach_tcp_proto_field \
10627_(src_port) \
10628_(dst_port)
10629
10630#define foreach_udp_proto_field \
10631_(src_port) \
10632_(dst_port)
10633
10634#define foreach_ip4_proto_field \
10635_(src_address) \
10636_(dst_address) \
10637_(tos) \
10638_(length) \
10639_(fragment_id) \
10640_(ttl) \
10641_(protocol) \
10642_(checksum)
10643
Dave Barach4a3f69c2017-02-22 12:44:56 -050010644typedef struct
10645{
10646 u16 src_port, dst_port;
10647} tcpudp_header_t;
10648
10649#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010010650uword
10651unformat_tcp_mask (unformat_input_t * input, va_list * args)
10652{
10653 u8 **maskp = va_arg (*args, u8 **);
10654 u8 *mask = 0;
10655 u8 found_something = 0;
10656 tcp_header_t *tcp;
10657
10658#define _(a) u8 a=0;
10659 foreach_tcp_proto_field;
10660#undef _
10661
10662 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10663 {
10664 if (0);
10665#define _(a) else if (unformat (input, #a)) a=1;
10666 foreach_tcp_proto_field
10667#undef _
10668 else
10669 break;
10670 }
10671
10672#define _(a) found_something += a;
10673 foreach_tcp_proto_field;
10674#undef _
10675
10676 if (found_something == 0)
10677 return 0;
10678
10679 vec_validate (mask, sizeof (*tcp) - 1);
10680
10681 tcp = (tcp_header_t *) mask;
10682
Dave Barachb7b92992018-10-17 10:38:51 -040010683#define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010684 foreach_tcp_proto_field;
10685#undef _
10686
10687 *maskp = mask;
10688 return 1;
10689}
10690
10691uword
10692unformat_udp_mask (unformat_input_t * input, va_list * args)
10693{
10694 u8 **maskp = va_arg (*args, u8 **);
10695 u8 *mask = 0;
10696 u8 found_something = 0;
10697 udp_header_t *udp;
10698
10699#define _(a) u8 a=0;
10700 foreach_udp_proto_field;
10701#undef _
10702
10703 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10704 {
10705 if (0);
10706#define _(a) else if (unformat (input, #a)) a=1;
10707 foreach_udp_proto_field
10708#undef _
10709 else
10710 break;
10711 }
10712
10713#define _(a) found_something += a;
10714 foreach_udp_proto_field;
10715#undef _
10716
10717 if (found_something == 0)
10718 return 0;
10719
10720 vec_validate (mask, sizeof (*udp) - 1);
10721
10722 udp = (udp_header_t *) mask;
10723
Dave Barachb7b92992018-10-17 10:38:51 -040010724#define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010725 foreach_udp_proto_field;
10726#undef _
10727
10728 *maskp = mask;
10729 return 1;
10730}
10731
Damjan Marion7cd468a2016-12-19 23:05:39 +010010732uword
10733unformat_l4_mask (unformat_input_t * input, va_list * args)
10734{
10735 u8 **maskp = va_arg (*args, u8 **);
10736 u16 src_port = 0, dst_port = 0;
10737 tcpudp_header_t *tcpudp;
10738
10739 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10740 {
10741 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
10742 return 1;
10743 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
10744 return 1;
10745 else if (unformat (input, "src_port"))
10746 src_port = 0xFFFF;
10747 else if (unformat (input, "dst_port"))
10748 dst_port = 0xFFFF;
10749 else
10750 return 0;
10751 }
10752
10753 if (!src_port && !dst_port)
10754 return 0;
10755
10756 u8 *mask = 0;
10757 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
10758
10759 tcpudp = (tcpudp_header_t *) mask;
10760 tcpudp->src_port = src_port;
10761 tcpudp->dst_port = dst_port;
10762
10763 *maskp = mask;
10764
10765 return 1;
10766}
10767
10768uword
10769unformat_ip4_mask (unformat_input_t * input, va_list * args)
10770{
10771 u8 **maskp = va_arg (*args, u8 **);
10772 u8 *mask = 0;
10773 u8 found_something = 0;
10774 ip4_header_t *ip;
10775
10776#define _(a) u8 a=0;
10777 foreach_ip4_proto_field;
10778#undef _
10779 u8 version = 0;
10780 u8 hdr_length = 0;
10781
10782
10783 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10784 {
10785 if (unformat (input, "version"))
10786 version = 1;
10787 else if (unformat (input, "hdr_length"))
10788 hdr_length = 1;
10789 else if (unformat (input, "src"))
10790 src_address = 1;
10791 else if (unformat (input, "dst"))
10792 dst_address = 1;
10793 else if (unformat (input, "proto"))
10794 protocol = 1;
10795
10796#define _(a) else if (unformat (input, #a)) a=1;
10797 foreach_ip4_proto_field
10798#undef _
10799 else
10800 break;
10801 }
10802
10803#define _(a) found_something += a;
10804 foreach_ip4_proto_field;
10805#undef _
10806
10807 if (found_something == 0)
10808 return 0;
10809
10810 vec_validate (mask, sizeof (*ip) - 1);
10811
10812 ip = (ip4_header_t *) mask;
10813
Dave Barachb7b92992018-10-17 10:38:51 -040010814#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010815 foreach_ip4_proto_field;
10816#undef _
10817
10818 ip->ip_version_and_header_length = 0;
10819
10820 if (version)
10821 ip->ip_version_and_header_length |= 0xF0;
10822
10823 if (hdr_length)
10824 ip->ip_version_and_header_length |= 0x0F;
10825
10826 *maskp = mask;
10827 return 1;
10828}
10829
10830#define foreach_ip6_proto_field \
10831_(src_address) \
10832_(dst_address) \
10833_(payload_length) \
10834_(hop_limit) \
10835_(protocol)
10836
10837uword
10838unformat_ip6_mask (unformat_input_t * input, va_list * args)
10839{
10840 u8 **maskp = va_arg (*args, u8 **);
10841 u8 *mask = 0;
10842 u8 found_something = 0;
10843 ip6_header_t *ip;
10844 u32 ip_version_traffic_class_and_flow_label;
10845
10846#define _(a) u8 a=0;
10847 foreach_ip6_proto_field;
10848#undef _
10849 u8 version = 0;
10850 u8 traffic_class = 0;
10851 u8 flow_label = 0;
10852
10853 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10854 {
10855 if (unformat (input, "version"))
10856 version = 1;
10857 else if (unformat (input, "traffic-class"))
10858 traffic_class = 1;
10859 else if (unformat (input, "flow-label"))
10860 flow_label = 1;
10861 else if (unformat (input, "src"))
10862 src_address = 1;
10863 else if (unformat (input, "dst"))
10864 dst_address = 1;
10865 else if (unformat (input, "proto"))
10866 protocol = 1;
10867
10868#define _(a) else if (unformat (input, #a)) a=1;
10869 foreach_ip6_proto_field
10870#undef _
10871 else
10872 break;
10873 }
10874
10875#define _(a) found_something += a;
10876 foreach_ip6_proto_field;
10877#undef _
10878
10879 if (found_something == 0)
10880 return 0;
10881
10882 vec_validate (mask, sizeof (*ip) - 1);
10883
10884 ip = (ip6_header_t *) mask;
10885
Dave Barachb7b92992018-10-17 10:38:51 -040010886#define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
Damjan Marion7cd468a2016-12-19 23:05:39 +010010887 foreach_ip6_proto_field;
10888#undef _
10889
10890 ip_version_traffic_class_and_flow_label = 0;
10891
10892 if (version)
10893 ip_version_traffic_class_and_flow_label |= 0xF0000000;
10894
10895 if (traffic_class)
10896 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
10897
10898 if (flow_label)
10899 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
10900
10901 ip->ip_version_traffic_class_and_flow_label =
10902 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
10903
10904 *maskp = mask;
10905 return 1;
10906}
10907
10908uword
10909unformat_l3_mask (unformat_input_t * input, va_list * args)
10910{
10911 u8 **maskp = va_arg (*args, u8 **);
10912
10913 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10914 {
10915 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
10916 return 1;
10917 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
10918 return 1;
10919 else
10920 break;
10921 }
10922 return 0;
10923}
10924
10925uword
10926unformat_l2_mask (unformat_input_t * input, va_list * args)
10927{
10928 u8 **maskp = va_arg (*args, u8 **);
10929 u8 *mask = 0;
10930 u8 src = 0;
10931 u8 dst = 0;
10932 u8 proto = 0;
10933 u8 tag1 = 0;
10934 u8 tag2 = 0;
10935 u8 ignore_tag1 = 0;
10936 u8 ignore_tag2 = 0;
10937 u8 cos1 = 0;
10938 u8 cos2 = 0;
10939 u8 dot1q = 0;
10940 u8 dot1ad = 0;
10941 int len = 14;
10942
10943 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10944 {
10945 if (unformat (input, "src"))
10946 src = 1;
10947 else if (unformat (input, "dst"))
10948 dst = 1;
10949 else if (unformat (input, "proto"))
10950 proto = 1;
10951 else if (unformat (input, "tag1"))
10952 tag1 = 1;
10953 else if (unformat (input, "tag2"))
10954 tag2 = 1;
10955 else if (unformat (input, "ignore-tag1"))
10956 ignore_tag1 = 1;
10957 else if (unformat (input, "ignore-tag2"))
10958 ignore_tag2 = 1;
10959 else if (unformat (input, "cos1"))
10960 cos1 = 1;
10961 else if (unformat (input, "cos2"))
10962 cos2 = 1;
10963 else if (unformat (input, "dot1q"))
10964 dot1q = 1;
10965 else if (unformat (input, "dot1ad"))
10966 dot1ad = 1;
10967 else
10968 break;
10969 }
10970 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
10971 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
10972 return 0;
10973
10974 if (tag1 || ignore_tag1 || cos1 || dot1q)
10975 len = 18;
10976 if (tag2 || ignore_tag2 || cos2 || dot1ad)
10977 len = 22;
10978
10979 vec_validate (mask, len - 1);
10980
10981 if (dst)
Dave Barachb7b92992018-10-17 10:38:51 -040010982 clib_memset (mask, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010983
10984 if (src)
Dave Barachb7b92992018-10-17 10:38:51 -040010985 clib_memset (mask + 6, 0xff, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010010986
10987 if (tag2 || dot1ad)
10988 {
10989 /* inner vlan tag */
10990 if (tag2)
10991 {
10992 mask[19] = 0xff;
10993 mask[18] = 0x0f;
10994 }
10995 if (cos2)
10996 mask[18] |= 0xe0;
10997 if (proto)
10998 mask[21] = mask[20] = 0xff;
10999 if (tag1)
11000 {
11001 mask[15] = 0xff;
11002 mask[14] = 0x0f;
11003 }
11004 if (cos1)
11005 mask[14] |= 0xe0;
11006 *maskp = mask;
11007 return 1;
11008 }
11009 if (tag1 | dot1q)
11010 {
11011 if (tag1)
11012 {
11013 mask[15] = 0xff;
11014 mask[14] = 0x0f;
11015 }
11016 if (cos1)
11017 mask[14] |= 0xe0;
11018 if (proto)
11019 mask[16] = mask[17] = 0xff;
11020
11021 *maskp = mask;
11022 return 1;
11023 }
11024 if (cos2)
11025 mask[18] |= 0xe0;
11026 if (cos1)
11027 mask[14] |= 0xe0;
11028 if (proto)
11029 mask[12] = mask[13] = 0xff;
11030
11031 *maskp = mask;
11032 return 1;
11033}
11034
11035uword
11036unformat_classify_mask (unformat_input_t * input, va_list * args)
11037{
11038 u8 **maskp = va_arg (*args, u8 **);
11039 u32 *skipp = va_arg (*args, u32 *);
11040 u32 *matchp = va_arg (*args, u32 *);
11041 u32 match;
11042 u8 *mask = 0;
11043 u8 *l2 = 0;
11044 u8 *l3 = 0;
11045 u8 *l4 = 0;
11046 int i;
11047
11048 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11049 {
11050 if (unformat (input, "hex %U", unformat_hex_string, &mask))
11051 ;
11052 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
11053 ;
11054 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
11055 ;
11056 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
11057 ;
11058 else
11059 break;
11060 }
11061
11062 if (l4 && !l3)
11063 {
11064 vec_free (mask);
11065 vec_free (l2);
11066 vec_free (l4);
11067 return 0;
11068 }
11069
11070 if (mask || l2 || l3 || l4)
11071 {
11072 if (l2 || l3 || l4)
11073 {
11074 /* "With a free Ethernet header in every package" */
11075 if (l2 == 0)
11076 vec_validate (l2, 13);
11077 mask = l2;
11078 if (vec_len (l3))
11079 {
11080 vec_append (mask, l3);
11081 vec_free (l3);
11082 }
11083 if (vec_len (l4))
11084 {
11085 vec_append (mask, l4);
11086 vec_free (l4);
11087 }
11088 }
11089
11090 /* Scan forward looking for the first significant mask octet */
11091 for (i = 0; i < vec_len (mask); i++)
11092 if (mask[i])
11093 break;
11094
11095 /* compute (skip, match) params */
11096 *skipp = i / sizeof (u32x4);
11097 vec_delete (mask, *skipp * sizeof (u32x4), 0);
11098
11099 /* Pad mask to an even multiple of the vector size */
11100 while (vec_len (mask) % sizeof (u32x4))
11101 vec_add1 (mask, 0);
11102
11103 match = vec_len (mask) / sizeof (u32x4);
11104
11105 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
11106 {
11107 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
11108 if (*tmp || *(tmp + 1))
11109 break;
11110 match--;
11111 }
11112 if (match == 0)
11113 clib_warning ("BUG: match 0");
11114
11115 _vec_len (mask) = match * sizeof (u32x4);
11116
11117 *matchp = match;
11118 *maskp = mask;
11119
11120 return 1;
11121 }
11122
11123 return 0;
11124}
Dave Barach4a3f69c2017-02-22 12:44:56 -050011125#endif /* VPP_API_TEST_BUILTIN */
Damjan Marion7cd468a2016-12-19 23:05:39 +010011126
11127#define foreach_l2_next \
11128_(drop, DROP) \
11129_(ethernet, ETHERNET_INPUT) \
11130_(ip4, IP4_INPUT) \
11131_(ip6, IP6_INPUT)
11132
11133uword
11134unformat_l2_next_index (unformat_input_t * input, va_list * args)
11135{
11136 u32 *miss_next_indexp = va_arg (*args, u32 *);
11137 u32 next_index = 0;
11138 u32 tmp;
11139
11140#define _(n,N) \
11141 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
11142 foreach_l2_next;
11143#undef _
11144
11145 if (unformat (input, "%d", &tmp))
11146 {
11147 next_index = tmp;
11148 goto out;
11149 }
11150
11151 return 0;
11152
11153out:
11154 *miss_next_indexp = next_index;
11155 return 1;
11156}
11157
11158#define foreach_ip_next \
11159_(drop, DROP) \
11160_(local, LOCAL) \
11161_(rewrite, REWRITE)
11162
11163uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050011164api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011165{
11166 u32 *miss_next_indexp = va_arg (*args, u32 *);
11167 u32 next_index = 0;
11168 u32 tmp;
11169
11170#define _(n,N) \
11171 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
11172 foreach_ip_next;
11173#undef _
11174
11175 if (unformat (input, "%d", &tmp))
11176 {
11177 next_index = tmp;
11178 goto out;
11179 }
11180
11181 return 0;
11182
11183out:
11184 *miss_next_indexp = next_index;
11185 return 1;
11186}
11187
11188#define foreach_acl_next \
11189_(deny, DENY)
11190
11191uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050011192api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011193{
11194 u32 *miss_next_indexp = va_arg (*args, u32 *);
11195 u32 next_index = 0;
11196 u32 tmp;
11197
11198#define _(n,N) \
11199 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
11200 foreach_acl_next;
11201#undef _
11202
11203 if (unformat (input, "permit"))
11204 {
11205 next_index = ~0;
11206 goto out;
11207 }
11208 else if (unformat (input, "%d", &tmp))
11209 {
11210 next_index = tmp;
11211 goto out;
11212 }
11213
11214 return 0;
11215
11216out:
11217 *miss_next_indexp = next_index;
11218 return 1;
11219}
11220
11221uword
11222unformat_policer_precolor (unformat_input_t * input, va_list * args)
11223{
11224 u32 *r = va_arg (*args, u32 *);
11225
11226 if (unformat (input, "conform-color"))
11227 *r = POLICE_CONFORM;
11228 else if (unformat (input, "exceed-color"))
11229 *r = POLICE_EXCEED;
11230 else
11231 return 0;
11232
11233 return 1;
11234}
11235
11236static int
11237api_classify_add_del_table (vat_main_t * vam)
11238{
11239 unformat_input_t *i = vam->input;
11240 vl_api_classify_add_del_table_t *mp;
11241
11242 u32 nbuckets = 2;
11243 u32 skip = ~0;
11244 u32 match = ~0;
11245 int is_add = 1;
11246 int del_chain = 0;
11247 u32 table_index = ~0;
11248 u32 next_table_index = ~0;
11249 u32 miss_next_index = ~0;
11250 u32 memory_size = 32 << 20;
11251 u8 *mask = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011252 u32 current_data_flag = 0;
11253 int current_data_offset = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011254 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011255
11256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11257 {
11258 if (unformat (i, "del"))
11259 is_add = 0;
11260 else if (unformat (i, "del-chain"))
11261 {
11262 is_add = 0;
11263 del_chain = 1;
11264 }
11265 else if (unformat (i, "buckets %d", &nbuckets))
11266 ;
11267 else if (unformat (i, "memory_size %d", &memory_size))
11268 ;
11269 else if (unformat (i, "skip %d", &skip))
11270 ;
11271 else if (unformat (i, "match %d", &match))
11272 ;
11273 else if (unformat (i, "table %d", &table_index))
11274 ;
11275 else if (unformat (i, "mask %U", unformat_classify_mask,
11276 &mask, &skip, &match))
11277 ;
11278 else if (unformat (i, "next-table %d", &next_table_index))
11279 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011280 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011281 &miss_next_index))
11282 ;
11283 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
11284 &miss_next_index))
11285 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011286 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011287 &miss_next_index))
11288 ;
11289 else if (unformat (i, "current-data-flag %d", &current_data_flag))
11290 ;
11291 else if (unformat (i, "current-data-offset %d", &current_data_offset))
11292 ;
11293 else
11294 break;
11295 }
11296
11297 if (is_add && mask == 0)
11298 {
11299 errmsg ("Mask required");
11300 return -99;
11301 }
11302
11303 if (is_add && skip == ~0)
11304 {
11305 errmsg ("skip count required");
11306 return -99;
11307 }
11308
11309 if (is_add && match == ~0)
11310 {
11311 errmsg ("match count required");
11312 return -99;
11313 }
11314
11315 if (!is_add && table_index == ~0)
11316 {
11317 errmsg ("table index required for delete");
11318 return -99;
11319 }
11320
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011321 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011322
11323 mp->is_add = is_add;
11324 mp->del_chain = del_chain;
11325 mp->table_index = ntohl (table_index);
11326 mp->nbuckets = ntohl (nbuckets);
11327 mp->memory_size = ntohl (memory_size);
11328 mp->skip_n_vectors = ntohl (skip);
11329 mp->match_n_vectors = ntohl (match);
11330 mp->next_table_index = ntohl (next_table_index);
11331 mp->miss_next_index = ntohl (miss_next_index);
11332 mp->current_data_flag = ntohl (current_data_flag);
11333 mp->current_data_offset = ntohl (current_data_offset);
Juraj Sloboda75282452018-06-12 14:20:49 +020011334 mp->mask_len = ntohl (vec_len (mask));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011335 clib_memcpy (mp->mask, mask, vec_len (mask));
11336
11337 vec_free (mask);
11338
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011339 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011340 W (ret);
11341 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011342}
11343
Dave Barach4a3f69c2017-02-22 12:44:56 -050011344#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010011345uword
11346unformat_l4_match (unformat_input_t * input, va_list * args)
11347{
11348 u8 **matchp = va_arg (*args, u8 **);
11349
11350 u8 *proto_header = 0;
11351 int src_port = 0;
11352 int dst_port = 0;
11353
11354 tcpudp_header_t h;
11355
11356 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11357 {
11358 if (unformat (input, "src_port %d", &src_port))
11359 ;
11360 else if (unformat (input, "dst_port %d", &dst_port))
11361 ;
11362 else
11363 return 0;
11364 }
11365
11366 h.src_port = clib_host_to_net_u16 (src_port);
11367 h.dst_port = clib_host_to_net_u16 (dst_port);
11368 vec_validate (proto_header, sizeof (h) - 1);
11369 memcpy (proto_header, &h, sizeof (h));
11370
11371 *matchp = proto_header;
11372
11373 return 1;
11374}
11375
11376uword
11377unformat_ip4_match (unformat_input_t * input, va_list * args)
11378{
11379 u8 **matchp = va_arg (*args, u8 **);
11380 u8 *match = 0;
11381 ip4_header_t *ip;
11382 int version = 0;
11383 u32 version_val;
11384 int hdr_length = 0;
11385 u32 hdr_length_val;
11386 int src = 0, dst = 0;
11387 ip4_address_t src_val, dst_val;
11388 int proto = 0;
11389 u32 proto_val;
11390 int tos = 0;
11391 u32 tos_val;
11392 int length = 0;
11393 u32 length_val;
11394 int fragment_id = 0;
11395 u32 fragment_id_val;
11396 int ttl = 0;
11397 int ttl_val;
11398 int checksum = 0;
11399 u32 checksum_val;
11400
11401 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11402 {
11403 if (unformat (input, "version %d", &version_val))
11404 version = 1;
11405 else if (unformat (input, "hdr_length %d", &hdr_length_val))
11406 hdr_length = 1;
11407 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
11408 src = 1;
11409 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
11410 dst = 1;
11411 else if (unformat (input, "proto %d", &proto_val))
11412 proto = 1;
11413 else if (unformat (input, "tos %d", &tos_val))
11414 tos = 1;
11415 else if (unformat (input, "length %d", &length_val))
11416 length = 1;
11417 else if (unformat (input, "fragment_id %d", &fragment_id_val))
11418 fragment_id = 1;
11419 else if (unformat (input, "ttl %d", &ttl_val))
11420 ttl = 1;
11421 else if (unformat (input, "checksum %d", &checksum_val))
11422 checksum = 1;
11423 else
11424 break;
11425 }
11426
11427 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
11428 + ttl + checksum == 0)
11429 return 0;
11430
11431 /*
11432 * Aligned because we use the real comparison functions
11433 */
11434 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11435
11436 ip = (ip4_header_t *) match;
11437
11438 /* These are realistically matched in practice */
11439 if (src)
11440 ip->src_address.as_u32 = src_val.as_u32;
11441
11442 if (dst)
11443 ip->dst_address.as_u32 = dst_val.as_u32;
11444
11445 if (proto)
11446 ip->protocol = proto_val;
11447
11448
11449 /* These are not, but they're included for completeness */
11450 if (version)
11451 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
11452
11453 if (hdr_length)
11454 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
11455
11456 if (tos)
11457 ip->tos = tos_val;
11458
11459 if (length)
11460 ip->length = clib_host_to_net_u16 (length_val);
11461
11462 if (ttl)
11463 ip->ttl = ttl_val;
11464
11465 if (checksum)
11466 ip->checksum = clib_host_to_net_u16 (checksum_val);
11467
11468 *matchp = match;
11469 return 1;
11470}
11471
11472uword
11473unformat_ip6_match (unformat_input_t * input, va_list * args)
11474{
11475 u8 **matchp = va_arg (*args, u8 **);
11476 u8 *match = 0;
11477 ip6_header_t *ip;
11478 int version = 0;
11479 u32 version_val;
11480 u8 traffic_class = 0;
11481 u32 traffic_class_val = 0;
11482 u8 flow_label = 0;
11483 u8 flow_label_val;
11484 int src = 0, dst = 0;
11485 ip6_address_t src_val, dst_val;
11486 int proto = 0;
11487 u32 proto_val;
11488 int payload_length = 0;
11489 u32 payload_length_val;
11490 int hop_limit = 0;
11491 int hop_limit_val;
11492 u32 ip_version_traffic_class_and_flow_label;
11493
11494 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11495 {
11496 if (unformat (input, "version %d", &version_val))
11497 version = 1;
11498 else if (unformat (input, "traffic_class %d", &traffic_class_val))
11499 traffic_class = 1;
11500 else if (unformat (input, "flow_label %d", &flow_label_val))
11501 flow_label = 1;
11502 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
11503 src = 1;
11504 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
11505 dst = 1;
11506 else if (unformat (input, "proto %d", &proto_val))
11507 proto = 1;
11508 else if (unformat (input, "payload_length %d", &payload_length_val))
11509 payload_length = 1;
11510 else if (unformat (input, "hop_limit %d", &hop_limit_val))
11511 hop_limit = 1;
11512 else
11513 break;
11514 }
11515
11516 if (version + traffic_class + flow_label + src + dst + proto +
11517 payload_length + hop_limit == 0)
11518 return 0;
11519
11520 /*
11521 * Aligned because we use the real comparison functions
11522 */
11523 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
11524
11525 ip = (ip6_header_t *) match;
11526
11527 if (src)
11528 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
11529
11530 if (dst)
11531 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
11532
11533 if (proto)
11534 ip->protocol = proto_val;
11535
11536 ip_version_traffic_class_and_flow_label = 0;
11537
11538 if (version)
11539 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
11540
11541 if (traffic_class)
11542 ip_version_traffic_class_and_flow_label |=
11543 (traffic_class_val & 0xFF) << 20;
11544
11545 if (flow_label)
11546 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
11547
11548 ip->ip_version_traffic_class_and_flow_label =
11549 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
11550
11551 if (payload_length)
11552 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
11553
11554 if (hop_limit)
11555 ip->hop_limit = hop_limit_val;
11556
11557 *matchp = match;
11558 return 1;
11559}
11560
11561uword
11562unformat_l3_match (unformat_input_t * input, va_list * args)
11563{
11564 u8 **matchp = va_arg (*args, u8 **);
11565
11566 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11567 {
11568 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
11569 return 1;
11570 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
11571 return 1;
11572 else
11573 break;
11574 }
11575 return 0;
11576}
11577
11578uword
11579unformat_vlan_tag (unformat_input_t * input, va_list * args)
11580{
11581 u8 *tagp = va_arg (*args, u8 *);
11582 u32 tag;
11583
11584 if (unformat (input, "%d", &tag))
11585 {
11586 tagp[0] = (tag >> 8) & 0x0F;
11587 tagp[1] = tag & 0xFF;
11588 return 1;
11589 }
11590
11591 return 0;
11592}
11593
11594uword
11595unformat_l2_match (unformat_input_t * input, va_list * args)
11596{
11597 u8 **matchp = va_arg (*args, u8 **);
11598 u8 *match = 0;
11599 u8 src = 0;
11600 u8 src_val[6];
11601 u8 dst = 0;
11602 u8 dst_val[6];
11603 u8 proto = 0;
11604 u16 proto_val;
11605 u8 tag1 = 0;
11606 u8 tag1_val[2];
11607 u8 tag2 = 0;
11608 u8 tag2_val[2];
11609 int len = 14;
11610 u8 ignore_tag1 = 0;
11611 u8 ignore_tag2 = 0;
11612 u8 cos1 = 0;
11613 u8 cos2 = 0;
11614 u32 cos1_val = 0;
11615 u32 cos2_val = 0;
11616
11617 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11618 {
11619 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
11620 src = 1;
11621 else
11622 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
11623 dst = 1;
11624 else if (unformat (input, "proto %U",
11625 unformat_ethernet_type_host_byte_order, &proto_val))
11626 proto = 1;
11627 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
11628 tag1 = 1;
11629 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
11630 tag2 = 1;
11631 else if (unformat (input, "ignore-tag1"))
11632 ignore_tag1 = 1;
11633 else if (unformat (input, "ignore-tag2"))
11634 ignore_tag2 = 1;
11635 else if (unformat (input, "cos1 %d", &cos1_val))
11636 cos1 = 1;
11637 else if (unformat (input, "cos2 %d", &cos2_val))
11638 cos2 = 1;
11639 else
11640 break;
11641 }
11642 if ((src + dst + proto + tag1 + tag2 +
11643 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
11644 return 0;
11645
11646 if (tag1 || ignore_tag1 || cos1)
11647 len = 18;
11648 if (tag2 || ignore_tag2 || cos2)
11649 len = 22;
11650
11651 vec_validate_aligned (match, len - 1, sizeof (u32x4));
11652
11653 if (dst)
11654 clib_memcpy (match, dst_val, 6);
11655
11656 if (src)
11657 clib_memcpy (match + 6, src_val, 6);
11658
11659 if (tag2)
11660 {
11661 /* inner vlan tag */
11662 match[19] = tag2_val[1];
11663 match[18] = tag2_val[0];
11664 if (cos2)
11665 match[18] |= (cos2_val & 0x7) << 5;
11666 if (proto)
11667 {
11668 match[21] = proto_val & 0xff;
11669 match[20] = proto_val >> 8;
11670 }
11671 if (tag1)
11672 {
11673 match[15] = tag1_val[1];
11674 match[14] = tag1_val[0];
11675 }
11676 if (cos1)
11677 match[14] |= (cos1_val & 0x7) << 5;
11678 *matchp = match;
11679 return 1;
11680 }
11681 if (tag1)
11682 {
11683 match[15] = tag1_val[1];
11684 match[14] = tag1_val[0];
11685 if (proto)
11686 {
11687 match[17] = proto_val & 0xff;
11688 match[16] = proto_val >> 8;
11689 }
11690 if (cos1)
11691 match[14] |= (cos1_val & 0x7) << 5;
11692
11693 *matchp = match;
11694 return 1;
11695 }
11696 if (cos2)
11697 match[18] |= (cos2_val & 0x7) << 5;
11698 if (cos1)
11699 match[14] |= (cos1_val & 0x7) << 5;
11700 if (proto)
11701 {
11702 match[13] = proto_val & 0xff;
11703 match[12] = proto_val >> 8;
11704 }
11705
11706 *matchp = match;
11707 return 1;
11708}
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070011709
11710uword
11711unformat_qos_source (unformat_input_t * input, va_list * args)
11712{
11713 int *qs = va_arg (*args, int *);
11714
11715 if (unformat (input, "ip"))
11716 *qs = QOS_SOURCE_IP;
11717 else if (unformat (input, "mpls"))
11718 *qs = QOS_SOURCE_MPLS;
11719 else if (unformat (input, "ext"))
11720 *qs = QOS_SOURCE_EXT;
11721 else if (unformat (input, "vlan"))
11722 *qs = QOS_SOURCE_VLAN;
11723 else
11724 return 0;
11725
11726 return 1;
11727}
Dave Barach4a3f69c2017-02-22 12:44:56 -050011728#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010011729
11730uword
Dave Barach4a3f69c2017-02-22 12:44:56 -050011731api_unformat_classify_match (unformat_input_t * input, va_list * args)
Damjan Marion7cd468a2016-12-19 23:05:39 +010011732{
11733 u8 **matchp = va_arg (*args, u8 **);
11734 u32 skip_n_vectors = va_arg (*args, u32);
11735 u32 match_n_vectors = va_arg (*args, u32);
11736
11737 u8 *match = 0;
11738 u8 *l2 = 0;
11739 u8 *l3 = 0;
11740 u8 *l4 = 0;
11741
11742 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11743 {
11744 if (unformat (input, "hex %U", unformat_hex_string, &match))
11745 ;
11746 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
11747 ;
11748 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
11749 ;
11750 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
11751 ;
11752 else
11753 break;
11754 }
11755
11756 if (l4 && !l3)
11757 {
11758 vec_free (match);
11759 vec_free (l2);
11760 vec_free (l4);
11761 return 0;
11762 }
11763
11764 if (match || l2 || l3 || l4)
11765 {
11766 if (l2 || l3 || l4)
11767 {
11768 /* "Win a free Ethernet header in every packet" */
11769 if (l2 == 0)
11770 vec_validate_aligned (l2, 13, sizeof (u32x4));
11771 match = l2;
11772 if (vec_len (l3))
11773 {
11774 vec_append_aligned (match, l3, sizeof (u32x4));
11775 vec_free (l3);
11776 }
11777 if (vec_len (l4))
11778 {
11779 vec_append_aligned (match, l4, sizeof (u32x4));
11780 vec_free (l4);
11781 }
11782 }
11783
11784 /* Make sure the vector is big enough even if key is all 0's */
11785 vec_validate_aligned
11786 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
11787 sizeof (u32x4));
11788
11789 /* Set size, include skipped vectors */
11790 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
11791
11792 *matchp = match;
11793
11794 return 1;
11795 }
11796
11797 return 0;
11798}
11799
11800static int
11801api_classify_add_del_session (vat_main_t * vam)
11802{
11803 unformat_input_t *i = vam->input;
11804 vl_api_classify_add_del_session_t *mp;
11805 int is_add = 1;
11806 u32 table_index = ~0;
11807 u32 hit_next_index = ~0;
11808 u32 opaque_index = ~0;
11809 u8 *match = 0;
11810 i32 advance = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011811 u32 skip_n_vectors = 0;
11812 u32 match_n_vectors = 0;
11813 u32 action = 0;
11814 u32 metadata = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011815 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011816
11817 /*
11818 * Warning: you have to supply skip_n and match_n
11819 * because the API client cant simply look at the classify
11820 * table object.
11821 */
11822
11823 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11824 {
11825 if (unformat (i, "del"))
11826 is_add = 0;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011827 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011828 &hit_next_index))
11829 ;
11830 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
11831 &hit_next_index))
11832 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011833 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011834 &hit_next_index))
11835 ;
11836 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
11837 ;
11838 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
11839 ;
11840 else if (unformat (i, "opaque-index %d", &opaque_index))
11841 ;
11842 else if (unformat (i, "skip_n %d", &skip_n_vectors))
11843 ;
11844 else if (unformat (i, "match_n %d", &match_n_vectors))
11845 ;
Dave Barach4a3f69c2017-02-22 12:44:56 -050011846 else if (unformat (i, "match %U", api_unformat_classify_match,
Damjan Marion7cd468a2016-12-19 23:05:39 +010011847 &match, skip_n_vectors, match_n_vectors))
11848 ;
11849 else if (unformat (i, "advance %d", &advance))
11850 ;
11851 else if (unformat (i, "table-index %d", &table_index))
11852 ;
11853 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
11854 action = 1;
11855 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
11856 action = 2;
11857 else if (unformat (i, "action %d", &action))
11858 ;
11859 else if (unformat (i, "metadata %d", &metadata))
11860 ;
11861 else
11862 break;
11863 }
11864
11865 if (table_index == ~0)
11866 {
11867 errmsg ("Table index required");
11868 return -99;
11869 }
11870
11871 if (is_add && match == 0)
11872 {
11873 errmsg ("Match value required");
11874 return -99;
11875 }
11876
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011877 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011878
11879 mp->is_add = is_add;
11880 mp->table_index = ntohl (table_index);
11881 mp->hit_next_index = ntohl (hit_next_index);
11882 mp->opaque_index = ntohl (opaque_index);
11883 mp->advance = ntohl (advance);
11884 mp->action = action;
11885 mp->metadata = ntohl (metadata);
Juraj Sloboda75282452018-06-12 14:20:49 +020011886 mp->match_len = ntohl (vec_len (match));
Damjan Marion7cd468a2016-12-19 23:05:39 +010011887 clib_memcpy (mp->match, match, vec_len (match));
11888 vec_free (match);
11889
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011890 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011891 W (ret);
11892 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011893}
11894
11895static int
11896api_classify_set_interface_ip_table (vat_main_t * vam)
11897{
11898 unformat_input_t *i = vam->input;
11899 vl_api_classify_set_interface_ip_table_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011900 u32 sw_if_index;
11901 int sw_if_index_set;
11902 u32 table_index = ~0;
11903 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011904 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011905
11906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11907 {
11908 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11909 sw_if_index_set = 1;
11910 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11911 sw_if_index_set = 1;
11912 else if (unformat (i, "table %d", &table_index))
11913 ;
11914 else
11915 {
11916 clib_warning ("parse error '%U'", format_unformat_error, i);
11917 return -99;
11918 }
11919 }
11920
11921 if (sw_if_index_set == 0)
11922 {
11923 errmsg ("missing interface name or sw_if_index");
11924 return -99;
11925 }
11926
11927
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011928 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011929
11930 mp->sw_if_index = ntohl (sw_if_index);
11931 mp->table_index = ntohl (table_index);
11932 mp->is_ipv6 = is_ipv6;
11933
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011934 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011935 W (ret);
11936 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011937}
11938
11939static int
11940api_classify_set_interface_l2_tables (vat_main_t * vam)
11941{
11942 unformat_input_t *i = vam->input;
11943 vl_api_classify_set_interface_l2_tables_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011944 u32 sw_if_index;
11945 int sw_if_index_set;
11946 u32 ip4_table_index = ~0;
11947 u32 ip6_table_index = ~0;
11948 u32 other_table_index = ~0;
11949 u32 is_input = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060011950 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011951
11952 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11953 {
11954 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11955 sw_if_index_set = 1;
11956 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11957 sw_if_index_set = 1;
11958 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11959 ;
11960 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11961 ;
11962 else if (unformat (i, "other-table %d", &other_table_index))
11963 ;
11964 else if (unformat (i, "is-input %d", &is_input))
11965 ;
11966 else
11967 {
11968 clib_warning ("parse error '%U'", format_unformat_error, i);
11969 return -99;
11970 }
11971 }
11972
11973 if (sw_if_index_set == 0)
11974 {
11975 errmsg ("missing interface name or sw_if_index");
11976 return -99;
11977 }
11978
11979
Jon Loeliger8a2aea32017-01-31 13:19:40 -060011980 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010011981
11982 mp->sw_if_index = ntohl (sw_if_index);
11983 mp->ip4_table_index = ntohl (ip4_table_index);
11984 mp->ip6_table_index = ntohl (ip6_table_index);
11985 mp->other_table_index = ntohl (other_table_index);
11986 mp->is_input = (u8) is_input;
11987
Jon Loeliger7bc770c2017-01-31 14:03:33 -060011988 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060011989 W (ret);
11990 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010011991}
11992
11993static int
11994api_set_ipfix_exporter (vat_main_t * vam)
11995{
11996 unformat_input_t *i = vam->input;
11997 vl_api_set_ipfix_exporter_t *mp;
11998 ip4_address_t collector_address;
11999 u8 collector_address_set = 0;
12000 u32 collector_port = ~0;
12001 ip4_address_t src_address;
12002 u8 src_address_set = 0;
12003 u32 vrf_id = ~0;
12004 u32 path_mtu = ~0;
12005 u32 template_interval = ~0;
12006 u8 udp_checksum = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012007 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012008
12009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12010 {
12011 if (unformat (i, "collector_address %U", unformat_ip4_address,
12012 &collector_address))
12013 collector_address_set = 1;
12014 else if (unformat (i, "collector_port %d", &collector_port))
12015 ;
12016 else if (unformat (i, "src_address %U", unformat_ip4_address,
12017 &src_address))
12018 src_address_set = 1;
12019 else if (unformat (i, "vrf_id %d", &vrf_id))
12020 ;
12021 else if (unformat (i, "path_mtu %d", &path_mtu))
12022 ;
12023 else if (unformat (i, "template_interval %d", &template_interval))
12024 ;
12025 else if (unformat (i, "udp_checksum"))
12026 udp_checksum = 1;
12027 else
12028 break;
12029 }
12030
12031 if (collector_address_set == 0)
12032 {
12033 errmsg ("collector_address required");
12034 return -99;
12035 }
12036
12037 if (src_address_set == 0)
12038 {
12039 errmsg ("src_address required");
12040 return -99;
12041 }
12042
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012043 M (SET_IPFIX_EXPORTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012044
12045 memcpy (mp->collector_address, collector_address.data,
12046 sizeof (collector_address.data));
12047 mp->collector_port = htons ((u16) collector_port);
12048 memcpy (mp->src_address, src_address.data, sizeof (src_address.data));
12049 mp->vrf_id = htonl (vrf_id);
12050 mp->path_mtu = htonl (path_mtu);
12051 mp->template_interval = htonl (template_interval);
12052 mp->udp_checksum = udp_checksum;
12053
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012054 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012055 W (ret);
12056 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012057}
12058
12059static int
12060api_set_ipfix_classify_stream (vat_main_t * vam)
12061{
12062 unformat_input_t *i = vam->input;
12063 vl_api_set_ipfix_classify_stream_t *mp;
12064 u32 domain_id = 0;
12065 u32 src_port = UDP_DST_PORT_ipfix;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012066 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012067
12068 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12069 {
12070 if (unformat (i, "domain %d", &domain_id))
12071 ;
12072 else if (unformat (i, "src_port %d", &src_port))
12073 ;
12074 else
12075 {
12076 errmsg ("unknown input `%U'", format_unformat_error, i);
12077 return -99;
12078 }
12079 }
12080
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012081 M (SET_IPFIX_CLASSIFY_STREAM, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012082
12083 mp->domain_id = htonl (domain_id);
12084 mp->src_port = htons ((u16) src_port);
12085
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012086 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012087 W (ret);
12088 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012089}
12090
12091static int
12092api_ipfix_classify_table_add_del (vat_main_t * vam)
12093{
12094 unformat_input_t *i = vam->input;
12095 vl_api_ipfix_classify_table_add_del_t *mp;
12096 int is_add = -1;
12097 u32 classify_table_index = ~0;
12098 u8 ip_version = 0;
12099 u8 transport_protocol = 255;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012100 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012101
12102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12103 {
12104 if (unformat (i, "add"))
12105 is_add = 1;
12106 else if (unformat (i, "del"))
12107 is_add = 0;
12108 else if (unformat (i, "table %d", &classify_table_index))
12109 ;
12110 else if (unformat (i, "ip4"))
12111 ip_version = 4;
12112 else if (unformat (i, "ip6"))
12113 ip_version = 6;
12114 else if (unformat (i, "tcp"))
12115 transport_protocol = 6;
12116 else if (unformat (i, "udp"))
12117 transport_protocol = 17;
12118 else
12119 {
12120 errmsg ("unknown input `%U'", format_unformat_error, i);
12121 return -99;
12122 }
12123 }
12124
12125 if (is_add == -1)
12126 {
12127 errmsg ("expecting: add|del");
12128 return -99;
12129 }
12130 if (classify_table_index == ~0)
12131 {
12132 errmsg ("classifier table not specified");
12133 return -99;
12134 }
12135 if (ip_version == 0)
12136 {
12137 errmsg ("IP version not specified");
12138 return -99;
12139 }
12140
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012141 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012142
12143 mp->is_add = is_add;
12144 mp->table_id = htonl (classify_table_index);
12145 mp->ip_version = ip_version;
12146 mp->transport_protocol = transport_protocol;
12147
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012148 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012149 W (ret);
12150 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012151}
12152
12153static int
12154api_get_node_index (vat_main_t * vam)
12155{
12156 unformat_input_t *i = vam->input;
12157 vl_api_get_node_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012158 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012159 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012160
12161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12162 {
12163 if (unformat (i, "node %s", &name))
12164 ;
12165 else
12166 break;
12167 }
12168 if (name == 0)
12169 {
12170 errmsg ("node name required");
12171 return -99;
12172 }
12173 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
12174 {
12175 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
12176 return -99;
12177 }
12178
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012179 M (GET_NODE_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012180 clib_memcpy (mp->node_name, name, vec_len (name));
12181 vec_free (name);
12182
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012183 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012184 W (ret);
12185 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012186}
12187
12188static int
12189api_get_next_index (vat_main_t * vam)
12190{
12191 unformat_input_t *i = vam->input;
12192 vl_api_get_next_index_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012193 u8 *node_name = 0, *next_node_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012194 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012195
12196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12197 {
12198 if (unformat (i, "node-name %s", &node_name))
12199 ;
12200 else if (unformat (i, "next-node-name %s", &next_node_name))
12201 break;
12202 }
12203
12204 if (node_name == 0)
12205 {
12206 errmsg ("node name required");
12207 return -99;
12208 }
12209 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
12210 {
12211 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
12212 return -99;
12213 }
12214
12215 if (next_node_name == 0)
12216 {
12217 errmsg ("next node name required");
12218 return -99;
12219 }
12220 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
12221 {
12222 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
12223 return -99;
12224 }
12225
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012226 M (GET_NEXT_INDEX, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012227 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
12228 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
12229 vec_free (node_name);
12230 vec_free (next_node_name);
12231
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012232 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012233 W (ret);
12234 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012235}
12236
12237static int
12238api_add_node_next (vat_main_t * vam)
12239{
12240 unformat_input_t *i = vam->input;
12241 vl_api_add_node_next_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012242 u8 *name = 0;
12243 u8 *next = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012244 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012245
12246 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12247 {
12248 if (unformat (i, "node %s", &name))
12249 ;
12250 else if (unformat (i, "next %s", &next))
12251 ;
12252 else
12253 break;
12254 }
12255 if (name == 0)
12256 {
12257 errmsg ("node name required");
12258 return -99;
12259 }
12260 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
12261 {
12262 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
12263 return -99;
12264 }
12265 if (next == 0)
12266 {
12267 errmsg ("next node required");
12268 return -99;
12269 }
12270 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
12271 {
12272 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
12273 return -99;
12274 }
12275
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012276 M (ADD_NODE_NEXT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012277 clib_memcpy (mp->node_name, name, vec_len (name));
12278 clib_memcpy (mp->next_name, next, vec_len (next));
12279 vec_free (name);
12280 vec_free (next);
12281
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012282 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012283 W (ret);
12284 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012285}
12286
12287static int
12288api_l2tpv3_create_tunnel (vat_main_t * vam)
12289{
12290 unformat_input_t *i = vam->input;
12291 ip6_address_t client_address, our_address;
12292 int client_address_set = 0;
12293 int our_address_set = 0;
12294 u32 local_session_id = 0;
12295 u32 remote_session_id = 0;
12296 u64 local_cookie = 0;
12297 u64 remote_cookie = 0;
12298 u8 l2_sublayer_present = 0;
12299 vl_api_l2tpv3_create_tunnel_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012300 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012301
12302 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12303 {
12304 if (unformat (i, "client_address %U", unformat_ip6_address,
12305 &client_address))
12306 client_address_set = 1;
12307 else if (unformat (i, "our_address %U", unformat_ip6_address,
12308 &our_address))
12309 our_address_set = 1;
12310 else if (unformat (i, "local_session_id %d", &local_session_id))
12311 ;
12312 else if (unformat (i, "remote_session_id %d", &remote_session_id))
12313 ;
12314 else if (unformat (i, "local_cookie %lld", &local_cookie))
12315 ;
12316 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
12317 ;
12318 else if (unformat (i, "l2-sublayer-present"))
12319 l2_sublayer_present = 1;
12320 else
12321 break;
12322 }
12323
12324 if (client_address_set == 0)
12325 {
12326 errmsg ("client_address required");
12327 return -99;
12328 }
12329
12330 if (our_address_set == 0)
12331 {
12332 errmsg ("our_address required");
12333 return -99;
12334 }
12335
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012336 M (L2TPV3_CREATE_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012337
12338 clib_memcpy (mp->client_address, client_address.as_u8,
12339 sizeof (mp->client_address));
12340
12341 clib_memcpy (mp->our_address, our_address.as_u8, sizeof (mp->our_address));
12342
12343 mp->local_session_id = ntohl (local_session_id);
12344 mp->remote_session_id = ntohl (remote_session_id);
12345 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
12346 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
12347 mp->l2_sublayer_present = l2_sublayer_present;
12348 mp->is_ipv6 = 1;
12349
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012350 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012351 W (ret);
12352 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012353}
12354
12355static int
12356api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
12357{
12358 unformat_input_t *i = vam->input;
12359 u32 sw_if_index;
12360 u8 sw_if_index_set = 0;
12361 u64 new_local_cookie = 0;
12362 u64 new_remote_cookie = 0;
12363 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012364 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012365
12366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12367 {
12368 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12369 sw_if_index_set = 1;
12370 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12371 sw_if_index_set = 1;
12372 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
12373 ;
12374 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
12375 ;
12376 else
12377 break;
12378 }
12379
12380 if (sw_if_index_set == 0)
12381 {
12382 errmsg ("missing interface name or sw_if_index");
12383 return -99;
12384 }
12385
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012386 M (L2TPV3_SET_TUNNEL_COOKIES, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012387
12388 mp->sw_if_index = ntohl (sw_if_index);
12389 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
12390 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
12391
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012392 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012393 W (ret);
12394 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012395}
12396
12397static int
12398api_l2tpv3_interface_enable_disable (vat_main_t * vam)
12399{
12400 unformat_input_t *i = vam->input;
12401 vl_api_l2tpv3_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012402 u32 sw_if_index;
12403 u8 sw_if_index_set = 0;
12404 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012405 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012406
12407 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12408 {
12409 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12410 sw_if_index_set = 1;
12411 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12412 sw_if_index_set = 1;
12413 else if (unformat (i, "enable"))
12414 enable_disable = 1;
12415 else if (unformat (i, "disable"))
12416 enable_disable = 0;
12417 else
12418 break;
12419 }
12420
12421 if (sw_if_index_set == 0)
12422 {
12423 errmsg ("missing interface name or sw_if_index");
12424 return -99;
12425 }
12426
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012427 M (L2TPV3_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012428
12429 mp->sw_if_index = ntohl (sw_if_index);
12430 mp->enable_disable = enable_disable;
12431
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012432 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012433 W (ret);
12434 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012435}
12436
12437static int
12438api_l2tpv3_set_lookup_key (vat_main_t * vam)
12439{
12440 unformat_input_t *i = vam->input;
12441 vl_api_l2tpv3_set_lookup_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012442 u8 key = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012443 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012444
12445 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12446 {
12447 if (unformat (i, "lookup_v6_src"))
12448 key = L2T_LOOKUP_SRC_ADDRESS;
12449 else if (unformat (i, "lookup_v6_dst"))
12450 key = L2T_LOOKUP_DST_ADDRESS;
12451 else if (unformat (i, "lookup_session_id"))
12452 key = L2T_LOOKUP_SESSION_ID;
12453 else
12454 break;
12455 }
12456
12457 if (key == (u8) ~ 0)
12458 {
12459 errmsg ("l2tp session lookup key unset");
12460 return -99;
12461 }
12462
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012463 M (L2TPV3_SET_LOOKUP_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012464
12465 mp->key = key;
12466
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012467 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012468 W (ret);
12469 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012470}
12471
12472static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
12473 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12474{
12475 vat_main_t *vam = &vat_main;
12476
12477 print (vam->ofp, "* %U (our) %U (client) (sw_if_index %d)",
12478 format_ip6_address, mp->our_address,
12479 format_ip6_address, mp->client_address,
12480 clib_net_to_host_u32 (mp->sw_if_index));
12481
12482 print (vam->ofp,
12483 " local cookies %016llx %016llx remote cookie %016llx",
12484 clib_net_to_host_u64 (mp->local_cookie[0]),
12485 clib_net_to_host_u64 (mp->local_cookie[1]),
12486 clib_net_to_host_u64 (mp->remote_cookie));
12487
12488 print (vam->ofp, " local session-id %d remote session-id %d",
12489 clib_net_to_host_u32 (mp->local_session_id),
12490 clib_net_to_host_u32 (mp->remote_session_id));
12491
12492 print (vam->ofp, " l2 specific sublayer %s\n",
12493 mp->l2_sublayer_present ? "preset" : "absent");
12494
12495}
12496
12497static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
12498 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
12499{
12500 vat_main_t *vam = &vat_main;
12501 vat_json_node_t *node = NULL;
12502 struct in6_addr addr;
12503
12504 if (VAT_JSON_ARRAY != vam->json_tree.type)
12505 {
12506 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12507 vat_json_init_array (&vam->json_tree);
12508 }
12509 node = vat_json_array_add (&vam->json_tree);
12510
12511 vat_json_init_object (node);
12512
12513 clib_memcpy (&addr, mp->our_address, sizeof (addr));
12514 vat_json_object_add_ip6 (node, "our_address", addr);
12515 clib_memcpy (&addr, mp->client_address, sizeof (addr));
12516 vat_json_object_add_ip6 (node, "client_address", addr);
12517
12518 vat_json_node_t *lc = vat_json_object_add (node, "local_cookie");
12519 vat_json_init_array (lc);
12520 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[0]));
12521 vat_json_array_add_uint (lc, clib_net_to_host_u64 (mp->local_cookie[1]));
12522 vat_json_object_add_uint (node, "remote_cookie",
12523 clib_net_to_host_u64 (mp->remote_cookie));
12524
12525 printf ("local id: %u", clib_net_to_host_u32 (mp->local_session_id));
12526 vat_json_object_add_uint (node, "local_session_id",
12527 clib_net_to_host_u32 (mp->local_session_id));
12528 vat_json_object_add_uint (node, "remote_session_id",
12529 clib_net_to_host_u32 (mp->remote_session_id));
12530 vat_json_object_add_string_copy (node, "l2_sublayer",
12531 mp->l2_sublayer_present ? (u8 *) "present"
12532 : (u8 *) "absent");
12533}
12534
12535static int
12536api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
12537{
12538 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012539 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012540 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012541
12542 /* Get list of l2tpv3-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012543 M (SW_IF_L2TPV3_TUNNEL_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012544 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012545
12546 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040012547 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060012548 S (mp_ping);
12549
Jon Loeliger56c7b012017-02-01 12:31:41 -060012550 W (ret);
12551 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012552}
12553
12554
Damjan Marion8389fb92017-10-13 18:29:53 +020012555static void vl_api_sw_interface_tap_v2_details_t_handler
12556 (vl_api_sw_interface_tap_v2_details_t * mp)
12557{
12558 vat_main_t *vam = &vat_main;
12559
Milan Lenco73e7f422017-12-14 10:04:25 +010012560 u8 *ip4 = format (0, "%U/%d", format_ip4_address, mp->host_ip4_addr,
12561 mp->host_ip4_prefix_len);
12562 u8 *ip6 = format (0, "%U/%d", format_ip6_address, mp->host_ip6_addr,
12563 mp->host_ip6_prefix_len);
12564
12565 print (vam->ofp,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012566 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
Milan Lenco73e7f422017-12-14 10:04:25 +010012567 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
12568 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12569 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012570 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
Milan Lenco73e7f422017-12-14 10:04:25 +010012571
12572 vec_free (ip4);
12573 vec_free (ip6);
Damjan Marion8389fb92017-10-13 18:29:53 +020012574}
12575
12576static void vl_api_sw_interface_tap_v2_details_t_handler_json
12577 (vl_api_sw_interface_tap_v2_details_t * mp)
12578{
12579 vat_main_t *vam = &vat_main;
12580 vat_json_node_t *node = NULL;
12581
12582 if (VAT_JSON_ARRAY != vam->json_tree.type)
12583 {
12584 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12585 vat_json_init_array (&vam->json_tree);
12586 }
12587 node = vat_json_array_add (&vam->json_tree);
12588
12589 vat_json_init_object (node);
Milan Lenco73e7f422017-12-14 10:04:25 +010012590 vat_json_object_add_uint (node, "id", ntohl (mp->id));
Damjan Marion8389fb92017-10-13 18:29:53 +020012591 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Andrew Yourtchenko754f24b2019-01-07 20:56:46 +010012592 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
Damjan Marion8389fb92017-10-13 18:29:53 +020012593 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
Milan Lenco73e7f422017-12-14 10:04:25 +010012594 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12595 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12596 vat_json_object_add_string_copy (node, "host_mac_addr",
12597 format (0, "%U", format_ethernet_address,
12598 &mp->host_mac_addr));
12599 vat_json_object_add_string_copy (node, "host_namespace",
12600 mp->host_namespace);
12601 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
12602 vat_json_object_add_string_copy (node, "host_ip4_addr",
12603 format (0, "%U/%d", format_ip4_address,
12604 mp->host_ip4_addr,
12605 mp->host_ip4_prefix_len));
12606 vat_json_object_add_string_copy (node, "host_ip6_addr",
12607 format (0, "%U/%d", format_ip6_address,
12608 mp->host_ip6_addr,
12609 mp->host_ip6_prefix_len));
12610
Damjan Marion8389fb92017-10-13 18:29:53 +020012611}
12612
12613static int
12614api_sw_interface_tap_v2_dump (vat_main_t * vam)
12615{
12616 vl_api_sw_interface_tap_v2_dump_t *mp;
12617 vl_api_control_ping_t *mp_ping;
12618 int ret;
12619
Milan Lenco73e7f422017-12-14 10:04:25 +010012620 print (vam->ofp,
12621 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
12622 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
12623 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
12624 "host_ip6_addr");
12625
Damjan Marion8389fb92017-10-13 18:29:53 +020012626 /* Get list of tap interfaces */
12627 M (SW_INTERFACE_TAP_V2_DUMP, mp);
12628 S (mp);
12629
12630 /* Use a control ping for synchronization */
12631 MPING (CONTROL_PING, mp_ping);
12632 S (mp_ping);
12633
12634 W (ret);
12635 return ret;
12636}
12637
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010012638static void vl_api_sw_interface_virtio_pci_details_t_handler
12639 (vl_api_sw_interface_virtio_pci_details_t * mp)
12640{
12641 vat_main_t *vam = &vat_main;
12642
12643 typedef union
12644 {
12645 struct
12646 {
12647 u16 domain;
12648 u8 bus;
12649 u8 slot:5;
12650 u8 function:3;
12651 };
12652 u32 as_u32;
12653 } pci_addr_t;
12654 pci_addr_t addr;
12655 addr.as_u32 = ntohl (mp->pci_addr);
12656 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
12657 addr.slot, addr.function);
12658
12659 print (vam->ofp,
12660 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
12661 pci_addr, ntohl (mp->sw_if_index),
12662 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
12663 format_ethernet_address, mp->mac_addr,
12664 clib_net_to_host_u64 (mp->features));
12665 vec_free (pci_addr);
12666}
12667
12668static void vl_api_sw_interface_virtio_pci_details_t_handler_json
12669 (vl_api_sw_interface_virtio_pci_details_t * mp)
12670{
12671 vat_main_t *vam = &vat_main;
12672 vat_json_node_t *node = NULL;
12673
12674 if (VAT_JSON_ARRAY != vam->json_tree.type)
12675 {
12676 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12677 vat_json_init_array (&vam->json_tree);
12678 }
12679 node = vat_json_array_add (&vam->json_tree);
12680
12681 vat_json_init_object (node);
12682 vat_json_object_add_uint (node, "pci-addr", ntohl (mp->pci_addr));
12683 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
12684 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
12685 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
12686 vat_json_object_add_uint (node, "features",
12687 clib_net_to_host_u64 (mp->features));
12688 vat_json_object_add_string_copy (node, "mac_addr",
12689 format (0, "%U", format_ethernet_address,
12690 &mp->mac_addr));
12691}
12692
12693static int
12694api_sw_interface_virtio_pci_dump (vat_main_t * vam)
12695{
12696 vl_api_sw_interface_virtio_pci_dump_t *mp;
12697 vl_api_control_ping_t *mp_ping;
12698 int ret;
12699
12700 print (vam->ofp,
12701 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
12702 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
12703 "mac_addr", "features");
12704
12705 /* Get list of tap interfaces */
12706 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
12707 S (mp);
12708
12709 /* Use a control ping for synchronization */
12710 MPING (CONTROL_PING, mp_ping);
12711 S (mp_ping);
12712
12713 W (ret);
12714 return ret;
12715}
12716
eyal bariaf86a482018-04-17 11:20:27 +030012717static int
12718api_vxlan_offload_rx (vat_main_t * vam)
12719{
12720 unformat_input_t *line_input = vam->input;
12721 vl_api_vxlan_offload_rx_t *mp;
12722 u32 hw_if_index = ~0, rx_if_index = ~0;
12723 u8 is_add = 1;
12724 int ret;
12725
12726 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12727 {
12728 if (unformat (line_input, "del"))
12729 is_add = 0;
12730 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
12731 &hw_if_index))
12732 ;
12733 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
12734 ;
12735 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
12736 &rx_if_index))
12737 ;
12738 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
12739 ;
12740 else
12741 {
12742 errmsg ("parse error '%U'", format_unformat_error, line_input);
12743 return -99;
12744 }
12745 }
12746
12747 if (hw_if_index == ~0)
12748 {
12749 errmsg ("no hw interface");
12750 return -99;
12751 }
12752
12753 if (rx_if_index == ~0)
12754 {
12755 errmsg ("no rx tunnel");
12756 return -99;
12757 }
12758
12759 M (VXLAN_OFFLOAD_RX, mp);
12760
12761 mp->hw_if_index = ntohl (hw_if_index);
12762 mp->sw_if_index = ntohl (rx_if_index);
12763 mp->enable = is_add;
12764
12765 S (mp);
12766 W (ret);
12767 return ret;
12768}
12769
Damjan Marion7cd468a2016-12-19 23:05:39 +010012770static uword unformat_vxlan_decap_next
12771 (unformat_input_t * input, va_list * args)
12772{
12773 u32 *result = va_arg (*args, u32 *);
12774 u32 tmp;
12775
12776 if (unformat (input, "l2"))
12777 *result = VXLAN_INPUT_NEXT_L2_INPUT;
12778 else if (unformat (input, "%d", &tmp))
12779 *result = tmp;
12780 else
12781 return 0;
12782 return 1;
12783}
12784
12785static int
12786api_vxlan_add_del_tunnel (vat_main_t * vam)
12787{
12788 unformat_input_t *line_input = vam->input;
12789 vl_api_vxlan_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012790 ip46_address_t src, dst;
12791 u8 is_add = 1;
12792 u8 ipv4_set = 0, ipv6_set = 0;
12793 u8 src_set = 0;
12794 u8 dst_set = 0;
12795 u8 grp_set = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012796 u32 instance = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012797 u32 mcast_sw_if_index = ~0;
12798 u32 encap_vrf_id = 0;
12799 u32 decap_next_index = ~0;
12800 u32 vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060012801 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012802
12803 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040012804 clib_memset (&src, 0, sizeof src);
12805 clib_memset (&dst, 0, sizeof dst);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012806
12807 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12808 {
12809 if (unformat (line_input, "del"))
12810 is_add = 0;
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012811 else if (unformat (line_input, "instance %d", &instance))
12812 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012813 else
12814 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
12815 {
12816 ipv4_set = 1;
12817 src_set = 1;
12818 }
12819 else
12820 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
12821 {
12822 ipv4_set = 1;
12823 dst_set = 1;
12824 }
12825 else
12826 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
12827 {
12828 ipv6_set = 1;
12829 src_set = 1;
12830 }
12831 else
12832 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
12833 {
12834 ipv6_set = 1;
12835 dst_set = 1;
12836 }
12837 else if (unformat (line_input, "group %U %U",
12838 unformat_ip4_address, &dst.ip4,
12839 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12840 {
12841 grp_set = dst_set = 1;
12842 ipv4_set = 1;
12843 }
12844 else if (unformat (line_input, "group %U",
12845 unformat_ip4_address, &dst.ip4))
12846 {
12847 grp_set = dst_set = 1;
12848 ipv4_set = 1;
12849 }
12850 else if (unformat (line_input, "group %U %U",
12851 unformat_ip6_address, &dst.ip6,
12852 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
12853 {
12854 grp_set = dst_set = 1;
12855 ipv6_set = 1;
12856 }
12857 else if (unformat (line_input, "group %U",
12858 unformat_ip6_address, &dst.ip6))
12859 {
12860 grp_set = dst_set = 1;
12861 ipv6_set = 1;
12862 }
12863 else
12864 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
12865 ;
12866 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
12867 ;
12868 else if (unformat (line_input, "decap-next %U",
12869 unformat_vxlan_decap_next, &decap_next_index))
12870 ;
12871 else if (unformat (line_input, "vni %d", &vni))
12872 ;
12873 else
12874 {
12875 errmsg ("parse error '%U'", format_unformat_error, line_input);
12876 return -99;
12877 }
12878 }
12879
12880 if (src_set == 0)
12881 {
12882 errmsg ("tunnel src address not specified");
12883 return -99;
12884 }
12885 if (dst_set == 0)
12886 {
12887 errmsg ("tunnel dst address not specified");
12888 return -99;
12889 }
12890
12891 if (grp_set && !ip46_address_is_multicast (&dst))
12892 {
12893 errmsg ("tunnel group address not multicast");
12894 return -99;
12895 }
12896 if (grp_set && mcast_sw_if_index == ~0)
12897 {
12898 errmsg ("tunnel nonexistent multicast device");
12899 return -99;
12900 }
12901 if (grp_set == 0 && ip46_address_is_multicast (&dst))
12902 {
12903 errmsg ("tunnel dst address must be unicast");
12904 return -99;
12905 }
12906
12907
12908 if (ipv4_set && ipv6_set)
12909 {
12910 errmsg ("both IPv4 and IPv6 addresses specified");
12911 return -99;
12912 }
12913
12914 if ((vni == 0) || (vni >> 24))
12915 {
12916 errmsg ("vni not specified or out of range");
12917 return -99;
12918 }
12919
Jon Loeliger8a2aea32017-01-31 13:19:40 -060012920 M (VXLAN_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012921
12922 if (ipv6_set)
12923 {
12924 clib_memcpy (mp->src_address, &src.ip6, sizeof (src.ip6));
12925 clib_memcpy (mp->dst_address, &dst.ip6, sizeof (dst.ip6));
12926 }
12927 else
12928 {
12929 clib_memcpy (mp->src_address, &src.ip4, sizeof (src.ip4));
12930 clib_memcpy (mp->dst_address, &dst.ip4, sizeof (dst.ip4));
12931 }
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012932
12933 mp->instance = htonl (instance);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012934 mp->encap_vrf_id = ntohl (encap_vrf_id);
12935 mp->decap_next_index = ntohl (decap_next_index);
12936 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
12937 mp->vni = ntohl (vni);
12938 mp->is_add = is_add;
12939 mp->is_ipv6 = ipv6_set;
12940
Jon Loeliger7bc770c2017-01-31 14:03:33 -060012941 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060012942 W (ret);
12943 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010012944}
12945
12946static void vl_api_vxlan_tunnel_details_t_handler
12947 (vl_api_vxlan_tunnel_details_t * mp)
12948{
12949 vat_main_t *vam = &vat_main;
Eyal Barie101e1f2017-03-15 08:23:42 +020012950 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
12951 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010012952
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012953 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010012954 ntohl (mp->sw_if_index),
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012955 ntohl (mp->instance),
Damjan Marion7cd468a2016-12-19 23:05:39 +010012956 format_ip46_address, &src, IP46_TYPE_ANY,
12957 format_ip46_address, &dst, IP46_TYPE_ANY,
12958 ntohl (mp->encap_vrf_id),
12959 ntohl (mp->decap_next_index), ntohl (mp->vni),
12960 ntohl (mp->mcast_sw_if_index));
12961}
12962
12963static void vl_api_vxlan_tunnel_details_t_handler_json
12964 (vl_api_vxlan_tunnel_details_t * mp)
12965{
12966 vat_main_t *vam = &vat_main;
12967 vat_json_node_t *node = NULL;
12968
12969 if (VAT_JSON_ARRAY != vam->json_tree.type)
12970 {
12971 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12972 vat_json_init_array (&vam->json_tree);
12973 }
12974 node = vat_json_array_add (&vam->json_tree);
12975
12976 vat_json_init_object (node);
12977 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Jon Loeliger3d460bd2018-02-01 16:36:12 -060012978
12979 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
12980
Damjan Marion7cd468a2016-12-19 23:05:39 +010012981 if (mp->is_ipv6)
12982 {
12983 struct in6_addr ip6;
12984
12985 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
12986 vat_json_object_add_ip6 (node, "src_address", ip6);
12987 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
12988 vat_json_object_add_ip6 (node, "dst_address", ip6);
12989 }
12990 else
12991 {
12992 struct in_addr ip4;
12993
12994 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
12995 vat_json_object_add_ip4 (node, "src_address", ip4);
12996 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
12997 vat_json_object_add_ip4 (node, "dst_address", ip4);
12998 }
12999 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
13000 vat_json_object_add_uint (node, "decap_next_index",
13001 ntohl (mp->decap_next_index));
13002 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
13003 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
13004 vat_json_object_add_uint (node, "mcast_sw_if_index",
13005 ntohl (mp->mcast_sw_if_index));
13006}
13007
13008static int
13009api_vxlan_tunnel_dump (vat_main_t * vam)
13010{
13011 unformat_input_t *i = vam->input;
13012 vl_api_vxlan_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013013 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013014 u32 sw_if_index;
13015 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013016 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013017
13018 /* Parse args required to build the message */
13019 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13020 {
13021 if (unformat (i, "sw_if_index %d", &sw_if_index))
13022 sw_if_index_set = 1;
13023 else
13024 break;
13025 }
13026
13027 if (sw_if_index_set == 0)
13028 {
13029 sw_if_index = ~0;
13030 }
13031
13032 if (!vam->json_output)
13033 {
Jon Loeliger3d460bd2018-02-01 16:36:12 -060013034 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
13035 "sw_if_index", "instance", "src_address", "dst_address",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013036 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
13037 }
13038
13039 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013040 M (VXLAN_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013041
13042 mp->sw_if_index = htonl (sw_if_index);
13043
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013044 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013045
13046 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013047 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013048 S (mp_ping);
13049
Jon Loeliger56c7b012017-02-01 12:31:41 -060013050 W (ret);
13051 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013052}
13053
Marco Varleseb598f1d2017-09-19 14:25:28 +020013054static uword unformat_geneve_decap_next
13055 (unformat_input_t * input, va_list * args)
13056{
13057 u32 *result = va_arg (*args, u32 *);
13058 u32 tmp;
13059
13060 if (unformat (input, "l2"))
13061 *result = GENEVE_INPUT_NEXT_L2_INPUT;
13062 else if (unformat (input, "%d", &tmp))
13063 *result = tmp;
13064 else
13065 return 0;
13066 return 1;
13067}
13068
13069static int
13070api_geneve_add_del_tunnel (vat_main_t * vam)
13071{
13072 unformat_input_t *line_input = vam->input;
13073 vl_api_geneve_add_del_tunnel_t *mp;
13074 ip46_address_t src, dst;
13075 u8 is_add = 1;
13076 u8 ipv4_set = 0, ipv6_set = 0;
13077 u8 src_set = 0;
13078 u8 dst_set = 0;
13079 u8 grp_set = 0;
13080 u32 mcast_sw_if_index = ~0;
13081 u32 encap_vrf_id = 0;
13082 u32 decap_next_index = ~0;
13083 u32 vni = 0;
13084 int ret;
13085
13086 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040013087 clib_memset (&src, 0, sizeof src);
13088 clib_memset (&dst, 0, sizeof dst);
Marco Varleseb598f1d2017-09-19 14:25:28 +020013089
13090 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13091 {
13092 if (unformat (line_input, "del"))
13093 is_add = 0;
13094 else
13095 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
13096 {
13097 ipv4_set = 1;
13098 src_set = 1;
13099 }
13100 else
13101 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
13102 {
13103 ipv4_set = 1;
13104 dst_set = 1;
13105 }
13106 else
13107 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
13108 {
13109 ipv6_set = 1;
13110 src_set = 1;
13111 }
13112 else
13113 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
13114 {
13115 ipv6_set = 1;
13116 dst_set = 1;
13117 }
13118 else if (unformat (line_input, "group %U %U",
13119 unformat_ip4_address, &dst.ip4,
13120 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13121 {
13122 grp_set = dst_set = 1;
13123 ipv4_set = 1;
13124 }
13125 else if (unformat (line_input, "group %U",
13126 unformat_ip4_address, &dst.ip4))
13127 {
13128 grp_set = dst_set = 1;
13129 ipv4_set = 1;
13130 }
13131 else if (unformat (line_input, "group %U %U",
13132 unformat_ip6_address, &dst.ip6,
13133 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13134 {
13135 grp_set = dst_set = 1;
13136 ipv6_set = 1;
13137 }
13138 else if (unformat (line_input, "group %U",
13139 unformat_ip6_address, &dst.ip6))
13140 {
13141 grp_set = dst_set = 1;
13142 ipv6_set = 1;
13143 }
13144 else
13145 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
13146 ;
13147 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
13148 ;
13149 else if (unformat (line_input, "decap-next %U",
13150 unformat_geneve_decap_next, &decap_next_index))
13151 ;
13152 else if (unformat (line_input, "vni %d", &vni))
13153 ;
13154 else
13155 {
13156 errmsg ("parse error '%U'", format_unformat_error, line_input);
13157 return -99;
13158 }
13159 }
13160
13161 if (src_set == 0)
13162 {
13163 errmsg ("tunnel src address not specified");
13164 return -99;
13165 }
13166 if (dst_set == 0)
13167 {
13168 errmsg ("tunnel dst address not specified");
13169 return -99;
13170 }
13171
13172 if (grp_set && !ip46_address_is_multicast (&dst))
13173 {
13174 errmsg ("tunnel group address not multicast");
13175 return -99;
13176 }
13177 if (grp_set && mcast_sw_if_index == ~0)
13178 {
13179 errmsg ("tunnel nonexistent multicast device");
13180 return -99;
13181 }
13182 if (grp_set == 0 && ip46_address_is_multicast (&dst))
13183 {
13184 errmsg ("tunnel dst address must be unicast");
13185 return -99;
13186 }
13187
13188
13189 if (ipv4_set && ipv6_set)
13190 {
13191 errmsg ("both IPv4 and IPv6 addresses specified");
13192 return -99;
13193 }
13194
13195 if ((vni == 0) || (vni >> 24))
13196 {
13197 errmsg ("vni not specified or out of range");
13198 return -99;
13199 }
13200
13201 M (GENEVE_ADD_DEL_TUNNEL, mp);
13202
13203 if (ipv6_set)
13204 {
13205 clib_memcpy (mp->local_address, &src.ip6, sizeof (src.ip6));
13206 clib_memcpy (mp->remote_address, &dst.ip6, sizeof (dst.ip6));
13207 }
13208 else
13209 {
13210 clib_memcpy (mp->local_address, &src.ip4, sizeof (src.ip4));
13211 clib_memcpy (mp->remote_address, &dst.ip4, sizeof (dst.ip4));
13212 }
13213 mp->encap_vrf_id = ntohl (encap_vrf_id);
13214 mp->decap_next_index = ntohl (decap_next_index);
13215 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
13216 mp->vni = ntohl (vni);
13217 mp->is_add = is_add;
13218 mp->is_ipv6 = ipv6_set;
13219
13220 S (mp);
13221 W (ret);
13222 return ret;
13223}
13224
13225static void vl_api_geneve_tunnel_details_t_handler
13226 (vl_api_geneve_tunnel_details_t * mp)
13227{
13228 vat_main_t *vam = &vat_main;
13229 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->dst_address);
13230 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->src_address);
13231
13232 print (vam->ofp, "%11d%24U%24U%14d%18d%13d%19d",
13233 ntohl (mp->sw_if_index),
13234 format_ip46_address, &src, IP46_TYPE_ANY,
13235 format_ip46_address, &dst, IP46_TYPE_ANY,
13236 ntohl (mp->encap_vrf_id),
13237 ntohl (mp->decap_next_index), ntohl (mp->vni),
13238 ntohl (mp->mcast_sw_if_index));
13239}
13240
13241static void vl_api_geneve_tunnel_details_t_handler_json
13242 (vl_api_geneve_tunnel_details_t * mp)
13243{
13244 vat_main_t *vam = &vat_main;
13245 vat_json_node_t *node = NULL;
13246
13247 if (VAT_JSON_ARRAY != vam->json_tree.type)
13248 {
13249 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13250 vat_json_init_array (&vam->json_tree);
13251 }
13252 node = vat_json_array_add (&vam->json_tree);
13253
13254 vat_json_init_object (node);
13255 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13256 if (mp->is_ipv6)
13257 {
13258 struct in6_addr ip6;
13259
13260 clib_memcpy (&ip6, mp->src_address, sizeof (ip6));
13261 vat_json_object_add_ip6 (node, "src_address", ip6);
13262 clib_memcpy (&ip6, mp->dst_address, sizeof (ip6));
13263 vat_json_object_add_ip6 (node, "dst_address", ip6);
13264 }
13265 else
13266 {
13267 struct in_addr ip4;
13268
13269 clib_memcpy (&ip4, mp->src_address, sizeof (ip4));
13270 vat_json_object_add_ip4 (node, "src_address", ip4);
13271 clib_memcpy (&ip4, mp->dst_address, sizeof (ip4));
13272 vat_json_object_add_ip4 (node, "dst_address", ip4);
13273 }
13274 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
13275 vat_json_object_add_uint (node, "decap_next_index",
13276 ntohl (mp->decap_next_index));
13277 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
13278 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
13279 vat_json_object_add_uint (node, "mcast_sw_if_index",
13280 ntohl (mp->mcast_sw_if_index));
13281}
13282
13283static int
13284api_geneve_tunnel_dump (vat_main_t * vam)
13285{
13286 unformat_input_t *i = vam->input;
13287 vl_api_geneve_tunnel_dump_t *mp;
13288 vl_api_control_ping_t *mp_ping;
13289 u32 sw_if_index;
13290 u8 sw_if_index_set = 0;
13291 int ret;
13292
13293 /* Parse args required to build the message */
13294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13295 {
13296 if (unformat (i, "sw_if_index %d", &sw_if_index))
13297 sw_if_index_set = 1;
13298 else
13299 break;
13300 }
13301
13302 if (sw_if_index_set == 0)
13303 {
13304 sw_if_index = ~0;
13305 }
13306
13307 if (!vam->json_output)
13308 {
13309 print (vam->ofp, "%11s%24s%24s%14s%18s%13s%19s",
13310 "sw_if_index", "local_address", "remote_address",
13311 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
13312 }
13313
13314 /* Get list of geneve-tunnel interfaces */
13315 M (GENEVE_TUNNEL_DUMP, mp);
13316
13317 mp->sw_if_index = htonl (sw_if_index);
13318
13319 S (mp);
13320
13321 /* Use a control ping for synchronization */
13322 M (CONTROL_PING, mp_ping);
13323 S (mp_ping);
13324
13325 W (ret);
13326 return ret;
13327}
13328
Damjan Marion7cd468a2016-12-19 23:05:39 +010013329static int
13330api_gre_add_del_tunnel (vat_main_t * vam)
13331{
13332 unformat_input_t *line_input = vam->input;
13333 vl_api_gre_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013334 ip4_address_t src4, dst4;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013335 ip6_address_t src6, dst6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013336 u8 is_add = 1;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013337 u8 ipv4_set = 0;
13338 u8 ipv6_set = 0;
John Loa43ccae2018-02-13 17:15:23 -050013339 u8 t_type = GRE_TUNNEL_TYPE_L3;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013340 u8 src_set = 0;
13341 u8 dst_set = 0;
13342 u32 outer_fib_id = 0;
John Loa43ccae2018-02-13 17:15:23 -050013343 u32 session_id = 0;
13344 u32 instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013345 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013346
Dave Barachb7b92992018-10-17 10:38:51 -040013347 clib_memset (&src4, 0, sizeof src4);
13348 clib_memset (&dst4, 0, sizeof dst4);
13349 clib_memset (&src6, 0, sizeof src6);
13350 clib_memset (&dst6, 0, sizeof dst6);
Ciara Loftus7eac9162016-09-30 15:47:03 +010013351
Damjan Marion7cd468a2016-12-19 23:05:39 +010013352 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13353 {
13354 if (unformat (line_input, "del"))
13355 is_add = 0;
John Loa43ccae2018-02-13 17:15:23 -050013356 else if (unformat (line_input, "instance %d", &instance))
13357 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013358 else if (unformat (line_input, "src %U", unformat_ip4_address, &src4))
Ciara Loftus7eac9162016-09-30 15:47:03 +010013359 {
13360 src_set = 1;
13361 ipv4_set = 1;
13362 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013363 else if (unformat (line_input, "dst %U", unformat_ip4_address, &dst4))
Ciara Loftus7eac9162016-09-30 15:47:03 +010013364 {
13365 dst_set = 1;
13366 ipv4_set = 1;
13367 }
13368 else if (unformat (line_input, "src %U", unformat_ip6_address, &src6))
13369 {
13370 src_set = 1;
13371 ipv6_set = 1;
13372 }
13373 else if (unformat (line_input, "dst %U", unformat_ip6_address, &dst6))
13374 {
13375 dst_set = 1;
13376 ipv6_set = 1;
13377 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013378 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
13379 ;
13380 else if (unformat (line_input, "teb"))
John Loa43ccae2018-02-13 17:15:23 -050013381 t_type = GRE_TUNNEL_TYPE_TEB;
13382 else if (unformat (line_input, "erspan %d", &session_id))
13383 t_type = GRE_TUNNEL_TYPE_ERSPAN;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013384 else
13385 {
13386 errmsg ("parse error '%U'", format_unformat_error, line_input);
13387 return -99;
13388 }
13389 }
13390
13391 if (src_set == 0)
13392 {
13393 errmsg ("tunnel src address not specified");
13394 return -99;
13395 }
13396 if (dst_set == 0)
13397 {
13398 errmsg ("tunnel dst address not specified");
13399 return -99;
13400 }
Ciara Loftus7eac9162016-09-30 15:47:03 +010013401 if (ipv4_set && ipv6_set)
13402 {
13403 errmsg ("both IPv4 and IPv6 addresses specified");
13404 return -99;
13405 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010013406
13407
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013408 M (GRE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013409
Ciara Loftus7eac9162016-09-30 15:47:03 +010013410 if (ipv4_set)
13411 {
13412 clib_memcpy (&mp->src_address, &src4, 4);
13413 clib_memcpy (&mp->dst_address, &dst4, 4);
13414 }
13415 else
13416 {
13417 clib_memcpy (&mp->src_address, &src6, 16);
13418 clib_memcpy (&mp->dst_address, &dst6, 16);
13419 }
John Loa43ccae2018-02-13 17:15:23 -050013420 mp->instance = htonl (instance);
13421 mp->outer_fib_id = htonl (outer_fib_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013422 mp->is_add = is_add;
John Loa43ccae2018-02-13 17:15:23 -050013423 mp->session_id = htons ((u16) session_id);
13424 mp->tunnel_type = t_type;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013425 mp->is_ipv6 = ipv6_set;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013426
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013427 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013428 W (ret);
13429 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013430}
13431
13432static void vl_api_gre_tunnel_details_t_handler
13433 (vl_api_gre_tunnel_details_t * mp)
13434{
13435 vat_main_t *vam = &vat_main;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013436 ip46_address_t src = to_ip46 (mp->is_ipv6, mp->src_address);
13437 ip46_address_t dst = to_ip46 (mp->is_ipv6, mp->dst_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013438
John Loa43ccae2018-02-13 17:15:23 -050013439 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013440 ntohl (mp->sw_if_index),
John Loa43ccae2018-02-13 17:15:23 -050013441 ntohl (mp->instance),
Ciara Loftus7eac9162016-09-30 15:47:03 +010013442 format_ip46_address, &src, IP46_TYPE_ANY,
13443 format_ip46_address, &dst, IP46_TYPE_ANY,
John Loa43ccae2018-02-13 17:15:23 -050013444 mp->tunnel_type, ntohl (mp->outer_fib_id), ntohl (mp->session_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013445}
13446
13447static void vl_api_gre_tunnel_details_t_handler_json
13448 (vl_api_gre_tunnel_details_t * mp)
13449{
13450 vat_main_t *vam = &vat_main;
13451 vat_json_node_t *node = NULL;
13452 struct in_addr ip4;
Ciara Loftus7eac9162016-09-30 15:47:03 +010013453 struct in6_addr ip6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013454
13455 if (VAT_JSON_ARRAY != vam->json_tree.type)
13456 {
13457 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13458 vat_json_init_array (&vam->json_tree);
13459 }
13460 node = vat_json_array_add (&vam->json_tree);
13461
13462 vat_json_init_object (node);
13463 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
John Loa43ccae2018-02-13 17:15:23 -050013464 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
Ciara Loftus7eac9162016-09-30 15:47:03 +010013465 if (!mp->is_ipv6)
13466 {
13467 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
13468 vat_json_object_add_ip4 (node, "src_address", ip4);
13469 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
13470 vat_json_object_add_ip4 (node, "dst_address", ip4);
13471 }
13472 else
13473 {
13474 clib_memcpy (&ip6, &mp->src_address, sizeof (ip6));
13475 vat_json_object_add_ip6 (node, "src_address", ip6);
13476 clib_memcpy (&ip6, &mp->dst_address, sizeof (ip6));
13477 vat_json_object_add_ip6 (node, "dst_address", ip6);
13478 }
John Loa43ccae2018-02-13 17:15:23 -050013479 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel_type);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013480 vat_json_object_add_uint (node, "outer_fib_id", ntohl (mp->outer_fib_id));
Ciara Loftus7eac9162016-09-30 15:47:03 +010013481 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6);
John Loa43ccae2018-02-13 17:15:23 -050013482 vat_json_object_add_uint (node, "session_id", mp->session_id);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013483}
13484
13485static int
13486api_gre_tunnel_dump (vat_main_t * vam)
13487{
13488 unformat_input_t *i = vam->input;
13489 vl_api_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013490 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013491 u32 sw_if_index;
13492 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013493 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013494
13495 /* Parse args required to build the message */
13496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13497 {
13498 if (unformat (i, "sw_if_index %d", &sw_if_index))
13499 sw_if_index_set = 1;
13500 else
13501 break;
13502 }
13503
13504 if (sw_if_index_set == 0)
13505 {
13506 sw_if_index = ~0;
13507 }
13508
13509 if (!vam->json_output)
13510 {
John Loa43ccae2018-02-13 17:15:23 -050013511 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
13512 "sw_if_index", "instance", "src_address", "dst_address",
13513 "tunnel_type", "outer_fib_id", "session_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013514 }
13515
13516 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013517 M (GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013518
13519 mp->sw_if_index = htonl (sw_if_index);
13520
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013521 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013522
13523 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013524 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013525 S (mp_ping);
13526
Jon Loeliger56c7b012017-02-01 12:31:41 -060013527 W (ret);
13528 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013529}
13530
13531static int
13532api_l2_fib_clear_table (vat_main_t * vam)
13533{
13534// unformat_input_t * i = vam->input;
13535 vl_api_l2_fib_clear_table_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013536 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013537
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013538 M (L2_FIB_CLEAR_TABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013539
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013540 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013541 W (ret);
13542 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013543}
13544
13545static int
13546api_l2_interface_efp_filter (vat_main_t * vam)
13547{
13548 unformat_input_t *i = vam->input;
13549 vl_api_l2_interface_efp_filter_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013550 u32 sw_if_index;
13551 u8 enable = 1;
13552 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013553 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013554
13555 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13556 {
13557 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13558 sw_if_index_set = 1;
13559 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13560 sw_if_index_set = 1;
13561 else if (unformat (i, "enable"))
13562 enable = 1;
13563 else if (unformat (i, "disable"))
13564 enable = 0;
13565 else
13566 {
13567 clib_warning ("parse error '%U'", format_unformat_error, i);
13568 return -99;
13569 }
13570 }
13571
13572 if (sw_if_index_set == 0)
13573 {
13574 errmsg ("missing sw_if_index");
13575 return -99;
13576 }
13577
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013578 M (L2_INTERFACE_EFP_FILTER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013579
13580 mp->sw_if_index = ntohl (sw_if_index);
13581 mp->enable_disable = enable;
13582
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013583 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013584 W (ret);
13585 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013586}
13587
13588#define foreach_vtr_op \
13589_("disable", L2_VTR_DISABLED) \
13590_("push-1", L2_VTR_PUSH_1) \
13591_("push-2", L2_VTR_PUSH_2) \
13592_("pop-1", L2_VTR_POP_1) \
13593_("pop-2", L2_VTR_POP_2) \
13594_("translate-1-1", L2_VTR_TRANSLATE_1_1) \
13595_("translate-1-2", L2_VTR_TRANSLATE_1_2) \
13596_("translate-2-1", L2_VTR_TRANSLATE_2_1) \
13597_("translate-2-2", L2_VTR_TRANSLATE_2_2)
13598
13599static int
13600api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
13601{
13602 unformat_input_t *i = vam->input;
13603 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013604 u32 sw_if_index;
13605 u8 sw_if_index_set = 0;
13606 u8 vtr_op_set = 0;
13607 u32 vtr_op = 0;
13608 u32 push_dot1q = 1;
13609 u32 tag1 = ~0;
13610 u32 tag2 = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013611 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013612
13613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13614 {
13615 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13616 sw_if_index_set = 1;
13617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13618 sw_if_index_set = 1;
13619 else if (unformat (i, "vtr_op %d", &vtr_op))
13620 vtr_op_set = 1;
13621#define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
13622 foreach_vtr_op
13623#undef _
13624 else if (unformat (i, "push_dot1q %d", &push_dot1q))
13625 ;
13626 else if (unformat (i, "tag1 %d", &tag1))
13627 ;
13628 else if (unformat (i, "tag2 %d", &tag2))
13629 ;
13630 else
13631 {
13632 clib_warning ("parse error '%U'", format_unformat_error, i);
13633 return -99;
13634 }
13635 }
13636
13637 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
13638 {
13639 errmsg ("missing vtr operation or sw_if_index");
13640 return -99;
13641 }
13642
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013643 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
13644 mp->sw_if_index = ntohl (sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013645 mp->vtr_op = ntohl (vtr_op);
13646 mp->push_dot1q = ntohl (push_dot1q);
13647 mp->tag1 = ntohl (tag1);
13648 mp->tag2 = ntohl (tag2);
13649
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013650 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013651 W (ret);
13652 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013653}
13654
13655static int
13656api_create_vhost_user_if (vat_main_t * vam)
13657{
13658 unformat_input_t *i = vam->input;
13659 vl_api_create_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013660 u8 *file_name;
13661 u8 is_server = 0;
13662 u8 file_name_set = 0;
13663 u32 custom_dev_instance = ~0;
13664 u8 hwaddr[6];
13665 u8 use_custom_mac = 0;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013666 u8 disable_mrg_rxbuf = 0;
13667 u8 disable_indirect_desc = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013668 u8 *tag = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013669 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013670
13671 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040013672 clib_memset (hwaddr, 0, sizeof (hwaddr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010013673
13674 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13675 {
13676 if (unformat (i, "socket %s", &file_name))
13677 {
13678 file_name_set = 1;
13679 }
13680 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13681 ;
13682 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
13683 use_custom_mac = 1;
13684 else if (unformat (i, "server"))
13685 is_server = 1;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013686 else if (unformat (i, "disable_mrg_rxbuf"))
13687 disable_mrg_rxbuf = 1;
13688 else if (unformat (i, "disable_indirect_desc"))
13689 disable_indirect_desc = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013690 else if (unformat (i, "tag %s", &tag))
13691 ;
13692 else
13693 break;
13694 }
13695
13696 if (file_name_set == 0)
13697 {
13698 errmsg ("missing socket file name");
13699 return -99;
13700 }
13701
13702 if (vec_len (file_name) > 255)
13703 {
13704 errmsg ("socket file name too long");
13705 return -99;
13706 }
13707 vec_add1 (file_name, 0);
13708
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013709 M (CREATE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013710
13711 mp->is_server = is_server;
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013712 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
13713 mp->disable_indirect_desc = disable_indirect_desc;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013714 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13715 vec_free (file_name);
13716 if (custom_dev_instance != ~0)
13717 {
13718 mp->renumber = 1;
13719 mp->custom_dev_instance = ntohl (custom_dev_instance);
13720 }
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020013721
Damjan Marion7cd468a2016-12-19 23:05:39 +010013722 mp->use_custom_mac = use_custom_mac;
13723 clib_memcpy (mp->mac_address, hwaddr, 6);
13724 if (tag)
13725 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13726 vec_free (tag);
13727
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013728 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013729 W (ret);
13730 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013731}
13732
13733static int
13734api_modify_vhost_user_if (vat_main_t * vam)
13735{
13736 unformat_input_t *i = vam->input;
13737 vl_api_modify_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013738 u8 *file_name;
13739 u8 is_server = 0;
13740 u8 file_name_set = 0;
13741 u32 custom_dev_instance = ~0;
13742 u8 sw_if_index_set = 0;
13743 u32 sw_if_index = (u32) ~ 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013744 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013745
13746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13747 {
13748 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13749 sw_if_index_set = 1;
13750 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13751 sw_if_index_set = 1;
13752 else if (unformat (i, "socket %s", &file_name))
13753 {
13754 file_name_set = 1;
13755 }
13756 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
13757 ;
13758 else if (unformat (i, "server"))
13759 is_server = 1;
13760 else
13761 break;
13762 }
13763
13764 if (sw_if_index_set == 0)
13765 {
13766 errmsg ("missing sw_if_index or interface name");
13767 return -99;
13768 }
13769
13770 if (file_name_set == 0)
13771 {
13772 errmsg ("missing socket file name");
13773 return -99;
13774 }
13775
13776 if (vec_len (file_name) > 255)
13777 {
13778 errmsg ("socket file name too long");
13779 return -99;
13780 }
13781 vec_add1 (file_name, 0);
13782
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013783 M (MODIFY_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013784
13785 mp->sw_if_index = ntohl (sw_if_index);
13786 mp->is_server = is_server;
13787 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
13788 vec_free (file_name);
13789 if (custom_dev_instance != ~0)
13790 {
13791 mp->renumber = 1;
13792 mp->custom_dev_instance = ntohl (custom_dev_instance);
13793 }
13794
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013795 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013796 W (ret);
13797 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013798}
13799
13800static int
13801api_delete_vhost_user_if (vat_main_t * vam)
13802{
13803 unformat_input_t *i = vam->input;
13804 vl_api_delete_vhost_user_if_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013805 u32 sw_if_index = ~0;
13806 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013807 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013808
13809 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13810 {
13811 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13812 sw_if_index_set = 1;
13813 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13814 sw_if_index_set = 1;
13815 else
13816 break;
13817 }
13818
13819 if (sw_if_index_set == 0)
13820 {
13821 errmsg ("missing sw_if_index or interface name");
13822 return -99;
13823 }
13824
13825
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013826 M (DELETE_VHOST_USER_IF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013827
13828 mp->sw_if_index = ntohl (sw_if_index);
13829
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013830 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013831 W (ret);
13832 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013833}
13834
13835static void vl_api_sw_interface_vhost_user_details_t_handler
13836 (vl_api_sw_interface_vhost_user_details_t * mp)
13837{
13838 vat_main_t *vam = &vat_main;
13839
Stevenf3b53642017-05-01 14:03:02 -070013840 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010013841 (char *) mp->interface_name,
13842 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
13843 clib_net_to_host_u64 (mp->features), mp->is_server,
Stevenf3b53642017-05-01 14:03:02 -070013844 ntohl (mp->num_regions), (char *) mp->sock_filename);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013845 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
13846}
13847
13848static void vl_api_sw_interface_vhost_user_details_t_handler_json
13849 (vl_api_sw_interface_vhost_user_details_t * mp)
13850{
13851 vat_main_t *vam = &vat_main;
13852 vat_json_node_t *node = NULL;
13853
13854 if (VAT_JSON_ARRAY != vam->json_tree.type)
13855 {
13856 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13857 vat_json_init_array (&vam->json_tree);
13858 }
13859 node = vat_json_array_add (&vam->json_tree);
13860
13861 vat_json_init_object (node);
13862 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
13863 vat_json_object_add_string_copy (node, "interface_name",
13864 mp->interface_name);
13865 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
13866 ntohl (mp->virtio_net_hdr_sz));
13867 vat_json_object_add_uint (node, "features",
13868 clib_net_to_host_u64 (mp->features));
13869 vat_json_object_add_uint (node, "is_server", mp->is_server);
13870 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
13871 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
13872 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
13873}
13874
13875static int
13876api_sw_interface_vhost_user_dump (vat_main_t * vam)
13877{
13878 vl_api_sw_interface_vhost_user_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013879 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013880 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013881 print (vam->ofp,
Stevenf3b53642017-05-01 14:03:02 -070013882 "Interface name idx hdr_sz features server regions filename");
Damjan Marion7cd468a2016-12-19 23:05:39 +010013883
13884 /* Get list of vhost-user interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013885 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013886 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013887
13888 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040013889 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060013890 S (mp_ping);
13891
Jon Loeliger56c7b012017-02-01 12:31:41 -060013892 W (ret);
13893 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013894}
13895
13896static int
13897api_show_version (vat_main_t * vam)
13898{
13899 vl_api_show_version_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013900 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013901
Jon Loeliger8a2aea32017-01-31 13:19:40 -060013902 M (SHOW_VERSION, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010013903
Jon Loeliger7bc770c2017-01-31 14:03:33 -060013904 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060013905 W (ret);
13906 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013907}
13908
13909
13910static int
13911api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
13912{
13913 unformat_input_t *line_input = vam->input;
13914 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013915 ip4_address_t local4, remote4;
13916 ip6_address_t local6, remote6;
13917 u8 is_add = 1;
13918 u8 ipv4_set = 0, ipv6_set = 0;
13919 u8 local_set = 0;
13920 u8 remote_set = 0;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013921 u8 grp_set = 0;
13922 u32 mcast_sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013923 u32 encap_vrf_id = 0;
13924 u32 decap_vrf_id = 0;
13925 u8 protocol = ~0;
13926 u32 vni;
13927 u8 vni_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060013928 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013929
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013930 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
Dave Barachb7b92992018-10-17 10:38:51 -040013931 clib_memset (&local4, 0, sizeof local4);
13932 clib_memset (&remote4, 0, sizeof remote4);
13933 clib_memset (&local6, 0, sizeof local6);
13934 clib_memset (&remote6, 0, sizeof remote6);
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013935
Damjan Marion7cd468a2016-12-19 23:05:39 +010013936 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13937 {
13938 if (unformat (line_input, "del"))
13939 is_add = 0;
13940 else if (unformat (line_input, "local %U",
13941 unformat_ip4_address, &local4))
13942 {
13943 local_set = 1;
13944 ipv4_set = 1;
13945 }
13946 else if (unformat (line_input, "remote %U",
13947 unformat_ip4_address, &remote4))
13948 {
13949 remote_set = 1;
13950 ipv4_set = 1;
13951 }
13952 else if (unformat (line_input, "local %U",
13953 unformat_ip6_address, &local6))
13954 {
13955 local_set = 1;
13956 ipv6_set = 1;
13957 }
13958 else if (unformat (line_input, "remote %U",
13959 unformat_ip6_address, &remote6))
13960 {
13961 remote_set = 1;
13962 ipv6_set = 1;
13963 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080013964 else if (unformat (line_input, "group %U %U",
13965 unformat_ip4_address, &remote4,
13966 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13967 {
13968 grp_set = remote_set = 1;
13969 ipv4_set = 1;
13970 }
13971 else if (unformat (line_input, "group %U",
13972 unformat_ip4_address, &remote4))
13973 {
13974 grp_set = remote_set = 1;
13975 ipv4_set = 1;
13976 }
13977 else if (unformat (line_input, "group %U %U",
13978 unformat_ip6_address, &remote6,
13979 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
13980 {
13981 grp_set = remote_set = 1;
13982 ipv6_set = 1;
13983 }
13984 else if (unformat (line_input, "group %U",
13985 unformat_ip6_address, &remote6))
13986 {
13987 grp_set = remote_set = 1;
13988 ipv6_set = 1;
13989 }
13990 else
13991 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
13992 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010013993 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
13994 ;
13995 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
13996 ;
13997 else if (unformat (line_input, "vni %d", &vni))
13998 vni_set = 1;
13999 else if (unformat (line_input, "next-ip4"))
14000 protocol = 1;
14001 else if (unformat (line_input, "next-ip6"))
14002 protocol = 2;
14003 else if (unformat (line_input, "next-ethernet"))
14004 protocol = 3;
14005 else if (unformat (line_input, "next-nsh"))
14006 protocol = 4;
14007 else
14008 {
14009 errmsg ("parse error '%U'", format_unformat_error, line_input);
14010 return -99;
14011 }
14012 }
14013
14014 if (local_set == 0)
14015 {
14016 errmsg ("tunnel local address not specified");
14017 return -99;
14018 }
14019 if (remote_set == 0)
14020 {
14021 errmsg ("tunnel remote address not specified");
14022 return -99;
14023 }
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014024 if (grp_set && mcast_sw_if_index == ~0)
14025 {
14026 errmsg ("tunnel nonexistent multicast device");
14027 return -99;
14028 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010014029 if (ipv4_set && ipv6_set)
14030 {
14031 errmsg ("both IPv4 and IPv6 addresses specified");
14032 return -99;
14033 }
14034
14035 if (vni_set == 0)
14036 {
14037 errmsg ("vni not specified");
14038 return -99;
14039 }
14040
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014041 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014042
14043
14044 if (ipv6_set)
14045 {
14046 clib_memcpy (&mp->local, &local6, sizeof (local6));
14047 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
14048 }
14049 else
14050 {
14051 clib_memcpy (&mp->local, &local4, sizeof (local4));
14052 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
14053 }
14054
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014055 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014056 mp->encap_vrf_id = ntohl (encap_vrf_id);
14057 mp->decap_vrf_id = ntohl (decap_vrf_id);
14058 mp->protocol = protocol;
14059 mp->vni = ntohl (vni);
14060 mp->is_add = is_add;
14061 mp->is_ipv6 = ipv6_set;
14062
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014063 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014064 W (ret);
14065 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014066}
14067
14068static void vl_api_vxlan_gpe_tunnel_details_t_handler
14069 (vl_api_vxlan_gpe_tunnel_details_t * mp)
14070{
14071 vat_main_t *vam = &vat_main;
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014072 ip46_address_t local = to_ip46 (mp->is_ipv6, mp->local);
14073 ip46_address_t remote = to_ip46 (mp->is_ipv6, mp->remote);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014074
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014075 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010014076 ntohl (mp->sw_if_index),
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014077 format_ip46_address, &local, IP46_TYPE_ANY,
14078 format_ip46_address, &remote, IP46_TYPE_ANY,
14079 ntohl (mp->vni), mp->protocol,
14080 ntohl (mp->mcast_sw_if_index),
Damjan Marion7cd468a2016-12-19 23:05:39 +010014081 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
14082}
14083
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014084
Damjan Marion7cd468a2016-12-19 23:05:39 +010014085static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
14086 (vl_api_vxlan_gpe_tunnel_details_t * mp)
14087{
14088 vat_main_t *vam = &vat_main;
14089 vat_json_node_t *node = NULL;
14090 struct in_addr ip4;
14091 struct in6_addr ip6;
14092
14093 if (VAT_JSON_ARRAY != vam->json_tree.type)
14094 {
14095 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14096 vat_json_init_array (&vam->json_tree);
14097 }
14098 node = vat_json_array_add (&vam->json_tree);
14099
14100 vat_json_init_object (node);
14101 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
14102 if (mp->is_ipv6)
14103 {
14104 clib_memcpy (&ip6, &(mp->local[0]), sizeof (ip6));
14105 vat_json_object_add_ip6 (node, "local", ip6);
14106 clib_memcpy (&ip6, &(mp->remote[0]), sizeof (ip6));
14107 vat_json_object_add_ip6 (node, "remote", ip6);
14108 }
14109 else
14110 {
14111 clib_memcpy (&ip4, &(mp->local[0]), sizeof (ip4));
14112 vat_json_object_add_ip4 (node, "local", ip4);
14113 clib_memcpy (&ip4, &(mp->remote[0]), sizeof (ip4));
14114 vat_json_object_add_ip4 (node, "remote", ip4);
14115 }
14116 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
14117 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014118 vat_json_object_add_uint (node, "mcast_sw_if_index",
14119 ntohl (mp->mcast_sw_if_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014120 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
14121 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
14122 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
14123}
14124
14125static int
14126api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
14127{
14128 unformat_input_t *i = vam->input;
14129 vl_api_vxlan_gpe_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014130 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014131 u32 sw_if_index;
14132 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014133 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014134
14135 /* Parse args required to build the message */
14136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14137 {
14138 if (unformat (i, "sw_if_index %d", &sw_if_index))
14139 sw_if_index_set = 1;
14140 else
14141 break;
14142 }
14143
14144 if (sw_if_index_set == 0)
14145 {
14146 sw_if_index = ~0;
14147 }
14148
14149 if (!vam->json_output)
14150 {
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014151 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
Damjan Marion7cd468a2016-12-19 23:05:39 +010014152 "sw_if_index", "local", "remote", "vni",
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080014153 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
Damjan Marion7cd468a2016-12-19 23:05:39 +010014154 }
14155
14156 /* Get list of vxlan-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014157 M (VXLAN_GPE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014158
14159 mp->sw_if_index = htonl (sw_if_index);
14160
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014161 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014162
14163 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014164 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014165 S (mp_ping);
14166
Jon Loeliger56c7b012017-02-01 12:31:41 -060014167 W (ret);
14168 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014169}
14170
Ole Troan01384fe2017-05-12 11:55:35 +020014171static void vl_api_l2_fib_table_details_t_handler
14172 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014173{
14174 vat_main_t *vam = &vat_main;
14175
14176 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
14177 " %d %d %d",
Mohsin Kazmi57938f62017-10-27 21:28:07 +020014178 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
Damjan Marion7cd468a2016-12-19 23:05:39 +010014179 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
14180 mp->bvi_mac);
14181}
14182
Ole Troan01384fe2017-05-12 11:55:35 +020014183static void vl_api_l2_fib_table_details_t_handler_json
14184 (vl_api_l2_fib_table_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014185{
14186 vat_main_t *vam = &vat_main;
14187 vat_json_node_t *node = NULL;
14188
14189 if (VAT_JSON_ARRAY != vam->json_tree.type)
14190 {
14191 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14192 vat_json_init_array (&vam->json_tree);
14193 }
14194 node = vat_json_array_add (&vam->json_tree);
14195
14196 vat_json_init_object (node);
14197 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
Mohsin Kazmi57938f62017-10-27 21:28:07 +020014198 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014199 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
14200 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
14201 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
14202 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
14203}
14204
14205static int
14206api_l2_fib_table_dump (vat_main_t * vam)
14207{
14208 unformat_input_t *i = vam->input;
14209 vl_api_l2_fib_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014210 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014211 u32 bd_id;
14212 u8 bd_id_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014213 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014214
14215 /* Parse args required to build the message */
14216 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14217 {
14218 if (unformat (i, "bd_id %d", &bd_id))
14219 bd_id_set = 1;
14220 else
14221 break;
14222 }
14223
14224 if (bd_id_set == 0)
14225 {
14226 errmsg ("missing bridge domain");
14227 return -99;
14228 }
14229
14230 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
14231
14232 /* Get list of l2 fib entries */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014233 M (L2_FIB_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014234
14235 mp->bd_id = ntohl (bd_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014236 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014237
14238 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014239 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014240 S (mp_ping);
14241
Jon Loeliger56c7b012017-02-01 12:31:41 -060014242 W (ret);
14243 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014244}
14245
14246
14247static int
14248api_interface_name_renumber (vat_main_t * vam)
14249{
14250 unformat_input_t *line_input = vam->input;
14251 vl_api_interface_name_renumber_t *mp;
14252 u32 sw_if_index = ~0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014253 u32 new_show_dev_instance = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014254 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014255
14256 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14257 {
14258 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
14259 &sw_if_index))
14260 ;
14261 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
14262 ;
14263 else if (unformat (line_input, "new_show_dev_instance %d",
14264 &new_show_dev_instance))
14265 ;
14266 else
14267 break;
14268 }
14269
14270 if (sw_if_index == ~0)
14271 {
14272 errmsg ("missing interface name or sw_if_index");
14273 return -99;
14274 }
14275
14276 if (new_show_dev_instance == ~0)
14277 {
14278 errmsg ("missing new_show_dev_instance");
14279 return -99;
14280 }
14281
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014282 M (INTERFACE_NAME_RENUMBER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014283
14284 mp->sw_if_index = ntohl (sw_if_index);
14285 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
14286
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014287 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014288 W (ret);
14289 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014290}
14291
14292static int
John Loc7b43042018-04-13 16:46:22 -040014293api_ip_probe_neighbor (vat_main_t * vam)
14294{
14295 unformat_input_t *i = vam->input;
14296 vl_api_ip_probe_neighbor_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -070014297 vl_api_address_t dst_adr;
John Loc7b43042018-04-13 16:46:22 -040014298 u8 int_set = 0;
14299 u8 adr_set = 0;
John Loc7b43042018-04-13 16:46:22 -040014300 u32 sw_if_index;
14301 int ret;
14302
14303 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14304 {
14305 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14306 int_set = 1;
14307 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14308 int_set = 1;
Neale Ranns37029302018-08-10 05:30:06 -070014309 else if (unformat (i, "address %U", unformat_vl_api_address, dst_adr))
John Loc7b43042018-04-13 16:46:22 -040014310 adr_set = 1;
John Loc7b43042018-04-13 16:46:22 -040014311 else
14312 break;
14313 }
14314
14315 if (int_set == 0)
14316 {
14317 errmsg ("missing interface");
14318 return -99;
14319 }
14320
14321 if (adr_set == 0)
14322 {
14323 errmsg ("missing addresses");
14324 return -99;
14325 }
14326
14327 M (IP_PROBE_NEIGHBOR, mp);
14328
14329 mp->sw_if_index = ntohl (sw_if_index);
Neale Ranns37029302018-08-10 05:30:06 -070014330 clib_memcpy (&mp->dst, &dst_adr, sizeof (dst_adr));
John Loc7b43042018-04-13 16:46:22 -040014331
14332 S (mp);
14333 W (ret);
14334 return ret;
14335}
14336
14337static int
John Lo7f358b32018-04-28 01:19:24 -040014338api_ip_scan_neighbor_enable_disable (vat_main_t * vam)
14339{
14340 unformat_input_t *i = vam->input;
14341 vl_api_ip_scan_neighbor_enable_disable_t *mp;
14342 u8 mode = IP_SCAN_V46_NEIGHBORS;
14343 u32 interval = 0, time = 0, update = 0, delay = 0, stale = 0;
14344 int ret;
14345
14346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14347 {
14348 if (unformat (i, "ip4"))
14349 mode = IP_SCAN_V4_NEIGHBORS;
14350 else if (unformat (i, "ip6"))
14351 mode = IP_SCAN_V6_NEIGHBORS;
14352 if (unformat (i, "both"))
14353 mode = IP_SCAN_V46_NEIGHBORS;
14354 else if (unformat (i, "disable"))
14355 mode = IP_SCAN_DISABLED;
14356 else if (unformat (i, "interval %d", &interval))
14357 ;
14358 else if (unformat (i, "max-time %d", &time))
14359 ;
14360 else if (unformat (i, "max-update %d", &update))
14361 ;
14362 else if (unformat (i, "delay %d", &delay))
14363 ;
14364 else if (unformat (i, "stale %d", &stale))
14365 ;
14366 else
14367 break;
14368 }
14369
14370 if (interval > 255)
14371 {
14372 errmsg ("interval cannot exceed 255 minutes.");
14373 return -99;
14374 }
14375 if (time > 255)
14376 {
14377 errmsg ("max-time cannot exceed 255 usec.");
14378 return -99;
14379 }
14380 if (update > 255)
14381 {
14382 errmsg ("max-update cannot exceed 255.");
14383 return -99;
14384 }
14385 if (delay > 255)
14386 {
14387 errmsg ("delay cannot exceed 255 msec.");
14388 return -99;
14389 }
14390 if (stale > 255)
14391 {
14392 errmsg ("stale cannot exceed 255 minutes.");
14393 return -99;
14394 }
14395
14396 M (IP_SCAN_NEIGHBOR_ENABLE_DISABLE, mp);
14397 mp->mode = mode;
14398 mp->scan_interval = interval;
14399 mp->max_proc_time = time;
14400 mp->max_update = update;
14401 mp->scan_int_delay = delay;
14402 mp->stale_threshold = stale;
14403
14404 S (mp);
14405 W (ret);
14406 return ret;
14407}
14408
14409static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014410api_want_ip4_arp_events (vat_main_t * vam)
14411{
14412 unformat_input_t *line_input = vam->input;
14413 vl_api_want_ip4_arp_events_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014414 ip4_address_t address;
14415 int address_set = 0;
14416 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014417 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014418
14419 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14420 {
14421 if (unformat (line_input, "address %U", unformat_ip4_address, &address))
14422 address_set = 1;
14423 else if (unformat (line_input, "del"))
14424 enable_disable = 0;
14425 else
14426 break;
14427 }
14428
14429 if (address_set == 0)
14430 {
14431 errmsg ("missing addresses");
14432 return -99;
14433 }
14434
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014435 M (WANT_IP4_ARP_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014436 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014437 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014438 clib_memcpy (mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014439
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014440 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014441 W (ret);
14442 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014443}
14444
14445static int
14446api_want_ip6_nd_events (vat_main_t * vam)
14447{
14448 unformat_input_t *line_input = vam->input;
14449 vl_api_want_ip6_nd_events_t *mp;
Neale Ranns37029302018-08-10 05:30:06 -070014450 vl_api_ip6_address_t address;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014451 int address_set = 0;
14452 u32 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014453 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014454
14455 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14456 {
Neale Ranns37029302018-08-10 05:30:06 -070014457 if (unformat
14458 (line_input, "address %U", unformat_vl_api_ip6_address, &address))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014459 address_set = 1;
14460 else if (unformat (line_input, "del"))
14461 enable_disable = 0;
14462 else
14463 break;
14464 }
14465
14466 if (address_set == 0)
14467 {
14468 errmsg ("missing addresses");
14469 return -99;
14470 }
14471
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014472 M (WANT_IP6_ND_EVENTS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014473 mp->enable_disable = enable_disable;
John Lo20e1f2a2017-03-29 13:35:43 -040014474 mp->pid = htonl (getpid ());
Neale Ranns37029302018-08-10 05:30:06 -070014475 clib_memcpy (&mp->ip, &address, sizeof (address));
Damjan Marion7cd468a2016-12-19 23:05:39 +010014476
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014477 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014478 W (ret);
14479 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014480}
14481
14482static int
John Lo8d00fff2017-08-03 00:35:36 -040014483api_want_l2_macs_events (vat_main_t * vam)
14484{
14485 unformat_input_t *line_input = vam->input;
14486 vl_api_want_l2_macs_events_t *mp;
14487 u8 enable_disable = 1;
14488 u32 scan_delay = 0;
14489 u32 max_macs_in_event = 0;
14490 u32 learn_limit = 0;
14491 int ret;
14492
14493 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14494 {
14495 if (unformat (line_input, "learn-limit %d", &learn_limit))
14496 ;
14497 else if (unformat (line_input, "scan-delay %d", &scan_delay))
14498 ;
14499 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
14500 ;
14501 else if (unformat (line_input, "disable"))
14502 enable_disable = 0;
14503 else
14504 break;
14505 }
14506
14507 M (WANT_L2_MACS_EVENTS, mp);
14508 mp->enable_disable = enable_disable;
14509 mp->pid = htonl (getpid ());
14510 mp->learn_limit = htonl (learn_limit);
14511 mp->scan_delay = (u8) scan_delay;
14512 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
14513 S (mp);
14514 W (ret);
14515 return ret;
14516}
14517
14518static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014519api_input_acl_set_interface (vat_main_t * vam)
14520{
14521 unformat_input_t *i = vam->input;
14522 vl_api_input_acl_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014523 u32 sw_if_index;
14524 int sw_if_index_set;
14525 u32 ip4_table_index = ~0;
14526 u32 ip6_table_index = ~0;
14527 u32 l2_table_index = ~0;
14528 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014529 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014530
14531 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14532 {
14533 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14534 sw_if_index_set = 1;
14535 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14536 sw_if_index_set = 1;
14537 else if (unformat (i, "del"))
14538 is_add = 0;
14539 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14540 ;
14541 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14542 ;
14543 else if (unformat (i, "l2-table %d", &l2_table_index))
14544 ;
14545 else
14546 {
14547 clib_warning ("parse error '%U'", format_unformat_error, i);
14548 return -99;
14549 }
14550 }
14551
14552 if (sw_if_index_set == 0)
14553 {
14554 errmsg ("missing interface name or sw_if_index");
14555 return -99;
14556 }
14557
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014558 M (INPUT_ACL_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014559
14560 mp->sw_if_index = ntohl (sw_if_index);
14561 mp->ip4_table_index = ntohl (ip4_table_index);
14562 mp->ip6_table_index = ntohl (ip6_table_index);
14563 mp->l2_table_index = ntohl (l2_table_index);
14564 mp->is_add = is_add;
14565
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014566 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014567 W (ret);
14568 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014569}
14570
14571static int
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010014572api_output_acl_set_interface (vat_main_t * vam)
14573{
14574 unformat_input_t *i = vam->input;
14575 vl_api_output_acl_set_interface_t *mp;
14576 u32 sw_if_index;
14577 int sw_if_index_set;
14578 u32 ip4_table_index = ~0;
14579 u32 ip6_table_index = ~0;
14580 u32 l2_table_index = ~0;
14581 u8 is_add = 1;
14582 int ret;
14583
14584 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14585 {
14586 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14587 sw_if_index_set = 1;
14588 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14589 sw_if_index_set = 1;
14590 else if (unformat (i, "del"))
14591 is_add = 0;
14592 else if (unformat (i, "ip4-table %d", &ip4_table_index))
14593 ;
14594 else if (unformat (i, "ip6-table %d", &ip6_table_index))
14595 ;
14596 else if (unformat (i, "l2-table %d", &l2_table_index))
14597 ;
14598 else
14599 {
14600 clib_warning ("parse error '%U'", format_unformat_error, i);
14601 return -99;
14602 }
14603 }
14604
14605 if (sw_if_index_set == 0)
14606 {
14607 errmsg ("missing interface name or sw_if_index");
14608 return -99;
14609 }
14610
14611 M (OUTPUT_ACL_SET_INTERFACE, mp);
14612
14613 mp->sw_if_index = ntohl (sw_if_index);
14614 mp->ip4_table_index = ntohl (ip4_table_index);
14615 mp->ip6_table_index = ntohl (ip6_table_index);
14616 mp->l2_table_index = ntohl (l2_table_index);
14617 mp->is_add = is_add;
14618
14619 S (mp);
14620 W (ret);
14621 return ret;
14622}
14623
14624static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010014625api_ip_address_dump (vat_main_t * vam)
14626{
14627 unformat_input_t *i = vam->input;
14628 vl_api_ip_address_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014629 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014630 u32 sw_if_index = ~0;
14631 u8 sw_if_index_set = 0;
14632 u8 ipv4_set = 0;
14633 u8 ipv6_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014634 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014635
14636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14637 {
14638 if (unformat (i, "sw_if_index %d", &sw_if_index))
14639 sw_if_index_set = 1;
14640 else
14641 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14642 sw_if_index_set = 1;
14643 else if (unformat (i, "ipv4"))
14644 ipv4_set = 1;
14645 else if (unformat (i, "ipv6"))
14646 ipv6_set = 1;
14647 else
14648 break;
14649 }
14650
14651 if (ipv4_set && ipv6_set)
14652 {
14653 errmsg ("ipv4 and ipv6 flags cannot be both set");
14654 return -99;
14655 }
14656
14657 if ((!ipv4_set) && (!ipv6_set))
14658 {
14659 errmsg ("no ipv4 nor ipv6 flag set");
14660 return -99;
14661 }
14662
14663 if (sw_if_index_set == 0)
14664 {
14665 errmsg ("missing interface name or sw_if_index");
14666 return -99;
14667 }
14668
14669 vam->current_sw_if_index = sw_if_index;
14670 vam->is_ipv6 = ipv6_set;
14671
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014672 M (IP_ADDRESS_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014673 mp->sw_if_index = ntohl (sw_if_index);
14674 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014675 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014676
14677 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014678 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014679 S (mp_ping);
14680
Jon Loeliger56c7b012017-02-01 12:31:41 -060014681 W (ret);
14682 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014683}
14684
14685static int
14686api_ip_dump (vat_main_t * vam)
14687{
14688 vl_api_ip_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014689 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014690 unformat_input_t *in = vam->input;
14691 int ipv4_set = 0;
14692 int ipv6_set = 0;
14693 int is_ipv6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014694 int i;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014695 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014696
14697 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
14698 {
14699 if (unformat (in, "ipv4"))
14700 ipv4_set = 1;
14701 else if (unformat (in, "ipv6"))
14702 ipv6_set = 1;
14703 else
14704 break;
14705 }
14706
14707 if (ipv4_set && ipv6_set)
14708 {
14709 errmsg ("ipv4 and ipv6 flags cannot be both set");
14710 return -99;
14711 }
14712
14713 if ((!ipv4_set) && (!ipv6_set))
14714 {
14715 errmsg ("no ipv4 nor ipv6 flag set");
14716 return -99;
14717 }
14718
14719 is_ipv6 = ipv6_set;
14720 vam->is_ipv6 = is_ipv6;
14721
14722 /* free old data */
14723 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
14724 {
14725 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
14726 }
14727 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
14728
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014729 M (IP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014730 mp->is_ipv6 = ipv6_set;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014731 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014732
14733 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040014734 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060014735 S (mp_ping);
14736
Jon Loeliger56c7b012017-02-01 12:31:41 -060014737 W (ret);
14738 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014739}
14740
14741static int
14742api_ipsec_spd_add_del (vat_main_t * vam)
14743{
14744 unformat_input_t *i = vam->input;
14745 vl_api_ipsec_spd_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014746 u32 spd_id = ~0;
14747 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014748 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014749
14750 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14751 {
14752 if (unformat (i, "spd_id %d", &spd_id))
14753 ;
14754 else if (unformat (i, "del"))
14755 is_add = 0;
14756 else
14757 {
14758 clib_warning ("parse error '%U'", format_unformat_error, i);
14759 return -99;
14760 }
14761 }
14762 if (spd_id == ~0)
14763 {
14764 errmsg ("spd_id must be set");
14765 return -99;
14766 }
14767
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014768 M (IPSEC_SPD_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014769
14770 mp->spd_id = ntohl (spd_id);
14771 mp->is_add = is_add;
14772
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014773 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014774 W (ret);
14775 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014776}
14777
14778static int
14779api_ipsec_interface_add_del_spd (vat_main_t * vam)
14780{
14781 unformat_input_t *i = vam->input;
14782 vl_api_ipsec_interface_add_del_spd_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014783 u32 sw_if_index;
14784 u8 sw_if_index_set = 0;
14785 u32 spd_id = (u32) ~ 0;
14786 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014787 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014788
14789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14790 {
14791 if (unformat (i, "del"))
14792 is_add = 0;
14793 else if (unformat (i, "spd_id %d", &spd_id))
14794 ;
14795 else
14796 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14797 sw_if_index_set = 1;
14798 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14799 sw_if_index_set = 1;
14800 else
14801 {
14802 clib_warning ("parse error '%U'", format_unformat_error, i);
14803 return -99;
14804 }
14805
14806 }
14807
14808 if (spd_id == (u32) ~ 0)
14809 {
14810 errmsg ("spd_id must be set");
14811 return -99;
14812 }
14813
14814 if (sw_if_index_set == 0)
14815 {
14816 errmsg ("missing interface name or sw_if_index");
14817 return -99;
14818 }
14819
Jon Loeliger8a2aea32017-01-31 13:19:40 -060014820 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014821
14822 mp->spd_id = ntohl (spd_id);
14823 mp->sw_if_index = ntohl (sw_if_index);
14824 mp->is_add = is_add;
14825
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014826 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014827 W (ret);
14828 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014829}
14830
14831static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014832api_ipsec_spd_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014833{
14834 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014835 vl_api_ipsec_spd_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014836 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
14837 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
14838 i32 priority = 0;
14839 u32 rport_start = 0, rport_stop = (u32) ~ 0;
14840 u32 lport_start = 0, lport_stop = (u32) ~ 0;
Neale Ranns17dcec02019-01-09 21:22:20 -080014841 vl_api_address_t laddr_start = { }, laddr_stop =
14842 {
14843 }, raddr_start =
14844 {
14845 }, raddr_stop =
14846 {
14847 };
Jon Loeliger56c7b012017-02-01 12:31:41 -060014848 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014849
Damjan Marion7cd468a2016-12-19 23:05:39 +010014850 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14851 {
14852 if (unformat (i, "del"))
14853 is_add = 0;
14854 if (unformat (i, "outbound"))
14855 is_outbound = 1;
14856 if (unformat (i, "inbound"))
14857 is_outbound = 0;
14858 else if (unformat (i, "spd_id %d", &spd_id))
14859 ;
14860 else if (unformat (i, "sa_id %d", &sa_id))
14861 ;
14862 else if (unformat (i, "priority %d", &priority))
14863 ;
14864 else if (unformat (i, "protocol %d", &protocol))
14865 ;
14866 else if (unformat (i, "lport_start %d", &lport_start))
14867 ;
14868 else if (unformat (i, "lport_stop %d", &lport_stop))
14869 ;
14870 else if (unformat (i, "rport_start %d", &rport_start))
14871 ;
14872 else if (unformat (i, "rport_stop %d", &rport_stop))
14873 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014874 else if (unformat (i, "laddr_start %U",
14875 unformat_vl_api_address, &laddr_start))
14876 is_ip_any = 0;
14877 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
14878 &laddr_stop))
14879 is_ip_any = 0;
14880 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
14881 &raddr_start))
14882 is_ip_any = 0;
14883 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
14884 &raddr_stop))
14885 is_ip_any = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014886 else
14887 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
14888 {
14889 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
14890 {
14891 clib_warning ("unsupported action: 'resolve'");
14892 return -99;
14893 }
14894 }
14895 else
14896 {
14897 clib_warning ("parse error '%U'", format_unformat_error, i);
14898 return -99;
14899 }
14900
14901 }
14902
Neale Ranns17dcec02019-01-09 21:22:20 -080014903 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014904
Damjan Marion7cd468a2016-12-19 23:05:39 +010014905 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014906
14907 mp->entry.spd_id = ntohl (spd_id);
14908 mp->entry.priority = ntohl (priority);
14909 mp->entry.is_outbound = is_outbound;
14910
14911 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
14912 sizeof (vl_api_address_t));
14913 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
14914 sizeof (vl_api_address_t));
14915 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
14916 sizeof (vl_api_address_t));
14917 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
14918 sizeof (vl_api_address_t));
14919
14920 mp->entry.protocol = (u8) protocol;
14921 mp->entry.local_port_start = ntohs ((u16) lport_start);
14922 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
14923 mp->entry.remote_port_start = ntohs ((u16) rport_start);
14924 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
14925 mp->entry.policy = (u8) policy;
14926 mp->entry.sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080014927
Jon Loeliger7bc770c2017-01-31 14:03:33 -060014928 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060014929 W (ret);
14930 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014931}
14932
14933static int
Neale Ranns17dcec02019-01-09 21:22:20 -080014934api_ipsec_sad_entry_add_del (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010014935{
14936 unformat_input_t *i = vam->input;
Neale Ranns17dcec02019-01-09 21:22:20 -080014937 vl_api_ipsec_sad_entry_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014938 u32 sad_id = 0, spi = 0;
14939 u8 *ck = 0, *ik = 0;
14940 u8 is_add = 1;
14941
Neale Ranns17dcec02019-01-09 21:22:20 -080014942 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
14943 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
14944 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
14945 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
14946 vl_api_address_t tun_src, tun_dst;
Jon Loeliger56c7b012017-02-01 12:31:41 -060014947 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014948
14949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14950 {
14951 if (unformat (i, "del"))
14952 is_add = 0;
14953 else if (unformat (i, "sad_id %d", &sad_id))
14954 ;
14955 else if (unformat (i, "spi %d", &spi))
14956 ;
14957 else if (unformat (i, "esp"))
Neale Ranns17dcec02019-01-09 21:22:20 -080014958 protocol = IPSEC_API_PROTO_ESP;
14959 else
14960 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014961 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014962 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14963 if (ADDRESS_IP6 == tun_src.af)
14964 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014965 }
14966 else
Neale Ranns17dcec02019-01-09 21:22:20 -080014967 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
Damjan Marion7cd468a2016-12-19 23:05:39 +010014968 {
Neale Ranns17dcec02019-01-09 21:22:20 -080014969 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
14970 if (ADDRESS_IP6 == tun_src.af)
14971 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014972 }
Neale Ranns17dcec02019-01-09 21:22:20 -080014973 else
14974 if (unformat (i, "crypto_alg %U",
14975 unformat_ipsec_api_crypto_alg, &crypto_alg))
14976 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014977 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
14978 ;
Neale Ranns17dcec02019-01-09 21:22:20 -080014979 else if (unformat (i, "integ_alg %U",
14980 unformat_ipsec_api_integ_alg, &integ_alg))
14981 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014982 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
14983 ;
14984 else
14985 {
14986 clib_warning ("parse error '%U'", format_unformat_error, i);
14987 return -99;
14988 }
14989
14990 }
14991
Neale Ranns17dcec02019-01-09 21:22:20 -080014992 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010014993
Damjan Marion7cd468a2016-12-19 23:05:39 +010014994 mp->is_add = is_add;
Neale Ranns17dcec02019-01-09 21:22:20 -080014995 mp->entry.sad_id = ntohl (sad_id);
14996 mp->entry.protocol = protocol;
14997 mp->entry.spi = ntohl (spi);
14998 mp->entry.flags = flags;
Damjan Marion7cd468a2016-12-19 23:05:39 +010014999
Neale Ranns17dcec02019-01-09 21:22:20 -080015000 mp->entry.crypto_algorithm = crypto_alg;
15001 mp->entry.integrity_algorithm = integ_alg;
15002 mp->entry.crypto_key.length = vec_len (ck);
15003 mp->entry.integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015004
Neale Ranns17dcec02019-01-09 21:22:20 -080015005 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
15006 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
15007
15008 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
15009 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015010
15011 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080015012 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015013 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080015014 clib_memcpy (mp->entry.integrity_key.data, ik,
15015 mp->entry.integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015016
Neale Ranns17dcec02019-01-09 21:22:20 -080015017 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
Damjan Marion7cd468a2016-12-19 23:05:39 +010015018 {
Neale Ranns17dcec02019-01-09 21:22:20 -080015019 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
15020 sizeof (mp->entry.tunnel_src));
15021 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
15022 sizeof (mp->entry.tunnel_dst));
Damjan Marion7cd468a2016-12-19 23:05:39 +010015023 }
15024
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015025 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015026 W (ret);
15027 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015028}
15029
15030static int
15031api_ipsec_sa_set_key (vat_main_t * vam)
15032{
15033 unformat_input_t *i = vam->input;
15034 vl_api_ipsec_sa_set_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015035 u32 sa_id;
15036 u8 *ck = 0, *ik = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015037 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015038
15039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15040 {
15041 if (unformat (i, "sa_id %d", &sa_id))
15042 ;
15043 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
15044 ;
15045 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
15046 ;
15047 else
15048 {
15049 clib_warning ("parse error '%U'", format_unformat_error, i);
15050 return -99;
15051 }
15052 }
15053
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015054 M (IPSEC_SA_SET_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015055
15056 mp->sa_id = ntohl (sa_id);
Neale Ranns17dcec02019-01-09 21:22:20 -080015057 mp->crypto_key.length = vec_len (ck);
15058 mp->integrity_key.length = vec_len (ik);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015059
Neale Ranns17dcec02019-01-09 21:22:20 -080015060 if (mp->crypto_key.length > sizeof (mp->crypto_key.data))
15061 mp->crypto_key.length = sizeof (mp->crypto_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015062
Neale Ranns17dcec02019-01-09 21:22:20 -080015063 if (mp->integrity_key.length > sizeof (mp->integrity_key.data))
15064 mp->integrity_key.length = sizeof (mp->integrity_key.data);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015065
15066 if (ck)
Neale Ranns17dcec02019-01-09 21:22:20 -080015067 clib_memcpy (mp->crypto_key.data, ck, mp->crypto_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015068 if (ik)
Neale Ranns17dcec02019-01-09 21:22:20 -080015069 clib_memcpy (mp->integrity_key.data, ik, mp->integrity_key.length);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015070
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015071 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015072 W (ret);
15073 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015074}
15075
15076static int
Matthew Smithb0972cb2017-05-02 16:20:41 -050015077api_ipsec_tunnel_if_add_del (vat_main_t * vam)
15078{
15079 unformat_input_t *i = vam->input;
15080 vl_api_ipsec_tunnel_if_add_del_t *mp;
15081 u32 local_spi = 0, remote_spi = 0;
15082 u32 crypto_alg = 0, integ_alg = 0;
15083 u8 *lck = NULL, *rck = NULL;
15084 u8 *lik = NULL, *rik = NULL;
15085 ip4_address_t local_ip = { {0} };
15086 ip4_address_t remote_ip = { {0} };
15087 u8 is_add = 1;
15088 u8 esn = 0;
15089 u8 anti_replay = 0;
Matthew Smith8e1039a2018-04-12 07:32:56 -050015090 u8 renumber = 0;
15091 u32 instance = ~0;
Matthew Smithb0972cb2017-05-02 16:20:41 -050015092 int ret;
15093
15094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15095 {
15096 if (unformat (i, "del"))
15097 is_add = 0;
15098 else if (unformat (i, "esn"))
15099 esn = 1;
15100 else if (unformat (i, "anti_replay"))
15101 anti_replay = 1;
15102 else if (unformat (i, "local_spi %d", &local_spi))
15103 ;
15104 else if (unformat (i, "remote_spi %d", &remote_spi))
15105 ;
15106 else if (unformat (i, "local_ip %U", unformat_ip4_address, &local_ip))
15107 ;
15108 else if (unformat (i, "remote_ip %U", unformat_ip4_address, &remote_ip))
15109 ;
15110 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
15111 ;
15112 else
15113 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
15114 ;
15115 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
15116 ;
15117 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
15118 ;
15119 else
15120 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080015121 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050015122 {
Dave Baracha8d47642018-07-13 11:22:23 -040015123 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050015124 {
15125 errmsg ("unsupported crypto-alg: '%U'\n",
15126 format_ipsec_crypto_alg, crypto_alg);
15127 return -99;
15128 }
15129 }
15130 else
15131 if (unformat
Neale Ranns17dcec02019-01-09 21:22:20 -080015132 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
Matthew Smithb0972cb2017-05-02 16:20:41 -050015133 {
Dave Baracha8d47642018-07-13 11:22:23 -040015134 if (integ_alg >= IPSEC_INTEG_N_ALG)
Matthew Smithb0972cb2017-05-02 16:20:41 -050015135 {
15136 errmsg ("unsupported integ-alg: '%U'\n",
15137 format_ipsec_integ_alg, integ_alg);
15138 return -99;
15139 }
15140 }
Matthew Smith8e1039a2018-04-12 07:32:56 -050015141 else if (unformat (i, "instance %u", &instance))
15142 renumber = 1;
Matthew Smithb0972cb2017-05-02 16:20:41 -050015143 else
15144 {
15145 errmsg ("parse error '%U'\n", format_unformat_error, i);
15146 return -99;
15147 }
15148 }
15149
15150 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
15151
15152 mp->is_add = is_add;
15153 mp->esn = esn;
15154 mp->anti_replay = anti_replay;
15155
15156 clib_memcpy (mp->local_ip, &local_ip, sizeof (ip4_address_t));
15157 clib_memcpy (mp->remote_ip, &remote_ip, sizeof (ip4_address_t));
15158
15159 mp->local_spi = htonl (local_spi);
15160 mp->remote_spi = htonl (remote_spi);
15161 mp->crypto_alg = (u8) crypto_alg;
15162
15163 mp->local_crypto_key_len = 0;
15164 if (lck)
15165 {
15166 mp->local_crypto_key_len = vec_len (lck);
15167 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
15168 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
15169 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
15170 }
15171
15172 mp->remote_crypto_key_len = 0;
15173 if (rck)
15174 {
15175 mp->remote_crypto_key_len = vec_len (rck);
15176 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
15177 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
15178 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
15179 }
15180
15181 mp->integ_alg = (u8) integ_alg;
15182
15183 mp->local_integ_key_len = 0;
15184 if (lik)
15185 {
15186 mp->local_integ_key_len = vec_len (lik);
15187 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
15188 mp->local_integ_key_len = sizeof (mp->local_integ_key);
15189 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
15190 }
15191
15192 mp->remote_integ_key_len = 0;
15193 if (rik)
15194 {
15195 mp->remote_integ_key_len = vec_len (rik);
15196 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
15197 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
15198 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
15199 }
15200
Matthew Smith8e1039a2018-04-12 07:32:56 -050015201 if (renumber)
15202 {
15203 mp->renumber = renumber;
15204 mp->show_instance = ntohl (instance);
15205 }
15206
Matthew Smithb0972cb2017-05-02 16:20:41 -050015207 S (mp);
15208 W (ret);
15209 return ret;
15210}
15211
Matthew Smith28029532017-09-26 13:33:44 -050015212static void
15213vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
15214{
15215 vat_main_t *vam = &vat_main;
15216
15217 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
Neale Ranns8d7c5022019-02-06 01:41:05 -080015218 "crypto_key %U integ_alg %u integ_key %U flags %x "
Matthew Smith28029532017-09-26 13:33:44 -050015219 "tunnel_src_addr %U tunnel_dst_addr %U "
15220 "salt %u seq_outbound %lu last_seq_inbound %lu "
15221 "replay_window %lu total_data_size %lu\n",
Neale Ranns8d7c5022019-02-06 01:41:05 -080015222 ntohl (mp->entry.sad_id),
15223 ntohl (mp->sw_if_index),
15224 ntohl (mp->entry.spi),
15225 ntohl (mp->entry.protocol),
15226 ntohl (mp->entry.crypto_algorithm),
15227 format_hex_bytes, mp->entry.crypto_key.data,
15228 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
15229 format_hex_bytes, mp->entry.integrity_key.data,
15230 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
15231 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
15232 &mp->entry.tunnel_dst, ntohl (mp->salt),
Matthew Smith28029532017-09-26 13:33:44 -050015233 clib_net_to_host_u64 (mp->seq_outbound),
15234 clib_net_to_host_u64 (mp->last_seq_inbound),
15235 clib_net_to_host_u64 (mp->replay_window),
15236 clib_net_to_host_u64 (mp->total_data_size));
15237}
15238
15239#define vl_api_ipsec_sa_details_t_endian vl_noop_handler
15240#define vl_api_ipsec_sa_details_t_print vl_noop_handler
15241
Neale Ranns8d7c5022019-02-06 01:41:05 -080015242static void
15243vat_json_object_add_address (vat_json_node_t * node,
15244 const vl_api_address_t * addr)
15245{
15246 if (ADDRESS_IP6 == addr->af)
15247 {
15248 struct in6_addr ip6;
15249
15250 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
15251 vat_json_object_add_ip6 (node, "ip_address", ip6);
15252 }
15253 else
15254 {
15255 struct in_addr ip4;
15256
15257 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
15258 vat_json_object_add_ip4 (node, "ip_address", ip4);
15259 }
15260}
15261
Matthew Smith28029532017-09-26 13:33:44 -050015262static void vl_api_ipsec_sa_details_t_handler_json
15263 (vl_api_ipsec_sa_details_t * mp)
15264{
15265 vat_main_t *vam = &vat_main;
15266 vat_json_node_t *node = NULL;
Neale Ranns8d7c5022019-02-06 01:41:05 -080015267 vl_api_ipsec_sad_flags_t flags;
Matthew Smith28029532017-09-26 13:33:44 -050015268
15269 if (VAT_JSON_ARRAY != vam->json_tree.type)
15270 {
15271 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
15272 vat_json_init_array (&vam->json_tree);
15273 }
15274 node = vat_json_array_add (&vam->json_tree);
15275
15276 vat_json_init_object (node);
Neale Ranns8d7c5022019-02-06 01:41:05 -080015277 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
Matthew Smith28029532017-09-26 13:33:44 -050015278 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
Neale Ranns8d7c5022019-02-06 01:41:05 -080015279 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
15280 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
15281 vat_json_object_add_uint (node, "crypto_alg",
15282 ntohl (mp->entry.crypto_algorithm));
15283 vat_json_object_add_uint (node, "integ_alg",
15284 ntohl (mp->entry.integrity_algorithm));
15285 flags = ntohl (mp->entry.flags);
15286 vat_json_object_add_uint (node, "use_esn",
15287 ! !(flags &
15288 IPSEC_API_SAD_FLAG_USE_EXTENDED_SEQ_NUM));
15289 vat_json_object_add_uint (node, "use_anti_replay",
15290 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
15291 vat_json_object_add_uint (node, "is_tunnel",
15292 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
15293 vat_json_object_add_uint (node, "is_tunnel_ip6",
15294 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
15295 vat_json_object_add_uint (node, "udp_encap",
15296 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
15297 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
15298 mp->entry.crypto_key.length);
15299 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
15300 mp->entry.integrity_key.length);
15301 vat_json_object_add_address (node, &mp->entry.tunnel_src);
15302 vat_json_object_add_address (node, &mp->entry.tunnel_dst);
Matthew Smith28029532017-09-26 13:33:44 -050015303 vat_json_object_add_uint (node, "replay_window",
15304 clib_net_to_host_u64 (mp->replay_window));
15305 vat_json_object_add_uint (node, "total_data_size",
15306 clib_net_to_host_u64 (mp->total_data_size));
Matthew Smith28029532017-09-26 13:33:44 -050015307}
15308
15309static int
15310api_ipsec_sa_dump (vat_main_t * vam)
15311{
15312 unformat_input_t *i = vam->input;
15313 vl_api_ipsec_sa_dump_t *mp;
15314 vl_api_control_ping_t *mp_ping;
15315 u32 sa_id = ~0;
15316 int ret;
15317
15318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15319 {
15320 if (unformat (i, "sa_id %d", &sa_id))
15321 ;
15322 else
15323 {
15324 clib_warning ("parse error '%U'", format_unformat_error, i);
15325 return -99;
15326 }
15327 }
15328
15329 M (IPSEC_SA_DUMP, mp);
15330
15331 mp->sa_id = ntohl (sa_id);
15332
15333 S (mp);
15334
15335 /* Use a control ping for synchronization */
15336 M (CONTROL_PING, mp_ping);
15337 S (mp_ping);
15338
15339 W (ret);
15340 return ret;
15341}
15342
Matthew Smithb0972cb2017-05-02 16:20:41 -050015343static int
Matthew Smith75d85602017-10-05 19:03:05 -050015344api_ipsec_tunnel_if_set_key (vat_main_t * vam)
15345{
15346 unformat_input_t *i = vam->input;
15347 vl_api_ipsec_tunnel_if_set_key_t *mp;
15348 u32 sw_if_index = ~0;
15349 u8 key_type = IPSEC_IF_SET_KEY_TYPE_NONE;
15350 u8 *key = 0;
15351 u32 alg = ~0;
15352 int ret;
15353
15354 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15355 {
15356 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
15357 ;
15358 else
Neale Ranns17dcec02019-01-09 21:22:20 -080015359 if (unformat
15360 (i, "local crypto %U", unformat_ipsec_api_crypto_alg, &alg))
Matthew Smith75d85602017-10-05 19:03:05 -050015361 key_type = IPSEC_IF_SET_KEY_TYPE_LOCAL_CRYPTO;
15362 else
Neale Ranns17dcec02019-01-09 21:22:20 -080015363 if (unformat
15364 (i, "remote crypto %U", unformat_ipsec_api_crypto_alg, &alg))
Matthew Smith75d85602017-10-05 19:03:05 -050015365 key_type = IPSEC_IF_SET_KEY_TYPE_REMOTE_CRYPTO;
Neale Ranns17dcec02019-01-09 21:22:20 -080015366 else
15367 if (unformat
15368 (i, "local integ %U", unformat_ipsec_api_integ_alg, &alg))
Matthew Smith75d85602017-10-05 19:03:05 -050015369 key_type = IPSEC_IF_SET_KEY_TYPE_LOCAL_INTEG;
15370 else
Neale Ranns17dcec02019-01-09 21:22:20 -080015371 if (unformat
15372 (i, "remote integ %U", unformat_ipsec_api_integ_alg, &alg))
Matthew Smith75d85602017-10-05 19:03:05 -050015373 key_type = IPSEC_IF_SET_KEY_TYPE_REMOTE_INTEG;
15374 else if (unformat (i, "%U", unformat_hex_string, &key))
15375 ;
15376 else
15377 {
15378 clib_warning ("parse error '%U'", format_unformat_error, i);
15379 return -99;
15380 }
15381 }
15382
15383 if (sw_if_index == ~0)
15384 {
15385 errmsg ("interface must be specified");
15386 return -99;
15387 }
15388
15389 if (key_type == IPSEC_IF_SET_KEY_TYPE_NONE)
15390 {
15391 errmsg ("key type must be specified");
15392 return -99;
15393 }
15394
15395 if (alg == ~0)
15396 {
15397 errmsg ("algorithm must be specified");
15398 return -99;
15399 }
15400
15401 if (vec_len (key) == 0)
15402 {
15403 errmsg ("key must be specified");
15404 return -99;
15405 }
15406
15407 M (IPSEC_TUNNEL_IF_SET_KEY, mp);
15408
15409 mp->sw_if_index = htonl (sw_if_index);
15410 mp->alg = alg;
15411 mp->key_type = key_type;
15412 mp->key_len = vec_len (key);
15413 clib_memcpy (mp->key, key, vec_len (key));
15414
15415 S (mp);
15416 W (ret);
15417
15418 return ret;
15419}
15420
15421static int
Matthew Smithca514fd2017-10-12 12:06:59 -050015422api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
15423{
15424 unformat_input_t *i = vam->input;
15425 vl_api_ipsec_tunnel_if_set_sa_t *mp;
15426 u32 sw_if_index = ~0;
15427 u32 sa_id = ~0;
15428 u8 is_outbound = (u8) ~ 0;
15429 int ret;
15430
15431 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15432 {
15433 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
15434 ;
15435 else if (unformat (i, "sa_id %d", &sa_id))
15436 ;
15437 else if (unformat (i, "outbound"))
15438 is_outbound = 1;
15439 else if (unformat (i, "inbound"))
15440 is_outbound = 0;
15441 else
15442 {
15443 clib_warning ("parse error '%U'", format_unformat_error, i);
15444 return -99;
15445 }
15446 }
15447
15448 if (sw_if_index == ~0)
15449 {
15450 errmsg ("interface must be specified");
15451 return -99;
15452 }
15453
15454 if (sa_id == ~0)
15455 {
15456 errmsg ("SA ID must be specified");
15457 return -99;
15458 }
15459
15460 M (IPSEC_TUNNEL_IF_SET_SA, mp);
15461
15462 mp->sw_if_index = htonl (sw_if_index);
15463 mp->sa_id = htonl (sa_id);
15464 mp->is_outbound = is_outbound;
15465
15466 S (mp);
15467 W (ret);
15468
15469 return ret;
15470}
15471
15472static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010015473api_ikev2_profile_add_del (vat_main_t * vam)
15474{
15475 unformat_input_t *i = vam->input;
15476 vl_api_ikev2_profile_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015477 u8 is_add = 1;
15478 u8 *name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015479 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015480
15481 const char *valid_chars = "a-zA-Z0-9_";
15482
15483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15484 {
15485 if (unformat (i, "del"))
15486 is_add = 0;
15487 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
15488 vec_add1 (name, 0);
15489 else
15490 {
15491 errmsg ("parse error '%U'", format_unformat_error, i);
15492 return -99;
15493 }
15494 }
15495
15496 if (!vec_len (name))
15497 {
15498 errmsg ("profile name must be specified");
15499 return -99;
15500 }
15501
15502 if (vec_len (name) > 64)
15503 {
15504 errmsg ("profile name too long");
15505 return -99;
15506 }
15507
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015508 M (IKEV2_PROFILE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015509
15510 clib_memcpy (mp->name, name, vec_len (name));
15511 mp->is_add = is_add;
15512 vec_free (name);
15513
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015514 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015515 W (ret);
15516 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015517}
15518
15519static int
15520api_ikev2_profile_set_auth (vat_main_t * vam)
15521{
15522 unformat_input_t *i = vam->input;
15523 vl_api_ikev2_profile_set_auth_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015524 u8 *name = 0;
15525 u8 *data = 0;
15526 u32 auth_method = 0;
15527 u8 is_hex = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015528 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015529
15530 const char *valid_chars = "a-zA-Z0-9_";
15531
15532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15533 {
15534 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
15535 vec_add1 (name, 0);
15536 else if (unformat (i, "auth_method %U",
15537 unformat_ikev2_auth_method, &auth_method))
15538 ;
15539 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
15540 is_hex = 1;
15541 else if (unformat (i, "auth_data %v", &data))
15542 ;
15543 else
15544 {
15545 errmsg ("parse error '%U'", format_unformat_error, i);
15546 return -99;
15547 }
15548 }
15549
15550 if (!vec_len (name))
15551 {
15552 errmsg ("profile name must be specified");
15553 return -99;
15554 }
15555
15556 if (vec_len (name) > 64)
15557 {
15558 errmsg ("profile name too long");
15559 return -99;
15560 }
15561
15562 if (!vec_len (data))
15563 {
15564 errmsg ("auth_data must be specified");
15565 return -99;
15566 }
15567
15568 if (!auth_method)
15569 {
15570 errmsg ("auth_method must be specified");
15571 return -99;
15572 }
15573
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015574 M (IKEV2_PROFILE_SET_AUTH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015575
15576 mp->is_hex = is_hex;
15577 mp->auth_method = (u8) auth_method;
15578 mp->data_len = vec_len (data);
15579 clib_memcpy (mp->name, name, vec_len (name));
15580 clib_memcpy (mp->data, data, vec_len (data));
15581 vec_free (name);
15582 vec_free (data);
15583
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015584 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015585 W (ret);
15586 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015587}
15588
15589static int
15590api_ikev2_profile_set_id (vat_main_t * vam)
15591{
15592 unformat_input_t *i = vam->input;
15593 vl_api_ikev2_profile_set_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015594 u8 *name = 0;
15595 u8 *data = 0;
15596 u8 is_local = 0;
15597 u32 id_type = 0;
15598 ip4_address_t ip4;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015599 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015600
15601 const char *valid_chars = "a-zA-Z0-9_";
15602
15603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15604 {
15605 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
15606 vec_add1 (name, 0);
15607 else if (unformat (i, "id_type %U", unformat_ikev2_id_type, &id_type))
15608 ;
15609 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
15610 {
15611 data = vec_new (u8, 4);
15612 clib_memcpy (data, ip4.as_u8, 4);
15613 }
15614 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
15615 ;
15616 else if (unformat (i, "id_data %v", &data))
15617 ;
15618 else if (unformat (i, "local"))
15619 is_local = 1;
15620 else if (unformat (i, "remote"))
15621 is_local = 0;
15622 else
15623 {
15624 errmsg ("parse error '%U'", format_unformat_error, i);
15625 return -99;
15626 }
15627 }
15628
15629 if (!vec_len (name))
15630 {
15631 errmsg ("profile name must be specified");
15632 return -99;
15633 }
15634
15635 if (vec_len (name) > 64)
15636 {
15637 errmsg ("profile name too long");
15638 return -99;
15639 }
15640
15641 if (!vec_len (data))
15642 {
15643 errmsg ("id_data must be specified");
15644 return -99;
15645 }
15646
15647 if (!id_type)
15648 {
15649 errmsg ("id_type must be specified");
15650 return -99;
15651 }
15652
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015653 M (IKEV2_PROFILE_SET_ID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015654
15655 mp->is_local = is_local;
15656 mp->id_type = (u8) id_type;
15657 mp->data_len = vec_len (data);
15658 clib_memcpy (mp->name, name, vec_len (name));
15659 clib_memcpy (mp->data, data, vec_len (data));
15660 vec_free (name);
15661 vec_free (data);
15662
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015663 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015664 W (ret);
15665 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015666}
15667
15668static int
15669api_ikev2_profile_set_ts (vat_main_t * vam)
15670{
15671 unformat_input_t *i = vam->input;
15672 vl_api_ikev2_profile_set_ts_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015673 u8 *name = 0;
15674 u8 is_local = 0;
15675 u32 proto = 0, start_port = 0, end_port = (u32) ~ 0;
15676 ip4_address_t start_addr, end_addr;
15677
15678 const char *valid_chars = "a-zA-Z0-9_";
Jon Loeliger56c7b012017-02-01 12:31:41 -060015679 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015680
15681 start_addr.as_u32 = 0;
15682 end_addr.as_u32 = (u32) ~ 0;
15683
15684 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15685 {
15686 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
15687 vec_add1 (name, 0);
15688 else if (unformat (i, "protocol %d", &proto))
15689 ;
15690 else if (unformat (i, "start_port %d", &start_port))
15691 ;
15692 else if (unformat (i, "end_port %d", &end_port))
15693 ;
15694 else
15695 if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
15696 ;
15697 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
15698 ;
15699 else if (unformat (i, "local"))
15700 is_local = 1;
15701 else if (unformat (i, "remote"))
15702 is_local = 0;
15703 else
15704 {
15705 errmsg ("parse error '%U'", format_unformat_error, i);
15706 return -99;
15707 }
15708 }
15709
15710 if (!vec_len (name))
15711 {
15712 errmsg ("profile name must be specified");
15713 return -99;
15714 }
15715
15716 if (vec_len (name) > 64)
15717 {
15718 errmsg ("profile name too long");
15719 return -99;
15720 }
15721
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015722 M (IKEV2_PROFILE_SET_TS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015723
15724 mp->is_local = is_local;
15725 mp->proto = (u8) proto;
15726 mp->start_port = (u16) start_port;
15727 mp->end_port = (u16) end_port;
15728 mp->start_addr = start_addr.as_u32;
15729 mp->end_addr = end_addr.as_u32;
15730 clib_memcpy (mp->name, name, vec_len (name));
15731 vec_free (name);
15732
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015733 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015734 W (ret);
15735 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015736}
15737
15738static int
15739api_ikev2_set_local_key (vat_main_t * vam)
15740{
15741 unformat_input_t *i = vam->input;
15742 vl_api_ikev2_set_local_key_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015743 u8 *file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060015744 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015745
15746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15747 {
15748 if (unformat (i, "file %v", &file))
15749 vec_add1 (file, 0);
15750 else
15751 {
15752 errmsg ("parse error '%U'", format_unformat_error, i);
15753 return -99;
15754 }
15755 }
15756
15757 if (!vec_len (file))
15758 {
15759 errmsg ("RSA key file must be specified");
15760 return -99;
15761 }
15762
15763 if (vec_len (file) > 256)
15764 {
15765 errmsg ("file name too long");
15766 return -99;
15767 }
15768
Jon Loeliger8a2aea32017-01-31 13:19:40 -060015769 M (IKEV2_SET_LOCAL_KEY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010015770
15771 clib_memcpy (mp->key_file, file, vec_len (file));
15772 vec_free (file);
15773
Jon Loeliger7bc770c2017-01-31 14:03:33 -060015774 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060015775 W (ret);
15776 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010015777}
15778
Radu Nicolaucb33dc22017-02-16 16:49:46 +000015779static int
15780api_ikev2_set_responder (vat_main_t * vam)
15781{
15782 unformat_input_t *i = vam->input;
15783 vl_api_ikev2_set_responder_t *mp;
15784 int ret;
15785 u8 *name = 0;
15786 u32 sw_if_index = ~0;
15787 ip4_address_t address;
15788
15789 const char *valid_chars = "a-zA-Z0-9_";
15790
15791 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15792 {
15793 if (unformat
15794 (i, "%U interface %d address %U", unformat_token, valid_chars,
15795 &name, &sw_if_index, unformat_ip4_address, &address))
15796 vec_add1 (name, 0);
15797 else
15798 {
15799 errmsg ("parse error '%U'", format_unformat_error, i);
15800 return -99;
15801 }
15802 }
15803
15804 if (!vec_len (name))
15805 {
15806 errmsg ("profile name must be specified");
15807 return -99;
15808 }
15809
15810 if (vec_len (name) > 64)
15811 {
15812 errmsg ("profile name too long");
15813 return -99;
15814 }
15815
15816 M (IKEV2_SET_RESPONDER, mp);
15817
15818 clib_memcpy (mp->name, name, vec_len (name));
15819 vec_free (name);
15820
15821 mp->sw_if_index = sw_if_index;
15822 clib_memcpy (mp->address, &address, sizeof (address));
15823
15824 S (mp);
15825 W (ret);
15826 return ret;
15827}
15828
15829static int
15830api_ikev2_set_ike_transforms (vat_main_t * vam)
15831{
15832 unformat_input_t *i = vam->input;
15833 vl_api_ikev2_set_ike_transforms_t *mp;
15834 int ret;
15835 u8 *name = 0;
15836 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
15837
15838 const char *valid_chars = "a-zA-Z0-9_";
15839
15840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15841 {
15842 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
15843 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
15844 vec_add1 (name, 0);
15845 else
15846 {
15847 errmsg ("parse error '%U'", format_unformat_error, i);
15848 return -99;
15849 }
15850 }
15851
15852 if (!vec_len (name))
15853 {
15854 errmsg ("profile name must be specified");
15855 return -99;
15856 }
15857
15858 if (vec_len (name) > 64)
15859 {
15860 errmsg ("profile name too long");
15861 return -99;
15862 }
15863
15864 M (IKEV2_SET_IKE_TRANSFORMS, mp);
15865
15866 clib_memcpy (mp->name, name, vec_len (name));
15867 vec_free (name);
15868 mp->crypto_alg = crypto_alg;
15869 mp->crypto_key_size = crypto_key_size;
15870 mp->integ_alg = integ_alg;
15871 mp->dh_group = dh_group;
15872
15873 S (mp);
15874 W (ret);
15875 return ret;
15876}
15877
15878
15879static int
15880api_ikev2_set_esp_transforms (vat_main_t * vam)
15881{
15882 unformat_input_t *i = vam->input;
15883 vl_api_ikev2_set_esp_transforms_t *mp;
15884 int ret;
15885 u8 *name = 0;
15886 u32 crypto_alg, crypto_key_size, integ_alg, dh_group;
15887
15888 const char *valid_chars = "a-zA-Z0-9_";
15889
15890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15891 {
15892 if (unformat (i, "%U %d %d %d %d", unformat_token, valid_chars, &name,
15893 &crypto_alg, &crypto_key_size, &integ_alg, &dh_group))
15894 vec_add1 (name, 0);
15895 else
15896 {
15897 errmsg ("parse error '%U'", format_unformat_error, i);
15898 return -99;
15899 }
15900 }
15901
15902 if (!vec_len (name))
15903 {
15904 errmsg ("profile name must be specified");
15905 return -99;
15906 }
15907
15908 if (vec_len (name) > 64)
15909 {
15910 errmsg ("profile name too long");
15911 return -99;
15912 }
15913
15914 M (IKEV2_SET_ESP_TRANSFORMS, mp);
15915
15916 clib_memcpy (mp->name, name, vec_len (name));
15917 vec_free (name);
15918 mp->crypto_alg = crypto_alg;
15919 mp->crypto_key_size = crypto_key_size;
15920 mp->integ_alg = integ_alg;
15921 mp->dh_group = dh_group;
15922
15923 S (mp);
15924 W (ret);
15925 return ret;
15926}
15927
15928static int
15929api_ikev2_set_sa_lifetime (vat_main_t * vam)
15930{
15931 unformat_input_t *i = vam->input;
15932 vl_api_ikev2_set_sa_lifetime_t *mp;
15933 int ret;
15934 u8 *name = 0;
15935 u64 lifetime, lifetime_maxdata;
15936 u32 lifetime_jitter, handover;
15937
15938 const char *valid_chars = "a-zA-Z0-9_";
15939
15940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15941 {
15942 if (unformat (i, "%U %lu %u %u %lu", unformat_token, valid_chars, &name,
15943 &lifetime, &lifetime_jitter, &handover,
15944 &lifetime_maxdata))
15945 vec_add1 (name, 0);
15946 else
15947 {
15948 errmsg ("parse error '%U'", format_unformat_error, i);
15949 return -99;
15950 }
15951 }
15952
15953 if (!vec_len (name))
15954 {
15955 errmsg ("profile name must be specified");
15956 return -99;
15957 }
15958
15959 if (vec_len (name) > 64)
15960 {
15961 errmsg ("profile name too long");
15962 return -99;
15963 }
15964
15965 M (IKEV2_SET_SA_LIFETIME, mp);
15966
15967 clib_memcpy (mp->name, name, vec_len (name));
15968 vec_free (name);
15969 mp->lifetime = lifetime;
15970 mp->lifetime_jitter = lifetime_jitter;
15971 mp->handover = handover;
15972 mp->lifetime_maxdata = lifetime_maxdata;
15973
15974 S (mp);
15975 W (ret);
15976 return ret;
15977}
15978
15979static int
15980api_ikev2_initiate_sa_init (vat_main_t * vam)
15981{
15982 unformat_input_t *i = vam->input;
15983 vl_api_ikev2_initiate_sa_init_t *mp;
15984 int ret;
15985 u8 *name = 0;
15986
15987 const char *valid_chars = "a-zA-Z0-9_";
15988
15989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
15990 {
15991 if (unformat (i, "%U", unformat_token, valid_chars, &name))
15992 vec_add1 (name, 0);
15993 else
15994 {
15995 errmsg ("parse error '%U'", format_unformat_error, i);
15996 return -99;
15997 }
15998 }
15999
16000 if (!vec_len (name))
16001 {
16002 errmsg ("profile name must be specified");
16003 return -99;
16004 }
16005
16006 if (vec_len (name) > 64)
16007 {
16008 errmsg ("profile name too long");
16009 return -99;
16010 }
16011
16012 M (IKEV2_INITIATE_SA_INIT, mp);
16013
16014 clib_memcpy (mp->name, name, vec_len (name));
16015 vec_free (name);
16016
16017 S (mp);
16018 W (ret);
16019 return ret;
16020}
16021
16022static int
16023api_ikev2_initiate_del_ike_sa (vat_main_t * vam)
16024{
16025 unformat_input_t *i = vam->input;
16026 vl_api_ikev2_initiate_del_ike_sa_t *mp;
16027 int ret;
16028 u64 ispi;
16029
16030
16031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16032 {
16033 if (unformat (i, "%lx", &ispi))
16034 ;
16035 else
16036 {
16037 errmsg ("parse error '%U'", format_unformat_error, i);
16038 return -99;
16039 }
16040 }
16041
16042 M (IKEV2_INITIATE_DEL_IKE_SA, mp);
16043
16044 mp->ispi = ispi;
16045
16046 S (mp);
16047 W (ret);
16048 return ret;
16049}
16050
16051static int
16052api_ikev2_initiate_del_child_sa (vat_main_t * vam)
16053{
16054 unformat_input_t *i = vam->input;
16055 vl_api_ikev2_initiate_del_child_sa_t *mp;
16056 int ret;
16057 u32 ispi;
16058
16059
16060 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16061 {
16062 if (unformat (i, "%x", &ispi))
16063 ;
16064 else
16065 {
16066 errmsg ("parse error '%U'", format_unformat_error, i);
16067 return -99;
16068 }
16069 }
16070
16071 M (IKEV2_INITIATE_DEL_CHILD_SA, mp);
16072
16073 mp->ispi = ispi;
16074
16075 S (mp);
16076 W (ret);
16077 return ret;
16078}
16079
16080static int
16081api_ikev2_initiate_rekey_child_sa (vat_main_t * vam)
16082{
16083 unformat_input_t *i = vam->input;
16084 vl_api_ikev2_initiate_rekey_child_sa_t *mp;
16085 int ret;
16086 u32 ispi;
16087
16088
16089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16090 {
16091 if (unformat (i, "%x", &ispi))
16092 ;
16093 else
16094 {
16095 errmsg ("parse error '%U'", format_unformat_error, i);
16096 return -99;
16097 }
16098 }
16099
16100 M (IKEV2_INITIATE_REKEY_CHILD_SA, mp);
16101
16102 mp->ispi = ispi;
16103
16104 S (mp);
16105 W (ret);
16106 return ret;
16107}
16108
Damjan Marion7cd468a2016-12-19 23:05:39 +010016109static int
16110api_get_first_msg_id (vat_main_t * vam)
16111{
16112 vl_api_get_first_msg_id_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016113 unformat_input_t *i = vam->input;
16114 u8 *name;
16115 u8 name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016116 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016117
16118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
16119 {
16120 if (unformat (i, "client %s", &name))
16121 name_set = 1;
16122 else
16123 break;
16124 }
16125
16126 if (name_set == 0)
16127 {
16128 errmsg ("missing client name");
16129 return -99;
16130 }
16131 vec_add1 (name, 0);
16132
16133 if (vec_len (name) > 63)
16134 {
16135 errmsg ("client name too long");
16136 return -99;
16137 }
16138
Jon Loeliger8a2aea32017-01-31 13:19:40 -060016139 M (GET_FIRST_MSG_ID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016140 clib_memcpy (mp->name, name, vec_len (name));
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016141 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060016142 W (ret);
16143 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016144}
16145
16146static int
16147api_cop_interface_enable_disable (vat_main_t * vam)
16148{
16149 unformat_input_t *line_input = vam->input;
16150 vl_api_cop_interface_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016151 u32 sw_if_index = ~0;
16152 u8 enable_disable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016153 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016154
16155 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
16156 {
16157 if (unformat (line_input, "disable"))
16158 enable_disable = 0;
16159 if (unformat (line_input, "enable"))
16160 enable_disable = 1;
16161 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
16162 vam, &sw_if_index))
16163 ;
16164 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
16165 ;
16166 else
16167 break;
16168 }
16169
16170 if (sw_if_index == ~0)
16171 {
16172 errmsg ("missing interface name or sw_if_index");
16173 return -99;
16174 }
16175
16176 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060016177 M (COP_INTERFACE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016178 mp->sw_if_index = ntohl (sw_if_index);
16179 mp->enable_disable = enable_disable;
16180
16181 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016182 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016183 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016184 W (ret);
16185 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016186}
16187
16188static int
16189api_cop_whitelist_enable_disable (vat_main_t * vam)
16190{
16191 unformat_input_t *line_input = vam->input;
16192 vl_api_cop_whitelist_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016193 u32 sw_if_index = ~0;
16194 u8 ip4 = 0, ip6 = 0, default_cop = 0;
16195 u32 fib_id = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016196 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016197
16198 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
16199 {
16200 if (unformat (line_input, "ip4"))
16201 ip4 = 1;
16202 else if (unformat (line_input, "ip6"))
16203 ip6 = 1;
16204 else if (unformat (line_input, "default"))
16205 default_cop = 1;
16206 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
16207 vam, &sw_if_index))
16208 ;
16209 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
16210 ;
16211 else if (unformat (line_input, "fib-id %d", &fib_id))
16212 ;
16213 else
16214 break;
16215 }
16216
16217 if (sw_if_index == ~0)
16218 {
16219 errmsg ("missing interface name or sw_if_index");
16220 return -99;
16221 }
16222
16223 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060016224 M (COP_WHITELIST_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016225 mp->sw_if_index = ntohl (sw_if_index);
16226 mp->fib_id = ntohl (fib_id);
16227 mp->ip4 = ip4;
16228 mp->ip6 = ip6;
16229 mp->default_cop = default_cop;
16230
16231 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016232 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016233 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016234 W (ret);
16235 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016236}
16237
16238static int
16239api_get_node_graph (vat_main_t * vam)
16240{
16241 vl_api_get_node_graph_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016242 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016243
Jon Loeliger8a2aea32017-01-31 13:19:40 -060016244 M (GET_NODE_GRAPH, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016245
16246 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016247 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016248 /* Wait for the reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016249 W (ret);
16250 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016251}
16252
16253/* *INDENT-OFF* */
16254/** Used for parsing LISP eids */
16255typedef CLIB_PACKED(struct{
16256 u8 addr[16]; /**< eid address */
16257 u32 len; /**< prefix length if IP */
16258 u8 type; /**< type of eid */
16259}) lisp_eid_vat_t;
16260/* *INDENT-ON* */
16261
16262static uword
16263unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
16264{
16265 lisp_eid_vat_t *a = va_arg (*args, lisp_eid_vat_t *);
16266
Dave Barachb7b92992018-10-17 10:38:51 -040016267 clib_memset (a, 0, sizeof (a[0]));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016268
16269 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len))
16270 {
16271 a->type = 0; /* ipv4 type */
16272 }
16273 else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr, &a->len))
16274 {
16275 a->type = 1; /* ipv6 type */
16276 }
16277 else if (unformat (input, "%U", unformat_ethernet_address, a->addr))
16278 {
16279 a->type = 2; /* mac type */
16280 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016281 else if (unformat (input, "%U", unformat_nsh_address, a->addr))
16282 {
16283 a->type = 3; /* NSH type */
16284 lisp_nsh_api_t *nsh = (lisp_nsh_api_t *) a->addr;
16285 nsh->spi = clib_host_to_net_u32 (nsh->spi);
16286 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010016287 else
16288 {
16289 return 0;
16290 }
16291
16292 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128))
16293 {
16294 return 0;
16295 }
16296
16297 return 1;
16298}
16299
16300static int
16301lisp_eid_size_vat (u8 type)
16302{
16303 switch (type)
16304 {
16305 case 0:
16306 return 4;
16307 case 1:
16308 return 16;
16309 case 2:
16310 return 6;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020016311 case 3:
16312 return 5;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016313 }
16314 return 0;
16315}
16316
16317static void
16318lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
16319{
16320 clib_memcpy (dst, eid, lisp_eid_size_vat (type));
16321}
16322
Damjan Marion7cd468a2016-12-19 23:05:39 +010016323static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016324api_one_add_del_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016325{
16326 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016327 vl_api_one_add_del_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016328 u8 is_add = 1;
16329 u8 *locator_set_name = NULL;
16330 u8 locator_set_name_set = 0;
Filip Tehlar05a057b2017-02-01 08:50:31 +010016331 vl_api_local_locator_t locator, *locators = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016332 u32 sw_if_index, priority, weight;
16333 u32 data_len = 0;
16334
Jon Loeliger56c7b012017-02-01 12:31:41 -060016335 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016336 /* Parse args required to build the message */
16337 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16338 {
16339 if (unformat (input, "del"))
16340 {
16341 is_add = 0;
16342 }
16343 else if (unformat (input, "locator-set %s", &locator_set_name))
16344 {
16345 locator_set_name_set = 1;
16346 }
16347 else if (unformat (input, "sw_if_index %u p %u w %u",
16348 &sw_if_index, &priority, &weight))
16349 {
16350 locator.sw_if_index = htonl (sw_if_index);
16351 locator.priority = priority;
16352 locator.weight = weight;
16353 vec_add1 (locators, locator);
16354 }
16355 else
16356 if (unformat
16357 (input, "iface %U p %u w %u", api_unformat_sw_if_index, vam,
16358 &sw_if_index, &priority, &weight))
16359 {
16360 locator.sw_if_index = htonl (sw_if_index);
16361 locator.priority = priority;
16362 locator.weight = weight;
16363 vec_add1 (locators, locator);
16364 }
16365 else
16366 break;
16367 }
16368
16369 if (locator_set_name_set == 0)
16370 {
16371 errmsg ("missing locator-set name");
16372 vec_free (locators);
16373 return -99;
16374 }
16375
16376 if (vec_len (locator_set_name) > 64)
16377 {
16378 errmsg ("locator-set name too long");
16379 vec_free (locator_set_name);
16380 vec_free (locators);
16381 return -99;
16382 }
16383 vec_add1 (locator_set_name, 0);
16384
Filip Tehlar05a057b2017-02-01 08:50:31 +010016385 data_len = sizeof (vl_api_local_locator_t) * vec_len (locators);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016386
16387 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010016388 M2 (ONE_ADD_DEL_LOCATOR_SET, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016389
16390 mp->is_add = is_add;
16391 clib_memcpy (mp->locator_set_name, locator_set_name,
16392 vec_len (locator_set_name));
16393 vec_free (locator_set_name);
16394
16395 mp->locator_num = clib_host_to_net_u32 (vec_len (locators));
16396 if (locators)
16397 clib_memcpy (mp->locators, locators, data_len);
16398 vec_free (locators);
16399
16400 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016401 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016402
16403 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016404 W (ret);
16405 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016406}
16407
Filip Tehlar694396d2017-02-17 14:29:11 +010016408#define api_lisp_add_del_locator_set api_one_add_del_locator_set
16409
Damjan Marion7cd468a2016-12-19 23:05:39 +010016410static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016411api_one_add_del_locator (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016412{
16413 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016414 vl_api_one_add_del_locator_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016415 u32 tmp_if_index = ~0;
16416 u32 sw_if_index = ~0;
16417 u8 sw_if_index_set = 0;
16418 u8 sw_if_index_if_name_set = 0;
16419 u32 priority = ~0;
16420 u8 priority_set = 0;
16421 u32 weight = ~0;
16422 u8 weight_set = 0;
16423 u8 is_add = 1;
16424 u8 *locator_set_name = NULL;
16425 u8 locator_set_name_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016426 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016427
16428 /* Parse args required to build the message */
16429 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16430 {
16431 if (unformat (input, "del"))
16432 {
16433 is_add = 0;
16434 }
16435 else if (unformat (input, "locator-set %s", &locator_set_name))
16436 {
16437 locator_set_name_set = 1;
16438 }
16439 else if (unformat (input, "iface %U", api_unformat_sw_if_index, vam,
16440 &tmp_if_index))
16441 {
16442 sw_if_index_if_name_set = 1;
16443 sw_if_index = tmp_if_index;
16444 }
16445 else if (unformat (input, "sw_if_index %d", &tmp_if_index))
16446 {
16447 sw_if_index_set = 1;
16448 sw_if_index = tmp_if_index;
16449 }
16450 else if (unformat (input, "p %d", &priority))
16451 {
16452 priority_set = 1;
16453 }
16454 else if (unformat (input, "w %d", &weight))
16455 {
16456 weight_set = 1;
16457 }
16458 else
16459 break;
16460 }
16461
16462 if (locator_set_name_set == 0)
16463 {
16464 errmsg ("missing locator-set name");
16465 return -99;
16466 }
16467
16468 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0)
16469 {
16470 errmsg ("missing sw_if_index");
16471 vec_free (locator_set_name);
16472 return -99;
16473 }
16474
16475 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0)
16476 {
16477 errmsg ("cannot use both params interface name and sw_if_index");
16478 vec_free (locator_set_name);
16479 return -99;
16480 }
16481
16482 if (priority_set == 0)
16483 {
16484 errmsg ("missing locator-set priority");
16485 vec_free (locator_set_name);
16486 return -99;
16487 }
16488
16489 if (weight_set == 0)
16490 {
16491 errmsg ("missing locator-set weight");
16492 vec_free (locator_set_name);
16493 return -99;
16494 }
16495
16496 if (vec_len (locator_set_name) > 64)
16497 {
16498 errmsg ("locator-set name too long");
16499 vec_free (locator_set_name);
16500 return -99;
16501 }
16502 vec_add1 (locator_set_name, 0);
16503
16504 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010016505 M (ONE_ADD_DEL_LOCATOR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016506
16507 mp->is_add = is_add;
16508 mp->sw_if_index = ntohl (sw_if_index);
16509 mp->priority = priority;
16510 mp->weight = weight;
16511 clib_memcpy (mp->locator_set_name, locator_set_name,
16512 vec_len (locator_set_name));
16513 vec_free (locator_set_name);
16514
16515 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016516 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016517
16518 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016519 W (ret);
16520 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016521}
16522
Filip Tehlar694396d2017-02-17 14:29:11 +010016523#define api_lisp_add_del_locator api_one_add_del_locator
16524
Damjan Marion7cd468a2016-12-19 23:05:39 +010016525uword
16526unformat_hmac_key_id (unformat_input_t * input, va_list * args)
16527{
16528 u32 *key_id = va_arg (*args, u32 *);
16529 u8 *s = 0;
16530
16531 if (unformat (input, "%s", &s))
16532 {
16533 if (!strcmp ((char *) s, "sha1"))
16534 key_id[0] = HMAC_SHA_1_96;
16535 else if (!strcmp ((char *) s, "sha256"))
16536 key_id[0] = HMAC_SHA_256_128;
16537 else
16538 {
16539 clib_warning ("invalid key_id: '%s'", s);
16540 key_id[0] = HMAC_NO_KEY;
16541 }
16542 }
16543 else
16544 return 0;
16545
16546 vec_free (s);
16547 return 1;
16548}
16549
16550static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016551api_one_add_del_local_eid (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016552{
16553 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016554 vl_api_one_add_del_local_eid_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016555 u8 is_add = 1;
16556 u8 eid_set = 0;
16557 lisp_eid_vat_t _eid, *eid = &_eid;
16558 u8 *locator_set_name = 0;
16559 u8 locator_set_name_set = 0;
16560 u32 vni = 0;
16561 u16 key_id = 0;
16562 u8 *key = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016563 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016564
16565 /* Parse args required to build the message */
16566 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16567 {
16568 if (unformat (input, "del"))
16569 {
16570 is_add = 0;
16571 }
16572 else if (unformat (input, "vni %d", &vni))
16573 {
16574 ;
16575 }
16576 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
16577 {
16578 eid_set = 1;
16579 }
16580 else if (unformat (input, "locator-set %s", &locator_set_name))
16581 {
16582 locator_set_name_set = 1;
16583 }
16584 else if (unformat (input, "key-id %U", unformat_hmac_key_id, &key_id))
16585 ;
16586 else if (unformat (input, "secret-key %_%v%_", &key))
16587 ;
16588 else
16589 break;
16590 }
16591
16592 if (locator_set_name_set == 0)
16593 {
16594 errmsg ("missing locator-set name");
16595 return -99;
16596 }
16597
16598 if (0 == eid_set)
16599 {
16600 errmsg ("EID address not set!");
16601 vec_free (locator_set_name);
16602 return -99;
16603 }
16604
16605 if (key && (0 == key_id))
16606 {
16607 errmsg ("invalid key_id!");
16608 return -99;
16609 }
16610
16611 if (vec_len (key) > 64)
16612 {
16613 errmsg ("key too long");
16614 vec_free (key);
16615 return -99;
16616 }
16617
16618 if (vec_len (locator_set_name) > 64)
16619 {
16620 errmsg ("locator-set name too long");
16621 vec_free (locator_set_name);
16622 return -99;
16623 }
16624 vec_add1 (locator_set_name, 0);
16625
16626 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010016627 M (ONE_ADD_DEL_LOCAL_EID, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016628
16629 mp->is_add = is_add;
16630 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
16631 mp->eid_type = eid->type;
16632 mp->prefix_len = eid->len;
16633 mp->vni = clib_host_to_net_u32 (vni);
16634 mp->key_id = clib_host_to_net_u16 (key_id);
16635 clib_memcpy (mp->locator_set_name, locator_set_name,
16636 vec_len (locator_set_name));
16637 clib_memcpy (mp->key, key, vec_len (key));
16638
16639 vec_free (locator_set_name);
16640 vec_free (key);
16641
16642 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016643 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016644
16645 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016646 W (ret);
16647 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016648}
16649
Filip Tehlar694396d2017-02-17 14:29:11 +010016650#define api_lisp_add_del_local_eid api_one_add_del_local_eid
Damjan Marion7cd468a2016-12-19 23:05:39 +010016651
16652static int
16653api_lisp_gpe_add_del_fwd_entry (vat_main_t * vam)
16654{
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016655 u32 dp_table = 0, vni = 0;;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016656 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010016657 vl_api_gpe_add_del_fwd_entry_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016658 u8 is_add = 1;
16659 lisp_eid_vat_t _rmt_eid, *rmt_eid = &_rmt_eid;
16660 lisp_eid_vat_t _lcl_eid, *lcl_eid = &_lcl_eid;
16661 u8 rmt_eid_set = 0, lcl_eid_set = 0;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016662 u32 action = ~0, w;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016663 ip4_address_t rmt_rloc4, lcl_rloc4;
16664 ip6_address_t rmt_rloc6, lcl_rloc6;
Filip Tehlar82786c42017-02-20 15:20:37 +010016665 vl_api_gpe_locator_t *rmt_locs = 0, *lcl_locs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016666 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016667
Dave Barachb7b92992018-10-17 10:38:51 -040016668 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016669
16670 /* Parse args required to build the message */
16671 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16672 {
16673 if (unformat (input, "del"))
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016674 is_add = 0;
16675 else if (unformat (input, "add"))
16676 is_add = 1;
16677 else if (unformat (input, "reid %U", unformat_lisp_eid_vat, rmt_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016678 {
16679 rmt_eid_set = 1;
16680 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016681 else if (unformat (input, "leid %U", unformat_lisp_eid_vat, lcl_eid))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016682 {
16683 lcl_eid_set = 1;
16684 }
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016685 else if (unformat (input, "vrf %d", &dp_table))
16686 ;
16687 else if (unformat (input, "bd %d", &dp_table))
16688 ;
16689 else if (unformat (input, "vni %d", &vni))
16690 ;
16691 else if (unformat (input, "w %d", &w))
Damjan Marion7cd468a2016-12-19 23:05:39 +010016692 {
16693 if (!curr_rloc)
16694 {
16695 errmsg ("No RLOC configured for setting priority/weight!");
16696 return -99;
16697 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010016698 curr_rloc->weight = w;
16699 }
16700 else if (unformat (input, "loc-pair %U %U", unformat_ip4_address,
16701 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4))
16702 {
16703 rloc.is_ip4 = 1;
16704
16705 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016706 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016707 vec_add1 (lcl_locs, rloc);
16708
16709 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
16710 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016711 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010016712 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
16713 }
16714 else if (unformat (input, "loc-pair %U %U", unformat_ip6_address,
16715 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6))
16716 {
16717 rloc.is_ip4 = 0;
16718 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016719 rloc.weight = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016720 vec_add1 (lcl_locs, rloc);
16721
16722 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
16723 vec_add1 (rmt_locs, rloc);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016724 /* weight saved in rmt loc */
Damjan Marion7cd468a2016-12-19 23:05:39 +010016725 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
16726 }
16727 else if (unformat (input, "action %d", &action))
16728 {
16729 ;
16730 }
16731 else
16732 {
16733 clib_warning ("parse error '%U'", format_unformat_error, input);
16734 return -99;
16735 }
16736 }
16737
16738 if (!rmt_eid_set)
16739 {
16740 errmsg ("remote eid addresses not set");
16741 return -99;
16742 }
16743
16744 if (lcl_eid_set && rmt_eid->type != lcl_eid->type)
16745 {
16746 errmsg ("eid types don't match");
16747 return -99;
16748 }
16749
16750 if (0 == rmt_locs && (u32) ~ 0 == action)
16751 {
16752 errmsg ("action not set for negative mapping");
16753 return -99;
16754 }
16755
16756 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010016757 M2 (GPE_ADD_DEL_FWD_ENTRY, mp,
16758 sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs) * 2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016759
16760 mp->is_add = is_add;
16761 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
16762 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
16763 mp->eid_type = rmt_eid->type;
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016764 mp->dp_table = clib_host_to_net_u32 (dp_table);
16765 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016766 mp->rmt_len = rmt_eid->len;
16767 mp->lcl_len = lcl_eid->len;
16768 mp->action = action;
16769
16770 if (0 != rmt_locs && 0 != lcl_locs)
16771 {
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016772 mp->loc_num = clib_host_to_net_u32 (vec_len (rmt_locs) * 2);
16773 clib_memcpy (mp->locs, lcl_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010016774 (sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs)));
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016775
Filip Tehlar82786c42017-02-20 15:20:37 +010016776 u32 offset = sizeof (vl_api_gpe_locator_t) * vec_len (lcl_locs);
Filip Tehlarc3af7bf2017-01-13 14:13:09 +010016777 clib_memcpy (((u8 *) mp->locs) + offset, rmt_locs,
Filip Tehlar82786c42017-02-20 15:20:37 +010016778 (sizeof (vl_api_gpe_locator_t) * vec_len (rmt_locs)));
Damjan Marion7cd468a2016-12-19 23:05:39 +010016779 }
16780 vec_free (lcl_locs);
16781 vec_free (rmt_locs);
16782
16783 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016784 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016785
16786 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016787 W (ret);
16788 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016789}
16790
16791static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016792api_one_add_del_map_server (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016793{
16794 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016795 vl_api_one_add_del_map_server_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016796 u8 is_add = 1;
16797 u8 ipv4_set = 0;
16798 u8 ipv6_set = 0;
16799 ip4_address_t ipv4;
16800 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016801 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016802
16803 /* Parse args required to build the message */
16804 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16805 {
16806 if (unformat (input, "del"))
16807 {
16808 is_add = 0;
16809 }
16810 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
16811 {
16812 ipv4_set = 1;
16813 }
16814 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
16815 {
16816 ipv6_set = 1;
16817 }
16818 else
16819 break;
16820 }
16821
16822 if (ipv4_set && ipv6_set)
16823 {
16824 errmsg ("both eid v4 and v6 addresses set");
16825 return -99;
16826 }
16827
16828 if (!ipv4_set && !ipv6_set)
16829 {
16830 errmsg ("eid addresses not set");
16831 return -99;
16832 }
16833
16834 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010016835 M (ONE_ADD_DEL_MAP_SERVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016836
16837 mp->is_add = is_add;
16838 if (ipv6_set)
16839 {
16840 mp->is_ipv6 = 1;
16841 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
16842 }
16843 else
16844 {
16845 mp->is_ipv6 = 0;
16846 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
16847 }
16848
16849 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016850 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016851
16852 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016853 W (ret);
16854 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016855}
16856
Filip Tehlar694396d2017-02-17 14:29:11 +010016857#define api_lisp_add_del_map_server api_one_add_del_map_server
16858
Damjan Marion7cd468a2016-12-19 23:05:39 +010016859static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016860api_one_add_del_map_resolver (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016861{
16862 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016863 vl_api_one_add_del_map_resolver_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016864 u8 is_add = 1;
16865 u8 ipv4_set = 0;
16866 u8 ipv6_set = 0;
16867 ip4_address_t ipv4;
16868 ip6_address_t ipv6;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016869 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016870
16871 /* Parse args required to build the message */
16872 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16873 {
16874 if (unformat (input, "del"))
16875 {
16876 is_add = 0;
16877 }
16878 else if (unformat (input, "%U", unformat_ip4_address, &ipv4))
16879 {
16880 ipv4_set = 1;
16881 }
16882 else if (unformat (input, "%U", unformat_ip6_address, &ipv6))
16883 {
16884 ipv6_set = 1;
16885 }
16886 else
16887 break;
16888 }
16889
16890 if (ipv4_set && ipv6_set)
16891 {
16892 errmsg ("both eid v4 and v6 addresses set");
16893 return -99;
16894 }
16895
16896 if (!ipv4_set && !ipv6_set)
16897 {
16898 errmsg ("eid addresses not set");
16899 return -99;
16900 }
16901
16902 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010016903 M (ONE_ADD_DEL_MAP_RESOLVER, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016904
16905 mp->is_add = is_add;
16906 if (ipv6_set)
16907 {
16908 mp->is_ipv6 = 1;
16909 clib_memcpy (mp->ip_address, &ipv6, sizeof (ipv6));
16910 }
16911 else
16912 {
16913 mp->is_ipv6 = 0;
16914 clib_memcpy (mp->ip_address, &ipv4, sizeof (ipv4));
16915 }
16916
16917 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016918 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016919
16920 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016921 W (ret);
16922 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016923}
16924
Filip Tehlar694396d2017-02-17 14:29:11 +010016925#define api_lisp_add_del_map_resolver api_one_add_del_map_resolver
16926
Damjan Marion7cd468a2016-12-19 23:05:39 +010016927static int
16928api_lisp_gpe_enable_disable (vat_main_t * vam)
16929{
16930 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010016931 vl_api_gpe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016932 u8 is_set = 0;
16933 u8 is_en = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016934 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016935
16936 /* Parse args required to build the message */
16937 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16938 {
16939 if (unformat (input, "enable"))
16940 {
16941 is_set = 1;
16942 is_en = 1;
16943 }
16944 else if (unformat (input, "disable"))
16945 {
16946 is_set = 1;
16947 is_en = 0;
16948 }
16949 else
16950 break;
16951 }
16952
16953 if (is_set == 0)
16954 {
16955 errmsg ("Value not set");
16956 return -99;
16957 }
16958
16959 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010016960 M (GPE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016961
16962 mp->is_en = is_en;
16963
16964 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060016965 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010016966
16967 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060016968 W (ret);
16969 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016970}
16971
16972static int
Filip Tehlar694396d2017-02-17 14:29:11 +010016973api_one_rloc_probe_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010016974{
16975 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010016976 vl_api_one_rloc_probe_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016977 u8 is_set = 0;
16978 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060016979 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010016980
16981 /* Parse args required to build the message */
16982 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
16983 {
16984 if (unformat (input, "enable"))
16985 {
16986 is_set = 1;
16987 is_en = 1;
16988 }
16989 else if (unformat (input, "disable"))
16990 is_set = 1;
16991 else
16992 break;
16993 }
16994
16995 if (!is_set)
16996 {
16997 errmsg ("Value not set");
16998 return -99;
16999 }
17000
17001 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010017002 M (ONE_RLOC_PROBE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017003
17004 mp->is_enabled = is_en;
17005
17006 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017007 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017008
17009 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017010 W (ret);
17011 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017012}
17013
Filip Tehlar694396d2017-02-17 14:29:11 +010017014#define api_lisp_rloc_probe_enable_disable api_one_rloc_probe_enable_disable
17015
Damjan Marion7cd468a2016-12-19 23:05:39 +010017016static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017017api_one_map_register_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017018{
17019 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017020 vl_api_one_map_register_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017021 u8 is_set = 0;
17022 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017023 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017024
17025 /* Parse args required to build the message */
17026 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17027 {
17028 if (unformat (input, "enable"))
17029 {
17030 is_set = 1;
17031 is_en = 1;
17032 }
17033 else if (unformat (input, "disable"))
17034 is_set = 1;
17035 else
17036 break;
17037 }
17038
17039 if (!is_set)
17040 {
17041 errmsg ("Value not set");
17042 return -99;
17043 }
17044
17045 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010017046 M (ONE_MAP_REGISTER_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017047
17048 mp->is_enabled = is_en;
17049
17050 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017051 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017052
17053 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017054 W (ret);
17055 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017056}
17057
Filip Tehlar694396d2017-02-17 14:29:11 +010017058#define api_lisp_map_register_enable_disable api_one_map_register_enable_disable
17059
Damjan Marion7cd468a2016-12-19 23:05:39 +010017060static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017061api_one_enable_disable (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017062{
17063 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017064 vl_api_one_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017065 u8 is_set = 0;
17066 u8 is_en = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017067 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017068
17069 /* Parse args required to build the message */
17070 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17071 {
17072 if (unformat (input, "enable"))
17073 {
17074 is_set = 1;
17075 is_en = 1;
17076 }
17077 else if (unformat (input, "disable"))
17078 {
17079 is_set = 1;
17080 }
17081 else
17082 break;
17083 }
17084
17085 if (!is_set)
17086 {
17087 errmsg ("Value not set");
17088 return -99;
17089 }
17090
17091 /* Construct the API message */
Filip Tehlar694396d2017-02-17 14:29:11 +010017092 M (ONE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017093
17094 mp->is_en = is_en;
17095
17096 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017097 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017098
17099 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017100 W (ret);
17101 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017102}
17103
Filip Tehlar694396d2017-02-17 14:29:11 +010017104#define api_lisp_enable_disable api_one_enable_disable
17105
Damjan Marion7cd468a2016-12-19 23:05:39 +010017106static int
Filip Tehlar0a8840d2017-10-16 05:48:23 -070017107api_one_enable_disable_xtr_mode (vat_main_t * vam)
17108{
17109 unformat_input_t *input = vam->input;
17110 vl_api_one_enable_disable_xtr_mode_t *mp;
17111 u8 is_set = 0;
17112 u8 is_en = 0;
17113 int ret;
17114
17115 /* Parse args required to build the message */
17116 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17117 {
17118 if (unformat (input, "enable"))
17119 {
17120 is_set = 1;
17121 is_en = 1;
17122 }
17123 else if (unformat (input, "disable"))
17124 {
17125 is_set = 1;
17126 }
17127 else
17128 break;
17129 }
17130
17131 if (!is_set)
17132 {
17133 errmsg ("Value not set");
17134 return -99;
17135 }
17136
17137 /* Construct the API message */
17138 M (ONE_ENABLE_DISABLE_XTR_MODE, mp);
17139
17140 mp->is_en = is_en;
17141
17142 /* send it... */
17143 S (mp);
17144
17145 /* Wait for a reply... */
17146 W (ret);
17147 return ret;
17148}
17149
17150static int
17151api_one_show_xtr_mode (vat_main_t * vam)
17152{
17153 vl_api_one_show_xtr_mode_t *mp;
17154 int ret;
17155
17156 /* Construct the API message */
17157 M (ONE_SHOW_XTR_MODE, mp);
17158
17159 /* send it... */
17160 S (mp);
17161
17162 /* Wait for a reply... */
17163 W (ret);
17164 return ret;
17165}
17166
17167static int
17168api_one_enable_disable_pitr_mode (vat_main_t * vam)
17169{
17170 unformat_input_t *input = vam->input;
17171 vl_api_one_enable_disable_pitr_mode_t *mp;
17172 u8 is_set = 0;
17173 u8 is_en = 0;
17174 int ret;
17175
17176 /* Parse args required to build the message */
17177 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17178 {
17179 if (unformat (input, "enable"))
17180 {
17181 is_set = 1;
17182 is_en = 1;
17183 }
17184 else if (unformat (input, "disable"))
17185 {
17186 is_set = 1;
17187 }
17188 else
17189 break;
17190 }
17191
17192 if (!is_set)
17193 {
17194 errmsg ("Value not set");
17195 return -99;
17196 }
17197
17198 /* Construct the API message */
17199 M (ONE_ENABLE_DISABLE_PITR_MODE, mp);
17200
17201 mp->is_en = is_en;
17202
17203 /* send it... */
17204 S (mp);
17205
17206 /* Wait for a reply... */
17207 W (ret);
17208 return ret;
17209}
17210
17211static int
17212api_one_show_pitr_mode (vat_main_t * vam)
17213{
17214 vl_api_one_show_pitr_mode_t *mp;
17215 int ret;
17216
17217 /* Construct the API message */
17218 M (ONE_SHOW_PITR_MODE, mp);
17219
17220 /* send it... */
17221 S (mp);
17222
17223 /* Wait for a reply... */
17224 W (ret);
17225 return ret;
17226}
17227
17228static int
17229api_one_enable_disable_petr_mode (vat_main_t * vam)
17230{
17231 unformat_input_t *input = vam->input;
17232 vl_api_one_enable_disable_petr_mode_t *mp;
17233 u8 is_set = 0;
17234 u8 is_en = 0;
17235 int ret;
17236
17237 /* Parse args required to build the message */
17238 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17239 {
17240 if (unformat (input, "enable"))
17241 {
17242 is_set = 1;
17243 is_en = 1;
17244 }
17245 else if (unformat (input, "disable"))
17246 {
17247 is_set = 1;
17248 }
17249 else
17250 break;
17251 }
17252
17253 if (!is_set)
17254 {
17255 errmsg ("Value not set");
17256 return -99;
17257 }
17258
17259 /* Construct the API message */
17260 M (ONE_ENABLE_DISABLE_PETR_MODE, mp);
17261
17262 mp->is_en = is_en;
17263
17264 /* send it... */
17265 S (mp);
17266
17267 /* Wait for a reply... */
17268 W (ret);
17269 return ret;
17270}
17271
17272static int
17273api_one_show_petr_mode (vat_main_t * vam)
17274{
17275 vl_api_one_show_petr_mode_t *mp;
17276 int ret;
17277
17278 /* Construct the API message */
17279 M (ONE_SHOW_PETR_MODE, mp);
17280
17281 /* send it... */
17282 S (mp);
17283
17284 /* Wait for a reply... */
17285 W (ret);
17286 return ret;
17287}
17288
17289static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017290api_show_one_map_register_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017291{
Filip Tehlar694396d2017-02-17 14:29:11 +010017292 vl_api_show_one_map_register_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017293 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017294
Filip Tehlar694396d2017-02-17 14:29:11 +010017295 M (SHOW_ONE_MAP_REGISTER_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017296
17297 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017298 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017299
17300 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017301 W (ret);
17302 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017303}
17304
Filip Tehlar694396d2017-02-17 14:29:11 +010017305#define api_show_lisp_map_register_state api_show_one_map_register_state
17306
Damjan Marion7cd468a2016-12-19 23:05:39 +010017307static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017308api_show_one_rloc_probe_state (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017309{
Filip Tehlar694396d2017-02-17 14:29:11 +010017310 vl_api_show_one_rloc_probe_state_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017311 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017312
Filip Tehlar694396d2017-02-17 14:29:11 +010017313 M (SHOW_ONE_RLOC_PROBE_STATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017314
17315 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017316 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017317
17318 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017319 W (ret);
17320 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017321}
17322
Filip Tehlar694396d2017-02-17 14:29:11 +010017323#define api_show_lisp_rloc_probe_state api_show_one_rloc_probe_state
17324
Damjan Marion7cd468a2016-12-19 23:05:39 +010017325static int
Filip Tehlar05879992017-09-05 15:46:09 +020017326api_one_add_del_ndp_entry (vat_main_t * vam)
17327{
17328 vl_api_one_add_del_ndp_entry_t *mp;
17329 unformat_input_t *input = vam->input;
17330 u8 is_add = 1;
17331 u8 mac_set = 0;
17332 u8 bd_set = 0;
17333 u8 ip_set = 0;
17334 u8 mac[6] = { 0, };
17335 u8 ip6[16] = { 0, };
17336 u32 bd = ~0;
17337 int ret;
17338
17339 /* Parse args required to build the message */
17340 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17341 {
17342 if (unformat (input, "del"))
17343 is_add = 0;
17344 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
17345 mac_set = 1;
17346 else if (unformat (input, "ip %U", unformat_ip6_address, ip6))
17347 ip_set = 1;
17348 else if (unformat (input, "bd %d", &bd))
17349 bd_set = 1;
17350 else
17351 {
17352 errmsg ("parse error '%U'", format_unformat_error, input);
17353 return -99;
17354 }
17355 }
17356
17357 if (!bd_set || !ip_set || (!mac_set && is_add))
17358 {
17359 errmsg ("Missing BD, IP or MAC!");
17360 return -99;
17361 }
17362
17363 M (ONE_ADD_DEL_NDP_ENTRY, mp);
17364 mp->is_add = is_add;
17365 clib_memcpy (mp->mac, mac, 6);
17366 mp->bd = clib_host_to_net_u32 (bd);
17367 clib_memcpy (mp->ip6, ip6, sizeof (mp->ip6));
17368
17369 /* send */
17370 S (mp);
17371
17372 /* wait for reply */
17373 W (ret);
17374 return ret;
17375}
17376
17377static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020017378api_one_add_del_l2_arp_entry (vat_main_t * vam)
17379{
17380 vl_api_one_add_del_l2_arp_entry_t *mp;
17381 unformat_input_t *input = vam->input;
17382 u8 is_add = 1;
17383 u8 mac_set = 0;
17384 u8 bd_set = 0;
17385 u8 ip_set = 0;
17386 u8 mac[6] = { 0, };
17387 u32 ip4 = 0, bd = ~0;
17388 int ret;
17389
17390 /* Parse args required to build the message */
17391 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17392 {
17393 if (unformat (input, "del"))
17394 is_add = 0;
17395 else if (unformat (input, "mac %U", unformat_ethernet_address, mac))
17396 mac_set = 1;
17397 else if (unformat (input, "ip %U", unformat_ip4_address, &ip4))
17398 ip_set = 1;
17399 else if (unformat (input, "bd %d", &bd))
17400 bd_set = 1;
17401 else
17402 {
17403 errmsg ("parse error '%U'", format_unformat_error, input);
17404 return -99;
17405 }
17406 }
17407
17408 if (!bd_set || !ip_set || (!mac_set && is_add))
17409 {
17410 errmsg ("Missing BD, IP or MAC!");
17411 return -99;
17412 }
17413
17414 M (ONE_ADD_DEL_L2_ARP_ENTRY, mp);
17415 mp->is_add = is_add;
17416 clib_memcpy (mp->mac, mac, 6);
17417 mp->bd = clib_host_to_net_u32 (bd);
17418 mp->ip4 = ip4;
17419
17420 /* send */
17421 S (mp);
17422
17423 /* wait for reply */
17424 W (ret);
17425 return ret;
17426}
17427
17428static int
Filip Tehlar05879992017-09-05 15:46:09 +020017429api_one_ndp_bd_get (vat_main_t * vam)
17430{
17431 vl_api_one_ndp_bd_get_t *mp;
17432 int ret;
17433
17434 M (ONE_NDP_BD_GET, mp);
17435
17436 /* send */
17437 S (mp);
17438
17439 /* wait for reply */
17440 W (ret);
17441 return ret;
17442}
17443
17444static int
17445api_one_ndp_entries_get (vat_main_t * vam)
17446{
17447 vl_api_one_ndp_entries_get_t *mp;
17448 unformat_input_t *input = vam->input;
17449 u8 bd_set = 0;
17450 u32 bd = ~0;
17451 int ret;
17452
17453 /* Parse args required to build the message */
17454 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17455 {
17456 if (unformat (input, "bd %d", &bd))
17457 bd_set = 1;
17458 else
17459 {
17460 errmsg ("parse error '%U'", format_unformat_error, input);
17461 return -99;
17462 }
17463 }
17464
17465 if (!bd_set)
17466 {
17467 errmsg ("Expected bridge domain!");
17468 return -99;
17469 }
17470
17471 M (ONE_NDP_ENTRIES_GET, mp);
17472 mp->bd = clib_host_to_net_u32 (bd);
17473
17474 /* send */
17475 S (mp);
17476
17477 /* wait for reply */
17478 W (ret);
17479 return ret;
17480}
17481
17482static int
Filip Tehlard5a65db2017-05-17 17:21:10 +020017483api_one_l2_arp_bd_get (vat_main_t * vam)
17484{
17485 vl_api_one_l2_arp_bd_get_t *mp;
17486 int ret;
17487
17488 M (ONE_L2_ARP_BD_GET, mp);
17489
17490 /* send */
17491 S (mp);
17492
17493 /* wait for reply */
17494 W (ret);
17495 return ret;
17496}
17497
17498static int
17499api_one_l2_arp_entries_get (vat_main_t * vam)
17500{
17501 vl_api_one_l2_arp_entries_get_t *mp;
17502 unformat_input_t *input = vam->input;
17503 u8 bd_set = 0;
17504 u32 bd = ~0;
17505 int ret;
17506
17507 /* Parse args required to build the message */
17508 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17509 {
17510 if (unformat (input, "bd %d", &bd))
17511 bd_set = 1;
17512 else
17513 {
17514 errmsg ("parse error '%U'", format_unformat_error, input);
17515 return -99;
17516 }
17517 }
17518
17519 if (!bd_set)
17520 {
17521 errmsg ("Expected bridge domain!");
17522 return -99;
17523 }
17524
17525 M (ONE_L2_ARP_ENTRIES_GET, mp);
17526 mp->bd = clib_host_to_net_u32 (bd);
17527
17528 /* send */
17529 S (mp);
17530
17531 /* wait for reply */
17532 W (ret);
17533 return ret;
17534}
17535
17536static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010017537api_one_stats_enable_disable (vat_main_t * vam)
17538{
17539 vl_api_one_stats_enable_disable_t *mp;
17540 unformat_input_t *input = vam->input;
17541 u8 is_set = 0;
17542 u8 is_en = 0;
17543 int ret;
17544
17545 /* Parse args required to build the message */
17546 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17547 {
17548 if (unformat (input, "enable"))
17549 {
17550 is_set = 1;
17551 is_en = 1;
17552 }
17553 else if (unformat (input, "disable"))
17554 {
17555 is_set = 1;
17556 }
17557 else
17558 break;
17559 }
17560
17561 if (!is_set)
17562 {
17563 errmsg ("Value not set");
17564 return -99;
17565 }
17566
17567 M (ONE_STATS_ENABLE_DISABLE, mp);
17568 mp->is_en = is_en;
17569
17570 /* send */
17571 S (mp);
17572
17573 /* wait for reply */
17574 W (ret);
17575 return ret;
17576}
17577
17578static int
17579api_show_one_stats_enable_disable (vat_main_t * vam)
17580{
17581 vl_api_show_one_stats_enable_disable_t *mp;
17582 int ret;
17583
17584 M (SHOW_ONE_STATS_ENABLE_DISABLE, mp);
17585
17586 /* send */
17587 S (mp);
17588
17589 /* wait for reply */
17590 W (ret);
17591 return ret;
17592}
17593
17594static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017595api_show_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017596{
Filip Tehlar694396d2017-02-17 14:29:11 +010017597 vl_api_show_one_map_request_mode_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017598 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017599
Filip Tehlar694396d2017-02-17 14:29:11 +010017600 M (SHOW_ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017601
17602 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017603 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017604
17605 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017606 W (ret);
17607 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017608}
17609
Filip Tehlar694396d2017-02-17 14:29:11 +010017610#define api_show_lisp_map_request_mode api_show_one_map_request_mode
17611
Damjan Marion7cd468a2016-12-19 23:05:39 +010017612static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017613api_one_map_request_mode (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017614{
Damjan Marion7cd468a2016-12-19 23:05:39 +010017615 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017616 vl_api_one_map_request_mode_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017617 u8 mode = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017618 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017619
17620 /* Parse args required to build the message */
17621 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17622 {
17623 if (unformat (input, "dst-only"))
17624 mode = 0;
17625 else if (unformat (input, "src-dst"))
17626 mode = 1;
17627 else
17628 {
17629 errmsg ("parse error '%U'", format_unformat_error, input);
17630 return -99;
17631 }
17632 }
17633
Filip Tehlar694396d2017-02-17 14:29:11 +010017634 M (ONE_MAP_REQUEST_MODE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017635
17636 mp->mode = mode;
17637
17638 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017639 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017640
17641 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017642 W (ret);
17643 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017644}
17645
Filip Tehlar694396d2017-02-17 14:29:11 +010017646#define api_lisp_map_request_mode api_one_map_request_mode
17647
Damjan Marion7cd468a2016-12-19 23:05:39 +010017648/**
Filip Tehlar694396d2017-02-17 14:29:11 +010017649 * Enable/disable ONE proxy ITR.
Damjan Marion7cd468a2016-12-19 23:05:39 +010017650 *
17651 * @param vam vpp API test context
17652 * @return return code
17653 */
17654static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017655api_one_pitr_set_locator_set (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017656{
Damjan Marion7cd468a2016-12-19 23:05:39 +010017657 u8 ls_name_set = 0;
17658 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017659 vl_api_one_pitr_set_locator_set_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017660 u8 is_add = 1;
17661 u8 *ls_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017662 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017663
17664 /* Parse args required to build the message */
17665 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17666 {
17667 if (unformat (input, "del"))
17668 is_add = 0;
17669 else if (unformat (input, "locator-set %s", &ls_name))
17670 ls_name_set = 1;
17671 else
17672 {
17673 errmsg ("parse error '%U'", format_unformat_error, input);
17674 return -99;
17675 }
17676 }
17677
17678 if (!ls_name_set)
17679 {
17680 errmsg ("locator-set name not set!");
17681 return -99;
17682 }
17683
Filip Tehlar694396d2017-02-17 14:29:11 +010017684 M (ONE_PITR_SET_LOCATOR_SET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017685
17686 mp->is_add = is_add;
17687 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
17688 vec_free (ls_name);
17689
17690 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017691 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017692
17693 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017694 W (ret);
17695 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017696}
17697
Filip Tehlar694396d2017-02-17 14:29:11 +010017698#define api_lisp_pitr_set_locator_set api_one_pitr_set_locator_set
17699
Damjan Marion7cd468a2016-12-19 23:05:39 +010017700static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017701api_one_nsh_set_locator_set (vat_main_t * vam)
17702{
17703 u8 ls_name_set = 0;
17704 unformat_input_t *input = vam->input;
17705 vl_api_one_nsh_set_locator_set_t *mp;
17706 u8 is_add = 1;
17707 u8 *ls_name = 0;
17708 int ret;
17709
17710 /* Parse args required to build the message */
17711 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17712 {
17713 if (unformat (input, "del"))
17714 is_add = 0;
17715 else if (unformat (input, "ls %s", &ls_name))
17716 ls_name_set = 1;
17717 else
17718 {
17719 errmsg ("parse error '%U'", format_unformat_error, input);
17720 return -99;
17721 }
17722 }
17723
17724 if (!ls_name_set && is_add)
17725 {
17726 errmsg ("locator-set name not set!");
17727 return -99;
17728 }
17729
17730 M (ONE_NSH_SET_LOCATOR_SET, mp);
17731
17732 mp->is_add = is_add;
17733 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
17734 vec_free (ls_name);
17735
17736 /* send */
17737 S (mp);
17738
17739 /* wait for reply */
17740 W (ret);
17741 return ret;
17742}
17743
17744static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017745api_show_one_pitr (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017746{
Filip Tehlar694396d2017-02-17 14:29:11 +010017747 vl_api_show_one_pitr_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017748 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017749
17750 if (!vam->json_output)
17751 {
17752 print (vam->ofp, "%=20s", "lisp status:");
17753 }
17754
Filip Tehlar694396d2017-02-17 14:29:11 +010017755 M (SHOW_ONE_PITR, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017756 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017757 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017758
17759 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017760 W (ret);
17761 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017762}
17763
Filip Tehlar694396d2017-02-17 14:29:11 +010017764#define api_show_lisp_pitr api_show_one_pitr
17765
Filip Tehlar67a99f82017-03-10 13:18:02 +010017766static int
17767api_one_use_petr (vat_main_t * vam)
17768{
17769 unformat_input_t *input = vam->input;
17770 vl_api_one_use_petr_t *mp;
17771 u8 is_add = 0;
17772 ip_address_t ip;
17773 int ret;
17774
Dave Barachb7b92992018-10-17 10:38:51 -040017775 clib_memset (&ip, 0, sizeof (ip));
Filip Tehlar67a99f82017-03-10 13:18:02 +010017776
17777 /* Parse args required to build the message */
17778 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17779 {
17780 if (unformat (input, "disable"))
17781 is_add = 0;
17782 else
17783 if (unformat (input, "%U", unformat_ip4_address, &ip_addr_v4 (&ip)))
17784 {
17785 is_add = 1;
17786 ip_addr_version (&ip) = IP4;
17787 }
17788 else
17789 if (unformat (input, "%U", unformat_ip6_address, &ip_addr_v6 (&ip)))
17790 {
17791 is_add = 1;
17792 ip_addr_version (&ip) = IP6;
17793 }
17794 else
17795 {
17796 errmsg ("parse error '%U'", format_unformat_error, input);
17797 return -99;
17798 }
17799 }
17800
17801 M (ONE_USE_PETR, mp);
17802
17803 mp->is_add = is_add;
17804 if (is_add)
17805 {
17806 mp->is_ip4 = ip_addr_version (&ip) == IP4 ? 1 : 0;
17807 if (mp->is_ip4)
17808 clib_memcpy (mp->address, &ip, 4);
17809 else
17810 clib_memcpy (mp->address, &ip, 16);
17811 }
17812
17813 /* send */
17814 S (mp);
17815
17816 /* wait for reply */
17817 W (ret);
17818 return ret;
17819}
17820
17821#define api_lisp_use_petr api_one_use_petr
17822
17823static int
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020017824api_show_one_nsh_mapping (vat_main_t * vam)
17825{
17826 vl_api_show_one_use_petr_t *mp;
17827 int ret;
17828
17829 if (!vam->json_output)
17830 {
17831 print (vam->ofp, "%=20s", "local ONE NSH mapping:");
17832 }
17833
17834 M (SHOW_ONE_NSH_MAPPING, mp);
17835 /* send it... */
17836 S (mp);
17837
17838 /* Wait for a reply... */
17839 W (ret);
17840 return ret;
17841}
17842
17843static int
Filip Tehlar67a99f82017-03-10 13:18:02 +010017844api_show_one_use_petr (vat_main_t * vam)
17845{
17846 vl_api_show_one_use_petr_t *mp;
17847 int ret;
17848
17849 if (!vam->json_output)
17850 {
17851 print (vam->ofp, "%=20s", "Proxy-ETR status:");
17852 }
17853
17854 M (SHOW_ONE_USE_PETR, mp);
17855 /* send it... */
17856 S (mp);
17857
17858 /* Wait for a reply... */
17859 W (ret);
17860 return ret;
17861}
17862
17863#define api_show_lisp_use_petr api_show_one_use_petr
17864
Damjan Marion7cd468a2016-12-19 23:05:39 +010017865/**
17866 * Add/delete mapping between vni and vrf
17867 */
17868static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017869api_one_eid_table_add_del_map (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017870{
Damjan Marion7cd468a2016-12-19 23:05:39 +010017871 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017872 vl_api_one_eid_table_add_del_map_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017873 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
17874 u32 vni, vrf, bd_index;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017875 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017876
17877 /* Parse args required to build the message */
17878 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17879 {
17880 if (unformat (input, "del"))
17881 is_add = 0;
17882 else if (unformat (input, "vrf %d", &vrf))
17883 vrf_set = 1;
17884 else if (unformat (input, "bd_index %d", &bd_index))
17885 bd_index_set = 1;
17886 else if (unformat (input, "vni %d", &vni))
17887 vni_set = 1;
17888 else
17889 break;
17890 }
17891
17892 if (!vni_set || (!vrf_set && !bd_index_set))
17893 {
17894 errmsg ("missing arguments!");
17895 return -99;
17896 }
17897
17898 if (vrf_set && bd_index_set)
17899 {
17900 errmsg ("error: both vrf and bd entered!");
17901 return -99;
17902 }
17903
Filip Tehlar694396d2017-02-17 14:29:11 +010017904 M (ONE_EID_TABLE_ADD_DEL_MAP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017905
17906 mp->is_add = is_add;
17907 mp->vni = htonl (vni);
17908 mp->dp_table = vrf_set ? htonl (vrf) : htonl (bd_index);
17909 mp->is_l2 = bd_index_set;
17910
17911 /* send */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060017912 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010017913
17914 /* wait for reply */
Jon Loeliger56c7b012017-02-01 12:31:41 -060017915 W (ret);
17916 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017917}
17918
Filip Tehlar694396d2017-02-17 14:29:11 +010017919#define api_lisp_eid_table_add_del_map api_one_eid_table_add_del_map
17920
Damjan Marion7cd468a2016-12-19 23:05:39 +010017921uword
17922unformat_negative_mapping_action (unformat_input_t * input, va_list * args)
17923{
17924 u32 *action = va_arg (*args, u32 *);
17925 u8 *s = 0;
17926
17927 if (unformat (input, "%s", &s))
17928 {
17929 if (!strcmp ((char *) s, "no-action"))
17930 action[0] = 0;
17931 else if (!strcmp ((char *) s, "natively-forward"))
17932 action[0] = 1;
17933 else if (!strcmp ((char *) s, "send-map-request"))
17934 action[0] = 2;
17935 else if (!strcmp ((char *) s, "drop"))
17936 action[0] = 3;
17937 else
17938 {
17939 clib_warning ("invalid action: '%s'", s);
17940 action[0] = 3;
17941 }
17942 }
17943 else
17944 return 0;
17945
17946 vec_free (s);
17947 return 1;
17948}
17949
17950/**
Filip Tehlar694396d2017-02-17 14:29:11 +010017951 * Add/del remote mapping to/from ONE control plane
Damjan Marion7cd468a2016-12-19 23:05:39 +010017952 *
17953 * @param vam vpp API test context
17954 * @return return code
17955 */
17956static int
Filip Tehlar694396d2017-02-17 14:29:11 +010017957api_one_add_del_remote_mapping (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010017958{
17959 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010017960 vl_api_one_add_del_remote_mapping_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017961 u32 vni = 0;
17962 lisp_eid_vat_t _eid, *eid = &_eid;
17963 lisp_eid_vat_t _seid, *seid = &_seid;
17964 u8 is_add = 1, del_all = 0, eid_set = 0, seid_set = 0;
17965 u32 action = ~0, p, w, data_len;
17966 ip4_address_t rloc4;
17967 ip6_address_t rloc6;
Filip Tehlar05a057b2017-02-01 08:50:31 +010017968 vl_api_remote_locator_t *rlocs = 0, rloc, *curr_rloc = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060017969 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010017970
Dave Barachb7b92992018-10-17 10:38:51 -040017971 clib_memset (&rloc, 0, sizeof (rloc));
Damjan Marion7cd468a2016-12-19 23:05:39 +010017972
17973 /* Parse args required to build the message */
17974 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
17975 {
17976 if (unformat (input, "del-all"))
17977 {
17978 del_all = 1;
17979 }
17980 else if (unformat (input, "del"))
17981 {
17982 is_add = 0;
17983 }
17984 else if (unformat (input, "add"))
17985 {
17986 is_add = 1;
17987 }
17988 else if (unformat (input, "eid %U", unformat_lisp_eid_vat, eid))
17989 {
17990 eid_set = 1;
17991 }
17992 else if (unformat (input, "seid %U", unformat_lisp_eid_vat, seid))
17993 {
17994 seid_set = 1;
17995 }
17996 else if (unformat (input, "vni %d", &vni))
17997 {
17998 ;
17999 }
18000 else if (unformat (input, "p %d w %d", &p, &w))
18001 {
18002 if (!curr_rloc)
18003 {
18004 errmsg ("No RLOC configured for setting priority/weight!");
18005 return -99;
18006 }
18007 curr_rloc->priority = p;
18008 curr_rloc->weight = w;
18009 }
18010 else if (unformat (input, "rloc %U", unformat_ip4_address, &rloc4))
18011 {
18012 rloc.is_ip4 = 1;
18013 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
18014 vec_add1 (rlocs, rloc);
18015 curr_rloc = &rlocs[vec_len (rlocs) - 1];
18016 }
18017 else if (unformat (input, "rloc %U", unformat_ip6_address, &rloc6))
18018 {
18019 rloc.is_ip4 = 0;
18020 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
18021 vec_add1 (rlocs, rloc);
18022 curr_rloc = &rlocs[vec_len (rlocs) - 1];
18023 }
18024 else if (unformat (input, "action %U",
18025 unformat_negative_mapping_action, &action))
18026 {
18027 ;
18028 }
18029 else
18030 {
18031 clib_warning ("parse error '%U'", format_unformat_error, input);
18032 return -99;
18033 }
18034 }
18035
18036 if (0 == eid_set)
18037 {
18038 errmsg ("missing params!");
18039 return -99;
18040 }
18041
18042 if (is_add && (~0 == action) && 0 == vec_len (rlocs))
18043 {
18044 errmsg ("no action set for negative map-reply!");
18045 return -99;
18046 }
18047
Filip Tehlar05a057b2017-02-01 08:50:31 +010018048 data_len = vec_len (rlocs) * sizeof (vl_api_remote_locator_t);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018049
Filip Tehlar694396d2017-02-17 14:29:11 +010018050 M2 (ONE_ADD_DEL_REMOTE_MAPPING, mp, data_len);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018051 mp->is_add = is_add;
18052 mp->vni = htonl (vni);
18053 mp->action = (u8) action;
18054 mp->is_src_dst = seid_set;
18055 mp->eid_len = eid->len;
18056 mp->seid_len = seid->len;
18057 mp->del_all = del_all;
18058 mp->eid_type = eid->type;
18059 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
18060 lisp_eid_put_vat (mp->seid, seid->addr, seid->type);
18061
18062 mp->rloc_num = clib_host_to_net_u32 (vec_len (rlocs));
18063 clib_memcpy (mp->rlocs, rlocs, data_len);
18064 vec_free (rlocs);
18065
18066 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018067 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018068
18069 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018070 W (ret);
18071 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018072}
18073
Filip Tehlar694396d2017-02-17 14:29:11 +010018074#define api_lisp_add_del_remote_mapping api_one_add_del_remote_mapping
18075
Damjan Marion7cd468a2016-12-19 23:05:39 +010018076/**
Filip Tehlar694396d2017-02-17 14:29:11 +010018077 * Add/del ONE adjacency. Saves mapping in ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010018078 * forwarding entries in data-plane accordingly.
18079 *
18080 * @param vam vpp API test context
18081 * @return return code
18082 */
18083static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018084api_one_add_del_adjacency (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018085{
18086 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018087 vl_api_one_add_del_adjacency_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018088 u32 vni = 0;
18089 ip4_address_t leid4, reid4;
18090 ip6_address_t leid6, reid6;
18091 u8 reid_mac[6] = { 0 };
18092 u8 leid_mac[6] = { 0 };
18093 u8 reid_type, leid_type;
18094 u32 leid_len = 0, reid_len = 0, len;
18095 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018096 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018097
18098 leid_type = reid_type = (u8) ~ 0;
18099
18100 /* Parse args required to build the message */
18101 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18102 {
18103 if (unformat (input, "del"))
18104 {
18105 is_add = 0;
18106 }
18107 else if (unformat (input, "add"))
18108 {
18109 is_add = 1;
18110 }
18111 else if (unformat (input, "reid %U/%d", unformat_ip4_address,
18112 &reid4, &len))
18113 {
18114 reid_type = 0; /* ipv4 */
18115 reid_len = len;
18116 }
18117 else if (unformat (input, "reid %U/%d", unformat_ip6_address,
18118 &reid6, &len))
18119 {
18120 reid_type = 1; /* ipv6 */
18121 reid_len = len;
18122 }
18123 else if (unformat (input, "reid %U", unformat_ethernet_address,
18124 reid_mac))
18125 {
18126 reid_type = 2; /* mac */
18127 }
18128 else if (unformat (input, "leid %U/%d", unformat_ip4_address,
18129 &leid4, &len))
18130 {
18131 leid_type = 0; /* ipv4 */
18132 leid_len = len;
18133 }
18134 else if (unformat (input, "leid %U/%d", unformat_ip6_address,
18135 &leid6, &len))
18136 {
18137 leid_type = 1; /* ipv6 */
18138 leid_len = len;
18139 }
18140 else if (unformat (input, "leid %U", unformat_ethernet_address,
18141 leid_mac))
18142 {
18143 leid_type = 2; /* mac */
18144 }
18145 else if (unformat (input, "vni %d", &vni))
18146 {
18147 ;
18148 }
18149 else
18150 {
18151 errmsg ("parse error '%U'", format_unformat_error, input);
18152 return -99;
18153 }
18154 }
18155
18156 if ((u8) ~ 0 == reid_type)
18157 {
18158 errmsg ("missing params!");
18159 return -99;
18160 }
18161
18162 if (leid_type != reid_type)
18163 {
18164 errmsg ("remote and local EIDs are of different types!");
18165 return -99;
18166 }
18167
Filip Tehlar694396d2017-02-17 14:29:11 +010018168 M (ONE_ADD_DEL_ADJACENCY, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018169 mp->is_add = is_add;
18170 mp->vni = htonl (vni);
18171 mp->leid_len = leid_len;
18172 mp->reid_len = reid_len;
18173 mp->eid_type = reid_type;
18174
18175 switch (mp->eid_type)
18176 {
18177 case 0:
18178 clib_memcpy (mp->leid, &leid4, sizeof (leid4));
18179 clib_memcpy (mp->reid, &reid4, sizeof (reid4));
18180 break;
18181 case 1:
18182 clib_memcpy (mp->leid, &leid6, sizeof (leid6));
18183 clib_memcpy (mp->reid, &reid6, sizeof (reid6));
18184 break;
18185 case 2:
18186 clib_memcpy (mp->leid, leid_mac, 6);
18187 clib_memcpy (mp->reid, reid_mac, 6);
18188 break;
18189 default:
18190 errmsg ("unknown EID type %d!", mp->eid_type);
18191 return 0;
18192 }
18193
18194 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018195 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018196
18197 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018198 W (ret);
18199 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018200}
18201
Filip Tehlar694396d2017-02-17 14:29:11 +010018202#define api_lisp_add_del_adjacency api_one_add_del_adjacency
18203
Filip Tehlar3e7b56932017-02-21 18:28:34 +010018204uword
18205unformat_gpe_encap_mode (unformat_input_t * input, va_list * args)
18206{
18207 u32 *mode = va_arg (*args, u32 *);
18208
18209 if (unformat (input, "lisp"))
18210 *mode = 0;
18211 else if (unformat (input, "vxlan"))
18212 *mode = 1;
18213 else
18214 return 0;
18215
18216 return 1;
18217}
18218
18219static int
18220api_gpe_get_encap_mode (vat_main_t * vam)
18221{
18222 vl_api_gpe_get_encap_mode_t *mp;
18223 int ret;
18224
18225 /* Construct the API message */
18226 M (GPE_GET_ENCAP_MODE, mp);
18227
18228 /* send it... */
18229 S (mp);
18230
18231 /* Wait for a reply... */
18232 W (ret);
18233 return ret;
18234}
18235
18236static int
18237api_gpe_set_encap_mode (vat_main_t * vam)
18238{
18239 unformat_input_t *input = vam->input;
18240 vl_api_gpe_set_encap_mode_t *mp;
18241 int ret;
18242 u32 mode = 0;
18243
18244 /* Parse args required to build the message */
18245 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18246 {
18247 if (unformat (input, "%U", unformat_gpe_encap_mode, &mode))
18248 ;
18249 else
18250 break;
18251 }
18252
18253 /* Construct the API message */
18254 M (GPE_SET_ENCAP_MODE, mp);
18255
18256 mp->mode = mode;
18257
18258 /* send it... */
18259 S (mp);
18260
18261 /* Wait for a reply... */
18262 W (ret);
18263 return ret;
18264}
18265
Damjan Marion7cd468a2016-12-19 23:05:39 +010018266static int
18267api_lisp_gpe_add_del_iface (vat_main_t * vam)
18268{
18269 unformat_input_t *input = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010018270 vl_api_gpe_add_del_iface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018271 u8 action_set = 0, is_add = 1, is_l2 = 0, dp_table_set = 0, vni_set = 0;
18272 u32 dp_table = 0, vni = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018273 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018274
18275 /* Parse args required to build the message */
18276 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18277 {
18278 if (unformat (input, "up"))
18279 {
18280 action_set = 1;
18281 is_add = 1;
18282 }
18283 else if (unformat (input, "down"))
18284 {
18285 action_set = 1;
18286 is_add = 0;
18287 }
18288 else if (unformat (input, "table_id %d", &dp_table))
18289 {
18290 dp_table_set = 1;
18291 }
18292 else if (unformat (input, "bd_id %d", &dp_table))
18293 {
18294 dp_table_set = 1;
18295 is_l2 = 1;
18296 }
18297 else if (unformat (input, "vni %d", &vni))
18298 {
18299 vni_set = 1;
18300 }
18301 else
18302 break;
18303 }
18304
18305 if (action_set == 0)
18306 {
18307 errmsg ("Action not set");
18308 return -99;
18309 }
18310 if (dp_table_set == 0 || vni_set == 0)
18311 {
18312 errmsg ("vni and dp_table must be set");
18313 return -99;
18314 }
18315
18316 /* Construct the API message */
Filip Tehlar82786c42017-02-20 15:20:37 +010018317 M (GPE_ADD_DEL_IFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018318
18319 mp->is_add = is_add;
Florin Corasf53a8ad2017-06-15 15:07:32 -070018320 mp->dp_table = clib_host_to_net_u32 (dp_table);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018321 mp->is_l2 = is_l2;
Florin Corasf53a8ad2017-06-15 15:07:32 -070018322 mp->vni = clib_host_to_net_u32 (vni);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018323
18324 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018325 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018326
18327 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018328 W (ret);
18329 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018330}
18331
Filip Tehlar1e553a02017-08-02 12:45:07 +020018332static int
Filip Tehlar7048ff12017-07-27 08:09:14 +020018333api_one_map_register_fallback_threshold (vat_main_t * vam)
18334{
18335 unformat_input_t *input = vam->input;
18336 vl_api_one_map_register_fallback_threshold_t *mp;
18337 u32 value = 0;
18338 u8 is_set = 0;
18339 int ret;
18340
18341 /* Parse args required to build the message */
18342 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18343 {
18344 if (unformat (input, "%u", &value))
18345 is_set = 1;
18346 else
18347 {
18348 clib_warning ("parse error '%U'", format_unformat_error, input);
18349 return -99;
18350 }
18351 }
18352
18353 if (!is_set)
18354 {
18355 errmsg ("fallback threshold value is missing!");
18356 return -99;
18357 }
18358
18359 M (ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
18360 mp->value = clib_host_to_net_u32 (value);
18361
18362 /* send it... */
18363 S (mp);
18364
18365 /* Wait for a reply... */
18366 W (ret);
18367 return ret;
18368}
18369
18370static int
18371api_show_one_map_register_fallback_threshold (vat_main_t * vam)
18372{
18373 vl_api_show_one_map_register_fallback_threshold_t *mp;
18374 int ret;
18375
18376 M (SHOW_ONE_MAP_REGISTER_FALLBACK_THRESHOLD, mp);
18377
18378 /* send it... */
18379 S (mp);
18380
18381 /* Wait for a reply... */
18382 W (ret);
18383 return ret;
18384}
18385
Filip Tehlara4980b82017-09-27 14:32:02 +020018386uword
18387unformat_lisp_transport_protocol (unformat_input_t * input, va_list * args)
18388{
18389 u32 *proto = va_arg (*args, u32 *);
18390
18391 if (unformat (input, "udp"))
18392 *proto = 1;
18393 else if (unformat (input, "api"))
18394 *proto = 2;
18395 else
18396 return 0;
18397
18398 return 1;
18399}
18400
18401static int
18402api_one_set_transport_protocol (vat_main_t * vam)
18403{
18404 unformat_input_t *input = vam->input;
18405 vl_api_one_set_transport_protocol_t *mp;
18406 u8 is_set = 0;
18407 u32 protocol = 0;
18408 int ret;
18409
18410 /* Parse args required to build the message */
18411 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18412 {
18413 if (unformat (input, "%U", unformat_lisp_transport_protocol, &protocol))
18414 is_set = 1;
18415 else
18416 {
18417 clib_warning ("parse error '%U'", format_unformat_error, input);
18418 return -99;
18419 }
18420 }
18421
18422 if (!is_set)
18423 {
18424 errmsg ("Transport protocol missing!");
18425 return -99;
18426 }
18427
18428 M (ONE_SET_TRANSPORT_PROTOCOL, mp);
18429 mp->protocol = (u8) protocol;
18430
18431 /* send it... */
18432 S (mp);
18433
18434 /* Wait for a reply... */
18435 W (ret);
18436 return ret;
18437}
18438
18439static int
18440api_one_get_transport_protocol (vat_main_t * vam)
18441{
18442 vl_api_one_get_transport_protocol_t *mp;
18443 int ret;
18444
18445 M (ONE_GET_TRANSPORT_PROTOCOL, mp);
18446
18447 /* send it... */
18448 S (mp);
18449
18450 /* Wait for a reply... */
18451 W (ret);
18452 return ret;
18453}
18454
Filip Tehlar7048ff12017-07-27 08:09:14 +020018455static int
Filip Tehlar1e553a02017-08-02 12:45:07 +020018456api_one_map_register_set_ttl (vat_main_t * vam)
18457{
18458 unformat_input_t *input = vam->input;
18459 vl_api_one_map_register_set_ttl_t *mp;
18460 u32 ttl = 0;
18461 u8 is_set = 0;
18462 int ret;
18463
18464 /* Parse args required to build the message */
18465 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18466 {
18467 if (unformat (input, "%u", &ttl))
18468 is_set = 1;
18469 else
18470 {
18471 clib_warning ("parse error '%U'", format_unformat_error, input);
18472 return -99;
18473 }
18474 }
18475
18476 if (!is_set)
18477 {
18478 errmsg ("TTL value missing!");
18479 return -99;
18480 }
18481
18482 M (ONE_MAP_REGISTER_SET_TTL, mp);
18483 mp->ttl = clib_host_to_net_u32 (ttl);
18484
18485 /* send it... */
18486 S (mp);
18487
18488 /* Wait for a reply... */
18489 W (ret);
18490 return ret;
18491}
18492
18493static int
18494api_show_one_map_register_ttl (vat_main_t * vam)
18495{
18496 vl_api_show_one_map_register_ttl_t *mp;
18497 int ret;
18498
18499 M (SHOW_ONE_MAP_REGISTER_TTL, mp);
18500
18501 /* send it... */
18502 S (mp);
18503
18504 /* Wait for a reply... */
18505 W (ret);
18506 return ret;
18507}
18508
Damjan Marion7cd468a2016-12-19 23:05:39 +010018509/**
Filip Tehlar694396d2017-02-17 14:29:11 +010018510 * Add/del map request itr rlocs from ONE control plane and updates
Damjan Marion7cd468a2016-12-19 23:05:39 +010018511 *
18512 * @param vam vpp API test context
18513 * @return return code
18514 */
18515static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018516api_one_add_del_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018517{
18518 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018519 vl_api_one_add_del_map_request_itr_rlocs_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018520 u8 *locator_set_name = 0;
18521 u8 locator_set_name_set = 0;
18522 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018523 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018524
18525 /* Parse args required to build the message */
18526 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18527 {
18528 if (unformat (input, "del"))
18529 {
18530 is_add = 0;
18531 }
18532 else if (unformat (input, "%_%v%_", &locator_set_name))
18533 {
18534 locator_set_name_set = 1;
18535 }
18536 else
18537 {
18538 clib_warning ("parse error '%U'", format_unformat_error, input);
18539 return -99;
18540 }
18541 }
18542
18543 if (is_add && !locator_set_name_set)
18544 {
18545 errmsg ("itr-rloc is not set!");
18546 return -99;
18547 }
18548
18549 if (is_add && vec_len (locator_set_name) > 64)
18550 {
18551 errmsg ("itr-rloc locator-set name too long");
18552 vec_free (locator_set_name);
18553 return -99;
18554 }
18555
Filip Tehlar694396d2017-02-17 14:29:11 +010018556 M (ONE_ADD_DEL_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018557 mp->is_add = is_add;
18558 if (is_add)
18559 {
18560 clib_memcpy (mp->locator_set_name, locator_set_name,
18561 vec_len (locator_set_name));
18562 }
18563 else
18564 {
Dave Barachb7b92992018-10-17 10:38:51 -040018565 clib_memset (mp->locator_set_name, 0, sizeof (mp->locator_set_name));
Damjan Marion7cd468a2016-12-19 23:05:39 +010018566 }
18567 vec_free (locator_set_name);
18568
18569 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018570 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018571
18572 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018573 W (ret);
18574 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018575}
18576
Filip Tehlar694396d2017-02-17 14:29:11 +010018577#define api_lisp_add_del_map_request_itr_rlocs api_one_add_del_map_request_itr_rlocs
18578
Damjan Marion7cd468a2016-12-19 23:05:39 +010018579static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018580api_one_locator_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018581{
18582 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018583 vl_api_one_locator_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018584 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018585 u8 is_index_set = 0, is_name_set = 0;
18586 u8 *ls_name = 0;
18587 u32 ls_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018588 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018589
18590 /* Parse args required to build the message */
18591 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18592 {
18593 if (unformat (input, "ls_name %_%v%_", &ls_name))
18594 {
18595 is_name_set = 1;
18596 }
18597 else if (unformat (input, "ls_index %d", &ls_index))
18598 {
18599 is_index_set = 1;
18600 }
18601 else
18602 {
18603 errmsg ("parse error '%U'", format_unformat_error, input);
18604 return -99;
18605 }
18606 }
18607
18608 if (!is_index_set && !is_name_set)
18609 {
18610 errmsg ("error: expected one of index or name!");
18611 return -99;
18612 }
18613
18614 if (is_index_set && is_name_set)
18615 {
18616 errmsg ("error: only one param expected!");
18617 return -99;
18618 }
18619
18620 if (vec_len (ls_name) > 62)
18621 {
18622 errmsg ("error: locator set name too long!");
18623 return -99;
18624 }
18625
18626 if (!vam->json_output)
18627 {
18628 print (vam->ofp, "%=16s%=16s%=16s", "locator", "priority", "weight");
18629 }
18630
Filip Tehlar694396d2017-02-17 14:29:11 +010018631 M (ONE_LOCATOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018632 mp->is_index_set = is_index_set;
18633
18634 if (is_index_set)
18635 mp->ls_index = clib_host_to_net_u32 (ls_index);
18636 else
18637 {
18638 vec_add1 (ls_name, 0);
18639 strncpy ((char *) mp->ls_name, (char *) ls_name,
18640 sizeof (mp->ls_name) - 1);
18641 }
18642
18643 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018644 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018645
18646 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018647 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018648 S (mp_ping);
18649
Damjan Marion7cd468a2016-12-19 23:05:39 +010018650 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018651 W (ret);
18652 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018653}
18654
Filip Tehlar694396d2017-02-17 14:29:11 +010018655#define api_lisp_locator_dump api_one_locator_dump
18656
Damjan Marion7cd468a2016-12-19 23:05:39 +010018657static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018658api_one_locator_set_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018659{
Filip Tehlar694396d2017-02-17 14:29:11 +010018660 vl_api_one_locator_set_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018661 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018662 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018663 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018664 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018665
18666 /* Parse args required to build the message */
18667 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18668 {
18669 if (unformat (input, "local"))
18670 {
18671 filter = 1;
18672 }
18673 else if (unformat (input, "remote"))
18674 {
18675 filter = 2;
18676 }
18677 else
18678 {
18679 errmsg ("parse error '%U'", format_unformat_error, input);
18680 return -99;
18681 }
18682 }
18683
18684 if (!vam->json_output)
18685 {
18686 print (vam->ofp, "%=10s%=15s", "ls_index", "ls_name");
18687 }
18688
Filip Tehlar694396d2017-02-17 14:29:11 +010018689 M (ONE_LOCATOR_SET_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018690
18691 mp->filter = filter;
18692
18693 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018694 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018695
18696 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018697 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018698 S (mp_ping);
18699
Damjan Marion7cd468a2016-12-19 23:05:39 +010018700 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018701 W (ret);
18702 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018703}
18704
Filip Tehlar694396d2017-02-17 14:29:11 +010018705#define api_lisp_locator_set_dump api_one_locator_set_dump
18706
Damjan Marion7cd468a2016-12-19 23:05:39 +010018707static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018708api_one_eid_table_map_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018709{
18710 u8 is_l2 = 0;
18711 u8 mode_set = 0;
18712 unformat_input_t *input = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018713 vl_api_one_eid_table_map_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018714 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018715 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018716
18717 /* Parse args required to build the message */
18718 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
18719 {
18720 if (unformat (input, "l2"))
18721 {
18722 is_l2 = 1;
18723 mode_set = 1;
18724 }
18725 else if (unformat (input, "l3"))
18726 {
18727 is_l2 = 0;
18728 mode_set = 1;
18729 }
18730 else
18731 {
18732 errmsg ("parse error '%U'", format_unformat_error, input);
18733 return -99;
18734 }
18735 }
18736
18737 if (!mode_set)
18738 {
18739 errmsg ("expected one of 'l2' or 'l3' parameter!");
18740 return -99;
18741 }
18742
18743 if (!vam->json_output)
18744 {
18745 print (vam->ofp, "%=10s%=10s", "VNI", is_l2 ? "BD" : "VRF");
18746 }
18747
Filip Tehlar694396d2017-02-17 14:29:11 +010018748 M (ONE_EID_TABLE_MAP_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018749 mp->is_l2 = is_l2;
18750
18751 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018752 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018753
18754 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018755 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018756 S (mp_ping);
18757
Damjan Marion7cd468a2016-12-19 23:05:39 +010018758 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018759 W (ret);
18760 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018761}
18762
Filip Tehlar694396d2017-02-17 14:29:11 +010018763#define api_lisp_eid_table_map_dump api_one_eid_table_map_dump
18764
Damjan Marion7cd468a2016-12-19 23:05:39 +010018765static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018766api_one_eid_table_vni_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018767{
Filip Tehlar694396d2017-02-17 14:29:11 +010018768 vl_api_one_eid_table_vni_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018769 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018770 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018771
18772 if (!vam->json_output)
18773 {
18774 print (vam->ofp, "VNI");
18775 }
18776
Filip Tehlar694396d2017-02-17 14:29:11 +010018777 M (ONE_EID_TABLE_VNI_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018778
18779 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018780 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018781
18782 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018783 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018784 S (mp_ping);
18785
Damjan Marion7cd468a2016-12-19 23:05:39 +010018786 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018787 W (ret);
18788 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018789}
18790
Filip Tehlar694396d2017-02-17 14:29:11 +010018791#define api_lisp_eid_table_vni_dump api_one_eid_table_vni_dump
18792
Damjan Marion7cd468a2016-12-19 23:05:39 +010018793static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018794api_one_eid_table_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018795{
18796 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018797 vl_api_one_eid_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018798 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018799 struct in_addr ip4;
18800 struct in6_addr ip6;
18801 u8 mac[6];
18802 u8 eid_type = ~0, eid_set = 0;
18803 u32 prefix_length = ~0, t, vni = 0;
18804 u8 filter = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018805 int ret;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020018806 lisp_nsh_api_t nsh;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018807
18808 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18809 {
18810 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t))
18811 {
18812 eid_set = 1;
18813 eid_type = 0;
18814 prefix_length = t;
18815 }
18816 else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t))
18817 {
18818 eid_set = 1;
18819 eid_type = 1;
18820 prefix_length = t;
18821 }
18822 else if (unformat (i, "eid %U", unformat_ethernet_address, mac))
18823 {
18824 eid_set = 1;
18825 eid_type = 2;
18826 }
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020018827 else if (unformat (i, "eid %U", unformat_nsh_address, &nsh))
18828 {
18829 eid_set = 1;
18830 eid_type = 3;
18831 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010018832 else if (unformat (i, "vni %d", &t))
18833 {
18834 vni = t;
18835 }
18836 else if (unformat (i, "local"))
18837 {
18838 filter = 1;
18839 }
18840 else if (unformat (i, "remote"))
18841 {
18842 filter = 2;
18843 }
18844 else
18845 {
18846 errmsg ("parse error '%U'", format_unformat_error, i);
18847 return -99;
18848 }
18849 }
18850
18851 if (!vam->json_output)
18852 {
18853 print (vam->ofp, "%-35s%-20s%-30s%-20s%-20s%-10s%-20s", "EID",
18854 "type", "ls_index", "ttl", "authoritative", "key_id", "key");
18855 }
18856
Filip Tehlar694396d2017-02-17 14:29:11 +010018857 M (ONE_EID_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018858
18859 mp->filter = filter;
18860 if (eid_set)
18861 {
18862 mp->eid_set = 1;
18863 mp->vni = htonl (vni);
18864 mp->eid_type = eid_type;
18865 switch (eid_type)
18866 {
18867 case 0:
18868 mp->prefix_length = prefix_length;
18869 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
18870 break;
18871 case 1:
18872 mp->prefix_length = prefix_length;
18873 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
18874 break;
18875 case 2:
18876 clib_memcpy (mp->eid, mac, sizeof (mac));
18877 break;
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020018878 case 3:
18879 clib_memcpy (mp->eid, &nsh, sizeof (nsh));
18880 break;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018881 default:
18882 errmsg ("unknown EID type %d!", eid_type);
18883 return -99;
18884 }
18885 }
18886
18887 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018888 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018889
18890 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040018891 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060018892 S (mp_ping);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018893
18894 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018895 W (ret);
18896 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018897}
18898
Filip Tehlar694396d2017-02-17 14:29:11 +010018899#define api_lisp_eid_table_dump api_one_eid_table_dump
18900
Damjan Marion7cd468a2016-12-19 23:05:39 +010018901static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018902api_lisp_gpe_fwd_entries_get (vat_main_t * vam)
18903{
18904 unformat_input_t *i = vam->input;
Filip Tehlar82786c42017-02-20 15:20:37 +010018905 vl_api_gpe_fwd_entries_get_t *mp;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018906 u8 vni_set = 0;
18907 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018908 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018909
18910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18911 {
18912 if (unformat (i, "vni %d", &vni))
18913 {
18914 vni_set = 1;
18915 }
18916 else
18917 {
18918 errmsg ("parse error '%U'", format_unformat_error, i);
18919 return -99;
18920 }
18921 }
18922
18923 if (!vni_set)
18924 {
18925 errmsg ("vni not set!");
18926 return -99;
18927 }
18928
18929 if (!vam->json_output)
18930 {
18931 print (vam->ofp, "%10s %10s %s %40s", "fwd_index", "dp_table",
18932 "leid", "reid");
18933 }
18934
Filip Tehlar82786c42017-02-20 15:20:37 +010018935 M (GPE_FWD_ENTRIES_GET, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018936 mp->vni = clib_host_to_net_u32 (vni);
18937
18938 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018939 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018940
18941 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018942 W (ret);
18943 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018944}
18945
Filip Tehlarb4243aa2017-06-14 14:39:42 +020018946#define vl_api_gpe_native_fwd_rpaths_get_reply_t_endian vl_noop_handler
18947#define vl_api_gpe_native_fwd_rpaths_get_reply_t_print vl_noop_handler
Filip Tehlar0eb874e2017-05-18 14:23:32 +020018948#define vl_api_gpe_fwd_entry_vnis_get_reply_t_endian vl_noop_handler
18949#define vl_api_gpe_fwd_entry_vnis_get_reply_t_print vl_noop_handler
Filip Tehlar82786c42017-02-20 15:20:37 +010018950#define vl_api_gpe_fwd_entries_get_reply_t_endian vl_noop_handler
18951#define vl_api_gpe_fwd_entries_get_reply_t_print vl_noop_handler
18952#define vl_api_gpe_fwd_entry_path_details_t_endian vl_noop_handler
18953#define vl_api_gpe_fwd_entry_path_details_t_print vl_noop_handler
Filip Tehlar5fae99c2017-01-18 12:57:37 +010018954
18955static int
Filip Tehlar694396d2017-02-17 14:29:11 +010018956api_one_adjacencies_get (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010018957{
18958 unformat_input_t *i = vam->input;
Filip Tehlar694396d2017-02-17 14:29:11 +010018959 vl_api_one_adjacencies_get_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018960 u8 vni_set = 0;
18961 u32 vni = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060018962 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018963
18964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
18965 {
18966 if (unformat (i, "vni %d", &vni))
18967 {
18968 vni_set = 1;
18969 }
18970 else
18971 {
18972 errmsg ("parse error '%U'", format_unformat_error, i);
18973 return -99;
18974 }
18975 }
18976
18977 if (!vni_set)
18978 {
18979 errmsg ("vni not set!");
18980 return -99;
18981 }
18982
18983 if (!vam->json_output)
18984 {
18985 print (vam->ofp, "%s %40s", "leid", "reid");
18986 }
18987
Filip Tehlar694396d2017-02-17 14:29:11 +010018988 M (ONE_ADJACENCIES_GET, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018989 mp->vni = clib_host_to_net_u32 (vni);
18990
18991 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060018992 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010018993
18994 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060018995 W (ret);
18996 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010018997}
18998
Filip Tehlar694396d2017-02-17 14:29:11 +010018999#define api_lisp_adjacencies_get api_one_adjacencies_get
19000
Damjan Marion7cd468a2016-12-19 23:05:39 +010019001static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020019002api_gpe_native_fwd_rpaths_get (vat_main_t * vam)
19003{
19004 unformat_input_t *i = vam->input;
19005 vl_api_gpe_native_fwd_rpaths_get_t *mp;
19006 int ret;
19007 u8 ip_family_set = 0, is_ip4 = 1;
19008
19009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19010 {
19011 if (unformat (i, "ip4"))
19012 {
19013 ip_family_set = 1;
19014 is_ip4 = 1;
19015 }
19016 else if (unformat (i, "ip6"))
19017 {
19018 ip_family_set = 1;
19019 is_ip4 = 0;
19020 }
19021 else
19022 {
19023 errmsg ("parse error '%U'", format_unformat_error, i);
19024 return -99;
19025 }
19026 }
19027
19028 if (!ip_family_set)
19029 {
19030 errmsg ("ip family not set!");
19031 return -99;
19032 }
19033
19034 M (GPE_NATIVE_FWD_RPATHS_GET, mp);
19035 mp->is_ip4 = is_ip4;
19036
19037 /* send it... */
19038 S (mp);
19039
19040 /* Wait for a reply... */
19041 W (ret);
19042 return ret;
19043}
19044
19045static int
Filip Tehlar0eb874e2017-05-18 14:23:32 +020019046api_gpe_fwd_entry_vnis_get (vat_main_t * vam)
19047{
19048 vl_api_gpe_fwd_entry_vnis_get_t *mp;
19049 int ret;
19050
19051 if (!vam->json_output)
19052 {
19053 print (vam->ofp, "VNIs");
19054 }
19055
19056 M (GPE_FWD_ENTRY_VNIS_GET, mp);
19057
19058 /* send it... */
19059 S (mp);
19060
19061 /* Wait for a reply... */
19062 W (ret);
19063 return ret;
19064}
19065
19066static int
Filip Tehlarb4243aa2017-06-14 14:39:42 +020019067api_gpe_add_del_native_fwd_rpath (vat_main_t * vam)
19068{
19069 unformat_input_t *i = vam->input;
19070 vl_api_gpe_add_del_native_fwd_rpath_t *mp;
19071 int ret = 0;
19072 u8 is_add = 1, ip_set = 0, is_ip4 = 1;
19073 struct in_addr ip4;
19074 struct in6_addr ip6;
19075 u32 table_id = 0, nh_sw_if_index = ~0;
19076
Dave Barachb7b92992018-10-17 10:38:51 -040019077 clib_memset (&ip4, 0, sizeof (ip4));
19078 clib_memset (&ip6, 0, sizeof (ip6));
Filip Tehlarb4243aa2017-06-14 14:39:42 +020019079
19080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19081 {
19082 if (unformat (i, "del"))
19083 is_add = 0;
19084 else if (unformat (i, "via %U %U", unformat_ip4_address, &ip4,
19085 api_unformat_sw_if_index, vam, &nh_sw_if_index))
19086 {
19087 ip_set = 1;
19088 is_ip4 = 1;
19089 }
19090 else if (unformat (i, "via %U %U", unformat_ip6_address, &ip6,
19091 api_unformat_sw_if_index, vam, &nh_sw_if_index))
19092 {
19093 ip_set = 1;
19094 is_ip4 = 0;
19095 }
19096 else if (unformat (i, "via %U", unformat_ip4_address, &ip4))
19097 {
19098 ip_set = 1;
19099 is_ip4 = 1;
19100 nh_sw_if_index = ~0;
19101 }
19102 else if (unformat (i, "via %U", unformat_ip6_address, &ip6))
19103 {
19104 ip_set = 1;
19105 is_ip4 = 0;
19106 nh_sw_if_index = ~0;
19107 }
19108 else if (unformat (i, "table %d", &table_id))
19109 ;
19110 else
19111 {
19112 errmsg ("parse error '%U'", format_unformat_error, i);
19113 return -99;
19114 }
19115 }
19116
19117 if (!ip_set)
19118 {
19119 errmsg ("nh addr not set!");
19120 return -99;
19121 }
19122
19123 M (GPE_ADD_DEL_NATIVE_FWD_RPATH, mp);
19124 mp->is_add = is_add;
19125 mp->table_id = clib_host_to_net_u32 (table_id);
19126 mp->nh_sw_if_index = clib_host_to_net_u32 (nh_sw_if_index);
19127 mp->is_ip4 = is_ip4;
19128 if (is_ip4)
19129 clib_memcpy (mp->nh_addr, &ip4, sizeof (ip4));
19130 else
19131 clib_memcpy (mp->nh_addr, &ip6, sizeof (ip6));
19132
19133 /* send it... */
19134 S (mp);
19135
19136 /* Wait for a reply... */
19137 W (ret);
19138 return ret;
19139}
19140
19141static int
Filip Tehlar694396d2017-02-17 14:29:11 +010019142api_one_map_server_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019143{
Filip Tehlar694396d2017-02-17 14:29:11 +010019144 vl_api_one_map_server_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019145 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019146 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019147
19148 if (!vam->json_output)
19149 {
19150 print (vam->ofp, "%=20s", "Map server");
19151 }
19152
Filip Tehlar694396d2017-02-17 14:29:11 +010019153 M (ONE_MAP_SERVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019154 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019155 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019156
19157 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019158 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019159 S (mp_ping);
19160
Damjan Marion7cd468a2016-12-19 23:05:39 +010019161 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019162 W (ret);
19163 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019164}
19165
Filip Tehlar694396d2017-02-17 14:29:11 +010019166#define api_lisp_map_server_dump api_one_map_server_dump
19167
Damjan Marion7cd468a2016-12-19 23:05:39 +010019168static int
Filip Tehlar694396d2017-02-17 14:29:11 +010019169api_one_map_resolver_dump (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019170{
Filip Tehlar694396d2017-02-17 14:29:11 +010019171 vl_api_one_map_resolver_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019172 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019173 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019174
19175 if (!vam->json_output)
19176 {
19177 print (vam->ofp, "%=20s", "Map resolver");
19178 }
19179
Filip Tehlar694396d2017-02-17 14:29:11 +010019180 M (ONE_MAP_RESOLVER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019181 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019182 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019183
19184 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019185 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019186 S (mp_ping);
19187
Damjan Marion7cd468a2016-12-19 23:05:39 +010019188 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019189 W (ret);
19190 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019191}
19192
Filip Tehlar694396d2017-02-17 14:29:11 +010019193#define api_lisp_map_resolver_dump api_one_map_resolver_dump
19194
Damjan Marion7cd468a2016-12-19 23:05:39 +010019195static int
Filip Tehlar21511912017-04-07 10:41:42 +020019196api_one_stats_flush (vat_main_t * vam)
19197{
19198 vl_api_one_stats_flush_t *mp;
19199 int ret = 0;
19200
19201 M (ONE_STATS_FLUSH, mp);
19202 S (mp);
19203 W (ret);
19204 return ret;
19205}
19206
19207static int
Filip Tehlar4868ff62017-03-09 16:48:39 +010019208api_one_stats_dump (vat_main_t * vam)
19209{
19210 vl_api_one_stats_dump_t *mp;
19211 vl_api_control_ping_t *mp_ping;
19212 int ret;
19213
19214 M (ONE_STATS_DUMP, mp);
19215 /* send it... */
19216 S (mp);
19217
19218 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019219 MPING (CONTROL_PING, mp_ping);
Filip Tehlar4868ff62017-03-09 16:48:39 +010019220 S (mp_ping);
19221
19222 /* Wait for a reply... */
19223 W (ret);
19224 return ret;
19225}
19226
19227static int
Filip Tehlar694396d2017-02-17 14:29:11 +010019228api_show_one_status (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019229{
Filip Tehlar694396d2017-02-17 14:29:11 +010019230 vl_api_show_one_status_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019231 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019232
19233 if (!vam->json_output)
19234 {
Filip Tehlar694396d2017-02-17 14:29:11 +010019235 print (vam->ofp, "%-20s%-16s", "ONE status", "locator-set");
Damjan Marion7cd468a2016-12-19 23:05:39 +010019236 }
19237
Filip Tehlar694396d2017-02-17 14:29:11 +010019238 M (SHOW_ONE_STATUS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019239 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019240 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019241 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019242 W (ret);
19243 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019244}
19245
Filip Tehlar694396d2017-02-17 14:29:11 +010019246#define api_show_lisp_status api_show_one_status
19247
Damjan Marion7cd468a2016-12-19 23:05:39 +010019248static int
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019249api_lisp_gpe_fwd_entry_path_dump (vat_main_t * vam)
19250{
Filip Tehlar82786c42017-02-20 15:20:37 +010019251 vl_api_gpe_fwd_entry_path_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019252 vl_api_control_ping_t *mp_ping;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019253 unformat_input_t *i = vam->input;
19254 u32 fwd_entry_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019255 int ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019256
19257 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19258 {
19259 if (unformat (i, "index %d", &fwd_entry_index))
19260 ;
19261 else
19262 break;
19263 }
19264
19265 if (~0 == fwd_entry_index)
19266 {
19267 errmsg ("no index specified!");
19268 return -99;
19269 }
19270
19271 if (!vam->json_output)
19272 {
19273 print (vam->ofp, "first line");
19274 }
19275
Filip Tehlar82786c42017-02-20 15:20:37 +010019276 M (GPE_FWD_ENTRY_PATH_DUMP, mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019277
19278 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019279 S (mp);
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019280 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019281 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019282 S (mp_ping);
19283
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019284 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019285 W (ret);
19286 return ret;
Filip Tehlar5fae99c2017-01-18 12:57:37 +010019287}
19288
19289static int
Filip Tehlar694396d2017-02-17 14:29:11 +010019290api_one_get_map_request_itr_rlocs (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019291{
Filip Tehlar694396d2017-02-17 14:29:11 +010019292 vl_api_one_get_map_request_itr_rlocs_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019293 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019294
19295 if (!vam->json_output)
19296 {
19297 print (vam->ofp, "%=20s", "itr-rlocs:");
19298 }
19299
Filip Tehlar694396d2017-02-17 14:29:11 +010019300 M (ONE_GET_MAP_REQUEST_ITR_RLOCS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019301 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019302 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019303 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019304 W (ret);
19305 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019306}
19307
Filip Tehlar694396d2017-02-17 14:29:11 +010019308#define api_lisp_get_map_request_itr_rlocs api_one_get_map_request_itr_rlocs
19309
Damjan Marion7cd468a2016-12-19 23:05:39 +010019310static int
19311api_af_packet_create (vat_main_t * vam)
19312{
19313 unformat_input_t *i = vam->input;
19314 vl_api_af_packet_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019315 u8 *host_if_name = 0;
19316 u8 hw_addr[6];
19317 u8 random_hw_addr = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019318 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019319
Dave Barachb7b92992018-10-17 10:38:51 -040019320 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019321
19322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19323 {
19324 if (unformat (i, "name %s", &host_if_name))
19325 vec_add1 (host_if_name, 0);
19326 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
19327 random_hw_addr = 0;
19328 else
19329 break;
19330 }
19331
19332 if (!vec_len (host_if_name))
19333 {
19334 errmsg ("host-interface name must be specified");
19335 return -99;
19336 }
19337
19338 if (vec_len (host_if_name) > 64)
19339 {
19340 errmsg ("host-interface name too long");
19341 return -99;
19342 }
19343
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019344 M (AF_PACKET_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019345
19346 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
19347 clib_memcpy (mp->hw_addr, hw_addr, 6);
19348 mp->use_random_hw_addr = random_hw_addr;
19349 vec_free (host_if_name);
19350
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019351 S (mp);
Dave Baracha1a093d2017-03-02 13:13:23 -050019352
19353 /* *INDENT-OFF* */
19354 W2 (ret,
19355 ({
19356 if (ret == 0)
19357 fprintf (vam->ofp ? vam->ofp : stderr,
19358 " new sw_if_index = %d\n", vam->sw_if_index);
19359 }));
19360 /* *INDENT-ON* */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019361 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019362}
19363
19364static int
19365api_af_packet_delete (vat_main_t * vam)
19366{
19367 unformat_input_t *i = vam->input;
19368 vl_api_af_packet_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019369 u8 *host_if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019370 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019371
19372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19373 {
19374 if (unformat (i, "name %s", &host_if_name))
19375 vec_add1 (host_if_name, 0);
19376 else
19377 break;
19378 }
19379
19380 if (!vec_len (host_if_name))
19381 {
19382 errmsg ("host-interface name must be specified");
19383 return -99;
19384 }
19385
19386 if (vec_len (host_if_name) > 64)
19387 {
19388 errmsg ("host-interface name too long");
19389 return -99;
19390 }
19391
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019392 M (AF_PACKET_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019393
19394 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
19395 vec_free (host_if_name);
19396
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019397 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019398 W (ret);
19399 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019400}
19401
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020019402static void vl_api_af_packet_details_t_handler
19403 (vl_api_af_packet_details_t * mp)
19404{
19405 vat_main_t *vam = &vat_main;
19406
19407 print (vam->ofp, "%-16s %d",
19408 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
19409}
19410
19411static void vl_api_af_packet_details_t_handler_json
19412 (vl_api_af_packet_details_t * mp)
19413{
19414 vat_main_t *vam = &vat_main;
19415 vat_json_node_t *node = NULL;
19416
19417 if (VAT_JSON_ARRAY != vam->json_tree.type)
19418 {
19419 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19420 vat_json_init_array (&vam->json_tree);
19421 }
19422 node = vat_json_array_add (&vam->json_tree);
19423
19424 vat_json_init_object (node);
19425 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
19426 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
19427}
19428
19429static int
19430api_af_packet_dump (vat_main_t * vam)
19431{
19432 vl_api_af_packet_dump_t *mp;
19433 vl_api_control_ping_t *mp_ping;
19434 int ret;
19435
19436 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
19437 /* Get list of tap interfaces */
19438 M (AF_PACKET_DUMP, mp);
19439 S (mp);
19440
19441 /* Use a control ping for synchronization */
19442 MPING (CONTROL_PING, mp_ping);
19443 S (mp_ping);
19444
19445 W (ret);
19446 return ret;
19447}
19448
Damjan Marion7cd468a2016-12-19 23:05:39 +010019449static int
19450api_policer_add_del (vat_main_t * vam)
19451{
19452 unformat_input_t *i = vam->input;
19453 vl_api_policer_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019454 u8 is_add = 1;
19455 u8 *name = 0;
19456 u32 cir = 0;
19457 u32 eir = 0;
19458 u64 cb = 0;
19459 u64 eb = 0;
19460 u8 rate_type = 0;
19461 u8 round_type = 0;
19462 u8 type = 0;
19463 u8 color_aware = 0;
19464 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019465 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019466
19467 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
19468 conform_action.dscp = 0;
19469 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
19470 exceed_action.dscp = 0;
19471 violate_action.action_type = SSE2_QOS_ACTION_DROP;
19472 violate_action.dscp = 0;
19473
19474 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19475 {
19476 if (unformat (i, "del"))
19477 is_add = 0;
19478 else if (unformat (i, "name %s", &name))
19479 vec_add1 (name, 0);
19480 else if (unformat (i, "cir %u", &cir))
19481 ;
19482 else if (unformat (i, "eir %u", &eir))
19483 ;
19484 else if (unformat (i, "cb %u", &cb))
19485 ;
19486 else if (unformat (i, "eb %u", &eb))
19487 ;
19488 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
19489 &rate_type))
19490 ;
19491 else if (unformat (i, "round_type %U", unformat_policer_round_type,
19492 &round_type))
19493 ;
19494 else if (unformat (i, "type %U", unformat_policer_type, &type))
19495 ;
19496 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
19497 &conform_action))
19498 ;
19499 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
19500 &exceed_action))
19501 ;
19502 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
19503 &violate_action))
19504 ;
19505 else if (unformat (i, "color-aware"))
19506 color_aware = 1;
19507 else
19508 break;
19509 }
19510
19511 if (!vec_len (name))
19512 {
19513 errmsg ("policer name must be specified");
19514 return -99;
19515 }
19516
19517 if (vec_len (name) > 64)
19518 {
19519 errmsg ("policer name too long");
19520 return -99;
19521 }
19522
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019523 M (POLICER_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019524
19525 clib_memcpy (mp->name, name, vec_len (name));
19526 vec_free (name);
19527 mp->is_add = is_add;
Neale Rannsd91c1db2017-07-31 02:30:50 -070019528 mp->cir = ntohl (cir);
19529 mp->eir = ntohl (eir);
19530 mp->cb = clib_net_to_host_u64 (cb);
19531 mp->eb = clib_net_to_host_u64 (eb);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019532 mp->rate_type = rate_type;
19533 mp->round_type = round_type;
19534 mp->type = type;
19535 mp->conform_action_type = conform_action.action_type;
19536 mp->conform_dscp = conform_action.dscp;
19537 mp->exceed_action_type = exceed_action.action_type;
19538 mp->exceed_dscp = exceed_action.dscp;
19539 mp->violate_action_type = violate_action.action_type;
19540 mp->violate_dscp = violate_action.dscp;
19541 mp->color_aware = color_aware;
19542
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019543 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019544 W (ret);
19545 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019546}
19547
19548static int
19549api_policer_dump (vat_main_t * vam)
19550{
19551 unformat_input_t *i = vam->input;
19552 vl_api_policer_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019553 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019554 u8 *match_name = 0;
19555 u8 match_name_valid = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019556 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019557
19558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19559 {
19560 if (unformat (i, "name %s", &match_name))
19561 {
19562 vec_add1 (match_name, 0);
19563 match_name_valid = 1;
19564 }
19565 else
19566 break;
19567 }
19568
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019569 M (POLICER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019570 mp->match_name_valid = match_name_valid;
19571 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
19572 vec_free (match_name);
19573 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019574 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019575
19576 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019577 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019578 S (mp_ping);
19579
Damjan Marion7cd468a2016-12-19 23:05:39 +010019580 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019581 W (ret);
19582 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019583}
19584
19585static int
19586api_policer_classify_set_interface (vat_main_t * vam)
19587{
19588 unformat_input_t *i = vam->input;
19589 vl_api_policer_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019590 u32 sw_if_index;
19591 int sw_if_index_set;
19592 u32 ip4_table_index = ~0;
19593 u32 ip6_table_index = ~0;
19594 u32 l2_table_index = ~0;
19595 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019596 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019597
19598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19599 {
19600 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
19601 sw_if_index_set = 1;
19602 else if (unformat (i, "sw_if_index %d", &sw_if_index))
19603 sw_if_index_set = 1;
19604 else if (unformat (i, "del"))
19605 is_add = 0;
19606 else if (unformat (i, "ip4-table %d", &ip4_table_index))
19607 ;
19608 else if (unformat (i, "ip6-table %d", &ip6_table_index))
19609 ;
19610 else if (unformat (i, "l2-table %d", &l2_table_index))
19611 ;
19612 else
19613 {
19614 clib_warning ("parse error '%U'", format_unformat_error, i);
19615 return -99;
19616 }
19617 }
19618
19619 if (sw_if_index_set == 0)
19620 {
19621 errmsg ("missing interface name or sw_if_index");
19622 return -99;
19623 }
19624
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019625 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019626
19627 mp->sw_if_index = ntohl (sw_if_index);
19628 mp->ip4_table_index = ntohl (ip4_table_index);
19629 mp->ip6_table_index = ntohl (ip6_table_index);
19630 mp->l2_table_index = ntohl (l2_table_index);
19631 mp->is_add = is_add;
19632
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019633 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019634 W (ret);
19635 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019636}
19637
19638static int
19639api_policer_classify_dump (vat_main_t * vam)
19640{
19641 unformat_input_t *i = vam->input;
19642 vl_api_policer_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019643 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019644 u8 type = POLICER_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019645 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019646
19647 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
19648 ;
19649 else
19650 {
19651 errmsg ("classify table type must be specified");
19652 return -99;
19653 }
19654
19655 if (!vam->json_output)
19656 {
19657 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
19658 }
19659
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019660 M (POLICER_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019661 mp->type = type;
19662 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019663 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019664
19665 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019666 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019667 S (mp_ping);
19668
Damjan Marion7cd468a2016-12-19 23:05:39 +010019669 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060019670 W (ret);
19671 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019672}
19673
19674static int
19675api_netmap_create (vat_main_t * vam)
19676{
19677 unformat_input_t *i = vam->input;
19678 vl_api_netmap_create_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019679 u8 *if_name = 0;
19680 u8 hw_addr[6];
19681 u8 random_hw_addr = 1;
19682 u8 is_pipe = 0;
19683 u8 is_master = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019684 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019685
Dave Barachb7b92992018-10-17 10:38:51 -040019686 clib_memset (hw_addr, 0, sizeof (hw_addr));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019687
19688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19689 {
19690 if (unformat (i, "name %s", &if_name))
19691 vec_add1 (if_name, 0);
19692 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
19693 random_hw_addr = 0;
19694 else if (unformat (i, "pipe"))
19695 is_pipe = 1;
19696 else if (unformat (i, "master"))
19697 is_master = 1;
19698 else if (unformat (i, "slave"))
19699 is_master = 0;
19700 else
19701 break;
19702 }
19703
19704 if (!vec_len (if_name))
19705 {
19706 errmsg ("interface name must be specified");
19707 return -99;
19708 }
19709
19710 if (vec_len (if_name) > 64)
19711 {
19712 errmsg ("interface name too long");
19713 return -99;
19714 }
19715
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019716 M (NETMAP_CREATE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019717
19718 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
19719 clib_memcpy (mp->hw_addr, hw_addr, 6);
19720 mp->use_random_hw_addr = random_hw_addr;
19721 mp->is_pipe = is_pipe;
19722 mp->is_master = is_master;
19723 vec_free (if_name);
19724
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019725 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019726 W (ret);
19727 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019728}
19729
19730static int
19731api_netmap_delete (vat_main_t * vam)
19732{
19733 unformat_input_t *i = vam->input;
19734 vl_api_netmap_delete_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019735 u8 *if_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019736 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019737
19738 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
19739 {
19740 if (unformat (i, "name %s", &if_name))
19741 vec_add1 (if_name, 0);
19742 else
19743 break;
19744 }
19745
19746 if (!vec_len (if_name))
19747 {
19748 errmsg ("interface name must be specified");
19749 return -99;
19750 }
19751
19752 if (vec_len (if_name) > 64)
19753 {
19754 errmsg ("interface name too long");
19755 return -99;
19756 }
19757
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019758 M (NETMAP_DELETE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019759
19760 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
19761 vec_free (if_name);
19762
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019763 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060019764 W (ret);
19765 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019766}
19767
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019768static void
Neale Ranns31ed7442018-02-23 05:29:09 -080019769vl_api_mpls_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019770{
19771 if (fp->afi == IP46_TYPE_IP6)
19772 print (vam->ofp,
19773 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
19774 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U",
Neale Ranns44cea222018-12-04 09:39:40 +000019775 fp->weight, ntohl (fp->sw_if_index), fp->is_local,
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019776 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
19777 format_ip6_address, fp->next_hop);
19778 else if (fp->afi == IP46_TYPE_IP4)
19779 print (vam->ofp,
19780 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
19781 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U",
Neale Ranns44cea222018-12-04 09:39:40 +000019782 fp->weight, ntohl (fp->sw_if_index), fp->is_local,
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019783 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
19784 format_ip4_address, fp->next_hop);
19785}
19786
19787static void
19788vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
Neale Ranns31ed7442018-02-23 05:29:09 -080019789 vl_api_fib_path_t * fp)
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019790{
19791 struct in_addr ip4;
19792 struct in6_addr ip6;
19793
19794 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
19795 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
19796 vat_json_object_add_uint (node, "is_local", fp->is_local);
19797 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
19798 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
19799 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
19800 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
19801 if (fp->afi == IP46_TYPE_IP4)
19802 {
19803 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
19804 vat_json_object_add_ip4 (node, "next_hop", ip4);
19805 }
19806 else if (fp->afi == IP46_TYPE_IP6)
19807 {
19808 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
19809 vat_json_object_add_ip6 (node, "next_hop", ip6);
19810 }
19811}
19812
19813static void
19814vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019815{
19816 vat_main_t *vam = &vat_main;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019817 int count = ntohl (mp->mt_count);
Neale Ranns31ed7442018-02-23 05:29:09 -080019818 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019819 i32 i;
19820
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019821 print (vam->ofp, "[%d]: sw_if_index %d via:",
19822 ntohl (mp->mt_tunnel_index), ntohl (mp->mt_sw_if_index));
19823 fp = mp->mt_paths;
19824 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019825 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019826 vl_api_mpls_fib_path_print (vam, fp);
19827 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019828 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019829
Damjan Marion7cd468a2016-12-19 23:05:39 +010019830 print (vam->ofp, "");
19831}
19832
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019833#define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
19834#define vl_api_mpls_tunnel_details_t_print vl_noop_handler
19835
19836static void
19837vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019838{
19839 vat_main_t *vam = &vat_main;
19840 vat_json_node_t *node = NULL;
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019841 int count = ntohl (mp->mt_count);
Neale Ranns31ed7442018-02-23 05:29:09 -080019842 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019843 i32 i;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019844
19845 if (VAT_JSON_ARRAY != vam->json_tree.type)
19846 {
19847 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19848 vat_json_init_array (&vam->json_tree);
19849 }
19850 node = vat_json_array_add (&vam->json_tree);
19851
19852 vat_json_init_object (node);
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019853 vat_json_object_add_uint (node, "tunnel_index",
19854 ntohl (mp->mt_tunnel_index));
19855 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->mt_sw_if_index));
19856
19857 vat_json_object_add_uint (node, "l2_only", mp->mt_l2_only);
19858
19859 fp = mp->mt_paths;
19860 for (i = 0; i < count; i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010019861 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019862 vl_api_mpls_fib_path_json_print (node, fp);
19863 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019864 }
19865}
19866
19867static int
19868api_mpls_tunnel_dump (vat_main_t * vam)
19869{
19870 vl_api_mpls_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019871 vl_api_control_ping_t *mp_ping;
Neale Rannsf5fa5ae2018-09-26 05:07:25 -070019872 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019873 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019874
19875 /* Parse args required to build the message */
19876 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT)
19877 {
Neale Rannsf5fa5ae2018-09-26 05:07:25 -070019878 if (unformat (vam->input, "sw_if_index %d", &sw_if_index))
19879 ;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019880 }
19881
Neale Rannsf5fa5ae2018-09-26 05:07:25 -070019882 print (vam->ofp, " sw_if_index %d", sw_if_index);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019883
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019884 M (MPLS_TUNNEL_DUMP, mp);
Neale Rannsf5fa5ae2018-09-26 05:07:25 -070019885 mp->sw_if_index = htonl (sw_if_index);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019886 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019887
19888 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019889 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019890 S (mp_ping);
19891
Jon Loeliger56c7b012017-02-01 12:31:41 -060019892 W (ret);
19893 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019894}
19895
19896#define vl_api_mpls_fib_details_t_endian vl_noop_handler
19897#define vl_api_mpls_fib_details_t_print vl_noop_handler
19898
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019899
Damjan Marion7cd468a2016-12-19 23:05:39 +010019900static void
19901vl_api_mpls_fib_details_t_handler (vl_api_mpls_fib_details_t * mp)
19902{
19903 vat_main_t *vam = &vat_main;
19904 int count = ntohl (mp->count);
Neale Ranns31ed7442018-02-23 05:29:09 -080019905 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019906 int i;
19907
19908 print (vam->ofp,
19909 "table-id %d, label %u, ess_bit %u",
19910 ntohl (mp->table_id), ntohl (mp->label), mp->eos_bit);
19911 fp = mp->path;
19912 for (i = 0; i < count; i++)
19913 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019914 vl_api_mpls_fib_path_print (vam, fp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019915 fp++;
19916 }
19917}
19918
19919static void vl_api_mpls_fib_details_t_handler_json
19920 (vl_api_mpls_fib_details_t * mp)
19921{
19922 vat_main_t *vam = &vat_main;
19923 int count = ntohl (mp->count);
19924 vat_json_node_t *node = NULL;
Neale Ranns31ed7442018-02-23 05:29:09 -080019925 vl_api_fib_path_t *fp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019926 int i;
19927
19928 if (VAT_JSON_ARRAY != vam->json_tree.type)
19929 {
19930 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
19931 vat_json_init_array (&vam->json_tree);
19932 }
19933 node = vat_json_array_add (&vam->json_tree);
19934
19935 vat_json_init_object (node);
19936 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
19937 vat_json_object_add_uint (node, "s_bit", mp->eos_bit);
19938 vat_json_object_add_uint (node, "label", ntohl (mp->label));
19939 vat_json_object_add_uint (node, "path_count", count);
19940 fp = mp->path;
19941 for (i = 0; i < count; i++)
19942 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -080019943 vl_api_mpls_fib_path_json_print (node, fp);
19944 fp++;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019945 }
19946}
19947
19948static int
19949api_mpls_fib_dump (vat_main_t * vam)
19950{
19951 vl_api_mpls_fib_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019952 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060019953 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019954
Jon Loeliger8a2aea32017-01-31 13:19:40 -060019955 M (MPLS_FIB_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060019956 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010019957
19958 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040019959 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060019960 S (mp_ping);
19961
Jon Loeliger56c7b012017-02-01 12:31:41 -060019962 W (ret);
19963 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010019964}
19965
19966#define vl_api_ip_fib_details_t_endian vl_noop_handler
19967#define vl_api_ip_fib_details_t_print vl_noop_handler
19968
19969static void
19970vl_api_ip_fib_details_t_handler (vl_api_ip_fib_details_t * mp)
19971{
19972 vat_main_t *vam = &vat_main;
19973 int count = ntohl (mp->count);
19974 vl_api_fib_path_t *fp;
19975 int i;
19976
19977 print (vam->ofp,
Neale Ranns008dbe12018-09-07 09:32:36 -070019978 "table-id %d, prefix %U/%d stats-index %d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010019979 ntohl (mp->table_id), format_ip4_address, mp->address,
Neale Ranns008dbe12018-09-07 09:32:36 -070019980 mp->address_length, ntohl (mp->stats_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019981 fp = mp->path;
19982 for (i = 0; i < count; i++)
19983 {
19984 if (fp->afi == IP46_TYPE_IP6)
19985 print (vam->ofp,
19986 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
Neale Rannsde450cb2018-07-10 03:00:07 -070019987 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U, "
19988 "next_hop_table %d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010019989 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
19990 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
Neale Rannsde450cb2018-07-10 03:00:07 -070019991 format_ip6_address, fp->next_hop, ntohl (fp->table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010019992 else if (fp->afi == IP46_TYPE_IP4)
19993 print (vam->ofp,
19994 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
Neale Rannsde450cb2018-07-10 03:00:07 -070019995 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U, "
19996 "next_hop_table %d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010019997 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
19998 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
Neale Rannsde450cb2018-07-10 03:00:07 -070019999 format_ip4_address, fp->next_hop, ntohl (fp->table_id));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020000 fp++;
20001 }
20002}
20003
20004static void vl_api_ip_fib_details_t_handler_json
20005 (vl_api_ip_fib_details_t * mp)
20006{
20007 vat_main_t *vam = &vat_main;
20008 int count = ntohl (mp->count);
20009 vat_json_node_t *node = NULL;
20010 struct in_addr ip4;
20011 struct in6_addr ip6;
20012 vl_api_fib_path_t *fp;
20013 int i;
20014
20015 if (VAT_JSON_ARRAY != vam->json_tree.type)
20016 {
20017 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20018 vat_json_init_array (&vam->json_tree);
20019 }
20020 node = vat_json_array_add (&vam->json_tree);
20021
20022 vat_json_init_object (node);
20023 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
20024 clib_memcpy (&ip4, &mp->address, sizeof (ip4));
20025 vat_json_object_add_ip4 (node, "prefix", ip4);
20026 vat_json_object_add_uint (node, "mask_length", mp->address_length);
20027 vat_json_object_add_uint (node, "path_count", count);
20028 fp = mp->path;
20029 for (i = 0; i < count; i++)
20030 {
20031 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
20032 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
20033 vat_json_object_add_uint (node, "is_local", fp->is_local);
20034 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
20035 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
20036 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
20037 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
20038 if (fp->afi == IP46_TYPE_IP4)
20039 {
20040 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
20041 vat_json_object_add_ip4 (node, "next_hop", ip4);
20042 }
20043 else if (fp->afi == IP46_TYPE_IP6)
20044 {
20045 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
20046 vat_json_object_add_ip6 (node, "next_hop", ip6);
20047 }
20048 }
20049}
20050
20051static int
20052api_ip_fib_dump (vat_main_t * vam)
20053{
20054 vl_api_ip_fib_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020055 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020056 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020057
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020058 M (IP_FIB_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020059 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020060
20061 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020062 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020063 S (mp_ping);
20064
Jon Loeliger56c7b012017-02-01 12:31:41 -060020065 W (ret);
20066 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020067}
20068
Neale Ranns5a8123b2017-01-26 01:18:23 -080020069static int
20070api_ip_mfib_dump (vat_main_t * vam)
20071{
20072 vl_api_ip_mfib_dump_t *mp;
20073 vl_api_control_ping_t *mp_ping;
20074 int ret;
20075
20076 M (IP_MFIB_DUMP, mp);
20077 S (mp);
20078
20079 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020080 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080020081 S (mp_ping);
20082
20083 W (ret);
20084 return ret;
20085}
20086
Damjan Marion7cd468a2016-12-19 23:05:39 +010020087static void vl_api_ip_neighbor_details_t_handler
20088 (vl_api_ip_neighbor_details_t * mp)
20089{
20090 vat_main_t *vam = &vat_main;
20091
20092 print (vam->ofp, "%c %U %U",
Neale Ranns37029302018-08-10 05:30:06 -070020093 (ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ? 'S' : 'D',
20094 format_vl_api_mac_address, &mp->neighbor.mac_address,
20095 format_vl_api_address, &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020096}
20097
20098static void vl_api_ip_neighbor_details_t_handler_json
20099 (vl_api_ip_neighbor_details_t * mp)
20100{
20101
20102 vat_main_t *vam = &vat_main;
20103 vat_json_node_t *node;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020104
20105 if (VAT_JSON_ARRAY != vam->json_tree.type)
20106 {
20107 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20108 vat_json_init_array (&vam->json_tree);
20109 }
20110 node = vat_json_array_add (&vam->json_tree);
20111
20112 vat_json_init_object (node);
Neale Ranns37029302018-08-10 05:30:06 -070020113 vat_json_object_add_string_copy
20114 (node, "flag",
20115 ((ntohl (mp->neighbor.flags) & IP_NEIGHBOR_FLAG_STATIC) ?
20116 (u8 *) "static" : (u8 *) "dynamic"));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020117
20118 vat_json_object_add_string_copy (node, "link_layer",
Neale Ranns37029302018-08-10 05:30:06 -070020119 format (0, "%U", format_vl_api_mac_address,
20120 &mp->neighbor.mac_address));
Neale Ranns8d7c5022019-02-06 01:41:05 -080020121 vat_json_object_add_address (node, &mp->neighbor.ip_address);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020122}
20123
20124static int
20125api_ip_neighbor_dump (vat_main_t * vam)
20126{
20127 unformat_input_t *i = vam->input;
20128 vl_api_ip_neighbor_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020129 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020130 u8 is_ipv6 = 0;
20131 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020132 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020133
20134 /* Parse args required to build the message */
20135 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20136 {
20137 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20138 ;
20139 else if (unformat (i, "sw_if_index %d", &sw_if_index))
20140 ;
20141 else if (unformat (i, "ip6"))
20142 is_ipv6 = 1;
20143 else
20144 break;
20145 }
20146
20147 if (sw_if_index == ~0)
20148 {
20149 errmsg ("missing interface name or sw_if_index");
20150 return -99;
20151 }
20152
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020153 M (IP_NEIGHBOR_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020154 mp->is_ipv6 = (u8) is_ipv6;
20155 mp->sw_if_index = ntohl (sw_if_index);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020156 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020157
20158 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020159 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020160 S (mp_ping);
20161
Jon Loeliger56c7b012017-02-01 12:31:41 -060020162 W (ret);
20163 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020164}
20165
20166#define vl_api_ip6_fib_details_t_endian vl_noop_handler
20167#define vl_api_ip6_fib_details_t_print vl_noop_handler
20168
20169static void
20170vl_api_ip6_fib_details_t_handler (vl_api_ip6_fib_details_t * mp)
20171{
20172 vat_main_t *vam = &vat_main;
20173 int count = ntohl (mp->count);
20174 vl_api_fib_path_t *fp;
20175 int i;
20176
20177 print (vam->ofp,
Neale Ranns008dbe12018-09-07 09:32:36 -070020178 "table-id %d, prefix %U/%d stats-index %d",
Damjan Marion7cd468a2016-12-19 23:05:39 +010020179 ntohl (mp->table_id), format_ip6_address, mp->address,
Neale Ranns008dbe12018-09-07 09:32:36 -070020180 mp->address_length, ntohl (mp->stats_index));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020181 fp = mp->path;
20182 for (i = 0; i < count; i++)
20183 {
20184 if (fp->afi == IP46_TYPE_IP6)
20185 print (vam->ofp,
20186 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
20187 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U",
20188 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
20189 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
20190 format_ip6_address, fp->next_hop);
20191 else if (fp->afi == IP46_TYPE_IP4)
20192 print (vam->ofp,
20193 " weight %d, sw_if_index %d, is_local %d, is_drop %d, "
20194 "is_unreach %d, is_prohitbit %d, afi %d, next_hop %U",
20195 ntohl (fp->weight), ntohl (fp->sw_if_index), fp->is_local,
20196 fp->is_drop, fp->is_unreach, fp->is_prohibit, fp->afi,
20197 format_ip4_address, fp->next_hop);
20198 fp++;
20199 }
20200}
20201
20202static void vl_api_ip6_fib_details_t_handler_json
20203 (vl_api_ip6_fib_details_t * mp)
20204{
20205 vat_main_t *vam = &vat_main;
20206 int count = ntohl (mp->count);
20207 vat_json_node_t *node = NULL;
20208 struct in_addr ip4;
20209 struct in6_addr ip6;
20210 vl_api_fib_path_t *fp;
20211 int i;
20212
20213 if (VAT_JSON_ARRAY != vam->json_tree.type)
20214 {
20215 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20216 vat_json_init_array (&vam->json_tree);
20217 }
20218 node = vat_json_array_add (&vam->json_tree);
20219
20220 vat_json_init_object (node);
20221 vat_json_object_add_uint (node, "table", ntohl (mp->table_id));
20222 clib_memcpy (&ip6, &mp->address, sizeof (ip6));
20223 vat_json_object_add_ip6 (node, "prefix", ip6);
20224 vat_json_object_add_uint (node, "mask_length", mp->address_length);
20225 vat_json_object_add_uint (node, "path_count", count);
20226 fp = mp->path;
20227 for (i = 0; i < count; i++)
20228 {
20229 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
20230 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
20231 vat_json_object_add_uint (node, "is_local", fp->is_local);
20232 vat_json_object_add_uint (node, "is_drop", fp->is_drop);
20233 vat_json_object_add_uint (node, "is_unreach", fp->is_unreach);
20234 vat_json_object_add_uint (node, "is_prohibit", fp->is_prohibit);
20235 vat_json_object_add_uint (node, "next_hop_afi", fp->afi);
20236 if (fp->afi == IP46_TYPE_IP4)
20237 {
20238 clib_memcpy (&ip4, &fp->next_hop, sizeof (ip4));
20239 vat_json_object_add_ip4 (node, "next_hop", ip4);
20240 }
20241 else if (fp->afi == IP46_TYPE_IP6)
20242 {
20243 clib_memcpy (&ip6, &fp->next_hop, sizeof (ip6));
20244 vat_json_object_add_ip6 (node, "next_hop", ip6);
20245 }
20246 }
20247}
20248
20249static int
20250api_ip6_fib_dump (vat_main_t * vam)
20251{
20252 vl_api_ip6_fib_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020253 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020254 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020255
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020256 M (IP6_FIB_DUMP, mp);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020257 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020258
20259 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020260 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020261 S (mp_ping);
20262
Jon Loeliger56c7b012017-02-01 12:31:41 -060020263 W (ret);
20264 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020265}
20266
Neale Ranns5a8123b2017-01-26 01:18:23 -080020267static int
20268api_ip6_mfib_dump (vat_main_t * vam)
20269{
20270 vl_api_ip6_mfib_dump_t *mp;
20271 vl_api_control_ping_t *mp_ping;
20272 int ret;
20273
20274 M (IP6_MFIB_DUMP, mp);
20275 S (mp);
20276
20277 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020278 MPING (CONTROL_PING, mp_ping);
Neale Ranns5a8123b2017-01-26 01:18:23 -080020279 S (mp_ping);
20280
20281 W (ret);
20282 return ret;
20283}
20284
Damjan Marion7cd468a2016-12-19 23:05:39 +010020285int
20286api_classify_table_ids (vat_main_t * vam)
20287{
20288 vl_api_classify_table_ids_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020289 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020290
20291 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020292 M (CLASSIFY_TABLE_IDS, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020293 mp->context = 0;
20294
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020295 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020296 W (ret);
20297 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020298}
20299
20300int
20301api_classify_table_by_interface (vat_main_t * vam)
20302{
20303 unformat_input_t *input = vam->input;
20304 vl_api_classify_table_by_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020305
20306 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020307 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020308 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20309 {
20310 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20311 ;
20312 else if (unformat (input, "sw_if_index %d", &sw_if_index))
20313 ;
20314 else
20315 break;
20316 }
20317 if (sw_if_index == ~0)
20318 {
20319 errmsg ("missing interface name or sw_if_index");
20320 return -99;
20321 }
20322
20323 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020324 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020325 mp->context = 0;
20326 mp->sw_if_index = ntohl (sw_if_index);
20327
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020328 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020329 W (ret);
20330 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020331}
20332
20333int
20334api_classify_table_info (vat_main_t * vam)
20335{
20336 unformat_input_t *input = vam->input;
20337 vl_api_classify_table_info_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020338
20339 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020340 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020341 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20342 {
20343 if (unformat (input, "table_id %d", &table_id))
20344 ;
20345 else
20346 break;
20347 }
20348 if (table_id == ~0)
20349 {
20350 errmsg ("missing table id");
20351 return -99;
20352 }
20353
20354 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020355 M (CLASSIFY_TABLE_INFO, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020356 mp->context = 0;
20357 mp->table_id = ntohl (table_id);
20358
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020359 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020360 W (ret);
20361 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020362}
20363
20364int
20365api_classify_session_dump (vat_main_t * vam)
20366{
20367 unformat_input_t *input = vam->input;
20368 vl_api_classify_session_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020369 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020370
20371 u32 table_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020372 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020373 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20374 {
20375 if (unformat (input, "table_id %d", &table_id))
20376 ;
20377 else
20378 break;
20379 }
20380 if (table_id == ~0)
20381 {
20382 errmsg ("missing table id");
20383 return -99;
20384 }
20385
20386 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020387 M (CLASSIFY_SESSION_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020388 mp->context = 0;
20389 mp->table_id = ntohl (table_id);
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020390 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020391
20392 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020393 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020394 S (mp_ping);
20395
Jon Loeliger56c7b012017-02-01 12:31:41 -060020396 W (ret);
20397 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020398}
20399
20400static void
20401vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
20402{
20403 vat_main_t *vam = &vat_main;
20404
20405 print (vam->ofp, "collector_address %U, collector_port %d, "
20406 "src_address %U, vrf_id %d, path_mtu %u, "
20407 "template_interval %u, udp_checksum %d",
20408 format_ip4_address, mp->collector_address,
20409 ntohs (mp->collector_port),
20410 format_ip4_address, mp->src_address,
20411 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
20412 ntohl (mp->template_interval), mp->udp_checksum);
20413
20414 vam->retval = 0;
20415 vam->result_ready = 1;
20416}
20417
20418static void
20419 vl_api_ipfix_exporter_details_t_handler_json
20420 (vl_api_ipfix_exporter_details_t * mp)
20421{
20422 vat_main_t *vam = &vat_main;
20423 vat_json_node_t node;
20424 struct in_addr collector_address;
20425 struct in_addr src_address;
20426
20427 vat_json_init_object (&node);
20428 clib_memcpy (&collector_address, &mp->collector_address,
20429 sizeof (collector_address));
20430 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
20431 vat_json_object_add_uint (&node, "collector_port",
20432 ntohs (mp->collector_port));
20433 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
20434 vat_json_object_add_ip4 (&node, "src_address", src_address);
20435 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
20436 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
20437 vat_json_object_add_uint (&node, "template_interval",
20438 ntohl (mp->template_interval));
20439 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
20440
20441 vat_json_print (vam->ofp, &node);
20442 vat_json_free (&node);
20443 vam->retval = 0;
20444 vam->result_ready = 1;
20445}
20446
20447int
20448api_ipfix_exporter_dump (vat_main_t * vam)
20449{
20450 vl_api_ipfix_exporter_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020451 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020452
20453 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020454 M (IPFIX_EXPORTER_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020455 mp->context = 0;
20456
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020457 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020458 W (ret);
20459 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020460}
20461
20462static int
20463api_ipfix_classify_stream_dump (vat_main_t * vam)
20464{
20465 vl_api_ipfix_classify_stream_dump_t *mp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020466 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020467
20468 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020469 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020470 mp->context = 0;
20471
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020472 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020473 W (ret);
20474 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020475 /* NOTREACHED */
20476 return 0;
20477}
20478
20479static void
20480 vl_api_ipfix_classify_stream_details_t_handler
20481 (vl_api_ipfix_classify_stream_details_t * mp)
20482{
20483 vat_main_t *vam = &vat_main;
20484 print (vam->ofp, "domain_id %d, src_port %d",
20485 ntohl (mp->domain_id), ntohs (mp->src_port));
20486 vam->retval = 0;
20487 vam->result_ready = 1;
20488}
20489
20490static void
20491 vl_api_ipfix_classify_stream_details_t_handler_json
20492 (vl_api_ipfix_classify_stream_details_t * mp)
20493{
20494 vat_main_t *vam = &vat_main;
20495 vat_json_node_t node;
20496
20497 vat_json_init_object (&node);
20498 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
20499 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
20500
20501 vat_json_print (vam->ofp, &node);
20502 vat_json_free (&node);
20503 vam->retval = 0;
20504 vam->result_ready = 1;
20505}
20506
20507static int
20508api_ipfix_classify_table_dump (vat_main_t * vam)
20509{
20510 vl_api_ipfix_classify_table_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020511 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020512 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020513
20514 if (!vam->json_output)
20515 {
20516 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
20517 "transport_protocol");
20518 }
20519
20520 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020521 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020522
20523 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020524 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020525
20526 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020527 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020528 S (mp_ping);
20529
Jon Loeliger56c7b012017-02-01 12:31:41 -060020530 W (ret);
20531 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020532}
20533
20534static void
20535 vl_api_ipfix_classify_table_details_t_handler
20536 (vl_api_ipfix_classify_table_details_t * mp)
20537{
20538 vat_main_t *vam = &vat_main;
20539 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
20540 mp->transport_protocol);
20541}
20542
20543static void
20544 vl_api_ipfix_classify_table_details_t_handler_json
20545 (vl_api_ipfix_classify_table_details_t * mp)
20546{
20547 vat_json_node_t *node = NULL;
20548 vat_main_t *vam = &vat_main;
20549
20550 if (VAT_JSON_ARRAY != vam->json_tree.type)
20551 {
20552 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20553 vat_json_init_array (&vam->json_tree);
20554 }
20555
20556 node = vat_json_array_add (&vam->json_tree);
20557 vat_json_init_object (node);
20558
20559 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
20560 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
20561 vat_json_object_add_uint (node, "transport_protocol",
20562 mp->transport_protocol);
20563}
20564
20565static int
20566api_sw_interface_span_enable_disable (vat_main_t * vam)
20567{
20568 unformat_input_t *i = vam->input;
20569 vl_api_sw_interface_span_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020570 u32 src_sw_if_index = ~0;
20571 u32 dst_sw_if_index = ~0;
20572 u8 state = 3;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020573 int ret;
Eyal Bari001fd402017-07-16 09:34:53 +030020574 u8 is_l2 = 0;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020575
20576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
20577 {
20578 if (unformat
20579 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
20580 ;
20581 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
20582 ;
20583 else
20584 if (unformat
20585 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
20586 ;
20587 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
20588 ;
20589 else if (unformat (i, "disable"))
20590 state = 0;
20591 else if (unformat (i, "rx"))
20592 state = 1;
20593 else if (unformat (i, "tx"))
20594 state = 2;
20595 else if (unformat (i, "both"))
20596 state = 3;
Eyal Bari001fd402017-07-16 09:34:53 +030020597 else if (unformat (i, "l2"))
20598 is_l2 = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020599 else
20600 break;
20601 }
20602
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020603 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020604
20605 mp->sw_if_index_from = htonl (src_sw_if_index);
20606 mp->sw_if_index_to = htonl (dst_sw_if_index);
20607 mp->state = state;
Eyal Bari001fd402017-07-16 09:34:53 +030020608 mp->is_l2 = is_l2;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020609
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020610 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020611 W (ret);
20612 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020613}
20614
20615static void
20616vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
20617 * mp)
20618{
20619 vat_main_t *vam = &vat_main;
20620 u8 *sw_if_from_name = 0;
20621 u8 *sw_if_to_name = 0;
20622 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
20623 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
20624 char *states[] = { "none", "rx", "tx", "both" };
20625 hash_pair_t *p;
20626
20627 /* *INDENT-OFF* */
20628 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
20629 ({
20630 if ((u32) p->value[0] == sw_if_index_from)
20631 {
20632 sw_if_from_name = (u8 *)(p->key);
20633 if (sw_if_to_name)
20634 break;
20635 }
20636 if ((u32) p->value[0] == sw_if_index_to)
20637 {
20638 sw_if_to_name = (u8 *)(p->key);
20639 if (sw_if_from_name)
20640 break;
20641 }
20642 }));
20643 /* *INDENT-ON* */
Jon Loeliger179ab362018-03-12 14:50:08 -050020644 print (vam->ofp, "%20s => %20s (%s) %s",
20645 sw_if_from_name, sw_if_to_name, states[mp->state],
20646 mp->is_l2 ? "l2" : "device");
Damjan Marion7cd468a2016-12-19 23:05:39 +010020647}
20648
20649static void
20650 vl_api_sw_interface_span_details_t_handler_json
20651 (vl_api_sw_interface_span_details_t * mp)
20652{
20653 vat_main_t *vam = &vat_main;
20654 vat_json_node_t *node = NULL;
20655 u8 *sw_if_from_name = 0;
20656 u8 *sw_if_to_name = 0;
20657 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
20658 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
20659 hash_pair_t *p;
20660
20661 /* *INDENT-OFF* */
20662 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
20663 ({
20664 if ((u32) p->value[0] == sw_if_index_from)
20665 {
20666 sw_if_from_name = (u8 *)(p->key);
20667 if (sw_if_to_name)
20668 break;
20669 }
20670 if ((u32) p->value[0] == sw_if_index_to)
20671 {
20672 sw_if_to_name = (u8 *)(p->key);
20673 if (sw_if_from_name)
20674 break;
20675 }
20676 }));
20677 /* *INDENT-ON* */
20678
20679 if (VAT_JSON_ARRAY != vam->json_tree.type)
20680 {
20681 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
20682 vat_json_init_array (&vam->json_tree);
20683 }
20684 node = vat_json_array_add (&vam->json_tree);
20685
20686 vat_json_init_object (node);
20687 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
20688 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
20689 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
Neale Ranns05b2bf22017-01-30 06:44:58 -080020690 if (0 != sw_if_to_name)
20691 {
20692 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
20693 }
Damjan Marion7cd468a2016-12-19 23:05:39 +010020694 vat_json_object_add_uint (node, "state", mp->state);
Jon Loeliger179ab362018-03-12 14:50:08 -050020695 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020696}
20697
20698static int
20699api_sw_interface_span_dump (vat_main_t * vam)
20700{
Eyal Bari5b311202017-07-31 13:12:30 +030020701 unformat_input_t *input = vam->input;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020702 vl_api_sw_interface_span_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020703 vl_api_control_ping_t *mp_ping;
Eyal Bari5b311202017-07-31 13:12:30 +030020704 u8 is_l2 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020705 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020706
Eyal Bari5b311202017-07-31 13:12:30 +030020707 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20708 {
20709 if (unformat (input, "l2"))
20710 is_l2 = 1;
20711 else
20712 break;
20713 }
20714
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020715 M (SW_INTERFACE_SPAN_DUMP, mp);
Eyal Bari5b311202017-07-31 13:12:30 +030020716 mp->is_l2 = is_l2;
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020717 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020718
20719 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040020720 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060020721 S (mp_ping);
20722
Jon Loeliger56c7b012017-02-01 12:31:41 -060020723 W (ret);
20724 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020725}
20726
20727int
20728api_pg_create_interface (vat_main_t * vam)
20729{
20730 unformat_input_t *input = vam->input;
20731 vl_api_pg_create_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020732
20733 u32 if_id = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020734 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020735 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20736 {
20737 if (unformat (input, "if_id %d", &if_id))
20738 ;
20739 else
20740 break;
20741 }
20742 if (if_id == ~0)
20743 {
20744 errmsg ("missing pg interface index");
20745 return -99;
20746 }
20747
20748 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020749 M (PG_CREATE_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020750 mp->context = 0;
20751 mp->interface_id = ntohl (if_id);
20752
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020753 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020754 W (ret);
20755 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020756}
20757
20758int
20759api_pg_capture (vat_main_t * vam)
20760{
20761 unformat_input_t *input = vam->input;
20762 vl_api_pg_capture_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020763
20764 u32 if_id = ~0;
20765 u8 enable = 1;
20766 u32 count = 1;
20767 u8 pcap_file_set = 0;
20768 u8 *pcap_file = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020769 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020770 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20771 {
20772 if (unformat (input, "if_id %d", &if_id))
20773 ;
20774 else if (unformat (input, "pcap %s", &pcap_file))
20775 pcap_file_set = 1;
20776 else if (unformat (input, "count %d", &count))
20777 ;
20778 else if (unformat (input, "disable"))
20779 enable = 0;
20780 else
20781 break;
20782 }
20783 if (if_id == ~0)
20784 {
20785 errmsg ("missing pg interface index");
20786 return -99;
20787 }
20788 if (pcap_file_set > 0)
20789 {
20790 if (vec_len (pcap_file) > 255)
20791 {
20792 errmsg ("pcap file name is too long");
20793 return -99;
20794 }
20795 }
20796
20797 u32 name_len = vec_len (pcap_file);
20798 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020799 M (PG_CAPTURE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020800 mp->context = 0;
20801 mp->interface_id = ntohl (if_id);
20802 mp->is_enabled = enable;
20803 mp->count = ntohl (count);
20804 mp->pcap_name_length = ntohl (name_len);
20805 if (pcap_file_set != 0)
20806 {
20807 clib_memcpy (mp->pcap_file_name, pcap_file, name_len);
20808 }
20809 vec_free (pcap_file);
20810
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020811 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020812 W (ret);
20813 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020814}
20815
20816int
20817api_pg_enable_disable (vat_main_t * vam)
20818{
20819 unformat_input_t *input = vam->input;
20820 vl_api_pg_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020821
20822 u8 enable = 1;
20823 u8 stream_name_set = 0;
20824 u8 *stream_name = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020825 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020826 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20827 {
20828 if (unformat (input, "stream %s", &stream_name))
20829 stream_name_set = 1;
20830 else if (unformat (input, "disable"))
20831 enable = 0;
20832 else
20833 break;
20834 }
20835
20836 if (stream_name_set > 0)
20837 {
20838 if (vec_len (stream_name) > 255)
20839 {
20840 errmsg ("stream name too long");
20841 return -99;
20842 }
20843 }
20844
20845 u32 name_len = vec_len (stream_name);
20846 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020847 M (PG_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020848 mp->context = 0;
20849 mp->is_enabled = enable;
20850 if (stream_name_set != 0)
20851 {
20852 mp->stream_name_length = ntohl (name_len);
20853 clib_memcpy (mp->stream_name, stream_name, name_len);
20854 }
20855 vec_free (stream_name);
20856
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020857 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020858 W (ret);
20859 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020860}
20861
20862int
20863api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
20864{
20865 unformat_input_t *input = vam->input;
20866 vl_api_ip_source_and_port_range_check_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020867
20868 u16 *low_ports = 0;
20869 u16 *high_ports = 0;
20870 u16 this_low;
20871 u16 this_hi;
Neale Ranns37029302018-08-10 05:30:06 -070020872 vl_api_prefix_t prefix;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020873 u32 tmp, tmp2;
20874 u8 prefix_set = 0;
20875 u32 vrf_id = ~0;
20876 u8 is_add = 1;
20877 u8 is_ipv6 = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020878 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020879
20880 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20881 {
Neale Ranns37029302018-08-10 05:30:06 -070020882 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
20883 prefix_set = 1;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020884 else if (unformat (input, "vrf %d", &vrf_id))
20885 ;
20886 else if (unformat (input, "del"))
20887 is_add = 0;
20888 else if (unformat (input, "port %d", &tmp))
20889 {
20890 if (tmp == 0 || tmp > 65535)
20891 {
20892 errmsg ("port %d out of range", tmp);
20893 return -99;
20894 }
20895 this_low = tmp;
20896 this_hi = this_low + 1;
20897 vec_add1 (low_ports, this_low);
20898 vec_add1 (high_ports, this_hi);
20899 }
20900 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
20901 {
20902 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
20903 {
20904 errmsg ("incorrect range parameters");
20905 return -99;
20906 }
20907 this_low = tmp;
20908 /* Note: in debug CLI +1 is added to high before
20909 passing to real fn that does "the work"
20910 (ip_source_and_port_range_check_add_del).
20911 This fn is a wrapper around the binary API fn a
20912 control plane will call, which expects this increment
20913 to have occurred. Hence letting the binary API control
20914 plane fn do the increment for consistency between VAT
20915 and other control planes.
20916 */
20917 this_hi = tmp2;
20918 vec_add1 (low_ports, this_low);
20919 vec_add1 (high_ports, this_hi);
20920 }
20921 else
20922 break;
20923 }
20924
20925 if (prefix_set == 0)
20926 {
20927 errmsg ("<address>/<mask> not specified");
20928 return -99;
20929 }
20930
20931 if (vrf_id == ~0)
20932 {
20933 errmsg ("VRF ID required, not specified");
20934 return -99;
20935 }
20936
20937 if (vrf_id == 0)
20938 {
20939 errmsg
20940 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
20941 return -99;
20942 }
20943
20944 if (vec_len (low_ports) == 0)
20945 {
20946 errmsg ("At least one port or port range required");
20947 return -99;
20948 }
20949
Jon Loeliger8a2aea32017-01-31 13:19:40 -060020950 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010020951
20952 mp->is_add = is_add;
20953
Neale Ranns37029302018-08-10 05:30:06 -070020954 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
Damjan Marion7cd468a2016-12-19 23:05:39 +010020955
Damjan Marion7cd468a2016-12-19 23:05:39 +010020956 mp->number_of_ranges = vec_len (low_ports);
20957
20958 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
20959 vec_free (low_ports);
20960
20961 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
20962 vec_free (high_ports);
20963
20964 mp->vrf_id = ntohl (vrf_id);
20965
Jon Loeliger7bc770c2017-01-31 14:03:33 -060020966 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060020967 W (ret);
20968 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020969}
20970
20971int
20972api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
20973{
20974 unformat_input_t *input = vam->input;
20975 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020976 u32 sw_if_index = ~0;
20977 int vrf_set = 0;
20978 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
20979 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
20980 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060020981 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010020982
20983 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
20984 {
20985 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
20986 ;
20987 else if (unformat (input, "sw_if_index %d", &sw_if_index))
20988 ;
20989 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
20990 vrf_set = 1;
20991 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
20992 vrf_set = 1;
20993 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
20994 vrf_set = 1;
20995 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
20996 vrf_set = 1;
20997 else if (unformat (input, "del"))
20998 is_add = 0;
20999 else
21000 break;
21001 }
21002
21003 if (sw_if_index == ~0)
21004 {
21005 errmsg ("Interface required but not specified");
21006 return -99;
21007 }
21008
21009 if (vrf_set == 0)
21010 {
21011 errmsg ("VRF ID required but not specified");
21012 return -99;
21013 }
21014
21015 if (tcp_out_vrf_id == 0
21016 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
21017 {
21018 errmsg
21019 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
21020 return -99;
21021 }
21022
21023 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021024 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021025
21026 mp->sw_if_index = ntohl (sw_if_index);
21027 mp->is_add = is_add;
21028 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
21029 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
21030 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
21031 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
21032
21033 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021034 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021035
21036 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060021037 W (ret);
21038 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021039}
21040
21041static int
21042api_ipsec_gre_add_del_tunnel (vat_main_t * vam)
21043{
21044 unformat_input_t *i = vam->input;
21045 vl_api_ipsec_gre_add_del_tunnel_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021046 u32 local_sa_id = 0;
21047 u32 remote_sa_id = 0;
21048 ip4_address_t src_address;
21049 ip4_address_t dst_address;
21050 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021051 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021052
21053 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21054 {
21055 if (unformat (i, "local_sa %d", &local_sa_id))
21056 ;
21057 else if (unformat (i, "remote_sa %d", &remote_sa_id))
21058 ;
21059 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
21060 ;
21061 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
21062 ;
21063 else if (unformat (i, "del"))
21064 is_add = 0;
21065 else
21066 {
21067 clib_warning ("parse error '%U'", format_unformat_error, i);
21068 return -99;
21069 }
21070 }
21071
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021072 M (IPSEC_GRE_ADD_DEL_TUNNEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021073
21074 mp->local_sa_id = ntohl (local_sa_id);
21075 mp->remote_sa_id = ntohl (remote_sa_id);
21076 clib_memcpy (mp->src_address, &src_address, sizeof (src_address));
21077 clib_memcpy (mp->dst_address, &dst_address, sizeof (dst_address));
21078 mp->is_add = is_add;
21079
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021080 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021081 W (ret);
21082 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021083}
21084
21085static int
Pavel Kotuceke88865d2018-11-28 07:42:11 +010021086api_set_punt (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010021087{
21088 unformat_input_t *i = vam->input;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010021089 vl_api_set_punt_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021090 u32 ipv = ~0;
21091 u32 protocol = ~0;
21092 u32 port = ~0;
21093 int is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021094 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021095
21096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21097 {
21098 if (unformat (i, "ip %d", &ipv))
21099 ;
21100 else if (unformat (i, "protocol %d", &protocol))
21101 ;
21102 else if (unformat (i, "port %d", &port))
21103 ;
21104 else if (unformat (i, "del"))
21105 is_add = 0;
21106 else
21107 {
21108 clib_warning ("parse error '%U'", format_unformat_error, i);
21109 return -99;
21110 }
21111 }
21112
Pavel Kotuceke88865d2018-11-28 07:42:11 +010021113 M (SET_PUNT, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021114
21115 mp->is_add = (u8) is_add;
Pavel Kotuceke88865d2018-11-28 07:42:11 +010021116 mp->punt.ipv = (u8) ipv;
21117 mp->punt.l4_protocol = (u8) protocol;
21118 mp->punt.l4_port = htons ((u16) port);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021119
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021120 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021121 W (ret);
21122 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021123}
21124
21125static void vl_api_ipsec_gre_tunnel_details_t_handler
21126 (vl_api_ipsec_gre_tunnel_details_t * mp)
21127{
21128 vat_main_t *vam = &vat_main;
21129
21130 print (vam->ofp, "%11d%15U%15U%14d%14d",
21131 ntohl (mp->sw_if_index),
21132 format_ip4_address, &mp->src_address,
21133 format_ip4_address, &mp->dst_address,
21134 ntohl (mp->local_sa_id), ntohl (mp->remote_sa_id));
21135}
21136
21137static void vl_api_ipsec_gre_tunnel_details_t_handler_json
21138 (vl_api_ipsec_gre_tunnel_details_t * mp)
21139{
21140 vat_main_t *vam = &vat_main;
21141 vat_json_node_t *node = NULL;
21142 struct in_addr ip4;
21143
21144 if (VAT_JSON_ARRAY != vam->json_tree.type)
21145 {
21146 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
21147 vat_json_init_array (&vam->json_tree);
21148 }
21149 node = vat_json_array_add (&vam->json_tree);
21150
21151 vat_json_init_object (node);
21152 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
21153 clib_memcpy (&ip4, &mp->src_address, sizeof (ip4));
21154 vat_json_object_add_ip4 (node, "src_address", ip4);
21155 clib_memcpy (&ip4, &mp->dst_address, sizeof (ip4));
21156 vat_json_object_add_ip4 (node, "dst_address", ip4);
21157 vat_json_object_add_uint (node, "local_sa_id", ntohl (mp->local_sa_id));
21158 vat_json_object_add_uint (node, "remote_sa_id", ntohl (mp->remote_sa_id));
21159}
21160
21161static int
21162api_ipsec_gre_tunnel_dump (vat_main_t * vam)
21163{
21164 unformat_input_t *i = vam->input;
21165 vl_api_ipsec_gre_tunnel_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021166 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021167 u32 sw_if_index;
21168 u8 sw_if_index_set = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021169 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021170
21171 /* Parse args required to build the message */
21172 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21173 {
21174 if (unformat (i, "sw_if_index %d", &sw_if_index))
21175 sw_if_index_set = 1;
21176 else
21177 break;
21178 }
21179
21180 if (sw_if_index_set == 0)
21181 {
21182 sw_if_index = ~0;
21183 }
21184
21185 if (!vam->json_output)
21186 {
21187 print (vam->ofp, "%11s%15s%15s%14s%14s",
21188 "sw_if_index", "src_address", "dst_address",
21189 "local_sa_id", "remote_sa_id");
21190 }
21191
21192 /* Get list of gre-tunnel interfaces */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021193 M (IPSEC_GRE_TUNNEL_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021194
21195 mp->sw_if_index = htonl (sw_if_index);
21196
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021197 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021198
21199 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040021200 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021201 S (mp_ping);
21202
Jon Loeliger56c7b012017-02-01 12:31:41 -060021203 W (ret);
21204 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021205}
21206
21207static int
21208api_delete_subif (vat_main_t * vam)
21209{
21210 unformat_input_t *i = vam->input;
21211 vl_api_delete_subif_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021212 u32 sw_if_index = ~0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021213 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021214
21215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21216 {
21217 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21218 ;
21219 if (unformat (i, "sw_if_index %d", &sw_if_index))
21220 ;
21221 else
21222 break;
21223 }
21224
21225 if (sw_if_index == ~0)
21226 {
21227 errmsg ("missing sw_if_index");
21228 return -99;
21229 }
21230
21231 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021232 M (DELETE_SUBIF, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021233 mp->sw_if_index = ntohl (sw_if_index);
21234
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021235 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021236 W (ret);
21237 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021238}
21239
21240#define foreach_pbb_vtr_op \
21241_("disable", L2_VTR_DISABLED) \
21242_("pop", L2_VTR_POP_2) \
21243_("push", L2_VTR_PUSH_2)
21244
21245static int
21246api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
21247{
21248 unformat_input_t *i = vam->input;
21249 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021250 u32 sw_if_index = ~0, vtr_op = ~0;
21251 u16 outer_tag = ~0;
21252 u8 dmac[6], smac[6];
21253 u8 dmac_set = 0, smac_set = 0;
21254 u16 vlanid = 0;
21255 u32 sid = ~0;
21256 u32 tmp;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021257 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021258
21259 /* Shut up coverity */
Dave Barachb7b92992018-10-17 10:38:51 -040021260 clib_memset (dmac, 0, sizeof (dmac));
21261 clib_memset (smac, 0, sizeof (smac));
Damjan Marion7cd468a2016-12-19 23:05:39 +010021262
21263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21264 {
21265 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21266 ;
21267 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21268 ;
21269 else if (unformat (i, "vtr_op %d", &vtr_op))
21270 ;
21271#define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
21272 foreach_pbb_vtr_op
21273#undef _
21274 else if (unformat (i, "translate_pbb_stag"))
21275 {
21276 if (unformat (i, "%d", &tmp))
21277 {
21278 vtr_op = L2_VTR_TRANSLATE_2_1;
21279 outer_tag = tmp;
21280 }
21281 else
21282 {
21283 errmsg
21284 ("translate_pbb_stag operation requires outer tag definition");
21285 return -99;
21286 }
21287 }
21288 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
21289 dmac_set++;
21290 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
21291 smac_set++;
21292 else if (unformat (i, "sid %d", &sid))
21293 ;
21294 else if (unformat (i, "vlanid %d", &tmp))
21295 vlanid = tmp;
21296 else
21297 {
21298 clib_warning ("parse error '%U'", format_unformat_error, i);
21299 return -99;
21300 }
21301 }
21302
21303 if ((sw_if_index == ~0) || (vtr_op == ~0))
21304 {
21305 errmsg ("missing sw_if_index or vtr operation");
21306 return -99;
21307 }
21308 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
21309 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
21310 {
21311 errmsg
21312 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
21313 return -99;
21314 }
21315
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021316 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021317 mp->sw_if_index = ntohl (sw_if_index);
21318 mp->vtr_op = ntohl (vtr_op);
21319 mp->outer_tag = ntohs (outer_tag);
21320 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
21321 clib_memcpy (mp->b_smac, smac, sizeof (smac));
21322 mp->b_vlanid = ntohs (vlanid);
21323 mp->i_sid = ntohl (sid);
21324
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021325 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021326 W (ret);
21327 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021328}
21329
21330static int
21331api_flow_classify_set_interface (vat_main_t * vam)
21332{
21333 unformat_input_t *i = vam->input;
21334 vl_api_flow_classify_set_interface_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021335 u32 sw_if_index;
21336 int sw_if_index_set;
21337 u32 ip4_table_index = ~0;
21338 u32 ip6_table_index = ~0;
21339 u8 is_add = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021340 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021341
21342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21343 {
21344 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21345 sw_if_index_set = 1;
21346 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21347 sw_if_index_set = 1;
21348 else if (unformat (i, "del"))
21349 is_add = 0;
21350 else if (unformat (i, "ip4-table %d", &ip4_table_index))
21351 ;
21352 else if (unformat (i, "ip6-table %d", &ip6_table_index))
21353 ;
21354 else
21355 {
21356 clib_warning ("parse error '%U'", format_unformat_error, i);
21357 return -99;
21358 }
21359 }
21360
21361 if (sw_if_index_set == 0)
21362 {
21363 errmsg ("missing interface name or sw_if_index");
21364 return -99;
21365 }
21366
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021367 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021368
21369 mp->sw_if_index = ntohl (sw_if_index);
21370 mp->ip4_table_index = ntohl (ip4_table_index);
21371 mp->ip6_table_index = ntohl (ip6_table_index);
21372 mp->is_add = is_add;
21373
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021374 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021375 W (ret);
21376 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021377}
21378
21379static int
21380api_flow_classify_dump (vat_main_t * vam)
21381{
21382 unformat_input_t *i = vam->input;
21383 vl_api_flow_classify_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021384 vl_api_control_ping_t *mp_ping;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021385 u8 type = FLOW_CLASSIFY_N_TABLES;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021386 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021387
21388 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
21389 ;
21390 else
21391 {
21392 errmsg ("classify table type must be specified");
21393 return -99;
21394 }
21395
21396 if (!vam->json_output)
21397 {
21398 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
21399 }
21400
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021401 M (FLOW_CLASSIFY_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021402 mp->type = type;
21403 /* send it... */
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021404 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021405
21406 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040021407 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021408 S (mp_ping);
21409
Damjan Marion7cd468a2016-12-19 23:05:39 +010021410 /* Wait for a reply... */
Jon Loeliger56c7b012017-02-01 12:31:41 -060021411 W (ret);
21412 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021413}
21414
21415static int
21416api_feature_enable_disable (vat_main_t * vam)
21417{
21418 unformat_input_t *i = vam->input;
21419 vl_api_feature_enable_disable_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021420 u8 *arc_name = 0;
21421 u8 *feature_name = 0;
21422 u32 sw_if_index = ~0;
21423 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021424 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021425
21426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21427 {
21428 if (unformat (i, "arc_name %s", &arc_name))
21429 ;
21430 else if (unformat (i, "feature_name %s", &feature_name))
21431 ;
21432 else
21433 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21434 ;
21435 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21436 ;
21437 else if (unformat (i, "disable"))
21438 enable = 0;
21439 else
21440 break;
21441 }
21442
21443 if (arc_name == 0)
21444 {
21445 errmsg ("missing arc name");
21446 return -99;
21447 }
21448 if (vec_len (arc_name) > 63)
21449 {
21450 errmsg ("arc name too long");
21451 }
21452
21453 if (feature_name == 0)
21454 {
21455 errmsg ("missing feature name");
21456 return -99;
21457 }
21458 if (vec_len (feature_name) > 63)
21459 {
21460 errmsg ("feature name too long");
21461 }
21462
21463 if (sw_if_index == ~0)
21464 {
21465 errmsg ("missing interface name or sw_if_index");
21466 return -99;
21467 }
21468
21469 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021470 M (FEATURE_ENABLE_DISABLE, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021471 mp->sw_if_index = ntohl (sw_if_index);
21472 mp->enable = enable;
21473 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
21474 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
21475 vec_free (arc_name);
21476 vec_free (feature_name);
21477
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021478 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021479 W (ret);
21480 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021481}
21482
21483static int
21484api_sw_interface_tag_add_del (vat_main_t * vam)
21485{
21486 unformat_input_t *i = vam->input;
21487 vl_api_sw_interface_tag_add_del_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021488 u32 sw_if_index = ~0;
21489 u8 *tag = 0;
21490 u8 enable = 1;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021491 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021492
21493 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21494 {
21495 if (unformat (i, "tag %s", &tag))
21496 ;
21497 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21498 ;
21499 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21500 ;
21501 else if (unformat (i, "del"))
21502 enable = 0;
21503 else
21504 break;
21505 }
21506
21507 if (sw_if_index == ~0)
21508 {
21509 errmsg ("missing interface name or sw_if_index");
21510 return -99;
21511 }
21512
21513 if (enable && (tag == 0))
21514 {
21515 errmsg ("no tag specified");
21516 return -99;
21517 }
21518
21519 /* Construct the API message */
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021520 M (SW_INTERFACE_TAG_ADD_DEL, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021521 mp->sw_if_index = ntohl (sw_if_index);
21522 mp->is_add = enable;
21523 if (enable)
21524 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
21525 vec_free (tag);
21526
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021527 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021528 W (ret);
21529 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021530}
21531
21532static void vl_api_l2_xconnect_details_t_handler
21533 (vl_api_l2_xconnect_details_t * mp)
21534{
21535 vat_main_t *vam = &vat_main;
21536
21537 print (vam->ofp, "%15d%15d",
21538 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
21539}
21540
21541static void vl_api_l2_xconnect_details_t_handler_json
21542 (vl_api_l2_xconnect_details_t * mp)
21543{
21544 vat_main_t *vam = &vat_main;
21545 vat_json_node_t *node = NULL;
21546
21547 if (VAT_JSON_ARRAY != vam->json_tree.type)
21548 {
21549 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
21550 vat_json_init_array (&vam->json_tree);
21551 }
21552 node = vat_json_array_add (&vam->json_tree);
21553
21554 vat_json_init_object (node);
21555 vat_json_object_add_uint (node, "rx_sw_if_index",
21556 ntohl (mp->rx_sw_if_index));
21557 vat_json_object_add_uint (node, "tx_sw_if_index",
21558 ntohl (mp->tx_sw_if_index));
21559}
21560
21561static int
21562api_l2_xconnect_dump (vat_main_t * vam)
21563{
21564 vl_api_l2_xconnect_dump_t *mp;
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021565 vl_api_control_ping_t *mp_ping;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021566 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021567
21568 if (!vam->json_output)
21569 {
21570 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
21571 }
21572
Jon Loeliger8a2aea32017-01-31 13:19:40 -060021573 M (L2_XCONNECT_DUMP, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021574
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021575 S (mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021576
21577 /* Use a control ping for synchronization */
Dave Barach59b25652017-09-10 15:04:27 -040021578 MPING (CONTROL_PING, mp_ping);
Jon Loeliger2d23eca2017-02-01 13:09:58 -060021579 S (mp_ping);
21580
Jon Loeliger56c7b012017-02-01 12:31:41 -060021581 W (ret);
21582 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021583}
21584
21585static int
Ole Troand7231612018-06-07 10:17:57 +020021586api_hw_interface_set_mtu (vat_main_t * vam)
Damjan Marion7cd468a2016-12-19 23:05:39 +010021587{
21588 unformat_input_t *i = vam->input;
Ole Troand7231612018-06-07 10:17:57 +020021589 vl_api_hw_interface_set_mtu_t *mp;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021590 u32 sw_if_index = ~0;
21591 u32 mtu = 0;
Jon Loeliger56c7b012017-02-01 12:31:41 -060021592 int ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021593
21594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21595 {
21596 if (unformat (i, "mtu %d", &mtu))
21597 ;
21598 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21599 ;
21600 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21601 ;
21602 else
21603 break;
21604 }
21605
21606 if (sw_if_index == ~0)
21607 {
21608 errmsg ("missing interface name or sw_if_index");
21609 return -99;
21610 }
21611
21612 if (mtu == 0)
21613 {
21614 errmsg ("no mtu specified");
21615 return -99;
21616 }
21617
21618 /* Construct the API message */
Ole Troand7231612018-06-07 10:17:57 +020021619 M (HW_INTERFACE_SET_MTU, mp);
Damjan Marion7cd468a2016-12-19 23:05:39 +010021620 mp->sw_if_index = ntohl (sw_if_index);
21621 mp->mtu = ntohs ((u16) mtu);
21622
Jon Loeliger7bc770c2017-01-31 14:03:33 -060021623 S (mp);
Jon Loeliger56c7b012017-02-01 12:31:41 -060021624 W (ret);
21625 return ret;
Damjan Marion7cd468a2016-12-19 23:05:39 +010021626}
21627
Pavel Kotucek6899a302017-06-08 08:46:10 +020021628static int
21629api_p2p_ethernet_add (vat_main_t * vam)
21630{
21631 unformat_input_t *i = vam->input;
21632 vl_api_p2p_ethernet_add_t *mp;
21633 u32 parent_if_index = ~0;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021634 u32 sub_id = ~0;
Pavel Kotucek6899a302017-06-08 08:46:10 +020021635 u8 remote_mac[6];
21636 u8 mac_set = 0;
21637 int ret;
21638
Dave Barachb7b92992018-10-17 10:38:51 -040021639 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020021640 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21641 {
21642 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
21643 ;
21644 else if (unformat (i, "sw_if_index %d", &parent_if_index))
21645 ;
21646 else
21647 if (unformat
21648 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
21649 mac_set++;
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021650 else if (unformat (i, "sub_id %d", &sub_id))
21651 ;
Pavel Kotucek6899a302017-06-08 08:46:10 +020021652 else
21653 {
21654 clib_warning ("parse error '%U'", format_unformat_error, i);
21655 return -99;
21656 }
21657 }
21658
21659 if (parent_if_index == ~0)
21660 {
21661 errmsg ("missing interface name or sw_if_index");
21662 return -99;
21663 }
21664 if (mac_set == 0)
21665 {
21666 errmsg ("missing remote mac address");
21667 return -99;
21668 }
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021669 if (sub_id == ~0)
21670 {
21671 errmsg ("missing sub-interface id");
21672 return -99;
21673 }
Pavel Kotucek6899a302017-06-08 08:46:10 +020021674
21675 M (P2P_ETHERNET_ADD, mp);
21676 mp->parent_if_index = ntohl (parent_if_index);
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020021677 mp->subif_id = ntohl (sub_id);
Pavel Kotucek6899a302017-06-08 08:46:10 +020021678 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
21679
21680 S (mp);
21681 W (ret);
21682 return ret;
21683}
21684
21685static int
21686api_p2p_ethernet_del (vat_main_t * vam)
21687{
21688 unformat_input_t *i = vam->input;
21689 vl_api_p2p_ethernet_del_t *mp;
21690 u32 parent_if_index = ~0;
21691 u8 remote_mac[6];
21692 u8 mac_set = 0;
21693 int ret;
21694
Dave Barachb7b92992018-10-17 10:38:51 -040021695 clib_memset (remote_mac, 0, sizeof (remote_mac));
Pavel Kotucek6899a302017-06-08 08:46:10 +020021696 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21697 {
21698 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
21699 ;
21700 else if (unformat (i, "sw_if_index %d", &parent_if_index))
21701 ;
21702 else
21703 if (unformat
21704 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
21705 mac_set++;
21706 else
21707 {
21708 clib_warning ("parse error '%U'", format_unformat_error, i);
21709 return -99;
21710 }
21711 }
21712
21713 if (parent_if_index == ~0)
21714 {
21715 errmsg ("missing interface name or sw_if_index");
21716 return -99;
21717 }
21718 if (mac_set == 0)
21719 {
21720 errmsg ("missing remote mac address");
21721 return -99;
21722 }
21723
21724 M (P2P_ETHERNET_DEL, mp);
21725 mp->parent_if_index = ntohl (parent_if_index);
21726 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
21727
21728 S (mp);
21729 W (ret);
21730 return ret;
21731}
Damjan Marion7cd468a2016-12-19 23:05:39 +010021732
21733static int
Steve Shin99a0e602017-07-01 04:16:20 +000021734api_lldp_config (vat_main_t * vam)
21735{
21736 unformat_input_t *i = vam->input;
21737 vl_api_lldp_config_t *mp;
21738 int tx_hold = 0;
21739 int tx_interval = 0;
21740 u8 *sys_name = NULL;
21741 int ret;
21742
21743 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21744 {
21745 if (unformat (i, "system-name %s", &sys_name))
21746 ;
21747 else if (unformat (i, "tx-hold %d", &tx_hold))
21748 ;
21749 else if (unformat (i, "tx-interval %d", &tx_interval))
21750 ;
21751 else
21752 {
21753 clib_warning ("parse error '%U'", format_unformat_error, i);
21754 return -99;
21755 }
21756 }
21757
21758 vec_add1 (sys_name, 0);
21759
21760 M (LLDP_CONFIG, mp);
21761 mp->tx_hold = htonl (tx_hold);
21762 mp->tx_interval = htonl (tx_interval);
21763 clib_memcpy (mp->system_name, sys_name, vec_len (sys_name));
21764 vec_free (sys_name);
21765
21766 S (mp);
21767 W (ret);
21768 return ret;
21769}
21770
21771static int
21772api_sw_interface_set_lldp (vat_main_t * vam)
21773{
21774 unformat_input_t *i = vam->input;
21775 vl_api_sw_interface_set_lldp_t *mp;
21776 u32 sw_if_index = ~0;
21777 u32 enable = 1;
Steve Shin9a6fcef2017-10-11 13:55:16 -070021778 u8 *port_desc = NULL, *mgmt_oid = NULL;
21779 ip4_address_t ip4_addr;
21780 ip6_address_t ip6_addr;
Steve Shin99a0e602017-07-01 04:16:20 +000021781 int ret;
21782
Dave Barachb7b92992018-10-17 10:38:51 -040021783 clib_memset (&ip4_addr, 0, sizeof (ip4_addr));
21784 clib_memset (&ip6_addr, 0, sizeof (ip6_addr));
Steve Shin9a6fcef2017-10-11 13:55:16 -070021785
Steve Shin99a0e602017-07-01 04:16:20 +000021786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21787 {
21788 if (unformat (i, "disable"))
21789 enable = 0;
21790 else
21791 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
21792 ;
21793 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21794 ;
21795 else if (unformat (i, "port-desc %s", &port_desc))
21796 ;
Steve Shin9a6fcef2017-10-11 13:55:16 -070021797 else if (unformat (i, "mgmt-ip4 %U", unformat_ip4_address, &ip4_addr))
21798 ;
21799 else if (unformat (i, "mgmt-ip6 %U", unformat_ip6_address, &ip6_addr))
21800 ;
21801 else if (unformat (i, "mgmt-oid %s", &mgmt_oid))
21802 ;
Steve Shin99a0e602017-07-01 04:16:20 +000021803 else
21804 break;
21805 }
21806
21807 if (sw_if_index == ~0)
21808 {
21809 errmsg ("missing interface name or sw_if_index");
21810 return -99;
21811 }
21812
21813 /* Construct the API message */
21814 vec_add1 (port_desc, 0);
Steve Shin9a6fcef2017-10-11 13:55:16 -070021815 vec_add1 (mgmt_oid, 0);
Steve Shin99a0e602017-07-01 04:16:20 +000021816 M (SW_INTERFACE_SET_LLDP, mp);
21817 mp->sw_if_index = ntohl (sw_if_index);
21818 mp->enable = enable;
21819 clib_memcpy (mp->port_desc, port_desc, vec_len (port_desc));
Steve Shin9a6fcef2017-10-11 13:55:16 -070021820 clib_memcpy (mp->mgmt_oid, mgmt_oid, vec_len (mgmt_oid));
21821 clib_memcpy (mp->mgmt_ip4, &ip4_addr, sizeof (ip4_addr));
21822 clib_memcpy (mp->mgmt_ip6, &ip6_addr, sizeof (ip6_addr));
Steve Shin99a0e602017-07-01 04:16:20 +000021823 vec_free (port_desc);
Steve Shin9a6fcef2017-10-11 13:55:16 -070021824 vec_free (mgmt_oid);
Steve Shin99a0e602017-07-01 04:16:20 +000021825
21826 S (mp);
21827 W (ret);
21828 return ret;
21829}
21830
21831static int
Dave Barach3bbcfab2017-08-15 19:03:44 -040021832api_tcp_configure_src_addresses (vat_main_t * vam)
21833{
21834 vl_api_tcp_configure_src_addresses_t *mp;
21835 unformat_input_t *i = vam->input;
21836 ip4_address_t v4first, v4last;
21837 ip6_address_t v6first, v6last;
21838 u8 range_set = 0;
21839 u32 vrf_id = 0;
21840 int ret;
21841
21842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21843 {
21844 if (unformat (i, "%U - %U",
21845 unformat_ip4_address, &v4first,
21846 unformat_ip4_address, &v4last))
21847 {
21848 if (range_set)
21849 {
21850 errmsg ("one range per message (range already set)");
21851 return -99;
21852 }
21853 range_set = 1;
21854 }
21855 else if (unformat (i, "%U - %U",
21856 unformat_ip6_address, &v6first,
21857 unformat_ip6_address, &v6last))
21858 {
21859 if (range_set)
21860 {
21861 errmsg ("one range per message (range already set)");
21862 return -99;
21863 }
21864 range_set = 2;
21865 }
21866 else if (unformat (i, "vrf %d", &vrf_id))
21867 ;
21868 else
21869 break;
21870 }
21871
21872 if (range_set == 0)
21873 {
21874 errmsg ("address range not set");
21875 return -99;
21876 }
21877
21878 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
21879 mp->vrf_id = ntohl (vrf_id);
21880 /* ipv6? */
21881 if (range_set == 2)
21882 {
21883 mp->is_ipv6 = 1;
21884 clib_memcpy (mp->first_address, &v6first, sizeof (v6first));
21885 clib_memcpy (mp->last_address, &v6last, sizeof (v6last));
21886 }
21887 else
21888 {
21889 mp->is_ipv6 = 0;
21890 clib_memcpy (mp->first_address, &v4first, sizeof (v4first));
21891 clib_memcpy (mp->last_address, &v4last, sizeof (v4last));
21892 }
21893 S (mp);
21894 W (ret);
21895 return ret;
21896}
21897
Florin Coras6e8c6672017-11-10 09:03:54 -080021898static void vl_api_app_namespace_add_del_reply_t_handler
21899 (vl_api_app_namespace_add_del_reply_t * mp)
21900{
21901 vat_main_t *vam = &vat_main;
21902 i32 retval = ntohl (mp->retval);
21903 if (vam->async_mode)
21904 {
21905 vam->async_errors += (retval < 0);
21906 }
21907 else
21908 {
21909 vam->retval = retval;
21910 if (retval == 0)
21911 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
21912 vam->result_ready = 1;
21913 }
21914}
21915
21916static void vl_api_app_namespace_add_del_reply_t_handler_json
21917 (vl_api_app_namespace_add_del_reply_t * mp)
21918{
21919 vat_main_t *vam = &vat_main;
21920 vat_json_node_t node;
21921
21922 vat_json_init_object (&node);
21923 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
21924 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
21925
21926 vat_json_print (vam->ofp, &node);
21927 vat_json_free (&node);
21928
21929 vam->retval = ntohl (mp->retval);
21930 vam->result_ready = 1;
21931}
21932
Dave Barach3bbcfab2017-08-15 19:03:44 -040021933static int
Florin Corascea194d2017-10-02 00:18:51 -070021934api_app_namespace_add_del (vat_main_t * vam)
21935{
21936 vl_api_app_namespace_add_del_t *mp;
21937 unformat_input_t *i = vam->input;
21938 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
21939 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
21940 u64 secret;
21941 int ret;
21942
21943 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21944 {
21945 if (unformat (i, "id %_%v%_", &ns_id))
21946 ;
21947 else if (unformat (i, "secret %lu", &secret))
21948 secret_set = 1;
21949 else if (unformat (i, "sw_if_index %d", &sw_if_index))
21950 sw_if_index_set = 1;
21951 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
21952 ;
21953 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
21954 ;
21955 else
21956 break;
21957 }
21958 if (!ns_id || !secret_set || !sw_if_index_set)
21959 {
21960 errmsg ("namespace id, secret and sw_if_index must be set");
21961 return -99;
21962 }
21963 if (vec_len (ns_id) > 64)
21964 {
21965 errmsg ("namespace id too long");
21966 return -99;
21967 }
21968 M (APP_NAMESPACE_ADD_DEL, mp);
21969
21970 clib_memcpy (mp->namespace_id, ns_id, vec_len (ns_id));
21971 mp->namespace_id_len = vec_len (ns_id);
Florin Coras9a9adb22017-10-26 08:16:59 -070021972 mp->secret = clib_host_to_net_u64 (secret);
Florin Corascea194d2017-10-02 00:18:51 -070021973 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
21974 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
21975 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
21976 vec_free (ns_id);
21977 S (mp);
21978 W (ret);
21979 return ret;
21980}
21981
21982static int
Florin Coras90a63982017-12-19 04:50:01 -080021983api_sock_init_shm (vat_main_t * vam)
21984{
21985#if VPP_API_TEST_BUILTIN == 0
21986 unformat_input_t *i = vam->input;
21987 vl_api_shm_elem_config_t *config = 0;
21988 u64 size = 64 << 20;
21989 int rv;
21990
21991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
21992 {
21993 if (unformat (i, "size %U", unformat_memory_size, &size))
21994 ;
21995 else
21996 break;
21997 }
21998
Dave Barach78958722018-05-10 16:44:27 -040021999 /*
22000 * Canned custom ring allocator config.
22001 * Should probably parse all of this
22002 */
22003 vec_validate (config, 6);
Florin Coras90a63982017-12-19 04:50:01 -080022004 config[0].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080022005 config[0].size = 256;
Dave Barach78958722018-05-10 16:44:27 -040022006 config[0].count = 32;
22007
22008 config[1].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080022009 config[1].size = 1024;
Dave Barach78958722018-05-10 16:44:27 -040022010 config[1].count = 16;
22011
22012 config[2].type = VL_API_VLIB_RING;
Florin Coras90a63982017-12-19 04:50:01 -080022013 config[2].size = 4096;
Dave Barach78958722018-05-10 16:44:27 -040022014 config[2].count = 2;
22015
22016 config[3].type = VL_API_CLIENT_RING;
22017 config[3].size = 256;
22018 config[3].count = 32;
22019
22020 config[4].type = VL_API_CLIENT_RING;
22021 config[4].size = 1024;
22022 config[4].count = 16;
22023
22024 config[5].type = VL_API_CLIENT_RING;
22025 config[5].size = 4096;
22026 config[5].count = 2;
22027
22028 config[6].type = VL_API_QUEUE;
22029 config[6].count = 128;
22030 config[6].size = sizeof (uword);
22031
Tomasz Kulasek97dcf5b2019-01-31 18:26:32 +010022032 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
Florin Coras90a63982017-12-19 04:50:01 -080022033 if (!rv)
22034 vam->client_index_invalid = 1;
22035 return rv;
22036#else
22037 return -99;
22038#endif
22039}
22040
22041static int
Dave Barach65457162017-10-10 17:53:14 -040022042api_dns_enable_disable (vat_main_t * vam)
22043{
22044 unformat_input_t *line_input = vam->input;
22045 vl_api_dns_enable_disable_t *mp;
22046 u8 enable_disable = 1;
22047 int ret;
22048
22049 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
22050 {
22051 if (unformat (line_input, "disable"))
22052 enable_disable = 0;
22053 if (unformat (line_input, "enable"))
22054 enable_disable = 1;
22055 else
22056 break;
22057 }
22058
22059 /* Construct the API message */
22060 M (DNS_ENABLE_DISABLE, mp);
22061 mp->enable = enable_disable;
22062
22063 /* send it... */
22064 S (mp);
22065 /* Wait for the reply */
22066 W (ret);
22067 return ret;
22068}
22069
22070static int
22071api_dns_resolve_name (vat_main_t * vam)
22072{
22073 unformat_input_t *line_input = vam->input;
22074 vl_api_dns_resolve_name_t *mp;
22075 u8 *name = 0;
22076 int ret;
22077
22078 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
22079 {
22080 if (unformat (line_input, "%s", &name))
22081 ;
22082 else
22083 break;
22084 }
22085
22086 if (vec_len (name) > 127)
22087 {
22088 errmsg ("name too long");
22089 return -99;
22090 }
22091
22092 /* Construct the API message */
22093 M (DNS_RESOLVE_NAME, mp);
22094 memcpy (mp->name, name, vec_len (name));
22095 vec_free (name);
22096
22097 /* send it... */
22098 S (mp);
22099 /* Wait for the reply */
22100 W (ret);
22101 return ret;
22102}
22103
22104static int
Dave Barachd2080152017-10-20 09:21:35 -040022105api_dns_resolve_ip (vat_main_t * vam)
22106{
22107 unformat_input_t *line_input = vam->input;
22108 vl_api_dns_resolve_ip_t *mp;
22109 int is_ip6 = -1;
22110 ip4_address_t addr4;
22111 ip6_address_t addr6;
22112 int ret;
22113
22114 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
22115 {
22116 if (unformat (line_input, "%U", unformat_ip6_address, &addr6))
22117 is_ip6 = 1;
22118 else if (unformat (line_input, "%U", unformat_ip4_address, &addr4))
22119 is_ip6 = 0;
22120 else
22121 break;
22122 }
22123
22124 if (is_ip6 == -1)
22125 {
22126 errmsg ("missing address");
22127 return -99;
22128 }
22129
22130 /* Construct the API message */
22131 M (DNS_RESOLVE_IP, mp);
22132 mp->is_ip6 = is_ip6;
22133 if (is_ip6)
22134 memcpy (mp->address, &addr6, sizeof (addr6));
22135 else
22136 memcpy (mp->address, &addr4, sizeof (addr4));
22137
22138 /* send it... */
22139 S (mp);
22140 /* Wait for the reply */
22141 W (ret);
22142 return ret;
22143}
22144
22145static int
Dave Barach65457162017-10-10 17:53:14 -040022146api_dns_name_server_add_del (vat_main_t * vam)
22147{
22148 unformat_input_t *i = vam->input;
22149 vl_api_dns_name_server_add_del_t *mp;
22150 u8 is_add = 1;
22151 ip6_address_t ip6_server;
22152 ip4_address_t ip4_server;
22153 int ip6_set = 0;
22154 int ip4_set = 0;
22155 int ret = 0;
22156
22157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
22158 {
22159 if (unformat (i, "%U", unformat_ip6_address, &ip6_server))
22160 ip6_set = 1;
22161 else if (unformat (i, "%U", unformat_ip4_address, &ip4_server))
22162 ip4_set = 1;
22163 else if (unformat (i, "del"))
22164 is_add = 0;
22165 else
22166 {
22167 clib_warning ("parse error '%U'", format_unformat_error, i);
22168 return -99;
22169 }
22170 }
22171
22172 if (ip4_set && ip6_set)
22173 {
22174 errmsg ("Only one server address allowed per message");
22175 return -99;
22176 }
22177 if ((ip4_set + ip6_set) == 0)
22178 {
22179 errmsg ("Server address required");
22180 return -99;
22181 }
22182
22183 /* Construct the API message */
22184 M (DNS_NAME_SERVER_ADD_DEL, mp);
22185
22186 if (ip6_set)
22187 {
22188 memcpy (mp->server_address, &ip6_server, sizeof (ip6_address_t));
22189 mp->is_ip6 = 1;
22190 }
22191 else
22192 {
22193 memcpy (mp->server_address, &ip4_server, sizeof (ip4_address_t));
22194 mp->is_ip6 = 0;
22195 }
22196
22197 mp->is_add = is_add;
22198
22199 /* send it... */
22200 S (mp);
22201
22202 /* Wait for a reply, return good/bad news */
22203 W (ret);
22204 return ret;
22205}
22206
Florin Coras6c36f532017-11-03 18:32:34 -070022207static void
22208vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
22209{
22210 vat_main_t *vam = &vat_main;
22211
22212 if (mp->is_ip4)
22213 {
Florin Corasc97a7392017-11-05 23:07:07 -080022214 print (vam->ofp,
22215 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080022216 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
22217 mp->scope, format_ip4_address, &mp->lcl_ip, mp->lcl_plen,
22218 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
22219 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
22220 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070022221 }
22222 else
22223 {
Florin Corasc97a7392017-11-05 23:07:07 -080022224 print (vam->ofp,
22225 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
Steven85dbac02017-11-07 16:29:53 -080022226 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
22227 mp->scope, format_ip6_address, &mp->lcl_ip, mp->lcl_plen,
22228 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
22229 &mp->rmt_ip, mp->rmt_plen, clib_net_to_host_u16 (mp->rmt_port),
22230 clib_net_to_host_u32 (mp->action_index), mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070022231 }
22232}
22233
22234static void
22235vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
22236 mp)
22237{
22238 vat_main_t *vam = &vat_main;
22239 vat_json_node_t *node = NULL;
22240 struct in6_addr ip6;
22241 struct in_addr ip4;
22242
22243 if (VAT_JSON_ARRAY != vam->json_tree.type)
22244 {
22245 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
22246 vat_json_init_array (&vam->json_tree);
22247 }
22248 node = vat_json_array_add (&vam->json_tree);
22249 vat_json_init_object (node);
22250
22251 vat_json_object_add_uint (node, "is_ip4", mp->is_ip4 ? 1 : 0);
22252 vat_json_object_add_uint (node, "appns_index",
22253 clib_net_to_host_u32 (mp->appns_index));
22254 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
22255 vat_json_object_add_uint (node, "scope", mp->scope);
22256 vat_json_object_add_uint (node, "action_index",
22257 clib_net_to_host_u32 (mp->action_index));
22258 vat_json_object_add_uint (node, "lcl_port",
22259 clib_net_to_host_u16 (mp->lcl_port));
22260 vat_json_object_add_uint (node, "rmt_port",
22261 clib_net_to_host_u16 (mp->rmt_port));
22262 vat_json_object_add_uint (node, "lcl_plen", mp->lcl_plen);
22263 vat_json_object_add_uint (node, "rmt_plen", mp->rmt_plen);
Florin Corasc97a7392017-11-05 23:07:07 -080022264 vat_json_object_add_string_copy (node, "tag", mp->tag);
Florin Coras6c36f532017-11-03 18:32:34 -070022265 if (mp->is_ip4)
22266 {
22267 clib_memcpy (&ip4, mp->lcl_ip, sizeof (ip4));
22268 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
22269 clib_memcpy (&ip4, mp->rmt_ip, sizeof (ip4));
22270 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
22271 }
22272 else
22273 {
22274 clib_memcpy (&ip6, mp->lcl_ip, sizeof (ip6));
22275 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
22276 clib_memcpy (&ip6, mp->rmt_ip, sizeof (ip6));
22277 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
22278 }
22279}
22280
Florin Coras1c710452017-10-17 00:03:13 -070022281static int
22282api_session_rule_add_del (vat_main_t * vam)
22283{
22284 vl_api_session_rule_add_del_t *mp;
22285 unformat_input_t *i = vam->input;
22286 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
22287 u32 appns_index = 0, scope = 0;
22288 ip4_address_t lcl_ip4, rmt_ip4;
22289 ip6_address_t lcl_ip6, rmt_ip6;
22290 u8 is_ip4 = 1, conn_set = 0;
Florin Corasc97a7392017-11-05 23:07:07 -080022291 u8 is_add = 1, *tag = 0;
Florin Coras1c710452017-10-17 00:03:13 -070022292 int ret;
22293
22294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
22295 {
22296 if (unformat (i, "del"))
22297 is_add = 0;
22298 else if (unformat (i, "add"))
22299 ;
22300 else if (unformat (i, "proto tcp"))
22301 proto = 0;
22302 else if (unformat (i, "proto udp"))
22303 proto = 1;
22304 else if (unformat (i, "appns %d", &appns_index))
22305 ;
22306 else if (unformat (i, "scope %d", &scope))
22307 ;
Florin Corasc97a7392017-11-05 23:07:07 -080022308 else if (unformat (i, "tag %_%v%_", &tag))
22309 ;
Florin Coras1c710452017-10-17 00:03:13 -070022310 else
22311 if (unformat
22312 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
22313 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
22314 &rmt_port))
22315 {
22316 is_ip4 = 1;
22317 conn_set = 1;
22318 }
22319 else
22320 if (unformat
22321 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
22322 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
22323 &rmt_port))
22324 {
22325 is_ip4 = 0;
22326 conn_set = 1;
22327 }
22328 else if (unformat (i, "action %d", &action))
22329 ;
22330 else
22331 break;
22332 }
22333 if (proto == ~0 || !conn_set || action == ~0)
22334 {
22335 errmsg ("transport proto, connection and action must be set");
22336 return -99;
22337 }
22338
22339 if (scope > 3)
22340 {
22341 errmsg ("scope should be 0-3");
22342 return -99;
22343 }
22344
22345 M (SESSION_RULE_ADD_DEL, mp);
22346
22347 mp->is_ip4 = is_ip4;
22348 mp->transport_proto = proto;
Florin Corasc97a7392017-11-05 23:07:07 -080022349 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
22350 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
22351 mp->lcl_plen = lcl_plen;
22352 mp->rmt_plen = rmt_plen;
Florin Coras1c710452017-10-17 00:03:13 -070022353 mp->action_index = clib_host_to_net_u32 (action);
22354 mp->appns_index = clib_host_to_net_u32 (appns_index);
22355 mp->scope = scope;
22356 mp->is_add = is_add;
22357 if (is_ip4)
22358 {
22359 clib_memcpy (mp->lcl_ip, &lcl_ip4, sizeof (lcl_ip4));
22360 clib_memcpy (mp->rmt_ip, &rmt_ip4, sizeof (rmt_ip4));
22361 }
22362 else
22363 {
22364 clib_memcpy (mp->lcl_ip, &lcl_ip6, sizeof (lcl_ip6));
22365 clib_memcpy (mp->rmt_ip, &rmt_ip6, sizeof (rmt_ip6));
22366 }
Florin Corasc97a7392017-11-05 23:07:07 -080022367 if (tag)
22368 {
22369 clib_memcpy (mp->tag, tag, vec_len (tag));
22370 vec_free (tag);
22371 }
Florin Coras1c710452017-10-17 00:03:13 -070022372
22373 S (mp);
22374 W (ret);
22375 return ret;
22376}
Dave Barach65457162017-10-10 17:53:14 -040022377
22378static int
Florin Coras6c36f532017-11-03 18:32:34 -070022379api_session_rules_dump (vat_main_t * vam)
22380{
22381 vl_api_session_rules_dump_t *mp;
22382 vl_api_control_ping_t *mp_ping;
22383 int ret;
22384
22385 if (!vam->json_output)
22386 {
22387 print (vam->ofp, "%=20s", "Session Rules");
22388 }
22389
22390 M (SESSION_RULES_DUMP, mp);
22391 /* send it... */
22392 S (mp);
22393
22394 /* Use a control ping for synchronization */
22395 MPING (CONTROL_PING, mp_ping);
22396 S (mp_ping);
22397
22398 /* Wait for a reply... */
22399 W (ret);
22400 return ret;
22401}
22402
22403static int
Florin Coras595992c2017-11-06 17:17:08 -080022404api_ip_container_proxy_add_del (vat_main_t * vam)
22405{
22406 vl_api_ip_container_proxy_add_del_t *mp;
22407 unformat_input_t *i = vam->input;
Neale Ranns37029302018-08-10 05:30:06 -070022408 u32 sw_if_index = ~0;
22409 vl_api_prefix_t pfx = { };
Florin Coras595992c2017-11-06 17:17:08 -080022410 u8 is_add = 1;
22411 int ret;
22412
22413 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
22414 {
22415 if (unformat (i, "del"))
22416 is_add = 0;
22417 else if (unformat (i, "add"))
22418 ;
Neale Ranns37029302018-08-10 05:30:06 -070022419 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
22420 ;
Florin Coras595992c2017-11-06 17:17:08 -080022421 else if (unformat (i, "sw_if_index %u", &sw_if_index))
22422 ;
22423 else
22424 break;
22425 }
Neale Ranns37029302018-08-10 05:30:06 -070022426 if (sw_if_index == ~0 || pfx.address_length == 0)
Florin Coras595992c2017-11-06 17:17:08 -080022427 {
22428 errmsg ("address and sw_if_index must be set");
22429 return -99;
22430 }
22431
22432 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
22433
Florin Coras595992c2017-11-06 17:17:08 -080022434 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
Florin Coras595992c2017-11-06 17:17:08 -080022435 mp->is_add = is_add;
Neale Ranns37029302018-08-10 05:30:06 -070022436 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
Florin Coras595992c2017-11-06 17:17:08 -080022437
22438 S (mp);
22439 W (ret);
22440 return ret;
22441}
22442
22443static int
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070022444api_qos_record_enable_disable (vat_main_t * vam)
22445{
22446 unformat_input_t *i = vam->input;
22447 vl_api_qos_record_enable_disable_t *mp;
22448 u32 sw_if_index, qs = 0xff;
22449 u8 sw_if_index_set = 0;
22450 u8 enable = 1;
22451 int ret;
22452
22453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
22454 {
22455 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
22456 sw_if_index_set = 1;
22457 else if (unformat (i, "sw_if_index %d", &sw_if_index))
22458 sw_if_index_set = 1;
22459 else if (unformat (i, "%U", unformat_qos_source, &qs))
22460 ;
22461 else if (unformat (i, "disable"))
22462 enable = 0;
22463 else
22464 {
22465 clib_warning ("parse error '%U'", format_unformat_error, i);
22466 return -99;
22467 }
22468 }
22469
22470 if (sw_if_index_set == 0)
22471 {
22472 errmsg ("missing interface name or sw_if_index");
22473 return -99;
22474 }
22475 if (qs == 0xff)
22476 {
22477 errmsg ("input location must be specified");
22478 return -99;
22479 }
22480
22481 M (QOS_RECORD_ENABLE_DISABLE, mp);
22482
22483 mp->sw_if_index = ntohl (sw_if_index);
22484 mp->input_source = qs;
22485 mp->enable = enable;
22486
22487 S (mp);
22488 W (ret);
22489 return ret;
22490}
22491
Dave Barach048a4e52018-06-01 18:52:25 -040022492
Igor Mikhailov (imichail)582caa32018-04-26 21:33:02 -070022493static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010022494q_or_quit (vat_main_t * vam)
22495{
Dave Barachdef19da2017-02-22 17:29:20 -050022496#if VPP_API_TEST_BUILTIN == 0
Damjan Marion7cd468a2016-12-19 23:05:39 +010022497 longjmp (vam->jump_buf, 1);
Dave Barachdef19da2017-02-22 17:29:20 -050022498#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010022499 return 0; /* not so much */
22500}
22501
22502static int
22503q (vat_main_t * vam)
22504{
22505 return q_or_quit (vam);
22506}
22507
22508static int
22509quit (vat_main_t * vam)
22510{
22511 return q_or_quit (vam);
22512}
22513
22514static int
22515comment (vat_main_t * vam)
22516{
22517 return 0;
22518}
22519
22520static int
Dave Barach048a4e52018-06-01 18:52:25 -040022521statseg (vat_main_t * vam)
22522{
22523 ssvm_private_t *ssvmp = &vam->stat_segment;
22524 ssvm_shared_header_t *shared_header = ssvmp->sh;
22525 vlib_counter_t **counters;
22526 u64 thread0_index1_packets;
22527 u64 thread0_index1_bytes;
22528 f64 vector_rate, input_rate;
22529 uword *p;
22530
22531 uword *counter_vector_by_name;
22532 if (vam->stat_segment_lockp == 0)
22533 {
22534 errmsg ("Stat segment not mapped...");
22535 return -99;
22536 }
22537
22538 /* look up "/if/rx for sw_if_index 1 as a test */
22539
22540 clib_spinlock_lock (vam->stat_segment_lockp);
22541
22542 counter_vector_by_name = (uword *) shared_header->opaque[1];
22543
22544 p = hash_get_mem (counter_vector_by_name, "/if/rx");
22545 if (p == 0)
22546 {
22547 clib_spinlock_unlock (vam->stat_segment_lockp);
22548 errmsg ("/if/tx not found?");
22549 return -99;
22550 }
22551
22552 /* Fish per-thread vector of combined counters from shared memory */
22553 counters = (vlib_counter_t **) p[0];
22554
22555 if (vec_len (counters[0]) < 2)
22556 {
22557 clib_spinlock_unlock (vam->stat_segment_lockp);
22558 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
22559 return -99;
22560 }
22561
22562 /* Read thread 0 sw_if_index 1 counter */
22563 thread0_index1_packets = counters[0][1].packets;
22564 thread0_index1_bytes = counters[0][1].bytes;
22565
22566 p = hash_get_mem (counter_vector_by_name, "vector_rate");
22567 if (p == 0)
22568 {
22569 clib_spinlock_unlock (vam->stat_segment_lockp);
22570 errmsg ("vector_rate not found?");
22571 return -99;
22572 }
22573
22574 vector_rate = *(f64 *) (p[0]);
22575 p = hash_get_mem (counter_vector_by_name, "input_rate");
22576 if (p == 0)
22577 {
22578 clib_spinlock_unlock (vam->stat_segment_lockp);
22579 errmsg ("input_rate not found?");
22580 return -99;
22581 }
22582 input_rate = *(f64 *) (p[0]);
22583
22584 clib_spinlock_unlock (vam->stat_segment_lockp);
22585
22586 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
22587 vector_rate, input_rate);
22588 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
22589 thread0_index1_packets, thread0_index1_bytes);
22590
22591 return 0;
22592}
22593
22594static int
Damjan Marion7cd468a2016-12-19 23:05:39 +010022595cmd_cmp (void *a1, void *a2)
22596{
22597 u8 **c1 = a1;
22598 u8 **c2 = a2;
22599
22600 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
22601}
22602
22603static int
22604help (vat_main_t * vam)
22605{
22606 u8 **cmds = 0;
22607 u8 *name = 0;
22608 hash_pair_t *p;
22609 unformat_input_t *i = vam->input;
22610 int j;
22611
22612 if (unformat (i, "%s", &name))
22613 {
22614 uword *hs;
22615
22616 vec_add1 (name, 0);
22617
22618 hs = hash_get_mem (vam->help_by_name, name);
22619 if (hs)
22620 print (vam->ofp, "usage: %s %s", name, hs[0]);
22621 else
22622 print (vam->ofp, "No such msg / command '%s'", name);
22623 vec_free (name);
22624 return 0;
22625 }
22626
22627 print (vam->ofp, "Help is available for the following:");
22628
22629 /* *INDENT-OFF* */
22630 hash_foreach_pair (p, vam->function_by_name,
22631 ({
22632 vec_add1 (cmds, (u8 *)(p->key));
22633 }));
22634 /* *INDENT-ON* */
22635
22636 vec_sort_with_function (cmds, cmd_cmp);
22637
22638 for (j = 0; j < vec_len (cmds); j++)
22639 print (vam->ofp, "%s", cmds[j]);
22640
22641 vec_free (cmds);
22642 return 0;
22643}
22644
22645static int
22646set (vat_main_t * vam)
22647{
22648 u8 *name = 0, *value = 0;
22649 unformat_input_t *i = vam->input;
22650
22651 if (unformat (i, "%s", &name))
22652 {
22653 /* The input buffer is a vector, not a string. */
22654 value = vec_dup (i->buffer);
22655 vec_delete (value, i->index, 0);
22656 /* Almost certainly has a trailing newline */
22657 if (value[vec_len (value) - 1] == '\n')
22658 value[vec_len (value) - 1] = 0;
22659 /* Make sure it's a proper string, one way or the other */
22660 vec_add1 (value, 0);
22661 (void) clib_macro_set_value (&vam->macro_main,
22662 (char *) name, (char *) value);
22663 }
22664 else
22665 errmsg ("usage: set <name> <value>");
22666
22667 vec_free (name);
22668 vec_free (value);
22669 return 0;
22670}
22671
22672static int
22673unset (vat_main_t * vam)
22674{
22675 u8 *name = 0;
22676
22677 if (unformat (vam->input, "%s", &name))
22678 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
22679 errmsg ("unset: %s wasn't set", name);
22680 vec_free (name);
22681 return 0;
22682}
22683
22684typedef struct
22685{
22686 u8 *name;
22687 u8 *value;
22688} macro_sort_t;
22689
22690
22691static int
22692macro_sort_cmp (void *a1, void *a2)
22693{
22694 macro_sort_t *s1 = a1;
22695 macro_sort_t *s2 = a2;
22696
22697 return strcmp ((char *) (s1->name), (char *) (s2->name));
22698}
22699
22700static int
22701dump_macro_table (vat_main_t * vam)
22702{
22703 macro_sort_t *sort_me = 0, *sm;
22704 int i;
22705 hash_pair_t *p;
22706
22707 /* *INDENT-OFF* */
22708 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
22709 ({
22710 vec_add2 (sort_me, sm, 1);
22711 sm->name = (u8 *)(p->key);
22712 sm->value = (u8 *) (p->value[0]);
22713 }));
22714 /* *INDENT-ON* */
22715
22716 vec_sort_with_function (sort_me, macro_sort_cmp);
22717
22718 if (vec_len (sort_me))
22719 print (vam->ofp, "%-15s%s", "Name", "Value");
22720 else
22721 print (vam->ofp, "The macro table is empty...");
22722
22723 for (i = 0; i < vec_len (sort_me); i++)
22724 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
22725 return 0;
22726}
22727
22728static int
22729dump_node_table (vat_main_t * vam)
22730{
22731 int i, j;
22732 vlib_node_t *node, *next_node;
22733
22734 if (vec_len (vam->graph_nodes) == 0)
22735 {
22736 print (vam->ofp, "Node table empty, issue get_node_graph...");
22737 return 0;
22738 }
22739
Dave Barach1ddbc012018-06-13 09:26:05 -040022740 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
Damjan Marion7cd468a2016-12-19 23:05:39 +010022741 {
Dave Barach1ddbc012018-06-13 09:26:05 -040022742 node = vam->graph_nodes[0][i];
Damjan Marion7cd468a2016-12-19 23:05:39 +010022743 print (vam->ofp, "[%d] %s", i, node->name);
22744 for (j = 0; j < vec_len (node->next_nodes); j++)
22745 {
22746 if (node->next_nodes[j] != ~0)
22747 {
Dave Barach1ddbc012018-06-13 09:26:05 -040022748 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010022749 print (vam->ofp, " [%d] %s", j, next_node->name);
22750 }
22751 }
22752 }
22753 return 0;
22754}
22755
22756static int
22757value_sort_cmp (void *a1, void *a2)
22758{
22759 name_sort_t *n1 = a1;
22760 name_sort_t *n2 = a2;
22761
22762 if (n1->value < n2->value)
22763 return -1;
22764 if (n1->value > n2->value)
22765 return 1;
22766 return 0;
22767}
22768
22769
22770static int
22771dump_msg_api_table (vat_main_t * vam)
22772{
22773 api_main_t *am = &api_main;
22774 name_sort_t *nses = 0, *ns;
22775 hash_pair_t *hp;
22776 int i;
22777
22778 /* *INDENT-OFF* */
22779 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
22780 ({
22781 vec_add2 (nses, ns, 1);
22782 ns->name = (u8 *)(hp->key);
22783 ns->value = (u32) hp->value[0];
22784 }));
22785 /* *INDENT-ON* */
22786
22787 vec_sort_with_function (nses, value_sort_cmp);
22788
22789 for (i = 0; i < vec_len (nses); i++)
22790 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
22791 vec_free (nses);
22792 return 0;
22793}
22794
22795static int
22796get_msg_id (vat_main_t * vam)
22797{
22798 u8 *name_and_crc;
22799 u32 message_index;
22800
22801 if (unformat (vam->input, "%s", &name_and_crc))
22802 {
Florin Corase86a8ed2018-01-05 03:20:25 -080022803 message_index = vl_msg_api_get_msg_index (name_and_crc);
Damjan Marion7cd468a2016-12-19 23:05:39 +010022804 if (message_index == ~0)
22805 {
22806 print (vam->ofp, " '%s' not found", name_and_crc);
22807 return 0;
22808 }
22809 print (vam->ofp, " '%s' has message index %d",
22810 name_and_crc, message_index);
22811 return 0;
22812 }
22813 errmsg ("name_and_crc required...");
22814 return 0;
22815}
22816
22817static int
22818search_node_table (vat_main_t * vam)
22819{
22820 unformat_input_t *line_input = vam->input;
22821 u8 *node_to_find;
22822 int j;
22823 vlib_node_t *node, *next_node;
22824 uword *p;
22825
22826 if (vam->graph_node_index_by_name == 0)
22827 {
22828 print (vam->ofp, "Node table empty, issue get_node_graph...");
22829 return 0;
22830 }
22831
22832 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
22833 {
22834 if (unformat (line_input, "%s", &node_to_find))
22835 {
22836 vec_add1 (node_to_find, 0);
22837 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
22838 if (p == 0)
22839 {
22840 print (vam->ofp, "%s not found...", node_to_find);
22841 goto out;
22842 }
Dave Barach1ddbc012018-06-13 09:26:05 -040022843 node = vam->graph_nodes[0][p[0]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010022844 print (vam->ofp, "[%d] %s", p[0], node->name);
22845 for (j = 0; j < vec_len (node->next_nodes); j++)
22846 {
22847 if (node->next_nodes[j] != ~0)
22848 {
Dave Barach1ddbc012018-06-13 09:26:05 -040022849 next_node = vam->graph_nodes[0][node->next_nodes[j]];
Damjan Marion7cd468a2016-12-19 23:05:39 +010022850 print (vam->ofp, " [%d] %s", j, next_node->name);
22851 }
22852 }
22853 }
22854
22855 else
22856 {
22857 clib_warning ("parse error '%U'", format_unformat_error,
22858 line_input);
22859 return -99;
22860 }
22861
22862 out:
22863 vec_free (node_to_find);
22864
22865 }
22866
22867 return 0;
22868}
22869
22870
22871static int
22872script (vat_main_t * vam)
22873{
22874#if (VPP_API_TEST_BUILTIN==0)
22875 u8 *s = 0;
22876 char *save_current_file;
22877 unformat_input_t save_input;
22878 jmp_buf save_jump_buf;
22879 u32 save_line_number;
22880
22881 FILE *new_fp, *save_ifp;
22882
22883 if (unformat (vam->input, "%s", &s))
22884 {
22885 new_fp = fopen ((char *) s, "r");
22886 if (new_fp == 0)
22887 {
22888 errmsg ("Couldn't open script file %s", s);
22889 vec_free (s);
22890 return -99;
22891 }
22892 }
22893 else
22894 {
22895 errmsg ("Missing script name");
22896 return -99;
22897 }
22898
22899 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
22900 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
22901 save_ifp = vam->ifp;
22902 save_line_number = vam->input_line_number;
22903 save_current_file = (char *) vam->current_file;
22904
22905 vam->input_line_number = 0;
22906 vam->ifp = new_fp;
22907 vam->current_file = s;
22908 do_one_file (vam);
22909
Sirshak Dasb0861822018-05-29 21:13:21 -050022910 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
Damjan Marion7cd468a2016-12-19 23:05:39 +010022911 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
22912 vam->ifp = save_ifp;
22913 vam->input_line_number = save_line_number;
22914 vam->current_file = (u8 *) save_current_file;
22915 vec_free (s);
22916
22917 return 0;
22918#else
22919 clib_warning ("use the exec command...");
22920 return -99;
22921#endif
22922}
22923
22924static int
22925echo (vat_main_t * vam)
22926{
22927 print (vam->ofp, "%v", vam->input->buffer);
22928 return 0;
22929}
22930
22931/* List of API message constructors, CLI names map to api_xxx */
22932#define foreach_vpe_api_msg \
Jon Loeligerc83c3b72017-02-23 13:57:35 -060022933_(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022934_(sw_interface_dump,"") \
22935_(sw_interface_set_flags, \
22936 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
22937_(sw_interface_add_del_address, \
22938 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
Stevenad8015b2017-10-29 22:10:46 -070022939_(sw_interface_set_rx_mode, \
22940 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
Mohsin Kazmi54f7c512018-08-23 18:28:11 +020022941_(sw_interface_set_rx_placement, \
22942 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
Mohsin Kazmif0b42f42018-09-10 18:11:00 +020022943_(sw_interface_rx_placement_dump, \
22944 "[<intfc> | sw_if_index <id>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022945_(sw_interface_set_table, \
22946 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
22947_(sw_interface_set_mpls_enable, \
22948 "<intfc> | sw_if_index [disable | dis]") \
22949_(sw_interface_set_vpath, \
22950 "<intfc> | sw_if_index <id> enable | disable") \
22951_(sw_interface_set_vxlan_bypass, \
John Lo2b81eb82017-01-30 13:12:10 -050022952 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020022953_(sw_interface_set_geneve_bypass, \
22954 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022955_(sw_interface_set_l2_xconnect, \
22956 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
22957 "enable | disable") \
22958_(sw_interface_set_l2_bridge, \
Eyal Barif24991c2017-04-05 05:33:21 +030022959 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022960 "[shg <split-horizon-group>] [bvi]\n" \
22961 "enable | disable") \
Eyal Barif24991c2017-04-05 05:33:21 +030022962_(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022963_(bridge_domain_add_del, \
John Lo70bfcaf2017-11-14 13:19:26 -050022964 "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 +010022965_(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
22966_(l2fib_add_del, \
22967 "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 +030022968_(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
22969_(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022970_(l2_flags, \
John Lo8d00fff2017-08-03 00:35:36 -040022971 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022972_(bridge_flags, \
22973 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
Damjan Marion8389fb92017-10-13 18:29:53 +020022974_(tap_create_v2, \
Steven9e635692018-03-01 09:36:01 -080022975 "id <num> [hw-addr <mac-addr>] [host-ns <name>] [rx-ring-size <num> [tx-ring-size <num>]") \
Damjan Marion8389fb92017-10-13 18:29:53 +020022976_(tap_delete_v2, \
22977 "<vpp-if-name> | sw_if_index <id>") \
22978_(sw_interface_tap_v2_dump, "") \
Mohsin Kazmi03ae24b2019-01-18 11:50:00 +010022979_(virtio_pci_create, \
22980 "pci-addr <pci-address> [use_random_mac | hw-addr <mac-addr>] [tx-ring-size <num> [rx-ring-size <num>] [features <hex-value>]") \
22981_(virtio_pci_delete, \
22982 "<vpp-if-name> | sw_if_index <id>") \
22983_(sw_interface_virtio_pci_dump, "") \
Steven9cd2d7a2017-12-20 12:43:01 -080022984_(bond_create, \
22985 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
Alexander Chernavinad9d5282018-12-13 09:08:09 -050022986 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
22987 "[id <if-id>]") \
Steven9cd2d7a2017-12-20 12:43:01 -080022988_(bond_delete, \
22989 "<vpp-if-name> | sw_if_index <id>") \
22990_(bond_enslave, \
22991 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
22992_(bond_detach_slave, \
22993 "sw_if_index <n>") \
22994_(sw_interface_bond_dump, "") \
22995_(sw_interface_slave_dump, \
22996 "<vpp-if-name> | sw_if_index <id>") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070022997_(ip_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040022998 "table <n> [ipv6] [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010022999_(ip_add_del_route, \
John Lo22030432018-09-20 16:07:00 -040023000 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
23001 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
John Lo06fda9c2018-10-03 16:32:44 -040023002 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
23003 "[multipath] [count <n>] [del]") \
Neale Ranns32e1c012016-11-22 17:07:28 +000023004_(ip_mroute_add_del, \
23005 "<src> <grp>/<mask> [table-id <n>]\n" \
23006 "[<intfc> | sw_if_index <id>] [local] [del]") \
Neale Ranns28ab9cc2017-08-14 07:18:42 -070023007_(mpls_table_add_del, \
John Loe166fd92018-09-13 14:08:59 -040023008 "table <n> [add | del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023009_(mpls_route_add_del, \
John Loe166fd92018-09-13 14:08:59 -040023010 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
23011 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
23012 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
23013 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
John Lo06fda9c2018-10-03 16:32:44 -040023014 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
23015 "[count <n>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023016_(mpls_ip_bind_unbind, \
23017 "<label> <addr/len>") \
23018_(mpls_tunnel_add_del, \
John Lo06fda9c2018-10-03 16:32:44 -040023019 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
23020 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
23021 "[l2-only] [out-label <n>]") \
John Loe166fd92018-09-13 14:08:59 -040023022_(sr_mpls_policy_add, \
23023 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
23024_(sr_mpls_policy_del, \
23025 "bsid <id>") \
Neale Rannsd792d9c2017-10-21 10:53:20 -070023026_(bier_table_add_del, \
23027 "<label> <sub-domain> <set> <bsl> [del]") \
23028_(bier_route_add_del, \
23029 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
23030 "[<intfc> | sw_if_index <id>]" \
23031 "[weight <n>] [del] [multipath]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023032_(proxy_arp_add_del, \
23033 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
23034_(proxy_arp_intfc_enable_disable, \
23035 "<intfc> | sw_if_index <id> enable | disable") \
23036_(sw_interface_set_unnumbered, \
23037 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
23038_(ip_neighbor_add_del, \
23039 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
23040 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023041_(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
23042_(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
23043 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
23044 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
23045 "[outer_vlan_id_any][inner_vlan_id_any]") \
23046_(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
23047_(reset_fib, "vrf <n> [ipv6]") \
23048_(dhcp_proxy_config, \
23049 "svr <v46-address> src <v46-address>\n" \
Neale Ranns20a175a2017-02-14 07:28:41 -080023050 "rx_vrf_id <nn> server_vrf_id <nn> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023051_(dhcp_proxy_set_vss, \
John Lo70bfcaf2017-11-14 13:19:26 -050023052 "tbl_id <n> [fib_id <n> oui <n> | vpn_ascii_id <text>] [ipv6] [del]") \
Neale Ranns20a175a2017-02-14 07:28:41 -080023053_(dhcp_proxy_dump, "ip6") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023054_(dhcp_client_config, \
23055 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
23056_(set_ip_flow_hash, \
23057 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
23058_(sw_interface_ip6_enable_disable, \
23059 "<intfc> | sw_if_index <id> enable | disable") \
Neale Ranns3f844d02017-02-18 00:03:54 -080023060_(ip6nd_proxy_add_del, \
23061 "<intfc> | sw_if_index <id> <ip6-address>") \
23062_(ip6nd_proxy_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023063_(sw_interface_ip6nd_ra_prefix, \
23064 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
23065 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
23066 "[nolink] [isno]") \
23067_(sw_interface_ip6nd_ra_config, \
23068 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
23069 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
23070 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
23071_(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
23072_(l2_patch_add_del, \
23073 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
23074 "enable | disable") \
Pablo Camarillofb380952016-12-07 18:34:18 +010023075_(sr_localsid_add_del, \
23076 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
23077 "fib-table <num> (end.psp) sw_if_index <num>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023078_(classify_add_del_table, \
23079 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
23080 " [del] [del-chain] mask <mask-value>\n" \
23081 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
23082 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
23083_(classify_add_del_session, \
23084 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
23085 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
23086 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
23087 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
23088_(classify_set_interface_ip_table, \
23089 "<intfc> | sw_if_index <nn> table <nn>") \
23090_(classify_set_interface_l2_tables, \
23091 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
23092 " [other-table <nn>]") \
23093_(get_node_index, "node <node-name") \
23094_(add_node_next, "node <node-name> next <next-node-name>") \
23095_(l2tpv3_create_tunnel, \
23096 "client_address <ip6-addr> our_address <ip6-addr>\n" \
23097 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n" \
23098 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
23099_(l2tpv3_set_tunnel_cookies, \
23100 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
23101 "[new_remote_cookie <nn>]\n") \
23102_(l2tpv3_interface_enable_disable, \
23103 "<intfc> | sw_if_index <nn> enable | disable") \
23104_(l2tpv3_set_lookup_key, \
23105 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
23106_(sw_if_l2tpv3_tunnel_dump, "") \
eyal bariaf86a482018-04-17 11:20:27 +030023107_(vxlan_offload_rx, \
23108 "hw { <interface name> | hw_if_index <nn>} " \
23109 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023110_(vxlan_add_del_tunnel, \
23111 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
Jon Loeliger3d460bd2018-02-01 16:36:12 -060023112 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023113 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020023114_(geneve_add_del_tunnel, \
23115 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
23116 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
23117 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023118_(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Marco Varleseb598f1d2017-09-19 14:25:28 +020023119_(geneve_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023120_(gre_add_del_tunnel, \
John Loa43ccae2018-02-13 17:15:23 -050023121 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
23122 "[teb | erspan <session-id>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023123_(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
23124_(l2_fib_clear_table, "") \
23125_(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
23126_(l2_interface_vlan_tag_rewrite, \
23127 "<intfc> | sw_if_index <nn> \n" \
23128 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
23129 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
23130_(create_vhost_user_if, \
23131 "socket <filename> [server] [renumber <dev_instance>] " \
Mohsin Kazmiee2e58f2018-08-21 16:07:03 +020023132 "[disable_mrg_rxbuf] [disable_indirect_desc] " \
Stevenf3b53642017-05-01 14:03:02 -070023133 "[mac <mac_address>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023134_(modify_vhost_user_if, \
23135 "<intfc> | sw_if_index <nn> socket <filename>\n" \
Stevenf3b53642017-05-01 14:03:02 -070023136 "[server] [renumber <dev_instance>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023137_(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
23138_(sw_interface_vhost_user_dump, "") \
23139_(show_version, "") \
Mohsin Kazmi5d64c782018-09-11 20:27:09 +020023140_(show_threads, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023141_(vxlan_gpe_add_del_tunnel, \
Hongjun Ni04ffd0ad2017-06-23 00:18:40 +080023142 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
23143 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
23144 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
23145 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023146_(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
23147_(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
23148_(interface_name_renumber, \
23149 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
23150_(input_acl_set_interface, \
23151 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
23152 " [l2-table <nn>] [del]") \
John Loc7b43042018-04-13 16:46:22 -040023153_(ip_probe_neighbor, "(<intc> | sw_if_index <nn>) address <ip4|ip6-addr>") \
John Lo7f358b32018-04-28 01:19:24 -040023154_(ip_scan_neighbor_enable_disable, "[ip4|ip6|both|disable] [interval <n-min>]\n" \
23155 " [max-time <n-usec>] [max-update <n>] [delay <n-msec>] [stale <n-min>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023156_(want_ip4_arp_events, "address <ip4-address> [del]") \
23157_(want_ip6_nd_events, "address <ip6-address> [del]") \
John Lo8d00fff2017-08-03 00:35:36 -040023158_(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023159_(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
23160_(ip_dump, "ipv4 | ipv6") \
23161_(ipsec_spd_add_del, "spd_id <n> [del]") \
23162_(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
23163 " spid_id <n> ") \
Neale Ranns17dcec02019-01-09 21:22:20 -080023164_(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023165 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
23166 " integ_alg <alg> integ_key <hex>") \
Neale Ranns17dcec02019-01-09 21:22:20 -080023167_(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023168 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
23169 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
23170 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
23171_(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
Matthew Smithb0972cb2017-05-02 16:20:41 -050023172_(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
23173 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
23174 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
Matthew Smith8e1039a2018-04-12 07:32:56 -050023175 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
23176 " [instance <n>]") \
Matthew Smith28029532017-09-26 13:33:44 -050023177_(ipsec_sa_dump, "[sa_id <n>]") \
Matthew Smith75d85602017-10-05 19:03:05 -050023178_(ipsec_tunnel_if_set_key, "<intfc> <local|remote> <crypto|integ>\n" \
23179 " <alg> <hex>\n") \
Matthew Smithca514fd2017-10-12 12:06:59 -050023180_(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023181_(ikev2_profile_add_del, "name <profile_name> [del]") \
23182_(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
23183 "(auth_data 0x<data> | auth_data <data>)") \
23184_(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
23185 "(id_data 0x<data> | id_data <data>) (local|remote)") \
23186_(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
23187 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
23188 "(local|remote)") \
23189_(ikev2_set_local_key, "file <absolute_file_path>") \
Radu Nicolaucb33dc22017-02-16 16:49:46 +000023190_(ikev2_set_responder, "<profile_name> interface <interface> address <addr>") \
23191_(ikev2_set_ike_transforms, "<profile_name> <crypto alg> <key size> <integrity alg> <DH group>") \
23192_(ikev2_set_esp_transforms, "<profile_name> <crypto alg> <key size> <integrity alg> <DH group>") \
23193_(ikev2_set_sa_lifetime, "<profile_name> <seconds> <jitter> <handover> <max bytes>") \
23194_(ikev2_initiate_sa_init, "<profile_name>") \
23195_(ikev2_initiate_del_ike_sa, "<ispi>") \
23196_(ikev2_initiate_del_child_sa, "<ispi>") \
23197_(ikev2_initiate_rekey_child_sa, "<ispi>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023198_(delete_loopback,"sw_if_index <nn>") \
23199_(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
John Loe26c81f2019-01-07 15:16:33 -050023200_(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
23201_(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023202_(want_interface_events, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023203_(get_first_msg_id, "client <name>") \
23204_(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
23205_(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
23206 "fib-id <nn> [ip4][ip6][default]") \
23207_(get_node_graph, " ") \
23208_(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
23209_(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
23210_(ioam_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023211_(one_add_del_locator_set, "locator-set <locator_name> [iface <intf> |" \
23212 " sw_if_index <sw_if_index> p <priority> " \
23213 "w <weight>] [del]") \
23214_(one_add_del_locator, "locator-set <locator_name> " \
23215 "iface <intf> | sw_if_index <sw_if_index> " \
23216 "p <priority> w <weight> [del]") \
23217_(one_add_del_local_eid,"vni <vni> eid " \
23218 "<ipv4|ipv6>/<prefix> | <L2 address> " \
23219 "locator-set <locator_name> [del]" \
23220 "[key-id sha1|sha256 secret-key <secret-key>]")\
23221_(one_add_del_map_resolver, "<ip4|6-addr> [del]") \
23222_(one_add_del_map_server, "<ip4|6-addr> [del]") \
23223_(one_enable_disable, "enable|disable") \
23224_(one_map_register_enable_disable, "enable|disable") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020023225_(one_map_register_fallback_threshold, "<value>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023226_(one_rloc_probe_enable_disable, "enable|disable") \
23227_(one_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
23228 "[seid <seid>] " \
23229 "rloc <locator> p <prio> " \
23230 "w <weight> [rloc <loc> ... ] " \
23231 "action <action> [del-all]") \
23232_(one_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
23233 "<local-eid>") \
23234_(one_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010023235_(one_use_petr, "ip-address> | disable") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023236_(one_map_request_mode, "src-dst|dst-only") \
23237_(one_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
23238_(one_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
23239_(one_locator_set_dump, "[local | remote]") \
23240_(one_locator_dump, "ls_index <index> | ls_name <name>") \
23241_(one_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
23242 "[local] | [remote]") \
Filip Tehlar05879992017-09-05 15:46:09 +020023243_(one_add_del_ndp_entry, "[del] mac <mac> bd <bd> ip6 <ip6>") \
23244_(one_ndp_bd_get, "") \
23245_(one_ndp_entries_get, "bd <bridge-domain>") \
Filip Tehlard5a65db2017-05-17 17:21:10 +020023246_(one_add_del_l2_arp_entry, "[del] mac <mac> bd <bd> ip4 <ip4>") \
23247_(one_l2_arp_bd_get, "") \
23248_(one_l2_arp_entries_get, "bd <bridge-domain>") \
Paul Vinciguerraec11b132018-09-24 05:25:00 -070023249_(one_stats_enable_disable, "enable|disable") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010023250_(show_one_stats_enable_disable, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023251_(one_eid_table_vni_dump, "") \
23252_(one_eid_table_map_dump, "l2|l3") \
23253_(one_map_resolver_dump, "") \
23254_(one_map_server_dump, "") \
23255_(one_adjacencies_get, "vni <vni>") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020023256_(one_nsh_set_locator_set, "[del] ls <locator-set-name>") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023257_(show_one_rloc_probe_state, "") \
23258_(show_one_map_register_state, "") \
23259_(show_one_status, "") \
Filip Tehlar4868ff62017-03-09 16:48:39 +010023260_(one_stats_dump, "") \
Filip Tehlar21511912017-04-07 10:41:42 +020023261_(one_stats_flush, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023262_(one_get_map_request_itr_rlocs, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020023263_(one_map_register_set_ttl, "<ttl>") \
Filip Tehlara4980b82017-09-27 14:32:02 +020023264_(one_set_transport_protocol, "udp|api") \
23265_(one_get_transport_protocol, "") \
Filip Tehlar0a8840d2017-10-16 05:48:23 -070023266_(one_enable_disable_xtr_mode, "enable|disable") \
23267_(one_show_xtr_mode, "") \
23268_(one_enable_disable_pitr_mode, "enable|disable") \
23269_(one_show_pitr_mode, "") \
23270_(one_enable_disable_petr_mode, "enable|disable") \
23271_(one_show_petr_mode, "") \
Filip Tehlaref2a5bf2017-05-30 07:14:46 +020023272_(show_one_nsh_mapping, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023273_(show_one_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010023274_(show_one_use_petr, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023275_(show_one_map_request_mode, "") \
Filip Tehlar1e553a02017-08-02 12:45:07 +020023276_(show_one_map_register_ttl, "") \
Filip Tehlar7048ff12017-07-27 08:09:14 +020023277_(show_one_map_register_fallback_threshold, "") \
Filip Tehlar694396d2017-02-17 14:29:11 +010023278_(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
Damjan Marion7cd468a2016-12-19 23:05:39 +010023279 " sw_if_index <sw_if_index> p <priority> " \
23280 "w <weight>] [del]") \
23281_(lisp_add_del_locator, "locator-set <locator_name> " \
23282 "iface <intf> | sw_if_index <sw_if_index> " \
23283 "p <priority> w <weight> [del]") \
23284_(lisp_add_del_local_eid,"vni <vni> eid " \
23285 "<ipv4|ipv6>/<prefix> | <L2 address> " \
23286 "locator-set <locator_name> [del]" \
23287 "[key-id sha1|sha256 secret-key <secret-key>]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023288_(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
23289_(lisp_add_del_map_server, "<ip4|6-addr> [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023290_(lisp_enable_disable, "enable|disable") \
23291_(lisp_map_register_enable_disable, "enable|disable") \
23292_(lisp_rloc_probe_enable_disable, "enable|disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023293_(lisp_add_del_remote_mapping, "add|del vni <vni> eid <dest-eid> " \
23294 "[seid <seid>] " \
23295 "rloc <locator> p <prio> " \
23296 "w <weight> [rloc <loc> ... ] " \
23297 "action <action> [del-all]") \
23298_(lisp_add_del_adjacency, "add|del vni <vni> reid <remote-eid> leid " \
23299 "<local-eid>") \
23300_(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010023301_(lisp_use_petr, "<ip-address> | disable") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023302_(lisp_map_request_mode, "src-dst|dst-only") \
23303_(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
23304_(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
23305_(lisp_locator_set_dump, "[local | remote]") \
23306_(lisp_locator_dump, "ls_index <index> | ls_name <name>") \
23307_(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
23308 "[local] | [remote]") \
23309_(lisp_eid_table_vni_dump, "") \
23310_(lisp_eid_table_map_dump, "l2|l3") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023311_(lisp_map_resolver_dump, "") \
23312_(lisp_map_server_dump, "") \
23313_(lisp_adjacencies_get, "vni <vni>") \
Filip Tehlar0eb874e2017-05-18 14:23:32 +020023314_(gpe_fwd_entry_vnis_get, "") \
Filip Tehlarb4243aa2017-06-14 14:39:42 +020023315_(gpe_native_fwd_rpaths_get, "ip4 | ip6") \
23316_(gpe_add_del_native_fwd_rpath, "[del] via <nh-ip-addr> [iface] " \
23317 "[table <table-id>]") \
Filip Tehlar5fae99c2017-01-18 12:57:37 +010023318_(lisp_gpe_fwd_entries_get, "vni <vni>") \
23319_(lisp_gpe_fwd_entry_path_dump, "index <fwd_entry_index>") \
Filip Tehlar3e7b56932017-02-21 18:28:34 +010023320_(gpe_set_encap_mode, "lisp|vxlan") \
23321_(gpe_get_encap_mode, "") \
Filip Tehlar82786c42017-02-20 15:20:37 +010023322_(lisp_gpe_add_del_iface, "up|down") \
23323_(lisp_gpe_enable_disable, "enable|disable") \
23324_(lisp_gpe_add_del_fwd_entry, "reid <eid> [leid <eid>] vni <vni>" \
23325 "vrf/bd <dp_table> loc-pair <lcl_loc> <rmt_loc> w <weight>... [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023326_(show_lisp_rloc_probe_state, "") \
23327_(show_lisp_map_register_state, "") \
23328_(show_lisp_status, "") \
23329_(lisp_get_map_request_itr_rlocs, "") \
23330_(show_lisp_pitr, "") \
Filip Tehlar67a99f82017-03-10 13:18:02 +010023331_(show_lisp_use_petr, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023332_(show_lisp_map_request_mode, "") \
23333_(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
23334_(af_packet_delete, "name <host interface name>") \
Mohsin Kazmi04e0bb22018-05-28 18:55:37 +020023335_(af_packet_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023336_(policer_add_del, "name <policer name> <params> [del]") \
23337_(policer_dump, "[name <policer name>]") \
23338_(policer_classify_set_interface, \
23339 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
23340 " [l2-table <nn>] [del]") \
23341_(policer_classify_dump, "type [ip4|ip6|l2]") \
23342_(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
23343 "[master|slave]") \
23344_(netmap_delete, "name <interface name>") \
23345_(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
23346_(mpls_fib_dump, "") \
23347_(classify_table_ids, "") \
23348_(classify_table_by_interface, "sw_if_index <sw_if_index>") \
23349_(classify_table_info, "table_id <nn>") \
23350_(classify_session_dump, "table_id <nn>") \
23351_(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
23352 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
23353 "[template_interval <nn>] [udp_checksum]") \
23354_(ipfix_exporter_dump, "") \
23355_(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
23356_(ipfix_classify_stream_dump, "") \
23357_(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
23358_(ipfix_classify_table_dump, "") \
Eyal Bari001fd402017-07-16 09:34:53 +030023359_(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 +030023360_(sw_interface_span_dump, "[l2]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023361_(get_next_index, "node-name <node-name> next-node-name <node-name>") \
23362_(pg_create_interface, "if_id <nn>") \
23363_(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
23364_(pg_enable_disable, "[stream <id>] disable") \
23365_(ip_source_and_port_range_check_add_del, \
23366 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
23367_(ip_source_and_port_range_check_interface_add_del, \
23368 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
23369 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
23370_(ipsec_gre_add_del_tunnel, \
23371 "src <addr> dst <addr> local_sa <sa-id> remote_sa <sa-id> [del]") \
23372_(ipsec_gre_tunnel_dump, "[sw_if_index <nn>]") \
23373_(delete_subif,"<intfc> | sw_if_index <nn>") \
23374_(l2_interface_pbb_tag_rewrite, \
23375 "<intfc> | sw_if_index <nn> \n" \
23376 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
23377 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
Pavel Kotuceke88865d2018-11-28 07:42:11 +010023378_(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023379_(flow_classify_set_interface, \
23380 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
23381_(flow_classify_dump, "type [ip4|ip6]") \
23382_(ip_fib_dump, "") \
Neale Ranns5a8123b2017-01-26 01:18:23 -080023383_(ip_mfib_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023384_(ip6_fib_dump, "") \
Neale Ranns5a8123b2017-01-26 01:18:23 -080023385_(ip6_mfib_dump, "") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023386_(feature_enable_disable, "arc_name <arc_name> " \
23387 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
23388_(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
23389"[disable]") \
23390_(l2_xconnect_dump, "") \
Ole Troand7231612018-06-07 10:17:57 +020023391_(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023392_(ip_neighbor_dump, "[ip6] <intfc> | sw_if_index <nn>") \
Pavel Kotucek6899a302017-06-08 08:46:10 +020023393_(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020023394_(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
Steve Shin99a0e602017-07-01 04:16:20 +000023395_(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
Pavel Kotucek15ac81c2017-06-20 14:00:26 +020023396_(lldp_config, "system-name <name> tx-hold <nn> tx-interval <nn>") \
Steve Shin9a6fcef2017-10-11 13:55:16 -070023397_(sw_interface_set_lldp, "<intfc> | sw_if_index <nn> [port-desc <description>]\n" \
23398 " [mgmt-ip4 <ip4>] [mgmt-ip6 <ip6>] [mgmt-oid <object id>] [disable]") \
Dave Barach59b25652017-09-10 15:04:27 -040023399_(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
Florin Coras90a63982017-12-19 04:50:01 -080023400_(sock_init_shm, "size <nnn>") \
Florin Corascea194d2017-10-02 00:18:51 -070023401_(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
Dave Barach65457162017-10-10 17:53:14 -040023402_(dns_enable_disable, "[enable][disable]") \
23403_(dns_name_server_add_del, "<ip-address> [del]") \
Dave Barachd2080152017-10-20 09:21:35 -040023404_(dns_resolve_name, "<hostname>") \
Florin Coras1c710452017-10-17 00:03:13 -070023405_(dns_resolve_ip, "<ip4|ip6>") \
23406_(dns_name_server_add_del, "<ip-address> [del]") \
23407_(dns_resolve_name, "<hostname>") \
23408_(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
23409 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
Florin Coras6c36f532017-11-03 18:32:34 -070023410_(session_rules_dump, "") \
Florin Coras595992c2017-11-06 17:17:08 -080023411_(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
Andrew Yourtchenko815d7d52018-02-07 11:37:02 +010023412_(output_acl_set_interface, \
23413 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
23414 " [l2-table <nn>] [del]") \
Ole Troane906aac2018-06-14 14:42:14 +020023415_(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
Damjan Marion7cd468a2016-12-19 23:05:39 +010023416
23417/* List of command functions, CLI names map directly to functions */
23418#define foreach_cli_function \
23419_(comment, "usage: comment <ignore-rest-of-line>") \
23420_(dump_interface_table, "usage: dump_interface_table") \
23421_(dump_sub_interface_table, "usage: dump_sub_interface_table") \
23422_(dump_ipv4_table, "usage: dump_ipv4_table") \
23423_(dump_ipv6_table, "usage: dump_ipv6_table") \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023424_(dump_macro_table, "usage: dump_macro_table ") \
23425_(dump_node_table, "usage: dump_node_table") \
23426_(dump_msg_api_table, "usage: dump_msg_api_table") \
23427_(get_msg_id, "usage: get_msg_id name_and_crc") \
23428_(echo, "usage: echo <message>") \
23429_(exec, "usage: exec <vpe-debug-CLI-command>") \
23430_(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
23431_(help, "usage: help") \
23432_(q, "usage: quit") \
23433_(quit, "usage: quit") \
23434_(search_node_table, "usage: search_node_table <name>...") \
23435_(set, "usage: set <variable-name> <value>") \
23436_(script, "usage: script <file-name>") \
Dave Barach048a4e52018-06-01 18:52:25 -040023437_(statseg, "usage: statseg"); \
Damjan Marion7cd468a2016-12-19 23:05:39 +010023438_(unset, "usage: unset <variable-name>")
Dave Barach048a4e52018-06-01 18:52:25 -040023439
Damjan Marion7cd468a2016-12-19 23:05:39 +010023440#define _(N,n) \
23441 static void vl_api_##n##_t_handler_uni \
23442 (vl_api_##n##_t * mp) \
23443 { \
23444 vat_main_t * vam = &vat_main; \
23445 if (vam->json_output) { \
23446 vl_api_##n##_t_handler_json(mp); \
23447 } else { \
23448 vl_api_##n##_t_handler(mp); \
23449 } \
23450 }
23451foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050023452#if VPP_API_TEST_BUILTIN == 0
23453foreach_standalone_reply_msg;
23454#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010023455#undef _
23456
23457void
23458vat_api_hookup (vat_main_t * vam)
23459{
23460#define _(N,n) \
23461 vl_msg_api_set_handlers(VL_API_##N, #n, \
23462 vl_api_##n##_t_handler_uni, \
23463 vl_noop_handler, \
23464 vl_api_##n##_t_endian, \
23465 vl_api_##n##_t_print, \
23466 sizeof(vl_api_##n##_t), 1);
23467 foreach_vpe_api_reply_msg;
Dave Baracha1a093d2017-03-02 13:13:23 -050023468#if VPP_API_TEST_BUILTIN == 0
23469 foreach_standalone_reply_msg;
23470#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010023471#undef _
23472
23473#if (VPP_API_TEST_BUILTIN==0)
23474 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
Damjan Marion7cd468a2016-12-19 23:05:39 +010023475
23476 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
23477
23478 vam->function_by_name = hash_create_string (0, sizeof (uword));
23479
23480 vam->help_by_name = hash_create_string (0, sizeof (uword));
Dave Barach45e4f362017-03-07 12:52:31 -050023481#endif
Damjan Marion7cd468a2016-12-19 23:05:39 +010023482
23483 /* API messages we can send */
23484#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
23485 foreach_vpe_api_msg;
23486#undef _
23487
23488 /* Help strings */
23489#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
23490 foreach_vpe_api_msg;
23491#undef _
Damjan Marion7cd468a2016-12-19 23:05:39 +010023492
23493 /* CLI functions */
23494#define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
23495 foreach_cli_function;
23496#undef _
23497
23498 /* Help strings */
23499#define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
23500 foreach_cli_function;
23501#undef _
23502}
23503
Dave Baracha1a093d2017-03-02 13:13:23 -050023504#if VPP_API_TEST_BUILTIN
23505static clib_error_t *
23506vat_api_hookup_shim (vlib_main_t * vm)
23507{
23508 vat_api_hookup (&vat_main);
23509 return 0;
23510}
23511
23512VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
23513#endif
23514
Damjan Marion7cd468a2016-12-19 23:05:39 +010023515/*
23516 * fd.io coding-style-patch-verification: ON
23517 *
23518 * Local Variables:
23519 * eval: (c-set-style "gnu")
23520 * End:
23521 */