2 *------------------------------------------------------------------
5 * Copyright (c) 2014-2020 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:
10 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
21 #include <vlib/pci/pci.h>
22 #include <vpp/api/types.h>
23 #include <vppinfra/socket.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/ip-neighbor/ip_neighbor.h>
28 #include <vnet/ip/ip_types_api.h>
29 #include <vnet/l2/l2_input.h>
30 #include <vnet/udp/udp_local.h>
32 #include <vpp/api/vpe_msg_enum.h>
33 #include <vnet/l2/l2_classify.h>
34 #include <vnet/l2/l2_vtr.h>
35 #include <vnet/classify/in_out_acl.h>
36 #include <vnet/classify/policer_classify.h>
37 #include <vnet/classify/flow_classify.h>
38 #include <vnet/mpls/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
41 #include <vnet/ip/ip6_hop_by_hop.h>
42 #include <vnet/ip/ip_source_and_port_range_check.h>
43 #include <vnet/policer/xlate.h>
44 #include <vnet/span/span.h>
45 #include <vnet/policer/policer.h>
46 #include <vnet/policer/police.h>
47 #include <vnet/mfib/mfib_types.h>
48 #include <vnet/bonding/node.h>
49 #include <vnet/qos/qos_types.h>
50 #include <vnet/ethernet/ethernet_types_api.h>
51 #include <vnet/ip/ip_types_api.h>
52 #include "vat/json_format.h"
53 #include <vnet/ip/ip_types_api.h>
54 #include <vnet/ethernet/ethernet_types_api.h>
59 #define vl_typedefs /* define message structures */
60 #include <vpp/api/vpe_all_api_h.h>
63 /* declare message handlers for each api */
65 #define vl_endianfun /* define message structures */
66 #include <vpp/api/vpe_all_api_h.h>
69 /* instantiate all the print functions we know about */
70 #if VPP_API_TEST_BUILTIN == 0
71 #define vl_print(handle, ...)
73 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
76 #include <vpp/api/vpe_all_api_h.h>
79 #define __plugin_msg_base 0
80 #include <vlibapi/vat_helper_macros.h>
82 void vl_api_set_elog_main (elog_main_t * m);
83 int vl_api_set_elog_trace_api_messages (int enable);
85 #if VPP_API_TEST_BUILTIN == 0
95 vat_socket_connect (vat_main_t * vam)
98 api_main_t *am = vlibapi_get_main ();
99 vam->socket_client_main = &socket_client_main;
100 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
102 0 /* default socket rx, tx buffer */ )))
105 /* vpp expects the client index in network order */
106 vam->my_client_index = htonl (socket_client_main.client_index);
107 am->my_client_index = vam->my_client_index;
110 #else /* vpp built-in case, we don't do sockets... */
112 vat_socket_connect (vat_main_t * vam)
118 vl_socket_client_read (int wait)
124 vl_socket_client_write ()
130 vl_socket_client_msg_alloc (int nbytes)
138 vat_time_now (vat_main_t * vam)
140 #if VPP_API_TEST_BUILTIN
141 return vlib_time_now (vam->vlib_main);
143 return clib_time_now (&vam->clib_time);
148 errmsg (char *fmt, ...)
150 vat_main_t *vam = &vat_main;
155 s = va_format (0, fmt, &va);
160 #if VPP_API_TEST_BUILTIN
161 vlib_cli_output (vam->vlib_main, (char *) s);
164 if (vam->ifp != stdin)
165 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
166 vam->input_line_number);
168 fformat (vam->ofp, "%s\n", (char *) s);
176 #if VPP_API_TEST_BUILTIN == 0
178 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
180 vat_main_t *vam = va_arg (*args, vat_main_t *);
181 u32 *result = va_arg (*args, u32 *);
185 if (!unformat (input, "%s", &if_name))
188 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
195 /* Parse an IP4 address %d.%d.%d.%d. */
197 unformat_ip4_address (unformat_input_t * input, va_list * args)
199 u8 *result = va_arg (*args, u8 *);
202 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
205 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217 unformat_ethernet_address (unformat_input_t * input, va_list * args)
219 u8 *result = va_arg (*args, u8 *);
222 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
223 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
227 for (i = 0; i < 6; i++)
228 if (a[i] >= (1 << 8))
231 for (i = 0; i < 6; i++)
237 /* Returns ethernet type as an int in host byte order. */
239 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
242 u16 *result = va_arg (*args, u16 *);
246 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
248 if (type >= (1 << 16))
256 /* Parse an IP46 address. */
258 unformat_ip46_address (unformat_input_t * input, va_list * args)
260 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
261 ip46_type_t type = va_arg (*args, ip46_type_t);
262 if ((type != IP46_TYPE_IP6) &&
263 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
265 ip46_address_mask_ip4 (ip46);
268 else if ((type != IP46_TYPE_IP4) &&
269 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
276 /* Parse an IP6 address. */
278 unformat_ip6_address (unformat_input_t * input, va_list * args)
280 ip6_address_t *result = va_arg (*args, ip6_address_t *);
282 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
283 uword c, n_colon, double_colon_index;
285 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
286 double_colon_index = ARRAY_LEN (hex_quads);
287 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
290 if (c >= '0' && c <= '9')
292 else if (c >= 'a' && c <= 'f')
293 hex_digit = c + 10 - 'a';
294 else if (c >= 'A' && c <= 'F')
295 hex_digit = c + 10 - 'A';
296 else if (c == ':' && n_colon < 2)
300 unformat_put_input (input);
304 /* Too many hex quads. */
305 if (n_hex_quads >= ARRAY_LEN (hex_quads))
310 hex_quad = (hex_quad << 4) | hex_digit;
312 /* Hex quad must fit in 16 bits. */
313 if (n_hex_digits >= 4)
320 /* Save position of :: */
323 /* More than one :: ? */
324 if (double_colon_index < ARRAY_LEN (hex_quads))
326 double_colon_index = n_hex_quads;
329 if (n_colon > 0 && n_hex_digits > 0)
331 hex_quads[n_hex_quads++] = hex_quad;
337 if (n_hex_digits > 0)
338 hex_quads[n_hex_quads++] = hex_quad;
343 /* Expand :: to appropriate number of zero hex quads. */
344 if (double_colon_index < ARRAY_LEN (hex_quads))
346 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
348 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
349 hex_quads[n_zero + i] = hex_quads[i];
351 for (i = 0; i < n_zero; i++)
352 hex_quads[double_colon_index + i] = 0;
354 n_hex_quads = ARRAY_LEN (hex_quads);
357 /* Too few hex quads given. */
358 if (n_hex_quads < ARRAY_LEN (hex_quads))
361 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
362 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
369 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
371 u32 *r = va_arg (*args, u32 *);
374 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
375 foreach_ipsec_policy_action
383 format_ipsec_crypto_alg (u8 * s, va_list * args)
385 u32 i = va_arg (*args, u32);
390 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
391 foreach_ipsec_crypto_alg
394 return format (s, "unknown");
396 return format (s, "%s", t);
400 format_ipsec_integ_alg (u8 * s, va_list * args)
402 u32 i = va_arg (*args, u32);
407 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
408 foreach_ipsec_integ_alg
411 return format (s, "unknown");
413 return format (s, "%s", t);
416 #else /* VPP_API_TEST_BUILTIN == 1 */
418 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
420 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
421 vnet_main_t *vnm = vnet_get_main ();
422 u32 *result = va_arg (*args, u32 *);
424 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
427 #endif /* VPP_API_TEST_BUILTIN */
429 #if (VPP_API_TEST_BUILTIN==0)
431 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
432 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
433 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
434 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
437 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
439 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
440 mfib_itf_attribute_t attr;
443 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
445 if (unformat (input, mfib_itf_flag_long_names[attr]))
446 *iflags |= (1 << attr);
448 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
450 if (unformat (input, mfib_itf_flag_names[attr]))
451 *iflags |= (1 << attr);
454 return (old == *iflags ? 0 : 1);
458 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
460 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
461 mfib_entry_attribute_t attr;
464 FOR_EACH_MFIB_ATTRIBUTE (attr)
466 if (unformat (input, mfib_flag_long_names[attr]))
467 *eflags |= (1 << attr);
469 FOR_EACH_MFIB_ATTRIBUTE (attr)
471 if (unformat (input, mfib_flag_names[attr]))
472 *eflags |= (1 << attr);
475 return (old == *eflags ? 0 : 1);
479 format_ip4_address (u8 * s, va_list * args)
481 u8 *a = va_arg (*args, u8 *);
482 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
486 format_ip6_address (u8 * s, va_list * args)
488 ip6_address_t *a = va_arg (*args, ip6_address_t *);
489 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
491 i_max_n_zero = ARRAY_LEN (a->as_u16);
493 i_first_zero = i_max_n_zero;
495 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
497 u32 is_zero = a->as_u16[i] == 0;
498 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
504 if ((!is_zero && n_zeros > max_n_zeros)
505 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
507 i_max_n_zero = i_first_zero;
508 max_n_zeros = n_zeros;
509 i_first_zero = ARRAY_LEN (a->as_u16);
514 last_double_colon = 0;
515 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
517 if (i == i_max_n_zero && max_n_zeros > 1)
519 s = format (s, "::");
520 i += max_n_zeros - 1;
521 last_double_colon = 1;
525 s = format (s, "%s%x",
526 (last_double_colon || i == 0) ? "" : ":",
527 clib_net_to_host_u16 (a->as_u16[i]));
528 last_double_colon = 0;
535 /* Format an IP46 address. */
537 format_ip46_address (u8 * s, va_list * args)
539 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
540 ip46_type_t type = va_arg (*args, ip46_type_t);
546 is_ip4 = ip46_address_is_ip4 (ip46);
557 format (s, "%U", format_ip4_address, &ip46->ip4) :
558 format (s, "%U", format_ip6_address, &ip46->ip6);
562 format_ethernet_address (u8 * s, va_list * args)
564 u8 *a = va_arg (*args, u8 *);
566 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
567 a[0], a[1], a[2], a[3], a[4], a[5]);
572 increment_v4_address (vl_api_ip4_address_t * i)
574 ip4_address_t *a = (ip4_address_t *) i;
577 v = ntohl (a->as_u32) + 1;
578 a->as_u32 = ntohl (v);
582 increment_v6_address (vl_api_ip6_address_t * i)
584 ip6_address_t *a = (ip6_address_t *) i;
587 v0 = clib_net_to_host_u64 (a->as_u64[0]);
588 v1 = clib_net_to_host_u64 (a->as_u64[1]);
593 a->as_u64[0] = clib_net_to_host_u64 (v0);
594 a->as_u64[1] = clib_net_to_host_u64 (v1);
598 increment_address (vl_api_address_t * a)
600 if (a->af == ADDRESS_IP4)
601 increment_v4_address (&a->un.ip4);
602 else if (a->af == ADDRESS_IP6)
603 increment_v6_address (&a->un.ip6);
607 set_ip4_address (vl_api_address_t * a, u32 v)
609 if (a->af == ADDRESS_IP4)
611 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
617 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
620 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
622 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
623 sizeof (ip6_address_t));
627 increment_mac_address (u8 * mac)
629 u64 tmp = *((u64 *) mac);
630 tmp = clib_net_to_host_u64 (tmp);
631 tmp += 1 << 16; /* skip unused (least significant) octets */
632 tmp = clib_host_to_net_u64 (tmp);
634 clib_memcpy (mac, &tmp, 6);
638 vat_json_object_add_address (vat_json_node_t * node,
639 const char *str, const vl_api_address_t * addr)
641 if (ADDRESS_IP6 == addr->af)
645 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
646 vat_json_object_add_ip6 (node, str, ip6);
652 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
653 vat_json_object_add_ip4 (node, str, ip4);
658 vat_json_object_add_prefix (vat_json_node_t * node,
659 const vl_api_prefix_t * prefix)
661 vat_json_object_add_uint (node, "len", prefix->len);
662 vat_json_object_add_address (node, "address", &prefix->address);
665 static void vl_api_create_loopback_reply_t_handler
666 (vl_api_create_loopback_reply_t * mp)
668 vat_main_t *vam = &vat_main;
669 i32 retval = ntohl (mp->retval);
671 vam->retval = retval;
672 vam->regenerate_interface_table = 1;
673 vam->sw_if_index = ntohl (mp->sw_if_index);
674 vam->result_ready = 1;
677 static void vl_api_create_loopback_reply_t_handler_json
678 (vl_api_create_loopback_reply_t * mp)
680 vat_main_t *vam = &vat_main;
681 vat_json_node_t node;
683 vat_json_init_object (&node);
684 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
685 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
687 vat_json_print (vam->ofp, &node);
688 vat_json_free (&node);
689 vam->retval = ntohl (mp->retval);
690 vam->result_ready = 1;
693 static void vl_api_create_loopback_instance_reply_t_handler
694 (vl_api_create_loopback_instance_reply_t * mp)
696 vat_main_t *vam = &vat_main;
697 i32 retval = ntohl (mp->retval);
699 vam->retval = retval;
700 vam->regenerate_interface_table = 1;
701 vam->sw_if_index = ntohl (mp->sw_if_index);
702 vam->result_ready = 1;
705 static void vl_api_create_loopback_instance_reply_t_handler_json
706 (vl_api_create_loopback_instance_reply_t * mp)
708 vat_main_t *vam = &vat_main;
709 vat_json_node_t node;
711 vat_json_init_object (&node);
712 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
713 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
715 vat_json_print (vam->ofp, &node);
716 vat_json_free (&node);
717 vam->retval = ntohl (mp->retval);
718 vam->result_ready = 1;
721 static void vl_api_af_packet_create_reply_t_handler
722 (vl_api_af_packet_create_reply_t * mp)
724 vat_main_t *vam = &vat_main;
725 i32 retval = ntohl (mp->retval);
727 vam->retval = retval;
728 vam->regenerate_interface_table = 1;
729 vam->sw_if_index = ntohl (mp->sw_if_index);
730 vam->result_ready = 1;
733 static void vl_api_af_packet_create_reply_t_handler_json
734 (vl_api_af_packet_create_reply_t * mp)
736 vat_main_t *vam = &vat_main;
737 vat_json_node_t node;
739 vat_json_init_object (&node);
740 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
741 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
743 vat_json_print (vam->ofp, &node);
744 vat_json_free (&node);
746 vam->retval = ntohl (mp->retval);
747 vam->result_ready = 1;
750 static void vl_api_create_vlan_subif_reply_t_handler
751 (vl_api_create_vlan_subif_reply_t * mp)
753 vat_main_t *vam = &vat_main;
754 i32 retval = ntohl (mp->retval);
756 vam->retval = retval;
757 vam->regenerate_interface_table = 1;
758 vam->sw_if_index = ntohl (mp->sw_if_index);
759 vam->result_ready = 1;
762 static void vl_api_create_vlan_subif_reply_t_handler_json
763 (vl_api_create_vlan_subif_reply_t * mp)
765 vat_main_t *vam = &vat_main;
766 vat_json_node_t node;
768 vat_json_init_object (&node);
769 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
770 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
772 vat_json_print (vam->ofp, &node);
773 vat_json_free (&node);
775 vam->retval = ntohl (mp->retval);
776 vam->result_ready = 1;
779 static void vl_api_create_subif_reply_t_handler
780 (vl_api_create_subif_reply_t * mp)
782 vat_main_t *vam = &vat_main;
783 i32 retval = ntohl (mp->retval);
785 vam->retval = retval;
786 vam->regenerate_interface_table = 1;
787 vam->sw_if_index = ntohl (mp->sw_if_index);
788 vam->result_ready = 1;
791 static void vl_api_create_subif_reply_t_handler_json
792 (vl_api_create_subif_reply_t * mp)
794 vat_main_t *vam = &vat_main;
795 vat_json_node_t node;
797 vat_json_init_object (&node);
798 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
799 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
801 vat_json_print (vam->ofp, &node);
802 vat_json_free (&node);
804 vam->retval = ntohl (mp->retval);
805 vam->result_ready = 1;
808 static void vl_api_interface_name_renumber_reply_t_handler
809 (vl_api_interface_name_renumber_reply_t * mp)
811 vat_main_t *vam = &vat_main;
812 i32 retval = ntohl (mp->retval);
814 vam->retval = retval;
815 vam->regenerate_interface_table = 1;
816 vam->result_ready = 1;
819 static void vl_api_interface_name_renumber_reply_t_handler_json
820 (vl_api_interface_name_renumber_reply_t * mp)
822 vat_main_t *vam = &vat_main;
823 vat_json_node_t node;
825 vat_json_init_object (&node);
826 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
828 vat_json_print (vam->ofp, &node);
829 vat_json_free (&node);
831 vam->retval = ntohl (mp->retval);
832 vam->result_ready = 1;
836 * Special-case: build the interface table, maintain
837 * the next loopback sw_if_index vbl.
839 static void vl_api_sw_interface_details_t_handler
840 (vl_api_sw_interface_details_t * mp)
842 vat_main_t *vam = &vat_main;
843 u8 *s = format (0, "%s%c", mp->interface_name, 0);
845 hash_set_mem (vam->sw_if_index_by_interface_name, s,
846 ntohl (mp->sw_if_index));
848 /* In sub interface case, fill the sub interface table entry */
849 if (mp->sw_if_index != mp->sup_sw_if_index)
851 sw_interface_subif_t *sub = NULL;
853 vec_add2 (vam->sw_if_subif_table, sub, 1);
855 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
856 strncpy ((char *) sub->interface_name, (char *) s,
857 vec_len (sub->interface_name));
858 sub->sw_if_index = ntohl (mp->sw_if_index);
859 sub->sub_id = ntohl (mp->sub_id);
861 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
863 sub->sub_number_of_tags = mp->sub_number_of_tags;
864 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
865 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
867 /* vlan tag rewrite */
868 sub->vtr_op = ntohl (mp->vtr_op);
869 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
870 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
871 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
875 static void vl_api_sw_interface_details_t_handler_json
876 (vl_api_sw_interface_details_t * mp)
878 vat_main_t *vam = &vat_main;
879 vat_json_node_t *node = NULL;
881 if (VAT_JSON_ARRAY != vam->json_tree.type)
883 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
884 vat_json_init_array (&vam->json_tree);
886 node = vat_json_array_add (&vam->json_tree);
888 vat_json_init_object (node);
889 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
890 vat_json_object_add_uint (node, "sup_sw_if_index",
891 ntohl (mp->sup_sw_if_index));
892 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
893 sizeof (mp->l2_address));
894 vat_json_object_add_string_copy (node, "interface_name",
896 vat_json_object_add_string_copy (node, "interface_dev_type",
897 mp->interface_dev_type);
898 vat_json_object_add_uint (node, "flags", mp->flags);
899 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
900 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
901 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
902 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
903 vat_json_object_add_uint (node, "sub_number_of_tags",
904 mp->sub_number_of_tags);
905 vat_json_object_add_uint (node, "sub_outer_vlan_id",
906 ntohs (mp->sub_outer_vlan_id));
907 vat_json_object_add_uint (node, "sub_inner_vlan_id",
908 ntohs (mp->sub_inner_vlan_id));
909 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
910 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
911 vat_json_object_add_uint (node, "vtr_push_dot1q",
912 ntohl (mp->vtr_push_dot1q));
913 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
914 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
915 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
917 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
919 format_ethernet_address,
921 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
923 format_ethernet_address,
925 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
926 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
930 #if VPP_API_TEST_BUILTIN == 0
931 static void vl_api_sw_interface_event_t_handler
932 (vl_api_sw_interface_event_t * mp)
934 vat_main_t *vam = &vat_main;
935 if (vam->interface_event_display)
936 errmsg ("interface flags: sw_if_index %d %s %s",
937 ntohl (mp->sw_if_index),
938 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
939 "admin-up" : "admin-down",
940 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
941 "link-up" : "link-down");
945 __clib_unused static void
946 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
948 /* JSON output not supported */
952 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
954 vat_main_t *vam = &vat_main;
955 i32 retval = ntohl (mp->retval);
957 vam->retval = retval;
958 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
959 vam->result_ready = 1;
963 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
965 vat_main_t *vam = &vat_main;
966 vat_json_node_t node;
970 vat_json_init_object (&node);
971 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
972 vat_json_object_add_uint (&node, "reply_in_shmem",
973 ntohl (mp->reply_in_shmem));
974 /* Toss the shared-memory original... */
975 oldheap = vl_msg_push_heap ();
977 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
980 vl_msg_pop_heap (oldheap);
982 vat_json_print (vam->ofp, &node);
983 vat_json_free (&node);
985 vam->retval = ntohl (mp->retval);
986 vam->result_ready = 1;
990 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
992 vat_main_t *vam = &vat_main;
993 i32 retval = ntohl (mp->retval);
995 vec_reset_length (vam->cmd_reply);
997 vam->retval = retval;
999 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1000 vam->result_ready = 1;
1004 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1006 vat_main_t *vam = &vat_main;
1007 vat_json_node_t node;
1008 u8 *reply = 0; /* reply vector */
1010 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1011 vec_reset_length (vam->cmd_reply);
1013 vat_json_init_object (&node);
1014 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1015 vat_json_object_add_string_copy (&node, "reply", reply);
1017 vat_json_print (vam->ofp, &node);
1018 vat_json_free (&node);
1021 vam->retval = ntohl (mp->retval);
1022 vam->result_ready = 1;
1025 static void vl_api_get_node_index_reply_t_handler
1026 (vl_api_get_node_index_reply_t * mp)
1028 vat_main_t *vam = &vat_main;
1029 i32 retval = ntohl (mp->retval);
1030 if (vam->async_mode)
1032 vam->async_errors += (retval < 0);
1036 vam->retval = retval;
1038 errmsg ("node index %d", ntohl (mp->node_index));
1039 vam->result_ready = 1;
1043 static void vl_api_get_node_index_reply_t_handler_json
1044 (vl_api_get_node_index_reply_t * mp)
1046 vat_main_t *vam = &vat_main;
1047 vat_json_node_t node;
1049 vat_json_init_object (&node);
1050 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1051 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1053 vat_json_print (vam->ofp, &node);
1054 vat_json_free (&node);
1056 vam->retval = ntohl (mp->retval);
1057 vam->result_ready = 1;
1060 static void vl_api_get_next_index_reply_t_handler
1061 (vl_api_get_next_index_reply_t * mp)
1063 vat_main_t *vam = &vat_main;
1064 i32 retval = ntohl (mp->retval);
1065 if (vam->async_mode)
1067 vam->async_errors += (retval < 0);
1071 vam->retval = retval;
1073 errmsg ("next node index %d", ntohl (mp->next_index));
1074 vam->result_ready = 1;
1078 static void vl_api_get_next_index_reply_t_handler_json
1079 (vl_api_get_next_index_reply_t * mp)
1081 vat_main_t *vam = &vat_main;
1082 vat_json_node_t node;
1084 vat_json_init_object (&node);
1085 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1086 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1088 vat_json_print (vam->ofp, &node);
1089 vat_json_free (&node);
1091 vam->retval = ntohl (mp->retval);
1092 vam->result_ready = 1;
1095 static void vl_api_add_node_next_reply_t_handler
1096 (vl_api_add_node_next_reply_t * mp)
1098 vat_main_t *vam = &vat_main;
1099 i32 retval = ntohl (mp->retval);
1100 if (vam->async_mode)
1102 vam->async_errors += (retval < 0);
1106 vam->retval = retval;
1108 errmsg ("next index %d", ntohl (mp->next_index));
1109 vam->result_ready = 1;
1113 static void vl_api_add_node_next_reply_t_handler_json
1114 (vl_api_add_node_next_reply_t * mp)
1116 vat_main_t *vam = &vat_main;
1117 vat_json_node_t node;
1119 vat_json_init_object (&node);
1120 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1121 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1123 vat_json_print (vam->ofp, &node);
1124 vat_json_free (&node);
1126 vam->retval = ntohl (mp->retval);
1127 vam->result_ready = 1;
1130 static void vl_api_show_version_reply_t_handler
1131 (vl_api_show_version_reply_t * mp)
1133 vat_main_t *vam = &vat_main;
1134 i32 retval = ntohl (mp->retval);
1138 errmsg (" program: %s", mp->program);
1139 errmsg (" version: %s", mp->version);
1140 errmsg (" build date: %s", mp->build_date);
1141 errmsg ("build directory: %s", mp->build_directory);
1143 vam->retval = retval;
1144 vam->result_ready = 1;
1147 static void vl_api_show_version_reply_t_handler_json
1148 (vl_api_show_version_reply_t * mp)
1150 vat_main_t *vam = &vat_main;
1151 vat_json_node_t node;
1153 vat_json_init_object (&node);
1154 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1155 vat_json_object_add_string_copy (&node, "program", mp->program);
1156 vat_json_object_add_string_copy (&node, "version", mp->version);
1157 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1158 vat_json_object_add_string_copy (&node, "build_directory",
1159 mp->build_directory);
1161 vat_json_print (vam->ofp, &node);
1162 vat_json_free (&node);
1164 vam->retval = ntohl (mp->retval);
1165 vam->result_ready = 1;
1168 static void vl_api_show_threads_reply_t_handler
1169 (vl_api_show_threads_reply_t * mp)
1171 vat_main_t *vam = &vat_main;
1172 i32 retval = ntohl (mp->retval);
1176 count = ntohl (mp->count);
1178 for (i = 0; i < count; i++)
1180 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1181 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1182 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1183 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1184 ntohl (mp->thread_data[i].cpu_socket));
1186 vam->retval = retval;
1187 vam->result_ready = 1;
1190 static void vl_api_show_threads_reply_t_handler_json
1191 (vl_api_show_threads_reply_t * mp)
1193 vat_main_t *vam = &vat_main;
1194 vat_json_node_t node;
1195 vl_api_thread_data_t *td;
1196 i32 retval = ntohl (mp->retval);
1200 count = ntohl (mp->count);
1202 vat_json_init_object (&node);
1203 vat_json_object_add_int (&node, "retval", retval);
1204 vat_json_object_add_uint (&node, "count", count);
1206 for (i = 0; i < count; i++)
1208 td = &mp->thread_data[i];
1209 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1210 vat_json_object_add_string_copy (&node, "name", td->name);
1211 vat_json_object_add_string_copy (&node, "type", td->type);
1212 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1213 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1214 vat_json_object_add_int (&node, "core", ntohl (td->id));
1215 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1218 vat_json_print (vam->ofp, &node);
1219 vat_json_free (&node);
1221 vam->retval = retval;
1222 vam->result_ready = 1;
1226 api_show_threads (vat_main_t * vam)
1228 vl_api_show_threads_t *mp;
1232 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1233 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1235 M (SHOW_THREADS, mp);
1243 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1245 u32 n_macs = ntohl (mp->n_macs);
1246 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1247 ntohl (mp->pid), mp->client_index, n_macs);
1249 for (i = 0; i < n_macs; i++)
1251 vl_api_mac_entry_t *mac = &mp->mac[i];
1252 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1253 i + 1, ntohl (mac->sw_if_index),
1254 format_ethernet_address, mac->mac_addr, mac->action);
1261 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1263 /* JSON output not supported */
1266 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1267 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1270 * Special-case: build the bridge domain table, maintain
1271 * the next bd id vbl.
1273 static void vl_api_bridge_domain_details_t_handler
1274 (vl_api_bridge_domain_details_t * mp)
1276 vat_main_t *vam = &vat_main;
1277 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1280 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1281 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1283 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1284 ntohl (mp->bd_id), mp->learn, mp->forward,
1285 mp->flood, ntohl (mp->bvi_sw_if_index),
1286 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1290 vl_api_bridge_domain_sw_if_t *sw_ifs;
1291 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1294 sw_ifs = mp->sw_if_details;
1295 for (i = 0; i < n_sw_ifs; i++)
1301 sw_if_index = ntohl (sw_ifs->sw_if_index);
1304 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1306 if ((u32) p->value[0] == sw_if_index)
1308 sw_if_name = (u8 *)(p->key);
1313 print (vam->ofp, "%7d %3d %s", sw_if_index,
1314 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1315 "sw_if_index not found!");
1322 static void vl_api_bridge_domain_details_t_handler_json
1323 (vl_api_bridge_domain_details_t * mp)
1325 vat_main_t *vam = &vat_main;
1326 vat_json_node_t *node, *array = NULL;
1327 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1329 if (VAT_JSON_ARRAY != vam->json_tree.type)
1331 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1332 vat_json_init_array (&vam->json_tree);
1334 node = vat_json_array_add (&vam->json_tree);
1336 vat_json_init_object (node);
1337 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1338 vat_json_object_add_uint (node, "flood", mp->flood);
1339 vat_json_object_add_uint (node, "forward", mp->forward);
1340 vat_json_object_add_uint (node, "learn", mp->learn);
1341 vat_json_object_add_uint (node, "bvi_sw_if_index",
1342 ntohl (mp->bvi_sw_if_index));
1343 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1344 array = vat_json_object_add (node, "sw_if");
1345 vat_json_init_array (array);
1351 vl_api_bridge_domain_sw_if_t *sw_ifs;
1354 sw_ifs = mp->sw_if_details;
1355 for (i = 0; i < n_sw_ifs; i++)
1357 node = vat_json_array_add (array);
1358 vat_json_init_object (node);
1359 vat_json_object_add_uint (node, "sw_if_index",
1360 ntohl (sw_ifs->sw_if_index));
1361 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1367 static void vl_api_control_ping_reply_t_handler
1368 (vl_api_control_ping_reply_t * mp)
1370 vat_main_t *vam = &vat_main;
1371 i32 retval = ntohl (mp->retval);
1372 if (vam->async_mode)
1374 vam->async_errors += (retval < 0);
1378 vam->retval = retval;
1379 vam->result_ready = 1;
1381 if (vam->socket_client_main)
1382 vam->socket_client_main->control_pings_outstanding--;
1385 static void vl_api_control_ping_reply_t_handler_json
1386 (vl_api_control_ping_reply_t * mp)
1388 vat_main_t *vam = &vat_main;
1389 i32 retval = ntohl (mp->retval);
1391 if (VAT_JSON_NONE != vam->json_tree.type)
1393 vat_json_print (vam->ofp, &vam->json_tree);
1394 vat_json_free (&vam->json_tree);
1395 vam->json_tree.type = VAT_JSON_NONE;
1400 vat_json_init_array (&vam->json_tree);
1401 vat_json_print (vam->ofp, &vam->json_tree);
1402 vam->json_tree.type = VAT_JSON_NONE;
1405 vam->retval = retval;
1406 vam->result_ready = 1;
1410 vl_api_bridge_domain_set_mac_age_reply_t_handler
1411 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1413 vat_main_t *vam = &vat_main;
1414 i32 retval = ntohl (mp->retval);
1415 if (vam->async_mode)
1417 vam->async_errors += (retval < 0);
1421 vam->retval = retval;
1422 vam->result_ready = 1;
1426 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1427 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1429 vat_main_t *vam = &vat_main;
1430 vat_json_node_t node;
1432 vat_json_init_object (&node);
1433 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1435 vat_json_print (vam->ofp, &node);
1436 vat_json_free (&node);
1438 vam->retval = ntohl (mp->retval);
1439 vam->result_ready = 1;
1443 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1445 vat_main_t *vam = &vat_main;
1446 i32 retval = ntohl (mp->retval);
1447 if (vam->async_mode)
1449 vam->async_errors += (retval < 0);
1453 vam->retval = retval;
1454 vam->result_ready = 1;
1458 static void vl_api_l2_flags_reply_t_handler_json
1459 (vl_api_l2_flags_reply_t * mp)
1461 vat_main_t *vam = &vat_main;
1462 vat_json_node_t node;
1464 vat_json_init_object (&node);
1465 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1466 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1467 ntohl (mp->resulting_feature_bitmap));
1469 vat_json_print (vam->ofp, &node);
1470 vat_json_free (&node);
1472 vam->retval = ntohl (mp->retval);
1473 vam->result_ready = 1;
1476 static void vl_api_bridge_flags_reply_t_handler
1477 (vl_api_bridge_flags_reply_t * mp)
1479 vat_main_t *vam = &vat_main;
1480 i32 retval = ntohl (mp->retval);
1481 if (vam->async_mode)
1483 vam->async_errors += (retval < 0);
1487 vam->retval = retval;
1488 vam->result_ready = 1;
1492 static void vl_api_bridge_flags_reply_t_handler_json
1493 (vl_api_bridge_flags_reply_t * mp)
1495 vat_main_t *vam = &vat_main;
1496 vat_json_node_t node;
1498 vat_json_init_object (&node);
1499 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1500 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1501 ntohl (mp->resulting_feature_bitmap));
1503 vat_json_print (vam->ofp, &node);
1504 vat_json_free (&node);
1506 vam->retval = ntohl (mp->retval);
1507 vam->result_ready = 1;
1511 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1513 vat_main_t *vam = &vat_main;
1514 i32 retval = ntohl (mp->retval);
1515 if (vam->async_mode)
1517 vam->async_errors += (retval < 0);
1521 vam->retval = retval;
1522 vam->sw_if_index = ntohl (mp->sw_if_index);
1523 vam->result_ready = 1;
1528 static void vl_api_tap_create_v2_reply_t_handler_json
1529 (vl_api_tap_create_v2_reply_t * mp)
1531 vat_main_t *vam = &vat_main;
1532 vat_json_node_t node;
1534 vat_json_init_object (&node);
1535 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1536 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1538 vat_json_print (vam->ofp, &node);
1539 vat_json_free (&node);
1541 vam->retval = ntohl (mp->retval);
1542 vam->result_ready = 1;
1547 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1549 vat_main_t *vam = &vat_main;
1550 i32 retval = ntohl (mp->retval);
1551 if (vam->async_mode)
1553 vam->async_errors += (retval < 0);
1557 vam->retval = retval;
1558 vam->result_ready = 1;
1562 static void vl_api_tap_delete_v2_reply_t_handler_json
1563 (vl_api_tap_delete_v2_reply_t * mp)
1565 vat_main_t *vam = &vat_main;
1566 vat_json_node_t node;
1568 vat_json_init_object (&node);
1569 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1571 vat_json_print (vam->ofp, &node);
1572 vat_json_free (&node);
1574 vam->retval = ntohl (mp->retval);
1575 vam->result_ready = 1;
1579 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1582 vat_main_t *vam = &vat_main;
1583 i32 retval = ntohl (mp->retval);
1584 if (vam->async_mode)
1586 vam->async_errors += (retval < 0);
1590 vam->retval = retval;
1591 vam->sw_if_index = ntohl (mp->sw_if_index);
1592 vam->result_ready = 1;
1596 static void vl_api_virtio_pci_create_reply_t_handler_json
1597 (vl_api_virtio_pci_create_reply_t * mp)
1599 vat_main_t *vam = &vat_main;
1600 vat_json_node_t node;
1602 vat_json_init_object (&node);
1603 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1604 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1606 vat_json_print (vam->ofp, &node);
1607 vat_json_free (&node);
1609 vam->retval = ntohl (mp->retval);
1610 vam->result_ready = 1;
1615 vl_api_virtio_pci_create_v2_reply_t_handler
1616 (vl_api_virtio_pci_create_v2_reply_t * mp)
1618 vat_main_t *vam = &vat_main;
1619 i32 retval = ntohl (mp->retval);
1620 if (vam->async_mode)
1622 vam->async_errors += (retval < 0);
1626 vam->retval = retval;
1627 vam->sw_if_index = ntohl (mp->sw_if_index);
1628 vam->result_ready = 1;
1632 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1633 (vl_api_virtio_pci_create_v2_reply_t * mp)
1635 vat_main_t *vam = &vat_main;
1636 vat_json_node_t node;
1638 vat_json_init_object (&node);
1639 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1640 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1642 vat_json_print (vam->ofp, &node);
1643 vat_json_free (&node);
1645 vam->retval = ntohl (mp->retval);
1646 vam->result_ready = 1;
1650 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1653 vat_main_t *vam = &vat_main;
1654 i32 retval = ntohl (mp->retval);
1655 if (vam->async_mode)
1657 vam->async_errors += (retval < 0);
1661 vam->retval = retval;
1662 vam->result_ready = 1;
1666 static void vl_api_virtio_pci_delete_reply_t_handler_json
1667 (vl_api_virtio_pci_delete_reply_t * mp)
1669 vat_main_t *vam = &vat_main;
1670 vat_json_node_t node;
1672 vat_json_init_object (&node);
1673 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1675 vat_json_print (vam->ofp, &node);
1676 vat_json_free (&node);
1678 vam->retval = ntohl (mp->retval);
1679 vam->result_ready = 1;
1683 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1685 vat_main_t *vam = &vat_main;
1686 i32 retval = ntohl (mp->retval);
1688 if (vam->async_mode)
1690 vam->async_errors += (retval < 0);
1694 vam->retval = retval;
1695 vam->sw_if_index = ntohl (mp->sw_if_index);
1696 vam->result_ready = 1;
1700 static void vl_api_bond_create_reply_t_handler_json
1701 (vl_api_bond_create_reply_t * mp)
1703 vat_main_t *vam = &vat_main;
1704 vat_json_node_t node;
1706 vat_json_init_object (&node);
1707 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1708 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1710 vat_json_print (vam->ofp, &node);
1711 vat_json_free (&node);
1713 vam->retval = ntohl (mp->retval);
1714 vam->result_ready = 1;
1718 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1720 vat_main_t *vam = &vat_main;
1721 i32 retval = ntohl (mp->retval);
1723 if (vam->async_mode)
1725 vam->async_errors += (retval < 0);
1729 vam->retval = retval;
1730 vam->sw_if_index = ntohl (mp->sw_if_index);
1731 vam->result_ready = 1;
1735 static void vl_api_bond_create2_reply_t_handler_json
1736 (vl_api_bond_create2_reply_t * mp)
1738 vat_main_t *vam = &vat_main;
1739 vat_json_node_t node;
1741 vat_json_init_object (&node);
1742 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1743 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1745 vat_json_print (vam->ofp, &node);
1746 vat_json_free (&node);
1748 vam->retval = ntohl (mp->retval);
1749 vam->result_ready = 1;
1753 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1755 vat_main_t *vam = &vat_main;
1756 i32 retval = ntohl (mp->retval);
1758 if (vam->async_mode)
1760 vam->async_errors += (retval < 0);
1764 vam->retval = retval;
1765 vam->result_ready = 1;
1769 static void vl_api_bond_delete_reply_t_handler_json
1770 (vl_api_bond_delete_reply_t * mp)
1772 vat_main_t *vam = &vat_main;
1773 vat_json_node_t node;
1775 vat_json_init_object (&node);
1776 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1778 vat_json_print (vam->ofp, &node);
1779 vat_json_free (&node);
1781 vam->retval = ntohl (mp->retval);
1782 vam->result_ready = 1;
1786 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
1788 vat_main_t *vam = &vat_main;
1789 i32 retval = ntohl (mp->retval);
1791 if (vam->async_mode)
1793 vam->async_errors += (retval < 0);
1797 vam->retval = retval;
1798 vam->result_ready = 1;
1802 static void vl_api_bond_add_member_reply_t_handler_json
1803 (vl_api_bond_add_member_reply_t * mp)
1805 vat_main_t *vam = &vat_main;
1806 vat_json_node_t node;
1808 vat_json_init_object (&node);
1809 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1811 vat_json_print (vam->ofp, &node);
1812 vat_json_free (&node);
1814 vam->retval = ntohl (mp->retval);
1815 vam->result_ready = 1;
1819 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
1822 vat_main_t *vam = &vat_main;
1823 i32 retval = ntohl (mp->retval);
1825 if (vam->async_mode)
1827 vam->async_errors += (retval < 0);
1831 vam->retval = retval;
1832 vam->result_ready = 1;
1836 static void vl_api_bond_detach_member_reply_t_handler_json
1837 (vl_api_bond_detach_member_reply_t * mp)
1839 vat_main_t *vam = &vat_main;
1840 vat_json_node_t node;
1842 vat_json_init_object (&node);
1843 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1845 vat_json_print (vam->ofp, &node);
1846 vat_json_free (&node);
1848 vam->retval = ntohl (mp->retval);
1849 vam->result_ready = 1;
1853 api_sw_interface_set_bond_weight (vat_main_t * vam)
1855 unformat_input_t *i = vam->input;
1856 vl_api_sw_interface_set_bond_weight_t *mp;
1857 u32 sw_if_index = ~0;
1859 u8 weight_enter = 0;
1862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1864 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1866 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1868 else if (unformat (i, "weight %u", &weight))
1874 if (sw_if_index == ~0)
1876 errmsg ("missing interface name or sw_if_index");
1879 if (weight_enter == 0)
1881 errmsg ("missing valid weight");
1885 /* Construct the API message */
1886 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
1887 mp->sw_if_index = ntohl (sw_if_index);
1888 mp->weight = ntohl (weight);
1895 static void vl_api_sw_bond_interface_details_t_handler
1896 (vl_api_sw_bond_interface_details_t * mp)
1898 vat_main_t *vam = &vat_main;
1901 "%-16s %-12d %-12U %-13U %-14u %-14u",
1902 mp->interface_name, ntohl (mp->sw_if_index),
1903 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
1904 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
1907 static void vl_api_sw_bond_interface_details_t_handler_json
1908 (vl_api_sw_bond_interface_details_t * mp)
1910 vat_main_t *vam = &vat_main;
1911 vat_json_node_t *node = NULL;
1913 if (VAT_JSON_ARRAY != vam->json_tree.type)
1915 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1916 vat_json_init_array (&vam->json_tree);
1918 node = vat_json_array_add (&vam->json_tree);
1920 vat_json_init_object (node);
1921 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1922 vat_json_object_add_string_copy (node, "interface_name",
1923 mp->interface_name);
1924 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
1925 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
1926 vat_json_object_add_uint (node, "active_members",
1927 ntohl (mp->active_members));
1928 vat_json_object_add_uint (node, "members", ntohl (mp->members));
1932 api_sw_bond_interface_dump (vat_main_t * vam)
1934 unformat_input_t *i = vam->input;
1935 vl_api_sw_bond_interface_dump_t *mp;
1936 vl_api_control_ping_t *mp_ping;
1938 u32 sw_if_index = ~0;
1940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1942 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1944 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1951 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
1952 "interface name", "sw_if_index", "mode", "load balance",
1953 "active members", "members");
1955 /* Get list of bond interfaces */
1956 M (SW_BOND_INTERFACE_DUMP, mp);
1957 mp->sw_if_index = ntohl (sw_if_index);
1960 /* Use a control ping for synchronization */
1961 MPING (CONTROL_PING, mp_ping);
1968 static void vl_api_sw_member_interface_details_t_handler
1969 (vl_api_sw_member_interface_details_t * mp)
1971 vat_main_t *vam = &vat_main;
1974 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
1975 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
1976 ntohl (mp->weight), mp->is_local_numa);
1979 static void vl_api_sw_member_interface_details_t_handler_json
1980 (vl_api_sw_member_interface_details_t * mp)
1982 vat_main_t *vam = &vat_main;
1983 vat_json_node_t *node = NULL;
1985 if (VAT_JSON_ARRAY != vam->json_tree.type)
1987 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1988 vat_json_init_array (&vam->json_tree);
1990 node = vat_json_array_add (&vam->json_tree);
1992 vat_json_init_object (node);
1993 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1994 vat_json_object_add_string_copy (node, "interface_name",
1995 mp->interface_name);
1996 vat_json_object_add_uint (node, "passive", mp->is_passive);
1997 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
1998 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
1999 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2003 api_sw_member_interface_dump (vat_main_t * vam)
2005 unformat_input_t *i = vam->input;
2006 vl_api_sw_member_interface_dump_t *mp;
2007 vl_api_control_ping_t *mp_ping;
2008 u32 sw_if_index = ~0;
2009 u8 sw_if_index_set = 0;
2012 /* Parse args required to build the message */
2013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2015 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2016 sw_if_index_set = 1;
2017 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2018 sw_if_index_set = 1;
2023 if (sw_if_index_set == 0)
2025 errmsg ("missing vpp interface name. ");
2030 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2031 "member interface name", "sw_if_index", "passive", "long_timeout",
2032 "weight", "local numa");
2034 /* Get list of bond interfaces */
2035 M (SW_MEMBER_INTERFACE_DUMP, mp);
2036 mp->sw_if_index = ntohl (sw_if_index);
2039 /* Use a control ping for synchronization */
2040 MPING (CONTROL_PING, mp_ping);
2047 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2048 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2050 vat_main_t *vam = &vat_main;
2051 i32 retval = ntohl (mp->retval);
2052 if (vam->async_mode)
2054 vam->async_errors += (retval < 0);
2058 vam->retval = retval;
2059 vam->sw_if_index = ntohl (mp->sw_if_index);
2060 vam->result_ready = 1;
2062 vam->regenerate_interface_table = 1;
2065 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2066 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2068 vat_main_t *vam = &vat_main;
2069 vat_json_node_t node;
2071 vat_json_init_object (&node);
2072 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2073 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2074 ntohl (mp->sw_if_index));
2076 vat_json_print (vam->ofp, &node);
2077 vat_json_free (&node);
2079 vam->retval = ntohl (mp->retval);
2080 vam->result_ready = 1;
2083 static void vl_api_create_vhost_user_if_reply_t_handler
2084 (vl_api_create_vhost_user_if_reply_t * mp)
2086 vat_main_t *vam = &vat_main;
2087 i32 retval = ntohl (mp->retval);
2088 if (vam->async_mode)
2090 vam->async_errors += (retval < 0);
2094 vam->retval = retval;
2095 vam->sw_if_index = ntohl (mp->sw_if_index);
2096 vam->result_ready = 1;
2098 vam->regenerate_interface_table = 1;
2101 static void vl_api_create_vhost_user_if_reply_t_handler_json
2102 (vl_api_create_vhost_user_if_reply_t * mp)
2104 vat_main_t *vam = &vat_main;
2105 vat_json_node_t node;
2107 vat_json_init_object (&node);
2108 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2109 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2111 vat_json_print (vam->ofp, &node);
2112 vat_json_free (&node);
2114 vam->retval = ntohl (mp->retval);
2115 vam->result_ready = 1;
2118 static void vl_api_create_vhost_user_if_v2_reply_t_handler
2119 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2121 vat_main_t *vam = &vat_main;
2122 i32 retval = ntohl (mp->retval);
2123 if (vam->async_mode)
2125 vam->async_errors += (retval < 0);
2129 vam->retval = retval;
2130 vam->sw_if_index = ntohl (mp->sw_if_index);
2131 vam->result_ready = 1;
2133 vam->regenerate_interface_table = 1;
2136 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2137 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2139 vat_main_t *vam = &vat_main;
2140 vat_json_node_t node;
2142 vat_json_init_object (&node);
2143 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2144 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2146 vat_json_print (vam->ofp, &node);
2147 vat_json_free (&node);
2149 vam->retval = ntohl (mp->retval);
2150 vam->result_ready = 1;
2153 static void vl_api_ip_address_details_t_handler
2154 (vl_api_ip_address_details_t * mp)
2156 vat_main_t *vam = &vat_main;
2157 static ip_address_details_t empty_ip_address_details = { {0} };
2158 ip_address_details_t *address = NULL;
2159 ip_details_t *current_ip_details = NULL;
2160 ip_details_t *details = NULL;
2162 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2164 if (!details || vam->current_sw_if_index >= vec_len (details)
2165 || !details[vam->current_sw_if_index].present)
2167 errmsg ("ip address details arrived but not stored");
2168 errmsg ("ip_dump should be called first");
2172 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2174 #define addresses (current_ip_details->addr)
2176 vec_validate_init_empty (addresses, vec_len (addresses),
2177 empty_ip_address_details);
2179 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2181 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2182 address->prefix_length = mp->prefix.len;
2186 static void vl_api_ip_address_details_t_handler_json
2187 (vl_api_ip_address_details_t * mp)
2189 vat_main_t *vam = &vat_main;
2190 vat_json_node_t *node = NULL;
2192 if (VAT_JSON_ARRAY != vam->json_tree.type)
2194 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2195 vat_json_init_array (&vam->json_tree);
2197 node = vat_json_array_add (&vam->json_tree);
2199 vat_json_init_object (node);
2200 vat_json_object_add_prefix (node, &mp->prefix);
2204 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2206 vat_main_t *vam = &vat_main;
2207 static ip_details_t empty_ip_details = { 0 };
2208 ip_details_t *ip = NULL;
2209 u32 sw_if_index = ~0;
2211 sw_if_index = ntohl (mp->sw_if_index);
2213 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2214 sw_if_index, empty_ip_details);
2216 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2223 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2225 vat_main_t *vam = &vat_main;
2227 if (VAT_JSON_ARRAY != vam->json_tree.type)
2229 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2230 vat_json_init_array (&vam->json_tree);
2232 vat_json_array_add_uint (&vam->json_tree,
2233 clib_net_to_host_u32 (mp->sw_if_index));
2236 static void vl_api_get_first_msg_id_reply_t_handler
2237 (vl_api_get_first_msg_id_reply_t * mp)
2239 vat_main_t *vam = &vat_main;
2240 i32 retval = ntohl (mp->retval);
2242 if (vam->async_mode)
2244 vam->async_errors += (retval < 0);
2248 vam->retval = retval;
2249 vam->result_ready = 1;
2253 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2257 static void vl_api_get_first_msg_id_reply_t_handler_json
2258 (vl_api_get_first_msg_id_reply_t * mp)
2260 vat_main_t *vam = &vat_main;
2261 vat_json_node_t node;
2263 vat_json_init_object (&node);
2264 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2265 vat_json_object_add_uint (&node, "first_msg_id",
2266 (uint) ntohs (mp->first_msg_id));
2268 vat_json_print (vam->ofp, &node);
2269 vat_json_free (&node);
2271 vam->retval = ntohl (mp->retval);
2272 vam->result_ready = 1;
2275 static void vl_api_get_node_graph_reply_t_handler
2276 (vl_api_get_node_graph_reply_t * mp)
2278 vat_main_t *vam = &vat_main;
2279 i32 retval = ntohl (mp->retval);
2280 u8 *pvt_copy, *reply;
2285 if (vam->async_mode)
2287 vam->async_errors += (retval < 0);
2291 vam->retval = retval;
2292 vam->result_ready = 1;
2295 /* "Should never happen..." */
2299 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2300 pvt_copy = vec_dup (reply);
2302 /* Toss the shared-memory original... */
2303 oldheap = vl_msg_push_heap ();
2307 vl_msg_pop_heap (oldheap);
2309 if (vam->graph_nodes)
2311 hash_free (vam->graph_node_index_by_name);
2313 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2315 node = vam->graph_nodes[0][i];
2316 vec_free (node->name);
2317 vec_free (node->next_nodes);
2320 vec_free (vam->graph_nodes[0]);
2321 vec_free (vam->graph_nodes);
2324 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2325 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2326 vec_free (pvt_copy);
2328 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2330 node = vam->graph_nodes[0][i];
2331 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2335 static void vl_api_get_node_graph_reply_t_handler_json
2336 (vl_api_get_node_graph_reply_t * mp)
2338 vat_main_t *vam = &vat_main;
2340 vat_json_node_t node;
2343 /* $$$$ make this real? */
2344 vat_json_init_object (&node);
2345 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2346 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2348 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2350 /* Toss the shared-memory original... */
2351 oldheap = vl_msg_push_heap ();
2355 vl_msg_pop_heap (oldheap);
2357 vat_json_print (vam->ofp, &node);
2358 vat_json_free (&node);
2360 vam->retval = ntohl (mp->retval);
2361 vam->result_ready = 1;
2364 /* Format hex dump. */
2366 format_hex_bytes (u8 * s, va_list * va)
2368 u8 *bytes = va_arg (*va, u8 *);
2369 int n_bytes = va_arg (*va, int);
2372 /* Print short or long form depending on byte count. */
2373 uword short_form = n_bytes <= 32;
2374 u32 indent = format_get_indent (s);
2379 for (i = 0; i < n_bytes; i++)
2381 if (!short_form && (i % 32) == 0)
2382 s = format (s, "%08x: ", i);
2383 s = format (s, "%02x", bytes[i]);
2384 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2385 s = format (s, "\n%U", format_white_space, indent);
2392 * Generate boilerplate reply handlers, which
2393 * dig the return value out of the xxx_reply_t API message,
2394 * stick it into vam->retval, and set vam->result_ready
2396 * Could also do this by pointing N message decode slots at
2397 * a single function, but that could break in subtle ways.
2400 #define foreach_standard_reply_retval_handler \
2401 _(sw_interface_set_flags_reply) \
2402 _(sw_interface_add_del_address_reply) \
2403 _(sw_interface_set_rx_mode_reply) \
2404 _(sw_interface_set_rx_placement_reply) \
2405 _(sw_interface_set_table_reply) \
2406 _(sw_interface_set_mpls_enable_reply) \
2407 _(sw_interface_set_vpath_reply) \
2408 _(sw_interface_set_l2_bridge_reply) \
2409 _(sw_interface_set_bond_weight_reply) \
2410 _(bridge_domain_add_del_reply) \
2411 _(sw_interface_set_l2_xconnect_reply) \
2412 _(l2fib_add_del_reply) \
2413 _(l2fib_flush_int_reply) \
2414 _(l2fib_flush_bd_reply) \
2415 _(ip_route_add_del_reply) \
2416 _(ip_table_add_del_reply) \
2417 _(ip_table_replace_begin_reply) \
2418 _(ip_table_flush_reply) \
2419 _(ip_table_replace_end_reply) \
2420 _(ip_mroute_add_del_reply) \
2421 _(mpls_route_add_del_reply) \
2422 _(mpls_table_add_del_reply) \
2423 _(mpls_ip_bind_unbind_reply) \
2424 _(sw_interface_set_unnumbered_reply) \
2425 _(set_ip_flow_hash_reply) \
2426 _(sw_interface_ip6_enable_disable_reply) \
2427 _(l2_patch_add_del_reply) \
2428 _(sr_mpls_policy_add_reply) \
2429 _(sr_mpls_policy_mod_reply) \
2430 _(sr_mpls_policy_del_reply) \
2431 _(sr_policy_add_reply) \
2432 _(sr_policy_mod_reply) \
2433 _(sr_policy_del_reply) \
2434 _(sr_localsid_add_del_reply) \
2435 _(sr_steering_add_del_reply) \
2436 _(l2_fib_clear_table_reply) \
2437 _(l2_interface_efp_filter_reply) \
2438 _(l2_interface_vlan_tag_rewrite_reply) \
2439 _(modify_vhost_user_if_reply) \
2440 _(modify_vhost_user_if_v2_reply) \
2441 _(delete_vhost_user_if_reply) \
2442 _(want_l2_macs_events_reply) \
2443 _(delete_loopback_reply) \
2444 _(bd_ip_mac_add_del_reply) \
2445 _(bd_ip_mac_flush_reply) \
2446 _(want_interface_events_reply) \
2447 _(sw_interface_clear_stats_reply) \
2448 _(ioam_enable_reply) \
2449 _(ioam_disable_reply) \
2450 _(af_packet_delete_reply) \
2451 _(sw_interface_span_enable_disable_reply) \
2452 _(ip_source_and_port_range_check_add_del_reply) \
2453 _(ip_source_and_port_range_check_interface_add_del_reply)\
2454 _(delete_subif_reply) \
2455 _(l2_interface_pbb_tag_rewrite_reply) \
2457 _(sw_interface_tag_add_del_reply) \
2458 _(sw_interface_add_del_mac_address_reply) \
2459 _(hw_interface_set_mtu_reply) \
2460 _(tcp_configure_src_addresses_reply) \
2461 _(session_rule_add_del_reply) \
2462 _(ip_container_proxy_add_del_reply) \
2463 _(qos_record_enable_disable_reply) \
2466 static void vl_api_##n##_t_handler \
2467 (vl_api_##n##_t * mp) \
2469 vat_main_t * vam = &vat_main; \
2470 i32 retval = ntohl(mp->retval); \
2471 if (vam->async_mode) { \
2472 vam->async_errors += (retval < 0); \
2474 vam->retval = retval; \
2475 vam->result_ready = 1; \
2478 foreach_standard_reply_retval_handler;
2482 static void vl_api_##n##_t_handler_json \
2483 (vl_api_##n##_t * mp) \
2485 vat_main_t * vam = &vat_main; \
2486 vat_json_node_t node; \
2487 vat_json_init_object(&node); \
2488 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2489 vat_json_print(vam->ofp, &node); \
2490 vam->retval = ntohl(mp->retval); \
2491 vam->result_ready = 1; \
2493 foreach_standard_reply_retval_handler;
2497 * Table of message reply handlers, must include boilerplate handlers
2501 #define foreach_vpe_api_reply_msg \
2502 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2503 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2504 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2505 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2506 _(CONTROL_PING_REPLY, control_ping_reply) \
2507 _(CLI_REPLY, cli_reply) \
2508 _(CLI_INBAND_REPLY, cli_inband_reply) \
2509 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2510 sw_interface_add_del_address_reply) \
2511 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2512 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2513 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2514 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2515 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2516 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2517 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2518 sw_interface_set_l2_xconnect_reply) \
2519 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2520 sw_interface_set_l2_bridge_reply) \
2521 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2522 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2523 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2524 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2525 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2526 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2527 _(L2_FLAGS_REPLY, l2_flags_reply) \
2528 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2529 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
2530 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
2531 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
2532 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2533 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2534 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2535 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2536 _(BOND_CREATE_REPLY, bond_create_reply) \
2537 _(BOND_CREATE2_REPLY, bond_create2_reply) \
2538 _(BOND_DELETE_REPLY, bond_delete_reply) \
2539 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
2540 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
2541 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
2542 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
2543 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
2544 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2545 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2546 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2547 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2548 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2549 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2550 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2551 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2552 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2553 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2554 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2555 sw_interface_set_unnumbered_reply) \
2556 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2557 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2558 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2559 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2560 sw_interface_ip6_enable_disable_reply) \
2561 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2562 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
2563 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
2564 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
2565 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
2566 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
2567 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
2568 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
2569 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
2570 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2571 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2572 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2573 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2574 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2575 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2576 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2577 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2578 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2579 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2580 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2581 _(SHOW_VERSION_REPLY, show_version_reply) \
2582 _(SHOW_THREADS_REPLY, show_threads_reply) \
2583 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2584 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2585 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2586 _(L2_MACS_EVENT, l2_macs_event) \
2587 _(IP_ADDRESS_DETAILS, ip_address_details) \
2588 _(IP_DETAILS, ip_details) \
2589 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2590 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2591 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
2592 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
2593 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2594 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2595 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2596 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2597 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
2598 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
2599 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2600 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2601 _(AF_PACKET_DETAILS, af_packet_details) \
2602 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
2603 _(MPLS_TABLE_DETAILS, mpls_table_details) \
2604 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
2605 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
2606 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
2607 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
2608 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
2609 ip_source_and_port_range_check_add_del_reply) \
2610 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
2611 ip_source_and_port_range_check_interface_add_del_reply) \
2612 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
2613 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
2614 _(SET_PUNT_REPLY, set_punt_reply) \
2615 _(IP_TABLE_DETAILS, ip_table_details) \
2616 _(IP_ROUTE_DETAILS, ip_route_details) \
2617 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
2618 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
2619 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
2620 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
2621 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
2622 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
2623 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
2624 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
2625 _(SESSION_RULES_DETAILS, session_rules_details) \
2626 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
2627 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
2629 #define foreach_standalone_reply_msg \
2630 _(SW_INTERFACE_EVENT, sw_interface_event)
2638 #define STR_VTR_OP_CASE(op) \
2639 case L2_VTR_ ## op: \
2643 str_vtr_op (u32 vtr_op)
2647 STR_VTR_OP_CASE (DISABLED);
2648 STR_VTR_OP_CASE (PUSH_1);
2649 STR_VTR_OP_CASE (PUSH_2);
2650 STR_VTR_OP_CASE (POP_1);
2651 STR_VTR_OP_CASE (POP_2);
2652 STR_VTR_OP_CASE (TRANSLATE_1_1);
2653 STR_VTR_OP_CASE (TRANSLATE_1_2);
2654 STR_VTR_OP_CASE (TRANSLATE_2_1);
2655 STR_VTR_OP_CASE (TRANSLATE_2_2);
2662 dump_sub_interface_table (vat_main_t * vam)
2664 const sw_interface_subif_t *sub = NULL;
2666 if (vam->json_output)
2669 ("JSON output supported only for VPE API calls and dump_stats_table");
2674 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
2675 "Interface", "sw_if_index",
2676 "sub id", "dot1ad", "tags", "outer id",
2677 "inner id", "exact", "default", "outer any", "inner any");
2679 vec_foreach (sub, vam->sw_if_subif_table)
2682 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
2683 sub->interface_name,
2685 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2686 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2687 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2688 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2689 if (sub->vtr_op != L2_VTR_DISABLED)
2692 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2693 "tag1: %d tag2: %d ]",
2694 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
2695 sub->vtr_tag1, sub->vtr_tag2);
2703 name_sort_cmp (void *a1, void *a2)
2705 name_sort_t *n1 = a1;
2706 name_sort_t *n2 = a2;
2708 return strcmp ((char *) n1->name, (char *) n2->name);
2712 dump_interface_table (vat_main_t * vam)
2715 name_sort_t *nses = 0, *ns;
2717 if (vam->json_output)
2720 ("JSON output supported only for VPE API calls and dump_stats_table");
2725 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2727 vec_add2 (nses, ns, 1);
2728 ns->name = (u8 *)(p->key);
2729 ns->value = (u32) p->value[0];
2733 vec_sort_with_function (nses, name_sort_cmp);
2735 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
2736 vec_foreach (ns, nses)
2738 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
2745 dump_ip_table (vat_main_t * vam, int is_ipv6)
2747 const ip_details_t *det = NULL;
2748 const ip_address_details_t *address = NULL;
2751 print (vam->ofp, "%-12s", "sw_if_index");
2753 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
2760 print (vam->ofp, "%-12d", i);
2761 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
2766 vec_foreach (address, det->addr)
2770 is_ipv6 ? format_ip6_address : format_ip4_address,
2771 address->ip, address->prefix_length);
2779 dump_ipv4_table (vat_main_t * vam)
2781 if (vam->json_output)
2784 ("JSON output supported only for VPE API calls and dump_stats_table");
2788 return dump_ip_table (vam, 0);
2792 dump_ipv6_table (vat_main_t * vam)
2794 if (vam->json_output)
2797 ("JSON output supported only for VPE API calls and dump_stats_table");
2801 return dump_ip_table (vam, 1);
2805 * Pass CLI buffers directly in the CLI_INBAND API message,
2806 * instead of an additional shared memory area.
2809 exec_inband (vat_main_t * vam)
2811 vl_api_cli_inband_t *mp;
2812 unformat_input_t *i = vam->input;
2815 if (vec_len (i->buffer) == 0)
2818 if (vam->exec_mode == 0 && unformat (i, "mode"))
2823 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
2830 * In order for the CLI command to work, it
2831 * must be a vector ending in \n, not a C-string ending
2834 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
2835 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
2839 /* json responses may or may not include a useful reply... */
2840 if (vec_len (vam->cmd_reply))
2841 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
2846 exec (vat_main_t * vam)
2848 return exec_inband (vam);
2852 api_create_loopback (vat_main_t * vam)
2854 unformat_input_t *i = vam->input;
2855 vl_api_create_loopback_t *mp;
2856 vl_api_create_loopback_instance_t *mp_lbi;
2859 u8 is_specified = 0;
2860 u32 user_instance = 0;
2863 clib_memset (mac_address, 0, sizeof (mac_address));
2865 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2867 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2869 if (unformat (i, "instance %d", &user_instance))
2877 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
2878 mp_lbi->is_specified = is_specified;
2880 mp_lbi->user_instance = htonl (user_instance);
2882 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
2887 /* Construct the API message */
2888 M (CREATE_LOOPBACK, mp);
2890 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2899 api_delete_loopback (vat_main_t * vam)
2901 unformat_input_t *i = vam->input;
2902 vl_api_delete_loopback_t *mp;
2903 u32 sw_if_index = ~0;
2906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2908 if (unformat (i, "sw_if_index %d", &sw_if_index))
2914 if (sw_if_index == ~0)
2916 errmsg ("missing sw_if_index");
2920 /* Construct the API message */
2921 M (DELETE_LOOPBACK, mp);
2922 mp->sw_if_index = ntohl (sw_if_index);
2930 api_want_interface_events (vat_main_t * vam)
2932 unformat_input_t *i = vam->input;
2933 vl_api_want_interface_events_t *mp;
2937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2939 if (unformat (i, "enable"))
2941 else if (unformat (i, "disable"))
2949 errmsg ("missing enable|disable");
2953 M (WANT_INTERFACE_EVENTS, mp);
2954 mp->enable_disable = enable;
2956 vam->interface_event_display = enable;
2964 /* Note: non-static, called once to set up the initial intfc table */
2966 api_sw_interface_dump (vat_main_t * vam)
2968 vl_api_sw_interface_dump_t *mp;
2969 vl_api_control_ping_t *mp_ping;
2971 name_sort_t *nses = 0, *ns;
2972 sw_interface_subif_t *sub = NULL;
2975 /* Toss the old name table */
2977 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2979 vec_add2 (nses, ns, 1);
2980 ns->name = (u8 *)(p->key);
2981 ns->value = (u32) p->value[0];
2985 hash_free (vam->sw_if_index_by_interface_name);
2987 vec_foreach (ns, nses) vec_free (ns->name);
2991 vec_foreach (sub, vam->sw_if_subif_table)
2993 vec_free (sub->interface_name);
2995 vec_free (vam->sw_if_subif_table);
2997 /* recreate the interface name hash table */
2998 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3001 * Ask for all interface names. Otherwise, the epic catalog of
3002 * name filters becomes ridiculously long, and vat ends up needing
3003 * to be taught about new interface types.
3005 M (SW_INTERFACE_DUMP, mp);
3008 /* Use a control ping for synchronization */
3009 MPING (CONTROL_PING, mp_ping);
3017 api_sw_interface_set_flags (vat_main_t * vam)
3019 unformat_input_t *i = vam->input;
3020 vl_api_sw_interface_set_flags_t *mp;
3022 u8 sw_if_index_set = 0;
3026 /* Parse args required to build the message */
3027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3029 if (unformat (i, "admin-up"))
3031 else if (unformat (i, "admin-down"))
3034 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3035 sw_if_index_set = 1;
3036 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3037 sw_if_index_set = 1;
3042 if (sw_if_index_set == 0)
3044 errmsg ("missing interface name or sw_if_index");
3048 /* Construct the API message */
3049 M (SW_INTERFACE_SET_FLAGS, mp);
3050 mp->sw_if_index = ntohl (sw_if_index);
3051 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3056 /* Wait for a reply, return the good/bad news... */
3062 api_sw_interface_set_rx_mode (vat_main_t * vam)
3064 unformat_input_t *i = vam->input;
3065 vl_api_sw_interface_set_rx_mode_t *mp;
3067 u8 sw_if_index_set = 0;
3069 u8 queue_id_valid = 0;
3071 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3073 /* Parse args required to build the message */
3074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3076 if (unformat (i, "queue %d", &queue_id))
3078 else if (unformat (i, "polling"))
3079 mode = VNET_HW_IF_RX_MODE_POLLING;
3080 else if (unformat (i, "interrupt"))
3081 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3082 else if (unformat (i, "adaptive"))
3083 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3085 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3086 sw_if_index_set = 1;
3087 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3088 sw_if_index_set = 1;
3093 if (sw_if_index_set == 0)
3095 errmsg ("missing interface name or sw_if_index");
3098 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3100 errmsg ("missing rx-mode");
3104 /* Construct the API message */
3105 M (SW_INTERFACE_SET_RX_MODE, mp);
3106 mp->sw_if_index = ntohl (sw_if_index);
3107 mp->mode = (vl_api_rx_mode_t) mode;
3108 mp->queue_id_valid = queue_id_valid;
3109 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3114 /* Wait for a reply, return the good/bad news... */
3120 api_sw_interface_set_rx_placement (vat_main_t * vam)
3122 unformat_input_t *i = vam->input;
3123 vl_api_sw_interface_set_rx_placement_t *mp;
3125 u8 sw_if_index_set = 0;
3128 u32 queue_id, thread_index;
3130 /* Parse args required to build the message */
3131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3133 if (unformat (i, "queue %d", &queue_id))
3135 else if (unformat (i, "main"))
3137 else if (unformat (i, "worker %d", &thread_index))
3140 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3141 sw_if_index_set = 1;
3142 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3143 sw_if_index_set = 1;
3148 if (sw_if_index_set == 0)
3150 errmsg ("missing interface name or sw_if_index");
3156 /* Construct the API message */
3157 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3158 mp->sw_if_index = ntohl (sw_if_index);
3159 mp->worker_id = ntohl (thread_index);
3160 mp->queue_id = ntohl (queue_id);
3161 mp->is_main = is_main;
3165 /* Wait for a reply, return the good/bad news... */
3170 static void vl_api_sw_interface_rx_placement_details_t_handler
3171 (vl_api_sw_interface_rx_placement_details_t * mp)
3173 vat_main_t *vam = &vat_main;
3174 u32 worker_id = ntohl (mp->worker_id);
3177 "\n%-11d %-11s %-6d %-5d %-9s",
3178 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3179 worker_id, ntohl (mp->queue_id),
3181 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3184 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3185 (vl_api_sw_interface_rx_placement_details_t * mp)
3187 vat_main_t *vam = &vat_main;
3188 vat_json_node_t *node = NULL;
3190 if (VAT_JSON_ARRAY != vam->json_tree.type)
3192 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3193 vat_json_init_array (&vam->json_tree);
3195 node = vat_json_array_add (&vam->json_tree);
3197 vat_json_init_object (node);
3198 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3199 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3200 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3201 vat_json_object_add_uint (node, "mode", mp->mode);
3205 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3207 unformat_input_t *i = vam->input;
3208 vl_api_sw_interface_rx_placement_dump_t *mp;
3209 vl_api_control_ping_t *mp_ping;
3212 u8 sw_if_index_set = 0;
3214 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3216 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3218 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3225 "\n%-11s %-11s %-6s %-5s %-4s",
3226 "sw_if_index", "main/worker", "thread", "queue", "mode");
3228 /* Dump Interface rx placement */
3229 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3231 if (sw_if_index_set)
3232 mp->sw_if_index = htonl (sw_if_index);
3234 mp->sw_if_index = ~0;
3238 /* Use a control ping for synchronization */
3239 MPING (CONTROL_PING, mp_ping);
3247 api_sw_interface_clear_stats (vat_main_t * vam)
3249 unformat_input_t *i = vam->input;
3250 vl_api_sw_interface_clear_stats_t *mp;
3252 u8 sw_if_index_set = 0;
3255 /* Parse args required to build the message */
3256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3258 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3259 sw_if_index_set = 1;
3260 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3261 sw_if_index_set = 1;
3266 /* Construct the API message */
3267 M (SW_INTERFACE_CLEAR_STATS, mp);
3269 if (sw_if_index_set == 1)
3270 mp->sw_if_index = ntohl (sw_if_index);
3272 mp->sw_if_index = ~0;
3277 /* Wait for a reply, return the good/bad news... */
3283 api_sw_interface_add_del_address (vat_main_t * vam)
3285 unformat_input_t *i = vam->input;
3286 vl_api_sw_interface_add_del_address_t *mp;
3288 u8 sw_if_index_set = 0;
3289 u8 is_add = 1, del_all = 0;
3290 u32 address_length = 0;
3291 u8 v4_address_set = 0;
3292 u8 v6_address_set = 0;
3293 ip4_address_t v4address;
3294 ip6_address_t v6address;
3297 /* Parse args required to build the message */
3298 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3300 if (unformat (i, "del-all"))
3302 else if (unformat (i, "del"))
3305 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3306 sw_if_index_set = 1;
3307 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3308 sw_if_index_set = 1;
3309 else if (unformat (i, "%U/%d",
3310 unformat_ip4_address, &v4address, &address_length))
3312 else if (unformat (i, "%U/%d",
3313 unformat_ip6_address, &v6address, &address_length))
3319 if (sw_if_index_set == 0)
3321 errmsg ("missing interface name or sw_if_index");
3324 if (v4_address_set && v6_address_set)
3326 errmsg ("both v4 and v6 addresses set");
3329 if (!v4_address_set && !v6_address_set && !del_all)
3331 errmsg ("no addresses set");
3335 /* Construct the API message */
3336 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3338 mp->sw_if_index = ntohl (sw_if_index);
3339 mp->is_add = is_add;
3340 mp->del_all = del_all;
3343 mp->prefix.address.af = ADDRESS_IP6;
3344 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3348 mp->prefix.address.af = ADDRESS_IP4;
3349 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3351 mp->prefix.len = address_length;
3356 /* Wait for a reply, return good/bad news */
3362 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3364 unformat_input_t *i = vam->input;
3365 vl_api_sw_interface_set_mpls_enable_t *mp;
3367 u8 sw_if_index_set = 0;
3371 /* Parse args required to build the message */
3372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3374 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3375 sw_if_index_set = 1;
3376 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3377 sw_if_index_set = 1;
3378 else if (unformat (i, "disable"))
3380 else if (unformat (i, "dis"))
3386 if (sw_if_index_set == 0)
3388 errmsg ("missing interface name or sw_if_index");
3392 /* Construct the API message */
3393 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3395 mp->sw_if_index = ntohl (sw_if_index);
3396 mp->enable = enable;
3401 /* Wait for a reply... */
3407 api_sw_interface_set_table (vat_main_t * vam)
3409 unformat_input_t *i = vam->input;
3410 vl_api_sw_interface_set_table_t *mp;
3411 u32 sw_if_index, vrf_id = 0;
3412 u8 sw_if_index_set = 0;
3416 /* Parse args required to build the message */
3417 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3419 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3420 sw_if_index_set = 1;
3421 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3422 sw_if_index_set = 1;
3423 else if (unformat (i, "vrf %d", &vrf_id))
3425 else if (unformat (i, "ipv6"))
3431 if (sw_if_index_set == 0)
3433 errmsg ("missing interface name or sw_if_index");
3437 /* Construct the API message */
3438 M (SW_INTERFACE_SET_TABLE, mp);
3440 mp->sw_if_index = ntohl (sw_if_index);
3441 mp->is_ipv6 = is_ipv6;
3442 mp->vrf_id = ntohl (vrf_id);
3447 /* Wait for a reply... */
3452 static void vl_api_sw_interface_get_table_reply_t_handler
3453 (vl_api_sw_interface_get_table_reply_t * mp)
3455 vat_main_t *vam = &vat_main;
3457 print (vam->ofp, "%d", ntohl (mp->vrf_id));
3459 vam->retval = ntohl (mp->retval);
3460 vam->result_ready = 1;
3464 static void vl_api_sw_interface_get_table_reply_t_handler_json
3465 (vl_api_sw_interface_get_table_reply_t * mp)
3467 vat_main_t *vam = &vat_main;
3468 vat_json_node_t node;
3470 vat_json_init_object (&node);
3471 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3472 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3474 vat_json_print (vam->ofp, &node);
3475 vat_json_free (&node);
3477 vam->retval = ntohl (mp->retval);
3478 vam->result_ready = 1;
3482 api_sw_interface_get_table (vat_main_t * vam)
3484 unformat_input_t *i = vam->input;
3485 vl_api_sw_interface_get_table_t *mp;
3487 u8 sw_if_index_set = 0;
3491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3493 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3494 sw_if_index_set = 1;
3495 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3496 sw_if_index_set = 1;
3497 else if (unformat (i, "ipv6"))
3503 if (sw_if_index_set == 0)
3505 errmsg ("missing interface name or sw_if_index");
3509 M (SW_INTERFACE_GET_TABLE, mp);
3510 mp->sw_if_index = htonl (sw_if_index);
3511 mp->is_ipv6 = is_ipv6;
3519 api_sw_interface_set_vpath (vat_main_t * vam)
3521 unformat_input_t *i = vam->input;
3522 vl_api_sw_interface_set_vpath_t *mp;
3523 u32 sw_if_index = 0;
3524 u8 sw_if_index_set = 0;
3528 /* Parse args required to build the message */
3529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3531 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3532 sw_if_index_set = 1;
3533 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3534 sw_if_index_set = 1;
3535 else if (unformat (i, "enable"))
3537 else if (unformat (i, "disable"))
3543 if (sw_if_index_set == 0)
3545 errmsg ("missing interface name or sw_if_index");
3549 /* Construct the API message */
3550 M (SW_INTERFACE_SET_VPATH, mp);
3552 mp->sw_if_index = ntohl (sw_if_index);
3553 mp->enable = is_enable;
3558 /* Wait for a reply... */
3564 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3566 unformat_input_t *i = vam->input;
3567 vl_api_sw_interface_set_l2_xconnect_t *mp;
3569 u8 rx_sw_if_index_set = 0;
3571 u8 tx_sw_if_index_set = 0;
3575 /* Parse args required to build the message */
3576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3578 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3579 rx_sw_if_index_set = 1;
3580 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3581 tx_sw_if_index_set = 1;
3582 else if (unformat (i, "rx"))
3584 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3586 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3588 rx_sw_if_index_set = 1;
3593 else if (unformat (i, "tx"))
3595 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3597 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3599 tx_sw_if_index_set = 1;
3604 else if (unformat (i, "enable"))
3606 else if (unformat (i, "disable"))
3612 if (rx_sw_if_index_set == 0)
3614 errmsg ("missing rx interface name or rx_sw_if_index");
3618 if (enable && (tx_sw_if_index_set == 0))
3620 errmsg ("missing tx interface name or tx_sw_if_index");
3624 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
3626 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3627 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
3628 mp->enable = enable;
3636 api_sw_interface_set_l2_bridge (vat_main_t * vam)
3638 unformat_input_t *i = vam->input;
3639 vl_api_sw_interface_set_l2_bridge_t *mp;
3640 vl_api_l2_port_type_t port_type;
3642 u8 rx_sw_if_index_set = 0;
3649 port_type = L2_API_PORT_TYPE_NORMAL;
3651 /* Parse args required to build the message */
3652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3654 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3655 rx_sw_if_index_set = 1;
3656 else if (unformat (i, "bd_id %d", &bd_id))
3660 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
3661 rx_sw_if_index_set = 1;
3662 else if (unformat (i, "shg %d", &shg))
3664 else if (unformat (i, "bvi"))
3665 port_type = L2_API_PORT_TYPE_BVI;
3666 else if (unformat (i, "uu-fwd"))
3667 port_type = L2_API_PORT_TYPE_UU_FWD;
3668 else if (unformat (i, "enable"))
3670 else if (unformat (i, "disable"))
3676 if (rx_sw_if_index_set == 0)
3678 errmsg ("missing rx interface name or sw_if_index");
3682 if (enable && (bd_id_set == 0))
3684 errmsg ("missing bridge domain");
3688 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
3690 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3691 mp->bd_id = ntohl (bd_id);
3693 mp->port_type = ntohl (port_type);
3694 mp->enable = enable;
3702 api_bridge_domain_dump (vat_main_t * vam)
3704 unformat_input_t *i = vam->input;
3705 vl_api_bridge_domain_dump_t *mp;
3706 vl_api_control_ping_t *mp_ping;
3710 /* Parse args required to build the message */
3711 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3713 if (unformat (i, "bd_id %d", &bd_id))
3719 M (BRIDGE_DOMAIN_DUMP, mp);
3720 mp->bd_id = ntohl (bd_id);
3723 /* Use a control ping for synchronization */
3724 MPING (CONTROL_PING, mp_ping);
3732 api_bridge_domain_add_del (vat_main_t * vam)
3734 unformat_input_t *i = vam->input;
3735 vl_api_bridge_domain_add_del_t *mp;
3738 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3743 /* Parse args required to build the message */
3744 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3746 if (unformat (i, "bd_id %d", &bd_id))
3748 else if (unformat (i, "flood %d", &flood))
3750 else if (unformat (i, "uu-flood %d", &uu_flood))
3752 else if (unformat (i, "forward %d", &forward))
3754 else if (unformat (i, "learn %d", &learn))
3756 else if (unformat (i, "arp-term %d", &arp_term))
3758 else if (unformat (i, "mac-age %d", &mac_age))
3760 else if (unformat (i, "bd-tag %s", &bd_tag))
3762 else if (unformat (i, "del"))
3765 flood = uu_flood = forward = learn = 0;
3773 errmsg ("missing bridge domain");
3780 errmsg ("mac age must be less than 256 ");
3785 if ((bd_tag) && (vec_len (bd_tag) > 63))
3787 errmsg ("bd-tag cannot be longer than 63");
3792 M (BRIDGE_DOMAIN_ADD_DEL, mp);
3794 mp->bd_id = ntohl (bd_id);
3796 mp->uu_flood = uu_flood;
3797 mp->forward = forward;
3799 mp->arp_term = arp_term;
3800 mp->is_add = is_add;
3801 mp->mac_age = (u8) mac_age;
3804 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
3805 mp->bd_tag[vec_len (bd_tag)] = 0;
3816 api_l2fib_flush_bd (vat_main_t * vam)
3818 unformat_input_t *i = vam->input;
3819 vl_api_l2fib_flush_bd_t *mp;
3823 /* Parse args required to build the message */
3824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3826 if (unformat (i, "bd_id %d", &bd_id));
3833 errmsg ("missing bridge domain");
3837 M (L2FIB_FLUSH_BD, mp);
3839 mp->bd_id = htonl (bd_id);
3847 api_l2fib_flush_int (vat_main_t * vam)
3849 unformat_input_t *i = vam->input;
3850 vl_api_l2fib_flush_int_t *mp;
3851 u32 sw_if_index = ~0;
3854 /* Parse args required to build the message */
3855 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3857 if (unformat (i, "sw_if_index %d", &sw_if_index));
3859 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
3864 if (sw_if_index == ~0)
3866 errmsg ("missing interface name or sw_if_index");
3870 M (L2FIB_FLUSH_INT, mp);
3872 mp->sw_if_index = ntohl (sw_if_index);
3880 api_l2fib_add_del (vat_main_t * vam)
3882 unformat_input_t *i = vam->input;
3883 vl_api_l2fib_add_del_t *mp;
3889 u32 sw_if_index = 0;
3890 u8 sw_if_index_set = 0;
3899 /* Parse args required to build the message */
3900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3902 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
3904 else if (unformat (i, "bd_id %d", &bd_id))
3906 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3907 sw_if_index_set = 1;
3908 else if (unformat (i, "sw_if"))
3910 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3913 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3914 sw_if_index_set = 1;
3919 else if (unformat (i, "static"))
3921 else if (unformat (i, "filter"))
3926 else if (unformat (i, "bvi"))
3931 else if (unformat (i, "del"))
3933 else if (unformat (i, "count %d", &count))
3941 errmsg ("missing mac address");
3947 errmsg ("missing bridge domain");
3951 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
3953 errmsg ("missing interface name or sw_if_index");
3959 /* Turn on async mode */
3960 vam->async_mode = 1;
3961 vam->async_errors = 0;
3962 before = vat_time_now (vam);
3965 for (j = 0; j < count; j++)
3967 M (L2FIB_ADD_DEL, mp);
3969 clib_memcpy (mp->mac, mac, 6);
3970 mp->bd_id = ntohl (bd_id);
3971 mp->is_add = is_add;
3972 mp->sw_if_index = ntohl (sw_if_index);
3976 mp->static_mac = static_mac;
3977 mp->filter_mac = filter_mac;
3978 mp->bvi_mac = bvi_mac;
3980 increment_mac_address (mac);
3987 vl_api_control_ping_t *mp_ping;
3990 /* Shut off async mode */
3991 vam->async_mode = 0;
3993 MPING (CONTROL_PING, mp_ping);
3996 timeout = vat_time_now (vam) + 1.0;
3997 while (vat_time_now (vam) < timeout)
3998 if (vam->result_ready == 1)
4003 if (vam->retval == -99)
4006 if (vam->async_errors > 0)
4008 errmsg ("%d asynchronous errors", vam->async_errors);
4011 vam->async_errors = 0;
4012 after = vat_time_now (vam);
4014 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4015 count, after - before, count / (after - before));
4021 /* Wait for a reply... */
4025 /* Return the good/bad news */
4026 return (vam->retval);
4030 api_bridge_domain_set_mac_age (vat_main_t * vam)
4032 unformat_input_t *i = vam->input;
4033 vl_api_bridge_domain_set_mac_age_t *mp;
4038 /* Parse args required to build the message */
4039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4041 if (unformat (i, "bd_id %d", &bd_id));
4042 else if (unformat (i, "mac-age %d", &mac_age));
4049 errmsg ("missing bridge domain");
4055 errmsg ("mac age must be less than 256 ");
4059 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4061 mp->bd_id = htonl (bd_id);
4062 mp->mac_age = (u8) mac_age;
4070 api_l2_flags (vat_main_t * vam)
4072 unformat_input_t *i = vam->input;
4073 vl_api_l2_flags_t *mp;
4076 u8 sw_if_index_set = 0;
4080 /* Parse args required to build the message */
4081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4083 if (unformat (i, "sw_if_index %d", &sw_if_index))
4084 sw_if_index_set = 1;
4085 else if (unformat (i, "sw_if"))
4087 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4090 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4091 sw_if_index_set = 1;
4096 else if (unformat (i, "learn"))
4098 else if (unformat (i, "forward"))
4100 else if (unformat (i, "flood"))
4102 else if (unformat (i, "uu-flood"))
4103 flags |= L2_UU_FLOOD;
4104 else if (unformat (i, "arp-term"))
4105 flags |= L2_ARP_TERM;
4106 else if (unformat (i, "off"))
4108 else if (unformat (i, "disable"))
4114 if (sw_if_index_set == 0)
4116 errmsg ("missing interface name or sw_if_index");
4122 mp->sw_if_index = ntohl (sw_if_index);
4123 mp->feature_bitmap = ntohl (flags);
4124 mp->is_set = is_set;
4132 api_bridge_flags (vat_main_t * vam)
4134 unformat_input_t *i = vam->input;
4135 vl_api_bridge_flags_t *mp;
4139 bd_flags_t flags = 0;
4142 /* Parse args required to build the message */
4143 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4145 if (unformat (i, "bd_id %d", &bd_id))
4147 else if (unformat (i, "learn"))
4148 flags |= BRIDGE_API_FLAG_LEARN;
4149 else if (unformat (i, "forward"))
4150 flags |= BRIDGE_API_FLAG_FWD;
4151 else if (unformat (i, "flood"))
4152 flags |= BRIDGE_API_FLAG_FLOOD;
4153 else if (unformat (i, "uu-flood"))
4154 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4155 else if (unformat (i, "arp-term"))
4156 flags |= BRIDGE_API_FLAG_ARP_TERM;
4157 else if (unformat (i, "off"))
4159 else if (unformat (i, "disable"))
4167 errmsg ("missing bridge domain");
4171 M (BRIDGE_FLAGS, mp);
4173 mp->bd_id = ntohl (bd_id);
4174 mp->flags = ntohl (flags);
4175 mp->is_set = is_set;
4183 api_bd_ip_mac_add_del (vat_main_t * vam)
4185 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4186 vl_api_mac_address_t mac = { 0 };
4187 unformat_input_t *i = vam->input;
4188 vl_api_bd_ip_mac_add_del_t *mp;
4197 /* Parse args required to build the message */
4198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4200 if (unformat (i, "bd_id %d", &bd_id))
4204 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4208 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4212 else if (unformat (i, "del"))
4220 errmsg ("missing bridge domain");
4223 else if (ip_set == 0)
4225 errmsg ("missing IP address");
4228 else if (mac_set == 0)
4230 errmsg ("missing MAC address");
4234 M (BD_IP_MAC_ADD_DEL, mp);
4236 mp->entry.bd_id = ntohl (bd_id);
4237 mp->is_add = is_add;
4239 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4240 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4248 api_bd_ip_mac_flush (vat_main_t * vam)
4250 unformat_input_t *i = vam->input;
4251 vl_api_bd_ip_mac_flush_t *mp;
4256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4258 if (unformat (i, "bd_id %d", &bd_id))
4268 errmsg ("missing bridge domain");
4272 M (BD_IP_MAC_FLUSH, mp);
4274 mp->bd_id = ntohl (bd_id);
4281 static void vl_api_bd_ip_mac_details_t_handler
4282 (vl_api_bd_ip_mac_details_t * mp)
4284 vat_main_t *vam = &vat_main;
4288 ntohl (mp->entry.bd_id),
4289 format_vl_api_mac_address, mp->entry.mac,
4290 format_vl_api_address, &mp->entry.ip);
4293 static void vl_api_bd_ip_mac_details_t_handler_json
4294 (vl_api_bd_ip_mac_details_t * mp)
4296 vat_main_t *vam = &vat_main;
4297 vat_json_node_t *node = NULL;
4299 if (VAT_JSON_ARRAY != vam->json_tree.type)
4301 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4302 vat_json_init_array (&vam->json_tree);
4304 node = vat_json_array_add (&vam->json_tree);
4306 vat_json_init_object (node);
4307 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4308 vat_json_object_add_string_copy (node, "mac_address",
4309 format (0, "%U", format_vl_api_mac_address,
4313 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4314 vat_json_object_add_string_copy (node, "ip_address", ip);
4319 api_bd_ip_mac_dump (vat_main_t * vam)
4321 unformat_input_t *i = vam->input;
4322 vl_api_bd_ip_mac_dump_t *mp;
4323 vl_api_control_ping_t *mp_ping;
4328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4330 if (unformat (i, "bd_id %d", &bd_id))
4339 "\n%-5s %-7s %-20s %-30s",
4340 "bd_id", "is_ipv6", "mac_address", "ip_address");
4342 /* Dump Bridge Domain Ip to Mac entries */
4343 M (BD_IP_MAC_DUMP, mp);
4346 mp->bd_id = htonl (bd_id);
4352 /* Use a control ping for synchronization */
4353 MPING (CONTROL_PING, mp_ping);
4361 api_tap_create_v2 (vat_main_t * vam)
4363 unformat_input_t *i = vam->input;
4364 vl_api_tap_create_v2_t *mp;
4368 u32 num_rx_queues = 0;
4369 u8 *host_if_name = 0;
4370 u8 host_if_name_set = 0;
4373 u8 host_mac_addr[6];
4374 u8 host_mac_addr_set = 0;
4375 u8 *host_bridge = 0;
4376 u8 host_bridge_set = 0;
4377 u8 host_ip4_prefix_set = 0;
4378 u8 host_ip6_prefix_set = 0;
4379 ip4_address_t host_ip4_addr;
4380 ip4_address_t host_ip4_gw;
4381 u8 host_ip4_gw_set = 0;
4382 u32 host_ip4_prefix_len = 0;
4383 ip6_address_t host_ip6_addr;
4384 ip6_address_t host_ip6_gw;
4385 u8 host_ip6_gw_set = 0;
4386 u32 host_ip6_prefix_len = 0;
4387 u32 host_mtu_size = 0;
4388 u8 host_mtu_set = 0;
4391 u32 rx_ring_sz = 0, tx_ring_sz = 0;
4393 clib_memset (mac_address, 0, sizeof (mac_address));
4395 /* Parse args required to build the message */
4396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4398 if (unformat (i, "id %u", &id))
4402 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4404 else if (unformat (i, "host-if-name %s", &host_if_name))
4405 host_if_name_set = 1;
4406 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
4408 else if (unformat (i, "host-ns %s", &host_ns))
4410 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
4412 host_mac_addr_set = 1;
4413 else if (unformat (i, "host-bridge %s", &host_bridge))
4414 host_bridge_set = 1;
4415 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
4416 &host_ip4_addr, &host_ip4_prefix_len))
4417 host_ip4_prefix_set = 1;
4418 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
4419 &host_ip6_addr, &host_ip6_prefix_len))
4420 host_ip6_prefix_set = 1;
4421 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
4423 host_ip4_gw_set = 1;
4424 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
4426 host_ip6_gw_set = 1;
4427 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
4429 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
4431 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
4433 else if (unformat (i, "no-gso"))
4434 tap_flags &= ~TAP_API_FLAG_GSO;
4435 else if (unformat (i, "gso"))
4436 tap_flags |= TAP_API_FLAG_GSO;
4437 else if (unformat (i, "csum-offload"))
4438 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
4439 else if (unformat (i, "persist"))
4440 tap_flags |= TAP_API_FLAG_PERSIST;
4441 else if (unformat (i, "attach"))
4442 tap_flags |= TAP_API_FLAG_ATTACH;
4443 else if (unformat (i, "tun"))
4444 tap_flags |= TAP_API_FLAG_TUN;
4445 else if (unformat (i, "gro-coalesce"))
4446 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
4447 else if (unformat (i, "packed"))
4448 tap_flags |= TAP_API_FLAG_PACKED;
4449 else if (unformat (i, "in-order"))
4450 tap_flags |= TAP_API_FLAG_IN_ORDER;
4455 if (vec_len (host_if_name) > 63)
4457 errmsg ("tap name too long. ");
4460 if (vec_len (host_ns) > 63)
4462 errmsg ("host name space too long. ");
4465 if (vec_len (host_bridge) > 63)
4467 errmsg ("host bridge name too long. ");
4470 if (host_ip4_prefix_len > 32)
4472 errmsg ("host ip4 prefix length not valid. ");
4475 if (host_ip6_prefix_len > 128)
4477 errmsg ("host ip6 prefix length not valid. ");
4480 if (!is_pow2 (rx_ring_sz))
4482 errmsg ("rx ring size must be power of 2. ");
4485 if (rx_ring_sz > 32768)
4487 errmsg ("rx ring size must be 32768 or lower. ");
4490 if (!is_pow2 (tx_ring_sz))
4492 errmsg ("tx ring size must be power of 2. ");
4495 if (tx_ring_sz > 32768)
4497 errmsg ("tx ring size must be 32768 or lower. ");
4500 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
4502 errmsg ("host MTU size must be in between 64 and 65355. ");
4506 /* Construct the API message */
4507 M (TAP_CREATE_V2, mp);
4509 mp->id = ntohl (id);
4510 mp->use_random_mac = random_mac;
4511 mp->num_rx_queues = (u8) num_rx_queues;
4512 mp->tx_ring_sz = ntohs (tx_ring_sz);
4513 mp->rx_ring_sz = ntohs (rx_ring_sz);
4514 mp->host_mtu_set = host_mtu_set;
4515 mp->host_mtu_size = ntohl (host_mtu_size);
4516 mp->host_mac_addr_set = host_mac_addr_set;
4517 mp->host_ip4_prefix_set = host_ip4_prefix_set;
4518 mp->host_ip6_prefix_set = host_ip6_prefix_set;
4519 mp->host_ip4_gw_set = host_ip4_gw_set;
4520 mp->host_ip6_gw_set = host_ip6_gw_set;
4521 mp->tap_flags = ntohl (tap_flags);
4522 mp->host_namespace_set = host_ns_set;
4523 mp->host_if_name_set = host_if_name_set;
4524 mp->host_bridge_set = host_bridge_set;
4526 if (random_mac == 0)
4527 clib_memcpy (mp->mac_address, mac_address, 6);
4528 if (host_mac_addr_set)
4529 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
4530 if (host_if_name_set)
4531 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
4533 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
4534 if (host_bridge_set)
4535 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
4536 if (host_ip4_prefix_set)
4538 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
4539 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
4541 if (host_ip6_prefix_set)
4543 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
4544 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
4546 if (host_ip4_gw_set)
4547 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
4548 if (host_ip6_gw_set)
4549 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
4552 vec_free (host_if_name);
4553 vec_free (host_bridge);
4558 /* Wait for a reply... */
4564 api_tap_delete_v2 (vat_main_t * vam)
4566 unformat_input_t *i = vam->input;
4567 vl_api_tap_delete_v2_t *mp;
4568 u32 sw_if_index = ~0;
4569 u8 sw_if_index_set = 0;
4572 /* Parse args required to build the message */
4573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4575 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4576 sw_if_index_set = 1;
4577 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4578 sw_if_index_set = 1;
4583 if (sw_if_index_set == 0)
4585 errmsg ("missing vpp interface name. ");
4589 /* Construct the API message */
4590 M (TAP_DELETE_V2, mp);
4592 mp->sw_if_index = ntohl (sw_if_index);
4597 /* Wait for a reply... */
4603 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
4605 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
4608 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
4611 addr->domain = x[0];
4614 addr->function = x[3];
4620 api_virtio_pci_create_v2 (vat_main_t * vam)
4622 unformat_input_t *i = vam->input;
4623 vl_api_virtio_pci_create_v2_t *mp;
4627 u64 features = (u64) ~ (0ULL);
4628 u32 virtio_flags = 0;
4631 clib_memset (mac_address, 0, sizeof (mac_address));
4633 /* Parse args required to build the message */
4634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4636 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4640 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
4642 else if (unformat (i, "features 0x%llx", &features))
4644 else if (unformat (i, "gso-enabled"))
4645 virtio_flags |= VIRTIO_API_FLAG_GSO;
4646 else if (unformat (i, "csum-offload-enabled"))
4647 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
4648 else if (unformat (i, "gro-coalesce"))
4649 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
4650 else if (unformat (i, "packed"))
4651 virtio_flags |= VIRTIO_API_FLAG_PACKED;
4652 else if (unformat (i, "in-order"))
4653 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
4654 else if (unformat (i, "buffering"))
4655 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
4662 errmsg ("pci address must be non zero. ");
4666 /* Construct the API message */
4667 M (VIRTIO_PCI_CREATE_V2, mp);
4669 mp->use_random_mac = random_mac;
4671 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
4672 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
4673 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
4674 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
4676 mp->features = clib_host_to_net_u64 (features);
4677 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
4679 if (random_mac == 0)
4680 clib_memcpy (mp->mac_address, mac_address, 6);
4685 /* Wait for a reply... */
4691 api_virtio_pci_delete (vat_main_t * vam)
4693 unformat_input_t *i = vam->input;
4694 vl_api_virtio_pci_delete_t *mp;
4695 u32 sw_if_index = ~0;
4696 u8 sw_if_index_set = 0;
4699 /* Parse args required to build the message */
4700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4702 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4703 sw_if_index_set = 1;
4704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4705 sw_if_index_set = 1;
4710 if (sw_if_index_set == 0)
4712 errmsg ("missing vpp interface name. ");
4716 /* Construct the API message */
4717 M (VIRTIO_PCI_DELETE, mp);
4719 mp->sw_if_index = htonl (sw_if_index);
4724 /* Wait for a reply... */
4730 api_bond_create (vat_main_t * vam)
4732 unformat_input_t *i = vam->input;
4733 vl_api_bond_create_t *mp;
4743 clib_memset (mac_address, 0, sizeof (mac_address));
4746 /* Parse args required to build the message */
4747 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4749 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
4751 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
4752 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
4754 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
4757 else if (unformat (i, "numa-only"))
4759 else if (unformat (i, "id %u", &id))
4765 if (mode_is_set == 0)
4767 errmsg ("Missing bond mode. ");
4771 /* Construct the API message */
4772 M (BOND_CREATE, mp);
4774 mp->use_custom_mac = custom_mac;
4776 mp->mode = htonl (mode);
4777 mp->lb = htonl (lb);
4778 mp->id = htonl (id);
4779 mp->numa_only = numa_only;
4782 clib_memcpy (mp->mac_address, mac_address, 6);
4787 /* Wait for a reply... */
4793 api_bond_create2 (vat_main_t * vam)
4795 unformat_input_t *i = vam->input;
4796 vl_api_bond_create2_t *mp;
4807 clib_memset (mac_address, 0, sizeof (mac_address));
4810 /* Parse args required to build the message */
4811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4813 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
4815 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
4816 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
4818 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
4821 else if (unformat (i, "numa-only"))
4823 else if (unformat (i, "gso"))
4825 else if (unformat (i, "id %u", &id))
4831 if (mode_is_set == 0)
4833 errmsg ("Missing bond mode. ");
4837 /* Construct the API message */
4838 M (BOND_CREATE2, mp);
4840 mp->use_custom_mac = custom_mac;
4842 mp->mode = htonl (mode);
4843 mp->lb = htonl (lb);
4844 mp->id = htonl (id);
4845 mp->numa_only = numa_only;
4846 mp->enable_gso = gso;
4849 clib_memcpy (mp->mac_address, mac_address, 6);
4854 /* Wait for a reply... */
4860 api_bond_delete (vat_main_t * vam)
4862 unformat_input_t *i = vam->input;
4863 vl_api_bond_delete_t *mp;
4864 u32 sw_if_index = ~0;
4865 u8 sw_if_index_set = 0;
4868 /* Parse args required to build the message */
4869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4871 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4872 sw_if_index_set = 1;
4873 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4874 sw_if_index_set = 1;
4879 if (sw_if_index_set == 0)
4881 errmsg ("missing vpp interface name. ");
4885 /* Construct the API message */
4886 M (BOND_DELETE, mp);
4888 mp->sw_if_index = ntohl (sw_if_index);
4893 /* Wait for a reply... */
4899 api_bond_add_member (vat_main_t * vam)
4901 unformat_input_t *i = vam->input;
4902 vl_api_bond_add_member_t *mp;
4903 u32 bond_sw_if_index;
4907 u32 bond_sw_if_index_is_set = 0;
4909 u8 sw_if_index_is_set = 0;
4911 /* Parse args required to build the message */
4912 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4914 if (unformat (i, "sw_if_index %d", &sw_if_index))
4915 sw_if_index_is_set = 1;
4916 else if (unformat (i, "bond %u", &bond_sw_if_index))
4917 bond_sw_if_index_is_set = 1;
4918 else if (unformat (i, "passive %d", &is_passive))
4920 else if (unformat (i, "long-timeout %d", &is_long_timeout))
4926 if (bond_sw_if_index_is_set == 0)
4928 errmsg ("Missing bond sw_if_index. ");
4931 if (sw_if_index_is_set == 0)
4933 errmsg ("Missing member sw_if_index. ");
4937 /* Construct the API message */
4938 M (BOND_ADD_MEMBER, mp);
4940 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
4941 mp->sw_if_index = ntohl (sw_if_index);
4942 mp->is_long_timeout = is_long_timeout;
4943 mp->is_passive = is_passive;
4948 /* Wait for a reply... */
4954 api_bond_detach_member (vat_main_t * vam)
4956 unformat_input_t *i = vam->input;
4957 vl_api_bond_detach_member_t *mp;
4958 u32 sw_if_index = ~0;
4959 u8 sw_if_index_set = 0;
4962 /* Parse args required to build the message */
4963 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4965 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4966 sw_if_index_set = 1;
4967 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4968 sw_if_index_set = 1;
4973 if (sw_if_index_set == 0)
4975 errmsg ("missing vpp interface name. ");
4979 /* Construct the API message */
4980 M (BOND_DETACH_MEMBER, mp);
4982 mp->sw_if_index = ntohl (sw_if_index);
4987 /* Wait for a reply... */
4993 api_ip_table_add_del (vat_main_t * vam)
4995 unformat_input_t *i = vam->input;
4996 vl_api_ip_table_add_del_t *mp;
5002 /* Parse args required to build the message */
5003 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5005 if (unformat (i, "ipv6"))
5007 else if (unformat (i, "del"))
5009 else if (unformat (i, "add"))
5011 else if (unformat (i, "table %d", &table_id))
5015 clib_warning ("parse error '%U'", format_unformat_error, i);
5022 errmsg ("missing table-ID");
5026 /* Construct the API message */
5027 M (IP_TABLE_ADD_DEL, mp);
5029 mp->table.table_id = ntohl (table_id);
5030 mp->table.is_ip6 = is_ipv6;
5031 mp->is_add = is_add;
5036 /* Wait for a reply... */
5043 unformat_fib_path (unformat_input_t * input, va_list * args)
5045 vat_main_t *vam = va_arg (*args, vat_main_t *);
5046 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5047 u32 weight, preference;
5048 mpls_label_t out_label;
5050 clib_memset (path, 0, sizeof (*path));
5052 path->sw_if_index = ~0;
5056 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5058 if (unformat (input, "%U %U",
5059 unformat_vl_api_ip4_address,
5060 &path->nh.address.ip4,
5061 api_unformat_sw_if_index, vam, &path->sw_if_index))
5063 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5065 else if (unformat (input, "%U %U",
5066 unformat_vl_api_ip6_address,
5067 &path->nh.address.ip6,
5068 api_unformat_sw_if_index, vam, &path->sw_if_index))
5070 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5072 else if (unformat (input, "weight %u", &weight))
5074 path->weight = weight;
5076 else if (unformat (input, "preference %u", &preference))
5078 path->preference = preference;
5080 else if (unformat (input, "%U next-hop-table %d",
5081 unformat_vl_api_ip4_address,
5082 &path->nh.address.ip4, &path->table_id))
5084 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5086 else if (unformat (input, "%U next-hop-table %d",
5087 unformat_vl_api_ip6_address,
5088 &path->nh.address.ip6, &path->table_id))
5090 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5092 else if (unformat (input, "%U",
5093 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5096 * the recursive next-hops are by default in the default table
5099 path->sw_if_index = ~0;
5100 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5102 else if (unformat (input, "%U",
5103 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5106 * the recursive next-hops are by default in the default table
5109 path->sw_if_index = ~0;
5110 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5112 else if (unformat (input, "resolve-via-host"))
5114 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5116 else if (unformat (input, "resolve-via-attached"))
5118 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5120 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5122 path->type = FIB_API_PATH_TYPE_LOCAL;
5123 path->sw_if_index = ~0;
5124 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5126 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5128 path->type = FIB_API_PATH_TYPE_LOCAL;
5129 path->sw_if_index = ~0;
5130 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5132 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5134 else if (unformat (input, "via-label %d", &path->nh.via_label))
5136 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5137 path->sw_if_index = ~0;
5139 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5141 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5142 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5144 else if (unformat (input, "local"))
5146 path->type = FIB_API_PATH_TYPE_LOCAL;
5148 else if (unformat (input, "out-labels"))
5150 while (unformat (input, "%d", &out_label))
5152 path->label_stack[path->n_labels].label = out_label;
5153 path->label_stack[path->n_labels].is_uniform = 0;
5154 path->label_stack[path->n_labels].ttl = 64;
5158 else if (unformat (input, "via"))
5160 /* new path, back up and return */
5161 unformat_put_input (input);
5162 unformat_put_input (input);
5163 unformat_put_input (input);
5164 unformat_put_input (input);
5173 path->proto = ntohl (path->proto);
5174 path->type = ntohl (path->type);
5175 path->flags = ntohl (path->flags);
5176 path->table_id = ntohl (path->table_id);
5177 path->sw_if_index = ntohl (path->sw_if_index);
5183 api_ip_route_add_del (vat_main_t * vam)
5185 unformat_input_t *i = vam->input;
5186 vl_api_ip_route_add_del_t *mp;
5189 u8 is_multipath = 0;
5192 vl_api_prefix_t pfx = { };
5193 vl_api_fib_path_t paths[8];
5197 u32 random_add_del = 0;
5198 u32 *random_vector = 0;
5199 u32 random_seed = 0xdeaddabe;
5201 /* Parse args required to build the message */
5202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5204 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5206 else if (unformat (i, "del"))
5208 else if (unformat (i, "add"))
5210 else if (unformat (i, "vrf %d", &vrf_id))
5212 else if (unformat (i, "count %d", &count))
5214 else if (unformat (i, "random"))
5216 else if (unformat (i, "multipath"))
5218 else if (unformat (i, "seed %d", &random_seed))
5222 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5225 if (8 == path_count)
5227 errmsg ("max 8 paths");
5233 clib_warning ("parse error '%U'", format_unformat_error, i);
5240 errmsg ("specify a path; via ...");
5243 if (prefix_set == 0)
5245 errmsg ("missing prefix");
5249 /* Generate a pile of unique, random routes */
5252 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5253 u32 this_random_address;
5256 random_hash = hash_create (count, sizeof (uword));
5258 hash_set (random_hash, i->as_u32, 1);
5259 for (j = 0; j <= count; j++)
5263 this_random_address = random_u32 (&random_seed);
5264 this_random_address =
5265 clib_host_to_net_u32 (this_random_address);
5267 while (hash_get (random_hash, this_random_address));
5268 vec_add1 (random_vector, this_random_address);
5269 hash_set (random_hash, this_random_address, 1);
5271 hash_free (random_hash);
5272 set_ip4_address (&pfx.address, random_vector[0]);
5277 /* Turn on async mode */
5278 vam->async_mode = 1;
5279 vam->async_errors = 0;
5280 before = vat_time_now (vam);
5283 for (j = 0; j < count; j++)
5285 /* Construct the API message */
5286 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5288 mp->is_add = is_add;
5289 mp->is_multipath = is_multipath;
5291 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5292 mp->route.table_id = ntohl (vrf_id);
5293 mp->route.n_paths = path_count;
5295 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5298 set_ip4_address (&pfx.address, random_vector[j + 1]);
5300 increment_address (&pfx.address);
5303 /* If we receive SIGTERM, stop now... */
5308 /* When testing multiple add/del ops, use a control-ping to sync */
5311 vl_api_control_ping_t *mp_ping;
5315 /* Shut off async mode */
5316 vam->async_mode = 0;
5318 MPING (CONTROL_PING, mp_ping);
5321 timeout = vat_time_now (vam) + 1.0;
5322 while (vat_time_now (vam) < timeout)
5323 if (vam->result_ready == 1)
5328 if (vam->retval == -99)
5331 if (vam->async_errors > 0)
5333 errmsg ("%d asynchronous errors", vam->async_errors);
5336 vam->async_errors = 0;
5337 after = vat_time_now (vam);
5339 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5343 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5344 count, after - before, count / (after - before));
5350 /* Wait for a reply... */
5355 /* Return the good/bad news */
5356 return (vam->retval);
5360 api_ip_mroute_add_del (vat_main_t * vam)
5362 unformat_input_t *i = vam->input;
5363 u8 path_set = 0, prefix_set = 0, is_add = 1;
5364 vl_api_ip_mroute_add_del_t *mp;
5365 mfib_entry_flags_t eflags = 0;
5366 vl_api_mfib_path_t path;
5367 vl_api_mprefix_t pfx = { };
5371 /* Parse args required to build the message */
5372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5374 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5377 pfx.grp_address_length = htons (pfx.grp_address_length);
5379 else if (unformat (i, "del"))
5381 else if (unformat (i, "add"))
5383 else if (unformat (i, "vrf %d", &vrf_id))
5385 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
5386 path.itf_flags = htonl (path.itf_flags);
5387 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
5389 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
5393 clib_warning ("parse error '%U'", format_unformat_error, i);
5398 if (prefix_set == 0)
5400 errmsg ("missing addresses\n");
5405 errmsg ("missing path\n");
5409 /* Construct the API message */
5410 M (IP_MROUTE_ADD_DEL, mp);
5412 mp->is_add = is_add;
5413 mp->is_multipath = 1;
5415 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5416 mp->route.table_id = htonl (vrf_id);
5417 mp->route.n_paths = 1;
5418 mp->route.entry_flags = htonl (eflags);
5420 clib_memcpy (&mp->route.paths, &path, sizeof (path));
5424 /* Wait for a reply... */
5430 api_mpls_table_add_del (vat_main_t * vam)
5432 unformat_input_t *i = vam->input;
5433 vl_api_mpls_table_add_del_t *mp;
5438 /* Parse args required to build the message */
5439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5441 if (unformat (i, "table %d", &table_id))
5443 else if (unformat (i, "del"))
5445 else if (unformat (i, "add"))
5449 clib_warning ("parse error '%U'", format_unformat_error, i);
5456 errmsg ("missing table-ID");
5460 /* Construct the API message */
5461 M (MPLS_TABLE_ADD_DEL, mp);
5463 mp->mt_table.mt_table_id = ntohl (table_id);
5464 mp->mt_is_add = is_add;
5469 /* Wait for a reply... */
5476 api_mpls_route_add_del (vat_main_t * vam)
5478 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
5479 mpls_label_t local_label = MPLS_LABEL_INVALID;
5480 unformat_input_t *i = vam->input;
5481 vl_api_mpls_route_add_del_t *mp;
5482 vl_api_fib_path_t paths[8];
5486 /* Parse args required to build the message */
5487 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5489 if (unformat (i, "%d", &local_label))
5491 else if (unformat (i, "eos"))
5493 else if (unformat (i, "non-eos"))
5495 else if (unformat (i, "del"))
5497 else if (unformat (i, "add"))
5499 else if (unformat (i, "multipath"))
5501 else if (unformat (i, "count %d", &count))
5505 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5508 if (8 == path_count)
5510 errmsg ("max 8 paths");
5516 clib_warning ("parse error '%U'", format_unformat_error, i);
5523 errmsg ("specify a path; via ...");
5527 if (MPLS_LABEL_INVALID == local_label)
5529 errmsg ("missing label");
5535 /* Turn on async mode */
5536 vam->async_mode = 1;
5537 vam->async_errors = 0;
5538 before = vat_time_now (vam);
5541 for (j = 0; j < count; j++)
5543 /* Construct the API message */
5544 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5546 mp->mr_is_add = is_add;
5547 mp->mr_is_multipath = is_multipath;
5549 mp->mr_route.mr_label = local_label;
5550 mp->mr_route.mr_eos = is_eos;
5551 mp->mr_route.mr_table_id = 0;
5552 mp->mr_route.mr_n_paths = path_count;
5554 clib_memcpy (&mp->mr_route.mr_paths, paths,
5555 sizeof (paths[0]) * path_count);
5561 /* If we receive SIGTERM, stop now... */
5566 /* When testing multiple add/del ops, use a control-ping to sync */
5569 vl_api_control_ping_t *mp_ping;
5573 /* Shut off async mode */
5574 vam->async_mode = 0;
5576 MPING (CONTROL_PING, mp_ping);
5579 timeout = vat_time_now (vam) + 1.0;
5580 while (vat_time_now (vam) < timeout)
5581 if (vam->result_ready == 1)
5586 if (vam->retval == -99)
5589 if (vam->async_errors > 0)
5591 errmsg ("%d asynchronous errors", vam->async_errors);
5594 vam->async_errors = 0;
5595 after = vat_time_now (vam);
5597 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5601 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5602 count, after - before, count / (after - before));
5608 /* Wait for a reply... */
5613 /* Return the good/bad news */
5614 return (vam->retval);
5619 api_mpls_ip_bind_unbind (vat_main_t * vam)
5621 unformat_input_t *i = vam->input;
5622 vl_api_mpls_ip_bind_unbind_t *mp;
5623 u32 ip_table_id = 0;
5625 vl_api_prefix_t pfx;
5627 mpls_label_t local_label = MPLS_LABEL_INVALID;
5630 /* Parse args required to build the message */
5631 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5633 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5635 else if (unformat (i, "%d", &local_label))
5637 else if (unformat (i, "table-id %d", &ip_table_id))
5639 else if (unformat (i, "unbind"))
5641 else if (unformat (i, "bind"))
5645 clib_warning ("parse error '%U'", format_unformat_error, i);
5652 errmsg ("IP prefix not set");
5656 if (MPLS_LABEL_INVALID == local_label)
5658 errmsg ("missing label");
5662 /* Construct the API message */
5663 M (MPLS_IP_BIND_UNBIND, mp);
5665 mp->mb_is_bind = is_bind;
5666 mp->mb_ip_table_id = ntohl (ip_table_id);
5667 mp->mb_mpls_table_id = 0;
5668 mp->mb_label = ntohl (local_label);
5669 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
5674 /* Wait for a reply... */
5681 api_sr_mpls_policy_add (vat_main_t * vam)
5683 unformat_input_t *i = vam->input;
5684 vl_api_sr_mpls_policy_add_t *mp;
5690 u32 *segments = NULL;
5693 /* Parse args required to build the message */
5694 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5696 if (unformat (i, "bsid %d", &bsid))
5698 else if (unformat (i, "weight %d", &weight))
5700 else if (unformat (i, "spray"))
5702 else if (unformat (i, "next %d", &sid))
5705 vec_add1 (segments, htonl (sid));
5709 clib_warning ("parse error '%U'", format_unformat_error, i);
5716 errmsg ("bsid not set");
5720 if (n_segments == 0)
5722 errmsg ("no sid in segment stack");
5726 /* Construct the API message */
5727 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
5729 mp->bsid = htonl (bsid);
5730 mp->weight = htonl (weight);
5731 mp->is_spray = type;
5732 mp->n_segments = n_segments;
5733 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
5734 vec_free (segments);
5739 /* Wait for a reply... */
5745 api_sr_mpls_policy_del (vat_main_t * vam)
5747 unformat_input_t *i = vam->input;
5748 vl_api_sr_mpls_policy_del_t *mp;
5752 /* Parse args required to build the message */
5753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5755 if (unformat (i, "bsid %d", &bsid))
5759 clib_warning ("parse error '%U'", format_unformat_error, i);
5766 errmsg ("bsid not set");
5770 /* Construct the API message */
5771 M (SR_MPLS_POLICY_DEL, mp);
5773 mp->bsid = htonl (bsid);
5778 /* Wait for a reply... */
5784 api_mpls_tunnel_add_del (vat_main_t * vam)
5786 unformat_input_t *i = vam->input;
5787 vl_api_mpls_tunnel_add_del_t *mp;
5789 vl_api_fib_path_t paths[8];
5790 u32 sw_if_index = ~0;
5796 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5798 if (unformat (i, "add"))
5802 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
5804 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
5806 else if (unformat (i, "l2-only"))
5810 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5813 if (8 == path_count)
5815 errmsg ("max 8 paths");
5821 clib_warning ("parse error '%U'", format_unformat_error, i);
5826 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5828 mp->mt_is_add = is_add;
5829 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
5830 mp->mt_tunnel.mt_l2_only = l2_only;
5831 mp->mt_tunnel.mt_is_multicast = 0;
5832 mp->mt_tunnel.mt_n_paths = path_count;
5834 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
5835 sizeof (paths[0]) * path_count);
5843 api_sw_interface_set_unnumbered (vat_main_t * vam)
5845 unformat_input_t *i = vam->input;
5846 vl_api_sw_interface_set_unnumbered_t *mp;
5848 u32 unnum_sw_index = ~0;
5850 u8 sw_if_index_set = 0;
5853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5855 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5856 sw_if_index_set = 1;
5857 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5858 sw_if_index_set = 1;
5859 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5861 else if (unformat (i, "del"))
5865 clib_warning ("parse error '%U'", format_unformat_error, i);
5870 if (sw_if_index_set == 0)
5872 errmsg ("missing interface name or sw_if_index");
5876 M (SW_INTERFACE_SET_UNNUMBERED, mp);
5878 mp->sw_if_index = ntohl (sw_if_index);
5879 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
5880 mp->is_add = is_add;
5889 api_create_vlan_subif (vat_main_t * vam)
5891 unformat_input_t *i = vam->input;
5892 vl_api_create_vlan_subif_t *mp;
5894 u8 sw_if_index_set = 0;
5899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5901 if (unformat (i, "sw_if_index %d", &sw_if_index))
5902 sw_if_index_set = 1;
5904 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5905 sw_if_index_set = 1;
5906 else if (unformat (i, "vlan %d", &vlan_id))
5910 clib_warning ("parse error '%U'", format_unformat_error, i);
5915 if (sw_if_index_set == 0)
5917 errmsg ("missing interface name or sw_if_index");
5921 if (vlan_id_set == 0)
5923 errmsg ("missing vlan_id");
5926 M (CREATE_VLAN_SUBIF, mp);
5928 mp->sw_if_index = ntohl (sw_if_index);
5929 mp->vlan_id = ntohl (vlan_id);
5936 #define foreach_create_subif_bit \
5943 _(outer_vlan_id_any) \
5944 _(inner_vlan_id_any)
5946 #define foreach_create_subif_flag \
5951 _(4, "exact_match") \
5952 _(5, "default_sub") \
5953 _(6, "outer_vlan_id_any") \
5954 _(7, "inner_vlan_id_any")
5957 api_create_subif (vat_main_t * vam)
5959 unformat_input_t *i = vam->input;
5960 vl_api_create_subif_t *mp;
5962 u8 sw_if_index_set = 0;
5965 u32 __attribute__ ((unused)) no_tags = 0;
5966 u32 __attribute__ ((unused)) one_tag = 0;
5967 u32 __attribute__ ((unused)) two_tags = 0;
5968 u32 __attribute__ ((unused)) dot1ad = 0;
5969 u32 __attribute__ ((unused)) exact_match = 0;
5970 u32 __attribute__ ((unused)) default_sub = 0;
5971 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
5972 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
5974 u16 outer_vlan_id = 0;
5975 u16 inner_vlan_id = 0;
5978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5980 if (unformat (i, "sw_if_index %d", &sw_if_index))
5981 sw_if_index_set = 1;
5983 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5984 sw_if_index_set = 1;
5985 else if (unformat (i, "sub_id %d", &sub_id))
5987 else if (unformat (i, "outer_vlan_id %d", &tmp))
5988 outer_vlan_id = tmp;
5989 else if (unformat (i, "inner_vlan_id %d", &tmp))
5990 inner_vlan_id = tmp;
5992 #define _(a) else if (unformat (i, #a)) a = 1 ;
5993 foreach_create_subif_bit
5997 clib_warning ("parse error '%U'", format_unformat_error, i);
6002 if (sw_if_index_set == 0)
6004 errmsg ("missing interface name or sw_if_index");
6008 if (sub_id_set == 0)
6010 errmsg ("missing sub_id");
6013 M (CREATE_SUBIF, mp);
6015 mp->sw_if_index = ntohl (sw_if_index);
6016 mp->sub_id = ntohl (sub_id);
6018 #define _(a,b) mp->sub_if_flags |= (1 << a);
6019 foreach_create_subif_flag;
6022 mp->outer_vlan_id = ntohs (outer_vlan_id);
6023 mp->inner_vlan_id = ntohs (inner_vlan_id);
6031 api_ip_table_replace_begin (vat_main_t * vam)
6033 unformat_input_t *i = vam->input;
6034 vl_api_ip_table_replace_begin_t *mp;
6039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6041 if (unformat (i, "table %d", &table_id))
6043 else if (unformat (i, "ipv6"))
6047 clib_warning ("parse error '%U'", format_unformat_error, i);
6052 M (IP_TABLE_REPLACE_BEGIN, mp);
6054 mp->table.table_id = ntohl (table_id);
6055 mp->table.is_ip6 = is_ipv6;
6063 api_ip_table_flush (vat_main_t * vam)
6065 unformat_input_t *i = vam->input;
6066 vl_api_ip_table_flush_t *mp;
6071 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6073 if (unformat (i, "table %d", &table_id))
6075 else if (unformat (i, "ipv6"))
6079 clib_warning ("parse error '%U'", format_unformat_error, i);
6084 M (IP_TABLE_FLUSH, mp);
6086 mp->table.table_id = ntohl (table_id);
6087 mp->table.is_ip6 = is_ipv6;
6095 api_ip_table_replace_end (vat_main_t * vam)
6097 unformat_input_t *i = vam->input;
6098 vl_api_ip_table_replace_end_t *mp;
6103 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6105 if (unformat (i, "table %d", &table_id))
6107 else if (unformat (i, "ipv6"))
6111 clib_warning ("parse error '%U'", format_unformat_error, i);
6116 M (IP_TABLE_REPLACE_END, mp);
6118 mp->table.table_id = ntohl (table_id);
6119 mp->table.is_ip6 = is_ipv6;
6127 api_set_ip_flow_hash (vat_main_t * vam)
6129 unformat_input_t *i = vam->input;
6130 vl_api_set_ip_flow_hash_t *mp;
6142 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6144 if (unformat (i, "vrf %d", &vrf_id))
6146 else if (unformat (i, "ipv6"))
6148 else if (unformat (i, "src"))
6150 else if (unformat (i, "dst"))
6152 else if (unformat (i, "sport"))
6154 else if (unformat (i, "dport"))
6156 else if (unformat (i, "proto"))
6158 else if (unformat (i, "reverse"))
6163 clib_warning ("parse error '%U'", format_unformat_error, i);
6168 if (vrf_id_set == 0)
6170 errmsg ("missing vrf id");
6174 M (SET_IP_FLOW_HASH, mp);
6180 mp->reverse = reverse;
6181 mp->vrf_id = ntohl (vrf_id);
6182 mp->is_ipv6 = is_ipv6;
6190 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6192 unformat_input_t *i = vam->input;
6193 vl_api_sw_interface_ip6_enable_disable_t *mp;
6195 u8 sw_if_index_set = 0;
6199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6201 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6202 sw_if_index_set = 1;
6203 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6204 sw_if_index_set = 1;
6205 else if (unformat (i, "enable"))
6207 else if (unformat (i, "disable"))
6211 clib_warning ("parse error '%U'", format_unformat_error, i);
6216 if (sw_if_index_set == 0)
6218 errmsg ("missing interface name or sw_if_index");
6222 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6224 mp->sw_if_index = ntohl (sw_if_index);
6225 mp->enable = enable;
6234 api_l2_patch_add_del (vat_main_t * vam)
6236 unformat_input_t *i = vam->input;
6237 vl_api_l2_patch_add_del_t *mp;
6239 u8 rx_sw_if_index_set = 0;
6241 u8 tx_sw_if_index_set = 0;
6245 /* Parse args required to build the message */
6246 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6248 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6249 rx_sw_if_index_set = 1;
6250 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6251 tx_sw_if_index_set = 1;
6252 else if (unformat (i, "rx"))
6254 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6256 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6258 rx_sw_if_index_set = 1;
6263 else if (unformat (i, "tx"))
6265 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6267 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6269 tx_sw_if_index_set = 1;
6274 else if (unformat (i, "del"))
6280 if (rx_sw_if_index_set == 0)
6282 errmsg ("missing rx interface name or rx_sw_if_index");
6286 if (tx_sw_if_index_set == 0)
6288 errmsg ("missing tx interface name or tx_sw_if_index");
6292 M (L2_PATCH_ADD_DEL, mp);
6294 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6295 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6296 mp->is_add = is_add;
6304 u8 localsid_addr[16];
6313 api_sr_localsid_add_del (vat_main_t * vam)
6315 unformat_input_t *i = vam->input;
6316 vl_api_sr_localsid_add_del_t *mp;
6319 ip6_address_t localsid;
6323 u32 fib_table = ~(u32) 0;
6324 ip46_address_t nh_addr;
6325 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6327 bool nexthop_set = 0;
6331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6333 if (unformat (i, "del"))
6335 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6336 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6338 else if (unformat (i, "behavior %u", &behavior));
6339 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6340 else if (unformat (i, "fib-table %u", &fib_table));
6341 else if (unformat (i, "end.psp %u", &behavior));
6346 M (SR_LOCALSID_ADD_DEL, mp);
6348 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6352 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6354 mp->behavior = behavior;
6355 mp->sw_if_index = ntohl (sw_if_index);
6356 mp->fib_table = ntohl (fib_table);
6357 mp->end_psp = end_psp;
6358 mp->is_del = is_del;
6366 api_ioam_enable (vat_main_t * vam)
6368 unformat_input_t *input = vam->input;
6369 vl_api_ioam_enable_t *mp;
6371 int has_trace_option = 0;
6372 int has_pot_option = 0;
6373 int has_seqno_option = 0;
6374 int has_analyse_option = 0;
6377 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6379 if (unformat (input, "trace"))
6380 has_trace_option = 1;
6381 else if (unformat (input, "pot"))
6383 else if (unformat (input, "seqno"))
6384 has_seqno_option = 1;
6385 else if (unformat (input, "analyse"))
6386 has_analyse_option = 1;
6390 M (IOAM_ENABLE, mp);
6391 mp->id = htons (id);
6392 mp->seqno = has_seqno_option;
6393 mp->analyse = has_analyse_option;
6394 mp->pot_enable = has_pot_option;
6395 mp->trace_enable = has_trace_option;
6404 api_ioam_disable (vat_main_t * vam)
6406 vl_api_ioam_disable_t *mp;
6409 M (IOAM_DISABLE, mp);
6415 #define foreach_tcp_proto_field \
6419 #define foreach_udp_proto_field \
6423 #define foreach_ip4_proto_field \
6435 u16 src_port, dst_port;
6438 #if VPP_API_TEST_BUILTIN == 0
6440 unformat_tcp_mask (unformat_input_t * input, va_list * args)
6442 u8 **maskp = va_arg (*args, u8 **);
6444 u8 found_something = 0;
6447 #define _(a) u8 a=0;
6448 foreach_tcp_proto_field;
6451 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6454 #define _(a) else if (unformat (input, #a)) a=1;
6455 foreach_tcp_proto_field
6461 #define _(a) found_something += a;
6462 foreach_tcp_proto_field;
6465 if (found_something == 0)
6468 vec_validate (mask, sizeof (*tcp) - 1);
6470 tcp = (tcp_header_t *) mask;
6472 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
6473 foreach_tcp_proto_field;
6481 unformat_udp_mask (unformat_input_t * input, va_list * args)
6483 u8 **maskp = va_arg (*args, u8 **);
6485 u8 found_something = 0;
6488 #define _(a) u8 a=0;
6489 foreach_udp_proto_field;
6492 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6495 #define _(a) else if (unformat (input, #a)) a=1;
6496 foreach_udp_proto_field
6502 #define _(a) found_something += a;
6503 foreach_udp_proto_field;
6506 if (found_something == 0)
6509 vec_validate (mask, sizeof (*udp) - 1);
6511 udp = (udp_header_t *) mask;
6513 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
6514 foreach_udp_proto_field;
6522 unformat_l4_mask (unformat_input_t * input, va_list * args)
6524 u8 **maskp = va_arg (*args, u8 **);
6525 u16 src_port = 0, dst_port = 0;
6526 tcpudp_header_t *tcpudp;
6528 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6530 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
6532 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
6534 else if (unformat (input, "src_port"))
6536 else if (unformat (input, "dst_port"))
6542 if (!src_port && !dst_port)
6546 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
6548 tcpudp = (tcpudp_header_t *) mask;
6549 tcpudp->src_port = src_port;
6550 tcpudp->dst_port = dst_port;
6558 unformat_ip4_mask (unformat_input_t * input, va_list * args)
6560 u8 **maskp = va_arg (*args, u8 **);
6562 u8 found_something = 0;
6565 #define _(a) u8 a=0;
6566 foreach_ip4_proto_field;
6572 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6574 if (unformat (input, "version"))
6576 else if (unformat (input, "hdr_length"))
6578 else if (unformat (input, "src"))
6580 else if (unformat (input, "dst"))
6582 else if (unformat (input, "proto"))
6585 #define _(a) else if (unformat (input, #a)) a=1;
6586 foreach_ip4_proto_field
6592 #define _(a) found_something += a;
6593 foreach_ip4_proto_field;
6596 if (found_something == 0)
6599 vec_validate (mask, sizeof (*ip) - 1);
6601 ip = (ip4_header_t *) mask;
6603 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
6604 foreach_ip4_proto_field;
6607 ip->ip_version_and_header_length = 0;
6610 ip->ip_version_and_header_length |= 0xF0;
6613 ip->ip_version_and_header_length |= 0x0F;
6619 #define foreach_ip6_proto_field \
6627 unformat_ip6_mask (unformat_input_t * input, va_list * args)
6629 u8 **maskp = va_arg (*args, u8 **);
6631 u8 found_something = 0;
6633 u32 ip_version_traffic_class_and_flow_label;
6635 #define _(a) u8 a=0;
6636 foreach_ip6_proto_field;
6639 u8 traffic_class = 0;
6642 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6644 if (unformat (input, "version"))
6646 else if (unformat (input, "traffic-class"))
6648 else if (unformat (input, "flow-label"))
6650 else if (unformat (input, "src"))
6652 else if (unformat (input, "dst"))
6654 else if (unformat (input, "proto"))
6657 #define _(a) else if (unformat (input, #a)) a=1;
6658 foreach_ip6_proto_field
6664 #define _(a) found_something += a;
6665 foreach_ip6_proto_field;
6668 if (found_something == 0)
6671 vec_validate (mask, sizeof (*ip) - 1);
6673 ip = (ip6_header_t *) mask;
6675 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
6676 foreach_ip6_proto_field;
6679 ip_version_traffic_class_and_flow_label = 0;
6682 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6685 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6688 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6690 ip->ip_version_traffic_class_and_flow_label =
6691 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6698 unformat_l3_mask (unformat_input_t * input, va_list * args)
6700 u8 **maskp = va_arg (*args, u8 **);
6702 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6704 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6706 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6715 unformat_l2_mask (unformat_input_t * input, va_list * args)
6717 u8 **maskp = va_arg (*args, u8 **);
6732 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6734 if (unformat (input, "src"))
6736 else if (unformat (input, "dst"))
6738 else if (unformat (input, "proto"))
6740 else if (unformat (input, "tag1"))
6742 else if (unformat (input, "tag2"))
6744 else if (unformat (input, "ignore-tag1"))
6746 else if (unformat (input, "ignore-tag2"))
6748 else if (unformat (input, "cos1"))
6750 else if (unformat (input, "cos2"))
6752 else if (unformat (input, "dot1q"))
6754 else if (unformat (input, "dot1ad"))
6759 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6760 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6763 if (tag1 || ignore_tag1 || cos1 || dot1q)
6765 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6768 vec_validate (mask, len - 1);
6771 clib_memset (mask, 0xff, 6);
6774 clib_memset (mask + 6, 0xff, 6);
6778 /* inner vlan tag */
6787 mask[21] = mask[20] = 0xff;
6808 mask[16] = mask[17] = 0xff;
6818 mask[12] = mask[13] = 0xff;
6825 unformat_classify_mask (unformat_input_t * input, va_list * args)
6827 u8 **maskp = va_arg (*args, u8 **);
6828 u32 *skipp = va_arg (*args, u32 *);
6829 u32 *matchp = va_arg (*args, u32 *);
6837 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6839 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6841 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6843 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6845 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
6859 if (mask || l2 || l3 || l4)
6863 /* "With a free Ethernet header in every package" */
6865 vec_validate (l2, 13);
6869 vec_append (mask, l3);
6874 vec_append (mask, l4);
6879 /* Scan forward looking for the first significant mask octet */
6880 for (i = 0; i < vec_len (mask); i++)
6884 /* compute (skip, match) params */
6885 *skipp = i / sizeof (u32x4);
6886 vec_delete (mask, *skipp * sizeof (u32x4), 0);
6888 /* Pad mask to an even multiple of the vector size */
6889 while (vec_len (mask) % sizeof (u32x4))
6892 match = vec_len (mask) / sizeof (u32x4);
6894 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
6896 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
6897 if (*tmp || *(tmp + 1))
6902 clib_warning ("BUG: match 0");
6904 _vec_len (mask) = match * sizeof (u32x4);
6914 #endif /* VPP_API_TEST_BUILTIN */
6916 #define foreach_l2_next \
6918 _(ethernet, ETHERNET_INPUT) \
6923 unformat_l2_next_index (unformat_input_t * input, va_list * args)
6925 u32 *miss_next_indexp = va_arg (*args, u32 *);
6930 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
6934 if (unformat (input, "%d", &tmp))
6943 *miss_next_indexp = next_index;
6947 #define foreach_ip_next \
6953 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
6955 u32 *miss_next_indexp = va_arg (*args, u32 *);
6960 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6964 if (unformat (input, "%d", &tmp))
6973 *miss_next_indexp = next_index;
6977 #define foreach_acl_next \
6981 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
6983 u32 *miss_next_indexp = va_arg (*args, u32 *);
6988 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6992 if (unformat (input, "permit"))
6997 else if (unformat (input, "%d", &tmp))
7006 *miss_next_indexp = next_index;
7011 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7013 u32 *r = va_arg (*args, u32 *);
7015 if (unformat (input, "conform-color"))
7016 *r = POLICE_CONFORM;
7017 else if (unformat (input, "exceed-color"))
7025 #if VPP_API_TEST_BUILTIN == 0
7027 unformat_l4_match (unformat_input_t * input, va_list * args)
7029 u8 **matchp = va_arg (*args, u8 **);
7031 u8 *proto_header = 0;
7037 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7039 if (unformat (input, "src_port %d", &src_port))
7041 else if (unformat (input, "dst_port %d", &dst_port))
7047 h.src_port = clib_host_to_net_u16 (src_port);
7048 h.dst_port = clib_host_to_net_u16 (dst_port);
7049 vec_validate (proto_header, sizeof (h) - 1);
7050 memcpy (proto_header, &h, sizeof (h));
7052 *matchp = proto_header;
7058 unformat_ip4_match (unformat_input_t * input, va_list * args)
7060 u8 **matchp = va_arg (*args, u8 **);
7067 int src = 0, dst = 0;
7068 ip4_address_t src_val, dst_val;
7075 int fragment_id = 0;
7076 u32 fragment_id_val;
7082 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7084 if (unformat (input, "version %d", &version_val))
7086 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7088 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7090 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7092 else if (unformat (input, "proto %d", &proto_val))
7094 else if (unformat (input, "tos %d", &tos_val))
7096 else if (unformat (input, "length %d", &length_val))
7098 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7100 else if (unformat (input, "ttl %d", &ttl_val))
7102 else if (unformat (input, "checksum %d", &checksum_val))
7108 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7109 + ttl + checksum == 0)
7113 * Aligned because we use the real comparison functions
7115 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7117 ip = (ip4_header_t *) match;
7119 /* These are realistically matched in practice */
7121 ip->src_address.as_u32 = src_val.as_u32;
7124 ip->dst_address.as_u32 = dst_val.as_u32;
7127 ip->protocol = proto_val;
7130 /* These are not, but they're included for completeness */
7132 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7135 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7141 ip->length = clib_host_to_net_u16 (length_val);
7147 ip->checksum = clib_host_to_net_u16 (checksum_val);
7154 unformat_ip6_match (unformat_input_t * input, va_list * args)
7156 u8 **matchp = va_arg (*args, u8 **);
7161 u8 traffic_class = 0;
7162 u32 traffic_class_val = 0;
7165 int src = 0, dst = 0;
7166 ip6_address_t src_val, dst_val;
7169 int payload_length = 0;
7170 u32 payload_length_val;
7173 u32 ip_version_traffic_class_and_flow_label;
7175 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7177 if (unformat (input, "version %d", &version_val))
7179 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7181 else if (unformat (input, "flow_label %d", &flow_label_val))
7183 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7185 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7187 else if (unformat (input, "proto %d", &proto_val))
7189 else if (unformat (input, "payload_length %d", &payload_length_val))
7191 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7197 if (version + traffic_class + flow_label + src + dst + proto +
7198 payload_length + hop_limit == 0)
7202 * Aligned because we use the real comparison functions
7204 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7206 ip = (ip6_header_t *) match;
7209 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7212 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7215 ip->protocol = proto_val;
7217 ip_version_traffic_class_and_flow_label = 0;
7220 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7223 ip_version_traffic_class_and_flow_label |=
7224 (traffic_class_val & 0xFF) << 20;
7227 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7229 ip->ip_version_traffic_class_and_flow_label =
7230 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7233 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7236 ip->hop_limit = hop_limit_val;
7243 unformat_l3_match (unformat_input_t * input, va_list * args)
7245 u8 **matchp = va_arg (*args, u8 **);
7247 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7249 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7251 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7260 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7262 u8 *tagp = va_arg (*args, u8 *);
7265 if (unformat (input, "%d", &tag))
7267 tagp[0] = (tag >> 8) & 0x0F;
7268 tagp[1] = tag & 0xFF;
7276 unformat_l2_match (unformat_input_t * input, va_list * args)
7278 u8 **matchp = va_arg (*args, u8 **);
7298 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7300 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7303 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7305 else if (unformat (input, "proto %U",
7306 unformat_ethernet_type_host_byte_order, &proto_val))
7308 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7310 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7312 else if (unformat (input, "ignore-tag1"))
7314 else if (unformat (input, "ignore-tag2"))
7316 else if (unformat (input, "cos1 %d", &cos1_val))
7318 else if (unformat (input, "cos2 %d", &cos2_val))
7323 if ((src + dst + proto + tag1 + tag2 +
7324 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7327 if (tag1 || ignore_tag1 || cos1)
7329 if (tag2 || ignore_tag2 || cos2)
7332 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7335 clib_memcpy (match, dst_val, 6);
7338 clib_memcpy (match + 6, src_val, 6);
7342 /* inner vlan tag */
7343 match[19] = tag2_val[1];
7344 match[18] = tag2_val[0];
7346 match[18] |= (cos2_val & 0x7) << 5;
7349 match[21] = proto_val & 0xff;
7350 match[20] = proto_val >> 8;
7354 match[15] = tag1_val[1];
7355 match[14] = tag1_val[0];
7358 match[14] |= (cos1_val & 0x7) << 5;
7364 match[15] = tag1_val[1];
7365 match[14] = tag1_val[0];
7368 match[17] = proto_val & 0xff;
7369 match[16] = proto_val >> 8;
7372 match[14] |= (cos1_val & 0x7) << 5;
7378 match[18] |= (cos2_val & 0x7) << 5;
7380 match[14] |= (cos1_val & 0x7) << 5;
7383 match[13] = proto_val & 0xff;
7384 match[12] = proto_val >> 8;
7392 unformat_qos_source (unformat_input_t * input, va_list * args)
7394 int *qs = va_arg (*args, int *);
7396 if (unformat (input, "ip"))
7397 *qs = QOS_SOURCE_IP;
7398 else if (unformat (input, "mpls"))
7399 *qs = QOS_SOURCE_MPLS;
7400 else if (unformat (input, "ext"))
7401 *qs = QOS_SOURCE_EXT;
7402 else if (unformat (input, "vlan"))
7403 *qs = QOS_SOURCE_VLAN;
7412 api_unformat_classify_match (unformat_input_t * input, va_list * args)
7414 u8 **matchp = va_arg (*args, u8 **);
7415 u32 skip_n_vectors = va_arg (*args, u32);
7416 u32 match_n_vectors = va_arg (*args, u32);
7423 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7425 if (unformat (input, "hex %U", unformat_hex_string, &match))
7427 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7429 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7431 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
7445 if (match || l2 || l3 || l4)
7449 /* "Win a free Ethernet header in every packet" */
7451 vec_validate_aligned (l2, 13, sizeof (u32x4));
7455 vec_append_aligned (match, l3, sizeof (u32x4));
7460 vec_append_aligned (match, l4, sizeof (u32x4));
7465 /* Make sure the vector is big enough even if key is all 0's */
7466 vec_validate_aligned
7467 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
7470 /* Set size, include skipped vectors */
7471 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
7482 api_get_node_index (vat_main_t * vam)
7484 unformat_input_t *i = vam->input;
7485 vl_api_get_node_index_t *mp;
7489 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7491 if (unformat (i, "node %s", &name))
7498 errmsg ("node name required");
7501 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7503 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7507 M (GET_NODE_INDEX, mp);
7508 clib_memcpy (mp->node_name, name, vec_len (name));
7517 api_get_next_index (vat_main_t * vam)
7519 unformat_input_t *i = vam->input;
7520 vl_api_get_next_index_t *mp;
7521 u8 *node_name = 0, *next_node_name = 0;
7524 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7526 if (unformat (i, "node-name %s", &node_name))
7528 else if (unformat (i, "next-node-name %s", &next_node_name))
7534 errmsg ("node name required");
7537 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
7539 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7543 if (next_node_name == 0)
7545 errmsg ("next node name required");
7548 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
7550 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
7554 M (GET_NEXT_INDEX, mp);
7555 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
7556 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
7557 vec_free (node_name);
7558 vec_free (next_node_name);
7566 api_add_node_next (vat_main_t * vam)
7568 unformat_input_t *i = vam->input;
7569 vl_api_add_node_next_t *mp;
7574 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7576 if (unformat (i, "node %s", &name))
7578 else if (unformat (i, "next %s", &next))
7585 errmsg ("node name required");
7588 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7590 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7595 errmsg ("next node required");
7598 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
7600 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
7604 M (ADD_NODE_NEXT, mp);
7605 clib_memcpy (mp->node_name, name, vec_len (name));
7606 clib_memcpy (mp->next_name, next, vec_len (next));
7615 static void vl_api_sw_interface_tap_v2_details_t_handler
7616 (vl_api_sw_interface_tap_v2_details_t * mp)
7618 vat_main_t *vam = &vat_main;
7621 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
7622 mp->host_ip4_prefix.len);
7624 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
7625 mp->host_ip6_prefix.len);
7628 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
7629 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
7630 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
7631 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
7632 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
7638 static void vl_api_sw_interface_tap_v2_details_t_handler_json
7639 (vl_api_sw_interface_tap_v2_details_t * mp)
7641 vat_main_t *vam = &vat_main;
7642 vat_json_node_t *node = NULL;
7644 if (VAT_JSON_ARRAY != vam->json_tree.type)
7646 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7647 vat_json_init_array (&vam->json_tree);
7649 node = vat_json_array_add (&vam->json_tree);
7651 vat_json_init_object (node);
7652 vat_json_object_add_uint (node, "id", ntohl (mp->id));
7653 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7654 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
7655 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
7656 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
7657 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
7658 vat_json_object_add_string_copy (node, "host_mac_addr",
7659 format (0, "%U", format_ethernet_address,
7660 &mp->host_mac_addr));
7661 vat_json_object_add_string_copy (node, "host_namespace",
7662 mp->host_namespace);
7663 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
7664 vat_json_object_add_string_copy (node, "host_ip4_addr",
7665 format (0, "%U/%d", format_ip4_address,
7666 mp->host_ip4_prefix.address,
7667 mp->host_ip4_prefix.len));
7668 vat_json_object_add_string_copy (node, "host_ip6_prefix",
7669 format (0, "%U/%d", format_ip6_address,
7670 mp->host_ip6_prefix.address,
7671 mp->host_ip6_prefix.len));
7676 api_sw_interface_tap_v2_dump (vat_main_t * vam)
7678 vl_api_sw_interface_tap_v2_dump_t *mp;
7679 vl_api_control_ping_t *mp_ping;
7683 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
7684 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
7685 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
7688 /* Get list of tap interfaces */
7689 M (SW_INTERFACE_TAP_V2_DUMP, mp);
7692 /* Use a control ping for synchronization */
7693 MPING (CONTROL_PING, mp_ping);
7700 static void vl_api_sw_interface_virtio_pci_details_t_handler
7701 (vl_api_sw_interface_virtio_pci_details_t * mp)
7703 vat_main_t *vam = &vat_main;
7718 addr.domain = ntohs (mp->pci_addr.domain);
7719 addr.bus = mp->pci_addr.bus;
7720 addr.slot = mp->pci_addr.slot;
7721 addr.function = mp->pci_addr.function;
7723 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
7724 addr.slot, addr.function);
7727 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
7728 pci_addr, ntohl (mp->sw_if_index),
7729 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
7730 format_ethernet_address, mp->mac_addr,
7731 clib_net_to_host_u64 (mp->features));
7732 vec_free (pci_addr);
7735 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
7736 (vl_api_sw_interface_virtio_pci_details_t * mp)
7738 vat_main_t *vam = &vat_main;
7739 vat_json_node_t *node = NULL;
7740 vlib_pci_addr_t pci_addr;
7742 if (VAT_JSON_ARRAY != vam->json_tree.type)
7744 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7745 vat_json_init_array (&vam->json_tree);
7747 node = vat_json_array_add (&vam->json_tree);
7749 pci_addr.domain = ntohs (mp->pci_addr.domain);
7750 pci_addr.bus = mp->pci_addr.bus;
7751 pci_addr.slot = mp->pci_addr.slot;
7752 pci_addr.function = mp->pci_addr.function;
7754 vat_json_init_object (node);
7755 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
7756 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7757 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
7758 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
7759 vat_json_object_add_uint (node, "features",
7760 clib_net_to_host_u64 (mp->features));
7761 vat_json_object_add_string_copy (node, "mac_addr",
7762 format (0, "%U", format_ethernet_address,
7767 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
7769 vl_api_sw_interface_virtio_pci_dump_t *mp;
7770 vl_api_control_ping_t *mp_ping;
7774 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
7775 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
7776 "mac_addr", "features");
7778 /* Get list of tap interfaces */
7779 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
7782 /* Use a control ping for synchronization */
7783 MPING (CONTROL_PING, mp_ping);
7791 api_l2_fib_clear_table (vat_main_t * vam)
7793 // unformat_input_t * i = vam->input;
7794 vl_api_l2_fib_clear_table_t *mp;
7797 M (L2_FIB_CLEAR_TABLE, mp);
7805 api_l2_interface_efp_filter (vat_main_t * vam)
7807 unformat_input_t *i = vam->input;
7808 vl_api_l2_interface_efp_filter_t *mp;
7811 u8 sw_if_index_set = 0;
7814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7816 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7817 sw_if_index_set = 1;
7818 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7819 sw_if_index_set = 1;
7820 else if (unformat (i, "enable"))
7822 else if (unformat (i, "disable"))
7826 clib_warning ("parse error '%U'", format_unformat_error, i);
7831 if (sw_if_index_set == 0)
7833 errmsg ("missing sw_if_index");
7837 M (L2_INTERFACE_EFP_FILTER, mp);
7839 mp->sw_if_index = ntohl (sw_if_index);
7840 mp->enable_disable = enable;
7847 #define foreach_vtr_op \
7848 _("disable", L2_VTR_DISABLED) \
7849 _("push-1", L2_VTR_PUSH_1) \
7850 _("push-2", L2_VTR_PUSH_2) \
7851 _("pop-1", L2_VTR_POP_1) \
7852 _("pop-2", L2_VTR_POP_2) \
7853 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7854 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7855 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7856 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7859 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7861 unformat_input_t *i = vam->input;
7862 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7864 u8 sw_if_index_set = 0;
7872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7874 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7875 sw_if_index_set = 1;
7876 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7877 sw_if_index_set = 1;
7878 else if (unformat (i, "vtr_op %d", &vtr_op))
7880 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7883 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7885 else if (unformat (i, "tag1 %d", &tag1))
7887 else if (unformat (i, "tag2 %d", &tag2))
7891 clib_warning ("parse error '%U'", format_unformat_error, i);
7896 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
7898 errmsg ("missing vtr operation or sw_if_index");
7902 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
7903 mp->sw_if_index = ntohl (sw_if_index);
7904 mp->vtr_op = ntohl (vtr_op);
7905 mp->push_dot1q = ntohl (push_dot1q);
7906 mp->tag1 = ntohl (tag1);
7907 mp->tag2 = ntohl (tag2);
7915 api_create_vhost_user_if (vat_main_t * vam)
7917 unformat_input_t *i = vam->input;
7918 vl_api_create_vhost_user_if_t *mp;
7921 u8 file_name_set = 0;
7922 u32 custom_dev_instance = ~0;
7924 u8 use_custom_mac = 0;
7925 u8 disable_mrg_rxbuf = 0;
7926 u8 disable_indirect_desc = 0;
7929 u8 enable_packed = 0;
7932 /* Shut up coverity */
7933 clib_memset (hwaddr, 0, sizeof (hwaddr));
7935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7937 if (unformat (i, "socket %s", &file_name))
7941 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
7943 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7945 else if (unformat (i, "server"))
7947 else if (unformat (i, "disable_mrg_rxbuf"))
7948 disable_mrg_rxbuf = 1;
7949 else if (unformat (i, "disable_indirect_desc"))
7950 disable_indirect_desc = 1;
7951 else if (unformat (i, "gso"))
7953 else if (unformat (i, "packed"))
7955 else if (unformat (i, "tag %s", &tag))
7961 if (file_name_set == 0)
7963 errmsg ("missing socket file name");
7967 if (vec_len (file_name) > 255)
7969 errmsg ("socket file name too long");
7972 vec_add1 (file_name, 0);
7974 M (CREATE_VHOST_USER_IF, mp);
7976 mp->is_server = is_server;
7977 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
7978 mp->disable_indirect_desc = disable_indirect_desc;
7979 mp->enable_gso = enable_gso;
7980 mp->enable_packed = enable_packed;
7981 mp->custom_dev_instance = ntohl (custom_dev_instance);
7982 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
7983 vec_free (file_name);
7984 if (custom_dev_instance != ~0)
7987 mp->use_custom_mac = use_custom_mac;
7988 clib_memcpy (mp->mac_address, hwaddr, 6);
7990 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
7999 api_modify_vhost_user_if (vat_main_t * vam)
8001 unformat_input_t *i = vam->input;
8002 vl_api_modify_vhost_user_if_t *mp;
8005 u8 file_name_set = 0;
8006 u32 custom_dev_instance = ~0;
8007 u8 sw_if_index_set = 0;
8008 u32 sw_if_index = (u32) ~ 0;
8010 u8 enable_packed = 0;
8013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8015 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8016 sw_if_index_set = 1;
8017 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8018 sw_if_index_set = 1;
8019 else if (unformat (i, "socket %s", &file_name))
8023 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8025 else if (unformat (i, "server"))
8027 else if (unformat (i, "gso"))
8029 else if (unformat (i, "packed"))
8035 if (sw_if_index_set == 0)
8037 errmsg ("missing sw_if_index or interface name");
8041 if (file_name_set == 0)
8043 errmsg ("missing socket file name");
8047 if (vec_len (file_name) > 255)
8049 errmsg ("socket file name too long");
8052 vec_add1 (file_name, 0);
8054 M (MODIFY_VHOST_USER_IF, mp);
8056 mp->sw_if_index = ntohl (sw_if_index);
8057 mp->is_server = is_server;
8058 mp->enable_gso = enable_gso;
8059 mp->enable_packed = enable_packed;
8060 mp->custom_dev_instance = ntohl (custom_dev_instance);
8061 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8062 vec_free (file_name);
8063 if (custom_dev_instance != ~0)
8072 api_create_vhost_user_if_v2 (vat_main_t * vam)
8074 unformat_input_t *i = vam->input;
8075 vl_api_create_vhost_user_if_v2_t *mp;
8078 u8 file_name_set = 0;
8079 u32 custom_dev_instance = ~0;
8081 u8 use_custom_mac = 0;
8082 u8 disable_mrg_rxbuf = 0;
8083 u8 disable_indirect_desc = 0;
8086 u8 enable_packed = 0;
8087 u8 enable_event_idx = 0;
8090 /* Shut up coverity */
8091 clib_memset (hwaddr, 0, sizeof (hwaddr));
8093 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8095 if (unformat (i, "socket %s", &file_name))
8099 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8101 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8103 else if (unformat (i, "server"))
8105 else if (unformat (i, "disable_mrg_rxbuf"))
8106 disable_mrg_rxbuf = 1;
8107 else if (unformat (i, "disable_indirect_desc"))
8108 disable_indirect_desc = 1;
8109 else if (unformat (i, "gso"))
8111 else if (unformat (i, "packed"))
8113 else if (unformat (i, "event-idx"))
8114 enable_event_idx = 1;
8115 else if (unformat (i, "tag %s", &tag))
8121 if (file_name_set == 0)
8123 errmsg ("missing socket file name");
8127 if (vec_len (file_name) > 255)
8129 errmsg ("socket file name too long");
8132 vec_add1 (file_name, 0);
8134 M (CREATE_VHOST_USER_IF_V2, mp);
8136 mp->is_server = is_server;
8137 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8138 mp->disable_indirect_desc = disable_indirect_desc;
8139 mp->enable_gso = enable_gso;
8140 mp->enable_packed = enable_packed;
8141 mp->enable_event_idx = enable_event_idx;
8142 mp->custom_dev_instance = ntohl (custom_dev_instance);
8143 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8144 vec_free (file_name);
8145 if (custom_dev_instance != ~0)
8148 mp->use_custom_mac = use_custom_mac;
8149 clib_memcpy (mp->mac_address, hwaddr, 6);
8151 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8160 api_modify_vhost_user_if_v2 (vat_main_t * vam)
8162 unformat_input_t *i = vam->input;
8163 vl_api_modify_vhost_user_if_v2_t *mp;
8166 u8 file_name_set = 0;
8167 u32 custom_dev_instance = ~0;
8168 u8 sw_if_index_set = 0;
8169 u32 sw_if_index = (u32) ~ 0;
8171 u8 enable_packed = 0;
8172 u8 enable_event_idx = 0;
8175 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8177 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8178 sw_if_index_set = 1;
8179 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8180 sw_if_index_set = 1;
8181 else if (unformat (i, "socket %s", &file_name))
8185 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8187 else if (unformat (i, "server"))
8189 else if (unformat (i, "gso"))
8191 else if (unformat (i, "packed"))
8193 else if (unformat (i, "event-idx"))
8194 enable_event_idx = 1;
8199 if (sw_if_index_set == 0)
8201 errmsg ("missing sw_if_index or interface name");
8205 if (file_name_set == 0)
8207 errmsg ("missing socket file name");
8211 if (vec_len (file_name) > 255)
8213 errmsg ("socket file name too long");
8216 vec_add1 (file_name, 0);
8218 M (MODIFY_VHOST_USER_IF_V2, mp);
8220 mp->sw_if_index = ntohl (sw_if_index);
8221 mp->is_server = is_server;
8222 mp->enable_gso = enable_gso;
8223 mp->enable_packed = enable_packed;
8224 mp->enable_event_idx = enable_event_idx;
8225 mp->custom_dev_instance = ntohl (custom_dev_instance);
8226 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8227 vec_free (file_name);
8228 if (custom_dev_instance != ~0)
8237 api_delete_vhost_user_if (vat_main_t * vam)
8239 unformat_input_t *i = vam->input;
8240 vl_api_delete_vhost_user_if_t *mp;
8241 u32 sw_if_index = ~0;
8242 u8 sw_if_index_set = 0;
8245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8247 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8248 sw_if_index_set = 1;
8249 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8250 sw_if_index_set = 1;
8255 if (sw_if_index_set == 0)
8257 errmsg ("missing sw_if_index or interface name");
8262 M (DELETE_VHOST_USER_IF, mp);
8264 mp->sw_if_index = ntohl (sw_if_index);
8271 static void vl_api_sw_interface_vhost_user_details_t_handler
8272 (vl_api_sw_interface_vhost_user_details_t * mp)
8274 vat_main_t *vam = &vat_main;
8278 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
8279 clib_net_to_host_u32
8280 (mp->features_last_32) <<
8283 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
8284 (char *) mp->interface_name, ntohl (mp->sw_if_index),
8285 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
8286 ntohl (mp->num_regions), (char *) mp->sock_filename);
8287 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
8290 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8291 (vl_api_sw_interface_vhost_user_details_t * mp)
8293 vat_main_t *vam = &vat_main;
8294 vat_json_node_t *node = NULL;
8296 if (VAT_JSON_ARRAY != vam->json_tree.type)
8298 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8299 vat_json_init_array (&vam->json_tree);
8301 node = vat_json_array_add (&vam->json_tree);
8303 vat_json_init_object (node);
8304 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8305 vat_json_object_add_string_copy (node, "interface_name",
8306 mp->interface_name);
8307 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
8308 ntohl (mp->virtio_net_hdr_sz));
8309 vat_json_object_add_uint (node, "features_first_32",
8310 clib_net_to_host_u32 (mp->features_first_32));
8311 vat_json_object_add_uint (node, "features_last_32",
8312 clib_net_to_host_u32 (mp->features_last_32));
8313 vat_json_object_add_uint (node, "is_server", mp->is_server);
8314 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
8315 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
8316 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
8320 api_sw_interface_vhost_user_dump (vat_main_t * vam)
8322 unformat_input_t *i = vam->input;
8323 vl_api_sw_interface_vhost_user_dump_t *mp;
8324 vl_api_control_ping_t *mp_ping;
8326 u32 sw_if_index = ~0;
8328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8330 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8332 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8338 print (vam->ofp, "Interface name idx hdr_sz features "
8339 "server regions filename");
8341 /* Get list of vhost-user interfaces */
8342 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
8343 mp->sw_if_index = ntohl (sw_if_index);
8346 /* Use a control ping for synchronization */
8347 MPING (CONTROL_PING, mp_ping);
8355 api_show_version (vat_main_t * vam)
8357 vl_api_show_version_t *mp;
8360 M (SHOW_VERSION, mp);
8367 static void vl_api_l2_fib_table_details_t_handler
8368 (vl_api_l2_fib_table_details_t * mp)
8370 vat_main_t *vam = &vat_main;
8372 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8374 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
8375 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
8379 static void vl_api_l2_fib_table_details_t_handler_json
8380 (vl_api_l2_fib_table_details_t * mp)
8382 vat_main_t *vam = &vat_main;
8383 vat_json_node_t *node = NULL;
8385 if (VAT_JSON_ARRAY != vam->json_tree.type)
8387 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8388 vat_json_init_array (&vam->json_tree);
8390 node = vat_json_array_add (&vam->json_tree);
8392 vat_json_init_object (node);
8393 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
8394 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
8395 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8396 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
8397 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
8398 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
8402 api_l2_fib_table_dump (vat_main_t * vam)
8404 unformat_input_t *i = vam->input;
8405 vl_api_l2_fib_table_dump_t *mp;
8406 vl_api_control_ping_t *mp_ping;
8411 /* Parse args required to build the message */
8412 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8414 if (unformat (i, "bd_id %d", &bd_id))
8422 errmsg ("missing bridge domain");
8426 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
8428 /* Get list of l2 fib entries */
8429 M (L2_FIB_TABLE_DUMP, mp);
8431 mp->bd_id = ntohl (bd_id);
8434 /* Use a control ping for synchronization */
8435 MPING (CONTROL_PING, mp_ping);
8444 api_interface_name_renumber (vat_main_t * vam)
8446 unformat_input_t *line_input = vam->input;
8447 vl_api_interface_name_renumber_t *mp;
8448 u32 sw_if_index = ~0;
8449 u32 new_show_dev_instance = ~0;
8452 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8454 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
8457 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8459 else if (unformat (line_input, "new_show_dev_instance %d",
8460 &new_show_dev_instance))
8466 if (sw_if_index == ~0)
8468 errmsg ("missing interface name or sw_if_index");
8472 if (new_show_dev_instance == ~0)
8474 errmsg ("missing new_show_dev_instance");
8478 M (INTERFACE_NAME_RENUMBER, mp);
8480 mp->sw_if_index = ntohl (sw_if_index);
8481 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8489 api_want_l2_macs_events (vat_main_t * vam)
8491 unformat_input_t *line_input = vam->input;
8492 vl_api_want_l2_macs_events_t *mp;
8493 u8 enable_disable = 1;
8495 u32 max_macs_in_event = 0;
8496 u32 learn_limit = 0;
8499 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8501 if (unformat (line_input, "learn-limit %d", &learn_limit))
8503 else if (unformat (line_input, "scan-delay %d", &scan_delay))
8505 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
8507 else if (unformat (line_input, "disable"))
8513 M (WANT_L2_MACS_EVENTS, mp);
8514 mp->enable_disable = enable_disable;
8515 mp->pid = htonl (getpid ());
8516 mp->learn_limit = htonl (learn_limit);
8517 mp->scan_delay = (u8) scan_delay;
8518 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
8525 api_ip_address_dump (vat_main_t * vam)
8527 unformat_input_t *i = vam->input;
8528 vl_api_ip_address_dump_t *mp;
8529 vl_api_control_ping_t *mp_ping;
8530 u32 sw_if_index = ~0;
8531 u8 sw_if_index_set = 0;
8536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8538 if (unformat (i, "sw_if_index %d", &sw_if_index))
8539 sw_if_index_set = 1;
8541 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8542 sw_if_index_set = 1;
8543 else if (unformat (i, "ipv4"))
8545 else if (unformat (i, "ipv6"))
8551 if (ipv4_set && ipv6_set)
8553 errmsg ("ipv4 and ipv6 flags cannot be both set");
8557 if ((!ipv4_set) && (!ipv6_set))
8559 errmsg ("no ipv4 nor ipv6 flag set");
8563 if (sw_if_index_set == 0)
8565 errmsg ("missing interface name or sw_if_index");
8569 vam->current_sw_if_index = sw_if_index;
8570 vam->is_ipv6 = ipv6_set;
8572 M (IP_ADDRESS_DUMP, mp);
8573 mp->sw_if_index = ntohl (sw_if_index);
8574 mp->is_ipv6 = ipv6_set;
8577 /* Use a control ping for synchronization */
8578 MPING (CONTROL_PING, mp_ping);
8586 api_ip_dump (vat_main_t * vam)
8588 vl_api_ip_dump_t *mp;
8589 vl_api_control_ping_t *mp_ping;
8590 unformat_input_t *in = vam->input;
8597 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
8599 if (unformat (in, "ipv4"))
8601 else if (unformat (in, "ipv6"))
8607 if (ipv4_set && ipv6_set)
8609 errmsg ("ipv4 and ipv6 flags cannot be both set");
8613 if ((!ipv4_set) && (!ipv6_set))
8615 errmsg ("no ipv4 nor ipv6 flag set");
8620 vam->is_ipv6 = is_ipv6;
8623 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
8625 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8627 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
8630 mp->is_ipv6 = ipv6_set;
8633 /* Use a control ping for synchronization */
8634 MPING (CONTROL_PING, mp_ping);
8642 api_get_first_msg_id (vat_main_t * vam)
8644 vl_api_get_first_msg_id_t *mp;
8645 unformat_input_t *i = vam->input;
8650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8652 if (unformat (i, "client %s", &name))
8660 errmsg ("missing client name");
8665 if (vec_len (name) > 63)
8667 errmsg ("client name too long");
8671 M (GET_FIRST_MSG_ID, mp);
8672 clib_memcpy (mp->name, name, vec_len (name));
8679 api_get_node_graph (vat_main_t * vam)
8681 vl_api_get_node_graph_t *mp;
8684 M (GET_NODE_GRAPH, mp);
8688 /* Wait for the reply */
8694 api_af_packet_create (vat_main_t * vam)
8696 unformat_input_t *i = vam->input;
8697 vl_api_af_packet_create_t *mp;
8698 u8 *host_if_name = 0;
8700 u8 random_hw_addr = 1;
8703 clib_memset (hw_addr, 0, sizeof (hw_addr));
8705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8707 if (unformat (i, "name %s", &host_if_name))
8708 vec_add1 (host_if_name, 0);
8709 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
8715 if (!vec_len (host_if_name))
8717 errmsg ("host-interface name must be specified");
8721 if (vec_len (host_if_name) > 64)
8723 errmsg ("host-interface name too long");
8727 M (AF_PACKET_CREATE, mp);
8729 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
8730 clib_memcpy (mp->hw_addr, hw_addr, 6);
8731 mp->use_random_hw_addr = random_hw_addr;
8732 vec_free (host_if_name);
8740 fprintf (vam->ofp ? vam->ofp : stderr,
8741 " new sw_if_index = %d\n", vam->sw_if_index);
8748 api_af_packet_delete (vat_main_t * vam)
8750 unformat_input_t *i = vam->input;
8751 vl_api_af_packet_delete_t *mp;
8752 u8 *host_if_name = 0;
8755 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8757 if (unformat (i, "name %s", &host_if_name))
8758 vec_add1 (host_if_name, 0);
8763 if (!vec_len (host_if_name))
8765 errmsg ("host-interface name must be specified");
8769 if (vec_len (host_if_name) > 64)
8771 errmsg ("host-interface name too long");
8775 M (AF_PACKET_DELETE, mp);
8777 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
8778 vec_free (host_if_name);
8785 static void vl_api_af_packet_details_t_handler
8786 (vl_api_af_packet_details_t * mp)
8788 vat_main_t *vam = &vat_main;
8790 print (vam->ofp, "%-16s %d",
8791 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
8794 static void vl_api_af_packet_details_t_handler_json
8795 (vl_api_af_packet_details_t * mp)
8797 vat_main_t *vam = &vat_main;
8798 vat_json_node_t *node = NULL;
8800 if (VAT_JSON_ARRAY != vam->json_tree.type)
8802 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8803 vat_json_init_array (&vam->json_tree);
8805 node = vat_json_array_add (&vam->json_tree);
8807 vat_json_init_object (node);
8808 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8809 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
8813 api_af_packet_dump (vat_main_t * vam)
8815 vl_api_af_packet_dump_t *mp;
8816 vl_api_control_ping_t *mp_ping;
8819 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
8820 /* Get list of tap interfaces */
8821 M (AF_PACKET_DUMP, mp);
8824 /* Use a control ping for synchronization */
8825 MPING (CONTROL_PING, mp_ping);
8833 format_fib_api_path_nh_proto (u8 * s, va_list * args)
8835 vl_api_fib_path_nh_proto_t proto =
8836 va_arg (*args, vl_api_fib_path_nh_proto_t);
8840 case FIB_API_PATH_NH_PROTO_IP4:
8841 s = format (s, "ip4");
8843 case FIB_API_PATH_NH_PROTO_IP6:
8844 s = format (s, "ip6");
8846 case FIB_API_PATH_NH_PROTO_MPLS:
8847 s = format (s, "mpls");
8849 case FIB_API_PATH_NH_PROTO_BIER:
8850 s = format (s, "bier");
8852 case FIB_API_PATH_NH_PROTO_ETHERNET:
8853 s = format (s, "ethernet");
8861 format_vl_api_ip_address_union (u8 * s, va_list * args)
8863 vl_api_address_family_t af = va_arg (*args, int);
8864 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
8869 s = format (s, "%U", format_ip4_address, u->ip4);
8872 s = format (s, "%U", format_ip6_address, u->ip6);
8879 format_vl_api_fib_path_type (u8 * s, va_list * args)
8881 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
8885 case FIB_API_PATH_TYPE_NORMAL:
8886 s = format (s, "normal");
8888 case FIB_API_PATH_TYPE_LOCAL:
8889 s = format (s, "local");
8891 case FIB_API_PATH_TYPE_DROP:
8892 s = format (s, "drop");
8894 case FIB_API_PATH_TYPE_UDP_ENCAP:
8895 s = format (s, "udp-encap");
8897 case FIB_API_PATH_TYPE_BIER_IMP:
8898 s = format (s, "bier-imp");
8900 case FIB_API_PATH_TYPE_ICMP_UNREACH:
8901 s = format (s, "unreach");
8903 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
8904 s = format (s, "prohibit");
8906 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
8907 s = format (s, "src-lookup");
8909 case FIB_API_PATH_TYPE_DVR:
8910 s = format (s, "dvr");
8912 case FIB_API_PATH_TYPE_INTERFACE_RX:
8913 s = format (s, "interface-rx");
8915 case FIB_API_PATH_TYPE_CLASSIFY:
8916 s = format (s, "classify");
8924 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
8927 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
8928 ntohl (fp->weight), ntohl (fp->sw_if_index),
8929 format_vl_api_fib_path_type, fp->type,
8930 format_fib_api_path_nh_proto, fp->proto,
8931 format_vl_api_ip_address_union, &fp->nh.address);
8935 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
8936 vl_api_fib_path_t * fp)
8939 struct in6_addr ip6;
8941 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
8942 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
8943 vat_json_object_add_uint (node, "type", fp->type);
8944 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
8945 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
8947 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
8948 vat_json_object_add_ip4 (node, "next_hop", ip4);
8950 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
8952 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
8953 vat_json_object_add_ip6 (node, "next_hop", ip6);
8958 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
8960 vat_main_t *vam = &vat_main;
8961 int count = ntohl (mp->mt_tunnel.mt_n_paths);
8962 vl_api_fib_path_t *fp;
8965 print (vam->ofp, "sw_if_index %d via:",
8966 ntohl (mp->mt_tunnel.mt_sw_if_index));
8967 fp = mp->mt_tunnel.mt_paths;
8968 for (i = 0; i < count; i++)
8970 vl_api_fib_path_print (vam, fp);
8974 print (vam->ofp, "");
8977 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
8978 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
8981 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
8983 vat_main_t *vam = &vat_main;
8984 vat_json_node_t *node = NULL;
8985 int count = ntohl (mp->mt_tunnel.mt_n_paths);
8986 vl_api_fib_path_t *fp;
8989 if (VAT_JSON_ARRAY != vam->json_tree.type)
8991 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8992 vat_json_init_array (&vam->json_tree);
8994 node = vat_json_array_add (&vam->json_tree);
8996 vat_json_init_object (node);
8997 vat_json_object_add_uint (node, "sw_if_index",
8998 ntohl (mp->mt_tunnel.mt_sw_if_index));
9000 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
9002 fp = mp->mt_tunnel.mt_paths;
9003 for (i = 0; i < count; i++)
9005 vl_api_mpls_fib_path_json_print (node, fp);
9011 api_mpls_tunnel_dump (vat_main_t * vam)
9013 vl_api_mpls_tunnel_dump_t *mp;
9014 vl_api_control_ping_t *mp_ping;
9017 M (MPLS_TUNNEL_DUMP, mp);
9021 /* Use a control ping for synchronization */
9022 MPING (CONTROL_PING, mp_ping);
9029 #define vl_api_mpls_table_details_t_endian vl_noop_handler
9030 #define vl_api_mpls_table_details_t_print vl_noop_handler
9034 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
9036 vat_main_t *vam = &vat_main;
9038 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
9041 static void vl_api_mpls_table_details_t_handler_json
9042 (vl_api_mpls_table_details_t * mp)
9044 vat_main_t *vam = &vat_main;
9045 vat_json_node_t *node = NULL;
9047 if (VAT_JSON_ARRAY != vam->json_tree.type)
9049 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9050 vat_json_init_array (&vam->json_tree);
9052 node = vat_json_array_add (&vam->json_tree);
9054 vat_json_init_object (node);
9055 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
9059 api_mpls_table_dump (vat_main_t * vam)
9061 vl_api_mpls_table_dump_t *mp;
9062 vl_api_control_ping_t *mp_ping;
9065 M (MPLS_TABLE_DUMP, mp);
9068 /* Use a control ping for synchronization */
9069 MPING (CONTROL_PING, mp_ping);
9076 #define vl_api_mpls_route_details_t_endian vl_noop_handler
9077 #define vl_api_mpls_route_details_t_print vl_noop_handler
9080 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
9082 vat_main_t *vam = &vat_main;
9083 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
9084 vl_api_fib_path_t *fp;
9088 "table-id %d, label %u, ess_bit %u",
9089 ntohl (mp->mr_route.mr_table_id),
9090 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
9091 fp = mp->mr_route.mr_paths;
9092 for (i = 0; i < count; i++)
9094 vl_api_fib_path_print (vam, fp);
9099 static void vl_api_mpls_route_details_t_handler_json
9100 (vl_api_mpls_route_details_t * mp)
9102 vat_main_t *vam = &vat_main;
9103 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
9104 vat_json_node_t *node = NULL;
9105 vl_api_fib_path_t *fp;
9108 if (VAT_JSON_ARRAY != vam->json_tree.type)
9110 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9111 vat_json_init_array (&vam->json_tree);
9113 node = vat_json_array_add (&vam->json_tree);
9115 vat_json_init_object (node);
9116 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
9117 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
9118 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
9119 vat_json_object_add_uint (node, "path_count", count);
9120 fp = mp->mr_route.mr_paths;
9121 for (i = 0; i < count; i++)
9123 vl_api_mpls_fib_path_json_print (node, fp);
9129 api_mpls_route_dump (vat_main_t * vam)
9131 unformat_input_t *input = vam->input;
9132 vl_api_mpls_route_dump_t *mp;
9133 vl_api_control_ping_t *mp_ping;
9137 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9139 if (unformat (input, "table_id %d", &table_id))
9146 errmsg ("missing table id");
9150 M (MPLS_ROUTE_DUMP, mp);
9152 mp->table.mt_table_id = ntohl (table_id);
9155 /* Use a control ping for synchronization */
9156 MPING (CONTROL_PING, mp_ping);
9163 #define vl_api_ip_table_details_t_endian vl_noop_handler
9164 #define vl_api_ip_table_details_t_print vl_noop_handler
9167 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
9169 vat_main_t *vam = &vat_main;
9172 "%s; table-id %d, prefix %U/%d",
9173 mp->table.name, ntohl (mp->table.table_id));
9177 static void vl_api_ip_table_details_t_handler_json
9178 (vl_api_ip_table_details_t * mp)
9180 vat_main_t *vam = &vat_main;
9181 vat_json_node_t *node = NULL;
9183 if (VAT_JSON_ARRAY != vam->json_tree.type)
9185 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9186 vat_json_init_array (&vam->json_tree);
9188 node = vat_json_array_add (&vam->json_tree);
9190 vat_json_init_object (node);
9191 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
9195 api_ip_table_dump (vat_main_t * vam)
9197 vl_api_ip_table_dump_t *mp;
9198 vl_api_control_ping_t *mp_ping;
9201 M (IP_TABLE_DUMP, mp);
9204 /* Use a control ping for synchronization */
9205 MPING (CONTROL_PING, mp_ping);
9213 api_ip_mtable_dump (vat_main_t * vam)
9215 vl_api_ip_mtable_dump_t *mp;
9216 vl_api_control_ping_t *mp_ping;
9219 M (IP_MTABLE_DUMP, mp);
9222 /* Use a control ping for synchronization */
9223 MPING (CONTROL_PING, mp_ping);
9231 api_ip_mroute_dump (vat_main_t * vam)
9233 unformat_input_t *input = vam->input;
9234 vl_api_control_ping_t *mp_ping;
9235 vl_api_ip_mroute_dump_t *mp;
9240 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9242 if (unformat (input, "table_id %d", &table_id))
9244 else if (unformat (input, "ip6"))
9246 else if (unformat (input, "ip4"))
9253 errmsg ("missing table id");
9257 M (IP_MROUTE_DUMP, mp);
9258 mp->table.table_id = table_id;
9259 mp->table.is_ip6 = is_ip6;
9262 /* Use a control ping for synchronization */
9263 MPING (CONTROL_PING, mp_ping);
9270 #define vl_api_ip_route_details_t_endian vl_noop_handler
9271 #define vl_api_ip_route_details_t_print vl_noop_handler
9274 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
9276 vat_main_t *vam = &vat_main;
9277 u8 count = mp->route.n_paths;
9278 vl_api_fib_path_t *fp;
9282 "table-id %d, prefix %U/%d",
9283 ntohl (mp->route.table_id),
9284 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
9285 for (i = 0; i < count; i++)
9287 fp = &mp->route.paths[i];
9289 vl_api_fib_path_print (vam, fp);
9294 static void vl_api_ip_route_details_t_handler_json
9295 (vl_api_ip_route_details_t * mp)
9297 vat_main_t *vam = &vat_main;
9298 u8 count = mp->route.n_paths;
9299 vat_json_node_t *node = NULL;
9301 struct in6_addr ip6;
9302 vl_api_fib_path_t *fp;
9305 if (VAT_JSON_ARRAY != vam->json_tree.type)
9307 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9308 vat_json_init_array (&vam->json_tree);
9310 node = vat_json_array_add (&vam->json_tree);
9312 vat_json_init_object (node);
9313 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
9314 if (ADDRESS_IP6 == mp->route.prefix.address.af)
9316 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
9317 vat_json_object_add_ip6 (node, "prefix", ip6);
9321 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
9322 vat_json_object_add_ip4 (node, "prefix", ip4);
9324 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
9325 vat_json_object_add_uint (node, "path_count", count);
9326 for (i = 0; i < count; i++)
9328 fp = &mp->route.paths[i];
9329 vl_api_mpls_fib_path_json_print (node, fp);
9334 api_ip_route_dump (vat_main_t * vam)
9336 unformat_input_t *input = vam->input;
9337 vl_api_ip_route_dump_t *mp;
9338 vl_api_control_ping_t *mp_ping;
9344 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9346 if (unformat (input, "table_id %d", &table_id))
9348 else if (unformat (input, "ip6"))
9350 else if (unformat (input, "ip4"))
9357 errmsg ("missing table id");
9361 M (IP_ROUTE_DUMP, mp);
9363 mp->table.table_id = table_id;
9364 mp->table.is_ip6 = is_ip6;
9368 /* Use a control ping for synchronization */
9369 MPING (CONTROL_PING, mp_ping);
9377 api_sw_interface_span_enable_disable (vat_main_t * vam)
9379 unformat_input_t *i = vam->input;
9380 vl_api_sw_interface_span_enable_disable_t *mp;
9381 u32 src_sw_if_index = ~0;
9382 u32 dst_sw_if_index = ~0;
9387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9390 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
9392 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
9396 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
9398 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
9400 else if (unformat (i, "disable"))
9402 else if (unformat (i, "rx"))
9404 else if (unformat (i, "tx"))
9406 else if (unformat (i, "both"))
9408 else if (unformat (i, "l2"))
9414 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
9416 mp->sw_if_index_from = htonl (src_sw_if_index);
9417 mp->sw_if_index_to = htonl (dst_sw_if_index);
9427 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
9430 vat_main_t *vam = &vat_main;
9431 u8 *sw_if_from_name = 0;
9432 u8 *sw_if_to_name = 0;
9433 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
9434 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
9435 char *states[] = { "none", "rx", "tx", "both" };
9439 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
9441 if ((u32) p->value[0] == sw_if_index_from)
9443 sw_if_from_name = (u8 *)(p->key);
9447 if ((u32) p->value[0] == sw_if_index_to)
9449 sw_if_to_name = (u8 *)(p->key);
9450 if (sw_if_from_name)
9455 print (vam->ofp, "%20s => %20s (%s) %s",
9456 sw_if_from_name, sw_if_to_name, states[mp->state],
9457 mp->is_l2 ? "l2" : "device");
9461 vl_api_sw_interface_span_details_t_handler_json
9462 (vl_api_sw_interface_span_details_t * mp)
9464 vat_main_t *vam = &vat_main;
9465 vat_json_node_t *node = NULL;
9466 u8 *sw_if_from_name = 0;
9467 u8 *sw_if_to_name = 0;
9468 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
9469 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
9473 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
9475 if ((u32) p->value[0] == sw_if_index_from)
9477 sw_if_from_name = (u8 *)(p->key);
9481 if ((u32) p->value[0] == sw_if_index_to)
9483 sw_if_to_name = (u8 *)(p->key);
9484 if (sw_if_from_name)
9490 if (VAT_JSON_ARRAY != vam->json_tree.type)
9492 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9493 vat_json_init_array (&vam->json_tree);
9495 node = vat_json_array_add (&vam->json_tree);
9497 vat_json_init_object (node);
9498 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
9499 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
9500 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
9501 if (0 != sw_if_to_name)
9503 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
9505 vat_json_object_add_uint (node, "state", mp->state);
9506 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
9510 api_sw_interface_span_dump (vat_main_t * vam)
9512 unformat_input_t *input = vam->input;
9513 vl_api_sw_interface_span_dump_t *mp;
9514 vl_api_control_ping_t *mp_ping;
9518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9520 if (unformat (input, "l2"))
9526 M (SW_INTERFACE_SPAN_DUMP, mp);
9530 /* Use a control ping for synchronization */
9531 MPING (CONTROL_PING, mp_ping);
9539 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
9541 unformat_input_t *input = vam->input;
9542 vl_api_ip_source_and_port_range_check_add_del_t *mp;
9545 u16 *high_ports = 0;
9548 vl_api_prefix_t prefix;
9555 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9557 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
9559 else if (unformat (input, "vrf %d", &vrf_id))
9561 else if (unformat (input, "del"))
9563 else if (unformat (input, "port %d", &tmp))
9565 if (tmp == 0 || tmp > 65535)
9567 errmsg ("port %d out of range", tmp);
9571 this_hi = this_low + 1;
9572 vec_add1 (low_ports, this_low);
9573 vec_add1 (high_ports, this_hi);
9575 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
9577 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
9579 errmsg ("incorrect range parameters");
9583 /* Note: in debug CLI +1 is added to high before
9584 passing to real fn that does "the work"
9585 (ip_source_and_port_range_check_add_del).
9586 This fn is a wrapper around the binary API fn a
9587 control plane will call, which expects this increment
9588 to have occurred. Hence letting the binary API control
9589 plane fn do the increment for consistency between VAT
9590 and other control planes.
9593 vec_add1 (low_ports, this_low);
9594 vec_add1 (high_ports, this_hi);
9600 if (prefix_set == 0)
9602 errmsg ("<address>/<mask> not specified");
9608 errmsg ("VRF ID required, not specified");
9615 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
9619 if (vec_len (low_ports) == 0)
9621 errmsg ("At least one port or port range required");
9625 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
9627 mp->is_add = is_add;
9629 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
9631 mp->number_of_ranges = vec_len (low_ports);
9633 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
9634 vec_free (low_ports);
9636 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
9637 vec_free (high_ports);
9639 mp->vrf_id = ntohl (vrf_id);
9647 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
9649 unformat_input_t *input = vam->input;
9650 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
9651 u32 sw_if_index = ~0;
9653 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
9654 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
9658 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9660 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9662 else if (unformat (input, "sw_if_index %d", &sw_if_index))
9664 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
9666 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
9668 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
9670 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
9672 else if (unformat (input, "del"))
9678 if (sw_if_index == ~0)
9680 errmsg ("Interface required but not specified");
9686 errmsg ("VRF ID required but not specified");
9690 if (tcp_out_vrf_id == 0
9691 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
9694 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
9698 /* Construct the API message */
9699 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
9701 mp->sw_if_index = ntohl (sw_if_index);
9702 mp->is_add = is_add;
9703 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
9704 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
9705 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
9706 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
9711 /* Wait for a reply... */
9717 api_set_punt (vat_main_t * vam)
9719 unformat_input_t *i = vam->input;
9720 vl_api_address_family_t af;
9721 vl_api_set_punt_t *mp;
9727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9729 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
9731 else if (unformat (i, "protocol %d", &protocol))
9733 else if (unformat (i, "port %d", &port))
9735 else if (unformat (i, "del"))
9739 clib_warning ("parse error '%U'", format_unformat_error, i);
9746 mp->is_add = (u8) is_add;
9747 mp->punt.type = PUNT_API_TYPE_L4;
9748 mp->punt.punt.l4.af = af;
9749 mp->punt.punt.l4.protocol = (u8) protocol;
9750 mp->punt.punt.l4.port = htons ((u16) port);
9758 api_delete_subif (vat_main_t * vam)
9760 unformat_input_t *i = vam->input;
9761 vl_api_delete_subif_t *mp;
9762 u32 sw_if_index = ~0;
9765 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9767 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9769 if (unformat (i, "sw_if_index %d", &sw_if_index))
9775 if (sw_if_index == ~0)
9777 errmsg ("missing sw_if_index");
9781 /* Construct the API message */
9782 M (DELETE_SUBIF, mp);
9783 mp->sw_if_index = ntohl (sw_if_index);
9790 #define foreach_pbb_vtr_op \
9791 _("disable", L2_VTR_DISABLED) \
9792 _("pop", L2_VTR_POP_2) \
9793 _("push", L2_VTR_PUSH_2)
9796 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
9798 unformat_input_t *i = vam->input;
9799 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
9800 u32 sw_if_index = ~0, vtr_op = ~0;
9802 u8 dmac[6], smac[6];
9803 u8 dmac_set = 0, smac_set = 0;
9809 /* Shut up coverity */
9810 clib_memset (dmac, 0, sizeof (dmac));
9811 clib_memset (smac, 0, sizeof (smac));
9813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9815 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9817 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9819 else if (unformat (i, "vtr_op %d", &vtr_op))
9821 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
9824 else if (unformat (i, "translate_pbb_stag"))
9826 if (unformat (i, "%d", &tmp))
9828 vtr_op = L2_VTR_TRANSLATE_2_1;
9834 ("translate_pbb_stag operation requires outer tag definition");
9838 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
9840 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
9842 else if (unformat (i, "sid %d", &sid))
9844 else if (unformat (i, "vlanid %d", &tmp))
9848 clib_warning ("parse error '%U'", format_unformat_error, i);
9853 if ((sw_if_index == ~0) || (vtr_op == ~0))
9855 errmsg ("missing sw_if_index or vtr operation");
9858 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
9859 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
9862 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
9866 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
9867 mp->sw_if_index = ntohl (sw_if_index);
9868 mp->vtr_op = ntohl (vtr_op);
9869 mp->outer_tag = ntohs (outer_tag);
9870 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
9871 clib_memcpy (mp->b_smac, smac, sizeof (smac));
9872 mp->b_vlanid = ntohs (vlanid);
9873 mp->i_sid = ntohl (sid);
9881 api_sw_interface_tag_add_del (vat_main_t * vam)
9883 unformat_input_t *i = vam->input;
9884 vl_api_sw_interface_tag_add_del_t *mp;
9885 u32 sw_if_index = ~0;
9890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9892 if (unformat (i, "tag %s", &tag))
9894 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9896 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9898 else if (unformat (i, "del"))
9904 if (sw_if_index == ~0)
9906 errmsg ("missing interface name or sw_if_index");
9910 if (enable && (tag == 0))
9912 errmsg ("no tag specified");
9916 /* Construct the API message */
9917 M (SW_INTERFACE_TAG_ADD_DEL, mp);
9918 mp->sw_if_index = ntohl (sw_if_index);
9919 mp->is_add = enable;
9921 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9930 api_sw_interface_add_del_mac_address (vat_main_t * vam)
9932 unformat_input_t *i = vam->input;
9933 vl_api_mac_address_t mac = { 0 };
9934 vl_api_sw_interface_add_del_mac_address_t *mp;
9935 u32 sw_if_index = ~0;
9940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9942 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9944 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9946 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
9948 else if (unformat (i, "del"))
9954 if (sw_if_index == ~0)
9956 errmsg ("missing interface name or sw_if_index");
9962 errmsg ("missing MAC address");
9966 /* Construct the API message */
9967 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
9968 mp->sw_if_index = ntohl (sw_if_index);
9969 mp->is_add = is_add;
9970 clib_memcpy (&mp->addr, &mac, sizeof (mac));
9977 static void vl_api_l2_xconnect_details_t_handler
9978 (vl_api_l2_xconnect_details_t * mp)
9980 vat_main_t *vam = &vat_main;
9982 print (vam->ofp, "%15d%15d",
9983 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
9986 static void vl_api_l2_xconnect_details_t_handler_json
9987 (vl_api_l2_xconnect_details_t * mp)
9989 vat_main_t *vam = &vat_main;
9990 vat_json_node_t *node = NULL;
9992 if (VAT_JSON_ARRAY != vam->json_tree.type)
9994 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9995 vat_json_init_array (&vam->json_tree);
9997 node = vat_json_array_add (&vam->json_tree);
9999 vat_json_init_object (node);
10000 vat_json_object_add_uint (node, "rx_sw_if_index",
10001 ntohl (mp->rx_sw_if_index));
10002 vat_json_object_add_uint (node, "tx_sw_if_index",
10003 ntohl (mp->tx_sw_if_index));
10007 api_l2_xconnect_dump (vat_main_t * vam)
10009 vl_api_l2_xconnect_dump_t *mp;
10010 vl_api_control_ping_t *mp_ping;
10013 if (!vam->json_output)
10015 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
10018 M (L2_XCONNECT_DUMP, mp);
10022 /* Use a control ping for synchronization */
10023 MPING (CONTROL_PING, mp_ping);
10031 api_hw_interface_set_mtu (vat_main_t * vam)
10033 unformat_input_t *i = vam->input;
10034 vl_api_hw_interface_set_mtu_t *mp;
10035 u32 sw_if_index = ~0;
10039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10041 if (unformat (i, "mtu %d", &mtu))
10043 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10045 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10051 if (sw_if_index == ~0)
10053 errmsg ("missing interface name or sw_if_index");
10059 errmsg ("no mtu specified");
10063 /* Construct the API message */
10064 M (HW_INTERFACE_SET_MTU, mp);
10065 mp->sw_if_index = ntohl (sw_if_index);
10066 mp->mtu = ntohs ((u16) mtu);
10074 api_tcp_configure_src_addresses (vat_main_t * vam)
10076 vl_api_tcp_configure_src_addresses_t *mp;
10077 unformat_input_t *i = vam->input;
10078 vl_api_address_t first, last;
10083 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10085 if (unformat (i, "%U - %U",
10086 unformat_vl_api_address, &first,
10087 unformat_vl_api_address, &last))
10091 errmsg ("one range per message (range already set)");
10096 else if (unformat (i, "vrf %d", &vrf_id))
10102 if (range_set == 0)
10104 errmsg ("address range not set");
10108 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
10110 mp->vrf_id = ntohl (vrf_id);
10111 clib_memcpy (&mp->first_address, &first, sizeof (first));
10112 clib_memcpy (&mp->last_address, &last, sizeof (last));
10119 static void vl_api_app_namespace_add_del_reply_t_handler
10120 (vl_api_app_namespace_add_del_reply_t * mp)
10122 vat_main_t *vam = &vat_main;
10123 i32 retval = ntohl (mp->retval);
10124 if (vam->async_mode)
10126 vam->async_errors += (retval < 0);
10130 vam->retval = retval;
10132 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
10133 vam->result_ready = 1;
10137 static void vl_api_app_namespace_add_del_reply_t_handler_json
10138 (vl_api_app_namespace_add_del_reply_t * mp)
10140 vat_main_t *vam = &vat_main;
10141 vat_json_node_t node;
10143 vat_json_init_object (&node);
10144 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
10145 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
10147 vat_json_print (vam->ofp, &node);
10148 vat_json_free (&node);
10150 vam->retval = ntohl (mp->retval);
10151 vam->result_ready = 1;
10155 api_app_namespace_add_del (vat_main_t * vam)
10157 vl_api_app_namespace_add_del_t *mp;
10158 unformat_input_t *i = vam->input;
10159 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
10160 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
10164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10166 if (unformat (i, "id %_%v%_", &ns_id))
10168 else if (unformat (i, "secret %lu", &secret))
10170 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10171 sw_if_index_set = 1;
10172 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
10174 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
10179 if (!ns_id || !secret_set || !sw_if_index_set)
10181 errmsg ("namespace id, secret and sw_if_index must be set");
10184 if (vec_len (ns_id) > 64)
10186 errmsg ("namespace id too long");
10189 M (APP_NAMESPACE_ADD_DEL, mp);
10191 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
10192 mp->secret = clib_host_to_net_u64 (secret);
10193 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
10194 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
10195 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
10203 api_sock_init_shm (vat_main_t * vam)
10205 #if VPP_API_TEST_BUILTIN == 0
10206 unformat_input_t *i = vam->input;
10207 vl_api_shm_elem_config_t *config = 0;
10208 u64 size = 64 << 20;
10211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10213 if (unformat (i, "size %U", unformat_memory_size, &size))
10220 * Canned custom ring allocator config.
10221 * Should probably parse all of this
10223 vec_validate (config, 6);
10224 config[0].type = VL_API_VLIB_RING;
10225 config[0].size = 256;
10226 config[0].count = 32;
10228 config[1].type = VL_API_VLIB_RING;
10229 config[1].size = 1024;
10230 config[1].count = 16;
10232 config[2].type = VL_API_VLIB_RING;
10233 config[2].size = 4096;
10234 config[2].count = 2;
10236 config[3].type = VL_API_CLIENT_RING;
10237 config[3].size = 256;
10238 config[3].count = 32;
10240 config[4].type = VL_API_CLIENT_RING;
10241 config[4].size = 1024;
10242 config[4].count = 16;
10244 config[5].type = VL_API_CLIENT_RING;
10245 config[5].size = 4096;
10246 config[5].count = 2;
10248 config[6].type = VL_API_QUEUE;
10249 config[6].count = 128;
10250 config[6].size = sizeof (uword);
10252 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
10254 vam->client_index_invalid = 1;
10262 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
10264 vat_main_t *vam = &vat_main;
10265 fib_prefix_t lcl, rmt;
10267 ip_prefix_decode (&mp->lcl, &lcl);
10268 ip_prefix_decode (&mp->rmt, &rmt);
10270 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
10273 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
10274 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
10275 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
10276 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
10277 &rmt.fp_addr.ip4, rmt.fp_len,
10278 clib_net_to_host_u16 (mp->rmt_port),
10279 clib_net_to_host_u32 (mp->action_index), mp->tag);
10284 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
10285 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
10286 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
10287 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
10288 &rmt.fp_addr.ip6, rmt.fp_len,
10289 clib_net_to_host_u16 (mp->rmt_port),
10290 clib_net_to_host_u32 (mp->action_index), mp->tag);
10295 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
10298 vat_main_t *vam = &vat_main;
10299 vat_json_node_t *node = NULL;
10300 struct in6_addr ip6;
10301 struct in_addr ip4;
10303 fib_prefix_t lcl, rmt;
10305 ip_prefix_decode (&mp->lcl, &lcl);
10306 ip_prefix_decode (&mp->rmt, &rmt);
10308 if (VAT_JSON_ARRAY != vam->json_tree.type)
10310 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10311 vat_json_init_array (&vam->json_tree);
10313 node = vat_json_array_add (&vam->json_tree);
10314 vat_json_init_object (node);
10316 vat_json_object_add_uint (node, "appns_index",
10317 clib_net_to_host_u32 (mp->appns_index));
10318 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
10319 vat_json_object_add_uint (node, "scope", mp->scope);
10320 vat_json_object_add_uint (node, "action_index",
10321 clib_net_to_host_u32 (mp->action_index));
10322 vat_json_object_add_uint (node, "lcl_port",
10323 clib_net_to_host_u16 (mp->lcl_port));
10324 vat_json_object_add_uint (node, "rmt_port",
10325 clib_net_to_host_u16 (mp->rmt_port));
10326 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
10327 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
10328 vat_json_object_add_string_copy (node, "tag", mp->tag);
10329 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
10331 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
10332 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
10333 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
10334 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
10338 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
10339 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
10340 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
10341 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
10346 api_session_rule_add_del (vat_main_t * vam)
10348 vl_api_session_rule_add_del_t *mp;
10349 unformat_input_t *i = vam->input;
10350 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
10351 u32 appns_index = 0, scope = 0;
10352 ip4_address_t lcl_ip4, rmt_ip4;
10353 ip6_address_t lcl_ip6, rmt_ip6;
10354 u8 is_ip4 = 1, conn_set = 0;
10355 u8 is_add = 1, *tag = 0;
10357 fib_prefix_t lcl, rmt;
10359 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10361 if (unformat (i, "del"))
10363 else if (unformat (i, "add"))
10365 else if (unformat (i, "proto tcp"))
10367 else if (unformat (i, "proto udp"))
10369 else if (unformat (i, "appns %d", &appns_index))
10371 else if (unformat (i, "scope %d", &scope))
10373 else if (unformat (i, "tag %_%v%_", &tag))
10377 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
10378 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
10386 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
10387 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
10393 else if (unformat (i, "action %d", &action))
10398 if (proto == ~0 || !conn_set || action == ~0)
10400 errmsg ("transport proto, connection and action must be set");
10406 errmsg ("scope should be 0-3");
10410 M (SESSION_RULE_ADD_DEL, mp);
10412 clib_memset (&lcl, 0, sizeof (lcl));
10413 clib_memset (&rmt, 0, sizeof (rmt));
10416 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
10417 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
10418 lcl.fp_len = lcl_plen;
10419 rmt.fp_len = rmt_plen;
10423 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
10424 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
10425 lcl.fp_len = lcl_plen;
10426 rmt.fp_len = rmt_plen;
10430 ip_prefix_encode (&lcl, &mp->lcl);
10431 ip_prefix_encode (&rmt, &mp->rmt);
10432 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
10433 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
10434 mp->transport_proto =
10435 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
10436 mp->action_index = clib_host_to_net_u32 (action);
10437 mp->appns_index = clib_host_to_net_u32 (appns_index);
10439 mp->is_add = is_add;
10442 clib_memcpy (mp->tag, tag, vec_len (tag));
10452 api_session_rules_dump (vat_main_t * vam)
10454 vl_api_session_rules_dump_t *mp;
10455 vl_api_control_ping_t *mp_ping;
10458 if (!vam->json_output)
10460 print (vam->ofp, "%=20s", "Session Rules");
10463 M (SESSION_RULES_DUMP, mp);
10467 /* Use a control ping for synchronization */
10468 MPING (CONTROL_PING, mp_ping);
10471 /* Wait for a reply... */
10477 api_ip_container_proxy_add_del (vat_main_t * vam)
10479 vl_api_ip_container_proxy_add_del_t *mp;
10480 unformat_input_t *i = vam->input;
10481 u32 sw_if_index = ~0;
10482 vl_api_prefix_t pfx = { };
10486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10488 if (unformat (i, "del"))
10490 else if (unformat (i, "add"))
10492 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
10494 else if (unformat (i, "sw_if_index %u", &sw_if_index))
10499 if (sw_if_index == ~0 || pfx.len == 0)
10501 errmsg ("address and sw_if_index must be set");
10505 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
10507 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
10508 mp->is_add = is_add;
10509 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
10517 api_qos_record_enable_disable (vat_main_t * vam)
10519 unformat_input_t *i = vam->input;
10520 vl_api_qos_record_enable_disable_t *mp;
10521 u32 sw_if_index, qs = 0xff;
10522 u8 sw_if_index_set = 0;
10526 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10528 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10529 sw_if_index_set = 1;
10530 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10531 sw_if_index_set = 1;
10532 else if (unformat (i, "%U", unformat_qos_source, &qs))
10534 else if (unformat (i, "disable"))
10538 clib_warning ("parse error '%U'", format_unformat_error, i);
10543 if (sw_if_index_set == 0)
10545 errmsg ("missing interface name or sw_if_index");
10550 errmsg ("input location must be specified");
10554 M (QOS_RECORD_ENABLE_DISABLE, mp);
10556 mp->record.sw_if_index = ntohl (sw_if_index);
10557 mp->record.input_source = qs;
10558 mp->enable = enable;
10567 q_or_quit (vat_main_t * vam)
10569 #if VPP_API_TEST_BUILTIN == 0
10570 longjmp (vam->jump_buf, 1);
10572 return 0; /* not so much */
10576 q (vat_main_t * vam)
10578 return q_or_quit (vam);
10582 quit (vat_main_t * vam)
10584 return q_or_quit (vam);
10588 comment (vat_main_t * vam)
10594 elog_save (vat_main_t * vam)
10596 #if VPP_API_TEST_BUILTIN == 0
10597 elog_main_t *em = &vam->elog_main;
10598 unformat_input_t *i = vam->input;
10599 char *file, *chroot_file;
10600 clib_error_t *error;
10602 if (!unformat (i, "%s", &file))
10604 errmsg ("expected file name, got `%U'", format_unformat_error, i);
10608 /* It's fairly hard to get "../oopsie" through unformat; just in case */
10609 if (strstr (file, "..") || index (file, '/'))
10611 errmsg ("illegal characters in filename '%s'", file);
10615 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
10619 errmsg ("Saving %wd of %wd events to %s",
10620 elog_n_events_in_buffer (em),
10621 elog_buffer_capacity (em), chroot_file);
10623 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
10624 vec_free (chroot_file);
10627 clib_error_report (error);
10629 errmsg ("Use the vpp event loger...");
10636 elog_setup (vat_main_t * vam)
10638 #if VPP_API_TEST_BUILTIN == 0
10639 elog_main_t *em = &vam->elog_main;
10640 unformat_input_t *i = vam->input;
10641 u32 nevents = 128 << 10;
10643 (void) unformat (i, "nevents %d", &nevents);
10645 elog_init (em, nevents);
10646 vl_api_set_elog_main (em);
10647 vl_api_set_elog_trace_api_messages (1);
10648 errmsg ("Event logger initialized with %u events", nevents);
10650 errmsg ("Use the vpp event loger...");
10656 elog_enable (vat_main_t * vam)
10658 #if VPP_API_TEST_BUILTIN == 0
10659 elog_main_t *em = &vam->elog_main;
10661 elog_enable_disable (em, 1 /* enable */ );
10662 vl_api_set_elog_trace_api_messages (1);
10663 errmsg ("Event logger enabled...");
10665 errmsg ("Use the vpp event loger...");
10671 elog_disable (vat_main_t * vam)
10673 #if VPP_API_TEST_BUILTIN == 0
10674 elog_main_t *em = &vam->elog_main;
10676 elog_enable_disable (em, 0 /* enable */ );
10677 vl_api_set_elog_trace_api_messages (1);
10678 errmsg ("Event logger disabled...");
10680 errmsg ("Use the vpp event loger...");
10686 statseg (vat_main_t * vam)
10688 ssvm_private_t *ssvmp = &vam->stat_segment;
10689 ssvm_shared_header_t *shared_header = ssvmp->sh;
10690 vlib_counter_t **counters;
10691 u64 thread0_index1_packets;
10692 u64 thread0_index1_bytes;
10693 f64 vector_rate, input_rate;
10696 uword *counter_vector_by_name;
10697 if (vam->stat_segment_lockp == 0)
10699 errmsg ("Stat segment not mapped...");
10703 /* look up "/if/rx for sw_if_index 1 as a test */
10705 clib_spinlock_lock (vam->stat_segment_lockp);
10707 counter_vector_by_name = (uword *) shared_header->opaque[1];
10709 p = hash_get_mem (counter_vector_by_name, "/if/rx");
10712 clib_spinlock_unlock (vam->stat_segment_lockp);
10713 errmsg ("/if/tx not found?");
10717 /* Fish per-thread vector of combined counters from shared memory */
10718 counters = (vlib_counter_t **) p[0];
10720 if (vec_len (counters[0]) < 2)
10722 clib_spinlock_unlock (vam->stat_segment_lockp);
10723 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
10727 /* Read thread 0 sw_if_index 1 counter */
10728 thread0_index1_packets = counters[0][1].packets;
10729 thread0_index1_bytes = counters[0][1].bytes;
10731 p = hash_get_mem (counter_vector_by_name, "vector_rate");
10734 clib_spinlock_unlock (vam->stat_segment_lockp);
10735 errmsg ("vector_rate not found?");
10739 vector_rate = *(f64 *) (p[0]);
10740 p = hash_get_mem (counter_vector_by_name, "input_rate");
10743 clib_spinlock_unlock (vam->stat_segment_lockp);
10744 errmsg ("input_rate not found?");
10747 input_rate = *(f64 *) (p[0]);
10749 clib_spinlock_unlock (vam->stat_segment_lockp);
10751 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
10752 vector_rate, input_rate);
10753 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
10754 thread0_index1_packets, thread0_index1_bytes);
10760 cmd_cmp (void *a1, void *a2)
10765 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
10769 help (vat_main_t * vam)
10774 unformat_input_t *i = vam->input;
10777 if (unformat (i, "%s", &name))
10781 vec_add1 (name, 0);
10783 hs = hash_get_mem (vam->help_by_name, name);
10785 print (vam->ofp, "usage: %s %s", name, hs[0]);
10787 print (vam->ofp, "No such msg / command '%s'", name);
10792 print (vam->ofp, "Help is available for the following:");
10795 hash_foreach_pair (p, vam->function_by_name,
10797 vec_add1 (cmds, (u8 *)(p->key));
10801 vec_sort_with_function (cmds, cmd_cmp);
10803 for (j = 0; j < vec_len (cmds); j++)
10804 print (vam->ofp, "%s", cmds[j]);
10811 set (vat_main_t * vam)
10813 u8 *name = 0, *value = 0;
10814 unformat_input_t *i = vam->input;
10816 if (unformat (i, "%s", &name))
10818 /* The input buffer is a vector, not a string. */
10819 value = vec_dup (i->buffer);
10820 vec_delete (value, i->index, 0);
10821 /* Almost certainly has a trailing newline */
10822 if (value[vec_len (value) - 1] == '\n')
10823 value[vec_len (value) - 1] = 0;
10824 /* Make sure it's a proper string, one way or the other */
10825 vec_add1 (value, 0);
10826 (void) clib_macro_set_value (&vam->macro_main,
10827 (char *) name, (char *) value);
10830 errmsg ("usage: set <name> <value>");
10838 unset (vat_main_t * vam)
10842 if (unformat (vam->input, "%s", &name))
10843 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
10844 errmsg ("unset: %s wasn't set", name);
10857 macro_sort_cmp (void *a1, void *a2)
10859 macro_sort_t *s1 = a1;
10860 macro_sort_t *s2 = a2;
10862 return strcmp ((char *) (s1->name), (char *) (s2->name));
10866 dump_macro_table (vat_main_t * vam)
10868 macro_sort_t *sort_me = 0, *sm;
10873 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10875 vec_add2 (sort_me, sm, 1);
10876 sm->name = (u8 *)(p->key);
10877 sm->value = (u8 *) (p->value[0]);
10881 vec_sort_with_function (sort_me, macro_sort_cmp);
10883 if (vec_len (sort_me))
10884 print (vam->ofp, "%-15s%s", "Name", "Value");
10886 print (vam->ofp, "The macro table is empty...");
10888 for (i = 0; i < vec_len (sort_me); i++)
10889 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
10894 dump_node_table (vat_main_t * vam)
10897 vlib_node_t *node, *next_node;
10899 if (vec_len (vam->graph_nodes) == 0)
10901 print (vam->ofp, "Node table empty, issue get_node_graph...");
10905 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
10907 node = vam->graph_nodes[0][i];
10908 print (vam->ofp, "[%d] %s", i, node->name);
10909 for (j = 0; j < vec_len (node->next_nodes); j++)
10911 if (node->next_nodes[j] != ~0)
10913 next_node = vam->graph_nodes[0][node->next_nodes[j]];
10914 print (vam->ofp, " [%d] %s", j, next_node->name);
10922 value_sort_cmp (void *a1, void *a2)
10924 name_sort_t *n1 = a1;
10925 name_sort_t *n2 = a2;
10927 if (n1->value < n2->value)
10929 if (n1->value > n2->value)
10936 dump_msg_api_table (vat_main_t * vam)
10938 api_main_t *am = vlibapi_get_main ();
10939 name_sort_t *nses = 0, *ns;
10944 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
10946 vec_add2 (nses, ns, 1);
10947 ns->name = (u8 *)(hp->key);
10948 ns->value = (u32) hp->value[0];
10952 vec_sort_with_function (nses, value_sort_cmp);
10954 for (i = 0; i < vec_len (nses); i++)
10955 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
10961 get_msg_id (vat_main_t * vam)
10966 if (unformat (vam->input, "%s", &name_and_crc))
10968 message_index = vl_msg_api_get_msg_index (name_and_crc);
10969 if (message_index == ~0)
10971 print (vam->ofp, " '%s' not found", name_and_crc);
10974 print (vam->ofp, " '%s' has message index %d",
10975 name_and_crc, message_index);
10978 errmsg ("name_and_crc required...");
10983 search_node_table (vat_main_t * vam)
10985 unformat_input_t *line_input = vam->input;
10988 vlib_node_t *node, *next_node;
10991 if (vam->graph_node_index_by_name == 0)
10993 print (vam->ofp, "Node table empty, issue get_node_graph...");
10997 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10999 if (unformat (line_input, "%s", &node_to_find))
11001 vec_add1 (node_to_find, 0);
11002 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
11005 print (vam->ofp, "%s not found...", node_to_find);
11008 node = vam->graph_nodes[0][p[0]];
11009 print (vam->ofp, "[%d] %s", p[0], node->name);
11010 for (j = 0; j < vec_len (node->next_nodes); j++)
11012 if (node->next_nodes[j] != ~0)
11014 next_node = vam->graph_nodes[0][node->next_nodes[j]];
11015 print (vam->ofp, " [%d] %s", j, next_node->name);
11022 clib_warning ("parse error '%U'", format_unformat_error,
11028 vec_free (node_to_find);
11037 script (vat_main_t * vam)
11039 #if (VPP_API_TEST_BUILTIN==0)
11041 char *save_current_file;
11042 unformat_input_t save_input;
11043 jmp_buf save_jump_buf;
11044 u32 save_line_number;
11046 FILE *new_fp, *save_ifp;
11048 if (unformat (vam->input, "%s", &s))
11050 new_fp = fopen ((char *) s, "r");
11053 errmsg ("Couldn't open script file %s", s);
11060 errmsg ("Missing script name");
11064 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
11065 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
11066 save_ifp = vam->ifp;
11067 save_line_number = vam->input_line_number;
11068 save_current_file = (char *) vam->current_file;
11070 vam->input_line_number = 0;
11072 vam->current_file = s;
11075 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
11076 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
11077 vam->ifp = save_ifp;
11078 vam->input_line_number = save_line_number;
11079 vam->current_file = (u8 *) save_current_file;
11084 clib_warning ("use the exec command...");
11090 echo (vat_main_t * vam)
11092 print (vam->ofp, "%v", vam->input->buffer);
11096 /* List of API message constructors, CLI names map to api_xxx */
11097 #define foreach_vpe_api_msg \
11098 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
11099 _(sw_interface_dump,"") \
11100 _(sw_interface_set_flags, \
11101 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
11102 _(sw_interface_add_del_address, \
11103 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
11104 _(sw_interface_set_rx_mode, \
11105 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
11106 _(sw_interface_set_rx_placement, \
11107 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
11108 _(sw_interface_rx_placement_dump, \
11109 "[<intfc> | sw_if_index <id>]") \
11110 _(sw_interface_set_table, \
11111 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
11112 _(sw_interface_set_mpls_enable, \
11113 "<intfc> | sw_if_index [disable | dis]") \
11114 _(sw_interface_set_vpath, \
11115 "<intfc> | sw_if_index <id> enable | disable") \
11116 _(sw_interface_set_l2_xconnect, \
11117 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11118 "enable | disable") \
11119 _(sw_interface_set_l2_bridge, \
11120 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
11121 "[shg <split-horizon-group>] [bvi]\n" \
11122 "enable | disable") \
11123 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
11124 _(bridge_domain_add_del, \
11125 "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") \
11126 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
11128 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
11129 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
11130 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
11132 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11134 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11136 "id <num> [hw-addr <mac-addr>] [host-if-name <name>] [host-ns <name>] [num-rx-queues <num>] [rx-ring-size <num>] [tx-ring-size <num>] [host-bridge <name>] [host-mac-addr <mac-addr>] [host-ip4-addr <ip4addr/mask>] [host-ip6-addr <ip6addr/mask>] [host-mtu-size <mtu>] [gso | no-gso | csum-offload | gro-coalesce] [persist] [attach] [tun] [packed] [in-order]") \
11138 "<vpp-if-name> | sw_if_index <id>") \
11139 _(sw_interface_tap_v2_dump, "") \
11140 _(virtio_pci_create_v2, \
11141 "pci-addr <pci-address> [use_random_mac | hw-addr <mac-addr>] [features <hex-value>] [gso-enabled [gro-coalesce] | csum-offload-enabled] [packed] [in-order] [buffering]") \
11142 _(virtio_pci_delete, \
11143 "<vpp-if-name> | sw_if_index <id>") \
11144 _(sw_interface_virtio_pci_dump, "") \
11146 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
11147 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
11150 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
11151 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
11152 "[id <if-id>] [gso]") \
11154 "<vpp-if-name> | sw_if_index <id>") \
11155 _(bond_add_member, \
11156 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
11157 _(bond_detach_member, \
11158 "sw_if_index <n>") \
11159 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
11160 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
11161 _(sw_member_interface_dump, \
11162 "<vpp-if-name> | sw_if_index <id>") \
11163 _(ip_table_add_del, \
11164 "table <n> [ipv6] [add | del]\n") \
11165 _(ip_route_add_del, \
11166 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
11167 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
11168 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
11169 "[multipath] [count <n>] [del]") \
11170 _(ip_mroute_add_del, \
11171 "<src> <grp>/<mask> [table-id <n>]\n" \
11172 "[<intfc> | sw_if_index <id>] [local] [del]") \
11173 _(mpls_table_add_del, \
11174 "table <n> [add | del]\n") \
11175 _(mpls_route_add_del, \
11176 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
11177 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
11178 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
11179 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
11180 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
11181 "[count <n>] [del]") \
11182 _(mpls_ip_bind_unbind, \
11183 "<label> <addr/len>") \
11184 _(mpls_tunnel_add_del, \
11185 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
11186 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
11187 "[l2-only] [out-label <n>]") \
11188 _(sr_mpls_policy_add, \
11189 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
11190 _(sr_mpls_policy_del, \
11192 _(sw_interface_set_unnumbered, \
11193 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
11194 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
11195 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
11196 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
11197 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
11198 "[outer_vlan_id_any][inner_vlan_id_any]") \
11199 _(ip_table_replace_begin, "table <n> [ipv6]") \
11200 _(ip_table_flush, "table <n> [ipv6]") \
11201 _(ip_table_replace_end, "table <n> [ipv6]") \
11202 _(set_ip_flow_hash, \
11203 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
11204 _(sw_interface_ip6_enable_disable, \
11205 "<intfc> | sw_if_index <id> enable | disable") \
11206 _(l2_patch_add_del, \
11207 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11208 "enable | disable") \
11209 _(sr_localsid_add_del, \
11210 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
11211 "fib-table <num> (end.psp) sw_if_index <num>") \
11212 _(get_node_index, "node <node-name") \
11213 _(add_node_next, "node <node-name> next <next-node-name>") \
11214 _(l2_fib_clear_table, "") \
11215 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
11216 _(l2_interface_vlan_tag_rewrite, \
11217 "<intfc> | sw_if_index <nn> \n" \
11218 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
11219 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
11220 _(create_vhost_user_if, \
11221 "socket <filename> [server] [renumber <dev_instance>] " \
11222 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
11223 "[mac <mac_address>] [packed]") \
11224 _(modify_vhost_user_if, \
11225 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11226 "[server] [renumber <dev_instance>] [gso] [packed]") \
11227 _(create_vhost_user_if_v2, \
11228 "socket <filename> [server] [renumber <dev_instance>] " \
11229 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
11230 "[mac <mac_address>] [packed] [event-idx]") \
11231 _(modify_vhost_user_if_v2, \
11232 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11233 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
11234 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
11235 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
11236 _(show_version, "") \
11237 _(show_threads, "") \
11238 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
11239 _(interface_name_renumber, \
11240 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
11241 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
11242 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
11243 _(ip_dump, "ipv4 | ipv6") \
11244 _(delete_loopback,"sw_if_index <nn>") \
11245 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
11246 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
11247 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
11248 _(want_interface_events, "enable|disable") \
11249 _(get_first_msg_id, "client <name>") \
11250 _(get_node_graph, " ") \
11251 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
11252 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
11253 _(ioam_disable, "") \
11254 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
11255 _(af_packet_delete, "name <host interface name>") \
11256 _(af_packet_dump, "") \
11257 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
11258 _(mpls_table_dump, "") \
11259 _(mpls_route_dump, "table-id <ID>") \
11260 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
11261 _(sw_interface_span_dump, "[l2]") \
11262 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
11263 _(ip_source_and_port_range_check_add_del, \
11264 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
11265 _(ip_source_and_port_range_check_interface_add_del, \
11266 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
11267 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
11268 _(delete_subif,"<intfc> | sw_if_index <nn>") \
11269 _(l2_interface_pbb_tag_rewrite, \
11270 "<intfc> | sw_if_index <nn> \n" \
11271 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
11272 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
11273 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
11274 _(ip_table_dump, "") \
11275 _(ip_route_dump, "table-id [ip4|ip6]") \
11276 _(ip_mtable_dump, "") \
11277 _(ip_mroute_dump, "table-id [ip4|ip6]") \
11278 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
11280 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
11281 "mac <mac-address> [del]") \
11282 _(l2_xconnect_dump, "") \
11283 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
11284 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
11285 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
11286 _(sock_init_shm, "size <nnn>") \
11287 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
11288 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
11289 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
11290 _(session_rules_dump, "") \
11291 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
11292 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
11294 /* List of command functions, CLI names map directly to functions */
11295 #define foreach_cli_function \
11296 _(comment, "usage: comment <ignore-rest-of-line>") \
11297 _(dump_interface_table, "usage: dump_interface_table") \
11298 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
11299 _(dump_ipv4_table, "usage: dump_ipv4_table") \
11300 _(dump_ipv6_table, "usage: dump_ipv6_table") \
11301 _(dump_macro_table, "usage: dump_macro_table ") \
11302 _(dump_node_table, "usage: dump_node_table") \
11303 _(dump_msg_api_table, "usage: dump_msg_api_table") \
11304 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
11305 _(elog_disable, "usage: elog_disable") \
11306 _(elog_enable, "usage: elog_enable") \
11307 _(elog_save, "usage: elog_save <filename>") \
11308 _(get_msg_id, "usage: get_msg_id name_and_crc") \
11309 _(echo, "usage: echo <message>") \
11310 _(exec, "usage: exec <vpe-debug-CLI-command>") \
11311 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
11312 _(help, "usage: help") \
11313 _(q, "usage: quit") \
11314 _(quit, "usage: quit") \
11315 _(search_node_table, "usage: search_node_table <name>...") \
11316 _(set, "usage: set <variable-name> <value>") \
11317 _(script, "usage: script <file-name>") \
11318 _(statseg, "usage: statseg") \
11319 _(unset, "usage: unset <variable-name>")
11322 static void vl_api_##n##_t_handler_uni \
11323 (vl_api_##n##_t * mp) \
11325 vat_main_t * vam = &vat_main; \
11326 if (vam->json_output) { \
11327 vl_api_##n##_t_handler_json(mp); \
11329 vl_api_##n##_t_handler(mp); \
11332 foreach_vpe_api_reply_msg;
11333 #if VPP_API_TEST_BUILTIN == 0
11334 foreach_standalone_reply_msg;
11339 vat_api_hookup (vat_main_t * vam)
11342 vl_msg_api_set_handlers(VL_API_##N, #n, \
11343 vl_api_##n##_t_handler_uni, \
11345 vl_api_##n##_t_endian, \
11346 vl_api_##n##_t_print, \
11347 sizeof(vl_api_##n##_t), 1);
11348 foreach_vpe_api_reply_msg;
11349 #if VPP_API_TEST_BUILTIN == 0
11350 foreach_standalone_reply_msg;
11354 #if (VPP_API_TEST_BUILTIN==0)
11355 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
11357 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
11359 vam->function_by_name = hash_create_string (0, sizeof (uword));
11361 vam->help_by_name = hash_create_string (0, sizeof (uword));
11364 /* API messages we can send */
11365 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
11366 foreach_vpe_api_msg;
11370 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11371 foreach_vpe_api_msg;
11374 /* CLI functions */
11375 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
11376 foreach_cli_function;
11380 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11381 foreach_cli_function;
11385 #if VPP_API_TEST_BUILTIN
11386 static clib_error_t *
11387 vat_api_hookup_shim (vlib_main_t * vm)
11389 vat_api_hookup (&vat_main);
11393 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
11397 * fd.io coding-style-patch-verification: ON
11400 * eval: (c-set-style "gnu")