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/vxlan/vxlan.h>
31 #include <vnet/vxlan-gpe/vxlan_gpe.h>
32 #include <vnet/udp/udp_local.h>
34 #include <vpp/api/vpe_msg_enum.h>
35 #include <vnet/l2/l2_classify.h>
36 #include <vnet/l2/l2_vtr.h>
37 #include <vnet/classify/in_out_acl.h>
38 #include <vnet/classify/policer_classify.h>
39 #include <vnet/classify/flow_classify.h>
40 #include <vnet/mpls/mpls.h>
41 #include <vnet/ipsec/ipsec.h>
43 #include <vnet/ip/ip6_hop_by_hop.h>
44 #include <vnet/ip/ip_source_and_port_range_check.h>
45 #include <vnet/policer/xlate.h>
46 #include <vnet/span/span.h>
47 #include <vnet/policer/policer.h>
48 #include <vnet/policer/police.h>
49 #include <vnet/mfib/mfib_types.h>
50 #include <vnet/bonding/node.h>
51 #include <vnet/qos/qos_types.h>
52 #include <vnet/ethernet/ethernet_types_api.h>
53 #include <vnet/ip/ip_types_api.h>
54 #include "vat/json_format.h"
55 #include <vnet/ip/ip_types_api.h>
56 #include <vnet/ethernet/ethernet_types_api.h>
61 #define vl_typedefs /* define message structures */
62 #include <vpp/api/vpe_all_api_h.h>
65 /* declare message handlers for each api */
67 #define vl_endianfun /* define message structures */
68 #include <vpp/api/vpe_all_api_h.h>
71 /* instantiate all the print functions we know about */
72 #if VPP_API_TEST_BUILTIN == 0
73 #define vl_print(handle, ...)
75 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
78 #include <vpp/api/vpe_all_api_h.h>
81 #define __plugin_msg_base 0
82 #include <vlibapi/vat_helper_macros.h>
84 void vl_api_set_elog_main (elog_main_t * m);
85 int vl_api_set_elog_trace_api_messages (int enable);
87 #if VPP_API_TEST_BUILTIN == 0
97 vat_socket_connect (vat_main_t * vam)
100 api_main_t *am = vlibapi_get_main ();
101 vam->socket_client_main = &socket_client_main;
102 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
104 0 /* default socket rx, tx buffer */ )))
107 /* vpp expects the client index in network order */
108 vam->my_client_index = htonl (socket_client_main.client_index);
109 am->my_client_index = vam->my_client_index;
112 #else /* vpp built-in case, we don't do sockets... */
114 vat_socket_connect (vat_main_t * vam)
120 vl_socket_client_read (int wait)
126 vl_socket_client_write ()
132 vl_socket_client_msg_alloc (int nbytes)
140 vat_time_now (vat_main_t * vam)
142 #if VPP_API_TEST_BUILTIN
143 return vlib_time_now (vam->vlib_main);
145 return clib_time_now (&vam->clib_time);
150 errmsg (char *fmt, ...)
152 vat_main_t *vam = &vat_main;
157 s = va_format (0, fmt, &va);
162 #if VPP_API_TEST_BUILTIN
163 vlib_cli_output (vam->vlib_main, (char *) s);
166 if (vam->ifp != stdin)
167 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
168 vam->input_line_number);
170 fformat (vam->ofp, "%s\n", (char *) s);
178 #if VPP_API_TEST_BUILTIN == 0
180 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
182 vat_main_t *vam = va_arg (*args, vat_main_t *);
183 u32 *result = va_arg (*args, u32 *);
187 if (!unformat (input, "%s", &if_name))
190 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
198 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
203 /* Parse an IP4 address %d.%d.%d.%d. */
205 unformat_ip4_address (unformat_input_t * input, va_list * args)
207 u8 *result = va_arg (*args, u8 *);
210 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
213 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
225 unformat_ethernet_address (unformat_input_t * input, va_list * args)
227 u8 *result = va_arg (*args, u8 *);
230 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
231 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
235 for (i = 0; i < 6; i++)
236 if (a[i] >= (1 << 8))
239 for (i = 0; i < 6; i++)
245 /* Returns ethernet type as an int in host byte order. */
247 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
250 u16 *result = va_arg (*args, u16 *);
254 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
256 if (type >= (1 << 16))
264 /* Parse an IP46 address. */
266 unformat_ip46_address (unformat_input_t * input, va_list * args)
268 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
269 ip46_type_t type = va_arg (*args, ip46_type_t);
270 if ((type != IP46_TYPE_IP6) &&
271 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
273 ip46_address_mask_ip4 (ip46);
276 else if ((type != IP46_TYPE_IP4) &&
277 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
284 /* Parse an IP6 address. */
286 unformat_ip6_address (unformat_input_t * input, va_list * args)
288 ip6_address_t *result = va_arg (*args, ip6_address_t *);
290 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
291 uword c, n_colon, double_colon_index;
293 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
294 double_colon_index = ARRAY_LEN (hex_quads);
295 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
298 if (c >= '0' && c <= '9')
300 else if (c >= 'a' && c <= 'f')
301 hex_digit = c + 10 - 'a';
302 else if (c >= 'A' && c <= 'F')
303 hex_digit = c + 10 - 'A';
304 else if (c == ':' && n_colon < 2)
308 unformat_put_input (input);
312 /* Too many hex quads. */
313 if (n_hex_quads >= ARRAY_LEN (hex_quads))
318 hex_quad = (hex_quad << 4) | hex_digit;
320 /* Hex quad must fit in 16 bits. */
321 if (n_hex_digits >= 4)
328 /* Save position of :: */
331 /* More than one :: ? */
332 if (double_colon_index < ARRAY_LEN (hex_quads))
334 double_colon_index = n_hex_quads;
337 if (n_colon > 0 && n_hex_digits > 0)
339 hex_quads[n_hex_quads++] = hex_quad;
345 if (n_hex_digits > 0)
346 hex_quads[n_hex_quads++] = hex_quad;
351 /* Expand :: to appropriate number of zero hex quads. */
352 if (double_colon_index < ARRAY_LEN (hex_quads))
354 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
356 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
357 hex_quads[n_zero + i] = hex_quads[i];
359 for (i = 0; i < n_zero; i++)
360 hex_quads[double_colon_index + i] = 0;
362 n_hex_quads = ARRAY_LEN (hex_quads);
365 /* Too few hex quads given. */
366 if (n_hex_quads < ARRAY_LEN (hex_quads))
369 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
370 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
377 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
379 u32 *r = va_arg (*args, u32 *);
382 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
383 foreach_ipsec_policy_action
391 format_ipsec_crypto_alg (u8 * s, va_list * args)
393 u32 i = va_arg (*args, u32);
398 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
399 foreach_ipsec_crypto_alg
402 return format (s, "unknown");
404 return format (s, "%s", t);
408 format_ipsec_integ_alg (u8 * s, va_list * args)
410 u32 i = va_arg (*args, u32);
415 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
416 foreach_ipsec_integ_alg
419 return format (s, "unknown");
421 return format (s, "%s", t);
424 #else /* VPP_API_TEST_BUILTIN == 1 */
426 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
428 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
429 vnet_main_t *vnm = vnet_get_main ();
430 u32 *result = va_arg (*args, u32 *);
432 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
436 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
438 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
439 vnet_main_t *vnm = vnet_get_main ();
440 u32 *result = va_arg (*args, u32 *);
442 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
445 #endif /* VPP_API_TEST_BUILTIN */
448 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
450 u32 *r = va_arg (*args, u32 *);
453 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
454 foreach_ipsec_crypto_alg
462 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
464 u32 *r = va_arg (*args, u32 *);
467 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
468 foreach_ipsec_integ_alg
476 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
478 u8 *r = va_arg (*args, u8 *);
480 if (unformat (input, "kbps"))
482 else if (unformat (input, "pps"))
490 unformat_policer_round_type (unformat_input_t * input, va_list * args)
492 u8 *r = va_arg (*args, u8 *);
494 if (unformat (input, "closest"))
495 *r = QOS_ROUND_TO_CLOSEST;
496 else if (unformat (input, "up"))
497 *r = QOS_ROUND_TO_UP;
498 else if (unformat (input, "down"))
499 *r = QOS_ROUND_TO_DOWN;
506 unformat_policer_type (unformat_input_t * input, va_list * args)
508 u8 *r = va_arg (*args, u8 *);
510 if (unformat (input, "1r2c"))
511 *r = QOS_POLICER_TYPE_1R2C;
512 else if (unformat (input, "1r3c"))
513 *r = QOS_POLICER_TYPE_1R3C_RFC_2697;
514 else if (unformat (input, "2r3c-2698"))
515 *r = QOS_POLICER_TYPE_2R3C_RFC_2698;
516 else if (unformat (input, "2r3c-4115"))
517 *r = QOS_POLICER_TYPE_2R3C_RFC_4115;
518 else if (unformat (input, "2r3c-mef5cf1"))
519 *r = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
526 unformat_dscp (unformat_input_t * input, va_list * va)
528 u8 *r = va_arg (*va, u8 *);
531 #define _(v, f) else if (unformat (input, #f)) *r = IP_DSCP_##f;
539 unformat_policer_action_type (unformat_input_t * input, va_list * va)
541 qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *);
543 if (unformat (input, "drop"))
544 a->action_type = QOS_ACTION_DROP;
545 else if (unformat (input, "transmit"))
546 a->action_type = QOS_ACTION_TRANSMIT;
547 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
548 a->action_type = QOS_ACTION_MARK_AND_TRANSMIT;
554 #if (VPP_API_TEST_BUILTIN==0)
556 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
557 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
558 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
559 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
562 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
564 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
565 mfib_itf_attribute_t attr;
568 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
570 if (unformat (input, mfib_itf_flag_long_names[attr]))
571 *iflags |= (1 << attr);
573 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
575 if (unformat (input, mfib_itf_flag_names[attr]))
576 *iflags |= (1 << attr);
579 return (old == *iflags ? 0 : 1);
583 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
585 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
586 mfib_entry_attribute_t attr;
589 FOR_EACH_MFIB_ATTRIBUTE (attr)
591 if (unformat (input, mfib_flag_long_names[attr]))
592 *eflags |= (1 << attr);
594 FOR_EACH_MFIB_ATTRIBUTE (attr)
596 if (unformat (input, mfib_flag_names[attr]))
597 *eflags |= (1 << attr);
600 return (old == *eflags ? 0 : 1);
604 format_ip4_address (u8 * s, va_list * args)
606 u8 *a = va_arg (*args, u8 *);
607 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
611 format_ip6_address (u8 * s, va_list * args)
613 ip6_address_t *a = va_arg (*args, ip6_address_t *);
614 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
616 i_max_n_zero = ARRAY_LEN (a->as_u16);
618 i_first_zero = i_max_n_zero;
620 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
622 u32 is_zero = a->as_u16[i] == 0;
623 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
629 if ((!is_zero && n_zeros > max_n_zeros)
630 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
632 i_max_n_zero = i_first_zero;
633 max_n_zeros = n_zeros;
634 i_first_zero = ARRAY_LEN (a->as_u16);
639 last_double_colon = 0;
640 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
642 if (i == i_max_n_zero && max_n_zeros > 1)
644 s = format (s, "::");
645 i += max_n_zeros - 1;
646 last_double_colon = 1;
650 s = format (s, "%s%x",
651 (last_double_colon || i == 0) ? "" : ":",
652 clib_net_to_host_u16 (a->as_u16[i]));
653 last_double_colon = 0;
660 /* Format an IP46 address. */
662 format_ip46_address (u8 * s, va_list * args)
664 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
665 ip46_type_t type = va_arg (*args, ip46_type_t);
671 is_ip4 = ip46_address_is_ip4 (ip46);
682 format (s, "%U", format_ip4_address, &ip46->ip4) :
683 format (s, "%U", format_ip6_address, &ip46->ip6);
687 format_ethernet_address (u8 * s, va_list * args)
689 u8 *a = va_arg (*args, u8 *);
691 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
692 a[0], a[1], a[2], a[3], a[4], a[5]);
697 increment_v4_address (vl_api_ip4_address_t * i)
699 ip4_address_t *a = (ip4_address_t *) i;
702 v = ntohl (a->as_u32) + 1;
703 a->as_u32 = ntohl (v);
707 increment_v6_address (vl_api_ip6_address_t * i)
709 ip6_address_t *a = (ip6_address_t *) i;
712 v0 = clib_net_to_host_u64 (a->as_u64[0]);
713 v1 = clib_net_to_host_u64 (a->as_u64[1]);
718 a->as_u64[0] = clib_net_to_host_u64 (v0);
719 a->as_u64[1] = clib_net_to_host_u64 (v1);
723 increment_address (vl_api_address_t * a)
725 if (a->af == ADDRESS_IP4)
726 increment_v4_address (&a->un.ip4);
727 else if (a->af == ADDRESS_IP6)
728 increment_v6_address (&a->un.ip6);
732 set_ip4_address (vl_api_address_t * a, u32 v)
734 if (a->af == ADDRESS_IP4)
736 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
742 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
745 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
747 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
748 sizeof (ip6_address_t));
752 increment_mac_address (u8 * mac)
754 u64 tmp = *((u64 *) mac);
755 tmp = clib_net_to_host_u64 (tmp);
756 tmp += 1 << 16; /* skip unused (least significant) octets */
757 tmp = clib_host_to_net_u64 (tmp);
759 clib_memcpy (mac, &tmp, 6);
763 vat_json_object_add_address (vat_json_node_t * node,
764 const char *str, const vl_api_address_t * addr)
766 if (ADDRESS_IP6 == addr->af)
770 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
771 vat_json_object_add_ip6 (node, str, ip6);
777 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
778 vat_json_object_add_ip4 (node, str, ip4);
783 vat_json_object_add_prefix (vat_json_node_t * node,
784 const vl_api_prefix_t * prefix)
786 vat_json_object_add_uint (node, "len", prefix->len);
787 vat_json_object_add_address (node, "address", &prefix->address);
790 static void vl_api_create_loopback_reply_t_handler
791 (vl_api_create_loopback_reply_t * mp)
793 vat_main_t *vam = &vat_main;
794 i32 retval = ntohl (mp->retval);
796 vam->retval = retval;
797 vam->regenerate_interface_table = 1;
798 vam->sw_if_index = ntohl (mp->sw_if_index);
799 vam->result_ready = 1;
802 static void vl_api_create_loopback_reply_t_handler_json
803 (vl_api_create_loopback_reply_t * mp)
805 vat_main_t *vam = &vat_main;
806 vat_json_node_t node;
808 vat_json_init_object (&node);
809 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
810 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
812 vat_json_print (vam->ofp, &node);
813 vat_json_free (&node);
814 vam->retval = ntohl (mp->retval);
815 vam->result_ready = 1;
818 static void vl_api_create_loopback_instance_reply_t_handler
819 (vl_api_create_loopback_instance_reply_t * mp)
821 vat_main_t *vam = &vat_main;
822 i32 retval = ntohl (mp->retval);
824 vam->retval = retval;
825 vam->regenerate_interface_table = 1;
826 vam->sw_if_index = ntohl (mp->sw_if_index);
827 vam->result_ready = 1;
830 static void vl_api_create_loopback_instance_reply_t_handler_json
831 (vl_api_create_loopback_instance_reply_t * mp)
833 vat_main_t *vam = &vat_main;
834 vat_json_node_t node;
836 vat_json_init_object (&node);
837 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
838 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
840 vat_json_print (vam->ofp, &node);
841 vat_json_free (&node);
842 vam->retval = ntohl (mp->retval);
843 vam->result_ready = 1;
846 static void vl_api_af_packet_create_reply_t_handler
847 (vl_api_af_packet_create_reply_t * mp)
849 vat_main_t *vam = &vat_main;
850 i32 retval = ntohl (mp->retval);
852 vam->retval = retval;
853 vam->regenerate_interface_table = 1;
854 vam->sw_if_index = ntohl (mp->sw_if_index);
855 vam->result_ready = 1;
858 static void vl_api_af_packet_create_reply_t_handler_json
859 (vl_api_af_packet_create_reply_t * mp)
861 vat_main_t *vam = &vat_main;
862 vat_json_node_t node;
864 vat_json_init_object (&node);
865 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
866 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
868 vat_json_print (vam->ofp, &node);
869 vat_json_free (&node);
871 vam->retval = ntohl (mp->retval);
872 vam->result_ready = 1;
875 static void vl_api_create_vlan_subif_reply_t_handler
876 (vl_api_create_vlan_subif_reply_t * mp)
878 vat_main_t *vam = &vat_main;
879 i32 retval = ntohl (mp->retval);
881 vam->retval = retval;
882 vam->regenerate_interface_table = 1;
883 vam->sw_if_index = ntohl (mp->sw_if_index);
884 vam->result_ready = 1;
887 static void vl_api_create_vlan_subif_reply_t_handler_json
888 (vl_api_create_vlan_subif_reply_t * mp)
890 vat_main_t *vam = &vat_main;
891 vat_json_node_t node;
893 vat_json_init_object (&node);
894 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
895 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
897 vat_json_print (vam->ofp, &node);
898 vat_json_free (&node);
900 vam->retval = ntohl (mp->retval);
901 vam->result_ready = 1;
904 static void vl_api_create_subif_reply_t_handler
905 (vl_api_create_subif_reply_t * mp)
907 vat_main_t *vam = &vat_main;
908 i32 retval = ntohl (mp->retval);
910 vam->retval = retval;
911 vam->regenerate_interface_table = 1;
912 vam->sw_if_index = ntohl (mp->sw_if_index);
913 vam->result_ready = 1;
916 static void vl_api_create_subif_reply_t_handler_json
917 (vl_api_create_subif_reply_t * mp)
919 vat_main_t *vam = &vat_main;
920 vat_json_node_t node;
922 vat_json_init_object (&node);
923 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
924 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
926 vat_json_print (vam->ofp, &node);
927 vat_json_free (&node);
929 vam->retval = ntohl (mp->retval);
930 vam->result_ready = 1;
933 static void vl_api_interface_name_renumber_reply_t_handler
934 (vl_api_interface_name_renumber_reply_t * mp)
936 vat_main_t *vam = &vat_main;
937 i32 retval = ntohl (mp->retval);
939 vam->retval = retval;
940 vam->regenerate_interface_table = 1;
941 vam->result_ready = 1;
944 static void vl_api_interface_name_renumber_reply_t_handler_json
945 (vl_api_interface_name_renumber_reply_t * mp)
947 vat_main_t *vam = &vat_main;
948 vat_json_node_t node;
950 vat_json_init_object (&node);
951 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
953 vat_json_print (vam->ofp, &node);
954 vat_json_free (&node);
956 vam->retval = ntohl (mp->retval);
957 vam->result_ready = 1;
961 * Special-case: build the interface table, maintain
962 * the next loopback sw_if_index vbl.
964 static void vl_api_sw_interface_details_t_handler
965 (vl_api_sw_interface_details_t * mp)
967 vat_main_t *vam = &vat_main;
968 u8 *s = format (0, "%s%c", mp->interface_name, 0);
970 hash_set_mem (vam->sw_if_index_by_interface_name, s,
971 ntohl (mp->sw_if_index));
973 /* In sub interface case, fill the sub interface table entry */
974 if (mp->sw_if_index != mp->sup_sw_if_index)
976 sw_interface_subif_t *sub = NULL;
978 vec_add2 (vam->sw_if_subif_table, sub, 1);
980 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
981 strncpy ((char *) sub->interface_name, (char *) s,
982 vec_len (sub->interface_name));
983 sub->sw_if_index = ntohl (mp->sw_if_index);
984 sub->sub_id = ntohl (mp->sub_id);
986 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
988 sub->sub_number_of_tags = mp->sub_number_of_tags;
989 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
990 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
992 /* vlan tag rewrite */
993 sub->vtr_op = ntohl (mp->vtr_op);
994 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
995 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
996 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1000 static void vl_api_sw_interface_details_t_handler_json
1001 (vl_api_sw_interface_details_t * mp)
1003 vat_main_t *vam = &vat_main;
1004 vat_json_node_t *node = NULL;
1006 if (VAT_JSON_ARRAY != vam->json_tree.type)
1008 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1009 vat_json_init_array (&vam->json_tree);
1011 node = vat_json_array_add (&vam->json_tree);
1013 vat_json_init_object (node);
1014 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1015 vat_json_object_add_uint (node, "sup_sw_if_index",
1016 ntohl (mp->sup_sw_if_index));
1017 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1018 sizeof (mp->l2_address));
1019 vat_json_object_add_string_copy (node, "interface_name",
1020 mp->interface_name);
1021 vat_json_object_add_string_copy (node, "interface_dev_type",
1022 mp->interface_dev_type);
1023 vat_json_object_add_uint (node, "flags", mp->flags);
1024 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1025 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1026 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1027 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1028 vat_json_object_add_uint (node, "sub_number_of_tags",
1029 mp->sub_number_of_tags);
1030 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1031 ntohs (mp->sub_outer_vlan_id));
1032 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1033 ntohs (mp->sub_inner_vlan_id));
1034 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1035 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1036 vat_json_object_add_uint (node, "vtr_push_dot1q",
1037 ntohl (mp->vtr_push_dot1q));
1038 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1039 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1040 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1042 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1044 format_ethernet_address,
1046 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1048 format_ethernet_address,
1050 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1051 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1055 #if VPP_API_TEST_BUILTIN == 0
1056 static void vl_api_sw_interface_event_t_handler
1057 (vl_api_sw_interface_event_t * mp)
1059 vat_main_t *vam = &vat_main;
1060 if (vam->interface_event_display)
1061 errmsg ("interface flags: sw_if_index %d %s %s",
1062 ntohl (mp->sw_if_index),
1063 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1064 "admin-up" : "admin-down",
1065 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1066 "link-up" : "link-down");
1070 __clib_unused static void
1071 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1073 /* JSON output not supported */
1077 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1079 vat_main_t *vam = &vat_main;
1080 i32 retval = ntohl (mp->retval);
1082 vam->retval = retval;
1083 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1084 vam->result_ready = 1;
1088 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1090 vat_main_t *vam = &vat_main;
1091 vat_json_node_t node;
1095 vat_json_init_object (&node);
1096 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1097 vat_json_object_add_uint (&node, "reply_in_shmem",
1098 ntohl (mp->reply_in_shmem));
1099 /* Toss the shared-memory original... */
1100 oldheap = vl_msg_push_heap ();
1102 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1105 vl_msg_pop_heap (oldheap);
1107 vat_json_print (vam->ofp, &node);
1108 vat_json_free (&node);
1110 vam->retval = ntohl (mp->retval);
1111 vam->result_ready = 1;
1115 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1117 vat_main_t *vam = &vat_main;
1118 i32 retval = ntohl (mp->retval);
1120 vec_reset_length (vam->cmd_reply);
1122 vam->retval = retval;
1124 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1125 vam->result_ready = 1;
1129 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1131 vat_main_t *vam = &vat_main;
1132 vat_json_node_t node;
1133 u8 *reply = 0; /* reply vector */
1135 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1136 vec_reset_length (vam->cmd_reply);
1138 vat_json_init_object (&node);
1139 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1140 vat_json_object_add_string_copy (&node, "reply", reply);
1142 vat_json_print (vam->ofp, &node);
1143 vat_json_free (&node);
1146 vam->retval = ntohl (mp->retval);
1147 vam->result_ready = 1;
1150 static void vl_api_get_node_index_reply_t_handler
1151 (vl_api_get_node_index_reply_t * mp)
1153 vat_main_t *vam = &vat_main;
1154 i32 retval = ntohl (mp->retval);
1155 if (vam->async_mode)
1157 vam->async_errors += (retval < 0);
1161 vam->retval = retval;
1163 errmsg ("node index %d", ntohl (mp->node_index));
1164 vam->result_ready = 1;
1168 static void vl_api_get_node_index_reply_t_handler_json
1169 (vl_api_get_node_index_reply_t * mp)
1171 vat_main_t *vam = &vat_main;
1172 vat_json_node_t node;
1174 vat_json_init_object (&node);
1175 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1176 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1178 vat_json_print (vam->ofp, &node);
1179 vat_json_free (&node);
1181 vam->retval = ntohl (mp->retval);
1182 vam->result_ready = 1;
1185 static void vl_api_get_next_index_reply_t_handler
1186 (vl_api_get_next_index_reply_t * mp)
1188 vat_main_t *vam = &vat_main;
1189 i32 retval = ntohl (mp->retval);
1190 if (vam->async_mode)
1192 vam->async_errors += (retval < 0);
1196 vam->retval = retval;
1198 errmsg ("next node index %d", ntohl (mp->next_index));
1199 vam->result_ready = 1;
1203 static void vl_api_get_next_index_reply_t_handler_json
1204 (vl_api_get_next_index_reply_t * mp)
1206 vat_main_t *vam = &vat_main;
1207 vat_json_node_t node;
1209 vat_json_init_object (&node);
1210 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1211 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1213 vat_json_print (vam->ofp, &node);
1214 vat_json_free (&node);
1216 vam->retval = ntohl (mp->retval);
1217 vam->result_ready = 1;
1220 static void vl_api_add_node_next_reply_t_handler
1221 (vl_api_add_node_next_reply_t * mp)
1223 vat_main_t *vam = &vat_main;
1224 i32 retval = ntohl (mp->retval);
1225 if (vam->async_mode)
1227 vam->async_errors += (retval < 0);
1231 vam->retval = retval;
1233 errmsg ("next index %d", ntohl (mp->next_index));
1234 vam->result_ready = 1;
1238 static void vl_api_add_node_next_reply_t_handler_json
1239 (vl_api_add_node_next_reply_t * mp)
1241 vat_main_t *vam = &vat_main;
1242 vat_json_node_t node;
1244 vat_json_init_object (&node);
1245 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1246 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1248 vat_json_print (vam->ofp, &node);
1249 vat_json_free (&node);
1251 vam->retval = ntohl (mp->retval);
1252 vam->result_ready = 1;
1255 static void vl_api_show_version_reply_t_handler
1256 (vl_api_show_version_reply_t * mp)
1258 vat_main_t *vam = &vat_main;
1259 i32 retval = ntohl (mp->retval);
1263 errmsg (" program: %s", mp->program);
1264 errmsg (" version: %s", mp->version);
1265 errmsg (" build date: %s", mp->build_date);
1266 errmsg ("build directory: %s", mp->build_directory);
1268 vam->retval = retval;
1269 vam->result_ready = 1;
1272 static void vl_api_show_version_reply_t_handler_json
1273 (vl_api_show_version_reply_t * mp)
1275 vat_main_t *vam = &vat_main;
1276 vat_json_node_t node;
1278 vat_json_init_object (&node);
1279 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1280 vat_json_object_add_string_copy (&node, "program", mp->program);
1281 vat_json_object_add_string_copy (&node, "version", mp->version);
1282 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1283 vat_json_object_add_string_copy (&node, "build_directory",
1284 mp->build_directory);
1286 vat_json_print (vam->ofp, &node);
1287 vat_json_free (&node);
1289 vam->retval = ntohl (mp->retval);
1290 vam->result_ready = 1;
1293 static void vl_api_show_threads_reply_t_handler
1294 (vl_api_show_threads_reply_t * mp)
1296 vat_main_t *vam = &vat_main;
1297 i32 retval = ntohl (mp->retval);
1301 count = ntohl (mp->count);
1303 for (i = 0; i < count; i++)
1305 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1306 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1307 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1308 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1309 ntohl (mp->thread_data[i].cpu_socket));
1311 vam->retval = retval;
1312 vam->result_ready = 1;
1315 static void vl_api_show_threads_reply_t_handler_json
1316 (vl_api_show_threads_reply_t * mp)
1318 vat_main_t *vam = &vat_main;
1319 vat_json_node_t node;
1320 vl_api_thread_data_t *td;
1321 i32 retval = ntohl (mp->retval);
1325 count = ntohl (mp->count);
1327 vat_json_init_object (&node);
1328 vat_json_object_add_int (&node, "retval", retval);
1329 vat_json_object_add_uint (&node, "count", count);
1331 for (i = 0; i < count; i++)
1333 td = &mp->thread_data[i];
1334 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1335 vat_json_object_add_string_copy (&node, "name", td->name);
1336 vat_json_object_add_string_copy (&node, "type", td->type);
1337 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1338 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1339 vat_json_object_add_int (&node, "core", ntohl (td->id));
1340 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1343 vat_json_print (vam->ofp, &node);
1344 vat_json_free (&node);
1346 vam->retval = retval;
1347 vam->result_ready = 1;
1351 api_show_threads (vat_main_t * vam)
1353 vl_api_show_threads_t *mp;
1357 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1358 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1360 M (SHOW_THREADS, mp);
1368 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1370 u32 n_macs = ntohl (mp->n_macs);
1371 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1372 ntohl (mp->pid), mp->client_index, n_macs);
1374 for (i = 0; i < n_macs; i++)
1376 vl_api_mac_entry_t *mac = &mp->mac[i];
1377 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1378 i + 1, ntohl (mac->sw_if_index),
1379 format_ethernet_address, mac->mac_addr, mac->action);
1386 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1388 /* JSON output not supported */
1391 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1392 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1395 * Special-case: build the bridge domain table, maintain
1396 * the next bd id vbl.
1398 static void vl_api_bridge_domain_details_t_handler
1399 (vl_api_bridge_domain_details_t * mp)
1401 vat_main_t *vam = &vat_main;
1402 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1405 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1406 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1408 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1409 ntohl (mp->bd_id), mp->learn, mp->forward,
1410 mp->flood, ntohl (mp->bvi_sw_if_index),
1411 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1415 vl_api_bridge_domain_sw_if_t *sw_ifs;
1416 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1419 sw_ifs = mp->sw_if_details;
1420 for (i = 0; i < n_sw_ifs; i++)
1426 sw_if_index = ntohl (sw_ifs->sw_if_index);
1429 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1431 if ((u32) p->value[0] == sw_if_index)
1433 sw_if_name = (u8 *)(p->key);
1438 print (vam->ofp, "%7d %3d %s", sw_if_index,
1439 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1440 "sw_if_index not found!");
1447 static void vl_api_bridge_domain_details_t_handler_json
1448 (vl_api_bridge_domain_details_t * mp)
1450 vat_main_t *vam = &vat_main;
1451 vat_json_node_t *node, *array = NULL;
1452 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1454 if (VAT_JSON_ARRAY != vam->json_tree.type)
1456 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1457 vat_json_init_array (&vam->json_tree);
1459 node = vat_json_array_add (&vam->json_tree);
1461 vat_json_init_object (node);
1462 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1463 vat_json_object_add_uint (node, "flood", mp->flood);
1464 vat_json_object_add_uint (node, "forward", mp->forward);
1465 vat_json_object_add_uint (node, "learn", mp->learn);
1466 vat_json_object_add_uint (node, "bvi_sw_if_index",
1467 ntohl (mp->bvi_sw_if_index));
1468 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1469 array = vat_json_object_add (node, "sw_if");
1470 vat_json_init_array (array);
1476 vl_api_bridge_domain_sw_if_t *sw_ifs;
1479 sw_ifs = mp->sw_if_details;
1480 for (i = 0; i < n_sw_ifs; i++)
1482 node = vat_json_array_add (array);
1483 vat_json_init_object (node);
1484 vat_json_object_add_uint (node, "sw_if_index",
1485 ntohl (sw_ifs->sw_if_index));
1486 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1492 static void vl_api_control_ping_reply_t_handler
1493 (vl_api_control_ping_reply_t * mp)
1495 vat_main_t *vam = &vat_main;
1496 i32 retval = ntohl (mp->retval);
1497 if (vam->async_mode)
1499 vam->async_errors += (retval < 0);
1503 vam->retval = retval;
1504 vam->result_ready = 1;
1506 if (vam->socket_client_main)
1507 vam->socket_client_main->control_pings_outstanding--;
1510 static void vl_api_control_ping_reply_t_handler_json
1511 (vl_api_control_ping_reply_t * mp)
1513 vat_main_t *vam = &vat_main;
1514 i32 retval = ntohl (mp->retval);
1516 if (VAT_JSON_NONE != vam->json_tree.type)
1518 vat_json_print (vam->ofp, &vam->json_tree);
1519 vat_json_free (&vam->json_tree);
1520 vam->json_tree.type = VAT_JSON_NONE;
1525 vat_json_init_array (&vam->json_tree);
1526 vat_json_print (vam->ofp, &vam->json_tree);
1527 vam->json_tree.type = VAT_JSON_NONE;
1530 vam->retval = retval;
1531 vam->result_ready = 1;
1535 vl_api_bridge_domain_set_mac_age_reply_t_handler
1536 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1538 vat_main_t *vam = &vat_main;
1539 i32 retval = ntohl (mp->retval);
1540 if (vam->async_mode)
1542 vam->async_errors += (retval < 0);
1546 vam->retval = retval;
1547 vam->result_ready = 1;
1551 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1552 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1554 vat_main_t *vam = &vat_main;
1555 vat_json_node_t node;
1557 vat_json_init_object (&node);
1558 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1560 vat_json_print (vam->ofp, &node);
1561 vat_json_free (&node);
1563 vam->retval = ntohl (mp->retval);
1564 vam->result_ready = 1;
1568 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1570 vat_main_t *vam = &vat_main;
1571 i32 retval = ntohl (mp->retval);
1572 if (vam->async_mode)
1574 vam->async_errors += (retval < 0);
1578 vam->retval = retval;
1579 vam->result_ready = 1;
1583 static void vl_api_l2_flags_reply_t_handler_json
1584 (vl_api_l2_flags_reply_t * mp)
1586 vat_main_t *vam = &vat_main;
1587 vat_json_node_t node;
1589 vat_json_init_object (&node);
1590 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1591 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1592 ntohl (mp->resulting_feature_bitmap));
1594 vat_json_print (vam->ofp, &node);
1595 vat_json_free (&node);
1597 vam->retval = ntohl (mp->retval);
1598 vam->result_ready = 1;
1601 static void vl_api_bridge_flags_reply_t_handler
1602 (vl_api_bridge_flags_reply_t * mp)
1604 vat_main_t *vam = &vat_main;
1605 i32 retval = ntohl (mp->retval);
1606 if (vam->async_mode)
1608 vam->async_errors += (retval < 0);
1612 vam->retval = retval;
1613 vam->result_ready = 1;
1617 static void vl_api_bridge_flags_reply_t_handler_json
1618 (vl_api_bridge_flags_reply_t * mp)
1620 vat_main_t *vam = &vat_main;
1621 vat_json_node_t node;
1623 vat_json_init_object (&node);
1624 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1625 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1626 ntohl (mp->resulting_feature_bitmap));
1628 vat_json_print (vam->ofp, &node);
1629 vat_json_free (&node);
1631 vam->retval = ntohl (mp->retval);
1632 vam->result_ready = 1;
1636 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1638 vat_main_t *vam = &vat_main;
1639 i32 retval = ntohl (mp->retval);
1640 if (vam->async_mode)
1642 vam->async_errors += (retval < 0);
1646 vam->retval = retval;
1647 vam->sw_if_index = ntohl (mp->sw_if_index);
1648 vam->result_ready = 1;
1653 static void vl_api_tap_create_v2_reply_t_handler_json
1654 (vl_api_tap_create_v2_reply_t * mp)
1656 vat_main_t *vam = &vat_main;
1657 vat_json_node_t node;
1659 vat_json_init_object (&node);
1660 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1661 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1663 vat_json_print (vam->ofp, &node);
1664 vat_json_free (&node);
1666 vam->retval = ntohl (mp->retval);
1667 vam->result_ready = 1;
1672 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1674 vat_main_t *vam = &vat_main;
1675 i32 retval = ntohl (mp->retval);
1676 if (vam->async_mode)
1678 vam->async_errors += (retval < 0);
1682 vam->retval = retval;
1683 vam->result_ready = 1;
1687 static void vl_api_tap_delete_v2_reply_t_handler_json
1688 (vl_api_tap_delete_v2_reply_t * mp)
1690 vat_main_t *vam = &vat_main;
1691 vat_json_node_t node;
1693 vat_json_init_object (&node);
1694 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1696 vat_json_print (vam->ofp, &node);
1697 vat_json_free (&node);
1699 vam->retval = ntohl (mp->retval);
1700 vam->result_ready = 1;
1704 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1707 vat_main_t *vam = &vat_main;
1708 i32 retval = ntohl (mp->retval);
1709 if (vam->async_mode)
1711 vam->async_errors += (retval < 0);
1715 vam->retval = retval;
1716 vam->sw_if_index = ntohl (mp->sw_if_index);
1717 vam->result_ready = 1;
1721 static void vl_api_virtio_pci_create_reply_t_handler_json
1722 (vl_api_virtio_pci_create_reply_t * mp)
1724 vat_main_t *vam = &vat_main;
1725 vat_json_node_t node;
1727 vat_json_init_object (&node);
1728 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1729 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1731 vat_json_print (vam->ofp, &node);
1732 vat_json_free (&node);
1734 vam->retval = ntohl (mp->retval);
1735 vam->result_ready = 1;
1740 vl_api_virtio_pci_create_v2_reply_t_handler
1741 (vl_api_virtio_pci_create_v2_reply_t * mp)
1743 vat_main_t *vam = &vat_main;
1744 i32 retval = ntohl (mp->retval);
1745 if (vam->async_mode)
1747 vam->async_errors += (retval < 0);
1751 vam->retval = retval;
1752 vam->sw_if_index = ntohl (mp->sw_if_index);
1753 vam->result_ready = 1;
1757 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1758 (vl_api_virtio_pci_create_v2_reply_t * mp)
1760 vat_main_t *vam = &vat_main;
1761 vat_json_node_t node;
1763 vat_json_init_object (&node);
1764 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1765 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1767 vat_json_print (vam->ofp, &node);
1768 vat_json_free (&node);
1770 vam->retval = ntohl (mp->retval);
1771 vam->result_ready = 1;
1775 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1778 vat_main_t *vam = &vat_main;
1779 i32 retval = ntohl (mp->retval);
1780 if (vam->async_mode)
1782 vam->async_errors += (retval < 0);
1786 vam->retval = retval;
1787 vam->result_ready = 1;
1791 static void vl_api_virtio_pci_delete_reply_t_handler_json
1792 (vl_api_virtio_pci_delete_reply_t * mp)
1794 vat_main_t *vam = &vat_main;
1795 vat_json_node_t node;
1797 vat_json_init_object (&node);
1798 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1800 vat_json_print (vam->ofp, &node);
1801 vat_json_free (&node);
1803 vam->retval = ntohl (mp->retval);
1804 vam->result_ready = 1;
1808 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1810 vat_main_t *vam = &vat_main;
1811 i32 retval = ntohl (mp->retval);
1813 if (vam->async_mode)
1815 vam->async_errors += (retval < 0);
1819 vam->retval = retval;
1820 vam->sw_if_index = ntohl (mp->sw_if_index);
1821 vam->result_ready = 1;
1825 static void vl_api_bond_create_reply_t_handler_json
1826 (vl_api_bond_create_reply_t * mp)
1828 vat_main_t *vam = &vat_main;
1829 vat_json_node_t node;
1831 vat_json_init_object (&node);
1832 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1833 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1835 vat_json_print (vam->ofp, &node);
1836 vat_json_free (&node);
1838 vam->retval = ntohl (mp->retval);
1839 vam->result_ready = 1;
1843 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1845 vat_main_t *vam = &vat_main;
1846 i32 retval = ntohl (mp->retval);
1848 if (vam->async_mode)
1850 vam->async_errors += (retval < 0);
1854 vam->retval = retval;
1855 vam->sw_if_index = ntohl (mp->sw_if_index);
1856 vam->result_ready = 1;
1860 static void vl_api_bond_create2_reply_t_handler_json
1861 (vl_api_bond_create2_reply_t * mp)
1863 vat_main_t *vam = &vat_main;
1864 vat_json_node_t node;
1866 vat_json_init_object (&node);
1867 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1868 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1870 vat_json_print (vam->ofp, &node);
1871 vat_json_free (&node);
1873 vam->retval = ntohl (mp->retval);
1874 vam->result_ready = 1;
1878 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1880 vat_main_t *vam = &vat_main;
1881 i32 retval = ntohl (mp->retval);
1883 if (vam->async_mode)
1885 vam->async_errors += (retval < 0);
1889 vam->retval = retval;
1890 vam->result_ready = 1;
1894 static void vl_api_bond_delete_reply_t_handler_json
1895 (vl_api_bond_delete_reply_t * mp)
1897 vat_main_t *vam = &vat_main;
1898 vat_json_node_t node;
1900 vat_json_init_object (&node);
1901 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1903 vat_json_print (vam->ofp, &node);
1904 vat_json_free (&node);
1906 vam->retval = ntohl (mp->retval);
1907 vam->result_ready = 1;
1911 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
1913 vat_main_t *vam = &vat_main;
1914 i32 retval = ntohl (mp->retval);
1916 if (vam->async_mode)
1918 vam->async_errors += (retval < 0);
1922 vam->retval = retval;
1923 vam->result_ready = 1;
1927 static void vl_api_bond_add_member_reply_t_handler_json
1928 (vl_api_bond_add_member_reply_t * mp)
1930 vat_main_t *vam = &vat_main;
1931 vat_json_node_t node;
1933 vat_json_init_object (&node);
1934 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1936 vat_json_print (vam->ofp, &node);
1937 vat_json_free (&node);
1939 vam->retval = ntohl (mp->retval);
1940 vam->result_ready = 1;
1944 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
1947 vat_main_t *vam = &vat_main;
1948 i32 retval = ntohl (mp->retval);
1950 if (vam->async_mode)
1952 vam->async_errors += (retval < 0);
1956 vam->retval = retval;
1957 vam->result_ready = 1;
1961 static void vl_api_bond_detach_member_reply_t_handler_json
1962 (vl_api_bond_detach_member_reply_t * mp)
1964 vat_main_t *vam = &vat_main;
1965 vat_json_node_t node;
1967 vat_json_init_object (&node);
1968 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1970 vat_json_print (vam->ofp, &node);
1971 vat_json_free (&node);
1973 vam->retval = ntohl (mp->retval);
1974 vam->result_ready = 1;
1978 api_sw_interface_set_bond_weight (vat_main_t * vam)
1980 unformat_input_t *i = vam->input;
1981 vl_api_sw_interface_set_bond_weight_t *mp;
1982 u32 sw_if_index = ~0;
1984 u8 weight_enter = 0;
1987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1989 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1991 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1993 else if (unformat (i, "weight %u", &weight))
1999 if (sw_if_index == ~0)
2001 errmsg ("missing interface name or sw_if_index");
2004 if (weight_enter == 0)
2006 errmsg ("missing valid weight");
2010 /* Construct the API message */
2011 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2012 mp->sw_if_index = ntohl (sw_if_index);
2013 mp->weight = ntohl (weight);
2020 static void vl_api_sw_bond_interface_details_t_handler
2021 (vl_api_sw_bond_interface_details_t * mp)
2023 vat_main_t *vam = &vat_main;
2026 "%-16s %-12d %-12U %-13U %-14u %-14u",
2027 mp->interface_name, ntohl (mp->sw_if_index),
2028 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2029 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2032 static void vl_api_sw_bond_interface_details_t_handler_json
2033 (vl_api_sw_bond_interface_details_t * mp)
2035 vat_main_t *vam = &vat_main;
2036 vat_json_node_t *node = NULL;
2038 if (VAT_JSON_ARRAY != vam->json_tree.type)
2040 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2041 vat_json_init_array (&vam->json_tree);
2043 node = vat_json_array_add (&vam->json_tree);
2045 vat_json_init_object (node);
2046 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2047 vat_json_object_add_string_copy (node, "interface_name",
2048 mp->interface_name);
2049 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2050 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2051 vat_json_object_add_uint (node, "active_members",
2052 ntohl (mp->active_members));
2053 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2057 api_sw_bond_interface_dump (vat_main_t * vam)
2059 unformat_input_t *i = vam->input;
2060 vl_api_sw_bond_interface_dump_t *mp;
2061 vl_api_control_ping_t *mp_ping;
2063 u32 sw_if_index = ~0;
2065 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2067 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2069 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2076 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2077 "interface name", "sw_if_index", "mode", "load balance",
2078 "active members", "members");
2080 /* Get list of bond interfaces */
2081 M (SW_BOND_INTERFACE_DUMP, mp);
2082 mp->sw_if_index = ntohl (sw_if_index);
2085 /* Use a control ping for synchronization */
2086 MPING (CONTROL_PING, mp_ping);
2093 static void vl_api_sw_member_interface_details_t_handler
2094 (vl_api_sw_member_interface_details_t * mp)
2096 vat_main_t *vam = &vat_main;
2099 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2100 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2101 ntohl (mp->weight), mp->is_local_numa);
2104 static void vl_api_sw_member_interface_details_t_handler_json
2105 (vl_api_sw_member_interface_details_t * mp)
2107 vat_main_t *vam = &vat_main;
2108 vat_json_node_t *node = NULL;
2110 if (VAT_JSON_ARRAY != vam->json_tree.type)
2112 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2113 vat_json_init_array (&vam->json_tree);
2115 node = vat_json_array_add (&vam->json_tree);
2117 vat_json_init_object (node);
2118 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2119 vat_json_object_add_string_copy (node, "interface_name",
2120 mp->interface_name);
2121 vat_json_object_add_uint (node, "passive", mp->is_passive);
2122 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2123 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2124 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2128 api_sw_member_interface_dump (vat_main_t * vam)
2130 unformat_input_t *i = vam->input;
2131 vl_api_sw_member_interface_dump_t *mp;
2132 vl_api_control_ping_t *mp_ping;
2133 u32 sw_if_index = ~0;
2134 u8 sw_if_index_set = 0;
2137 /* Parse args required to build the message */
2138 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2140 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2141 sw_if_index_set = 1;
2142 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2143 sw_if_index_set = 1;
2148 if (sw_if_index_set == 0)
2150 errmsg ("missing vpp interface name. ");
2155 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2156 "member interface name", "sw_if_index", "passive", "long_timeout",
2157 "weight", "local numa");
2159 /* Get list of bond interfaces */
2160 M (SW_MEMBER_INTERFACE_DUMP, mp);
2161 mp->sw_if_index = ntohl (sw_if_index);
2164 /* Use a control ping for synchronization */
2165 MPING (CONTROL_PING, mp_ping);
2172 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2173 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2175 vat_main_t *vam = &vat_main;
2176 i32 retval = ntohl (mp->retval);
2177 if (vam->async_mode)
2179 vam->async_errors += (retval < 0);
2183 vam->retval = retval;
2184 vam->sw_if_index = ntohl (mp->sw_if_index);
2185 vam->result_ready = 1;
2187 vam->regenerate_interface_table = 1;
2190 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2191 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2193 vat_main_t *vam = &vat_main;
2194 vat_json_node_t node;
2196 vat_json_init_object (&node);
2197 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2198 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2199 ntohl (mp->sw_if_index));
2201 vat_json_print (vam->ofp, &node);
2202 vat_json_free (&node);
2204 vam->retval = ntohl (mp->retval);
2205 vam->result_ready = 1;
2208 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2209 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2211 vat_main_t *vam = &vat_main;
2212 i32 retval = ntohl (mp->retval);
2213 if (vam->async_mode)
2215 vam->async_errors += (retval < 0);
2219 vam->retval = retval;
2220 vam->sw_if_index = ntohl (mp->sw_if_index);
2221 vam->result_ready = 1;
2223 vam->regenerate_interface_table = 1;
2226 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2227 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2229 vat_main_t *vam = &vat_main;
2230 vat_json_node_t node;
2232 vat_json_init_object (&node);
2233 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2234 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2236 vat_json_print (vam->ofp, &node);
2237 vat_json_free (&node);
2239 vam->retval = ntohl (mp->retval);
2240 vam->result_ready = 1;
2243 static void vl_api_vxlan_offload_rx_reply_t_handler
2244 (vl_api_vxlan_offload_rx_reply_t * mp)
2246 vat_main_t *vam = &vat_main;
2247 i32 retval = ntohl (mp->retval);
2248 if (vam->async_mode)
2250 vam->async_errors += (retval < 0);
2254 vam->retval = retval;
2255 vam->result_ready = 1;
2259 static void vl_api_vxlan_offload_rx_reply_t_handler_json
2260 (vl_api_vxlan_offload_rx_reply_t * mp)
2262 vat_main_t *vam = &vat_main;
2263 vat_json_node_t node;
2265 vat_json_init_object (&node);
2266 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
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_vxlan_gpe_add_del_tunnel_reply_t_handler
2276 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2278 vat_main_t *vam = &vat_main;
2279 i32 retval = ntohl (mp->retval);
2280 if (vam->async_mode)
2282 vam->async_errors += (retval < 0);
2286 vam->retval = retval;
2287 vam->sw_if_index = ntohl (mp->sw_if_index);
2288 vam->result_ready = 1;
2290 vam->regenerate_interface_table = 1;
2293 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2294 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2296 vat_main_t *vam = &vat_main;
2297 vat_json_node_t node;
2299 vat_json_init_object (&node);
2300 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2301 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2303 vat_json_print (vam->ofp, &node);
2304 vat_json_free (&node);
2306 vam->retval = ntohl (mp->retval);
2307 vam->result_ready = 1;
2310 static void vl_api_create_vhost_user_if_reply_t_handler
2311 (vl_api_create_vhost_user_if_reply_t * mp)
2313 vat_main_t *vam = &vat_main;
2314 i32 retval = ntohl (mp->retval);
2315 if (vam->async_mode)
2317 vam->async_errors += (retval < 0);
2321 vam->retval = retval;
2322 vam->sw_if_index = ntohl (mp->sw_if_index);
2323 vam->result_ready = 1;
2325 vam->regenerate_interface_table = 1;
2328 static void vl_api_create_vhost_user_if_reply_t_handler_json
2329 (vl_api_create_vhost_user_if_reply_t * mp)
2331 vat_main_t *vam = &vat_main;
2332 vat_json_node_t node;
2334 vat_json_init_object (&node);
2335 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2336 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2338 vat_json_print (vam->ofp, &node);
2339 vat_json_free (&node);
2341 vam->retval = ntohl (mp->retval);
2342 vam->result_ready = 1;
2345 static void vl_api_create_vhost_user_if_v2_reply_t_handler
2346 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2348 vat_main_t *vam = &vat_main;
2349 i32 retval = ntohl (mp->retval);
2350 if (vam->async_mode)
2352 vam->async_errors += (retval < 0);
2356 vam->retval = retval;
2357 vam->sw_if_index = ntohl (mp->sw_if_index);
2358 vam->result_ready = 1;
2360 vam->regenerate_interface_table = 1;
2363 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2364 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2366 vat_main_t *vam = &vat_main;
2367 vat_json_node_t node;
2369 vat_json_init_object (&node);
2370 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2371 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2373 vat_json_print (vam->ofp, &node);
2374 vat_json_free (&node);
2376 vam->retval = ntohl (mp->retval);
2377 vam->result_ready = 1;
2380 static void vl_api_ip_address_details_t_handler
2381 (vl_api_ip_address_details_t * mp)
2383 vat_main_t *vam = &vat_main;
2384 static ip_address_details_t empty_ip_address_details = { {0} };
2385 ip_address_details_t *address = NULL;
2386 ip_details_t *current_ip_details = NULL;
2387 ip_details_t *details = NULL;
2389 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2391 if (!details || vam->current_sw_if_index >= vec_len (details)
2392 || !details[vam->current_sw_if_index].present)
2394 errmsg ("ip address details arrived but not stored");
2395 errmsg ("ip_dump should be called first");
2399 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2401 #define addresses (current_ip_details->addr)
2403 vec_validate_init_empty (addresses, vec_len (addresses),
2404 empty_ip_address_details);
2406 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2408 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2409 address->prefix_length = mp->prefix.len;
2413 static void vl_api_ip_address_details_t_handler_json
2414 (vl_api_ip_address_details_t * mp)
2416 vat_main_t *vam = &vat_main;
2417 vat_json_node_t *node = NULL;
2419 if (VAT_JSON_ARRAY != vam->json_tree.type)
2421 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2422 vat_json_init_array (&vam->json_tree);
2424 node = vat_json_array_add (&vam->json_tree);
2426 vat_json_init_object (node);
2427 vat_json_object_add_prefix (node, &mp->prefix);
2431 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2433 vat_main_t *vam = &vat_main;
2434 static ip_details_t empty_ip_details = { 0 };
2435 ip_details_t *ip = NULL;
2436 u32 sw_if_index = ~0;
2438 sw_if_index = ntohl (mp->sw_if_index);
2440 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2441 sw_if_index, empty_ip_details);
2443 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2450 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2452 vat_main_t *vam = &vat_main;
2454 if (VAT_JSON_ARRAY != vam->json_tree.type)
2456 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2457 vat_json_init_array (&vam->json_tree);
2459 vat_json_array_add_uint (&vam->json_tree,
2460 clib_net_to_host_u32 (mp->sw_if_index));
2463 static void vl_api_get_first_msg_id_reply_t_handler
2464 (vl_api_get_first_msg_id_reply_t * mp)
2466 vat_main_t *vam = &vat_main;
2467 i32 retval = ntohl (mp->retval);
2469 if (vam->async_mode)
2471 vam->async_errors += (retval < 0);
2475 vam->retval = retval;
2476 vam->result_ready = 1;
2480 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2484 static void vl_api_get_first_msg_id_reply_t_handler_json
2485 (vl_api_get_first_msg_id_reply_t * mp)
2487 vat_main_t *vam = &vat_main;
2488 vat_json_node_t node;
2490 vat_json_init_object (&node);
2491 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2492 vat_json_object_add_uint (&node, "first_msg_id",
2493 (uint) ntohs (mp->first_msg_id));
2495 vat_json_print (vam->ofp, &node);
2496 vat_json_free (&node);
2498 vam->retval = ntohl (mp->retval);
2499 vam->result_ready = 1;
2502 static void vl_api_get_node_graph_reply_t_handler
2503 (vl_api_get_node_graph_reply_t * mp)
2505 vat_main_t *vam = &vat_main;
2506 i32 retval = ntohl (mp->retval);
2507 u8 *pvt_copy, *reply;
2512 if (vam->async_mode)
2514 vam->async_errors += (retval < 0);
2518 vam->retval = retval;
2519 vam->result_ready = 1;
2522 /* "Should never happen..." */
2526 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2527 pvt_copy = vec_dup (reply);
2529 /* Toss the shared-memory original... */
2530 oldheap = vl_msg_push_heap ();
2534 vl_msg_pop_heap (oldheap);
2536 if (vam->graph_nodes)
2538 hash_free (vam->graph_node_index_by_name);
2540 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2542 node = vam->graph_nodes[0][i];
2543 vec_free (node->name);
2544 vec_free (node->next_nodes);
2547 vec_free (vam->graph_nodes[0]);
2548 vec_free (vam->graph_nodes);
2551 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2552 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2553 vec_free (pvt_copy);
2555 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2557 node = vam->graph_nodes[0][i];
2558 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2562 static void vl_api_get_node_graph_reply_t_handler_json
2563 (vl_api_get_node_graph_reply_t * mp)
2565 vat_main_t *vam = &vat_main;
2567 vat_json_node_t node;
2570 /* $$$$ make this real? */
2571 vat_json_init_object (&node);
2572 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2573 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2575 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2577 /* Toss the shared-memory original... */
2578 oldheap = vl_msg_push_heap ();
2582 vl_msg_pop_heap (oldheap);
2584 vat_json_print (vam->ofp, &node);
2585 vat_json_free (&node);
2587 vam->retval = ntohl (mp->retval);
2588 vam->result_ready = 1;
2592 format_policer_type (u8 * s, va_list * va)
2594 u32 i = va_arg (*va, u32);
2596 if (i == QOS_POLICER_TYPE_1R2C)
2597 s = format (s, "1r2c");
2598 else if (i == QOS_POLICER_TYPE_1R3C_RFC_2697)
2599 s = format (s, "1r3c");
2600 else if (i == QOS_POLICER_TYPE_2R3C_RFC_2698)
2601 s = format (s, "2r3c-2698");
2602 else if (i == QOS_POLICER_TYPE_2R3C_RFC_4115)
2603 s = format (s, "2r3c-4115");
2604 else if (i == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2605 s = format (s, "2r3c-mef5cf1");
2607 s = format (s, "ILLEGAL");
2612 format_policer_rate_type (u8 * s, va_list * va)
2614 u32 i = va_arg (*va, u32);
2616 if (i == QOS_RATE_KBPS)
2617 s = format (s, "kbps");
2618 else if (i == QOS_RATE_PPS)
2619 s = format (s, "pps");
2621 s = format (s, "ILLEGAL");
2626 format_policer_round_type (u8 * s, va_list * va)
2628 u32 i = va_arg (*va, u32);
2630 if (i == QOS_ROUND_TO_CLOSEST)
2631 s = format (s, "closest");
2632 else if (i == QOS_ROUND_TO_UP)
2633 s = format (s, "up");
2634 else if (i == QOS_ROUND_TO_DOWN)
2635 s = format (s, "down");
2637 s = format (s, "ILLEGAL");
2642 format_policer_action_type (u8 * s, va_list * va)
2644 u32 i = va_arg (*va, u32);
2646 if (i == QOS_ACTION_DROP)
2647 s = format (s, "drop");
2648 else if (i == QOS_ACTION_TRANSMIT)
2649 s = format (s, "transmit");
2650 else if (i == QOS_ACTION_MARK_AND_TRANSMIT)
2651 s = format (s, "mark-and-transmit");
2653 s = format (s, "ILLEGAL");
2658 format_dscp (u8 * s, va_list * va)
2660 u32 i = va_arg (*va, u32);
2667 return (format (s, "%s", #f));
2671 s = format (s, "%s", t);
2672 return (format (s, "ILLEGAL"));
2676 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2678 vat_main_t *vam = &vat_main;
2679 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2681 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2682 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2684 conform_dscp_str = format (0, "");
2686 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2687 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2689 exceed_dscp_str = format (0, "");
2691 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2692 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2694 violate_dscp_str = format (0, "");
2696 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2697 "rate type %U, round type %U, %s rate, %s color-aware, "
2698 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2699 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2700 "conform action %U%s, exceed action %U%s, violate action %U%s",
2702 format_policer_type, mp->type,
2705 clib_net_to_host_u64 (mp->cb),
2706 clib_net_to_host_u64 (mp->eb),
2707 format_policer_rate_type, mp->rate_type,
2708 format_policer_round_type, mp->round_type,
2709 mp->single_rate ? "single" : "dual",
2710 mp->color_aware ? "is" : "not",
2711 ntohl (mp->cir_tokens_per_period),
2712 ntohl (mp->pir_tokens_per_period),
2714 ntohl (mp->current_limit),
2715 ntohl (mp->current_bucket),
2716 ntohl (mp->extended_limit),
2717 ntohl (mp->extended_bucket),
2718 clib_net_to_host_u64 (mp->last_update_time),
2719 format_policer_action_type, mp->conform_action.type,
2721 format_policer_action_type, mp->exceed_action.type,
2723 format_policer_action_type, mp->violate_action.type,
2726 vec_free (conform_dscp_str);
2727 vec_free (exceed_dscp_str);
2728 vec_free (violate_dscp_str);
2731 static void vl_api_policer_details_t_handler_json
2732 (vl_api_policer_details_t * mp)
2734 vat_main_t *vam = &vat_main;
2735 vat_json_node_t *node;
2736 u8 *rate_type_str, *round_type_str, *type_str;
2737 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2739 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2741 format (0, "%U", format_policer_round_type, mp->round_type);
2742 type_str = format (0, "%U", format_policer_type, mp->type);
2743 conform_action_str = format (0, "%U", format_policer_action_type,
2744 mp->conform_action.type);
2745 exceed_action_str = format (0, "%U", format_policer_action_type,
2746 mp->exceed_action.type);
2747 violate_action_str = format (0, "%U", format_policer_action_type,
2748 mp->violate_action.type);
2750 if (VAT_JSON_ARRAY != vam->json_tree.type)
2752 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2753 vat_json_init_array (&vam->json_tree);
2755 node = vat_json_array_add (&vam->json_tree);
2757 vat_json_init_object (node);
2758 vat_json_object_add_string_copy (node, "name", mp->name);
2759 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2760 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2761 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2762 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2763 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2764 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2765 vat_json_object_add_string_copy (node, "type", type_str);
2766 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2767 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2768 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2769 vat_json_object_add_uint (node, "cir_tokens_per_period",
2770 ntohl (mp->cir_tokens_per_period));
2771 vat_json_object_add_uint (node, "eir_tokens_per_period",
2772 ntohl (mp->pir_tokens_per_period));
2773 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2774 vat_json_object_add_uint (node, "current_bucket",
2775 ntohl (mp->current_bucket));
2776 vat_json_object_add_uint (node, "extended_limit",
2777 ntohl (mp->extended_limit));
2778 vat_json_object_add_uint (node, "extended_bucket",
2779 ntohl (mp->extended_bucket));
2780 vat_json_object_add_uint (node, "last_update_time",
2781 ntohl (mp->last_update_time));
2782 vat_json_object_add_string_copy (node, "conform_action",
2783 conform_action_str);
2784 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2786 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2787 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2788 vec_free (dscp_str);
2790 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2791 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2793 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2794 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2795 vec_free (dscp_str);
2797 vat_json_object_add_string_copy (node, "violate_action",
2798 violate_action_str);
2799 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2801 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2802 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2803 vec_free (dscp_str);
2806 vec_free (rate_type_str);
2807 vec_free (round_type_str);
2808 vec_free (type_str);
2809 vec_free (conform_action_str);
2810 vec_free (exceed_action_str);
2811 vec_free (violate_action_str);
2814 static void vl_api_policer_add_del_reply_t_handler
2815 (vl_api_policer_add_del_reply_t * mp)
2817 vat_main_t *vam = &vat_main;
2818 i32 retval = ntohl (mp->retval);
2819 if (vam->async_mode)
2821 vam->async_errors += (retval < 0);
2825 vam->retval = retval;
2826 vam->result_ready = 1;
2827 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2829 * Note: this is just barely thread-safe, depends on
2830 * the main thread spinning waiting for an answer...
2832 errmsg ("policer index %d", ntohl (mp->policer_index));
2836 static void vl_api_policer_add_del_reply_t_handler_json
2837 (vl_api_policer_add_del_reply_t * mp)
2839 vat_main_t *vam = &vat_main;
2840 vat_json_node_t node;
2842 vat_json_init_object (&node);
2843 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2844 vat_json_object_add_uint (&node, "policer_index",
2845 ntohl (mp->policer_index));
2847 vat_json_print (vam->ofp, &node);
2848 vat_json_free (&node);
2850 vam->retval = ntohl (mp->retval);
2851 vam->result_ready = 1;
2854 /* Format hex dump. */
2856 format_hex_bytes (u8 * s, va_list * va)
2858 u8 *bytes = va_arg (*va, u8 *);
2859 int n_bytes = va_arg (*va, int);
2862 /* Print short or long form depending on byte count. */
2863 uword short_form = n_bytes <= 32;
2864 u32 indent = format_get_indent (s);
2869 for (i = 0; i < n_bytes; i++)
2871 if (!short_form && (i % 32) == 0)
2872 s = format (s, "%08x: ", i);
2873 s = format (s, "%02x", bytes[i]);
2874 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2875 s = format (s, "\n%U", format_white_space, indent);
2881 static void vl_api_pg_create_interface_reply_t_handler
2882 (vl_api_pg_create_interface_reply_t * mp)
2884 vat_main_t *vam = &vat_main;
2886 vam->retval = ntohl (mp->retval);
2887 vam->result_ready = 1;
2890 static void vl_api_pg_create_interface_reply_t_handler_json
2891 (vl_api_pg_create_interface_reply_t * mp)
2893 vat_main_t *vam = &vat_main;
2894 vat_json_node_t node;
2896 i32 retval = ntohl (mp->retval);
2899 vat_json_init_object (&node);
2901 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
2903 vat_json_print (vam->ofp, &node);
2904 vat_json_free (&node);
2906 vam->retval = ntohl (mp->retval);
2907 vam->result_ready = 1;
2911 * Generate boilerplate reply handlers, which
2912 * dig the return value out of the xxx_reply_t API message,
2913 * stick it into vam->retval, and set vam->result_ready
2915 * Could also do this by pointing N message decode slots at
2916 * a single function, but that could break in subtle ways.
2919 #define foreach_standard_reply_retval_handler \
2920 _(sw_interface_set_flags_reply) \
2921 _(sw_interface_add_del_address_reply) \
2922 _(sw_interface_set_rx_mode_reply) \
2923 _(sw_interface_set_rx_placement_reply) \
2924 _(sw_interface_set_table_reply) \
2925 _(sw_interface_set_mpls_enable_reply) \
2926 _(sw_interface_set_vpath_reply) \
2927 _(sw_interface_set_vxlan_bypass_reply) \
2928 _(sw_interface_set_vxlan_gpe_bypass_reply) \
2929 _(sw_interface_set_l2_bridge_reply) \
2930 _(sw_interface_set_bond_weight_reply) \
2931 _(bridge_domain_add_del_reply) \
2932 _(sw_interface_set_l2_xconnect_reply) \
2933 _(l2fib_add_del_reply) \
2934 _(l2fib_flush_int_reply) \
2935 _(l2fib_flush_bd_reply) \
2936 _(ip_route_add_del_reply) \
2937 _(ip_table_add_del_reply) \
2938 _(ip_table_replace_begin_reply) \
2939 _(ip_table_flush_reply) \
2940 _(ip_table_replace_end_reply) \
2941 _(ip_mroute_add_del_reply) \
2942 _(mpls_route_add_del_reply) \
2943 _(mpls_table_add_del_reply) \
2944 _(mpls_ip_bind_unbind_reply) \
2945 _(sw_interface_set_unnumbered_reply) \
2946 _(set_ip_flow_hash_reply) \
2947 _(sw_interface_ip6_enable_disable_reply) \
2948 _(l2_patch_add_del_reply) \
2949 _(sr_mpls_policy_add_reply) \
2950 _(sr_mpls_policy_mod_reply) \
2951 _(sr_mpls_policy_del_reply) \
2952 _(sr_policy_add_reply) \
2953 _(sr_policy_mod_reply) \
2954 _(sr_policy_del_reply) \
2955 _(sr_localsid_add_del_reply) \
2956 _(sr_steering_add_del_reply) \
2957 _(l2_fib_clear_table_reply) \
2958 _(l2_interface_efp_filter_reply) \
2959 _(l2_interface_vlan_tag_rewrite_reply) \
2960 _(modify_vhost_user_if_reply) \
2961 _(modify_vhost_user_if_v2_reply) \
2962 _(delete_vhost_user_if_reply) \
2963 _(want_l2_macs_events_reply) \
2964 _(ipsec_spd_add_del_reply) \
2965 _(ipsec_interface_add_del_spd_reply) \
2966 _(ipsec_spd_entry_add_del_reply) \
2967 _(ipsec_sad_entry_add_del_reply) \
2968 _(delete_loopback_reply) \
2969 _(bd_ip_mac_add_del_reply) \
2970 _(bd_ip_mac_flush_reply) \
2971 _(want_interface_events_reply) \
2972 _(sw_interface_clear_stats_reply) \
2973 _(ioam_enable_reply) \
2974 _(ioam_disable_reply) \
2975 _(af_packet_delete_reply) \
2976 _(set_ipfix_exporter_reply) \
2977 _(set_ipfix_classify_stream_reply) \
2978 _(ipfix_classify_table_add_del_reply) \
2979 _(sw_interface_span_enable_disable_reply) \
2980 _(pg_capture_reply) \
2981 _(pg_enable_disable_reply) \
2982 _(pg_interface_enable_disable_coalesce_reply) \
2983 _(ip_source_and_port_range_check_add_del_reply) \
2984 _(ip_source_and_port_range_check_interface_add_del_reply)\
2985 _(delete_subif_reply) \
2986 _(l2_interface_pbb_tag_rewrite_reply) \
2988 _(feature_enable_disable_reply) \
2989 _(feature_gso_enable_disable_reply) \
2990 _(sw_interface_tag_add_del_reply) \
2991 _(sw_interface_add_del_mac_address_reply) \
2992 _(hw_interface_set_mtu_reply) \
2993 _(p2p_ethernet_add_reply) \
2994 _(p2p_ethernet_del_reply) \
2995 _(tcp_configure_src_addresses_reply) \
2996 _(session_rule_add_del_reply) \
2997 _(ip_container_proxy_add_del_reply) \
2998 _(qos_record_enable_disable_reply) \
3002 static void vl_api_##n##_t_handler \
3003 (vl_api_##n##_t * mp) \
3005 vat_main_t * vam = &vat_main; \
3006 i32 retval = ntohl(mp->retval); \
3007 if (vam->async_mode) { \
3008 vam->async_errors += (retval < 0); \
3010 vam->retval = retval; \
3011 vam->result_ready = 1; \
3014 foreach_standard_reply_retval_handler;
3018 static void vl_api_##n##_t_handler_json \
3019 (vl_api_##n##_t * mp) \
3021 vat_main_t * vam = &vat_main; \
3022 vat_json_node_t node; \
3023 vat_json_init_object(&node); \
3024 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3025 vat_json_print(vam->ofp, &node); \
3026 vam->retval = ntohl(mp->retval); \
3027 vam->result_ready = 1; \
3029 foreach_standard_reply_retval_handler;
3033 * Table of message reply handlers, must include boilerplate handlers
3037 #define foreach_vpe_api_reply_msg \
3038 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3039 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3040 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3041 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3042 _(CONTROL_PING_REPLY, control_ping_reply) \
3043 _(CLI_REPLY, cli_reply) \
3044 _(CLI_INBAND_REPLY, cli_inband_reply) \
3045 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3046 sw_interface_add_del_address_reply) \
3047 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3048 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3049 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3050 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3051 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3052 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3053 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3054 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3055 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3056 sw_interface_set_l2_xconnect_reply) \
3057 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3058 sw_interface_set_l2_bridge_reply) \
3059 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3060 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3061 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3062 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3063 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3064 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3065 _(L2_FLAGS_REPLY, l2_flags_reply) \
3066 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3067 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3068 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3069 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3070 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3071 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3072 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3073 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3074 _(BOND_CREATE_REPLY, bond_create_reply) \
3075 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3076 _(BOND_DELETE_REPLY, bond_delete_reply) \
3077 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3078 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3079 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3080 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3081 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3082 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3083 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3084 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3085 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3086 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3087 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3088 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3089 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3090 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3091 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3092 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3093 sw_interface_set_unnumbered_reply) \
3094 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3095 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3096 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3097 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3098 sw_interface_ip6_enable_disable_reply) \
3099 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3100 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3101 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3102 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3103 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3104 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3105 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3106 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3107 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3108 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3109 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3110 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3111 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3112 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3113 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3114 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3115 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3116 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3117 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3118 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3119 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
3120 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
3121 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3122 _(SHOW_VERSION_REPLY, show_version_reply) \
3123 _(SHOW_THREADS_REPLY, show_threads_reply) \
3124 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3125 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3126 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3127 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3128 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3129 _(L2_MACS_EVENT, l2_macs_event) \
3130 _(IP_ADDRESS_DETAILS, ip_address_details) \
3131 _(IP_DETAILS, ip_details) \
3132 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3133 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3134 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3135 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3136 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3137 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3138 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3139 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3140 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3141 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3142 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3143 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3144 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3145 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3146 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3147 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3148 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3149 _(AF_PACKET_DETAILS, af_packet_details) \
3150 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3151 _(POLICER_DETAILS, policer_details) \
3152 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3153 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3154 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3155 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3156 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3157 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3158 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3159 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3160 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3161 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3162 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3163 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3164 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3165 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3166 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3167 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3168 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3169 ip_source_and_port_range_check_add_del_reply) \
3170 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3171 ip_source_and_port_range_check_interface_add_del_reply) \
3172 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3173 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3174 _(SET_PUNT_REPLY, set_punt_reply) \
3175 _(IP_TABLE_DETAILS, ip_table_details) \
3176 _(IP_ROUTE_DETAILS, ip_route_details) \
3177 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3178 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3179 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3180 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3181 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3182 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3183 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3184 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3185 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3186 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3187 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3188 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3189 _(SESSION_RULES_DETAILS, session_rules_details) \
3190 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3191 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3192 _(FLOW_ADD_REPLY, flow_add_reply) \
3194 #define foreach_standalone_reply_msg \
3195 _(SW_INTERFACE_EVENT, sw_interface_event)
3203 #define STR_VTR_OP_CASE(op) \
3204 case L2_VTR_ ## op: \
3208 str_vtr_op (u32 vtr_op)
3212 STR_VTR_OP_CASE (DISABLED);
3213 STR_VTR_OP_CASE (PUSH_1);
3214 STR_VTR_OP_CASE (PUSH_2);
3215 STR_VTR_OP_CASE (POP_1);
3216 STR_VTR_OP_CASE (POP_2);
3217 STR_VTR_OP_CASE (TRANSLATE_1_1);
3218 STR_VTR_OP_CASE (TRANSLATE_1_2);
3219 STR_VTR_OP_CASE (TRANSLATE_2_1);
3220 STR_VTR_OP_CASE (TRANSLATE_2_2);
3227 dump_sub_interface_table (vat_main_t * vam)
3229 const sw_interface_subif_t *sub = NULL;
3231 if (vam->json_output)
3234 ("JSON output supported only for VPE API calls and dump_stats_table");
3239 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3240 "Interface", "sw_if_index",
3241 "sub id", "dot1ad", "tags", "outer id",
3242 "inner id", "exact", "default", "outer any", "inner any");
3244 vec_foreach (sub, vam->sw_if_subif_table)
3247 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3248 sub->interface_name,
3250 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3251 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3252 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3253 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3254 if (sub->vtr_op != L2_VTR_DISABLED)
3257 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3258 "tag1: %d tag2: %d ]",
3259 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3260 sub->vtr_tag1, sub->vtr_tag2);
3268 name_sort_cmp (void *a1, void *a2)
3270 name_sort_t *n1 = a1;
3271 name_sort_t *n2 = a2;
3273 return strcmp ((char *) n1->name, (char *) n2->name);
3277 dump_interface_table (vat_main_t * vam)
3280 name_sort_t *nses = 0, *ns;
3282 if (vam->json_output)
3285 ("JSON output supported only for VPE API calls and dump_stats_table");
3290 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3292 vec_add2 (nses, ns, 1);
3293 ns->name = (u8 *)(p->key);
3294 ns->value = (u32) p->value[0];
3298 vec_sort_with_function (nses, name_sort_cmp);
3300 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3301 vec_foreach (ns, nses)
3303 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3310 dump_ip_table (vat_main_t * vam, int is_ipv6)
3312 const ip_details_t *det = NULL;
3313 const ip_address_details_t *address = NULL;
3316 print (vam->ofp, "%-12s", "sw_if_index");
3318 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3325 print (vam->ofp, "%-12d", i);
3326 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3331 vec_foreach (address, det->addr)
3335 is_ipv6 ? format_ip6_address : format_ip4_address,
3336 address->ip, address->prefix_length);
3344 dump_ipv4_table (vat_main_t * vam)
3346 if (vam->json_output)
3349 ("JSON output supported only for VPE API calls and dump_stats_table");
3353 return dump_ip_table (vam, 0);
3357 dump_ipv6_table (vat_main_t * vam)
3359 if (vam->json_output)
3362 ("JSON output supported only for VPE API calls and dump_stats_table");
3366 return dump_ip_table (vam, 1);
3370 * Pass CLI buffers directly in the CLI_INBAND API message,
3371 * instead of an additional shared memory area.
3374 exec_inband (vat_main_t * vam)
3376 vl_api_cli_inband_t *mp;
3377 unformat_input_t *i = vam->input;
3380 if (vec_len (i->buffer) == 0)
3383 if (vam->exec_mode == 0 && unformat (i, "mode"))
3388 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3395 * In order for the CLI command to work, it
3396 * must be a vector ending in \n, not a C-string ending
3399 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3400 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3404 /* json responses may or may not include a useful reply... */
3405 if (vec_len (vam->cmd_reply))
3406 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3411 exec (vat_main_t * vam)
3413 return exec_inband (vam);
3417 api_create_loopback (vat_main_t * vam)
3419 unformat_input_t *i = vam->input;
3420 vl_api_create_loopback_t *mp;
3421 vl_api_create_loopback_instance_t *mp_lbi;
3424 u8 is_specified = 0;
3425 u32 user_instance = 0;
3428 clib_memset (mac_address, 0, sizeof (mac_address));
3430 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3432 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3434 if (unformat (i, "instance %d", &user_instance))
3442 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3443 mp_lbi->is_specified = is_specified;
3445 mp_lbi->user_instance = htonl (user_instance);
3447 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3452 /* Construct the API message */
3453 M (CREATE_LOOPBACK, mp);
3455 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3464 api_delete_loopback (vat_main_t * vam)
3466 unformat_input_t *i = vam->input;
3467 vl_api_delete_loopback_t *mp;
3468 u32 sw_if_index = ~0;
3471 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3473 if (unformat (i, "sw_if_index %d", &sw_if_index))
3479 if (sw_if_index == ~0)
3481 errmsg ("missing sw_if_index");
3485 /* Construct the API message */
3486 M (DELETE_LOOPBACK, mp);
3487 mp->sw_if_index = ntohl (sw_if_index);
3495 api_want_interface_events (vat_main_t * vam)
3497 unformat_input_t *i = vam->input;
3498 vl_api_want_interface_events_t *mp;
3502 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3504 if (unformat (i, "enable"))
3506 else if (unformat (i, "disable"))
3514 errmsg ("missing enable|disable");
3518 M (WANT_INTERFACE_EVENTS, mp);
3519 mp->enable_disable = enable;
3521 vam->interface_event_display = enable;
3529 /* Note: non-static, called once to set up the initial intfc table */
3531 api_sw_interface_dump (vat_main_t * vam)
3533 vl_api_sw_interface_dump_t *mp;
3534 vl_api_control_ping_t *mp_ping;
3536 name_sort_t *nses = 0, *ns;
3537 sw_interface_subif_t *sub = NULL;
3540 /* Toss the old name table */
3542 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3544 vec_add2 (nses, ns, 1);
3545 ns->name = (u8 *)(p->key);
3546 ns->value = (u32) p->value[0];
3550 hash_free (vam->sw_if_index_by_interface_name);
3552 vec_foreach (ns, nses) vec_free (ns->name);
3556 vec_foreach (sub, vam->sw_if_subif_table)
3558 vec_free (sub->interface_name);
3560 vec_free (vam->sw_if_subif_table);
3562 /* recreate the interface name hash table */
3563 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3566 * Ask for all interface names. Otherwise, the epic catalog of
3567 * name filters becomes ridiculously long, and vat ends up needing
3568 * to be taught about new interface types.
3570 M (SW_INTERFACE_DUMP, mp);
3573 /* Use a control ping for synchronization */
3574 MPING (CONTROL_PING, mp_ping);
3582 api_sw_interface_set_flags (vat_main_t * vam)
3584 unformat_input_t *i = vam->input;
3585 vl_api_sw_interface_set_flags_t *mp;
3587 u8 sw_if_index_set = 0;
3591 /* Parse args required to build the message */
3592 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3594 if (unformat (i, "admin-up"))
3596 else if (unformat (i, "admin-down"))
3599 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3600 sw_if_index_set = 1;
3601 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3602 sw_if_index_set = 1;
3607 if (sw_if_index_set == 0)
3609 errmsg ("missing interface name or sw_if_index");
3613 /* Construct the API message */
3614 M (SW_INTERFACE_SET_FLAGS, mp);
3615 mp->sw_if_index = ntohl (sw_if_index);
3616 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3621 /* Wait for a reply, return the good/bad news... */
3627 api_sw_interface_set_rx_mode (vat_main_t * vam)
3629 unformat_input_t *i = vam->input;
3630 vl_api_sw_interface_set_rx_mode_t *mp;
3632 u8 sw_if_index_set = 0;
3634 u8 queue_id_valid = 0;
3636 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3638 /* Parse args required to build the message */
3639 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3641 if (unformat (i, "queue %d", &queue_id))
3643 else if (unformat (i, "polling"))
3644 mode = VNET_HW_IF_RX_MODE_POLLING;
3645 else if (unformat (i, "interrupt"))
3646 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3647 else if (unformat (i, "adaptive"))
3648 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3650 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3651 sw_if_index_set = 1;
3652 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3653 sw_if_index_set = 1;
3658 if (sw_if_index_set == 0)
3660 errmsg ("missing interface name or sw_if_index");
3663 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3665 errmsg ("missing rx-mode");
3669 /* Construct the API message */
3670 M (SW_INTERFACE_SET_RX_MODE, mp);
3671 mp->sw_if_index = ntohl (sw_if_index);
3672 mp->mode = (vl_api_rx_mode_t) mode;
3673 mp->queue_id_valid = queue_id_valid;
3674 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3679 /* Wait for a reply, return the good/bad news... */
3685 api_sw_interface_set_rx_placement (vat_main_t * vam)
3687 unformat_input_t *i = vam->input;
3688 vl_api_sw_interface_set_rx_placement_t *mp;
3690 u8 sw_if_index_set = 0;
3693 u32 queue_id, thread_index;
3695 /* Parse args required to build the message */
3696 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3698 if (unformat (i, "queue %d", &queue_id))
3700 else if (unformat (i, "main"))
3702 else if (unformat (i, "worker %d", &thread_index))
3705 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3706 sw_if_index_set = 1;
3707 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3708 sw_if_index_set = 1;
3713 if (sw_if_index_set == 0)
3715 errmsg ("missing interface name or sw_if_index");
3721 /* Construct the API message */
3722 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3723 mp->sw_if_index = ntohl (sw_if_index);
3724 mp->worker_id = ntohl (thread_index);
3725 mp->queue_id = ntohl (queue_id);
3726 mp->is_main = is_main;
3730 /* Wait for a reply, return the good/bad news... */
3735 static void vl_api_sw_interface_rx_placement_details_t_handler
3736 (vl_api_sw_interface_rx_placement_details_t * mp)
3738 vat_main_t *vam = &vat_main;
3739 u32 worker_id = ntohl (mp->worker_id);
3742 "\n%-11d %-11s %-6d %-5d %-9s",
3743 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3744 worker_id, ntohl (mp->queue_id),
3746 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3749 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3750 (vl_api_sw_interface_rx_placement_details_t * mp)
3752 vat_main_t *vam = &vat_main;
3753 vat_json_node_t *node = NULL;
3755 if (VAT_JSON_ARRAY != vam->json_tree.type)
3757 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3758 vat_json_init_array (&vam->json_tree);
3760 node = vat_json_array_add (&vam->json_tree);
3762 vat_json_init_object (node);
3763 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3764 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3765 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3766 vat_json_object_add_uint (node, "mode", mp->mode);
3770 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3772 unformat_input_t *i = vam->input;
3773 vl_api_sw_interface_rx_placement_dump_t *mp;
3774 vl_api_control_ping_t *mp_ping;
3777 u8 sw_if_index_set = 0;
3779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3781 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3783 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3790 "\n%-11s %-11s %-6s %-5s %-4s",
3791 "sw_if_index", "main/worker", "thread", "queue", "mode");
3793 /* Dump Interface rx placement */
3794 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3796 if (sw_if_index_set)
3797 mp->sw_if_index = htonl (sw_if_index);
3799 mp->sw_if_index = ~0;
3803 /* Use a control ping for synchronization */
3804 MPING (CONTROL_PING, mp_ping);
3812 api_sw_interface_clear_stats (vat_main_t * vam)
3814 unformat_input_t *i = vam->input;
3815 vl_api_sw_interface_clear_stats_t *mp;
3817 u8 sw_if_index_set = 0;
3820 /* Parse args required to build the message */
3821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3823 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3824 sw_if_index_set = 1;
3825 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3826 sw_if_index_set = 1;
3831 /* Construct the API message */
3832 M (SW_INTERFACE_CLEAR_STATS, mp);
3834 if (sw_if_index_set == 1)
3835 mp->sw_if_index = ntohl (sw_if_index);
3837 mp->sw_if_index = ~0;
3842 /* Wait for a reply, return the good/bad news... */
3848 api_sw_interface_add_del_address (vat_main_t * vam)
3850 unformat_input_t *i = vam->input;
3851 vl_api_sw_interface_add_del_address_t *mp;
3853 u8 sw_if_index_set = 0;
3854 u8 is_add = 1, del_all = 0;
3855 u32 address_length = 0;
3856 u8 v4_address_set = 0;
3857 u8 v6_address_set = 0;
3858 ip4_address_t v4address;
3859 ip6_address_t v6address;
3862 /* Parse args required to build the message */
3863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3865 if (unformat (i, "del-all"))
3867 else if (unformat (i, "del"))
3870 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3871 sw_if_index_set = 1;
3872 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3873 sw_if_index_set = 1;
3874 else if (unformat (i, "%U/%d",
3875 unformat_ip4_address, &v4address, &address_length))
3877 else if (unformat (i, "%U/%d",
3878 unformat_ip6_address, &v6address, &address_length))
3884 if (sw_if_index_set == 0)
3886 errmsg ("missing interface name or sw_if_index");
3889 if (v4_address_set && v6_address_set)
3891 errmsg ("both v4 and v6 addresses set");
3894 if (!v4_address_set && !v6_address_set && !del_all)
3896 errmsg ("no addresses set");
3900 /* Construct the API message */
3901 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3903 mp->sw_if_index = ntohl (sw_if_index);
3904 mp->is_add = is_add;
3905 mp->del_all = del_all;
3908 mp->prefix.address.af = ADDRESS_IP6;
3909 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3913 mp->prefix.address.af = ADDRESS_IP4;
3914 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3916 mp->prefix.len = address_length;
3921 /* Wait for a reply, return good/bad news */
3927 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3929 unformat_input_t *i = vam->input;
3930 vl_api_sw_interface_set_mpls_enable_t *mp;
3932 u8 sw_if_index_set = 0;
3936 /* Parse args required to build the message */
3937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3939 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3940 sw_if_index_set = 1;
3941 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3942 sw_if_index_set = 1;
3943 else if (unformat (i, "disable"))
3945 else if (unformat (i, "dis"))
3951 if (sw_if_index_set == 0)
3953 errmsg ("missing interface name or sw_if_index");
3957 /* Construct the API message */
3958 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3960 mp->sw_if_index = ntohl (sw_if_index);
3961 mp->enable = enable;
3966 /* Wait for a reply... */
3972 api_sw_interface_set_table (vat_main_t * vam)
3974 unformat_input_t *i = vam->input;
3975 vl_api_sw_interface_set_table_t *mp;
3976 u32 sw_if_index, vrf_id = 0;
3977 u8 sw_if_index_set = 0;
3981 /* Parse args required to build the message */
3982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3984 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3985 sw_if_index_set = 1;
3986 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3987 sw_if_index_set = 1;
3988 else if (unformat (i, "vrf %d", &vrf_id))
3990 else if (unformat (i, "ipv6"))
3996 if (sw_if_index_set == 0)
3998 errmsg ("missing interface name or sw_if_index");
4002 /* Construct the API message */
4003 M (SW_INTERFACE_SET_TABLE, mp);
4005 mp->sw_if_index = ntohl (sw_if_index);
4006 mp->is_ipv6 = is_ipv6;
4007 mp->vrf_id = ntohl (vrf_id);
4012 /* Wait for a reply... */
4017 static void vl_api_sw_interface_get_table_reply_t_handler
4018 (vl_api_sw_interface_get_table_reply_t * mp)
4020 vat_main_t *vam = &vat_main;
4022 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4024 vam->retval = ntohl (mp->retval);
4025 vam->result_ready = 1;
4029 static void vl_api_sw_interface_get_table_reply_t_handler_json
4030 (vl_api_sw_interface_get_table_reply_t * mp)
4032 vat_main_t *vam = &vat_main;
4033 vat_json_node_t node;
4035 vat_json_init_object (&node);
4036 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4037 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4039 vat_json_print (vam->ofp, &node);
4040 vat_json_free (&node);
4042 vam->retval = ntohl (mp->retval);
4043 vam->result_ready = 1;
4047 api_sw_interface_get_table (vat_main_t * vam)
4049 unformat_input_t *i = vam->input;
4050 vl_api_sw_interface_get_table_t *mp;
4052 u8 sw_if_index_set = 0;
4056 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4058 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4059 sw_if_index_set = 1;
4060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4061 sw_if_index_set = 1;
4062 else if (unformat (i, "ipv6"))
4068 if (sw_if_index_set == 0)
4070 errmsg ("missing interface name or sw_if_index");
4074 M (SW_INTERFACE_GET_TABLE, mp);
4075 mp->sw_if_index = htonl (sw_if_index);
4076 mp->is_ipv6 = is_ipv6;
4084 api_sw_interface_set_vpath (vat_main_t * vam)
4086 unformat_input_t *i = vam->input;
4087 vl_api_sw_interface_set_vpath_t *mp;
4088 u32 sw_if_index = 0;
4089 u8 sw_if_index_set = 0;
4093 /* Parse args required to build the message */
4094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4096 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4097 sw_if_index_set = 1;
4098 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4099 sw_if_index_set = 1;
4100 else if (unformat (i, "enable"))
4102 else if (unformat (i, "disable"))
4108 if (sw_if_index_set == 0)
4110 errmsg ("missing interface name or sw_if_index");
4114 /* Construct the API message */
4115 M (SW_INTERFACE_SET_VPATH, mp);
4117 mp->sw_if_index = ntohl (sw_if_index);
4118 mp->enable = is_enable;
4123 /* Wait for a reply... */
4129 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4131 unformat_input_t *i = vam->input;
4132 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4133 u32 sw_if_index = 0;
4134 u8 sw_if_index_set = 0;
4139 /* Parse args required to build the message */
4140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4142 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4143 sw_if_index_set = 1;
4144 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4145 sw_if_index_set = 1;
4146 else if (unformat (i, "enable"))
4148 else if (unformat (i, "disable"))
4150 else if (unformat (i, "ip4"))
4152 else if (unformat (i, "ip6"))
4158 if (sw_if_index_set == 0)
4160 errmsg ("missing interface name or sw_if_index");
4164 /* Construct the API message */
4165 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4167 mp->sw_if_index = ntohl (sw_if_index);
4168 mp->enable = is_enable;
4169 mp->is_ipv6 = is_ipv6;
4174 /* Wait for a reply... */
4180 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4182 unformat_input_t *i = vam->input;
4183 vl_api_sw_interface_set_l2_xconnect_t *mp;
4185 u8 rx_sw_if_index_set = 0;
4187 u8 tx_sw_if_index_set = 0;
4191 /* Parse args required to build the message */
4192 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4194 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4195 rx_sw_if_index_set = 1;
4196 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4197 tx_sw_if_index_set = 1;
4198 else if (unformat (i, "rx"))
4200 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4202 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4204 rx_sw_if_index_set = 1;
4209 else if (unformat (i, "tx"))
4211 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4213 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4215 tx_sw_if_index_set = 1;
4220 else if (unformat (i, "enable"))
4222 else if (unformat (i, "disable"))
4228 if (rx_sw_if_index_set == 0)
4230 errmsg ("missing rx interface name or rx_sw_if_index");
4234 if (enable && (tx_sw_if_index_set == 0))
4236 errmsg ("missing tx interface name or tx_sw_if_index");
4240 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4242 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4243 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4244 mp->enable = enable;
4252 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4254 unformat_input_t *i = vam->input;
4255 vl_api_sw_interface_set_l2_bridge_t *mp;
4256 vl_api_l2_port_type_t port_type;
4258 u8 rx_sw_if_index_set = 0;
4265 port_type = L2_API_PORT_TYPE_NORMAL;
4267 /* Parse args required to build the message */
4268 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4270 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4271 rx_sw_if_index_set = 1;
4272 else if (unformat (i, "bd_id %d", &bd_id))
4276 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4277 rx_sw_if_index_set = 1;
4278 else if (unformat (i, "shg %d", &shg))
4280 else if (unformat (i, "bvi"))
4281 port_type = L2_API_PORT_TYPE_BVI;
4282 else if (unformat (i, "uu-fwd"))
4283 port_type = L2_API_PORT_TYPE_UU_FWD;
4284 else if (unformat (i, "enable"))
4286 else if (unformat (i, "disable"))
4292 if (rx_sw_if_index_set == 0)
4294 errmsg ("missing rx interface name or sw_if_index");
4298 if (enable && (bd_id_set == 0))
4300 errmsg ("missing bridge domain");
4304 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4306 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4307 mp->bd_id = ntohl (bd_id);
4309 mp->port_type = ntohl (port_type);
4310 mp->enable = enable;
4318 api_bridge_domain_dump (vat_main_t * vam)
4320 unformat_input_t *i = vam->input;
4321 vl_api_bridge_domain_dump_t *mp;
4322 vl_api_control_ping_t *mp_ping;
4326 /* Parse args required to build the message */
4327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4329 if (unformat (i, "bd_id %d", &bd_id))
4335 M (BRIDGE_DOMAIN_DUMP, mp);
4336 mp->bd_id = ntohl (bd_id);
4339 /* Use a control ping for synchronization */
4340 MPING (CONTROL_PING, mp_ping);
4348 api_bridge_domain_add_del (vat_main_t * vam)
4350 unformat_input_t *i = vam->input;
4351 vl_api_bridge_domain_add_del_t *mp;
4354 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4359 /* Parse args required to build the message */
4360 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4362 if (unformat (i, "bd_id %d", &bd_id))
4364 else if (unformat (i, "flood %d", &flood))
4366 else if (unformat (i, "uu-flood %d", &uu_flood))
4368 else if (unformat (i, "forward %d", &forward))
4370 else if (unformat (i, "learn %d", &learn))
4372 else if (unformat (i, "arp-term %d", &arp_term))
4374 else if (unformat (i, "mac-age %d", &mac_age))
4376 else if (unformat (i, "bd-tag %s", &bd_tag))
4378 else if (unformat (i, "del"))
4381 flood = uu_flood = forward = learn = 0;
4389 errmsg ("missing bridge domain");
4396 errmsg ("mac age must be less than 256 ");
4401 if ((bd_tag) && (vec_len (bd_tag) > 63))
4403 errmsg ("bd-tag cannot be longer than 63");
4408 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4410 mp->bd_id = ntohl (bd_id);
4412 mp->uu_flood = uu_flood;
4413 mp->forward = forward;
4415 mp->arp_term = arp_term;
4416 mp->is_add = is_add;
4417 mp->mac_age = (u8) mac_age;
4420 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4421 mp->bd_tag[vec_len (bd_tag)] = 0;
4432 api_l2fib_flush_bd (vat_main_t * vam)
4434 unformat_input_t *i = vam->input;
4435 vl_api_l2fib_flush_bd_t *mp;
4439 /* Parse args required to build the message */
4440 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4442 if (unformat (i, "bd_id %d", &bd_id));
4449 errmsg ("missing bridge domain");
4453 M (L2FIB_FLUSH_BD, mp);
4455 mp->bd_id = htonl (bd_id);
4463 api_l2fib_flush_int (vat_main_t * vam)
4465 unformat_input_t *i = vam->input;
4466 vl_api_l2fib_flush_int_t *mp;
4467 u32 sw_if_index = ~0;
4470 /* Parse args required to build the message */
4471 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4473 if (unformat (i, "sw_if_index %d", &sw_if_index));
4475 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4480 if (sw_if_index == ~0)
4482 errmsg ("missing interface name or sw_if_index");
4486 M (L2FIB_FLUSH_INT, mp);
4488 mp->sw_if_index = ntohl (sw_if_index);
4496 api_l2fib_add_del (vat_main_t * vam)
4498 unformat_input_t *i = vam->input;
4499 vl_api_l2fib_add_del_t *mp;
4505 u32 sw_if_index = 0;
4506 u8 sw_if_index_set = 0;
4515 /* Parse args required to build the message */
4516 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4518 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4520 else if (unformat (i, "bd_id %d", &bd_id))
4522 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4523 sw_if_index_set = 1;
4524 else if (unformat (i, "sw_if"))
4526 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4529 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4530 sw_if_index_set = 1;
4535 else if (unformat (i, "static"))
4537 else if (unformat (i, "filter"))
4542 else if (unformat (i, "bvi"))
4547 else if (unformat (i, "del"))
4549 else if (unformat (i, "count %d", &count))
4557 errmsg ("missing mac address");
4563 errmsg ("missing bridge domain");
4567 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4569 errmsg ("missing interface name or sw_if_index");
4575 /* Turn on async mode */
4576 vam->async_mode = 1;
4577 vam->async_errors = 0;
4578 before = vat_time_now (vam);
4581 for (j = 0; j < count; j++)
4583 M (L2FIB_ADD_DEL, mp);
4585 clib_memcpy (mp->mac, mac, 6);
4586 mp->bd_id = ntohl (bd_id);
4587 mp->is_add = is_add;
4588 mp->sw_if_index = ntohl (sw_if_index);
4592 mp->static_mac = static_mac;
4593 mp->filter_mac = filter_mac;
4594 mp->bvi_mac = bvi_mac;
4596 increment_mac_address (mac);
4603 vl_api_control_ping_t *mp_ping;
4606 /* Shut off async mode */
4607 vam->async_mode = 0;
4609 MPING (CONTROL_PING, mp_ping);
4612 timeout = vat_time_now (vam) + 1.0;
4613 while (vat_time_now (vam) < timeout)
4614 if (vam->result_ready == 1)
4619 if (vam->retval == -99)
4622 if (vam->async_errors > 0)
4624 errmsg ("%d asynchronous errors", vam->async_errors);
4627 vam->async_errors = 0;
4628 after = vat_time_now (vam);
4630 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4631 count, after - before, count / (after - before));
4637 /* Wait for a reply... */
4641 /* Return the good/bad news */
4642 return (vam->retval);
4646 api_bridge_domain_set_mac_age (vat_main_t * vam)
4648 unformat_input_t *i = vam->input;
4649 vl_api_bridge_domain_set_mac_age_t *mp;
4654 /* Parse args required to build the message */
4655 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4657 if (unformat (i, "bd_id %d", &bd_id));
4658 else if (unformat (i, "mac-age %d", &mac_age));
4665 errmsg ("missing bridge domain");
4671 errmsg ("mac age must be less than 256 ");
4675 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4677 mp->bd_id = htonl (bd_id);
4678 mp->mac_age = (u8) mac_age;
4686 api_l2_flags (vat_main_t * vam)
4688 unformat_input_t *i = vam->input;
4689 vl_api_l2_flags_t *mp;
4692 u8 sw_if_index_set = 0;
4696 /* Parse args required to build the message */
4697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4699 if (unformat (i, "sw_if_index %d", &sw_if_index))
4700 sw_if_index_set = 1;
4701 else if (unformat (i, "sw_if"))
4703 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4706 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4707 sw_if_index_set = 1;
4712 else if (unformat (i, "learn"))
4714 else if (unformat (i, "forward"))
4716 else if (unformat (i, "flood"))
4718 else if (unformat (i, "uu-flood"))
4719 flags |= L2_UU_FLOOD;
4720 else if (unformat (i, "arp-term"))
4721 flags |= L2_ARP_TERM;
4722 else if (unformat (i, "off"))
4724 else if (unformat (i, "disable"))
4730 if (sw_if_index_set == 0)
4732 errmsg ("missing interface name or sw_if_index");
4738 mp->sw_if_index = ntohl (sw_if_index);
4739 mp->feature_bitmap = ntohl (flags);
4740 mp->is_set = is_set;
4748 api_bridge_flags (vat_main_t * vam)
4750 unformat_input_t *i = vam->input;
4751 vl_api_bridge_flags_t *mp;
4755 bd_flags_t flags = 0;
4758 /* Parse args required to build the message */
4759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4761 if (unformat (i, "bd_id %d", &bd_id))
4763 else if (unformat (i, "learn"))
4764 flags |= BRIDGE_API_FLAG_LEARN;
4765 else if (unformat (i, "forward"))
4766 flags |= BRIDGE_API_FLAG_FWD;
4767 else if (unformat (i, "flood"))
4768 flags |= BRIDGE_API_FLAG_FLOOD;
4769 else if (unformat (i, "uu-flood"))
4770 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4771 else if (unformat (i, "arp-term"))
4772 flags |= BRIDGE_API_FLAG_ARP_TERM;
4773 else if (unformat (i, "off"))
4775 else if (unformat (i, "disable"))
4783 errmsg ("missing bridge domain");
4787 M (BRIDGE_FLAGS, mp);
4789 mp->bd_id = ntohl (bd_id);
4790 mp->flags = ntohl (flags);
4791 mp->is_set = is_set;
4799 api_bd_ip_mac_add_del (vat_main_t * vam)
4801 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4802 vl_api_mac_address_t mac = { 0 };
4803 unformat_input_t *i = vam->input;
4804 vl_api_bd_ip_mac_add_del_t *mp;
4813 /* Parse args required to build the message */
4814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4816 if (unformat (i, "bd_id %d", &bd_id))
4820 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4824 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4828 else if (unformat (i, "del"))
4836 errmsg ("missing bridge domain");
4839 else if (ip_set == 0)
4841 errmsg ("missing IP address");
4844 else if (mac_set == 0)
4846 errmsg ("missing MAC address");
4850 M (BD_IP_MAC_ADD_DEL, mp);
4852 mp->entry.bd_id = ntohl (bd_id);
4853 mp->is_add = is_add;
4855 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4856 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4864 api_bd_ip_mac_flush (vat_main_t * vam)
4866 unformat_input_t *i = vam->input;
4867 vl_api_bd_ip_mac_flush_t *mp;
4872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4874 if (unformat (i, "bd_id %d", &bd_id))
4884 errmsg ("missing bridge domain");
4888 M (BD_IP_MAC_FLUSH, mp);
4890 mp->bd_id = ntohl (bd_id);
4897 static void vl_api_bd_ip_mac_details_t_handler
4898 (vl_api_bd_ip_mac_details_t * mp)
4900 vat_main_t *vam = &vat_main;
4904 ntohl (mp->entry.bd_id),
4905 format_vl_api_mac_address, mp->entry.mac,
4906 format_vl_api_address, &mp->entry.ip);
4909 static void vl_api_bd_ip_mac_details_t_handler_json
4910 (vl_api_bd_ip_mac_details_t * mp)
4912 vat_main_t *vam = &vat_main;
4913 vat_json_node_t *node = NULL;
4915 if (VAT_JSON_ARRAY != vam->json_tree.type)
4917 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4918 vat_json_init_array (&vam->json_tree);
4920 node = vat_json_array_add (&vam->json_tree);
4922 vat_json_init_object (node);
4923 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4924 vat_json_object_add_string_copy (node, "mac_address",
4925 format (0, "%U", format_vl_api_mac_address,
4929 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4930 vat_json_object_add_string_copy (node, "ip_address", ip);
4935 api_bd_ip_mac_dump (vat_main_t * vam)
4937 unformat_input_t *i = vam->input;
4938 vl_api_bd_ip_mac_dump_t *mp;
4939 vl_api_control_ping_t *mp_ping;
4944 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4946 if (unformat (i, "bd_id %d", &bd_id))
4955 "\n%-5s %-7s %-20s %-30s",
4956 "bd_id", "is_ipv6", "mac_address", "ip_address");
4958 /* Dump Bridge Domain Ip to Mac entries */
4959 M (BD_IP_MAC_DUMP, mp);
4962 mp->bd_id = htonl (bd_id);
4968 /* Use a control ping for synchronization */
4969 MPING (CONTROL_PING, mp_ping);
4977 api_tap_create_v2 (vat_main_t * vam)
4979 unformat_input_t *i = vam->input;
4980 vl_api_tap_create_v2_t *mp;
4984 u32 num_rx_queues = 0;
4985 u8 *host_if_name = 0;
4986 u8 host_if_name_set = 0;
4989 u8 host_mac_addr[6];
4990 u8 host_mac_addr_set = 0;
4991 u8 *host_bridge = 0;
4992 u8 host_bridge_set = 0;
4993 u8 host_ip4_prefix_set = 0;
4994 u8 host_ip6_prefix_set = 0;
4995 ip4_address_t host_ip4_addr;
4996 ip4_address_t host_ip4_gw;
4997 u8 host_ip4_gw_set = 0;
4998 u32 host_ip4_prefix_len = 0;
4999 ip6_address_t host_ip6_addr;
5000 ip6_address_t host_ip6_gw;
5001 u8 host_ip6_gw_set = 0;
5002 u32 host_ip6_prefix_len = 0;
5003 u32 host_mtu_size = 0;
5004 u8 host_mtu_set = 0;
5007 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5009 clib_memset (mac_address, 0, sizeof (mac_address));
5011 /* Parse args required to build the message */
5012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5014 if (unformat (i, "id %u", &id))
5018 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5020 else if (unformat (i, "host-if-name %s", &host_if_name))
5021 host_if_name_set = 1;
5022 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5024 else if (unformat (i, "host-ns %s", &host_ns))
5026 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5028 host_mac_addr_set = 1;
5029 else if (unformat (i, "host-bridge %s", &host_bridge))
5030 host_bridge_set = 1;
5031 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5032 &host_ip4_addr, &host_ip4_prefix_len))
5033 host_ip4_prefix_set = 1;
5034 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5035 &host_ip6_addr, &host_ip6_prefix_len))
5036 host_ip6_prefix_set = 1;
5037 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5039 host_ip4_gw_set = 1;
5040 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5042 host_ip6_gw_set = 1;
5043 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5045 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5047 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5049 else if (unformat (i, "no-gso"))
5050 tap_flags &= ~TAP_API_FLAG_GSO;
5051 else if (unformat (i, "gso"))
5052 tap_flags |= TAP_API_FLAG_GSO;
5053 else if (unformat (i, "csum-offload"))
5054 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5055 else if (unformat (i, "persist"))
5056 tap_flags |= TAP_API_FLAG_PERSIST;
5057 else if (unformat (i, "attach"))
5058 tap_flags |= TAP_API_FLAG_ATTACH;
5059 else if (unformat (i, "tun"))
5060 tap_flags |= TAP_API_FLAG_TUN;
5061 else if (unformat (i, "gro-coalesce"))
5062 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5063 else if (unformat (i, "packed"))
5064 tap_flags |= TAP_API_FLAG_PACKED;
5065 else if (unformat (i, "in-order"))
5066 tap_flags |= TAP_API_FLAG_IN_ORDER;
5071 if (vec_len (host_if_name) > 63)
5073 errmsg ("tap name too long. ");
5076 if (vec_len (host_ns) > 63)
5078 errmsg ("host name space too long. ");
5081 if (vec_len (host_bridge) > 63)
5083 errmsg ("host bridge name too long. ");
5086 if (host_ip4_prefix_len > 32)
5088 errmsg ("host ip4 prefix length not valid. ");
5091 if (host_ip6_prefix_len > 128)
5093 errmsg ("host ip6 prefix length not valid. ");
5096 if (!is_pow2 (rx_ring_sz))
5098 errmsg ("rx ring size must be power of 2. ");
5101 if (rx_ring_sz > 32768)
5103 errmsg ("rx ring size must be 32768 or lower. ");
5106 if (!is_pow2 (tx_ring_sz))
5108 errmsg ("tx ring size must be power of 2. ");
5111 if (tx_ring_sz > 32768)
5113 errmsg ("tx ring size must be 32768 or lower. ");
5116 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5118 errmsg ("host MTU size must be in between 64 and 65355. ");
5122 /* Construct the API message */
5123 M (TAP_CREATE_V2, mp);
5125 mp->id = ntohl (id);
5126 mp->use_random_mac = random_mac;
5127 mp->num_rx_queues = (u8) num_rx_queues;
5128 mp->tx_ring_sz = ntohs (tx_ring_sz);
5129 mp->rx_ring_sz = ntohs (rx_ring_sz);
5130 mp->host_mtu_set = host_mtu_set;
5131 mp->host_mtu_size = ntohl (host_mtu_size);
5132 mp->host_mac_addr_set = host_mac_addr_set;
5133 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5134 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5135 mp->host_ip4_gw_set = host_ip4_gw_set;
5136 mp->host_ip6_gw_set = host_ip6_gw_set;
5137 mp->tap_flags = ntohl (tap_flags);
5138 mp->host_namespace_set = host_ns_set;
5139 mp->host_if_name_set = host_if_name_set;
5140 mp->host_bridge_set = host_bridge_set;
5142 if (random_mac == 0)
5143 clib_memcpy (mp->mac_address, mac_address, 6);
5144 if (host_mac_addr_set)
5145 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5146 if (host_if_name_set)
5147 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5149 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5150 if (host_bridge_set)
5151 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5152 if (host_ip4_prefix_set)
5154 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5155 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5157 if (host_ip6_prefix_set)
5159 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5160 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5162 if (host_ip4_gw_set)
5163 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5164 if (host_ip6_gw_set)
5165 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5168 vec_free (host_if_name);
5169 vec_free (host_bridge);
5174 /* Wait for a reply... */
5180 api_tap_delete_v2 (vat_main_t * vam)
5182 unformat_input_t *i = vam->input;
5183 vl_api_tap_delete_v2_t *mp;
5184 u32 sw_if_index = ~0;
5185 u8 sw_if_index_set = 0;
5188 /* Parse args required to build the message */
5189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5191 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5192 sw_if_index_set = 1;
5193 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5194 sw_if_index_set = 1;
5199 if (sw_if_index_set == 0)
5201 errmsg ("missing vpp interface name. ");
5205 /* Construct the API message */
5206 M (TAP_DELETE_V2, mp);
5208 mp->sw_if_index = ntohl (sw_if_index);
5213 /* Wait for a reply... */
5219 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5221 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5224 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5227 addr->domain = x[0];
5230 addr->function = x[3];
5236 api_virtio_pci_create_v2 (vat_main_t * vam)
5238 unformat_input_t *i = vam->input;
5239 vl_api_virtio_pci_create_v2_t *mp;
5243 u64 features = (u64) ~ (0ULL);
5244 u32 virtio_flags = 0;
5247 clib_memset (mac_address, 0, sizeof (mac_address));
5249 /* Parse args required to build the message */
5250 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5252 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5256 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5258 else if (unformat (i, "features 0x%llx", &features))
5260 else if (unformat (i, "gso-enabled"))
5261 virtio_flags |= VIRTIO_API_FLAG_GSO;
5262 else if (unformat (i, "csum-offload-enabled"))
5263 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5264 else if (unformat (i, "gro-coalesce"))
5265 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5266 else if (unformat (i, "packed"))
5267 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5268 else if (unformat (i, "in-order"))
5269 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5270 else if (unformat (i, "buffering"))
5271 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5278 errmsg ("pci address must be non zero. ");
5282 /* Construct the API message */
5283 M (VIRTIO_PCI_CREATE_V2, mp);
5285 mp->use_random_mac = random_mac;
5287 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5288 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5289 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5290 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5292 mp->features = clib_host_to_net_u64 (features);
5293 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5295 if (random_mac == 0)
5296 clib_memcpy (mp->mac_address, mac_address, 6);
5301 /* Wait for a reply... */
5307 api_virtio_pci_delete (vat_main_t * vam)
5309 unformat_input_t *i = vam->input;
5310 vl_api_virtio_pci_delete_t *mp;
5311 u32 sw_if_index = ~0;
5312 u8 sw_if_index_set = 0;
5315 /* Parse args required to build the message */
5316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5318 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5319 sw_if_index_set = 1;
5320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5321 sw_if_index_set = 1;
5326 if (sw_if_index_set == 0)
5328 errmsg ("missing vpp interface name. ");
5332 /* Construct the API message */
5333 M (VIRTIO_PCI_DELETE, mp);
5335 mp->sw_if_index = htonl (sw_if_index);
5340 /* Wait for a reply... */
5346 api_bond_create (vat_main_t * vam)
5348 unformat_input_t *i = vam->input;
5349 vl_api_bond_create_t *mp;
5359 clib_memset (mac_address, 0, sizeof (mac_address));
5362 /* Parse args required to build the message */
5363 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5365 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5367 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5368 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5370 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5373 else if (unformat (i, "numa-only"))
5375 else if (unformat (i, "id %u", &id))
5381 if (mode_is_set == 0)
5383 errmsg ("Missing bond mode. ");
5387 /* Construct the API message */
5388 M (BOND_CREATE, mp);
5390 mp->use_custom_mac = custom_mac;
5392 mp->mode = htonl (mode);
5393 mp->lb = htonl (lb);
5394 mp->id = htonl (id);
5395 mp->numa_only = numa_only;
5398 clib_memcpy (mp->mac_address, mac_address, 6);
5403 /* Wait for a reply... */
5409 api_bond_create2 (vat_main_t * vam)
5411 unformat_input_t *i = vam->input;
5412 vl_api_bond_create2_t *mp;
5423 clib_memset (mac_address, 0, sizeof (mac_address));
5426 /* Parse args required to build the message */
5427 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5429 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5431 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5432 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5434 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5437 else if (unformat (i, "numa-only"))
5439 else if (unformat (i, "gso"))
5441 else if (unformat (i, "id %u", &id))
5447 if (mode_is_set == 0)
5449 errmsg ("Missing bond mode. ");
5453 /* Construct the API message */
5454 M (BOND_CREATE2, mp);
5456 mp->use_custom_mac = custom_mac;
5458 mp->mode = htonl (mode);
5459 mp->lb = htonl (lb);
5460 mp->id = htonl (id);
5461 mp->numa_only = numa_only;
5462 mp->enable_gso = gso;
5465 clib_memcpy (mp->mac_address, mac_address, 6);
5470 /* Wait for a reply... */
5476 api_bond_delete (vat_main_t * vam)
5478 unformat_input_t *i = vam->input;
5479 vl_api_bond_delete_t *mp;
5480 u32 sw_if_index = ~0;
5481 u8 sw_if_index_set = 0;
5484 /* Parse args required to build the message */
5485 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5487 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5488 sw_if_index_set = 1;
5489 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5490 sw_if_index_set = 1;
5495 if (sw_if_index_set == 0)
5497 errmsg ("missing vpp interface name. ");
5501 /* Construct the API message */
5502 M (BOND_DELETE, mp);
5504 mp->sw_if_index = ntohl (sw_if_index);
5509 /* Wait for a reply... */
5515 api_bond_add_member (vat_main_t * vam)
5517 unformat_input_t *i = vam->input;
5518 vl_api_bond_add_member_t *mp;
5519 u32 bond_sw_if_index;
5523 u32 bond_sw_if_index_is_set = 0;
5525 u8 sw_if_index_is_set = 0;
5527 /* Parse args required to build the message */
5528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5530 if (unformat (i, "sw_if_index %d", &sw_if_index))
5531 sw_if_index_is_set = 1;
5532 else if (unformat (i, "bond %u", &bond_sw_if_index))
5533 bond_sw_if_index_is_set = 1;
5534 else if (unformat (i, "passive %d", &is_passive))
5536 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5542 if (bond_sw_if_index_is_set == 0)
5544 errmsg ("Missing bond sw_if_index. ");
5547 if (sw_if_index_is_set == 0)
5549 errmsg ("Missing member sw_if_index. ");
5553 /* Construct the API message */
5554 M (BOND_ADD_MEMBER, mp);
5556 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5557 mp->sw_if_index = ntohl (sw_if_index);
5558 mp->is_long_timeout = is_long_timeout;
5559 mp->is_passive = is_passive;
5564 /* Wait for a reply... */
5570 api_bond_detach_member (vat_main_t * vam)
5572 unformat_input_t *i = vam->input;
5573 vl_api_bond_detach_member_t *mp;
5574 u32 sw_if_index = ~0;
5575 u8 sw_if_index_set = 0;
5578 /* Parse args required to build the message */
5579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5581 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5582 sw_if_index_set = 1;
5583 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5584 sw_if_index_set = 1;
5589 if (sw_if_index_set == 0)
5591 errmsg ("missing vpp interface name. ");
5595 /* Construct the API message */
5596 M (BOND_DETACH_MEMBER, mp);
5598 mp->sw_if_index = ntohl (sw_if_index);
5603 /* Wait for a reply... */
5609 api_ip_table_add_del (vat_main_t * vam)
5611 unformat_input_t *i = vam->input;
5612 vl_api_ip_table_add_del_t *mp;
5618 /* Parse args required to build the message */
5619 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5621 if (unformat (i, "ipv6"))
5623 else if (unformat (i, "del"))
5625 else if (unformat (i, "add"))
5627 else if (unformat (i, "table %d", &table_id))
5631 clib_warning ("parse error '%U'", format_unformat_error, i);
5638 errmsg ("missing table-ID");
5642 /* Construct the API message */
5643 M (IP_TABLE_ADD_DEL, mp);
5645 mp->table.table_id = ntohl (table_id);
5646 mp->table.is_ip6 = is_ipv6;
5647 mp->is_add = is_add;
5652 /* Wait for a reply... */
5659 unformat_fib_path (unformat_input_t * input, va_list * args)
5661 vat_main_t *vam = va_arg (*args, vat_main_t *);
5662 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5663 u32 weight, preference;
5664 mpls_label_t out_label;
5666 clib_memset (path, 0, sizeof (*path));
5668 path->sw_if_index = ~0;
5672 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5674 if (unformat (input, "%U %U",
5675 unformat_vl_api_ip4_address,
5676 &path->nh.address.ip4,
5677 api_unformat_sw_if_index, vam, &path->sw_if_index))
5679 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5681 else if (unformat (input, "%U %U",
5682 unformat_vl_api_ip6_address,
5683 &path->nh.address.ip6,
5684 api_unformat_sw_if_index, vam, &path->sw_if_index))
5686 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5688 else if (unformat (input, "weight %u", &weight))
5690 path->weight = weight;
5692 else if (unformat (input, "preference %u", &preference))
5694 path->preference = preference;
5696 else if (unformat (input, "%U next-hop-table %d",
5697 unformat_vl_api_ip4_address,
5698 &path->nh.address.ip4, &path->table_id))
5700 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5702 else if (unformat (input, "%U next-hop-table %d",
5703 unformat_vl_api_ip6_address,
5704 &path->nh.address.ip6, &path->table_id))
5706 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5708 else if (unformat (input, "%U",
5709 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5712 * the recursive next-hops are by default in the default table
5715 path->sw_if_index = ~0;
5716 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5718 else if (unformat (input, "%U",
5719 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5722 * the recursive next-hops are by default in the default table
5725 path->sw_if_index = ~0;
5726 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5728 else if (unformat (input, "resolve-via-host"))
5730 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5732 else if (unformat (input, "resolve-via-attached"))
5734 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5736 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5738 path->type = FIB_API_PATH_TYPE_LOCAL;
5739 path->sw_if_index = ~0;
5740 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5742 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5744 path->type = FIB_API_PATH_TYPE_LOCAL;
5745 path->sw_if_index = ~0;
5746 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5748 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5750 else if (unformat (input, "via-label %d", &path->nh.via_label))
5752 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5753 path->sw_if_index = ~0;
5755 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5757 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5758 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5760 else if (unformat (input, "local"))
5762 path->type = FIB_API_PATH_TYPE_LOCAL;
5764 else if (unformat (input, "out-labels"))
5766 while (unformat (input, "%d", &out_label))
5768 path->label_stack[path->n_labels].label = out_label;
5769 path->label_stack[path->n_labels].is_uniform = 0;
5770 path->label_stack[path->n_labels].ttl = 64;
5774 else if (unformat (input, "via"))
5776 /* new path, back up and return */
5777 unformat_put_input (input);
5778 unformat_put_input (input);
5779 unformat_put_input (input);
5780 unformat_put_input (input);
5789 path->proto = ntohl (path->proto);
5790 path->type = ntohl (path->type);
5791 path->flags = ntohl (path->flags);
5792 path->table_id = ntohl (path->table_id);
5793 path->sw_if_index = ntohl (path->sw_if_index);
5799 api_ip_route_add_del (vat_main_t * vam)
5801 unformat_input_t *i = vam->input;
5802 vl_api_ip_route_add_del_t *mp;
5805 u8 is_multipath = 0;
5808 vl_api_prefix_t pfx = { };
5809 vl_api_fib_path_t paths[8];
5813 u32 random_add_del = 0;
5814 u32 *random_vector = 0;
5815 u32 random_seed = 0xdeaddabe;
5817 /* Parse args required to build the message */
5818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5820 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5822 else if (unformat (i, "del"))
5824 else if (unformat (i, "add"))
5826 else if (unformat (i, "vrf %d", &vrf_id))
5828 else if (unformat (i, "count %d", &count))
5830 else if (unformat (i, "random"))
5832 else if (unformat (i, "multipath"))
5834 else if (unformat (i, "seed %d", &random_seed))
5838 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5841 if (8 == path_count)
5843 errmsg ("max 8 paths");
5849 clib_warning ("parse error '%U'", format_unformat_error, i);
5856 errmsg ("specify a path; via ...");
5859 if (prefix_set == 0)
5861 errmsg ("missing prefix");
5865 /* Generate a pile of unique, random routes */
5868 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5869 u32 this_random_address;
5872 random_hash = hash_create (count, sizeof (uword));
5874 hash_set (random_hash, i->as_u32, 1);
5875 for (j = 0; j <= count; j++)
5879 this_random_address = random_u32 (&random_seed);
5880 this_random_address =
5881 clib_host_to_net_u32 (this_random_address);
5883 while (hash_get (random_hash, this_random_address));
5884 vec_add1 (random_vector, this_random_address);
5885 hash_set (random_hash, this_random_address, 1);
5887 hash_free (random_hash);
5888 set_ip4_address (&pfx.address, random_vector[0]);
5893 /* Turn on async mode */
5894 vam->async_mode = 1;
5895 vam->async_errors = 0;
5896 before = vat_time_now (vam);
5899 for (j = 0; j < count; j++)
5901 /* Construct the API message */
5902 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5904 mp->is_add = is_add;
5905 mp->is_multipath = is_multipath;
5907 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5908 mp->route.table_id = ntohl (vrf_id);
5909 mp->route.n_paths = path_count;
5911 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5914 set_ip4_address (&pfx.address, random_vector[j + 1]);
5916 increment_address (&pfx.address);
5919 /* If we receive SIGTERM, stop now... */
5924 /* When testing multiple add/del ops, use a control-ping to sync */
5927 vl_api_control_ping_t *mp_ping;
5931 /* Shut off async mode */
5932 vam->async_mode = 0;
5934 MPING (CONTROL_PING, mp_ping);
5937 timeout = vat_time_now (vam) + 1.0;
5938 while (vat_time_now (vam) < timeout)
5939 if (vam->result_ready == 1)
5944 if (vam->retval == -99)
5947 if (vam->async_errors > 0)
5949 errmsg ("%d asynchronous errors", vam->async_errors);
5952 vam->async_errors = 0;
5953 after = vat_time_now (vam);
5955 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5959 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5960 count, after - before, count / (after - before));
5966 /* Wait for a reply... */
5971 /* Return the good/bad news */
5972 return (vam->retval);
5976 api_ip_mroute_add_del (vat_main_t * vam)
5978 unformat_input_t *i = vam->input;
5979 u8 path_set = 0, prefix_set = 0, is_add = 1;
5980 vl_api_ip_mroute_add_del_t *mp;
5981 mfib_entry_flags_t eflags = 0;
5982 vl_api_mfib_path_t path;
5983 vl_api_mprefix_t pfx = { };
5987 /* Parse args required to build the message */
5988 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5990 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5993 pfx.grp_address_length = htons (pfx.grp_address_length);
5995 else if (unformat (i, "del"))
5997 else if (unformat (i, "add"))
5999 else if (unformat (i, "vrf %d", &vrf_id))
6001 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6002 path.itf_flags = htonl (path.itf_flags);
6003 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6005 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6009 clib_warning ("parse error '%U'", format_unformat_error, i);
6014 if (prefix_set == 0)
6016 errmsg ("missing addresses\n");
6021 errmsg ("missing path\n");
6025 /* Construct the API message */
6026 M (IP_MROUTE_ADD_DEL, mp);
6028 mp->is_add = is_add;
6029 mp->is_multipath = 1;
6031 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6032 mp->route.table_id = htonl (vrf_id);
6033 mp->route.n_paths = 1;
6034 mp->route.entry_flags = htonl (eflags);
6036 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6040 /* Wait for a reply... */
6046 api_mpls_table_add_del (vat_main_t * vam)
6048 unformat_input_t *i = vam->input;
6049 vl_api_mpls_table_add_del_t *mp;
6054 /* Parse args required to build the message */
6055 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6057 if (unformat (i, "table %d", &table_id))
6059 else if (unformat (i, "del"))
6061 else if (unformat (i, "add"))
6065 clib_warning ("parse error '%U'", format_unformat_error, i);
6072 errmsg ("missing table-ID");
6076 /* Construct the API message */
6077 M (MPLS_TABLE_ADD_DEL, mp);
6079 mp->mt_table.mt_table_id = ntohl (table_id);
6080 mp->mt_is_add = is_add;
6085 /* Wait for a reply... */
6092 api_mpls_route_add_del (vat_main_t * vam)
6094 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6095 mpls_label_t local_label = MPLS_LABEL_INVALID;
6096 unformat_input_t *i = vam->input;
6097 vl_api_mpls_route_add_del_t *mp;
6098 vl_api_fib_path_t paths[8];
6102 /* Parse args required to build the message */
6103 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6105 if (unformat (i, "%d", &local_label))
6107 else if (unformat (i, "eos"))
6109 else if (unformat (i, "non-eos"))
6111 else if (unformat (i, "del"))
6113 else if (unformat (i, "add"))
6115 else if (unformat (i, "multipath"))
6117 else if (unformat (i, "count %d", &count))
6121 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6124 if (8 == path_count)
6126 errmsg ("max 8 paths");
6132 clib_warning ("parse error '%U'", format_unformat_error, i);
6139 errmsg ("specify a path; via ...");
6143 if (MPLS_LABEL_INVALID == local_label)
6145 errmsg ("missing label");
6151 /* Turn on async mode */
6152 vam->async_mode = 1;
6153 vam->async_errors = 0;
6154 before = vat_time_now (vam);
6157 for (j = 0; j < count; j++)
6159 /* Construct the API message */
6160 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6162 mp->mr_is_add = is_add;
6163 mp->mr_is_multipath = is_multipath;
6165 mp->mr_route.mr_label = local_label;
6166 mp->mr_route.mr_eos = is_eos;
6167 mp->mr_route.mr_table_id = 0;
6168 mp->mr_route.mr_n_paths = path_count;
6170 clib_memcpy (&mp->mr_route.mr_paths, paths,
6171 sizeof (paths[0]) * path_count);
6177 /* If we receive SIGTERM, stop now... */
6182 /* When testing multiple add/del ops, use a control-ping to sync */
6185 vl_api_control_ping_t *mp_ping;
6189 /* Shut off async mode */
6190 vam->async_mode = 0;
6192 MPING (CONTROL_PING, mp_ping);
6195 timeout = vat_time_now (vam) + 1.0;
6196 while (vat_time_now (vam) < timeout)
6197 if (vam->result_ready == 1)
6202 if (vam->retval == -99)
6205 if (vam->async_errors > 0)
6207 errmsg ("%d asynchronous errors", vam->async_errors);
6210 vam->async_errors = 0;
6211 after = vat_time_now (vam);
6213 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6217 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6218 count, after - before, count / (after - before));
6224 /* Wait for a reply... */
6229 /* Return the good/bad news */
6230 return (vam->retval);
6235 api_mpls_ip_bind_unbind (vat_main_t * vam)
6237 unformat_input_t *i = vam->input;
6238 vl_api_mpls_ip_bind_unbind_t *mp;
6239 u32 ip_table_id = 0;
6241 vl_api_prefix_t pfx;
6243 mpls_label_t local_label = MPLS_LABEL_INVALID;
6246 /* Parse args required to build the message */
6247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6249 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6251 else if (unformat (i, "%d", &local_label))
6253 else if (unformat (i, "table-id %d", &ip_table_id))
6255 else if (unformat (i, "unbind"))
6257 else if (unformat (i, "bind"))
6261 clib_warning ("parse error '%U'", format_unformat_error, i);
6268 errmsg ("IP prefix not set");
6272 if (MPLS_LABEL_INVALID == local_label)
6274 errmsg ("missing label");
6278 /* Construct the API message */
6279 M (MPLS_IP_BIND_UNBIND, mp);
6281 mp->mb_is_bind = is_bind;
6282 mp->mb_ip_table_id = ntohl (ip_table_id);
6283 mp->mb_mpls_table_id = 0;
6284 mp->mb_label = ntohl (local_label);
6285 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6290 /* Wait for a reply... */
6297 api_sr_mpls_policy_add (vat_main_t * vam)
6299 unformat_input_t *i = vam->input;
6300 vl_api_sr_mpls_policy_add_t *mp;
6306 u32 *segments = NULL;
6309 /* Parse args required to build the message */
6310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6312 if (unformat (i, "bsid %d", &bsid))
6314 else if (unformat (i, "weight %d", &weight))
6316 else if (unformat (i, "spray"))
6318 else if (unformat (i, "next %d", &sid))
6321 vec_add1 (segments, htonl (sid));
6325 clib_warning ("parse error '%U'", format_unformat_error, i);
6332 errmsg ("bsid not set");
6336 if (n_segments == 0)
6338 errmsg ("no sid in segment stack");
6342 /* Construct the API message */
6343 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6345 mp->bsid = htonl (bsid);
6346 mp->weight = htonl (weight);
6347 mp->is_spray = type;
6348 mp->n_segments = n_segments;
6349 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6350 vec_free (segments);
6355 /* Wait for a reply... */
6361 api_sr_mpls_policy_del (vat_main_t * vam)
6363 unformat_input_t *i = vam->input;
6364 vl_api_sr_mpls_policy_del_t *mp;
6368 /* Parse args required to build the message */
6369 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6371 if (unformat (i, "bsid %d", &bsid))
6375 clib_warning ("parse error '%U'", format_unformat_error, i);
6382 errmsg ("bsid not set");
6386 /* Construct the API message */
6387 M (SR_MPLS_POLICY_DEL, mp);
6389 mp->bsid = htonl (bsid);
6394 /* Wait for a reply... */
6400 api_mpls_tunnel_add_del (vat_main_t * vam)
6402 unformat_input_t *i = vam->input;
6403 vl_api_mpls_tunnel_add_del_t *mp;
6405 vl_api_fib_path_t paths[8];
6406 u32 sw_if_index = ~0;
6412 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6414 if (unformat (i, "add"))
6418 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6420 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6422 else if (unformat (i, "l2-only"))
6426 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6429 if (8 == path_count)
6431 errmsg ("max 8 paths");
6437 clib_warning ("parse error '%U'", format_unformat_error, i);
6442 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6444 mp->mt_is_add = is_add;
6445 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6446 mp->mt_tunnel.mt_l2_only = l2_only;
6447 mp->mt_tunnel.mt_is_multicast = 0;
6448 mp->mt_tunnel.mt_n_paths = path_count;
6450 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6451 sizeof (paths[0]) * path_count);
6459 api_sw_interface_set_unnumbered (vat_main_t * vam)
6461 unformat_input_t *i = vam->input;
6462 vl_api_sw_interface_set_unnumbered_t *mp;
6464 u32 unnum_sw_index = ~0;
6466 u8 sw_if_index_set = 0;
6469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6471 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6472 sw_if_index_set = 1;
6473 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6474 sw_if_index_set = 1;
6475 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6477 else if (unformat (i, "del"))
6481 clib_warning ("parse error '%U'", format_unformat_error, i);
6486 if (sw_if_index_set == 0)
6488 errmsg ("missing interface name or sw_if_index");
6492 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6494 mp->sw_if_index = ntohl (sw_if_index);
6495 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6496 mp->is_add = is_add;
6505 api_create_vlan_subif (vat_main_t * vam)
6507 unformat_input_t *i = vam->input;
6508 vl_api_create_vlan_subif_t *mp;
6510 u8 sw_if_index_set = 0;
6515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6517 if (unformat (i, "sw_if_index %d", &sw_if_index))
6518 sw_if_index_set = 1;
6520 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6521 sw_if_index_set = 1;
6522 else if (unformat (i, "vlan %d", &vlan_id))
6526 clib_warning ("parse error '%U'", format_unformat_error, i);
6531 if (sw_if_index_set == 0)
6533 errmsg ("missing interface name or sw_if_index");
6537 if (vlan_id_set == 0)
6539 errmsg ("missing vlan_id");
6542 M (CREATE_VLAN_SUBIF, mp);
6544 mp->sw_if_index = ntohl (sw_if_index);
6545 mp->vlan_id = ntohl (vlan_id);
6552 #define foreach_create_subif_bit \
6559 _(outer_vlan_id_any) \
6560 _(inner_vlan_id_any)
6562 #define foreach_create_subif_flag \
6567 _(4, "exact_match") \
6568 _(5, "default_sub") \
6569 _(6, "outer_vlan_id_any") \
6570 _(7, "inner_vlan_id_any")
6573 api_create_subif (vat_main_t * vam)
6575 unformat_input_t *i = vam->input;
6576 vl_api_create_subif_t *mp;
6578 u8 sw_if_index_set = 0;
6581 u32 __attribute__ ((unused)) no_tags = 0;
6582 u32 __attribute__ ((unused)) one_tag = 0;
6583 u32 __attribute__ ((unused)) two_tags = 0;
6584 u32 __attribute__ ((unused)) dot1ad = 0;
6585 u32 __attribute__ ((unused)) exact_match = 0;
6586 u32 __attribute__ ((unused)) default_sub = 0;
6587 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
6588 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
6590 u16 outer_vlan_id = 0;
6591 u16 inner_vlan_id = 0;
6594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6596 if (unformat (i, "sw_if_index %d", &sw_if_index))
6597 sw_if_index_set = 1;
6599 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6600 sw_if_index_set = 1;
6601 else if (unformat (i, "sub_id %d", &sub_id))
6603 else if (unformat (i, "outer_vlan_id %d", &tmp))
6604 outer_vlan_id = tmp;
6605 else if (unformat (i, "inner_vlan_id %d", &tmp))
6606 inner_vlan_id = tmp;
6608 #define _(a) else if (unformat (i, #a)) a = 1 ;
6609 foreach_create_subif_bit
6613 clib_warning ("parse error '%U'", format_unformat_error, i);
6618 if (sw_if_index_set == 0)
6620 errmsg ("missing interface name or sw_if_index");
6624 if (sub_id_set == 0)
6626 errmsg ("missing sub_id");
6629 M (CREATE_SUBIF, mp);
6631 mp->sw_if_index = ntohl (sw_if_index);
6632 mp->sub_id = ntohl (sub_id);
6634 #define _(a,b) mp->sub_if_flags |= (1 << a);
6635 foreach_create_subif_flag;
6638 mp->outer_vlan_id = ntohs (outer_vlan_id);
6639 mp->inner_vlan_id = ntohs (inner_vlan_id);
6647 api_ip_table_replace_begin (vat_main_t * vam)
6649 unformat_input_t *i = vam->input;
6650 vl_api_ip_table_replace_begin_t *mp;
6655 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6657 if (unformat (i, "table %d", &table_id))
6659 else if (unformat (i, "ipv6"))
6663 clib_warning ("parse error '%U'", format_unformat_error, i);
6668 M (IP_TABLE_REPLACE_BEGIN, mp);
6670 mp->table.table_id = ntohl (table_id);
6671 mp->table.is_ip6 = is_ipv6;
6679 api_ip_table_flush (vat_main_t * vam)
6681 unformat_input_t *i = vam->input;
6682 vl_api_ip_table_flush_t *mp;
6687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6689 if (unformat (i, "table %d", &table_id))
6691 else if (unformat (i, "ipv6"))
6695 clib_warning ("parse error '%U'", format_unformat_error, i);
6700 M (IP_TABLE_FLUSH, mp);
6702 mp->table.table_id = ntohl (table_id);
6703 mp->table.is_ip6 = is_ipv6;
6711 api_ip_table_replace_end (vat_main_t * vam)
6713 unformat_input_t *i = vam->input;
6714 vl_api_ip_table_replace_end_t *mp;
6719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6721 if (unformat (i, "table %d", &table_id))
6723 else if (unformat (i, "ipv6"))
6727 clib_warning ("parse error '%U'", format_unformat_error, i);
6732 M (IP_TABLE_REPLACE_END, mp);
6734 mp->table.table_id = ntohl (table_id);
6735 mp->table.is_ip6 = is_ipv6;
6743 api_set_ip_flow_hash (vat_main_t * vam)
6745 unformat_input_t *i = vam->input;
6746 vl_api_set_ip_flow_hash_t *mp;
6758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6760 if (unformat (i, "vrf %d", &vrf_id))
6762 else if (unformat (i, "ipv6"))
6764 else if (unformat (i, "src"))
6766 else if (unformat (i, "dst"))
6768 else if (unformat (i, "sport"))
6770 else if (unformat (i, "dport"))
6772 else if (unformat (i, "proto"))
6774 else if (unformat (i, "reverse"))
6779 clib_warning ("parse error '%U'", format_unformat_error, i);
6784 if (vrf_id_set == 0)
6786 errmsg ("missing vrf id");
6790 M (SET_IP_FLOW_HASH, mp);
6796 mp->reverse = reverse;
6797 mp->vrf_id = ntohl (vrf_id);
6798 mp->is_ipv6 = is_ipv6;
6806 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6808 unformat_input_t *i = vam->input;
6809 vl_api_sw_interface_ip6_enable_disable_t *mp;
6811 u8 sw_if_index_set = 0;
6815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6817 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6818 sw_if_index_set = 1;
6819 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6820 sw_if_index_set = 1;
6821 else if (unformat (i, "enable"))
6823 else if (unformat (i, "disable"))
6827 clib_warning ("parse error '%U'", format_unformat_error, i);
6832 if (sw_if_index_set == 0)
6834 errmsg ("missing interface name or sw_if_index");
6838 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6840 mp->sw_if_index = ntohl (sw_if_index);
6841 mp->enable = enable;
6850 api_l2_patch_add_del (vat_main_t * vam)
6852 unformat_input_t *i = vam->input;
6853 vl_api_l2_patch_add_del_t *mp;
6855 u8 rx_sw_if_index_set = 0;
6857 u8 tx_sw_if_index_set = 0;
6861 /* Parse args required to build the message */
6862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6864 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6865 rx_sw_if_index_set = 1;
6866 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6867 tx_sw_if_index_set = 1;
6868 else if (unformat (i, "rx"))
6870 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6872 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6874 rx_sw_if_index_set = 1;
6879 else if (unformat (i, "tx"))
6881 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6883 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6885 tx_sw_if_index_set = 1;
6890 else if (unformat (i, "del"))
6896 if (rx_sw_if_index_set == 0)
6898 errmsg ("missing rx interface name or rx_sw_if_index");
6902 if (tx_sw_if_index_set == 0)
6904 errmsg ("missing tx interface name or tx_sw_if_index");
6908 M (L2_PATCH_ADD_DEL, mp);
6910 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6911 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6912 mp->is_add = is_add;
6920 u8 localsid_addr[16];
6929 api_sr_localsid_add_del (vat_main_t * vam)
6931 unformat_input_t *i = vam->input;
6932 vl_api_sr_localsid_add_del_t *mp;
6935 ip6_address_t localsid;
6939 u32 fib_table = ~(u32) 0;
6940 ip46_address_t nh_addr;
6941 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6943 bool nexthop_set = 0;
6947 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6949 if (unformat (i, "del"))
6951 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6952 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6954 else if (unformat (i, "behavior %u", &behavior));
6955 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6956 else if (unformat (i, "fib-table %u", &fib_table));
6957 else if (unformat (i, "end.psp %u", &behavior));
6962 M (SR_LOCALSID_ADD_DEL, mp);
6964 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6968 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6970 mp->behavior = behavior;
6971 mp->sw_if_index = ntohl (sw_if_index);
6972 mp->fib_table = ntohl (fib_table);
6973 mp->end_psp = end_psp;
6974 mp->is_del = is_del;
6982 api_ioam_enable (vat_main_t * vam)
6984 unformat_input_t *input = vam->input;
6985 vl_api_ioam_enable_t *mp;
6987 int has_trace_option = 0;
6988 int has_pot_option = 0;
6989 int has_seqno_option = 0;
6990 int has_analyse_option = 0;
6993 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6995 if (unformat (input, "trace"))
6996 has_trace_option = 1;
6997 else if (unformat (input, "pot"))
6999 else if (unformat (input, "seqno"))
7000 has_seqno_option = 1;
7001 else if (unformat (input, "analyse"))
7002 has_analyse_option = 1;
7006 M (IOAM_ENABLE, mp);
7007 mp->id = htons (id);
7008 mp->seqno = has_seqno_option;
7009 mp->analyse = has_analyse_option;
7010 mp->pot_enable = has_pot_option;
7011 mp->trace_enable = has_trace_option;
7020 api_ioam_disable (vat_main_t * vam)
7022 vl_api_ioam_disable_t *mp;
7025 M (IOAM_DISABLE, mp);
7031 #define foreach_tcp_proto_field \
7035 #define foreach_udp_proto_field \
7039 #define foreach_ip4_proto_field \
7051 u16 src_port, dst_port;
7054 #if VPP_API_TEST_BUILTIN == 0
7056 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7058 u8 **maskp = va_arg (*args, u8 **);
7060 u8 found_something = 0;
7063 #define _(a) u8 a=0;
7064 foreach_tcp_proto_field;
7067 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7070 #define _(a) else if (unformat (input, #a)) a=1;
7071 foreach_tcp_proto_field
7077 #define _(a) found_something += a;
7078 foreach_tcp_proto_field;
7081 if (found_something == 0)
7084 vec_validate (mask, sizeof (*tcp) - 1);
7086 tcp = (tcp_header_t *) mask;
7088 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7089 foreach_tcp_proto_field;
7097 unformat_udp_mask (unformat_input_t * input, va_list * args)
7099 u8 **maskp = va_arg (*args, u8 **);
7101 u8 found_something = 0;
7104 #define _(a) u8 a=0;
7105 foreach_udp_proto_field;
7108 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7111 #define _(a) else if (unformat (input, #a)) a=1;
7112 foreach_udp_proto_field
7118 #define _(a) found_something += a;
7119 foreach_udp_proto_field;
7122 if (found_something == 0)
7125 vec_validate (mask, sizeof (*udp) - 1);
7127 udp = (udp_header_t *) mask;
7129 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7130 foreach_udp_proto_field;
7138 unformat_l4_mask (unformat_input_t * input, va_list * args)
7140 u8 **maskp = va_arg (*args, u8 **);
7141 u16 src_port = 0, dst_port = 0;
7142 tcpudp_header_t *tcpudp;
7144 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7146 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7148 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7150 else if (unformat (input, "src_port"))
7152 else if (unformat (input, "dst_port"))
7158 if (!src_port && !dst_port)
7162 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7164 tcpudp = (tcpudp_header_t *) mask;
7165 tcpudp->src_port = src_port;
7166 tcpudp->dst_port = dst_port;
7174 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7176 u8 **maskp = va_arg (*args, u8 **);
7178 u8 found_something = 0;
7181 #define _(a) u8 a=0;
7182 foreach_ip4_proto_field;
7188 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7190 if (unformat (input, "version"))
7192 else if (unformat (input, "hdr_length"))
7194 else if (unformat (input, "src"))
7196 else if (unformat (input, "dst"))
7198 else if (unformat (input, "proto"))
7201 #define _(a) else if (unformat (input, #a)) a=1;
7202 foreach_ip4_proto_field
7208 #define _(a) found_something += a;
7209 foreach_ip4_proto_field;
7212 if (found_something == 0)
7215 vec_validate (mask, sizeof (*ip) - 1);
7217 ip = (ip4_header_t *) mask;
7219 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7220 foreach_ip4_proto_field;
7223 ip->ip_version_and_header_length = 0;
7226 ip->ip_version_and_header_length |= 0xF0;
7229 ip->ip_version_and_header_length |= 0x0F;
7235 #define foreach_ip6_proto_field \
7243 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7245 u8 **maskp = va_arg (*args, u8 **);
7247 u8 found_something = 0;
7249 u32 ip_version_traffic_class_and_flow_label;
7251 #define _(a) u8 a=0;
7252 foreach_ip6_proto_field;
7255 u8 traffic_class = 0;
7258 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7260 if (unformat (input, "version"))
7262 else if (unformat (input, "traffic-class"))
7264 else if (unformat (input, "flow-label"))
7266 else if (unformat (input, "src"))
7268 else if (unformat (input, "dst"))
7270 else if (unformat (input, "proto"))
7273 #define _(a) else if (unformat (input, #a)) a=1;
7274 foreach_ip6_proto_field
7280 #define _(a) found_something += a;
7281 foreach_ip6_proto_field;
7284 if (found_something == 0)
7287 vec_validate (mask, sizeof (*ip) - 1);
7289 ip = (ip6_header_t *) mask;
7291 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7292 foreach_ip6_proto_field;
7295 ip_version_traffic_class_and_flow_label = 0;
7298 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7301 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7304 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7306 ip->ip_version_traffic_class_and_flow_label =
7307 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7314 unformat_l3_mask (unformat_input_t * input, va_list * args)
7316 u8 **maskp = va_arg (*args, u8 **);
7318 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7320 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7322 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7331 unformat_l2_mask (unformat_input_t * input, va_list * args)
7333 u8 **maskp = va_arg (*args, u8 **);
7348 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7350 if (unformat (input, "src"))
7352 else if (unformat (input, "dst"))
7354 else if (unformat (input, "proto"))
7356 else if (unformat (input, "tag1"))
7358 else if (unformat (input, "tag2"))
7360 else if (unformat (input, "ignore-tag1"))
7362 else if (unformat (input, "ignore-tag2"))
7364 else if (unformat (input, "cos1"))
7366 else if (unformat (input, "cos2"))
7368 else if (unformat (input, "dot1q"))
7370 else if (unformat (input, "dot1ad"))
7375 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7376 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7379 if (tag1 || ignore_tag1 || cos1 || dot1q)
7381 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7384 vec_validate (mask, len - 1);
7387 clib_memset (mask, 0xff, 6);
7390 clib_memset (mask + 6, 0xff, 6);
7394 /* inner vlan tag */
7403 mask[21] = mask[20] = 0xff;
7424 mask[16] = mask[17] = 0xff;
7434 mask[12] = mask[13] = 0xff;
7441 unformat_classify_mask (unformat_input_t * input, va_list * args)
7443 u8 **maskp = va_arg (*args, u8 **);
7444 u32 *skipp = va_arg (*args, u32 *);
7445 u32 *matchp = va_arg (*args, u32 *);
7453 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7455 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7457 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7459 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7461 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7475 if (mask || l2 || l3 || l4)
7479 /* "With a free Ethernet header in every package" */
7481 vec_validate (l2, 13);
7485 vec_append (mask, l3);
7490 vec_append (mask, l4);
7495 /* Scan forward looking for the first significant mask octet */
7496 for (i = 0; i < vec_len (mask); i++)
7500 /* compute (skip, match) params */
7501 *skipp = i / sizeof (u32x4);
7502 vec_delete (mask, *skipp * sizeof (u32x4), 0);
7504 /* Pad mask to an even multiple of the vector size */
7505 while (vec_len (mask) % sizeof (u32x4))
7508 match = vec_len (mask) / sizeof (u32x4);
7510 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
7512 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
7513 if (*tmp || *(tmp + 1))
7518 clib_warning ("BUG: match 0");
7520 _vec_len (mask) = match * sizeof (u32x4);
7530 #endif /* VPP_API_TEST_BUILTIN */
7532 #define foreach_l2_next \
7534 _(ethernet, ETHERNET_INPUT) \
7539 unformat_l2_next_index (unformat_input_t * input, va_list * args)
7541 u32 *miss_next_indexp = va_arg (*args, u32 *);
7546 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
7550 if (unformat (input, "%d", &tmp))
7559 *miss_next_indexp = next_index;
7563 #define foreach_ip_next \
7569 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
7571 u32 *miss_next_indexp = va_arg (*args, u32 *);
7576 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7580 if (unformat (input, "%d", &tmp))
7589 *miss_next_indexp = next_index;
7593 #define foreach_acl_next \
7597 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
7599 u32 *miss_next_indexp = va_arg (*args, u32 *);
7604 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7608 if (unformat (input, "permit"))
7613 else if (unformat (input, "%d", &tmp))
7622 *miss_next_indexp = next_index;
7627 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7629 u32 *r = va_arg (*args, u32 *);
7631 if (unformat (input, "conform-color"))
7632 *r = POLICE_CONFORM;
7633 else if (unformat (input, "exceed-color"))
7641 #if VPP_API_TEST_BUILTIN == 0
7643 unformat_l4_match (unformat_input_t * input, va_list * args)
7645 u8 **matchp = va_arg (*args, u8 **);
7647 u8 *proto_header = 0;
7653 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7655 if (unformat (input, "src_port %d", &src_port))
7657 else if (unformat (input, "dst_port %d", &dst_port))
7663 h.src_port = clib_host_to_net_u16 (src_port);
7664 h.dst_port = clib_host_to_net_u16 (dst_port);
7665 vec_validate (proto_header, sizeof (h) - 1);
7666 memcpy (proto_header, &h, sizeof (h));
7668 *matchp = proto_header;
7674 unformat_ip4_match (unformat_input_t * input, va_list * args)
7676 u8 **matchp = va_arg (*args, u8 **);
7683 int src = 0, dst = 0;
7684 ip4_address_t src_val, dst_val;
7691 int fragment_id = 0;
7692 u32 fragment_id_val;
7698 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7700 if (unformat (input, "version %d", &version_val))
7702 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7704 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7706 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7708 else if (unformat (input, "proto %d", &proto_val))
7710 else if (unformat (input, "tos %d", &tos_val))
7712 else if (unformat (input, "length %d", &length_val))
7714 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7716 else if (unformat (input, "ttl %d", &ttl_val))
7718 else if (unformat (input, "checksum %d", &checksum_val))
7724 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7725 + ttl + checksum == 0)
7729 * Aligned because we use the real comparison functions
7731 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7733 ip = (ip4_header_t *) match;
7735 /* These are realistically matched in practice */
7737 ip->src_address.as_u32 = src_val.as_u32;
7740 ip->dst_address.as_u32 = dst_val.as_u32;
7743 ip->protocol = proto_val;
7746 /* These are not, but they're included for completeness */
7748 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7751 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7757 ip->length = clib_host_to_net_u16 (length_val);
7763 ip->checksum = clib_host_to_net_u16 (checksum_val);
7770 unformat_ip6_match (unformat_input_t * input, va_list * args)
7772 u8 **matchp = va_arg (*args, u8 **);
7777 u8 traffic_class = 0;
7778 u32 traffic_class_val = 0;
7781 int src = 0, dst = 0;
7782 ip6_address_t src_val, dst_val;
7785 int payload_length = 0;
7786 u32 payload_length_val;
7789 u32 ip_version_traffic_class_and_flow_label;
7791 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7793 if (unformat (input, "version %d", &version_val))
7795 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7797 else if (unformat (input, "flow_label %d", &flow_label_val))
7799 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7801 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7803 else if (unformat (input, "proto %d", &proto_val))
7805 else if (unformat (input, "payload_length %d", &payload_length_val))
7807 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7813 if (version + traffic_class + flow_label + src + dst + proto +
7814 payload_length + hop_limit == 0)
7818 * Aligned because we use the real comparison functions
7820 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7822 ip = (ip6_header_t *) match;
7825 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7828 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7831 ip->protocol = proto_val;
7833 ip_version_traffic_class_and_flow_label = 0;
7836 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7839 ip_version_traffic_class_and_flow_label |=
7840 (traffic_class_val & 0xFF) << 20;
7843 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7845 ip->ip_version_traffic_class_and_flow_label =
7846 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7849 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7852 ip->hop_limit = hop_limit_val;
7859 unformat_l3_match (unformat_input_t * input, va_list * args)
7861 u8 **matchp = va_arg (*args, u8 **);
7863 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7865 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7867 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7876 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7878 u8 *tagp = va_arg (*args, u8 *);
7881 if (unformat (input, "%d", &tag))
7883 tagp[0] = (tag >> 8) & 0x0F;
7884 tagp[1] = tag & 0xFF;
7892 unformat_l2_match (unformat_input_t * input, va_list * args)
7894 u8 **matchp = va_arg (*args, u8 **);
7914 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7916 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7919 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7921 else if (unformat (input, "proto %U",
7922 unformat_ethernet_type_host_byte_order, &proto_val))
7924 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7926 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7928 else if (unformat (input, "ignore-tag1"))
7930 else if (unformat (input, "ignore-tag2"))
7932 else if (unformat (input, "cos1 %d", &cos1_val))
7934 else if (unformat (input, "cos2 %d", &cos2_val))
7939 if ((src + dst + proto + tag1 + tag2 +
7940 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7943 if (tag1 || ignore_tag1 || cos1)
7945 if (tag2 || ignore_tag2 || cos2)
7948 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7951 clib_memcpy (match, dst_val, 6);
7954 clib_memcpy (match + 6, src_val, 6);
7958 /* inner vlan tag */
7959 match[19] = tag2_val[1];
7960 match[18] = tag2_val[0];
7962 match[18] |= (cos2_val & 0x7) << 5;
7965 match[21] = proto_val & 0xff;
7966 match[20] = proto_val >> 8;
7970 match[15] = tag1_val[1];
7971 match[14] = tag1_val[0];
7974 match[14] |= (cos1_val & 0x7) << 5;
7980 match[15] = tag1_val[1];
7981 match[14] = tag1_val[0];
7984 match[17] = proto_val & 0xff;
7985 match[16] = proto_val >> 8;
7988 match[14] |= (cos1_val & 0x7) << 5;
7994 match[18] |= (cos2_val & 0x7) << 5;
7996 match[14] |= (cos1_val & 0x7) << 5;
7999 match[13] = proto_val & 0xff;
8000 match[12] = proto_val >> 8;
8008 unformat_qos_source (unformat_input_t * input, va_list * args)
8010 int *qs = va_arg (*args, int *);
8012 if (unformat (input, "ip"))
8013 *qs = QOS_SOURCE_IP;
8014 else if (unformat (input, "mpls"))
8015 *qs = QOS_SOURCE_MPLS;
8016 else if (unformat (input, "ext"))
8017 *qs = QOS_SOURCE_EXT;
8018 else if (unformat (input, "vlan"))
8019 *qs = QOS_SOURCE_VLAN;
8028 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8030 u8 **matchp = va_arg (*args, u8 **);
8031 u32 skip_n_vectors = va_arg (*args, u32);
8032 u32 match_n_vectors = va_arg (*args, u32);
8039 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8041 if (unformat (input, "hex %U", unformat_hex_string, &match))
8043 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8045 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8047 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8061 if (match || l2 || l3 || l4)
8065 /* "Win a free Ethernet header in every packet" */
8067 vec_validate_aligned (l2, 13, sizeof (u32x4));
8071 vec_append_aligned (match, l3, sizeof (u32x4));
8076 vec_append_aligned (match, l4, sizeof (u32x4));
8081 /* Make sure the vector is big enough even if key is all 0's */
8082 vec_validate_aligned
8083 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8086 /* Set size, include skipped vectors */
8087 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8098 api_set_ipfix_exporter (vat_main_t *vam)
8100 unformat_input_t *i = vam->input;
8101 vl_api_set_ipfix_exporter_t *mp;
8102 ip4_address_t collector_address;
8103 u8 collector_address_set = 0;
8104 u32 collector_port = ~0;
8105 ip4_address_t src_address;
8106 u8 src_address_set = 0;
8109 u32 template_interval = ~0;
8110 u8 udp_checksum = 0;
8113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8115 if (unformat (i, "collector_address %U", unformat_ip4_address,
8116 &collector_address))
8117 collector_address_set = 1;
8118 else if (unformat (i, "collector_port %d", &collector_port))
8120 else if (unformat (i, "src_address %U", unformat_ip4_address,
8122 src_address_set = 1;
8123 else if (unformat (i, "vrf_id %d", &vrf_id))
8125 else if (unformat (i, "path_mtu %d", &path_mtu))
8127 else if (unformat (i, "template_interval %d", &template_interval))
8129 else if (unformat (i, "udp_checksum"))
8135 if (collector_address_set == 0)
8137 errmsg ("collector_address required");
8141 if (src_address_set == 0)
8143 errmsg ("src_address required");
8147 M (SET_IPFIX_EXPORTER, mp);
8149 memcpy (mp->collector_address.un.ip4, collector_address.data,
8150 sizeof (collector_address.data));
8151 mp->collector_port = htons ((u16) collector_port);
8152 memcpy (mp->src_address.un.ip4, src_address.data,
8153 sizeof (src_address.data));
8154 mp->vrf_id = htonl (vrf_id);
8155 mp->path_mtu = htonl (path_mtu);
8156 mp->template_interval = htonl (template_interval);
8157 mp->udp_checksum = udp_checksum;
8165 api_set_ipfix_classify_stream (vat_main_t * vam)
8167 unformat_input_t *i = vam->input;
8168 vl_api_set_ipfix_classify_stream_t *mp;
8170 u32 src_port = UDP_DST_PORT_ipfix;
8173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8175 if (unformat (i, "domain %d", &domain_id))
8177 else if (unformat (i, "src_port %d", &src_port))
8181 errmsg ("unknown input `%U'", format_unformat_error, i);
8186 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8188 mp->domain_id = htonl (domain_id);
8189 mp->src_port = htons ((u16) src_port);
8197 api_ipfix_classify_table_add_del (vat_main_t * vam)
8199 unformat_input_t *i = vam->input;
8200 vl_api_ipfix_classify_table_add_del_t *mp;
8202 u32 classify_table_index = ~0;
8204 u8 transport_protocol = 255;
8207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8209 if (unformat (i, "add"))
8211 else if (unformat (i, "del"))
8213 else if (unformat (i, "table %d", &classify_table_index))
8215 else if (unformat (i, "ip4"))
8217 else if (unformat (i, "ip6"))
8219 else if (unformat (i, "tcp"))
8220 transport_protocol = 6;
8221 else if (unformat (i, "udp"))
8222 transport_protocol = 17;
8225 errmsg ("unknown input `%U'", format_unformat_error, i);
8232 errmsg ("expecting: add|del");
8235 if (classify_table_index == ~0)
8237 errmsg ("classifier table not specified");
8240 if (ip_version == 0)
8242 errmsg ("IP version not specified");
8246 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
8248 mp->is_add = is_add;
8249 mp->table_id = htonl (classify_table_index);
8250 mp->ip_version = ip_version;
8251 mp->transport_protocol = transport_protocol;
8259 api_get_node_index (vat_main_t * vam)
8261 unformat_input_t *i = vam->input;
8262 vl_api_get_node_index_t *mp;
8266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8268 if (unformat (i, "node %s", &name))
8275 errmsg ("node name required");
8278 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
8280 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8284 M (GET_NODE_INDEX, mp);
8285 clib_memcpy (mp->node_name, name, vec_len (name));
8294 api_get_next_index (vat_main_t * vam)
8296 unformat_input_t *i = vam->input;
8297 vl_api_get_next_index_t *mp;
8298 u8 *node_name = 0, *next_node_name = 0;
8301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8303 if (unformat (i, "node-name %s", &node_name))
8305 else if (unformat (i, "next-node-name %s", &next_node_name))
8311 errmsg ("node name required");
8314 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
8316 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8320 if (next_node_name == 0)
8322 errmsg ("next node name required");
8325 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
8327 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
8331 M (GET_NEXT_INDEX, mp);
8332 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
8333 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
8334 vec_free (node_name);
8335 vec_free (next_node_name);
8343 api_add_node_next (vat_main_t * vam)
8345 unformat_input_t *i = vam->input;
8346 vl_api_add_node_next_t *mp;
8351 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8353 if (unformat (i, "node %s", &name))
8355 else if (unformat (i, "next %s", &next))
8362 errmsg ("node name required");
8365 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
8367 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8372 errmsg ("next node required");
8375 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
8377 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
8381 M (ADD_NODE_NEXT, mp);
8382 clib_memcpy (mp->node_name, name, vec_len (name));
8383 clib_memcpy (mp->next_name, next, vec_len (next));
8392 static void vl_api_sw_interface_tap_v2_details_t_handler
8393 (vl_api_sw_interface_tap_v2_details_t * mp)
8395 vat_main_t *vam = &vat_main;
8398 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
8399 mp->host_ip4_prefix.len);
8401 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
8402 mp->host_ip6_prefix.len);
8405 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
8406 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
8407 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8408 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
8409 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
8415 static void vl_api_sw_interface_tap_v2_details_t_handler_json
8416 (vl_api_sw_interface_tap_v2_details_t * mp)
8418 vat_main_t *vam = &vat_main;
8419 vat_json_node_t *node = NULL;
8421 if (VAT_JSON_ARRAY != vam->json_tree.type)
8423 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8424 vat_json_init_array (&vam->json_tree);
8426 node = vat_json_array_add (&vam->json_tree);
8428 vat_json_init_object (node);
8429 vat_json_object_add_uint (node, "id", ntohl (mp->id));
8430 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8431 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
8432 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
8433 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8434 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8435 vat_json_object_add_string_copy (node, "host_mac_addr",
8436 format (0, "%U", format_ethernet_address,
8437 &mp->host_mac_addr));
8438 vat_json_object_add_string_copy (node, "host_namespace",
8439 mp->host_namespace);
8440 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
8441 vat_json_object_add_string_copy (node, "host_ip4_addr",
8442 format (0, "%U/%d", format_ip4_address,
8443 mp->host_ip4_prefix.address,
8444 mp->host_ip4_prefix.len));
8445 vat_json_object_add_string_copy (node, "host_ip6_prefix",
8446 format (0, "%U/%d", format_ip6_address,
8447 mp->host_ip6_prefix.address,
8448 mp->host_ip6_prefix.len));
8453 api_sw_interface_tap_v2_dump (vat_main_t * vam)
8455 vl_api_sw_interface_tap_v2_dump_t *mp;
8456 vl_api_control_ping_t *mp_ping;
8460 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
8461 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
8462 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
8465 /* Get list of tap interfaces */
8466 M (SW_INTERFACE_TAP_V2_DUMP, mp);
8469 /* Use a control ping for synchronization */
8470 MPING (CONTROL_PING, mp_ping);
8477 static void vl_api_sw_interface_virtio_pci_details_t_handler
8478 (vl_api_sw_interface_virtio_pci_details_t * mp)
8480 vat_main_t *vam = &vat_main;
8495 addr.domain = ntohs (mp->pci_addr.domain);
8496 addr.bus = mp->pci_addr.bus;
8497 addr.slot = mp->pci_addr.slot;
8498 addr.function = mp->pci_addr.function;
8500 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
8501 addr.slot, addr.function);
8504 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
8505 pci_addr, ntohl (mp->sw_if_index),
8506 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8507 format_ethernet_address, mp->mac_addr,
8508 clib_net_to_host_u64 (mp->features));
8509 vec_free (pci_addr);
8512 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
8513 (vl_api_sw_interface_virtio_pci_details_t * mp)
8515 vat_main_t *vam = &vat_main;
8516 vat_json_node_t *node = NULL;
8517 vlib_pci_addr_t pci_addr;
8519 if (VAT_JSON_ARRAY != vam->json_tree.type)
8521 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8522 vat_json_init_array (&vam->json_tree);
8524 node = vat_json_array_add (&vam->json_tree);
8526 pci_addr.domain = ntohs (mp->pci_addr.domain);
8527 pci_addr.bus = mp->pci_addr.bus;
8528 pci_addr.slot = mp->pci_addr.slot;
8529 pci_addr.function = mp->pci_addr.function;
8531 vat_json_init_object (node);
8532 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
8533 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8534 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8535 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8536 vat_json_object_add_uint (node, "features",
8537 clib_net_to_host_u64 (mp->features));
8538 vat_json_object_add_string_copy (node, "mac_addr",
8539 format (0, "%U", format_ethernet_address,
8544 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
8546 vl_api_sw_interface_virtio_pci_dump_t *mp;
8547 vl_api_control_ping_t *mp_ping;
8551 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
8552 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
8553 "mac_addr", "features");
8555 /* Get list of tap interfaces */
8556 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
8559 /* Use a control ping for synchronization */
8560 MPING (CONTROL_PING, mp_ping);
8568 api_vxlan_offload_rx (vat_main_t * vam)
8570 unformat_input_t *line_input = vam->input;
8571 vl_api_vxlan_offload_rx_t *mp;
8572 u32 hw_if_index = ~0, rx_if_index = ~0;
8576 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8578 if (unformat (line_input, "del"))
8580 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
8583 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
8585 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
8588 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
8592 errmsg ("parse error '%U'", format_unformat_error, line_input);
8597 if (hw_if_index == ~0)
8599 errmsg ("no hw interface");
8603 if (rx_if_index == ~0)
8605 errmsg ("no rx tunnel");
8609 M (VXLAN_OFFLOAD_RX, mp);
8611 mp->hw_if_index = ntohl (hw_if_index);
8612 mp->sw_if_index = ntohl (rx_if_index);
8613 mp->enable = is_add;
8620 static uword unformat_vxlan_decap_next
8621 (unformat_input_t * input, va_list * args)
8623 u32 *result = va_arg (*args, u32 *);
8626 if (unformat (input, "l2"))
8627 *result = VXLAN_INPUT_NEXT_L2_INPUT;
8628 else if (unformat (input, "%d", &tmp))
8636 api_vxlan_add_del_tunnel (vat_main_t * vam)
8638 unformat_input_t *line_input = vam->input;
8639 vl_api_vxlan_add_del_tunnel_t *mp;
8640 ip46_address_t src, dst;
8642 u8 ipv4_set = 0, ipv6_set = 0;
8647 u32 mcast_sw_if_index = ~0;
8648 u32 encap_vrf_id = 0;
8649 u32 decap_next_index = ~0;
8653 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
8654 clib_memset (&src, 0, sizeof src);
8655 clib_memset (&dst, 0, sizeof dst);
8657 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8659 if (unformat (line_input, "del"))
8661 else if (unformat (line_input, "instance %d", &instance))
8664 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
8670 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
8676 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
8682 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
8687 else if (unformat (line_input, "group %U %U",
8688 unformat_ip4_address, &dst.ip4,
8689 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
8691 grp_set = dst_set = 1;
8694 else if (unformat (line_input, "group %U",
8695 unformat_ip4_address, &dst.ip4))
8697 grp_set = dst_set = 1;
8700 else if (unformat (line_input, "group %U %U",
8701 unformat_ip6_address, &dst.ip6,
8702 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
8704 grp_set = dst_set = 1;
8707 else if (unformat (line_input, "group %U",
8708 unformat_ip6_address, &dst.ip6))
8710 grp_set = dst_set = 1;
8714 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
8716 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8718 else if (unformat (line_input, "decap-next %U",
8719 unformat_vxlan_decap_next, &decap_next_index))
8721 else if (unformat (line_input, "vni %d", &vni))
8725 errmsg ("parse error '%U'", format_unformat_error, line_input);
8732 errmsg ("tunnel src address not specified");
8737 errmsg ("tunnel dst address not specified");
8741 if (grp_set && !ip46_address_is_multicast (&dst))
8743 errmsg ("tunnel group address not multicast");
8746 if (grp_set && mcast_sw_if_index == ~0)
8748 errmsg ("tunnel nonexistent multicast device");
8751 if (grp_set == 0 && ip46_address_is_multicast (&dst))
8753 errmsg ("tunnel dst address must be unicast");
8758 if (ipv4_set && ipv6_set)
8760 errmsg ("both IPv4 and IPv6 addresses specified");
8764 if ((vni == 0) || (vni >> 24))
8766 errmsg ("vni not specified or out of range");
8770 M (VXLAN_ADD_DEL_TUNNEL, mp);
8774 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
8775 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
8779 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
8780 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
8782 mp->src_address.af = ipv6_set;
8783 mp->dst_address.af = ipv6_set;
8785 mp->instance = htonl (instance);
8786 mp->encap_vrf_id = ntohl (encap_vrf_id);
8787 mp->decap_next_index = ntohl (decap_next_index);
8788 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
8789 mp->vni = ntohl (vni);
8790 mp->is_add = is_add;
8797 static void vl_api_vxlan_tunnel_details_t_handler
8798 (vl_api_vxlan_tunnel_details_t * mp)
8800 vat_main_t *vam = &vat_main;
8801 ip46_address_t src =
8802 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
8803 ip46_address_t dst =
8804 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
8806 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
8807 ntohl (mp->sw_if_index),
8808 ntohl (mp->instance),
8809 format_ip46_address, &src, IP46_TYPE_ANY,
8810 format_ip46_address, &dst, IP46_TYPE_ANY,
8811 ntohl (mp->encap_vrf_id),
8812 ntohl (mp->decap_next_index), ntohl (mp->vni),
8813 ntohl (mp->mcast_sw_if_index));
8816 static void vl_api_vxlan_tunnel_details_t_handler_json
8817 (vl_api_vxlan_tunnel_details_t * mp)
8819 vat_main_t *vam = &vat_main;
8820 vat_json_node_t *node = NULL;
8822 if (VAT_JSON_ARRAY != vam->json_tree.type)
8824 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8825 vat_json_init_array (&vam->json_tree);
8827 node = vat_json_array_add (&vam->json_tree);
8829 vat_json_init_object (node);
8830 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8832 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
8834 if (mp->src_address.af)
8836 struct in6_addr ip6;
8838 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
8839 vat_json_object_add_ip6 (node, "src_address", ip6);
8840 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
8841 vat_json_object_add_ip6 (node, "dst_address", ip6);
8847 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
8848 vat_json_object_add_ip4 (node, "src_address", ip4);
8849 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
8850 vat_json_object_add_ip4 (node, "dst_address", ip4);
8852 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
8853 vat_json_object_add_uint (node, "decap_next_index",
8854 ntohl (mp->decap_next_index));
8855 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
8856 vat_json_object_add_uint (node, "mcast_sw_if_index",
8857 ntohl (mp->mcast_sw_if_index));
8861 api_vxlan_tunnel_dump (vat_main_t * vam)
8863 unformat_input_t *i = vam->input;
8864 vl_api_vxlan_tunnel_dump_t *mp;
8865 vl_api_control_ping_t *mp_ping;
8867 u8 sw_if_index_set = 0;
8870 /* Parse args required to build the message */
8871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8873 if (unformat (i, "sw_if_index %d", &sw_if_index))
8874 sw_if_index_set = 1;
8879 if (sw_if_index_set == 0)
8884 if (!vam->json_output)
8886 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
8887 "sw_if_index", "instance", "src_address", "dst_address",
8888 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
8891 /* Get list of vxlan-tunnel interfaces */
8892 M (VXLAN_TUNNEL_DUMP, mp);
8894 mp->sw_if_index = htonl (sw_if_index);
8898 /* Use a control ping for synchronization */
8899 MPING (CONTROL_PING, mp_ping);
8907 api_l2_fib_clear_table (vat_main_t * vam)
8909 // unformat_input_t * i = vam->input;
8910 vl_api_l2_fib_clear_table_t *mp;
8913 M (L2_FIB_CLEAR_TABLE, mp);
8921 api_l2_interface_efp_filter (vat_main_t * vam)
8923 unformat_input_t *i = vam->input;
8924 vl_api_l2_interface_efp_filter_t *mp;
8927 u8 sw_if_index_set = 0;
8930 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8932 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8933 sw_if_index_set = 1;
8934 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8935 sw_if_index_set = 1;
8936 else if (unformat (i, "enable"))
8938 else if (unformat (i, "disable"))
8942 clib_warning ("parse error '%U'", format_unformat_error, i);
8947 if (sw_if_index_set == 0)
8949 errmsg ("missing sw_if_index");
8953 M (L2_INTERFACE_EFP_FILTER, mp);
8955 mp->sw_if_index = ntohl (sw_if_index);
8956 mp->enable_disable = enable;
8963 #define foreach_vtr_op \
8964 _("disable", L2_VTR_DISABLED) \
8965 _("push-1", L2_VTR_PUSH_1) \
8966 _("push-2", L2_VTR_PUSH_2) \
8967 _("pop-1", L2_VTR_POP_1) \
8968 _("pop-2", L2_VTR_POP_2) \
8969 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8970 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8971 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8972 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8975 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8977 unformat_input_t *i = vam->input;
8978 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8980 u8 sw_if_index_set = 0;
8988 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8990 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8991 sw_if_index_set = 1;
8992 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8993 sw_if_index_set = 1;
8994 else if (unformat (i, "vtr_op %d", &vtr_op))
8996 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8999 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9001 else if (unformat (i, "tag1 %d", &tag1))
9003 else if (unformat (i, "tag2 %d", &tag2))
9007 clib_warning ("parse error '%U'", format_unformat_error, i);
9012 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9014 errmsg ("missing vtr operation or sw_if_index");
9018 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9019 mp->sw_if_index = ntohl (sw_if_index);
9020 mp->vtr_op = ntohl (vtr_op);
9021 mp->push_dot1q = ntohl (push_dot1q);
9022 mp->tag1 = ntohl (tag1);
9023 mp->tag2 = ntohl (tag2);
9031 api_create_vhost_user_if (vat_main_t * vam)
9033 unformat_input_t *i = vam->input;
9034 vl_api_create_vhost_user_if_t *mp;
9037 u8 file_name_set = 0;
9038 u32 custom_dev_instance = ~0;
9040 u8 use_custom_mac = 0;
9041 u8 disable_mrg_rxbuf = 0;
9042 u8 disable_indirect_desc = 0;
9045 u8 enable_packed = 0;
9048 /* Shut up coverity */
9049 clib_memset (hwaddr, 0, sizeof (hwaddr));
9051 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9053 if (unformat (i, "socket %s", &file_name))
9057 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9059 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9061 else if (unformat (i, "server"))
9063 else if (unformat (i, "disable_mrg_rxbuf"))
9064 disable_mrg_rxbuf = 1;
9065 else if (unformat (i, "disable_indirect_desc"))
9066 disable_indirect_desc = 1;
9067 else if (unformat (i, "gso"))
9069 else if (unformat (i, "packed"))
9071 else if (unformat (i, "tag %s", &tag))
9077 if (file_name_set == 0)
9079 errmsg ("missing socket file name");
9083 if (vec_len (file_name) > 255)
9085 errmsg ("socket file name too long");
9088 vec_add1 (file_name, 0);
9090 M (CREATE_VHOST_USER_IF, mp);
9092 mp->is_server = is_server;
9093 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9094 mp->disable_indirect_desc = disable_indirect_desc;
9095 mp->enable_gso = enable_gso;
9096 mp->enable_packed = enable_packed;
9097 mp->custom_dev_instance = ntohl (custom_dev_instance);
9098 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9099 vec_free (file_name);
9100 if (custom_dev_instance != ~0)
9103 mp->use_custom_mac = use_custom_mac;
9104 clib_memcpy (mp->mac_address, hwaddr, 6);
9106 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9115 api_modify_vhost_user_if (vat_main_t * vam)
9117 unformat_input_t *i = vam->input;
9118 vl_api_modify_vhost_user_if_t *mp;
9121 u8 file_name_set = 0;
9122 u32 custom_dev_instance = ~0;
9123 u8 sw_if_index_set = 0;
9124 u32 sw_if_index = (u32) ~ 0;
9126 u8 enable_packed = 0;
9129 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9131 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9132 sw_if_index_set = 1;
9133 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9134 sw_if_index_set = 1;
9135 else if (unformat (i, "socket %s", &file_name))
9139 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9141 else if (unformat (i, "server"))
9143 else if (unformat (i, "gso"))
9145 else if (unformat (i, "packed"))
9151 if (sw_if_index_set == 0)
9153 errmsg ("missing sw_if_index or interface name");
9157 if (file_name_set == 0)
9159 errmsg ("missing socket file name");
9163 if (vec_len (file_name) > 255)
9165 errmsg ("socket file name too long");
9168 vec_add1 (file_name, 0);
9170 M (MODIFY_VHOST_USER_IF, mp);
9172 mp->sw_if_index = ntohl (sw_if_index);
9173 mp->is_server = is_server;
9174 mp->enable_gso = enable_gso;
9175 mp->enable_packed = enable_packed;
9176 mp->custom_dev_instance = ntohl (custom_dev_instance);
9177 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9178 vec_free (file_name);
9179 if (custom_dev_instance != ~0)
9188 api_create_vhost_user_if_v2 (vat_main_t * vam)
9190 unformat_input_t *i = vam->input;
9191 vl_api_create_vhost_user_if_v2_t *mp;
9194 u8 file_name_set = 0;
9195 u32 custom_dev_instance = ~0;
9197 u8 use_custom_mac = 0;
9198 u8 disable_mrg_rxbuf = 0;
9199 u8 disable_indirect_desc = 0;
9202 u8 enable_packed = 0;
9203 u8 enable_event_idx = 0;
9206 /* Shut up coverity */
9207 clib_memset (hwaddr, 0, sizeof (hwaddr));
9209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9211 if (unformat (i, "socket %s", &file_name))
9215 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9217 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9219 else if (unformat (i, "server"))
9221 else if (unformat (i, "disable_mrg_rxbuf"))
9222 disable_mrg_rxbuf = 1;
9223 else if (unformat (i, "disable_indirect_desc"))
9224 disable_indirect_desc = 1;
9225 else if (unformat (i, "gso"))
9227 else if (unformat (i, "packed"))
9229 else if (unformat (i, "event-idx"))
9230 enable_event_idx = 1;
9231 else if (unformat (i, "tag %s", &tag))
9237 if (file_name_set == 0)
9239 errmsg ("missing socket file name");
9243 if (vec_len (file_name) > 255)
9245 errmsg ("socket file name too long");
9248 vec_add1 (file_name, 0);
9250 M (CREATE_VHOST_USER_IF_V2, mp);
9252 mp->is_server = is_server;
9253 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9254 mp->disable_indirect_desc = disable_indirect_desc;
9255 mp->enable_gso = enable_gso;
9256 mp->enable_packed = enable_packed;
9257 mp->enable_event_idx = enable_event_idx;
9258 mp->custom_dev_instance = ntohl (custom_dev_instance);
9259 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9260 vec_free (file_name);
9261 if (custom_dev_instance != ~0)
9264 mp->use_custom_mac = use_custom_mac;
9265 clib_memcpy (mp->mac_address, hwaddr, 6);
9267 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9276 api_modify_vhost_user_if_v2 (vat_main_t * vam)
9278 unformat_input_t *i = vam->input;
9279 vl_api_modify_vhost_user_if_v2_t *mp;
9282 u8 file_name_set = 0;
9283 u32 custom_dev_instance = ~0;
9284 u8 sw_if_index_set = 0;
9285 u32 sw_if_index = (u32) ~ 0;
9287 u8 enable_packed = 0;
9288 u8 enable_event_idx = 0;
9291 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9293 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9294 sw_if_index_set = 1;
9295 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9296 sw_if_index_set = 1;
9297 else if (unformat (i, "socket %s", &file_name))
9301 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9303 else if (unformat (i, "server"))
9305 else if (unformat (i, "gso"))
9307 else if (unformat (i, "packed"))
9309 else if (unformat (i, "event-idx"))
9310 enable_event_idx = 1;
9315 if (sw_if_index_set == 0)
9317 errmsg ("missing sw_if_index or interface name");
9321 if (file_name_set == 0)
9323 errmsg ("missing socket file name");
9327 if (vec_len (file_name) > 255)
9329 errmsg ("socket file name too long");
9332 vec_add1 (file_name, 0);
9334 M (MODIFY_VHOST_USER_IF_V2, mp);
9336 mp->sw_if_index = ntohl (sw_if_index);
9337 mp->is_server = is_server;
9338 mp->enable_gso = enable_gso;
9339 mp->enable_packed = enable_packed;
9340 mp->enable_event_idx = enable_event_idx;
9341 mp->custom_dev_instance = ntohl (custom_dev_instance);
9342 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9343 vec_free (file_name);
9344 if (custom_dev_instance != ~0)
9353 api_delete_vhost_user_if (vat_main_t * vam)
9355 unformat_input_t *i = vam->input;
9356 vl_api_delete_vhost_user_if_t *mp;
9357 u32 sw_if_index = ~0;
9358 u8 sw_if_index_set = 0;
9361 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9363 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9364 sw_if_index_set = 1;
9365 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9366 sw_if_index_set = 1;
9371 if (sw_if_index_set == 0)
9373 errmsg ("missing sw_if_index or interface name");
9378 M (DELETE_VHOST_USER_IF, mp);
9380 mp->sw_if_index = ntohl (sw_if_index);
9387 static void vl_api_sw_interface_vhost_user_details_t_handler
9388 (vl_api_sw_interface_vhost_user_details_t * mp)
9390 vat_main_t *vam = &vat_main;
9394 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
9395 clib_net_to_host_u32
9396 (mp->features_last_32) <<
9399 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
9400 (char *) mp->interface_name, ntohl (mp->sw_if_index),
9401 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
9402 ntohl (mp->num_regions), (char *) mp->sock_filename);
9403 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
9406 static void vl_api_sw_interface_vhost_user_details_t_handler_json
9407 (vl_api_sw_interface_vhost_user_details_t * mp)
9409 vat_main_t *vam = &vat_main;
9410 vat_json_node_t *node = NULL;
9412 if (VAT_JSON_ARRAY != vam->json_tree.type)
9414 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9415 vat_json_init_array (&vam->json_tree);
9417 node = vat_json_array_add (&vam->json_tree);
9419 vat_json_init_object (node);
9420 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9421 vat_json_object_add_string_copy (node, "interface_name",
9422 mp->interface_name);
9423 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
9424 ntohl (mp->virtio_net_hdr_sz));
9425 vat_json_object_add_uint (node, "features_first_32",
9426 clib_net_to_host_u32 (mp->features_first_32));
9427 vat_json_object_add_uint (node, "features_last_32",
9428 clib_net_to_host_u32 (mp->features_last_32));
9429 vat_json_object_add_uint (node, "is_server", mp->is_server);
9430 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
9431 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
9432 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
9436 api_sw_interface_vhost_user_dump (vat_main_t * vam)
9438 unformat_input_t *i = vam->input;
9439 vl_api_sw_interface_vhost_user_dump_t *mp;
9440 vl_api_control_ping_t *mp_ping;
9442 u32 sw_if_index = ~0;
9444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9446 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9448 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9454 print (vam->ofp, "Interface name idx hdr_sz features "
9455 "server regions filename");
9457 /* Get list of vhost-user interfaces */
9458 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
9459 mp->sw_if_index = ntohl (sw_if_index);
9462 /* Use a control ping for synchronization */
9463 MPING (CONTROL_PING, mp_ping);
9471 api_show_version (vat_main_t * vam)
9473 vl_api_show_version_t *mp;
9476 M (SHOW_VERSION, mp);
9485 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
9487 unformat_input_t *line_input = vam->input;
9488 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
9489 ip46_address_t local, remote;
9494 u32 mcast_sw_if_index = ~0;
9495 u32 encap_vrf_id = 0;
9496 u32 decap_vrf_id = 0;
9502 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9504 if (unformat (line_input, "del"))
9506 else if (unformat (line_input, "local %U",
9507 unformat_ip46_address, &local))
9511 else if (unformat (line_input, "remote %U",
9512 unformat_ip46_address, &remote))
9516 else if (unformat (line_input, "group %U %U",
9517 unformat_ip46_address, &remote,
9518 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9520 grp_set = remote_set = 1;
9522 else if (unformat (line_input, "group %U",
9523 unformat_ip46_address, &remote))
9525 grp_set = remote_set = 1;
9528 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9530 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9532 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
9534 else if (unformat (line_input, "vni %d", &vni))
9536 else if (unformat (line_input, "next-ip4"))
9538 else if (unformat (line_input, "next-ip6"))
9540 else if (unformat (line_input, "next-ethernet"))
9542 else if (unformat (line_input, "next-nsh"))
9546 errmsg ("parse error '%U'", format_unformat_error, line_input);
9553 errmsg ("tunnel local address not specified");
9556 if (remote_set == 0)
9558 errmsg ("tunnel remote address not specified");
9561 if (grp_set && mcast_sw_if_index == ~0)
9563 errmsg ("tunnel nonexistent multicast device");
9566 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
9568 errmsg ("both IPv4 and IPv6 addresses specified");
9574 errmsg ("vni not specified");
9578 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
9580 ip_address_encode (&local,
9581 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
9582 IP46_TYPE_IP6, &mp->local);
9583 ip_address_encode (&remote,
9584 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
9585 IP46_TYPE_IP6, &mp->remote);
9587 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9588 mp->encap_vrf_id = ntohl (encap_vrf_id);
9589 mp->decap_vrf_id = ntohl (decap_vrf_id);
9590 mp->protocol = protocol;
9591 mp->vni = ntohl (vni);
9592 mp->is_add = is_add;
9599 static void vl_api_vxlan_gpe_tunnel_details_t_handler
9600 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9602 vat_main_t *vam = &vat_main;
9603 ip46_address_t local, remote;
9605 ip_address_decode (&mp->local, &local);
9606 ip_address_decode (&mp->remote, &remote);
9608 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
9609 ntohl (mp->sw_if_index),
9610 format_ip46_address, &local, IP46_TYPE_ANY,
9611 format_ip46_address, &remote, IP46_TYPE_ANY,
9612 ntohl (mp->vni), mp->protocol,
9613 ntohl (mp->mcast_sw_if_index),
9614 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
9618 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
9619 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9621 vat_main_t *vam = &vat_main;
9622 vat_json_node_t *node = NULL;
9624 struct in6_addr ip6;
9625 ip46_address_t local, remote;
9627 ip_address_decode (&mp->local, &local);
9628 ip_address_decode (&mp->remote, &remote);
9630 if (VAT_JSON_ARRAY != vam->json_tree.type)
9632 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9633 vat_json_init_array (&vam->json_tree);
9635 node = vat_json_array_add (&vam->json_tree);
9637 vat_json_init_object (node);
9638 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9639 if (ip46_address_is_ip4 (&local))
9641 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
9642 vat_json_object_add_ip4 (node, "local", ip4);
9643 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
9644 vat_json_object_add_ip4 (node, "remote", ip4);
9648 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
9649 vat_json_object_add_ip6 (node, "local", ip6);
9650 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
9651 vat_json_object_add_ip6 (node, "remote", ip6);
9653 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9654 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
9655 vat_json_object_add_uint (node, "mcast_sw_if_index",
9656 ntohl (mp->mcast_sw_if_index));
9657 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9658 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
9659 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
9663 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
9665 unformat_input_t *i = vam->input;
9666 vl_api_vxlan_gpe_tunnel_dump_t *mp;
9667 vl_api_control_ping_t *mp_ping;
9669 u8 sw_if_index_set = 0;
9672 /* Parse args required to build the message */
9673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9675 if (unformat (i, "sw_if_index %d", &sw_if_index))
9676 sw_if_index_set = 1;
9681 if (sw_if_index_set == 0)
9686 if (!vam->json_output)
9688 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
9689 "sw_if_index", "local", "remote", "vni",
9690 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
9693 /* Get list of vxlan-tunnel interfaces */
9694 M (VXLAN_GPE_TUNNEL_DUMP, mp);
9696 mp->sw_if_index = htonl (sw_if_index);
9700 /* Use a control ping for synchronization */
9701 MPING (CONTROL_PING, mp_ping);
9708 static void vl_api_l2_fib_table_details_t_handler
9709 (vl_api_l2_fib_table_details_t * mp)
9711 vat_main_t *vam = &vat_main;
9713 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
9715 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
9716 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
9720 static void vl_api_l2_fib_table_details_t_handler_json
9721 (vl_api_l2_fib_table_details_t * mp)
9723 vat_main_t *vam = &vat_main;
9724 vat_json_node_t *node = NULL;
9726 if (VAT_JSON_ARRAY != vam->json_tree.type)
9728 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9729 vat_json_init_array (&vam->json_tree);
9731 node = vat_json_array_add (&vam->json_tree);
9733 vat_json_init_object (node);
9734 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
9735 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
9736 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9737 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
9738 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
9739 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
9743 api_l2_fib_table_dump (vat_main_t * vam)
9745 unformat_input_t *i = vam->input;
9746 vl_api_l2_fib_table_dump_t *mp;
9747 vl_api_control_ping_t *mp_ping;
9752 /* Parse args required to build the message */
9753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9755 if (unformat (i, "bd_id %d", &bd_id))
9763 errmsg ("missing bridge domain");
9767 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
9769 /* Get list of l2 fib entries */
9770 M (L2_FIB_TABLE_DUMP, mp);
9772 mp->bd_id = ntohl (bd_id);
9775 /* Use a control ping for synchronization */
9776 MPING (CONTROL_PING, mp_ping);
9785 api_interface_name_renumber (vat_main_t * vam)
9787 unformat_input_t *line_input = vam->input;
9788 vl_api_interface_name_renumber_t *mp;
9789 u32 sw_if_index = ~0;
9790 u32 new_show_dev_instance = ~0;
9793 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9795 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
9798 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9800 else if (unformat (line_input, "new_show_dev_instance %d",
9801 &new_show_dev_instance))
9807 if (sw_if_index == ~0)
9809 errmsg ("missing interface name or sw_if_index");
9813 if (new_show_dev_instance == ~0)
9815 errmsg ("missing new_show_dev_instance");
9819 M (INTERFACE_NAME_RENUMBER, mp);
9821 mp->sw_if_index = ntohl (sw_if_index);
9822 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
9830 api_want_l2_macs_events (vat_main_t * vam)
9832 unformat_input_t *line_input = vam->input;
9833 vl_api_want_l2_macs_events_t *mp;
9834 u8 enable_disable = 1;
9836 u32 max_macs_in_event = 0;
9837 u32 learn_limit = 0;
9840 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9842 if (unformat (line_input, "learn-limit %d", &learn_limit))
9844 else if (unformat (line_input, "scan-delay %d", &scan_delay))
9846 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
9848 else if (unformat (line_input, "disable"))
9854 M (WANT_L2_MACS_EVENTS, mp);
9855 mp->enable_disable = enable_disable;
9856 mp->pid = htonl (getpid ());
9857 mp->learn_limit = htonl (learn_limit);
9858 mp->scan_delay = (u8) scan_delay;
9859 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
9866 api_ip_address_dump (vat_main_t * vam)
9868 unformat_input_t *i = vam->input;
9869 vl_api_ip_address_dump_t *mp;
9870 vl_api_control_ping_t *mp_ping;
9871 u32 sw_if_index = ~0;
9872 u8 sw_if_index_set = 0;
9877 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9879 if (unformat (i, "sw_if_index %d", &sw_if_index))
9880 sw_if_index_set = 1;
9882 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9883 sw_if_index_set = 1;
9884 else if (unformat (i, "ipv4"))
9886 else if (unformat (i, "ipv6"))
9892 if (ipv4_set && ipv6_set)
9894 errmsg ("ipv4 and ipv6 flags cannot be both set");
9898 if ((!ipv4_set) && (!ipv6_set))
9900 errmsg ("no ipv4 nor ipv6 flag set");
9904 if (sw_if_index_set == 0)
9906 errmsg ("missing interface name or sw_if_index");
9910 vam->current_sw_if_index = sw_if_index;
9911 vam->is_ipv6 = ipv6_set;
9913 M (IP_ADDRESS_DUMP, mp);
9914 mp->sw_if_index = ntohl (sw_if_index);
9915 mp->is_ipv6 = ipv6_set;
9918 /* Use a control ping for synchronization */
9919 MPING (CONTROL_PING, mp_ping);
9927 api_ip_dump (vat_main_t * vam)
9929 vl_api_ip_dump_t *mp;
9930 vl_api_control_ping_t *mp_ping;
9931 unformat_input_t *in = vam->input;
9938 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
9940 if (unformat (in, "ipv4"))
9942 else if (unformat (in, "ipv6"))
9948 if (ipv4_set && ipv6_set)
9950 errmsg ("ipv4 and ipv6 flags cannot be both set");
9954 if ((!ipv4_set) && (!ipv6_set))
9956 errmsg ("no ipv4 nor ipv6 flag set");
9961 vam->is_ipv6 = is_ipv6;
9964 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
9966 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9968 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
9971 mp->is_ipv6 = ipv6_set;
9974 /* Use a control ping for synchronization */
9975 MPING (CONTROL_PING, mp_ping);
9983 api_ipsec_spd_add_del (vat_main_t * vam)
9985 unformat_input_t *i = vam->input;
9986 vl_api_ipsec_spd_add_del_t *mp;
9991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9993 if (unformat (i, "spd_id %d", &spd_id))
9995 else if (unformat (i, "del"))
9999 clib_warning ("parse error '%U'", format_unformat_error, i);
10005 errmsg ("spd_id must be set");
10009 M (IPSEC_SPD_ADD_DEL, mp);
10011 mp->spd_id = ntohl (spd_id);
10012 mp->is_add = is_add;
10020 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10022 unformat_input_t *i = vam->input;
10023 vl_api_ipsec_interface_add_del_spd_t *mp;
10025 u8 sw_if_index_set = 0;
10026 u32 spd_id = (u32) ~ 0;
10030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10032 if (unformat (i, "del"))
10034 else if (unformat (i, "spd_id %d", &spd_id))
10037 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10038 sw_if_index_set = 1;
10039 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10040 sw_if_index_set = 1;
10043 clib_warning ("parse error '%U'", format_unformat_error, i);
10049 if (spd_id == (u32) ~ 0)
10051 errmsg ("spd_id must be set");
10055 if (sw_if_index_set == 0)
10057 errmsg ("missing interface name or sw_if_index");
10061 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10063 mp->spd_id = ntohl (spd_id);
10064 mp->sw_if_index = ntohl (sw_if_index);
10065 mp->is_add = is_add;
10073 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10075 unformat_input_t *i = vam->input;
10076 vl_api_ipsec_spd_entry_add_del_t *mp;
10077 u8 is_add = 1, is_outbound = 0;
10078 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10080 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10081 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10082 vl_api_address_t laddr_start = { }, laddr_stop =
10091 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10093 if (unformat (i, "del"))
10095 if (unformat (i, "outbound"))
10097 if (unformat (i, "inbound"))
10099 else if (unformat (i, "spd_id %d", &spd_id))
10101 else if (unformat (i, "sa_id %d", &sa_id))
10103 else if (unformat (i, "priority %d", &priority))
10105 else if (unformat (i, "protocol %d", &protocol))
10107 else if (unformat (i, "lport_start %d", &lport_start))
10109 else if (unformat (i, "lport_stop %d", &lport_stop))
10111 else if (unformat (i, "rport_start %d", &rport_start))
10113 else if (unformat (i, "rport_stop %d", &rport_stop))
10115 else if (unformat (i, "laddr_start %U",
10116 unformat_vl_api_address, &laddr_start))
10118 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
10121 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
10124 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
10128 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
10130 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
10132 clib_warning ("unsupported action: 'resolve'");
10138 clib_warning ("parse error '%U'", format_unformat_error, i);
10144 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
10146 mp->is_add = is_add;
10148 mp->entry.spd_id = ntohl (spd_id);
10149 mp->entry.priority = ntohl (priority);
10150 mp->entry.is_outbound = is_outbound;
10152 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
10153 sizeof (vl_api_address_t));
10154 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
10155 sizeof (vl_api_address_t));
10156 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
10157 sizeof (vl_api_address_t));
10158 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
10159 sizeof (vl_api_address_t));
10161 mp->entry.protocol = (u8) protocol;
10162 mp->entry.local_port_start = ntohs ((u16) lport_start);
10163 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
10164 mp->entry.remote_port_start = ntohs ((u16) rport_start);
10165 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
10166 mp->entry.policy = (u8) policy;
10167 mp->entry.sa_id = ntohl (sa_id);
10175 api_ipsec_sad_entry_add_del (vat_main_t * vam)
10177 unformat_input_t *i = vam->input;
10178 vl_api_ipsec_sad_entry_add_del_t *mp;
10179 u32 sad_id = 0, spi = 0;
10180 u8 *ck = 0, *ik = 0;
10183 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
10184 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
10185 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
10186 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
10187 vl_api_address_t tun_src, tun_dst;
10190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10192 if (unformat (i, "del"))
10194 else if (unformat (i, "sad_id %d", &sad_id))
10196 else if (unformat (i, "spi %d", &spi))
10198 else if (unformat (i, "esp"))
10199 protocol = IPSEC_API_PROTO_ESP;
10201 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
10203 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
10204 if (ADDRESS_IP6 == tun_src.af)
10205 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
10208 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
10210 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
10211 if (ADDRESS_IP6 == tun_src.af)
10212 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
10215 if (unformat (i, "crypto_alg %U",
10216 unformat_ipsec_api_crypto_alg, &crypto_alg))
10218 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
10220 else if (unformat (i, "integ_alg %U",
10221 unformat_ipsec_api_integ_alg, &integ_alg))
10223 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
10227 clib_warning ("parse error '%U'", format_unformat_error, i);
10233 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
10235 mp->is_add = is_add;
10236 mp->entry.sad_id = ntohl (sad_id);
10237 mp->entry.protocol = protocol;
10238 mp->entry.spi = ntohl (spi);
10239 mp->entry.flags = flags;
10241 mp->entry.crypto_algorithm = crypto_alg;
10242 mp->entry.integrity_algorithm = integ_alg;
10243 mp->entry.crypto_key.length = vec_len (ck);
10244 mp->entry.integrity_key.length = vec_len (ik);
10246 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
10247 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
10249 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
10250 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
10253 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
10255 clib_memcpy (mp->entry.integrity_key.data, ik,
10256 mp->entry.integrity_key.length);
10258 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
10260 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
10261 sizeof (mp->entry.tunnel_src));
10262 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
10263 sizeof (mp->entry.tunnel_dst));
10272 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
10274 vat_main_t *vam = &vat_main;
10276 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
10277 "crypto_key %U integ_alg %u integ_key %U flags %x "
10278 "tunnel_src_addr %U tunnel_dst_addr %U "
10279 "salt %u seq_outbound %lu last_seq_inbound %lu "
10280 "replay_window %lu stat_index %u\n",
10281 ntohl (mp->entry.sad_id),
10282 ntohl (mp->sw_if_index),
10283 ntohl (mp->entry.spi),
10284 ntohl (mp->entry.protocol),
10285 ntohl (mp->entry.crypto_algorithm),
10286 format_hex_bytes, mp->entry.crypto_key.data,
10287 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
10288 format_hex_bytes, mp->entry.integrity_key.data,
10289 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
10290 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
10291 &mp->entry.tunnel_dst, ntohl (mp->salt),
10292 clib_net_to_host_u64 (mp->seq_outbound),
10293 clib_net_to_host_u64 (mp->last_seq_inbound),
10294 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
10297 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
10298 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
10300 static void vl_api_ipsec_sa_details_t_handler_json
10301 (vl_api_ipsec_sa_details_t * mp)
10303 vat_main_t *vam = &vat_main;
10304 vat_json_node_t *node = NULL;
10305 vl_api_ipsec_sad_flags_t flags;
10307 if (VAT_JSON_ARRAY != vam->json_tree.type)
10309 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10310 vat_json_init_array (&vam->json_tree);
10312 node = vat_json_array_add (&vam->json_tree);
10314 vat_json_init_object (node);
10315 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
10316 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10317 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
10318 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
10319 vat_json_object_add_uint (node, "crypto_alg",
10320 ntohl (mp->entry.crypto_algorithm));
10321 vat_json_object_add_uint (node, "integ_alg",
10322 ntohl (mp->entry.integrity_algorithm));
10323 flags = ntohl (mp->entry.flags);
10324 vat_json_object_add_uint (node, "use_esn",
10325 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
10326 vat_json_object_add_uint (node, "use_anti_replay",
10327 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
10328 vat_json_object_add_uint (node, "is_tunnel",
10329 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
10330 vat_json_object_add_uint (node, "is_tunnel_ip6",
10331 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
10332 vat_json_object_add_uint (node, "udp_encap",
10333 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
10334 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
10335 mp->entry.crypto_key.length);
10336 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
10337 mp->entry.integrity_key.length);
10338 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
10339 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
10340 vat_json_object_add_uint (node, "replay_window",
10341 clib_net_to_host_u64 (mp->replay_window));
10342 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
10346 api_ipsec_sa_dump (vat_main_t * vam)
10348 unformat_input_t *i = vam->input;
10349 vl_api_ipsec_sa_dump_t *mp;
10350 vl_api_control_ping_t *mp_ping;
10354 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10356 if (unformat (i, "sa_id %d", &sa_id))
10360 clib_warning ("parse error '%U'", format_unformat_error, i);
10365 M (IPSEC_SA_DUMP, mp);
10367 mp->sa_id = ntohl (sa_id);
10371 /* Use a control ping for synchronization */
10372 M (CONTROL_PING, mp_ping);
10380 api_get_first_msg_id (vat_main_t * vam)
10382 vl_api_get_first_msg_id_t *mp;
10383 unformat_input_t *i = vam->input;
10388 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10390 if (unformat (i, "client %s", &name))
10398 errmsg ("missing client name");
10401 vec_add1 (name, 0);
10403 if (vec_len (name) > 63)
10405 errmsg ("client name too long");
10409 M (GET_FIRST_MSG_ID, mp);
10410 clib_memcpy (mp->name, name, vec_len (name));
10417 api_get_node_graph (vat_main_t * vam)
10419 vl_api_get_node_graph_t *mp;
10422 M (GET_NODE_GRAPH, mp);
10426 /* Wait for the reply */
10432 api_af_packet_create (vat_main_t * vam)
10434 unformat_input_t *i = vam->input;
10435 vl_api_af_packet_create_t *mp;
10436 u8 *host_if_name = 0;
10438 u8 random_hw_addr = 1;
10441 clib_memset (hw_addr, 0, sizeof (hw_addr));
10443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10445 if (unformat (i, "name %s", &host_if_name))
10446 vec_add1 (host_if_name, 0);
10447 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10448 random_hw_addr = 0;
10453 if (!vec_len (host_if_name))
10455 errmsg ("host-interface name must be specified");
10459 if (vec_len (host_if_name) > 64)
10461 errmsg ("host-interface name too long");
10465 M (AF_PACKET_CREATE, mp);
10467 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10468 clib_memcpy (mp->hw_addr, hw_addr, 6);
10469 mp->use_random_hw_addr = random_hw_addr;
10470 vec_free (host_if_name);
10478 fprintf (vam->ofp ? vam->ofp : stderr,
10479 " new sw_if_index = %d\n", vam->sw_if_index);
10486 api_af_packet_delete (vat_main_t * vam)
10488 unformat_input_t *i = vam->input;
10489 vl_api_af_packet_delete_t *mp;
10490 u8 *host_if_name = 0;
10493 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10495 if (unformat (i, "name %s", &host_if_name))
10496 vec_add1 (host_if_name, 0);
10501 if (!vec_len (host_if_name))
10503 errmsg ("host-interface name must be specified");
10507 if (vec_len (host_if_name) > 64)
10509 errmsg ("host-interface name too long");
10513 M (AF_PACKET_DELETE, mp);
10515 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10516 vec_free (host_if_name);
10523 static void vl_api_af_packet_details_t_handler
10524 (vl_api_af_packet_details_t * mp)
10526 vat_main_t *vam = &vat_main;
10528 print (vam->ofp, "%-16s %d",
10529 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
10532 static void vl_api_af_packet_details_t_handler_json
10533 (vl_api_af_packet_details_t * mp)
10535 vat_main_t *vam = &vat_main;
10536 vat_json_node_t *node = NULL;
10538 if (VAT_JSON_ARRAY != vam->json_tree.type)
10540 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10541 vat_json_init_array (&vam->json_tree);
10543 node = vat_json_array_add (&vam->json_tree);
10545 vat_json_init_object (node);
10546 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10547 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
10551 api_af_packet_dump (vat_main_t * vam)
10553 vl_api_af_packet_dump_t *mp;
10554 vl_api_control_ping_t *mp_ping;
10557 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
10558 /* Get list of tap interfaces */
10559 M (AF_PACKET_DUMP, mp);
10562 /* Use a control ping for synchronization */
10563 MPING (CONTROL_PING, mp_ping);
10571 api_policer_add_del (vat_main_t * vam)
10573 unformat_input_t *i = vam->input;
10574 vl_api_policer_add_del_t *mp;
10584 u8 color_aware = 0;
10585 qos_pol_action_params_st conform_action, exceed_action, violate_action;
10588 conform_action.action_type = QOS_ACTION_TRANSMIT;
10589 conform_action.dscp = 0;
10590 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
10591 exceed_action.dscp = 0;
10592 violate_action.action_type = QOS_ACTION_DROP;
10593 violate_action.dscp = 0;
10595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10597 if (unformat (i, "del"))
10599 else if (unformat (i, "name %s", &name))
10600 vec_add1 (name, 0);
10601 else if (unformat (i, "cir %u", &cir))
10603 else if (unformat (i, "eir %u", &eir))
10605 else if (unformat (i, "cb %u", &cb))
10607 else if (unformat (i, "eb %u", &eb))
10609 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
10612 else if (unformat (i, "round_type %U", unformat_policer_round_type,
10615 else if (unformat (i, "type %U", unformat_policer_type, &type))
10617 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
10620 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
10623 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
10626 else if (unformat (i, "color-aware"))
10632 if (!vec_len (name))
10634 errmsg ("policer name must be specified");
10638 if (vec_len (name) > 64)
10640 errmsg ("policer name too long");
10644 M (POLICER_ADD_DEL, mp);
10646 clib_memcpy (mp->name, name, vec_len (name));
10648 mp->is_add = is_add;
10649 mp->cir = ntohl (cir);
10650 mp->eir = ntohl (eir);
10651 mp->cb = clib_net_to_host_u64 (cb);
10652 mp->eb = clib_net_to_host_u64 (eb);
10653 mp->rate_type = rate_type;
10654 mp->round_type = round_type;
10656 mp->conform_action.type =
10657 (vl_api_sse2_qos_action_type_t) conform_action.action_type;
10658 mp->conform_action.dscp = conform_action.dscp;
10659 mp->exceed_action.type =
10660 (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
10661 mp->exceed_action.dscp = exceed_action.dscp;
10662 mp->violate_action.type =
10663 (vl_api_sse2_qos_action_type_t) violate_action.action_type;
10664 mp->violate_action.dscp = violate_action.dscp;
10665 mp->color_aware = color_aware;
10673 api_policer_dump (vat_main_t * vam)
10675 unformat_input_t *i = vam->input;
10676 vl_api_policer_dump_t *mp;
10677 vl_api_control_ping_t *mp_ping;
10678 u8 *match_name = 0;
10679 u8 match_name_valid = 0;
10682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10684 if (unformat (i, "name %s", &match_name))
10686 vec_add1 (match_name, 0);
10687 match_name_valid = 1;
10693 M (POLICER_DUMP, mp);
10694 mp->match_name_valid = match_name_valid;
10695 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
10696 vec_free (match_name);
10700 /* Use a control ping for synchronization */
10701 MPING (CONTROL_PING, mp_ping);
10704 /* Wait for a reply... */
10710 format_fib_api_path_nh_proto (u8 * s, va_list * args)
10712 vl_api_fib_path_nh_proto_t proto =
10713 va_arg (*args, vl_api_fib_path_nh_proto_t);
10717 case FIB_API_PATH_NH_PROTO_IP4:
10718 s = format (s, "ip4");
10720 case FIB_API_PATH_NH_PROTO_IP6:
10721 s = format (s, "ip6");
10723 case FIB_API_PATH_NH_PROTO_MPLS:
10724 s = format (s, "mpls");
10726 case FIB_API_PATH_NH_PROTO_BIER:
10727 s = format (s, "bier");
10729 case FIB_API_PATH_NH_PROTO_ETHERNET:
10730 s = format (s, "ethernet");
10738 format_vl_api_ip_address_union (u8 * s, va_list * args)
10740 vl_api_address_family_t af = va_arg (*args, int);
10741 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
10746 s = format (s, "%U", format_ip4_address, u->ip4);
10749 s = format (s, "%U", format_ip6_address, u->ip6);
10756 format_vl_api_fib_path_type (u8 * s, va_list * args)
10758 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
10762 case FIB_API_PATH_TYPE_NORMAL:
10763 s = format (s, "normal");
10765 case FIB_API_PATH_TYPE_LOCAL:
10766 s = format (s, "local");
10768 case FIB_API_PATH_TYPE_DROP:
10769 s = format (s, "drop");
10771 case FIB_API_PATH_TYPE_UDP_ENCAP:
10772 s = format (s, "udp-encap");
10774 case FIB_API_PATH_TYPE_BIER_IMP:
10775 s = format (s, "bier-imp");
10777 case FIB_API_PATH_TYPE_ICMP_UNREACH:
10778 s = format (s, "unreach");
10780 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
10781 s = format (s, "prohibit");
10783 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
10784 s = format (s, "src-lookup");
10786 case FIB_API_PATH_TYPE_DVR:
10787 s = format (s, "dvr");
10789 case FIB_API_PATH_TYPE_INTERFACE_RX:
10790 s = format (s, "interface-rx");
10792 case FIB_API_PATH_TYPE_CLASSIFY:
10793 s = format (s, "classify");
10801 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
10804 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
10805 ntohl (fp->weight), ntohl (fp->sw_if_index),
10806 format_vl_api_fib_path_type, fp->type,
10807 format_fib_api_path_nh_proto, fp->proto,
10808 format_vl_api_ip_address_union, &fp->nh.address);
10812 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
10813 vl_api_fib_path_t * fp)
10815 struct in_addr ip4;
10816 struct in6_addr ip6;
10818 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
10819 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
10820 vat_json_object_add_uint (node, "type", fp->type);
10821 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
10822 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
10824 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
10825 vat_json_object_add_ip4 (node, "next_hop", ip4);
10827 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
10829 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
10830 vat_json_object_add_ip6 (node, "next_hop", ip6);
10835 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
10837 vat_main_t *vam = &vat_main;
10838 int count = ntohl (mp->mt_tunnel.mt_n_paths);
10839 vl_api_fib_path_t *fp;
10842 print (vam->ofp, "sw_if_index %d via:",
10843 ntohl (mp->mt_tunnel.mt_sw_if_index));
10844 fp = mp->mt_tunnel.mt_paths;
10845 for (i = 0; i < count; i++)
10847 vl_api_fib_path_print (vam, fp);
10851 print (vam->ofp, "");
10854 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
10855 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
10858 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
10860 vat_main_t *vam = &vat_main;
10861 vat_json_node_t *node = NULL;
10862 int count = ntohl (mp->mt_tunnel.mt_n_paths);
10863 vl_api_fib_path_t *fp;
10866 if (VAT_JSON_ARRAY != vam->json_tree.type)
10868 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10869 vat_json_init_array (&vam->json_tree);
10871 node = vat_json_array_add (&vam->json_tree);
10873 vat_json_init_object (node);
10874 vat_json_object_add_uint (node, "sw_if_index",
10875 ntohl (mp->mt_tunnel.mt_sw_if_index));
10877 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
10879 fp = mp->mt_tunnel.mt_paths;
10880 for (i = 0; i < count; i++)
10882 vl_api_mpls_fib_path_json_print (node, fp);
10888 api_mpls_tunnel_dump (vat_main_t * vam)
10890 vl_api_mpls_tunnel_dump_t *mp;
10891 vl_api_control_ping_t *mp_ping;
10894 M (MPLS_TUNNEL_DUMP, mp);
10898 /* Use a control ping for synchronization */
10899 MPING (CONTROL_PING, mp_ping);
10906 #define vl_api_mpls_table_details_t_endian vl_noop_handler
10907 #define vl_api_mpls_table_details_t_print vl_noop_handler
10911 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
10913 vat_main_t *vam = &vat_main;
10915 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
10918 static void vl_api_mpls_table_details_t_handler_json
10919 (vl_api_mpls_table_details_t * mp)
10921 vat_main_t *vam = &vat_main;
10922 vat_json_node_t *node = NULL;
10924 if (VAT_JSON_ARRAY != vam->json_tree.type)
10926 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10927 vat_json_init_array (&vam->json_tree);
10929 node = vat_json_array_add (&vam->json_tree);
10931 vat_json_init_object (node);
10932 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
10936 api_mpls_table_dump (vat_main_t * vam)
10938 vl_api_mpls_table_dump_t *mp;
10939 vl_api_control_ping_t *mp_ping;
10942 M (MPLS_TABLE_DUMP, mp);
10945 /* Use a control ping for synchronization */
10946 MPING (CONTROL_PING, mp_ping);
10953 #define vl_api_mpls_route_details_t_endian vl_noop_handler
10954 #define vl_api_mpls_route_details_t_print vl_noop_handler
10957 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
10959 vat_main_t *vam = &vat_main;
10960 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
10961 vl_api_fib_path_t *fp;
10965 "table-id %d, label %u, ess_bit %u",
10966 ntohl (mp->mr_route.mr_table_id),
10967 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
10968 fp = mp->mr_route.mr_paths;
10969 for (i = 0; i < count; i++)
10971 vl_api_fib_path_print (vam, fp);
10976 static void vl_api_mpls_route_details_t_handler_json
10977 (vl_api_mpls_route_details_t * mp)
10979 vat_main_t *vam = &vat_main;
10980 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
10981 vat_json_node_t *node = NULL;
10982 vl_api_fib_path_t *fp;
10985 if (VAT_JSON_ARRAY != vam->json_tree.type)
10987 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10988 vat_json_init_array (&vam->json_tree);
10990 node = vat_json_array_add (&vam->json_tree);
10992 vat_json_init_object (node);
10993 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
10994 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
10995 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
10996 vat_json_object_add_uint (node, "path_count", count);
10997 fp = mp->mr_route.mr_paths;
10998 for (i = 0; i < count; i++)
11000 vl_api_mpls_fib_path_json_print (node, fp);
11006 api_mpls_route_dump (vat_main_t * vam)
11008 unformat_input_t *input = vam->input;
11009 vl_api_mpls_route_dump_t *mp;
11010 vl_api_control_ping_t *mp_ping;
11014 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11016 if (unformat (input, "table_id %d", &table_id))
11021 if (table_id == ~0)
11023 errmsg ("missing table id");
11027 M (MPLS_ROUTE_DUMP, mp);
11029 mp->table.mt_table_id = ntohl (table_id);
11032 /* Use a control ping for synchronization */
11033 MPING (CONTROL_PING, mp_ping);
11040 #define vl_api_ip_table_details_t_endian vl_noop_handler
11041 #define vl_api_ip_table_details_t_print vl_noop_handler
11044 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
11046 vat_main_t *vam = &vat_main;
11049 "%s; table-id %d, prefix %U/%d",
11050 mp->table.name, ntohl (mp->table.table_id));
11054 static void vl_api_ip_table_details_t_handler_json
11055 (vl_api_ip_table_details_t * mp)
11057 vat_main_t *vam = &vat_main;
11058 vat_json_node_t *node = NULL;
11060 if (VAT_JSON_ARRAY != vam->json_tree.type)
11062 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11063 vat_json_init_array (&vam->json_tree);
11065 node = vat_json_array_add (&vam->json_tree);
11067 vat_json_init_object (node);
11068 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
11072 api_ip_table_dump (vat_main_t * vam)
11074 vl_api_ip_table_dump_t *mp;
11075 vl_api_control_ping_t *mp_ping;
11078 M (IP_TABLE_DUMP, mp);
11081 /* Use a control ping for synchronization */
11082 MPING (CONTROL_PING, mp_ping);
11090 api_ip_mtable_dump (vat_main_t * vam)
11092 vl_api_ip_mtable_dump_t *mp;
11093 vl_api_control_ping_t *mp_ping;
11096 M (IP_MTABLE_DUMP, mp);
11099 /* Use a control ping for synchronization */
11100 MPING (CONTROL_PING, mp_ping);
11108 api_ip_mroute_dump (vat_main_t * vam)
11110 unformat_input_t *input = vam->input;
11111 vl_api_control_ping_t *mp_ping;
11112 vl_api_ip_mroute_dump_t *mp;
11117 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11119 if (unformat (input, "table_id %d", &table_id))
11121 else if (unformat (input, "ip6"))
11123 else if (unformat (input, "ip4"))
11128 if (table_id == ~0)
11130 errmsg ("missing table id");
11134 M (IP_MROUTE_DUMP, mp);
11135 mp->table.table_id = table_id;
11136 mp->table.is_ip6 = is_ip6;
11139 /* Use a control ping for synchronization */
11140 MPING (CONTROL_PING, mp_ping);
11147 #define vl_api_ip_route_details_t_endian vl_noop_handler
11148 #define vl_api_ip_route_details_t_print vl_noop_handler
11151 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
11153 vat_main_t *vam = &vat_main;
11154 u8 count = mp->route.n_paths;
11155 vl_api_fib_path_t *fp;
11159 "table-id %d, prefix %U/%d",
11160 ntohl (mp->route.table_id),
11161 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
11162 for (i = 0; i < count; i++)
11164 fp = &mp->route.paths[i];
11166 vl_api_fib_path_print (vam, fp);
11171 static void vl_api_ip_route_details_t_handler_json
11172 (vl_api_ip_route_details_t * mp)
11174 vat_main_t *vam = &vat_main;
11175 u8 count = mp->route.n_paths;
11176 vat_json_node_t *node = NULL;
11177 struct in_addr ip4;
11178 struct in6_addr ip6;
11179 vl_api_fib_path_t *fp;
11182 if (VAT_JSON_ARRAY != vam->json_tree.type)
11184 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11185 vat_json_init_array (&vam->json_tree);
11187 node = vat_json_array_add (&vam->json_tree);
11189 vat_json_init_object (node);
11190 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
11191 if (ADDRESS_IP6 == mp->route.prefix.address.af)
11193 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
11194 vat_json_object_add_ip6 (node, "prefix", ip6);
11198 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
11199 vat_json_object_add_ip4 (node, "prefix", ip4);
11201 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
11202 vat_json_object_add_uint (node, "path_count", count);
11203 for (i = 0; i < count; i++)
11205 fp = &mp->route.paths[i];
11206 vl_api_mpls_fib_path_json_print (node, fp);
11211 api_ip_route_dump (vat_main_t * vam)
11213 unformat_input_t *input = vam->input;
11214 vl_api_ip_route_dump_t *mp;
11215 vl_api_control_ping_t *mp_ping;
11221 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11223 if (unformat (input, "table_id %d", &table_id))
11225 else if (unformat (input, "ip6"))
11227 else if (unformat (input, "ip4"))
11232 if (table_id == ~0)
11234 errmsg ("missing table id");
11238 M (IP_ROUTE_DUMP, mp);
11240 mp->table.table_id = table_id;
11241 mp->table.is_ip6 = is_ip6;
11245 /* Use a control ping for synchronization */
11246 MPING (CONTROL_PING, mp_ping);
11254 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
11256 vat_main_t *vam = &vat_main;
11258 print (vam->ofp, "collector_address %U, collector_port %d, "
11259 "src_address %U, vrf_id %d, path_mtu %u, "
11260 "template_interval %u, udp_checksum %d",
11261 format_ip4_address, mp->collector_address,
11262 ntohs (mp->collector_port),
11263 format_ip4_address, mp->src_address,
11264 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
11265 ntohl (mp->template_interval), mp->udp_checksum);
11268 vam->result_ready = 1;
11272 vl_api_ipfix_exporter_details_t_handler_json
11273 (vl_api_ipfix_exporter_details_t * mp)
11275 vat_main_t *vam = &vat_main;
11276 vat_json_node_t node;
11277 struct in_addr collector_address;
11278 struct in_addr src_address;
11280 vat_json_init_object (&node);
11281 clib_memcpy (&collector_address, &mp->collector_address,
11282 sizeof (collector_address));
11283 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
11284 vat_json_object_add_uint (&node, "collector_port",
11285 ntohs (mp->collector_port));
11286 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
11287 vat_json_object_add_ip4 (&node, "src_address", src_address);
11288 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
11289 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
11290 vat_json_object_add_uint (&node, "template_interval",
11291 ntohl (mp->template_interval));
11292 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
11294 vat_json_print (vam->ofp, &node);
11295 vat_json_free (&node);
11297 vam->result_ready = 1;
11301 api_ipfix_exporter_dump (vat_main_t * vam)
11303 vl_api_ipfix_exporter_dump_t *mp;
11306 /* Construct the API message */
11307 M (IPFIX_EXPORTER_DUMP, mp);
11316 api_ipfix_classify_stream_dump (vat_main_t * vam)
11318 vl_api_ipfix_classify_stream_dump_t *mp;
11321 /* Construct the API message */
11322 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
11333 vl_api_ipfix_classify_stream_details_t_handler
11334 (vl_api_ipfix_classify_stream_details_t * mp)
11336 vat_main_t *vam = &vat_main;
11337 print (vam->ofp, "domain_id %d, src_port %d",
11338 ntohl (mp->domain_id), ntohs (mp->src_port));
11340 vam->result_ready = 1;
11344 vl_api_ipfix_classify_stream_details_t_handler_json
11345 (vl_api_ipfix_classify_stream_details_t * mp)
11347 vat_main_t *vam = &vat_main;
11348 vat_json_node_t node;
11350 vat_json_init_object (&node);
11351 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
11352 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
11354 vat_json_print (vam->ofp, &node);
11355 vat_json_free (&node);
11357 vam->result_ready = 1;
11361 api_ipfix_classify_table_dump (vat_main_t * vam)
11363 vl_api_ipfix_classify_table_dump_t *mp;
11364 vl_api_control_ping_t *mp_ping;
11367 if (!vam->json_output)
11369 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
11370 "transport_protocol");
11373 /* Construct the API message */
11374 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
11379 /* Use a control ping for synchronization */
11380 MPING (CONTROL_PING, mp_ping);
11388 vl_api_ipfix_classify_table_details_t_handler
11389 (vl_api_ipfix_classify_table_details_t * mp)
11391 vat_main_t *vam = &vat_main;
11392 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
11393 mp->transport_protocol);
11397 vl_api_ipfix_classify_table_details_t_handler_json
11398 (vl_api_ipfix_classify_table_details_t * mp)
11400 vat_json_node_t *node = NULL;
11401 vat_main_t *vam = &vat_main;
11403 if (VAT_JSON_ARRAY != vam->json_tree.type)
11405 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11406 vat_json_init_array (&vam->json_tree);
11409 node = vat_json_array_add (&vam->json_tree);
11410 vat_json_init_object (node);
11412 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
11413 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
11414 vat_json_object_add_uint (node, "transport_protocol",
11415 mp->transport_protocol);
11419 api_sw_interface_span_enable_disable (vat_main_t * vam)
11421 unformat_input_t *i = vam->input;
11422 vl_api_sw_interface_span_enable_disable_t *mp;
11423 u32 src_sw_if_index = ~0;
11424 u32 dst_sw_if_index = ~0;
11429 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11432 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
11434 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
11438 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
11440 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
11442 else if (unformat (i, "disable"))
11444 else if (unformat (i, "rx"))
11446 else if (unformat (i, "tx"))
11448 else if (unformat (i, "both"))
11450 else if (unformat (i, "l2"))
11456 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
11458 mp->sw_if_index_from = htonl (src_sw_if_index);
11459 mp->sw_if_index_to = htonl (dst_sw_if_index);
11469 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
11472 vat_main_t *vam = &vat_main;
11473 u8 *sw_if_from_name = 0;
11474 u8 *sw_if_to_name = 0;
11475 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
11476 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
11477 char *states[] = { "none", "rx", "tx", "both" };
11481 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
11483 if ((u32) p->value[0] == sw_if_index_from)
11485 sw_if_from_name = (u8 *)(p->key);
11489 if ((u32) p->value[0] == sw_if_index_to)
11491 sw_if_to_name = (u8 *)(p->key);
11492 if (sw_if_from_name)
11497 print (vam->ofp, "%20s => %20s (%s) %s",
11498 sw_if_from_name, sw_if_to_name, states[mp->state],
11499 mp->is_l2 ? "l2" : "device");
11503 vl_api_sw_interface_span_details_t_handler_json
11504 (vl_api_sw_interface_span_details_t * mp)
11506 vat_main_t *vam = &vat_main;
11507 vat_json_node_t *node = NULL;
11508 u8 *sw_if_from_name = 0;
11509 u8 *sw_if_to_name = 0;
11510 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
11511 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
11515 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
11517 if ((u32) p->value[0] == sw_if_index_from)
11519 sw_if_from_name = (u8 *)(p->key);
11523 if ((u32) p->value[0] == sw_if_index_to)
11525 sw_if_to_name = (u8 *)(p->key);
11526 if (sw_if_from_name)
11532 if (VAT_JSON_ARRAY != vam->json_tree.type)
11534 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11535 vat_json_init_array (&vam->json_tree);
11537 node = vat_json_array_add (&vam->json_tree);
11539 vat_json_init_object (node);
11540 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
11541 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
11542 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
11543 if (0 != sw_if_to_name)
11545 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
11547 vat_json_object_add_uint (node, "state", mp->state);
11548 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
11552 api_sw_interface_span_dump (vat_main_t * vam)
11554 unformat_input_t *input = vam->input;
11555 vl_api_sw_interface_span_dump_t *mp;
11556 vl_api_control_ping_t *mp_ping;
11560 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11562 if (unformat (input, "l2"))
11568 M (SW_INTERFACE_SPAN_DUMP, mp);
11572 /* Use a control ping for synchronization */
11573 MPING (CONTROL_PING, mp_ping);
11581 api_pg_create_interface (vat_main_t * vam)
11583 unformat_input_t *input = vam->input;
11584 vl_api_pg_create_interface_t *mp;
11586 u32 if_id = ~0, gso_size = 0;
11587 u8 gso_enabled = 0;
11589 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11591 if (unformat (input, "if_id %d", &if_id))
11593 else if (unformat (input, "gso-enabled"))
11596 if (unformat (input, "gso-size %u", &gso_size))
11600 errmsg ("missing gso-size");
11609 errmsg ("missing pg interface index");
11613 /* Construct the API message */
11614 M (PG_CREATE_INTERFACE, mp);
11616 mp->interface_id = ntohl (if_id);
11617 mp->gso_enabled = gso_enabled;
11625 api_pg_capture (vat_main_t * vam)
11627 unformat_input_t *input = vam->input;
11628 vl_api_pg_capture_t *mp;
11633 u8 pcap_file_set = 0;
11636 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11638 if (unformat (input, "if_id %d", &if_id))
11640 else if (unformat (input, "pcap %s", &pcap_file))
11642 else if (unformat (input, "count %d", &count))
11644 else if (unformat (input, "disable"))
11651 errmsg ("missing pg interface index");
11654 if (pcap_file_set > 0)
11656 if (vec_len (pcap_file) > 255)
11658 errmsg ("pcap file name is too long");
11663 /* Construct the API message */
11664 M (PG_CAPTURE, mp);
11666 mp->interface_id = ntohl (if_id);
11667 mp->is_enabled = enable;
11668 mp->count = ntohl (count);
11669 if (pcap_file_set != 0)
11671 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
11673 vec_free (pcap_file);
11681 api_pg_enable_disable (vat_main_t * vam)
11683 unformat_input_t *input = vam->input;
11684 vl_api_pg_enable_disable_t *mp;
11687 u8 stream_name_set = 0;
11688 u8 *stream_name = 0;
11690 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11692 if (unformat (input, "stream %s", &stream_name))
11693 stream_name_set = 1;
11694 else if (unformat (input, "disable"))
11700 if (stream_name_set > 0)
11702 if (vec_len (stream_name) > 255)
11704 errmsg ("stream name too long");
11709 /* Construct the API message */
11710 M (PG_ENABLE_DISABLE, mp);
11712 mp->is_enabled = enable;
11713 if (stream_name_set != 0)
11715 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
11717 vec_free (stream_name);
11725 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
11727 unformat_input_t *input = vam->input;
11728 vl_api_pg_interface_enable_disable_coalesce_t *mp;
11730 u32 sw_if_index = ~0;
11733 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11735 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11737 else if (unformat (input, "sw_if_index %d", &sw_if_index))
11739 else if (unformat (input, "disable"))
11745 if (sw_if_index == ~0)
11747 errmsg ("Interface required but not specified");
11751 /* Construct the API message */
11752 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
11754 mp->coalesce_enabled = enable;
11755 mp->sw_if_index = htonl (sw_if_index);
11763 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
11765 unformat_input_t *input = vam->input;
11766 vl_api_ip_source_and_port_range_check_add_del_t *mp;
11768 u16 *low_ports = 0;
11769 u16 *high_ports = 0;
11772 vl_api_prefix_t prefix;
11779 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11781 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
11783 else if (unformat (input, "vrf %d", &vrf_id))
11785 else if (unformat (input, "del"))
11787 else if (unformat (input, "port %d", &tmp))
11789 if (tmp == 0 || tmp > 65535)
11791 errmsg ("port %d out of range", tmp);
11795 this_hi = this_low + 1;
11796 vec_add1 (low_ports, this_low);
11797 vec_add1 (high_ports, this_hi);
11799 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
11801 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
11803 errmsg ("incorrect range parameters");
11807 /* Note: in debug CLI +1 is added to high before
11808 passing to real fn that does "the work"
11809 (ip_source_and_port_range_check_add_del).
11810 This fn is a wrapper around the binary API fn a
11811 control plane will call, which expects this increment
11812 to have occurred. Hence letting the binary API control
11813 plane fn do the increment for consistency between VAT
11814 and other control planes.
11817 vec_add1 (low_ports, this_low);
11818 vec_add1 (high_ports, this_hi);
11824 if (prefix_set == 0)
11826 errmsg ("<address>/<mask> not specified");
11832 errmsg ("VRF ID required, not specified");
11839 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
11843 if (vec_len (low_ports) == 0)
11845 errmsg ("At least one port or port range required");
11849 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
11851 mp->is_add = is_add;
11853 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
11855 mp->number_of_ranges = vec_len (low_ports);
11857 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
11858 vec_free (low_ports);
11860 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
11861 vec_free (high_ports);
11863 mp->vrf_id = ntohl (vrf_id);
11871 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
11873 unformat_input_t *input = vam->input;
11874 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
11875 u32 sw_if_index = ~0;
11877 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
11878 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
11882 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11884 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11886 else if (unformat (input, "sw_if_index %d", &sw_if_index))
11888 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
11890 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
11892 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
11894 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
11896 else if (unformat (input, "del"))
11902 if (sw_if_index == ~0)
11904 errmsg ("Interface required but not specified");
11910 errmsg ("VRF ID required but not specified");
11914 if (tcp_out_vrf_id == 0
11915 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
11918 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
11922 /* Construct the API message */
11923 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
11925 mp->sw_if_index = ntohl (sw_if_index);
11926 mp->is_add = is_add;
11927 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
11928 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
11929 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
11930 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
11935 /* Wait for a reply... */
11941 api_set_punt (vat_main_t * vam)
11943 unformat_input_t *i = vam->input;
11944 vl_api_address_family_t af;
11945 vl_api_set_punt_t *mp;
11951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11953 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
11955 else if (unformat (i, "protocol %d", &protocol))
11957 else if (unformat (i, "port %d", &port))
11959 else if (unformat (i, "del"))
11963 clib_warning ("parse error '%U'", format_unformat_error, i);
11970 mp->is_add = (u8) is_add;
11971 mp->punt.type = PUNT_API_TYPE_L4;
11972 mp->punt.punt.l4.af = af;
11973 mp->punt.punt.l4.protocol = (u8) protocol;
11974 mp->punt.punt.l4.port = htons ((u16) port);
11982 api_delete_subif (vat_main_t * vam)
11984 unformat_input_t *i = vam->input;
11985 vl_api_delete_subif_t *mp;
11986 u32 sw_if_index = ~0;
11989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11991 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11993 if (unformat (i, "sw_if_index %d", &sw_if_index))
11999 if (sw_if_index == ~0)
12001 errmsg ("missing sw_if_index");
12005 /* Construct the API message */
12006 M (DELETE_SUBIF, mp);
12007 mp->sw_if_index = ntohl (sw_if_index);
12014 #define foreach_pbb_vtr_op \
12015 _("disable", L2_VTR_DISABLED) \
12016 _("pop", L2_VTR_POP_2) \
12017 _("push", L2_VTR_PUSH_2)
12020 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
12022 unformat_input_t *i = vam->input;
12023 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
12024 u32 sw_if_index = ~0, vtr_op = ~0;
12025 u16 outer_tag = ~0;
12026 u8 dmac[6], smac[6];
12027 u8 dmac_set = 0, smac_set = 0;
12033 /* Shut up coverity */
12034 clib_memset (dmac, 0, sizeof (dmac));
12035 clib_memset (smac, 0, sizeof (smac));
12037 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12039 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12041 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12043 else if (unformat (i, "vtr_op %d", &vtr_op))
12045 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
12048 else if (unformat (i, "translate_pbb_stag"))
12050 if (unformat (i, "%d", &tmp))
12052 vtr_op = L2_VTR_TRANSLATE_2_1;
12058 ("translate_pbb_stag operation requires outer tag definition");
12062 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
12064 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
12066 else if (unformat (i, "sid %d", &sid))
12068 else if (unformat (i, "vlanid %d", &tmp))
12072 clib_warning ("parse error '%U'", format_unformat_error, i);
12077 if ((sw_if_index == ~0) || (vtr_op == ~0))
12079 errmsg ("missing sw_if_index or vtr operation");
12082 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
12083 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
12086 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
12090 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
12091 mp->sw_if_index = ntohl (sw_if_index);
12092 mp->vtr_op = ntohl (vtr_op);
12093 mp->outer_tag = ntohs (outer_tag);
12094 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
12095 clib_memcpy (mp->b_smac, smac, sizeof (smac));
12096 mp->b_vlanid = ntohs (vlanid);
12097 mp->i_sid = ntohl (sid);
12105 api_feature_enable_disable (vat_main_t * vam)
12107 unformat_input_t *i = vam->input;
12108 vl_api_feature_enable_disable_t *mp;
12110 u8 *feature_name = 0;
12111 u32 sw_if_index = ~0;
12115 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12117 if (unformat (i, "arc_name %s", &arc_name))
12119 else if (unformat (i, "feature_name %s", &feature_name))
12122 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12124 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12126 else if (unformat (i, "disable"))
12134 errmsg ("missing arc name");
12137 if (vec_len (arc_name) > 63)
12139 errmsg ("arc name too long");
12142 if (feature_name == 0)
12144 errmsg ("missing feature name");
12147 if (vec_len (feature_name) > 63)
12149 errmsg ("feature name too long");
12152 if (sw_if_index == ~0)
12154 errmsg ("missing interface name or sw_if_index");
12158 /* Construct the API message */
12159 M (FEATURE_ENABLE_DISABLE, mp);
12160 mp->sw_if_index = ntohl (sw_if_index);
12161 mp->enable = enable;
12162 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
12163 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
12164 vec_free (arc_name);
12165 vec_free (feature_name);
12173 api_feature_gso_enable_disable (vat_main_t * vam)
12175 unformat_input_t *i = vam->input;
12176 vl_api_feature_gso_enable_disable_t *mp;
12177 u32 sw_if_index = ~0;
12181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12183 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12185 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12187 else if (unformat (i, "enable"))
12189 else if (unformat (i, "disable"))
12195 if (sw_if_index == ~0)
12197 errmsg ("missing interface name or sw_if_index");
12201 /* Construct the API message */
12202 M (FEATURE_GSO_ENABLE_DISABLE, mp);
12203 mp->sw_if_index = ntohl (sw_if_index);
12204 mp->enable_disable = enable;
12212 api_sw_interface_tag_add_del (vat_main_t * vam)
12214 unformat_input_t *i = vam->input;
12215 vl_api_sw_interface_tag_add_del_t *mp;
12216 u32 sw_if_index = ~0;
12221 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12223 if (unformat (i, "tag %s", &tag))
12225 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12227 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12229 else if (unformat (i, "del"))
12235 if (sw_if_index == ~0)
12237 errmsg ("missing interface name or sw_if_index");
12241 if (enable && (tag == 0))
12243 errmsg ("no tag specified");
12247 /* Construct the API message */
12248 M (SW_INTERFACE_TAG_ADD_DEL, mp);
12249 mp->sw_if_index = ntohl (sw_if_index);
12250 mp->is_add = enable;
12252 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
12261 api_sw_interface_add_del_mac_address (vat_main_t * vam)
12263 unformat_input_t *i = vam->input;
12264 vl_api_mac_address_t mac = { 0 };
12265 vl_api_sw_interface_add_del_mac_address_t *mp;
12266 u32 sw_if_index = ~0;
12271 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12273 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12275 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12277 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
12279 else if (unformat (i, "del"))
12285 if (sw_if_index == ~0)
12287 errmsg ("missing interface name or sw_if_index");
12293 errmsg ("missing MAC address");
12297 /* Construct the API message */
12298 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
12299 mp->sw_if_index = ntohl (sw_if_index);
12300 mp->is_add = is_add;
12301 clib_memcpy (&mp->addr, &mac, sizeof (mac));
12308 static void vl_api_l2_xconnect_details_t_handler
12309 (vl_api_l2_xconnect_details_t * mp)
12311 vat_main_t *vam = &vat_main;
12313 print (vam->ofp, "%15d%15d",
12314 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
12317 static void vl_api_l2_xconnect_details_t_handler_json
12318 (vl_api_l2_xconnect_details_t * mp)
12320 vat_main_t *vam = &vat_main;
12321 vat_json_node_t *node = NULL;
12323 if (VAT_JSON_ARRAY != vam->json_tree.type)
12325 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12326 vat_json_init_array (&vam->json_tree);
12328 node = vat_json_array_add (&vam->json_tree);
12330 vat_json_init_object (node);
12331 vat_json_object_add_uint (node, "rx_sw_if_index",
12332 ntohl (mp->rx_sw_if_index));
12333 vat_json_object_add_uint (node, "tx_sw_if_index",
12334 ntohl (mp->tx_sw_if_index));
12338 api_l2_xconnect_dump (vat_main_t * vam)
12340 vl_api_l2_xconnect_dump_t *mp;
12341 vl_api_control_ping_t *mp_ping;
12344 if (!vam->json_output)
12346 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
12349 M (L2_XCONNECT_DUMP, mp);
12353 /* Use a control ping for synchronization */
12354 MPING (CONTROL_PING, mp_ping);
12362 api_hw_interface_set_mtu (vat_main_t * vam)
12364 unformat_input_t *i = vam->input;
12365 vl_api_hw_interface_set_mtu_t *mp;
12366 u32 sw_if_index = ~0;
12370 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12372 if (unformat (i, "mtu %d", &mtu))
12374 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12376 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12382 if (sw_if_index == ~0)
12384 errmsg ("missing interface name or sw_if_index");
12390 errmsg ("no mtu specified");
12394 /* Construct the API message */
12395 M (HW_INTERFACE_SET_MTU, mp);
12396 mp->sw_if_index = ntohl (sw_if_index);
12397 mp->mtu = ntohs ((u16) mtu);
12405 api_p2p_ethernet_add (vat_main_t * vam)
12407 unformat_input_t *i = vam->input;
12408 vl_api_p2p_ethernet_add_t *mp;
12409 u32 parent_if_index = ~0;
12415 clib_memset (remote_mac, 0, sizeof (remote_mac));
12416 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12418 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
12420 else if (unformat (i, "sw_if_index %d", &parent_if_index))
12424 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
12426 else if (unformat (i, "sub_id %d", &sub_id))
12430 clib_warning ("parse error '%U'", format_unformat_error, i);
12435 if (parent_if_index == ~0)
12437 errmsg ("missing interface name or sw_if_index");
12442 errmsg ("missing remote mac address");
12447 errmsg ("missing sub-interface id");
12451 M (P2P_ETHERNET_ADD, mp);
12452 mp->parent_if_index = ntohl (parent_if_index);
12453 mp->subif_id = ntohl (sub_id);
12454 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
12462 api_p2p_ethernet_del (vat_main_t * vam)
12464 unformat_input_t *i = vam->input;
12465 vl_api_p2p_ethernet_del_t *mp;
12466 u32 parent_if_index = ~0;
12471 clib_memset (remote_mac, 0, sizeof (remote_mac));
12472 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12474 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
12476 else if (unformat (i, "sw_if_index %d", &parent_if_index))
12480 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
12484 clib_warning ("parse error '%U'", format_unformat_error, i);
12489 if (parent_if_index == ~0)
12491 errmsg ("missing interface name or sw_if_index");
12496 errmsg ("missing remote mac address");
12500 M (P2P_ETHERNET_DEL, mp);
12501 mp->parent_if_index = ntohl (parent_if_index);
12502 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
12510 api_tcp_configure_src_addresses (vat_main_t * vam)
12512 vl_api_tcp_configure_src_addresses_t *mp;
12513 unformat_input_t *i = vam->input;
12514 vl_api_address_t first, last;
12519 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12521 if (unformat (i, "%U - %U",
12522 unformat_vl_api_address, &first,
12523 unformat_vl_api_address, &last))
12527 errmsg ("one range per message (range already set)");
12532 else if (unformat (i, "vrf %d", &vrf_id))
12538 if (range_set == 0)
12540 errmsg ("address range not set");
12544 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
12546 mp->vrf_id = ntohl (vrf_id);
12547 clib_memcpy (&mp->first_address, &first, sizeof (first));
12548 clib_memcpy (&mp->last_address, &last, sizeof (last));
12555 static void vl_api_app_namespace_add_del_reply_t_handler
12556 (vl_api_app_namespace_add_del_reply_t * mp)
12558 vat_main_t *vam = &vat_main;
12559 i32 retval = ntohl (mp->retval);
12560 if (vam->async_mode)
12562 vam->async_errors += (retval < 0);
12566 vam->retval = retval;
12568 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
12569 vam->result_ready = 1;
12573 static void vl_api_app_namespace_add_del_reply_t_handler_json
12574 (vl_api_app_namespace_add_del_reply_t * mp)
12576 vat_main_t *vam = &vat_main;
12577 vat_json_node_t node;
12579 vat_json_init_object (&node);
12580 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
12581 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
12583 vat_json_print (vam->ofp, &node);
12584 vat_json_free (&node);
12586 vam->retval = ntohl (mp->retval);
12587 vam->result_ready = 1;
12591 api_app_namespace_add_del (vat_main_t * vam)
12593 vl_api_app_namespace_add_del_t *mp;
12594 unformat_input_t *i = vam->input;
12595 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
12596 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
12600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12602 if (unformat (i, "id %_%v%_", &ns_id))
12604 else if (unformat (i, "secret %lu", &secret))
12606 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12607 sw_if_index_set = 1;
12608 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
12610 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
12615 if (!ns_id || !secret_set || !sw_if_index_set)
12617 errmsg ("namespace id, secret and sw_if_index must be set");
12620 if (vec_len (ns_id) > 64)
12622 errmsg ("namespace id too long");
12625 M (APP_NAMESPACE_ADD_DEL, mp);
12627 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
12628 mp->secret = clib_host_to_net_u64 (secret);
12629 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
12630 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
12631 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
12639 api_sock_init_shm (vat_main_t * vam)
12641 #if VPP_API_TEST_BUILTIN == 0
12642 unformat_input_t *i = vam->input;
12643 vl_api_shm_elem_config_t *config = 0;
12644 u64 size = 64 << 20;
12647 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12649 if (unformat (i, "size %U", unformat_memory_size, &size))
12656 * Canned custom ring allocator config.
12657 * Should probably parse all of this
12659 vec_validate (config, 6);
12660 config[0].type = VL_API_VLIB_RING;
12661 config[0].size = 256;
12662 config[0].count = 32;
12664 config[1].type = VL_API_VLIB_RING;
12665 config[1].size = 1024;
12666 config[1].count = 16;
12668 config[2].type = VL_API_VLIB_RING;
12669 config[2].size = 4096;
12670 config[2].count = 2;
12672 config[3].type = VL_API_CLIENT_RING;
12673 config[3].size = 256;
12674 config[3].count = 32;
12676 config[4].type = VL_API_CLIENT_RING;
12677 config[4].size = 1024;
12678 config[4].count = 16;
12680 config[5].type = VL_API_CLIENT_RING;
12681 config[5].size = 4096;
12682 config[5].count = 2;
12684 config[6].type = VL_API_QUEUE;
12685 config[6].count = 128;
12686 config[6].size = sizeof (uword);
12688 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
12690 vam->client_index_invalid = 1;
12698 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
12700 vat_main_t *vam = &vat_main;
12701 fib_prefix_t lcl, rmt;
12703 ip_prefix_decode (&mp->lcl, &lcl);
12704 ip_prefix_decode (&mp->rmt, &rmt);
12706 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
12709 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
12710 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
12711 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
12712 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
12713 &rmt.fp_addr.ip4, rmt.fp_len,
12714 clib_net_to_host_u16 (mp->rmt_port),
12715 clib_net_to_host_u32 (mp->action_index), mp->tag);
12720 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
12721 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
12722 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
12723 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
12724 &rmt.fp_addr.ip6, rmt.fp_len,
12725 clib_net_to_host_u16 (mp->rmt_port),
12726 clib_net_to_host_u32 (mp->action_index), mp->tag);
12731 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
12734 vat_main_t *vam = &vat_main;
12735 vat_json_node_t *node = NULL;
12736 struct in6_addr ip6;
12737 struct in_addr ip4;
12739 fib_prefix_t lcl, rmt;
12741 ip_prefix_decode (&mp->lcl, &lcl);
12742 ip_prefix_decode (&mp->rmt, &rmt);
12744 if (VAT_JSON_ARRAY != vam->json_tree.type)
12746 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12747 vat_json_init_array (&vam->json_tree);
12749 node = vat_json_array_add (&vam->json_tree);
12750 vat_json_init_object (node);
12752 vat_json_object_add_uint (node, "appns_index",
12753 clib_net_to_host_u32 (mp->appns_index));
12754 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
12755 vat_json_object_add_uint (node, "scope", mp->scope);
12756 vat_json_object_add_uint (node, "action_index",
12757 clib_net_to_host_u32 (mp->action_index));
12758 vat_json_object_add_uint (node, "lcl_port",
12759 clib_net_to_host_u16 (mp->lcl_port));
12760 vat_json_object_add_uint (node, "rmt_port",
12761 clib_net_to_host_u16 (mp->rmt_port));
12762 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
12763 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
12764 vat_json_object_add_string_copy (node, "tag", mp->tag);
12765 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
12767 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
12768 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
12769 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
12770 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
12774 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
12775 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
12776 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
12777 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
12782 api_session_rule_add_del (vat_main_t * vam)
12784 vl_api_session_rule_add_del_t *mp;
12785 unformat_input_t *i = vam->input;
12786 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
12787 u32 appns_index = 0, scope = 0;
12788 ip4_address_t lcl_ip4, rmt_ip4;
12789 ip6_address_t lcl_ip6, rmt_ip6;
12790 u8 is_ip4 = 1, conn_set = 0;
12791 u8 is_add = 1, *tag = 0;
12793 fib_prefix_t lcl, rmt;
12795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12797 if (unformat (i, "del"))
12799 else if (unformat (i, "add"))
12801 else if (unformat (i, "proto tcp"))
12803 else if (unformat (i, "proto udp"))
12805 else if (unformat (i, "appns %d", &appns_index))
12807 else if (unformat (i, "scope %d", &scope))
12809 else if (unformat (i, "tag %_%v%_", &tag))
12813 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
12814 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
12822 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
12823 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
12829 else if (unformat (i, "action %d", &action))
12834 if (proto == ~0 || !conn_set || action == ~0)
12836 errmsg ("transport proto, connection and action must be set");
12842 errmsg ("scope should be 0-3");
12846 M (SESSION_RULE_ADD_DEL, mp);
12848 clib_memset (&lcl, 0, sizeof (lcl));
12849 clib_memset (&rmt, 0, sizeof (rmt));
12852 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
12853 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
12854 lcl.fp_len = lcl_plen;
12855 rmt.fp_len = rmt_plen;
12859 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
12860 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
12861 lcl.fp_len = lcl_plen;
12862 rmt.fp_len = rmt_plen;
12866 ip_prefix_encode (&lcl, &mp->lcl);
12867 ip_prefix_encode (&rmt, &mp->rmt);
12868 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
12869 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
12870 mp->transport_proto =
12871 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
12872 mp->action_index = clib_host_to_net_u32 (action);
12873 mp->appns_index = clib_host_to_net_u32 (appns_index);
12875 mp->is_add = is_add;
12878 clib_memcpy (mp->tag, tag, vec_len (tag));
12888 api_session_rules_dump (vat_main_t * vam)
12890 vl_api_session_rules_dump_t *mp;
12891 vl_api_control_ping_t *mp_ping;
12894 if (!vam->json_output)
12896 print (vam->ofp, "%=20s", "Session Rules");
12899 M (SESSION_RULES_DUMP, mp);
12903 /* Use a control ping for synchronization */
12904 MPING (CONTROL_PING, mp_ping);
12907 /* Wait for a reply... */
12913 api_ip_container_proxy_add_del (vat_main_t * vam)
12915 vl_api_ip_container_proxy_add_del_t *mp;
12916 unformat_input_t *i = vam->input;
12917 u32 sw_if_index = ~0;
12918 vl_api_prefix_t pfx = { };
12922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12924 if (unformat (i, "del"))
12926 else if (unformat (i, "add"))
12928 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
12930 else if (unformat (i, "sw_if_index %u", &sw_if_index))
12935 if (sw_if_index == ~0 || pfx.len == 0)
12937 errmsg ("address and sw_if_index must be set");
12941 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
12943 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
12944 mp->is_add = is_add;
12945 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
12953 api_qos_record_enable_disable (vat_main_t * vam)
12955 unformat_input_t *i = vam->input;
12956 vl_api_qos_record_enable_disable_t *mp;
12957 u32 sw_if_index, qs = 0xff;
12958 u8 sw_if_index_set = 0;
12962 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12964 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12965 sw_if_index_set = 1;
12966 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12967 sw_if_index_set = 1;
12968 else if (unformat (i, "%U", unformat_qos_source, &qs))
12970 else if (unformat (i, "disable"))
12974 clib_warning ("parse error '%U'", format_unformat_error, i);
12979 if (sw_if_index_set == 0)
12981 errmsg ("missing interface name or sw_if_index");
12986 errmsg ("input location must be specified");
12990 M (QOS_RECORD_ENABLE_DISABLE, mp);
12992 mp->record.sw_if_index = ntohl (sw_if_index);
12993 mp->record.input_source = qs;
12994 mp->enable = enable;
13003 q_or_quit (vat_main_t * vam)
13005 #if VPP_API_TEST_BUILTIN == 0
13006 longjmp (vam->jump_buf, 1);
13008 return 0; /* not so much */
13012 q (vat_main_t * vam)
13014 return q_or_quit (vam);
13018 quit (vat_main_t * vam)
13020 return q_or_quit (vam);
13024 comment (vat_main_t * vam)
13030 elog_save (vat_main_t * vam)
13032 #if VPP_API_TEST_BUILTIN == 0
13033 elog_main_t *em = &vam->elog_main;
13034 unformat_input_t *i = vam->input;
13035 char *file, *chroot_file;
13036 clib_error_t *error;
13038 if (!unformat (i, "%s", &file))
13040 errmsg ("expected file name, got `%U'", format_unformat_error, i);
13044 /* It's fairly hard to get "../oopsie" through unformat; just in case */
13045 if (strstr (file, "..") || index (file, '/'))
13047 errmsg ("illegal characters in filename '%s'", file);
13051 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
13055 errmsg ("Saving %wd of %wd events to %s",
13056 elog_n_events_in_buffer (em),
13057 elog_buffer_capacity (em), chroot_file);
13059 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
13060 vec_free (chroot_file);
13063 clib_error_report (error);
13065 errmsg ("Use the vpp event loger...");
13072 elog_setup (vat_main_t * vam)
13074 #if VPP_API_TEST_BUILTIN == 0
13075 elog_main_t *em = &vam->elog_main;
13076 unformat_input_t *i = vam->input;
13077 u32 nevents = 128 << 10;
13079 (void) unformat (i, "nevents %d", &nevents);
13081 elog_init (em, nevents);
13082 vl_api_set_elog_main (em);
13083 vl_api_set_elog_trace_api_messages (1);
13084 errmsg ("Event logger initialized with %u events", nevents);
13086 errmsg ("Use the vpp event loger...");
13092 elog_enable (vat_main_t * vam)
13094 #if VPP_API_TEST_BUILTIN == 0
13095 elog_main_t *em = &vam->elog_main;
13097 elog_enable_disable (em, 1 /* enable */ );
13098 vl_api_set_elog_trace_api_messages (1);
13099 errmsg ("Event logger enabled...");
13101 errmsg ("Use the vpp event loger...");
13107 elog_disable (vat_main_t * vam)
13109 #if VPP_API_TEST_BUILTIN == 0
13110 elog_main_t *em = &vam->elog_main;
13112 elog_enable_disable (em, 0 /* enable */ );
13113 vl_api_set_elog_trace_api_messages (1);
13114 errmsg ("Event logger disabled...");
13116 errmsg ("Use the vpp event loger...");
13122 statseg (vat_main_t * vam)
13124 ssvm_private_t *ssvmp = &vam->stat_segment;
13125 ssvm_shared_header_t *shared_header = ssvmp->sh;
13126 vlib_counter_t **counters;
13127 u64 thread0_index1_packets;
13128 u64 thread0_index1_bytes;
13129 f64 vector_rate, input_rate;
13132 uword *counter_vector_by_name;
13133 if (vam->stat_segment_lockp == 0)
13135 errmsg ("Stat segment not mapped...");
13139 /* look up "/if/rx for sw_if_index 1 as a test */
13141 clib_spinlock_lock (vam->stat_segment_lockp);
13143 counter_vector_by_name = (uword *) shared_header->opaque[1];
13145 p = hash_get_mem (counter_vector_by_name, "/if/rx");
13148 clib_spinlock_unlock (vam->stat_segment_lockp);
13149 errmsg ("/if/tx not found?");
13153 /* Fish per-thread vector of combined counters from shared memory */
13154 counters = (vlib_counter_t **) p[0];
13156 if (vec_len (counters[0]) < 2)
13158 clib_spinlock_unlock (vam->stat_segment_lockp);
13159 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
13163 /* Read thread 0 sw_if_index 1 counter */
13164 thread0_index1_packets = counters[0][1].packets;
13165 thread0_index1_bytes = counters[0][1].bytes;
13167 p = hash_get_mem (counter_vector_by_name, "vector_rate");
13170 clib_spinlock_unlock (vam->stat_segment_lockp);
13171 errmsg ("vector_rate not found?");
13175 vector_rate = *(f64 *) (p[0]);
13176 p = hash_get_mem (counter_vector_by_name, "input_rate");
13179 clib_spinlock_unlock (vam->stat_segment_lockp);
13180 errmsg ("input_rate not found?");
13183 input_rate = *(f64 *) (p[0]);
13185 clib_spinlock_unlock (vam->stat_segment_lockp);
13187 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
13188 vector_rate, input_rate);
13189 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
13190 thread0_index1_packets, thread0_index1_bytes);
13196 cmd_cmp (void *a1, void *a2)
13201 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
13205 help (vat_main_t * vam)
13210 unformat_input_t *i = vam->input;
13213 if (unformat (i, "%s", &name))
13217 vec_add1 (name, 0);
13219 hs = hash_get_mem (vam->help_by_name, name);
13221 print (vam->ofp, "usage: %s %s", name, hs[0]);
13223 print (vam->ofp, "No such msg / command '%s'", name);
13228 print (vam->ofp, "Help is available for the following:");
13231 hash_foreach_pair (p, vam->function_by_name,
13233 vec_add1 (cmds, (u8 *)(p->key));
13237 vec_sort_with_function (cmds, cmd_cmp);
13239 for (j = 0; j < vec_len (cmds); j++)
13240 print (vam->ofp, "%s", cmds[j]);
13247 set (vat_main_t * vam)
13249 u8 *name = 0, *value = 0;
13250 unformat_input_t *i = vam->input;
13252 if (unformat (i, "%s", &name))
13254 /* The input buffer is a vector, not a string. */
13255 value = vec_dup (i->buffer);
13256 vec_delete (value, i->index, 0);
13257 /* Almost certainly has a trailing newline */
13258 if (value[vec_len (value) - 1] == '\n')
13259 value[vec_len (value) - 1] = 0;
13260 /* Make sure it's a proper string, one way or the other */
13261 vec_add1 (value, 0);
13262 (void) clib_macro_set_value (&vam->macro_main,
13263 (char *) name, (char *) value);
13266 errmsg ("usage: set <name> <value>");
13274 unset (vat_main_t * vam)
13278 if (unformat (vam->input, "%s", &name))
13279 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
13280 errmsg ("unset: %s wasn't set", name);
13293 macro_sort_cmp (void *a1, void *a2)
13295 macro_sort_t *s1 = a1;
13296 macro_sort_t *s2 = a2;
13298 return strcmp ((char *) (s1->name), (char *) (s2->name));
13302 dump_macro_table (vat_main_t * vam)
13304 macro_sort_t *sort_me = 0, *sm;
13309 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
13311 vec_add2 (sort_me, sm, 1);
13312 sm->name = (u8 *)(p->key);
13313 sm->value = (u8 *) (p->value[0]);
13317 vec_sort_with_function (sort_me, macro_sort_cmp);
13319 if (vec_len (sort_me))
13320 print (vam->ofp, "%-15s%s", "Name", "Value");
13322 print (vam->ofp, "The macro table is empty...");
13324 for (i = 0; i < vec_len (sort_me); i++)
13325 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
13330 dump_node_table (vat_main_t * vam)
13333 vlib_node_t *node, *next_node;
13335 if (vec_len (vam->graph_nodes) == 0)
13337 print (vam->ofp, "Node table empty, issue get_node_graph...");
13341 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
13343 node = vam->graph_nodes[0][i];
13344 print (vam->ofp, "[%d] %s", i, node->name);
13345 for (j = 0; j < vec_len (node->next_nodes); j++)
13347 if (node->next_nodes[j] != ~0)
13349 next_node = vam->graph_nodes[0][node->next_nodes[j]];
13350 print (vam->ofp, " [%d] %s", j, next_node->name);
13358 value_sort_cmp (void *a1, void *a2)
13360 name_sort_t *n1 = a1;
13361 name_sort_t *n2 = a2;
13363 if (n1->value < n2->value)
13365 if (n1->value > n2->value)
13372 dump_msg_api_table (vat_main_t * vam)
13374 api_main_t *am = vlibapi_get_main ();
13375 name_sort_t *nses = 0, *ns;
13380 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
13382 vec_add2 (nses, ns, 1);
13383 ns->name = (u8 *)(hp->key);
13384 ns->value = (u32) hp->value[0];
13388 vec_sort_with_function (nses, value_sort_cmp);
13390 for (i = 0; i < vec_len (nses); i++)
13391 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
13397 get_msg_id (vat_main_t * vam)
13402 if (unformat (vam->input, "%s", &name_and_crc))
13404 message_index = vl_msg_api_get_msg_index (name_and_crc);
13405 if (message_index == ~0)
13407 print (vam->ofp, " '%s' not found", name_and_crc);
13410 print (vam->ofp, " '%s' has message index %d",
13411 name_and_crc, message_index);
13414 errmsg ("name_and_crc required...");
13419 search_node_table (vat_main_t * vam)
13421 unformat_input_t *line_input = vam->input;
13424 vlib_node_t *node, *next_node;
13427 if (vam->graph_node_index_by_name == 0)
13429 print (vam->ofp, "Node table empty, issue get_node_graph...");
13433 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
13435 if (unformat (line_input, "%s", &node_to_find))
13437 vec_add1 (node_to_find, 0);
13438 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
13441 print (vam->ofp, "%s not found...", node_to_find);
13444 node = vam->graph_nodes[0][p[0]];
13445 print (vam->ofp, "[%d] %s", p[0], node->name);
13446 for (j = 0; j < vec_len (node->next_nodes); j++)
13448 if (node->next_nodes[j] != ~0)
13450 next_node = vam->graph_nodes[0][node->next_nodes[j]];
13451 print (vam->ofp, " [%d] %s", j, next_node->name);
13458 clib_warning ("parse error '%U'", format_unformat_error,
13464 vec_free (node_to_find);
13473 script (vat_main_t * vam)
13475 #if (VPP_API_TEST_BUILTIN==0)
13477 char *save_current_file;
13478 unformat_input_t save_input;
13479 jmp_buf save_jump_buf;
13480 u32 save_line_number;
13482 FILE *new_fp, *save_ifp;
13484 if (unformat (vam->input, "%s", &s))
13486 new_fp = fopen ((char *) s, "r");
13489 errmsg ("Couldn't open script file %s", s);
13496 errmsg ("Missing script name");
13500 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
13501 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
13502 save_ifp = vam->ifp;
13503 save_line_number = vam->input_line_number;
13504 save_current_file = (char *) vam->current_file;
13506 vam->input_line_number = 0;
13508 vam->current_file = s;
13511 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
13512 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
13513 vam->ifp = save_ifp;
13514 vam->input_line_number = save_line_number;
13515 vam->current_file = (u8 *) save_current_file;
13520 clib_warning ("use the exec command...");
13526 echo (vat_main_t * vam)
13528 print (vam->ofp, "%v", vam->input->buffer);
13532 /* List of API message constructors, CLI names map to api_xxx */
13533 #define foreach_vpe_api_msg \
13534 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
13535 _(sw_interface_dump,"") \
13536 _(sw_interface_set_flags, \
13537 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
13538 _(sw_interface_add_del_address, \
13539 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
13540 _(sw_interface_set_rx_mode, \
13541 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
13542 _(sw_interface_set_rx_placement, \
13543 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
13544 _(sw_interface_rx_placement_dump, \
13545 "[<intfc> | sw_if_index <id>]") \
13546 _(sw_interface_set_table, \
13547 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
13548 _(sw_interface_set_mpls_enable, \
13549 "<intfc> | sw_if_index [disable | dis]") \
13550 _(sw_interface_set_vpath, \
13551 "<intfc> | sw_if_index <id> enable | disable") \
13552 _(sw_interface_set_vxlan_bypass, \
13553 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
13554 _(sw_interface_set_l2_xconnect, \
13555 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13556 "enable | disable") \
13557 _(sw_interface_set_l2_bridge, \
13558 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
13559 "[shg <split-horizon-group>] [bvi]\n" \
13560 "enable | disable") \
13561 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
13562 _(bridge_domain_add_del, \
13563 "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") \
13564 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
13566 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
13567 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
13568 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
13570 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
13572 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
13574 "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]") \
13576 "<vpp-if-name> | sw_if_index <id>") \
13577 _(sw_interface_tap_v2_dump, "") \
13578 _(virtio_pci_create_v2, \
13579 "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]") \
13580 _(virtio_pci_delete, \
13581 "<vpp-if-name> | sw_if_index <id>") \
13582 _(sw_interface_virtio_pci_dump, "") \
13584 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
13585 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
13588 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
13589 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
13590 "[id <if-id>] [gso]") \
13592 "<vpp-if-name> | sw_if_index <id>") \
13593 _(bond_add_member, \
13594 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
13595 _(bond_detach_member, \
13596 "sw_if_index <n>") \
13597 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
13598 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
13599 _(sw_member_interface_dump, \
13600 "<vpp-if-name> | sw_if_index <id>") \
13601 _(ip_table_add_del, \
13602 "table <n> [ipv6] [add | del]\n") \
13603 _(ip_route_add_del, \
13604 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
13605 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
13606 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
13607 "[multipath] [count <n>] [del]") \
13608 _(ip_mroute_add_del, \
13609 "<src> <grp>/<mask> [table-id <n>]\n" \
13610 "[<intfc> | sw_if_index <id>] [local] [del]") \
13611 _(mpls_table_add_del, \
13612 "table <n> [add | del]\n") \
13613 _(mpls_route_add_del, \
13614 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
13615 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
13616 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
13617 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
13618 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
13619 "[count <n>] [del]") \
13620 _(mpls_ip_bind_unbind, \
13621 "<label> <addr/len>") \
13622 _(mpls_tunnel_add_del, \
13623 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
13624 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
13625 "[l2-only] [out-label <n>]") \
13626 _(sr_mpls_policy_add, \
13627 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
13628 _(sr_mpls_policy_del, \
13630 _(sw_interface_set_unnumbered, \
13631 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
13632 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
13633 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
13634 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
13635 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
13636 "[outer_vlan_id_any][inner_vlan_id_any]") \
13637 _(ip_table_replace_begin, "table <n> [ipv6]") \
13638 _(ip_table_flush, "table <n> [ipv6]") \
13639 _(ip_table_replace_end, "table <n> [ipv6]") \
13640 _(set_ip_flow_hash, \
13641 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
13642 _(sw_interface_ip6_enable_disable, \
13643 "<intfc> | sw_if_index <id> enable | disable") \
13644 _(l2_patch_add_del, \
13645 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13646 "enable | disable") \
13647 _(sr_localsid_add_del, \
13648 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
13649 "fib-table <num> (end.psp) sw_if_index <num>") \
13650 _(get_node_index, "node <node-name") \
13651 _(add_node_next, "node <node-name> next <next-node-name>") \
13652 _(vxlan_offload_rx, \
13653 "hw { <interface name> | hw_if_index <nn>} " \
13654 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
13655 _(vxlan_add_del_tunnel, \
13656 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
13657 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
13658 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
13659 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13660 _(l2_fib_clear_table, "") \
13661 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
13662 _(l2_interface_vlan_tag_rewrite, \
13663 "<intfc> | sw_if_index <nn> \n" \
13664 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
13665 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
13666 _(create_vhost_user_if, \
13667 "socket <filename> [server] [renumber <dev_instance>] " \
13668 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
13669 "[mac <mac_address>] [packed]") \
13670 _(modify_vhost_user_if, \
13671 "<intfc> | sw_if_index <nn> socket <filename>\n" \
13672 "[server] [renumber <dev_instance>] [gso] [packed]") \
13673 _(create_vhost_user_if_v2, \
13674 "socket <filename> [server] [renumber <dev_instance>] " \
13675 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
13676 "[mac <mac_address>] [packed] [event-idx]") \
13677 _(modify_vhost_user_if_v2, \
13678 "<intfc> | sw_if_index <nn> socket <filename>\n" \
13679 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
13680 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
13681 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
13682 _(show_version, "") \
13683 _(show_threads, "") \
13684 _(vxlan_gpe_add_del_tunnel, \
13685 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
13686 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
13687 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
13688 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
13689 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13690 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
13691 _(interface_name_renumber, \
13692 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
13693 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
13694 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
13695 _(ip_dump, "ipv4 | ipv6") \
13696 _(ipsec_spd_add_del, "spd_id <n> [del]") \
13697 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
13699 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
13700 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
13701 " integ_alg <alg> integ_key <hex>") \
13702 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
13703 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
13704 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
13705 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
13706 _(ipsec_sa_dump, "[sa_id <n>]") \
13707 _(delete_loopback,"sw_if_index <nn>") \
13708 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
13709 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
13710 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
13711 _(want_interface_events, "enable|disable") \
13712 _(get_first_msg_id, "client <name>") \
13713 _(get_node_graph, " ") \
13714 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
13715 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
13716 _(ioam_disable, "") \
13717 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
13718 _(af_packet_delete, "name <host interface name>") \
13719 _(af_packet_dump, "") \
13720 _(policer_add_del, "name <policer name> <params> [del]") \
13721 _(policer_dump, "[name <policer name>]") \
13722 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
13723 _(mpls_table_dump, "") \
13724 _(mpls_route_dump, "table-id <ID>") \
13725 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
13726 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
13727 "[template_interval <nn>] [udp_checksum]") \
13728 _(ipfix_exporter_dump, "") \
13729 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
13730 _(ipfix_classify_stream_dump, "") \
13731 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
13732 _(ipfix_classify_table_dump, "") \
13733 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
13734 _(sw_interface_span_dump, "[l2]") \
13735 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
13736 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
13737 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
13738 _(pg_enable_disable, "[stream <id>] disable") \
13739 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
13740 _(ip_source_and_port_range_check_add_del, \
13741 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
13742 _(ip_source_and_port_range_check_interface_add_del, \
13743 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
13744 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
13745 _(delete_subif,"<intfc> | sw_if_index <nn>") \
13746 _(l2_interface_pbb_tag_rewrite, \
13747 "<intfc> | sw_if_index <nn> \n" \
13748 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
13749 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
13750 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
13751 _(ip_table_dump, "") \
13752 _(ip_route_dump, "table-id [ip4|ip6]") \
13753 _(ip_mtable_dump, "") \
13754 _(ip_mroute_dump, "table-id [ip4|ip6]") \
13755 _(feature_enable_disable, "arc_name <arc_name> " \
13756 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
13757 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
13758 "[enable | disable] ") \
13759 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
13761 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
13762 "mac <mac-address> [del]") \
13763 _(l2_xconnect_dump, "") \
13764 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
13765 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
13766 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
13767 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
13768 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
13769 _(sock_init_shm, "size <nnn>") \
13770 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
13771 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
13772 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
13773 _(session_rules_dump, "") \
13774 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
13775 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
13777 /* List of command functions, CLI names map directly to functions */
13778 #define foreach_cli_function \
13779 _(comment, "usage: comment <ignore-rest-of-line>") \
13780 _(dump_interface_table, "usage: dump_interface_table") \
13781 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
13782 _(dump_ipv4_table, "usage: dump_ipv4_table") \
13783 _(dump_ipv6_table, "usage: dump_ipv6_table") \
13784 _(dump_macro_table, "usage: dump_macro_table ") \
13785 _(dump_node_table, "usage: dump_node_table") \
13786 _(dump_msg_api_table, "usage: dump_msg_api_table") \
13787 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
13788 _(elog_disable, "usage: elog_disable") \
13789 _(elog_enable, "usage: elog_enable") \
13790 _(elog_save, "usage: elog_save <filename>") \
13791 _(get_msg_id, "usage: get_msg_id name_and_crc") \
13792 _(echo, "usage: echo <message>") \
13793 _(exec, "usage: exec <vpe-debug-CLI-command>") \
13794 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
13795 _(help, "usage: help") \
13796 _(q, "usage: quit") \
13797 _(quit, "usage: quit") \
13798 _(search_node_table, "usage: search_node_table <name>...") \
13799 _(set, "usage: set <variable-name> <value>") \
13800 _(script, "usage: script <file-name>") \
13801 _(statseg, "usage: statseg") \
13802 _(unset, "usage: unset <variable-name>")
13805 static void vl_api_##n##_t_handler_uni \
13806 (vl_api_##n##_t * mp) \
13808 vat_main_t * vam = &vat_main; \
13809 if (vam->json_output) { \
13810 vl_api_##n##_t_handler_json(mp); \
13812 vl_api_##n##_t_handler(mp); \
13815 foreach_vpe_api_reply_msg;
13816 #if VPP_API_TEST_BUILTIN == 0
13817 foreach_standalone_reply_msg;
13822 vat_api_hookup (vat_main_t * vam)
13825 vl_msg_api_set_handlers(VL_API_##N, #n, \
13826 vl_api_##n##_t_handler_uni, \
13828 vl_api_##n##_t_endian, \
13829 vl_api_##n##_t_print, \
13830 sizeof(vl_api_##n##_t), 1);
13831 foreach_vpe_api_reply_msg;
13832 #if VPP_API_TEST_BUILTIN == 0
13833 foreach_standalone_reply_msg;
13837 #if (VPP_API_TEST_BUILTIN==0)
13838 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
13840 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
13842 vam->function_by_name = hash_create_string (0, sizeof (uword));
13844 vam->help_by_name = hash_create_string (0, sizeof (uword));
13847 /* API messages we can send */
13848 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
13849 foreach_vpe_api_msg;
13853 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13854 foreach_vpe_api_msg;
13857 /* CLI functions */
13858 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
13859 foreach_cli_function;
13863 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13864 foreach_cli_function;
13868 #if VPP_API_TEST_BUILTIN
13869 static clib_error_t *
13870 vat_api_hookup_shim (vlib_main_t * vm)
13872 vat_api_hookup (&vat_main);
13876 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
13880 * fd.io coding-style-patch-verification: ON
13883 * eval: (c-set-style "gnu")