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 #include <vnet/format_fns.h>
86 void vl_api_set_elog_main (elog_main_t * m);
87 int vl_api_set_elog_trace_api_messages (int enable);
89 #if VPP_API_TEST_BUILTIN == 0
99 vat_socket_connect (vat_main_t * vam)
102 api_main_t *am = vlibapi_get_main ();
103 vam->socket_client_main = &socket_client_main;
104 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
106 0 /* default socket rx, tx buffer */ )))
109 /* vpp expects the client index in network order */
110 vam->my_client_index = htonl (socket_client_main.client_index);
111 am->my_client_index = vam->my_client_index;
114 #else /* vpp built-in case, we don't do sockets... */
116 vat_socket_connect (vat_main_t * vam)
122 vl_socket_client_read (int wait)
128 vl_socket_client_write ()
134 vl_socket_client_msg_alloc (int nbytes)
142 vat_time_now (vat_main_t * vam)
144 #if VPP_API_TEST_BUILTIN
145 return vlib_time_now (vam->vlib_main);
147 return clib_time_now (&vam->clib_time);
152 errmsg (char *fmt, ...)
154 vat_main_t *vam = &vat_main;
159 s = va_format (0, fmt, &va);
164 #if VPP_API_TEST_BUILTIN
165 vlib_cli_output (vam->vlib_main, (char *) s);
168 if (vam->ifp != stdin)
169 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
170 vam->input_line_number);
172 fformat (vam->ofp, "%s\n", (char *) s);
180 #if VPP_API_TEST_BUILTIN == 0
182 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
184 vat_main_t *vam = va_arg (*args, vat_main_t *);
185 u32 *result = va_arg (*args, u32 *);
189 if (!unformat (input, "%s", &if_name))
192 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
200 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
205 /* Parse an IP4 address %d.%d.%d.%d. */
207 unformat_ip4_address (unformat_input_t * input, va_list * args)
209 u8 *result = va_arg (*args, u8 *);
212 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
215 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
227 unformat_ethernet_address (unformat_input_t * input, va_list * args)
229 u8 *result = va_arg (*args, u8 *);
232 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
233 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
237 for (i = 0; i < 6; i++)
238 if (a[i] >= (1 << 8))
241 for (i = 0; i < 6; i++)
247 /* Returns ethernet type as an int in host byte order. */
249 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
252 u16 *result = va_arg (*args, u16 *);
256 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
258 if (type >= (1 << 16))
266 /* Parse an IP46 address. */
268 unformat_ip46_address (unformat_input_t * input, va_list * args)
270 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
271 ip46_type_t type = va_arg (*args, ip46_type_t);
272 if ((type != IP46_TYPE_IP6) &&
273 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
275 ip46_address_mask_ip4 (ip46);
278 else if ((type != IP46_TYPE_IP4) &&
279 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
286 /* Parse an IP6 address. */
288 unformat_ip6_address (unformat_input_t * input, va_list * args)
290 ip6_address_t *result = va_arg (*args, ip6_address_t *);
292 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
293 uword c, n_colon, double_colon_index;
295 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
296 double_colon_index = ARRAY_LEN (hex_quads);
297 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
300 if (c >= '0' && c <= '9')
302 else if (c >= 'a' && c <= 'f')
303 hex_digit = c + 10 - 'a';
304 else if (c >= 'A' && c <= 'F')
305 hex_digit = c + 10 - 'A';
306 else if (c == ':' && n_colon < 2)
310 unformat_put_input (input);
314 /* Too many hex quads. */
315 if (n_hex_quads >= ARRAY_LEN (hex_quads))
320 hex_quad = (hex_quad << 4) | hex_digit;
322 /* Hex quad must fit in 16 bits. */
323 if (n_hex_digits >= 4)
330 /* Save position of :: */
333 /* More than one :: ? */
334 if (double_colon_index < ARRAY_LEN (hex_quads))
336 double_colon_index = n_hex_quads;
339 if (n_colon > 0 && n_hex_digits > 0)
341 hex_quads[n_hex_quads++] = hex_quad;
347 if (n_hex_digits > 0)
348 hex_quads[n_hex_quads++] = hex_quad;
353 /* Expand :: to appropriate number of zero hex quads. */
354 if (double_colon_index < ARRAY_LEN (hex_quads))
356 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
358 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
359 hex_quads[n_zero + i] = hex_quads[i];
361 for (i = 0; i < n_zero; i++)
362 hex_quads[double_colon_index + i] = 0;
364 n_hex_quads = ARRAY_LEN (hex_quads);
367 /* Too few hex quads given. */
368 if (n_hex_quads < ARRAY_LEN (hex_quads))
371 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
372 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
379 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
381 u32 *r = va_arg (*args, u32 *);
384 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
385 foreach_ipsec_policy_action
393 format_ipsec_crypto_alg (u8 * s, va_list * args)
395 u32 i = va_arg (*args, u32);
400 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
401 foreach_ipsec_crypto_alg
404 return format (s, "unknown");
406 return format (s, "%s", t);
410 format_ipsec_integ_alg (u8 * s, va_list * args)
412 u32 i = va_arg (*args, u32);
417 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
418 foreach_ipsec_integ_alg
421 return format (s, "unknown");
423 return format (s, "%s", t);
426 #else /* VPP_API_TEST_BUILTIN == 1 */
428 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
430 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
431 vnet_main_t *vnm = vnet_get_main ();
432 u32 *result = va_arg (*args, u32 *);
434 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
438 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
440 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
441 vnet_main_t *vnm = vnet_get_main ();
442 u32 *result = va_arg (*args, u32 *);
444 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
447 #endif /* VPP_API_TEST_BUILTIN */
450 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
452 u32 *r = va_arg (*args, u32 *);
455 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
456 foreach_ipsec_crypto_alg
464 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
466 u32 *r = va_arg (*args, u32 *);
469 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
470 foreach_ipsec_integ_alg
478 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
480 u8 *r = va_arg (*args, u8 *);
482 if (unformat (input, "kbps"))
484 else if (unformat (input, "pps"))
492 unformat_policer_round_type (unformat_input_t * input, va_list * args)
494 u8 *r = va_arg (*args, u8 *);
496 if (unformat (input, "closest"))
497 *r = QOS_ROUND_TO_CLOSEST;
498 else if (unformat (input, "up"))
499 *r = QOS_ROUND_TO_UP;
500 else if (unformat (input, "down"))
501 *r = QOS_ROUND_TO_DOWN;
508 unformat_policer_type (unformat_input_t * input, va_list * args)
510 u8 *r = va_arg (*args, u8 *);
512 if (unformat (input, "1r2c"))
513 *r = QOS_POLICER_TYPE_1R2C;
514 else if (unformat (input, "1r3c"))
515 *r = QOS_POLICER_TYPE_1R3C_RFC_2697;
516 else if (unformat (input, "2r3c-2698"))
517 *r = QOS_POLICER_TYPE_2R3C_RFC_2698;
518 else if (unformat (input, "2r3c-4115"))
519 *r = QOS_POLICER_TYPE_2R3C_RFC_4115;
520 else if (unformat (input, "2r3c-mef5cf1"))
521 *r = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
528 unformat_dscp (unformat_input_t * input, va_list * va)
530 u8 *r = va_arg (*va, u8 *);
533 #define _(v, f) else if (unformat (input, #f)) *r = IP_DSCP_##f;
541 unformat_policer_action_type (unformat_input_t * input, va_list * va)
543 qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *);
545 if (unformat (input, "drop"))
546 a->action_type = QOS_ACTION_DROP;
547 else if (unformat (input, "transmit"))
548 a->action_type = QOS_ACTION_TRANSMIT;
549 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
550 a->action_type = QOS_ACTION_MARK_AND_TRANSMIT;
557 unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
559 u32 *r = va_arg (*va, u32 *);
562 if (unformat (input, "ip4"))
563 tid = POLICER_CLASSIFY_TABLE_IP4;
564 else if (unformat (input, "ip6"))
565 tid = POLICER_CLASSIFY_TABLE_IP6;
566 else if (unformat (input, "l2"))
567 tid = POLICER_CLASSIFY_TABLE_L2;
576 unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
578 u32 *r = va_arg (*va, u32 *);
581 if (unformat (input, "ip4"))
582 tid = FLOW_CLASSIFY_TABLE_IP4;
583 else if (unformat (input, "ip6"))
584 tid = FLOW_CLASSIFY_TABLE_IP6;
592 #if (VPP_API_TEST_BUILTIN==0)
594 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
595 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
596 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
597 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
600 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
602 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
603 mfib_itf_attribute_t attr;
606 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
608 if (unformat (input, mfib_itf_flag_long_names[attr]))
609 *iflags |= (1 << attr);
611 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
613 if (unformat (input, mfib_itf_flag_names[attr]))
614 *iflags |= (1 << attr);
617 return (old == *iflags ? 0 : 1);
621 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
623 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
624 mfib_entry_attribute_t attr;
627 FOR_EACH_MFIB_ATTRIBUTE (attr)
629 if (unformat (input, mfib_flag_long_names[attr]))
630 *eflags |= (1 << attr);
632 FOR_EACH_MFIB_ATTRIBUTE (attr)
634 if (unformat (input, mfib_flag_names[attr]))
635 *eflags |= (1 << attr);
638 return (old == *eflags ? 0 : 1);
642 format_ip4_address (u8 * s, va_list * args)
644 u8 *a = va_arg (*args, u8 *);
645 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
649 format_ip6_address (u8 * s, va_list * args)
651 ip6_address_t *a = va_arg (*args, ip6_address_t *);
652 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
654 i_max_n_zero = ARRAY_LEN (a->as_u16);
656 i_first_zero = i_max_n_zero;
658 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
660 u32 is_zero = a->as_u16[i] == 0;
661 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
667 if ((!is_zero && n_zeros > max_n_zeros)
668 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
670 i_max_n_zero = i_first_zero;
671 max_n_zeros = n_zeros;
672 i_first_zero = ARRAY_LEN (a->as_u16);
677 last_double_colon = 0;
678 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
680 if (i == i_max_n_zero && max_n_zeros > 1)
682 s = format (s, "::");
683 i += max_n_zeros - 1;
684 last_double_colon = 1;
688 s = format (s, "%s%x",
689 (last_double_colon || i == 0) ? "" : ":",
690 clib_net_to_host_u16 (a->as_u16[i]));
691 last_double_colon = 0;
698 /* Format an IP46 address. */
700 format_ip46_address (u8 * s, va_list * args)
702 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
703 ip46_type_t type = va_arg (*args, ip46_type_t);
709 is_ip4 = ip46_address_is_ip4 (ip46);
720 format (s, "%U", format_ip4_address, &ip46->ip4) :
721 format (s, "%U", format_ip6_address, &ip46->ip6);
725 format_ethernet_address (u8 * s, va_list * args)
727 u8 *a = va_arg (*args, u8 *);
729 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
730 a[0], a[1], a[2], a[3], a[4], a[5]);
735 increment_v4_address (vl_api_ip4_address_t * i)
737 ip4_address_t *a = (ip4_address_t *) i;
740 v = ntohl (a->as_u32) + 1;
741 a->as_u32 = ntohl (v);
745 increment_v6_address (vl_api_ip6_address_t * i)
747 ip6_address_t *a = (ip6_address_t *) i;
750 v0 = clib_net_to_host_u64 (a->as_u64[0]);
751 v1 = clib_net_to_host_u64 (a->as_u64[1]);
756 a->as_u64[0] = clib_net_to_host_u64 (v0);
757 a->as_u64[1] = clib_net_to_host_u64 (v1);
761 increment_address (vl_api_address_t * a)
763 if (a->af == ADDRESS_IP4)
764 increment_v4_address (&a->un.ip4);
765 else if (a->af == ADDRESS_IP6)
766 increment_v6_address (&a->un.ip6);
770 set_ip4_address (vl_api_address_t * a, u32 v)
772 if (a->af == ADDRESS_IP4)
774 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
780 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
783 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
785 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
786 sizeof (ip6_address_t));
790 increment_mac_address (u8 * mac)
792 u64 tmp = *((u64 *) mac);
793 tmp = clib_net_to_host_u64 (tmp);
794 tmp += 1 << 16; /* skip unused (least significant) octets */
795 tmp = clib_host_to_net_u64 (tmp);
797 clib_memcpy (mac, &tmp, 6);
801 vat_json_object_add_address (vat_json_node_t * node,
802 const char *str, const vl_api_address_t * addr)
804 if (ADDRESS_IP6 == addr->af)
808 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
809 vat_json_object_add_ip6 (node, str, ip6);
815 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
816 vat_json_object_add_ip4 (node, str, ip4);
821 vat_json_object_add_prefix (vat_json_node_t * node,
822 const vl_api_prefix_t * prefix)
824 vat_json_object_add_uint (node, "len", prefix->len);
825 vat_json_object_add_address (node, "address", &prefix->address);
828 static void vl_api_create_loopback_reply_t_handler
829 (vl_api_create_loopback_reply_t * mp)
831 vat_main_t *vam = &vat_main;
832 i32 retval = ntohl (mp->retval);
834 vam->retval = retval;
835 vam->regenerate_interface_table = 1;
836 vam->sw_if_index = ntohl (mp->sw_if_index);
837 vam->result_ready = 1;
840 static void vl_api_create_loopback_reply_t_handler_json
841 (vl_api_create_loopback_reply_t * mp)
843 vat_main_t *vam = &vat_main;
844 vat_json_node_t node;
846 vat_json_init_object (&node);
847 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
848 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
850 vat_json_print (vam->ofp, &node);
851 vat_json_free (&node);
852 vam->retval = ntohl (mp->retval);
853 vam->result_ready = 1;
856 static void vl_api_create_loopback_instance_reply_t_handler
857 (vl_api_create_loopback_instance_reply_t * mp)
859 vat_main_t *vam = &vat_main;
860 i32 retval = ntohl (mp->retval);
862 vam->retval = retval;
863 vam->regenerate_interface_table = 1;
864 vam->sw_if_index = ntohl (mp->sw_if_index);
865 vam->result_ready = 1;
868 static void vl_api_create_loopback_instance_reply_t_handler_json
869 (vl_api_create_loopback_instance_reply_t * mp)
871 vat_main_t *vam = &vat_main;
872 vat_json_node_t node;
874 vat_json_init_object (&node);
875 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
876 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
878 vat_json_print (vam->ofp, &node);
879 vat_json_free (&node);
880 vam->retval = ntohl (mp->retval);
881 vam->result_ready = 1;
884 static void vl_api_af_packet_create_reply_t_handler
885 (vl_api_af_packet_create_reply_t * mp)
887 vat_main_t *vam = &vat_main;
888 i32 retval = ntohl (mp->retval);
890 vam->retval = retval;
891 vam->regenerate_interface_table = 1;
892 vam->sw_if_index = ntohl (mp->sw_if_index);
893 vam->result_ready = 1;
896 static void vl_api_af_packet_create_reply_t_handler_json
897 (vl_api_af_packet_create_reply_t * mp)
899 vat_main_t *vam = &vat_main;
900 vat_json_node_t node;
902 vat_json_init_object (&node);
903 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
904 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
906 vat_json_print (vam->ofp, &node);
907 vat_json_free (&node);
909 vam->retval = ntohl (mp->retval);
910 vam->result_ready = 1;
913 static void vl_api_create_vlan_subif_reply_t_handler
914 (vl_api_create_vlan_subif_reply_t * mp)
916 vat_main_t *vam = &vat_main;
917 i32 retval = ntohl (mp->retval);
919 vam->retval = retval;
920 vam->regenerate_interface_table = 1;
921 vam->sw_if_index = ntohl (mp->sw_if_index);
922 vam->result_ready = 1;
925 static void vl_api_create_vlan_subif_reply_t_handler_json
926 (vl_api_create_vlan_subif_reply_t * mp)
928 vat_main_t *vam = &vat_main;
929 vat_json_node_t node;
931 vat_json_init_object (&node);
932 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
933 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
935 vat_json_print (vam->ofp, &node);
936 vat_json_free (&node);
938 vam->retval = ntohl (mp->retval);
939 vam->result_ready = 1;
942 static void vl_api_create_subif_reply_t_handler
943 (vl_api_create_subif_reply_t * mp)
945 vat_main_t *vam = &vat_main;
946 i32 retval = ntohl (mp->retval);
948 vam->retval = retval;
949 vam->regenerate_interface_table = 1;
950 vam->sw_if_index = ntohl (mp->sw_if_index);
951 vam->result_ready = 1;
954 static void vl_api_create_subif_reply_t_handler_json
955 (vl_api_create_subif_reply_t * mp)
957 vat_main_t *vam = &vat_main;
958 vat_json_node_t node;
960 vat_json_init_object (&node);
961 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
962 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
964 vat_json_print (vam->ofp, &node);
965 vat_json_free (&node);
967 vam->retval = ntohl (mp->retval);
968 vam->result_ready = 1;
971 static void vl_api_interface_name_renumber_reply_t_handler
972 (vl_api_interface_name_renumber_reply_t * mp)
974 vat_main_t *vam = &vat_main;
975 i32 retval = ntohl (mp->retval);
977 vam->retval = retval;
978 vam->regenerate_interface_table = 1;
979 vam->result_ready = 1;
982 static void vl_api_interface_name_renumber_reply_t_handler_json
983 (vl_api_interface_name_renumber_reply_t * mp)
985 vat_main_t *vam = &vat_main;
986 vat_json_node_t node;
988 vat_json_init_object (&node);
989 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
991 vat_json_print (vam->ofp, &node);
992 vat_json_free (&node);
994 vam->retval = ntohl (mp->retval);
995 vam->result_ready = 1;
999 * Special-case: build the interface table, maintain
1000 * the next loopback sw_if_index vbl.
1002 static void vl_api_sw_interface_details_t_handler
1003 (vl_api_sw_interface_details_t * mp)
1005 vat_main_t *vam = &vat_main;
1006 u8 *s = format (0, "%s%c", mp->interface_name, 0);
1008 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1009 ntohl (mp->sw_if_index));
1011 /* In sub interface case, fill the sub interface table entry */
1012 if (mp->sw_if_index != mp->sup_sw_if_index)
1014 sw_interface_subif_t *sub = NULL;
1016 vec_add2 (vam->sw_if_subif_table, sub, 1);
1018 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1019 strncpy ((char *) sub->interface_name, (char *) s,
1020 vec_len (sub->interface_name));
1021 sub->sw_if_index = ntohl (mp->sw_if_index);
1022 sub->sub_id = ntohl (mp->sub_id);
1024 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1026 sub->sub_number_of_tags = mp->sub_number_of_tags;
1027 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1028 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
1030 /* vlan tag rewrite */
1031 sub->vtr_op = ntohl (mp->vtr_op);
1032 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1033 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1034 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1038 static void vl_api_sw_interface_details_t_handler_json
1039 (vl_api_sw_interface_details_t * mp)
1041 vat_main_t *vam = &vat_main;
1042 vat_json_node_t *node = NULL;
1044 if (VAT_JSON_ARRAY != vam->json_tree.type)
1046 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1047 vat_json_init_array (&vam->json_tree);
1049 node = vat_json_array_add (&vam->json_tree);
1051 vat_json_init_object (node);
1052 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1053 vat_json_object_add_uint (node, "sup_sw_if_index",
1054 ntohl (mp->sup_sw_if_index));
1055 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1056 sizeof (mp->l2_address));
1057 vat_json_object_add_string_copy (node, "interface_name",
1058 mp->interface_name);
1059 vat_json_object_add_string_copy (node, "interface_dev_type",
1060 mp->interface_dev_type);
1061 vat_json_object_add_uint (node, "flags", mp->flags);
1062 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1063 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1064 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1065 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1066 vat_json_object_add_uint (node, "sub_number_of_tags",
1067 mp->sub_number_of_tags);
1068 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1069 ntohs (mp->sub_outer_vlan_id));
1070 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1071 ntohs (mp->sub_inner_vlan_id));
1072 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1073 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1074 vat_json_object_add_uint (node, "vtr_push_dot1q",
1075 ntohl (mp->vtr_push_dot1q));
1076 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1077 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1078 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1080 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1082 format_ethernet_address,
1084 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1086 format_ethernet_address,
1088 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1089 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1093 #if VPP_API_TEST_BUILTIN == 0
1094 static void vl_api_sw_interface_event_t_handler
1095 (vl_api_sw_interface_event_t * mp)
1097 vat_main_t *vam = &vat_main;
1098 if (vam->interface_event_display)
1099 errmsg ("interface flags: sw_if_index %d %s %s",
1100 ntohl (mp->sw_if_index),
1101 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1102 "admin-up" : "admin-down",
1103 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1104 "link-up" : "link-down");
1108 __clib_unused static void
1109 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1111 /* JSON output not supported */
1115 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1117 vat_main_t *vam = &vat_main;
1118 i32 retval = ntohl (mp->retval);
1120 vam->retval = retval;
1121 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1122 vam->result_ready = 1;
1126 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1128 vat_main_t *vam = &vat_main;
1129 vat_json_node_t node;
1133 vat_json_init_object (&node);
1134 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1135 vat_json_object_add_uint (&node, "reply_in_shmem",
1136 ntohl (mp->reply_in_shmem));
1137 /* Toss the shared-memory original... */
1138 oldheap = vl_msg_push_heap ();
1140 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1143 vl_msg_pop_heap (oldheap);
1145 vat_json_print (vam->ofp, &node);
1146 vat_json_free (&node);
1148 vam->retval = ntohl (mp->retval);
1149 vam->result_ready = 1;
1153 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1155 vat_main_t *vam = &vat_main;
1156 i32 retval = ntohl (mp->retval);
1158 vec_reset_length (vam->cmd_reply);
1160 vam->retval = retval;
1162 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1163 vam->result_ready = 1;
1167 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1169 vat_main_t *vam = &vat_main;
1170 vat_json_node_t node;
1171 u8 *reply = 0; /* reply vector */
1173 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1174 vec_reset_length (vam->cmd_reply);
1176 vat_json_init_object (&node);
1177 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1178 vat_json_object_add_string_copy (&node, "reply", reply);
1180 vat_json_print (vam->ofp, &node);
1181 vat_json_free (&node);
1184 vam->retval = ntohl (mp->retval);
1185 vam->result_ready = 1;
1188 static void vl_api_classify_add_del_table_reply_t_handler
1189 (vl_api_classify_add_del_table_reply_t * mp)
1191 vat_main_t *vam = &vat_main;
1192 i32 retval = ntohl (mp->retval);
1193 if (vam->async_mode)
1195 vam->async_errors += (retval < 0);
1199 vam->retval = retval;
1201 ((mp->new_table_index != 0xFFFFFFFF) ||
1202 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1203 (mp->match_n_vectors != 0xFFFFFFFF)))
1205 * Note: this is just barely thread-safe, depends on
1206 * the main thread spinning waiting for an answer...
1208 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1209 ntohl (mp->new_table_index),
1210 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1211 vam->result_ready = 1;
1215 static void vl_api_classify_add_del_table_reply_t_handler_json
1216 (vl_api_classify_add_del_table_reply_t * mp)
1218 vat_main_t *vam = &vat_main;
1219 vat_json_node_t node;
1221 vat_json_init_object (&node);
1222 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1223 vat_json_object_add_uint (&node, "new_table_index",
1224 ntohl (mp->new_table_index));
1225 vat_json_object_add_uint (&node, "skip_n_vectors",
1226 ntohl (mp->skip_n_vectors));
1227 vat_json_object_add_uint (&node, "match_n_vectors",
1228 ntohl (mp->match_n_vectors));
1230 vat_json_print (vam->ofp, &node);
1231 vat_json_free (&node);
1233 vam->retval = ntohl (mp->retval);
1234 vam->result_ready = 1;
1237 static void vl_api_get_node_index_reply_t_handler
1238 (vl_api_get_node_index_reply_t * mp)
1240 vat_main_t *vam = &vat_main;
1241 i32 retval = ntohl (mp->retval);
1242 if (vam->async_mode)
1244 vam->async_errors += (retval < 0);
1248 vam->retval = retval;
1250 errmsg ("node index %d", ntohl (mp->node_index));
1251 vam->result_ready = 1;
1255 static void vl_api_get_node_index_reply_t_handler_json
1256 (vl_api_get_node_index_reply_t * mp)
1258 vat_main_t *vam = &vat_main;
1259 vat_json_node_t node;
1261 vat_json_init_object (&node);
1262 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1263 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1265 vat_json_print (vam->ofp, &node);
1266 vat_json_free (&node);
1268 vam->retval = ntohl (mp->retval);
1269 vam->result_ready = 1;
1272 static void vl_api_get_next_index_reply_t_handler
1273 (vl_api_get_next_index_reply_t * mp)
1275 vat_main_t *vam = &vat_main;
1276 i32 retval = ntohl (mp->retval);
1277 if (vam->async_mode)
1279 vam->async_errors += (retval < 0);
1283 vam->retval = retval;
1285 errmsg ("next node index %d", ntohl (mp->next_index));
1286 vam->result_ready = 1;
1290 static void vl_api_get_next_index_reply_t_handler_json
1291 (vl_api_get_next_index_reply_t * mp)
1293 vat_main_t *vam = &vat_main;
1294 vat_json_node_t node;
1296 vat_json_init_object (&node);
1297 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1298 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1300 vat_json_print (vam->ofp, &node);
1301 vat_json_free (&node);
1303 vam->retval = ntohl (mp->retval);
1304 vam->result_ready = 1;
1307 static void vl_api_add_node_next_reply_t_handler
1308 (vl_api_add_node_next_reply_t * mp)
1310 vat_main_t *vam = &vat_main;
1311 i32 retval = ntohl (mp->retval);
1312 if (vam->async_mode)
1314 vam->async_errors += (retval < 0);
1318 vam->retval = retval;
1320 errmsg ("next index %d", ntohl (mp->next_index));
1321 vam->result_ready = 1;
1325 static void vl_api_add_node_next_reply_t_handler_json
1326 (vl_api_add_node_next_reply_t * mp)
1328 vat_main_t *vam = &vat_main;
1329 vat_json_node_t node;
1331 vat_json_init_object (&node);
1332 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1333 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1335 vat_json_print (vam->ofp, &node);
1336 vat_json_free (&node);
1338 vam->retval = ntohl (mp->retval);
1339 vam->result_ready = 1;
1342 static void vl_api_show_version_reply_t_handler
1343 (vl_api_show_version_reply_t * mp)
1345 vat_main_t *vam = &vat_main;
1346 i32 retval = ntohl (mp->retval);
1350 errmsg (" program: %s", mp->program);
1351 errmsg (" version: %s", mp->version);
1352 errmsg (" build date: %s", mp->build_date);
1353 errmsg ("build directory: %s", mp->build_directory);
1355 vam->retval = retval;
1356 vam->result_ready = 1;
1359 static void vl_api_show_version_reply_t_handler_json
1360 (vl_api_show_version_reply_t * mp)
1362 vat_main_t *vam = &vat_main;
1363 vat_json_node_t node;
1365 vat_json_init_object (&node);
1366 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1367 vat_json_object_add_string_copy (&node, "program", mp->program);
1368 vat_json_object_add_string_copy (&node, "version", mp->version);
1369 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1370 vat_json_object_add_string_copy (&node, "build_directory",
1371 mp->build_directory);
1373 vat_json_print (vam->ofp, &node);
1374 vat_json_free (&node);
1376 vam->retval = ntohl (mp->retval);
1377 vam->result_ready = 1;
1380 static void vl_api_show_threads_reply_t_handler
1381 (vl_api_show_threads_reply_t * mp)
1383 vat_main_t *vam = &vat_main;
1384 i32 retval = ntohl (mp->retval);
1388 count = ntohl (mp->count);
1390 for (i = 0; i < count; i++)
1392 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1393 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1394 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1395 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1396 ntohl (mp->thread_data[i].cpu_socket));
1398 vam->retval = retval;
1399 vam->result_ready = 1;
1402 static void vl_api_show_threads_reply_t_handler_json
1403 (vl_api_show_threads_reply_t * mp)
1405 vat_main_t *vam = &vat_main;
1406 vat_json_node_t node;
1407 vl_api_thread_data_t *td;
1408 i32 retval = ntohl (mp->retval);
1412 count = ntohl (mp->count);
1414 vat_json_init_object (&node);
1415 vat_json_object_add_int (&node, "retval", retval);
1416 vat_json_object_add_uint (&node, "count", count);
1418 for (i = 0; i < count; i++)
1420 td = &mp->thread_data[i];
1421 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1422 vat_json_object_add_string_copy (&node, "name", td->name);
1423 vat_json_object_add_string_copy (&node, "type", td->type);
1424 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1425 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1426 vat_json_object_add_int (&node, "core", ntohl (td->id));
1427 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1430 vat_json_print (vam->ofp, &node);
1431 vat_json_free (&node);
1433 vam->retval = retval;
1434 vam->result_ready = 1;
1438 api_show_threads (vat_main_t * vam)
1440 vl_api_show_threads_t *mp;
1444 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1445 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1447 M (SHOW_THREADS, mp);
1455 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1457 u32 n_macs = ntohl (mp->n_macs);
1458 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1459 ntohl (mp->pid), mp->client_index, n_macs);
1461 for (i = 0; i < n_macs; i++)
1463 vl_api_mac_entry_t *mac = &mp->mac[i];
1464 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1465 i + 1, ntohl (mac->sw_if_index),
1466 format_ethernet_address, mac->mac_addr, mac->action);
1473 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1475 /* JSON output not supported */
1478 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1479 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1482 * Special-case: build the bridge domain table, maintain
1483 * the next bd id vbl.
1485 static void vl_api_bridge_domain_details_t_handler
1486 (vl_api_bridge_domain_details_t * mp)
1488 vat_main_t *vam = &vat_main;
1489 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1492 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1493 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1495 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1496 ntohl (mp->bd_id), mp->learn, mp->forward,
1497 mp->flood, ntohl (mp->bvi_sw_if_index),
1498 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1502 vl_api_bridge_domain_sw_if_t *sw_ifs;
1503 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1506 sw_ifs = mp->sw_if_details;
1507 for (i = 0; i < n_sw_ifs; i++)
1513 sw_if_index = ntohl (sw_ifs->sw_if_index);
1516 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1518 if ((u32) p->value[0] == sw_if_index)
1520 sw_if_name = (u8 *)(p->key);
1525 print (vam->ofp, "%7d %3d %s", sw_if_index,
1526 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1527 "sw_if_index not found!");
1534 static void vl_api_bridge_domain_details_t_handler_json
1535 (vl_api_bridge_domain_details_t * mp)
1537 vat_main_t *vam = &vat_main;
1538 vat_json_node_t *node, *array = NULL;
1539 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1541 if (VAT_JSON_ARRAY != vam->json_tree.type)
1543 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1544 vat_json_init_array (&vam->json_tree);
1546 node = vat_json_array_add (&vam->json_tree);
1548 vat_json_init_object (node);
1549 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1550 vat_json_object_add_uint (node, "flood", mp->flood);
1551 vat_json_object_add_uint (node, "forward", mp->forward);
1552 vat_json_object_add_uint (node, "learn", mp->learn);
1553 vat_json_object_add_uint (node, "bvi_sw_if_index",
1554 ntohl (mp->bvi_sw_if_index));
1555 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1556 array = vat_json_object_add (node, "sw_if");
1557 vat_json_init_array (array);
1563 vl_api_bridge_domain_sw_if_t *sw_ifs;
1566 sw_ifs = mp->sw_if_details;
1567 for (i = 0; i < n_sw_ifs; i++)
1569 node = vat_json_array_add (array);
1570 vat_json_init_object (node);
1571 vat_json_object_add_uint (node, "sw_if_index",
1572 ntohl (sw_ifs->sw_if_index));
1573 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1579 static void vl_api_control_ping_reply_t_handler
1580 (vl_api_control_ping_reply_t * mp)
1582 vat_main_t *vam = &vat_main;
1583 i32 retval = ntohl (mp->retval);
1584 if (vam->async_mode)
1586 vam->async_errors += (retval < 0);
1590 vam->retval = retval;
1591 vam->result_ready = 1;
1593 if (vam->socket_client_main)
1594 vam->socket_client_main->control_pings_outstanding--;
1597 static void vl_api_control_ping_reply_t_handler_json
1598 (vl_api_control_ping_reply_t * mp)
1600 vat_main_t *vam = &vat_main;
1601 i32 retval = ntohl (mp->retval);
1603 if (VAT_JSON_NONE != vam->json_tree.type)
1605 vat_json_print (vam->ofp, &vam->json_tree);
1606 vat_json_free (&vam->json_tree);
1607 vam->json_tree.type = VAT_JSON_NONE;
1612 vat_json_init_array (&vam->json_tree);
1613 vat_json_print (vam->ofp, &vam->json_tree);
1614 vam->json_tree.type = VAT_JSON_NONE;
1617 vam->retval = retval;
1618 vam->result_ready = 1;
1622 vl_api_bridge_domain_set_mac_age_reply_t_handler
1623 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1625 vat_main_t *vam = &vat_main;
1626 i32 retval = ntohl (mp->retval);
1627 if (vam->async_mode)
1629 vam->async_errors += (retval < 0);
1633 vam->retval = retval;
1634 vam->result_ready = 1;
1638 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1639 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1641 vat_main_t *vam = &vat_main;
1642 vat_json_node_t node;
1644 vat_json_init_object (&node);
1645 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1647 vat_json_print (vam->ofp, &node);
1648 vat_json_free (&node);
1650 vam->retval = ntohl (mp->retval);
1651 vam->result_ready = 1;
1655 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1657 vat_main_t *vam = &vat_main;
1658 i32 retval = ntohl (mp->retval);
1659 if (vam->async_mode)
1661 vam->async_errors += (retval < 0);
1665 vam->retval = retval;
1666 vam->result_ready = 1;
1670 static void vl_api_l2_flags_reply_t_handler_json
1671 (vl_api_l2_flags_reply_t * mp)
1673 vat_main_t *vam = &vat_main;
1674 vat_json_node_t node;
1676 vat_json_init_object (&node);
1677 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1678 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1679 ntohl (mp->resulting_feature_bitmap));
1681 vat_json_print (vam->ofp, &node);
1682 vat_json_free (&node);
1684 vam->retval = ntohl (mp->retval);
1685 vam->result_ready = 1;
1688 static void vl_api_bridge_flags_reply_t_handler
1689 (vl_api_bridge_flags_reply_t * mp)
1691 vat_main_t *vam = &vat_main;
1692 i32 retval = ntohl (mp->retval);
1693 if (vam->async_mode)
1695 vam->async_errors += (retval < 0);
1699 vam->retval = retval;
1700 vam->result_ready = 1;
1704 static void vl_api_bridge_flags_reply_t_handler_json
1705 (vl_api_bridge_flags_reply_t * mp)
1707 vat_main_t *vam = &vat_main;
1708 vat_json_node_t node;
1710 vat_json_init_object (&node);
1711 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1712 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1713 ntohl (mp->resulting_feature_bitmap));
1715 vat_json_print (vam->ofp, &node);
1716 vat_json_free (&node);
1718 vam->retval = ntohl (mp->retval);
1719 vam->result_ready = 1;
1723 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1725 vat_main_t *vam = &vat_main;
1726 i32 retval = ntohl (mp->retval);
1727 if (vam->async_mode)
1729 vam->async_errors += (retval < 0);
1733 vam->retval = retval;
1734 vam->sw_if_index = ntohl (mp->sw_if_index);
1735 vam->result_ready = 1;
1740 static void vl_api_tap_create_v2_reply_t_handler_json
1741 (vl_api_tap_create_v2_reply_t * mp)
1743 vat_main_t *vam = &vat_main;
1744 vat_json_node_t node;
1746 vat_json_init_object (&node);
1747 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1748 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1750 vat_json_print (vam->ofp, &node);
1751 vat_json_free (&node);
1753 vam->retval = ntohl (mp->retval);
1754 vam->result_ready = 1;
1759 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1761 vat_main_t *vam = &vat_main;
1762 i32 retval = ntohl (mp->retval);
1763 if (vam->async_mode)
1765 vam->async_errors += (retval < 0);
1769 vam->retval = retval;
1770 vam->result_ready = 1;
1774 static void vl_api_tap_delete_v2_reply_t_handler_json
1775 (vl_api_tap_delete_v2_reply_t * mp)
1777 vat_main_t *vam = &vat_main;
1778 vat_json_node_t node;
1780 vat_json_init_object (&node);
1781 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1783 vat_json_print (vam->ofp, &node);
1784 vat_json_free (&node);
1786 vam->retval = ntohl (mp->retval);
1787 vam->result_ready = 1;
1791 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1794 vat_main_t *vam = &vat_main;
1795 i32 retval = ntohl (mp->retval);
1796 if (vam->async_mode)
1798 vam->async_errors += (retval < 0);
1802 vam->retval = retval;
1803 vam->sw_if_index = ntohl (mp->sw_if_index);
1804 vam->result_ready = 1;
1808 static void vl_api_virtio_pci_create_reply_t_handler_json
1809 (vl_api_virtio_pci_create_reply_t * mp)
1811 vat_main_t *vam = &vat_main;
1812 vat_json_node_t node;
1814 vat_json_init_object (&node);
1815 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1816 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1818 vat_json_print (vam->ofp, &node);
1819 vat_json_free (&node);
1821 vam->retval = ntohl (mp->retval);
1822 vam->result_ready = 1;
1827 vl_api_virtio_pci_create_v2_reply_t_handler
1828 (vl_api_virtio_pci_create_v2_reply_t * mp)
1830 vat_main_t *vam = &vat_main;
1831 i32 retval = ntohl (mp->retval);
1832 if (vam->async_mode)
1834 vam->async_errors += (retval < 0);
1838 vam->retval = retval;
1839 vam->sw_if_index = ntohl (mp->sw_if_index);
1840 vam->result_ready = 1;
1844 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1845 (vl_api_virtio_pci_create_v2_reply_t * mp)
1847 vat_main_t *vam = &vat_main;
1848 vat_json_node_t node;
1850 vat_json_init_object (&node);
1851 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1852 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1854 vat_json_print (vam->ofp, &node);
1855 vat_json_free (&node);
1857 vam->retval = ntohl (mp->retval);
1858 vam->result_ready = 1;
1862 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1865 vat_main_t *vam = &vat_main;
1866 i32 retval = ntohl (mp->retval);
1867 if (vam->async_mode)
1869 vam->async_errors += (retval < 0);
1873 vam->retval = retval;
1874 vam->result_ready = 1;
1878 static void vl_api_virtio_pci_delete_reply_t_handler_json
1879 (vl_api_virtio_pci_delete_reply_t * mp)
1881 vat_main_t *vam = &vat_main;
1882 vat_json_node_t node;
1884 vat_json_init_object (&node);
1885 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1887 vat_json_print (vam->ofp, &node);
1888 vat_json_free (&node);
1890 vam->retval = ntohl (mp->retval);
1891 vam->result_ready = 1;
1895 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1897 vat_main_t *vam = &vat_main;
1898 i32 retval = ntohl (mp->retval);
1900 if (vam->async_mode)
1902 vam->async_errors += (retval < 0);
1906 vam->retval = retval;
1907 vam->sw_if_index = ntohl (mp->sw_if_index);
1908 vam->result_ready = 1;
1912 static void vl_api_bond_create_reply_t_handler_json
1913 (vl_api_bond_create_reply_t * mp)
1915 vat_main_t *vam = &vat_main;
1916 vat_json_node_t node;
1918 vat_json_init_object (&node);
1919 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1920 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1922 vat_json_print (vam->ofp, &node);
1923 vat_json_free (&node);
1925 vam->retval = ntohl (mp->retval);
1926 vam->result_ready = 1;
1930 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1932 vat_main_t *vam = &vat_main;
1933 i32 retval = ntohl (mp->retval);
1935 if (vam->async_mode)
1937 vam->async_errors += (retval < 0);
1941 vam->retval = retval;
1942 vam->sw_if_index = ntohl (mp->sw_if_index);
1943 vam->result_ready = 1;
1947 static void vl_api_bond_create2_reply_t_handler_json
1948 (vl_api_bond_create2_reply_t * mp)
1950 vat_main_t *vam = &vat_main;
1951 vat_json_node_t node;
1953 vat_json_init_object (&node);
1954 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1955 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1957 vat_json_print (vam->ofp, &node);
1958 vat_json_free (&node);
1960 vam->retval = ntohl (mp->retval);
1961 vam->result_ready = 1;
1965 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1967 vat_main_t *vam = &vat_main;
1968 i32 retval = ntohl (mp->retval);
1970 if (vam->async_mode)
1972 vam->async_errors += (retval < 0);
1976 vam->retval = retval;
1977 vam->result_ready = 1;
1981 static void vl_api_bond_delete_reply_t_handler_json
1982 (vl_api_bond_delete_reply_t * mp)
1984 vat_main_t *vam = &vat_main;
1985 vat_json_node_t node;
1987 vat_json_init_object (&node);
1988 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1990 vat_json_print (vam->ofp, &node);
1991 vat_json_free (&node);
1993 vam->retval = ntohl (mp->retval);
1994 vam->result_ready = 1;
1998 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
2000 vat_main_t *vam = &vat_main;
2001 i32 retval = ntohl (mp->retval);
2003 if (vam->async_mode)
2005 vam->async_errors += (retval < 0);
2009 vam->retval = retval;
2010 vam->result_ready = 1;
2014 static void vl_api_bond_add_member_reply_t_handler_json
2015 (vl_api_bond_add_member_reply_t * mp)
2017 vat_main_t *vam = &vat_main;
2018 vat_json_node_t node;
2020 vat_json_init_object (&node);
2021 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2023 vat_json_print (vam->ofp, &node);
2024 vat_json_free (&node);
2026 vam->retval = ntohl (mp->retval);
2027 vam->result_ready = 1;
2031 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
2034 vat_main_t *vam = &vat_main;
2035 i32 retval = ntohl (mp->retval);
2037 if (vam->async_mode)
2039 vam->async_errors += (retval < 0);
2043 vam->retval = retval;
2044 vam->result_ready = 1;
2048 static void vl_api_bond_detach_member_reply_t_handler_json
2049 (vl_api_bond_detach_member_reply_t * mp)
2051 vat_main_t *vam = &vat_main;
2052 vat_json_node_t node;
2054 vat_json_init_object (&node);
2055 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2057 vat_json_print (vam->ofp, &node);
2058 vat_json_free (&node);
2060 vam->retval = ntohl (mp->retval);
2061 vam->result_ready = 1;
2065 api_sw_interface_set_bond_weight (vat_main_t * vam)
2067 unformat_input_t *i = vam->input;
2068 vl_api_sw_interface_set_bond_weight_t *mp;
2069 u32 sw_if_index = ~0;
2071 u8 weight_enter = 0;
2074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2076 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2078 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2080 else if (unformat (i, "weight %u", &weight))
2086 if (sw_if_index == ~0)
2088 errmsg ("missing interface name or sw_if_index");
2091 if (weight_enter == 0)
2093 errmsg ("missing valid weight");
2097 /* Construct the API message */
2098 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2099 mp->sw_if_index = ntohl (sw_if_index);
2100 mp->weight = ntohl (weight);
2107 static void vl_api_sw_bond_interface_details_t_handler
2108 (vl_api_sw_bond_interface_details_t * mp)
2110 vat_main_t *vam = &vat_main;
2113 "%-16s %-12d %-12U %-13U %-14u %-14u",
2114 mp->interface_name, ntohl (mp->sw_if_index),
2115 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2116 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2119 static void vl_api_sw_bond_interface_details_t_handler_json
2120 (vl_api_sw_bond_interface_details_t * mp)
2122 vat_main_t *vam = &vat_main;
2123 vat_json_node_t *node = NULL;
2125 if (VAT_JSON_ARRAY != vam->json_tree.type)
2127 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2128 vat_json_init_array (&vam->json_tree);
2130 node = vat_json_array_add (&vam->json_tree);
2132 vat_json_init_object (node);
2133 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2134 vat_json_object_add_string_copy (node, "interface_name",
2135 mp->interface_name);
2136 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2137 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2138 vat_json_object_add_uint (node, "active_members",
2139 ntohl (mp->active_members));
2140 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2144 api_sw_bond_interface_dump (vat_main_t * vam)
2146 unformat_input_t *i = vam->input;
2147 vl_api_sw_bond_interface_dump_t *mp;
2148 vl_api_control_ping_t *mp_ping;
2150 u32 sw_if_index = ~0;
2152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2154 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2156 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2163 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2164 "interface name", "sw_if_index", "mode", "load balance",
2165 "active members", "members");
2167 /* Get list of bond interfaces */
2168 M (SW_BOND_INTERFACE_DUMP, mp);
2169 mp->sw_if_index = ntohl (sw_if_index);
2172 /* Use a control ping for synchronization */
2173 MPING (CONTROL_PING, mp_ping);
2180 static void vl_api_sw_member_interface_details_t_handler
2181 (vl_api_sw_member_interface_details_t * mp)
2183 vat_main_t *vam = &vat_main;
2186 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2187 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2188 ntohl (mp->weight), mp->is_local_numa);
2191 static void vl_api_sw_member_interface_details_t_handler_json
2192 (vl_api_sw_member_interface_details_t * mp)
2194 vat_main_t *vam = &vat_main;
2195 vat_json_node_t *node = NULL;
2197 if (VAT_JSON_ARRAY != vam->json_tree.type)
2199 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2200 vat_json_init_array (&vam->json_tree);
2202 node = vat_json_array_add (&vam->json_tree);
2204 vat_json_init_object (node);
2205 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2206 vat_json_object_add_string_copy (node, "interface_name",
2207 mp->interface_name);
2208 vat_json_object_add_uint (node, "passive", mp->is_passive);
2209 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2210 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2211 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2215 api_sw_member_interface_dump (vat_main_t * vam)
2217 unformat_input_t *i = vam->input;
2218 vl_api_sw_member_interface_dump_t *mp;
2219 vl_api_control_ping_t *mp_ping;
2220 u32 sw_if_index = ~0;
2221 u8 sw_if_index_set = 0;
2224 /* Parse args required to build the message */
2225 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2227 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2228 sw_if_index_set = 1;
2229 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2230 sw_if_index_set = 1;
2235 if (sw_if_index_set == 0)
2237 errmsg ("missing vpp interface name. ");
2242 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2243 "member interface name", "sw_if_index", "passive", "long_timeout",
2244 "weight", "local numa");
2246 /* Get list of bond interfaces */
2247 M (SW_MEMBER_INTERFACE_DUMP, mp);
2248 mp->sw_if_index = ntohl (sw_if_index);
2251 /* Use a control ping for synchronization */
2252 MPING (CONTROL_PING, mp_ping);
2259 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2260 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2262 vat_main_t *vam = &vat_main;
2263 i32 retval = ntohl (mp->retval);
2264 if (vam->async_mode)
2266 vam->async_errors += (retval < 0);
2270 vam->retval = retval;
2271 vam->sw_if_index = ntohl (mp->sw_if_index);
2272 vam->result_ready = 1;
2274 vam->regenerate_interface_table = 1;
2277 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2278 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2280 vat_main_t *vam = &vat_main;
2281 vat_json_node_t node;
2283 vat_json_init_object (&node);
2284 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2285 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2286 ntohl (mp->sw_if_index));
2288 vat_json_print (vam->ofp, &node);
2289 vat_json_free (&node);
2291 vam->retval = ntohl (mp->retval);
2292 vam->result_ready = 1;
2295 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2296 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2298 vat_main_t *vam = &vat_main;
2299 i32 retval = ntohl (mp->retval);
2300 if (vam->async_mode)
2302 vam->async_errors += (retval < 0);
2306 vam->retval = retval;
2307 vam->sw_if_index = ntohl (mp->sw_if_index);
2308 vam->result_ready = 1;
2310 vam->regenerate_interface_table = 1;
2313 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2314 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2316 vat_main_t *vam = &vat_main;
2317 vat_json_node_t node;
2319 vat_json_init_object (&node);
2320 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2321 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2323 vat_json_print (vam->ofp, &node);
2324 vat_json_free (&node);
2326 vam->retval = ntohl (mp->retval);
2327 vam->result_ready = 1;
2330 static void vl_api_vxlan_offload_rx_reply_t_handler
2331 (vl_api_vxlan_offload_rx_reply_t * mp)
2333 vat_main_t *vam = &vat_main;
2334 i32 retval = ntohl (mp->retval);
2335 if (vam->async_mode)
2337 vam->async_errors += (retval < 0);
2341 vam->retval = retval;
2342 vam->result_ready = 1;
2346 static void vl_api_vxlan_offload_rx_reply_t_handler_json
2347 (vl_api_vxlan_offload_rx_reply_t * mp)
2349 vat_main_t *vam = &vat_main;
2350 vat_json_node_t node;
2352 vat_json_init_object (&node);
2353 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2355 vat_json_print (vam->ofp, &node);
2356 vat_json_free (&node);
2358 vam->retval = ntohl (mp->retval);
2359 vam->result_ready = 1;
2362 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2363 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2365 vat_main_t *vam = &vat_main;
2366 i32 retval = ntohl (mp->retval);
2367 if (vam->async_mode)
2369 vam->async_errors += (retval < 0);
2373 vam->retval = retval;
2374 vam->sw_if_index = ntohl (mp->sw_if_index);
2375 vam->result_ready = 1;
2377 vam->regenerate_interface_table = 1;
2380 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2381 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2383 vat_main_t *vam = &vat_main;
2384 vat_json_node_t node;
2386 vat_json_init_object (&node);
2387 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2388 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2390 vat_json_print (vam->ofp, &node);
2391 vat_json_free (&node);
2393 vam->retval = ntohl (mp->retval);
2394 vam->result_ready = 1;
2397 static void vl_api_create_vhost_user_if_reply_t_handler
2398 (vl_api_create_vhost_user_if_reply_t * mp)
2400 vat_main_t *vam = &vat_main;
2401 i32 retval = ntohl (mp->retval);
2402 if (vam->async_mode)
2404 vam->async_errors += (retval < 0);
2408 vam->retval = retval;
2409 vam->sw_if_index = ntohl (mp->sw_if_index);
2410 vam->result_ready = 1;
2412 vam->regenerate_interface_table = 1;
2415 static void vl_api_create_vhost_user_if_reply_t_handler_json
2416 (vl_api_create_vhost_user_if_reply_t * mp)
2418 vat_main_t *vam = &vat_main;
2419 vat_json_node_t node;
2421 vat_json_init_object (&node);
2422 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2423 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2425 vat_json_print (vam->ofp, &node);
2426 vat_json_free (&node);
2428 vam->retval = ntohl (mp->retval);
2429 vam->result_ready = 1;
2432 static void vl_api_create_vhost_user_if_v2_reply_t_handler
2433 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2435 vat_main_t *vam = &vat_main;
2436 i32 retval = ntohl (mp->retval);
2437 if (vam->async_mode)
2439 vam->async_errors += (retval < 0);
2443 vam->retval = retval;
2444 vam->sw_if_index = ntohl (mp->sw_if_index);
2445 vam->result_ready = 1;
2447 vam->regenerate_interface_table = 1;
2450 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2451 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2453 vat_main_t *vam = &vat_main;
2454 vat_json_node_t node;
2456 vat_json_init_object (&node);
2457 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2458 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2460 vat_json_print (vam->ofp, &node);
2461 vat_json_free (&node);
2463 vam->retval = ntohl (mp->retval);
2464 vam->result_ready = 1;
2467 static void vl_api_ip_address_details_t_handler
2468 (vl_api_ip_address_details_t * mp)
2470 vat_main_t *vam = &vat_main;
2471 static ip_address_details_t empty_ip_address_details = { {0} };
2472 ip_address_details_t *address = NULL;
2473 ip_details_t *current_ip_details = NULL;
2474 ip_details_t *details = NULL;
2476 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2478 if (!details || vam->current_sw_if_index >= vec_len (details)
2479 || !details[vam->current_sw_if_index].present)
2481 errmsg ("ip address details arrived but not stored");
2482 errmsg ("ip_dump should be called first");
2486 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2488 #define addresses (current_ip_details->addr)
2490 vec_validate_init_empty (addresses, vec_len (addresses),
2491 empty_ip_address_details);
2493 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2495 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2496 address->prefix_length = mp->prefix.len;
2500 static void vl_api_ip_address_details_t_handler_json
2501 (vl_api_ip_address_details_t * mp)
2503 vat_main_t *vam = &vat_main;
2504 vat_json_node_t *node = NULL;
2506 if (VAT_JSON_ARRAY != vam->json_tree.type)
2508 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2509 vat_json_init_array (&vam->json_tree);
2511 node = vat_json_array_add (&vam->json_tree);
2513 vat_json_init_object (node);
2514 vat_json_object_add_prefix (node, &mp->prefix);
2518 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2520 vat_main_t *vam = &vat_main;
2521 static ip_details_t empty_ip_details = { 0 };
2522 ip_details_t *ip = NULL;
2523 u32 sw_if_index = ~0;
2525 sw_if_index = ntohl (mp->sw_if_index);
2527 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2528 sw_if_index, empty_ip_details);
2530 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2537 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2539 vat_main_t *vam = &vat_main;
2541 if (VAT_JSON_ARRAY != vam->json_tree.type)
2543 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2544 vat_json_init_array (&vam->json_tree);
2546 vat_json_array_add_uint (&vam->json_tree,
2547 clib_net_to_host_u32 (mp->sw_if_index));
2550 static void vl_api_get_first_msg_id_reply_t_handler
2551 (vl_api_get_first_msg_id_reply_t * mp)
2553 vat_main_t *vam = &vat_main;
2554 i32 retval = ntohl (mp->retval);
2556 if (vam->async_mode)
2558 vam->async_errors += (retval < 0);
2562 vam->retval = retval;
2563 vam->result_ready = 1;
2567 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2571 static void vl_api_get_first_msg_id_reply_t_handler_json
2572 (vl_api_get_first_msg_id_reply_t * mp)
2574 vat_main_t *vam = &vat_main;
2575 vat_json_node_t node;
2577 vat_json_init_object (&node);
2578 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2579 vat_json_object_add_uint (&node, "first_msg_id",
2580 (uint) ntohs (mp->first_msg_id));
2582 vat_json_print (vam->ofp, &node);
2583 vat_json_free (&node);
2585 vam->retval = ntohl (mp->retval);
2586 vam->result_ready = 1;
2589 static void vl_api_get_node_graph_reply_t_handler
2590 (vl_api_get_node_graph_reply_t * mp)
2592 vat_main_t *vam = &vat_main;
2593 i32 retval = ntohl (mp->retval);
2594 u8 *pvt_copy, *reply;
2599 if (vam->async_mode)
2601 vam->async_errors += (retval < 0);
2605 vam->retval = retval;
2606 vam->result_ready = 1;
2609 /* "Should never happen..." */
2613 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2614 pvt_copy = vec_dup (reply);
2616 /* Toss the shared-memory original... */
2617 oldheap = vl_msg_push_heap ();
2621 vl_msg_pop_heap (oldheap);
2623 if (vam->graph_nodes)
2625 hash_free (vam->graph_node_index_by_name);
2627 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2629 node = vam->graph_nodes[0][i];
2630 vec_free (node->name);
2631 vec_free (node->next_nodes);
2634 vec_free (vam->graph_nodes[0]);
2635 vec_free (vam->graph_nodes);
2638 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2639 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2640 vec_free (pvt_copy);
2642 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2644 node = vam->graph_nodes[0][i];
2645 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2649 static void vl_api_get_node_graph_reply_t_handler_json
2650 (vl_api_get_node_graph_reply_t * mp)
2652 vat_main_t *vam = &vat_main;
2654 vat_json_node_t node;
2657 /* $$$$ make this real? */
2658 vat_json_init_object (&node);
2659 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2660 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2662 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2664 /* Toss the shared-memory original... */
2665 oldheap = vl_msg_push_heap ();
2669 vl_msg_pop_heap (oldheap);
2671 vat_json_print (vam->ofp, &node);
2672 vat_json_free (&node);
2674 vam->retval = ntohl (mp->retval);
2675 vam->result_ready = 1;
2679 format_policer_type (u8 * s, va_list * va)
2681 u32 i = va_arg (*va, u32);
2683 if (i == QOS_POLICER_TYPE_1R2C)
2684 s = format (s, "1r2c");
2685 else if (i == QOS_POLICER_TYPE_1R3C_RFC_2697)
2686 s = format (s, "1r3c");
2687 else if (i == QOS_POLICER_TYPE_2R3C_RFC_2698)
2688 s = format (s, "2r3c-2698");
2689 else if (i == QOS_POLICER_TYPE_2R3C_RFC_4115)
2690 s = format (s, "2r3c-4115");
2691 else if (i == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2692 s = format (s, "2r3c-mef5cf1");
2694 s = format (s, "ILLEGAL");
2699 format_policer_rate_type (u8 * s, va_list * va)
2701 u32 i = va_arg (*va, u32);
2703 if (i == QOS_RATE_KBPS)
2704 s = format (s, "kbps");
2705 else if (i == QOS_RATE_PPS)
2706 s = format (s, "pps");
2708 s = format (s, "ILLEGAL");
2713 format_policer_round_type (u8 * s, va_list * va)
2715 u32 i = va_arg (*va, u32);
2717 if (i == QOS_ROUND_TO_CLOSEST)
2718 s = format (s, "closest");
2719 else if (i == QOS_ROUND_TO_UP)
2720 s = format (s, "up");
2721 else if (i == QOS_ROUND_TO_DOWN)
2722 s = format (s, "down");
2724 s = format (s, "ILLEGAL");
2729 format_policer_action_type (u8 * s, va_list * va)
2731 u32 i = va_arg (*va, u32);
2733 if (i == QOS_ACTION_DROP)
2734 s = format (s, "drop");
2735 else if (i == QOS_ACTION_TRANSMIT)
2736 s = format (s, "transmit");
2737 else if (i == QOS_ACTION_MARK_AND_TRANSMIT)
2738 s = format (s, "mark-and-transmit");
2740 s = format (s, "ILLEGAL");
2745 format_dscp (u8 * s, va_list * va)
2747 u32 i = va_arg (*va, u32);
2754 return (format (s, "%s", #f));
2758 s = format (s, "%s", t);
2759 return (format (s, "ILLEGAL"));
2763 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2765 vat_main_t *vam = &vat_main;
2766 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2768 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2769 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2771 conform_dscp_str = format (0, "");
2773 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2774 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2776 exceed_dscp_str = format (0, "");
2778 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2779 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2781 violate_dscp_str = format (0, "");
2783 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2784 "rate type %U, round type %U, %s rate, %s color-aware, "
2785 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2786 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2787 "conform action %U%s, exceed action %U%s, violate action %U%s",
2789 format_policer_type, mp->type,
2792 clib_net_to_host_u64 (mp->cb),
2793 clib_net_to_host_u64 (mp->eb),
2794 format_policer_rate_type, mp->rate_type,
2795 format_policer_round_type, mp->round_type,
2796 mp->single_rate ? "single" : "dual",
2797 mp->color_aware ? "is" : "not",
2798 ntohl (mp->cir_tokens_per_period),
2799 ntohl (mp->pir_tokens_per_period),
2801 ntohl (mp->current_limit),
2802 ntohl (mp->current_bucket),
2803 ntohl (mp->extended_limit),
2804 ntohl (mp->extended_bucket),
2805 clib_net_to_host_u64 (mp->last_update_time),
2806 format_policer_action_type, mp->conform_action.type,
2808 format_policer_action_type, mp->exceed_action.type,
2810 format_policer_action_type, mp->violate_action.type,
2813 vec_free (conform_dscp_str);
2814 vec_free (exceed_dscp_str);
2815 vec_free (violate_dscp_str);
2818 static void vl_api_policer_details_t_handler_json
2819 (vl_api_policer_details_t * mp)
2821 vat_main_t *vam = &vat_main;
2822 vat_json_node_t *node;
2823 u8 *rate_type_str, *round_type_str, *type_str;
2824 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2826 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2828 format (0, "%U", format_policer_round_type, mp->round_type);
2829 type_str = format (0, "%U", format_policer_type, mp->type);
2830 conform_action_str = format (0, "%U", format_policer_action_type,
2831 mp->conform_action.type);
2832 exceed_action_str = format (0, "%U", format_policer_action_type,
2833 mp->exceed_action.type);
2834 violate_action_str = format (0, "%U", format_policer_action_type,
2835 mp->violate_action.type);
2837 if (VAT_JSON_ARRAY != vam->json_tree.type)
2839 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2840 vat_json_init_array (&vam->json_tree);
2842 node = vat_json_array_add (&vam->json_tree);
2844 vat_json_init_object (node);
2845 vat_json_object_add_string_copy (node, "name", mp->name);
2846 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2847 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2848 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2849 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2850 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2851 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2852 vat_json_object_add_string_copy (node, "type", type_str);
2853 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2854 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2855 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2856 vat_json_object_add_uint (node, "cir_tokens_per_period",
2857 ntohl (mp->cir_tokens_per_period));
2858 vat_json_object_add_uint (node, "eir_tokens_per_period",
2859 ntohl (mp->pir_tokens_per_period));
2860 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2861 vat_json_object_add_uint (node, "current_bucket",
2862 ntohl (mp->current_bucket));
2863 vat_json_object_add_uint (node, "extended_limit",
2864 ntohl (mp->extended_limit));
2865 vat_json_object_add_uint (node, "extended_bucket",
2866 ntohl (mp->extended_bucket));
2867 vat_json_object_add_uint (node, "last_update_time",
2868 ntohl (mp->last_update_time));
2869 vat_json_object_add_string_copy (node, "conform_action",
2870 conform_action_str);
2871 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2873 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2874 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2875 vec_free (dscp_str);
2877 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2878 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2880 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2881 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2882 vec_free (dscp_str);
2884 vat_json_object_add_string_copy (node, "violate_action",
2885 violate_action_str);
2886 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2888 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2889 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2890 vec_free (dscp_str);
2893 vec_free (rate_type_str);
2894 vec_free (round_type_str);
2895 vec_free (type_str);
2896 vec_free (conform_action_str);
2897 vec_free (exceed_action_str);
2898 vec_free (violate_action_str);
2902 vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
2905 vat_main_t *vam = &vat_main;
2906 int i, count = ntohl (mp->count);
2909 print (vam->ofp, "classify table ids (%d) : ", count);
2910 for (i = 0; i < count; i++)
2912 print (vam->ofp, "%d", ntohl (mp->ids[i]));
2913 print (vam->ofp, (i < count - 1) ? "," : "");
2915 vam->retval = ntohl (mp->retval);
2916 vam->result_ready = 1;
2920 vl_api_classify_table_ids_reply_t_handler_json
2921 (vl_api_classify_table_ids_reply_t * mp)
2923 vat_main_t *vam = &vat_main;
2924 int i, count = ntohl (mp->count);
2928 vat_json_node_t node;
2930 vat_json_init_object (&node);
2931 for (i = 0; i < count; i++)
2933 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
2935 vat_json_print (vam->ofp, &node);
2936 vat_json_free (&node);
2938 vam->retval = ntohl (mp->retval);
2939 vam->result_ready = 1;
2943 vl_api_classify_table_by_interface_reply_t_handler
2944 (vl_api_classify_table_by_interface_reply_t * mp)
2946 vat_main_t *vam = &vat_main;
2949 table_id = ntohl (mp->l2_table_id);
2951 print (vam->ofp, "l2 table id : %d", table_id);
2953 print (vam->ofp, "l2 table id : No input ACL tables configured");
2954 table_id = ntohl (mp->ip4_table_id);
2956 print (vam->ofp, "ip4 table id : %d", table_id);
2958 print (vam->ofp, "ip4 table id : No input ACL tables configured");
2959 table_id = ntohl (mp->ip6_table_id);
2961 print (vam->ofp, "ip6 table id : %d", table_id);
2963 print (vam->ofp, "ip6 table id : No input ACL tables configured");
2964 vam->retval = ntohl (mp->retval);
2965 vam->result_ready = 1;
2969 vl_api_classify_table_by_interface_reply_t_handler_json
2970 (vl_api_classify_table_by_interface_reply_t * mp)
2972 vat_main_t *vam = &vat_main;
2973 vat_json_node_t node;
2975 vat_json_init_object (&node);
2977 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
2978 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
2979 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
2981 vat_json_print (vam->ofp, &node);
2982 vat_json_free (&node);
2984 vam->retval = ntohl (mp->retval);
2985 vam->result_ready = 1;
2988 static void vl_api_policer_add_del_reply_t_handler
2989 (vl_api_policer_add_del_reply_t * mp)
2991 vat_main_t *vam = &vat_main;
2992 i32 retval = ntohl (mp->retval);
2993 if (vam->async_mode)
2995 vam->async_errors += (retval < 0);
2999 vam->retval = retval;
3000 vam->result_ready = 1;
3001 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3003 * Note: this is just barely thread-safe, depends on
3004 * the main thread spinning waiting for an answer...
3006 errmsg ("policer index %d", ntohl (mp->policer_index));
3010 static void vl_api_policer_add_del_reply_t_handler_json
3011 (vl_api_policer_add_del_reply_t * mp)
3013 vat_main_t *vam = &vat_main;
3014 vat_json_node_t node;
3016 vat_json_init_object (&node);
3017 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3018 vat_json_object_add_uint (&node, "policer_index",
3019 ntohl (mp->policer_index));
3021 vat_json_print (vam->ofp, &node);
3022 vat_json_free (&node);
3024 vam->retval = ntohl (mp->retval);
3025 vam->result_ready = 1;
3028 /* Format hex dump. */
3030 format_hex_bytes (u8 * s, va_list * va)
3032 u8 *bytes = va_arg (*va, u8 *);
3033 int n_bytes = va_arg (*va, int);
3036 /* Print short or long form depending on byte count. */
3037 uword short_form = n_bytes <= 32;
3038 u32 indent = format_get_indent (s);
3043 for (i = 0; i < n_bytes; i++)
3045 if (!short_form && (i % 32) == 0)
3046 s = format (s, "%08x: ", i);
3047 s = format (s, "%02x", bytes[i]);
3048 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3049 s = format (s, "\n%U", format_white_space, indent);
3056 vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3059 vat_main_t *vam = &vat_main;
3060 i32 retval = ntohl (mp->retval);
3063 print (vam->ofp, "classify table info :");
3064 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
3065 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3066 ntohl (mp->miss_next_index));
3067 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
3068 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3069 ntohl (mp->match_n_vectors));
3070 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
3071 ntohl (mp->mask_length));
3073 vam->retval = retval;
3074 vam->result_ready = 1;
3078 vl_api_classify_table_info_reply_t_handler_json
3079 (vl_api_classify_table_info_reply_t * mp)
3081 vat_main_t *vam = &vat_main;
3082 vat_json_node_t node;
3084 i32 retval = ntohl (mp->retval);
3087 vat_json_init_object (&node);
3089 vat_json_object_add_int (&node, "sessions",
3090 ntohl (mp->active_sessions));
3091 vat_json_object_add_int (&node, "nexttbl",
3092 ntohl (mp->next_table_index));
3093 vat_json_object_add_int (&node, "nextnode",
3094 ntohl (mp->miss_next_index));
3095 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3096 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3097 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3098 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3099 ntohl (mp->mask_length), 0);
3100 vat_json_object_add_string_copy (&node, "mask", s);
3102 vat_json_print (vam->ofp, &node);
3103 vat_json_free (&node);
3105 vam->retval = ntohl (mp->retval);
3106 vam->result_ready = 1;
3110 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3113 vat_main_t *vam = &vat_main;
3115 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3116 ntohl (mp->hit_next_index), ntohl (mp->advance),
3117 ntohl (mp->opaque_index));
3118 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
3119 ntohl (mp->match_length));
3123 vl_api_classify_session_details_t_handler_json
3124 (vl_api_classify_session_details_t * mp)
3126 vat_main_t *vam = &vat_main;
3127 vat_json_node_t *node = NULL;
3129 if (VAT_JSON_ARRAY != vam->json_tree.type)
3131 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3132 vat_json_init_array (&vam->json_tree);
3134 node = vat_json_array_add (&vam->json_tree);
3136 vat_json_init_object (node);
3137 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3138 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3139 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3141 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3143 vat_json_object_add_string_copy (node, "match", s);
3146 static void vl_api_pg_create_interface_reply_t_handler
3147 (vl_api_pg_create_interface_reply_t * mp)
3149 vat_main_t *vam = &vat_main;
3151 vam->retval = ntohl (mp->retval);
3152 vam->result_ready = 1;
3155 static void vl_api_pg_create_interface_reply_t_handler_json
3156 (vl_api_pg_create_interface_reply_t * mp)
3158 vat_main_t *vam = &vat_main;
3159 vat_json_node_t node;
3161 i32 retval = ntohl (mp->retval);
3164 vat_json_init_object (&node);
3166 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
3168 vat_json_print (vam->ofp, &node);
3169 vat_json_free (&node);
3171 vam->retval = ntohl (mp->retval);
3172 vam->result_ready = 1;
3175 static void vl_api_policer_classify_details_t_handler
3176 (vl_api_policer_classify_details_t * mp)
3178 vat_main_t *vam = &vat_main;
3180 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3181 ntohl (mp->table_index));
3184 static void vl_api_policer_classify_details_t_handler_json
3185 (vl_api_policer_classify_details_t * mp)
3187 vat_main_t *vam = &vat_main;
3188 vat_json_node_t *node;
3190 if (VAT_JSON_ARRAY != vam->json_tree.type)
3192 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3193 vat_json_init_array (&vam->json_tree);
3195 node = vat_json_array_add (&vam->json_tree);
3197 vat_json_init_object (node);
3198 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3199 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3202 static void vl_api_flow_classify_details_t_handler
3203 (vl_api_flow_classify_details_t * mp)
3205 vat_main_t *vam = &vat_main;
3207 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3208 ntohl (mp->table_index));
3211 static void vl_api_flow_classify_details_t_handler_json
3212 (vl_api_flow_classify_details_t * mp)
3214 vat_main_t *vam = &vat_main;
3215 vat_json_node_t *node;
3217 if (VAT_JSON_ARRAY != vam->json_tree.type)
3219 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3220 vat_json_init_array (&vam->json_tree);
3222 node = vat_json_array_add (&vam->json_tree);
3224 vat_json_init_object (node);
3225 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3226 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3230 * Generate boilerplate reply handlers, which
3231 * dig the return value out of the xxx_reply_t API message,
3232 * stick it into vam->retval, and set vam->result_ready
3234 * Could also do this by pointing N message decode slots at
3235 * a single function, but that could break in subtle ways.
3238 #define foreach_standard_reply_retval_handler \
3239 _(sw_interface_set_flags_reply) \
3240 _(sw_interface_add_del_address_reply) \
3241 _(sw_interface_set_rx_mode_reply) \
3242 _(sw_interface_set_rx_placement_reply) \
3243 _(sw_interface_set_table_reply) \
3244 _(sw_interface_set_mpls_enable_reply) \
3245 _(sw_interface_set_vpath_reply) \
3246 _(sw_interface_set_vxlan_bypass_reply) \
3247 _(sw_interface_set_vxlan_gpe_bypass_reply) \
3248 _(sw_interface_set_l2_bridge_reply) \
3249 _(sw_interface_set_bond_weight_reply) \
3250 _(bridge_domain_add_del_reply) \
3251 _(sw_interface_set_l2_xconnect_reply) \
3252 _(l2fib_add_del_reply) \
3253 _(l2fib_flush_int_reply) \
3254 _(l2fib_flush_bd_reply) \
3255 _(ip_route_add_del_reply) \
3256 _(ip_table_add_del_reply) \
3257 _(ip_table_replace_begin_reply) \
3258 _(ip_table_flush_reply) \
3259 _(ip_table_replace_end_reply) \
3260 _(ip_mroute_add_del_reply) \
3261 _(mpls_route_add_del_reply) \
3262 _(mpls_table_add_del_reply) \
3263 _(mpls_ip_bind_unbind_reply) \
3264 _(bier_route_add_del_reply) \
3265 _(bier_table_add_del_reply) \
3266 _(sw_interface_set_unnumbered_reply) \
3267 _(set_ip_flow_hash_reply) \
3268 _(sw_interface_ip6_enable_disable_reply) \
3269 _(l2_patch_add_del_reply) \
3270 _(sr_mpls_policy_add_reply) \
3271 _(sr_mpls_policy_mod_reply) \
3272 _(sr_mpls_policy_del_reply) \
3273 _(sr_policy_add_reply) \
3274 _(sr_policy_mod_reply) \
3275 _(sr_policy_del_reply) \
3276 _(sr_localsid_add_del_reply) \
3277 _(sr_steering_add_del_reply) \
3278 _(classify_add_del_session_reply) \
3279 _(classify_set_interface_ip_table_reply) \
3280 _(classify_set_interface_l2_tables_reply) \
3281 _(l2_fib_clear_table_reply) \
3282 _(l2_interface_efp_filter_reply) \
3283 _(l2_interface_vlan_tag_rewrite_reply) \
3284 _(modify_vhost_user_if_reply) \
3285 _(modify_vhost_user_if_v2_reply) \
3286 _(delete_vhost_user_if_reply) \
3287 _(want_l2_macs_events_reply) \
3288 _(input_acl_set_interface_reply) \
3289 _(ipsec_spd_add_del_reply) \
3290 _(ipsec_interface_add_del_spd_reply) \
3291 _(ipsec_spd_entry_add_del_reply) \
3292 _(ipsec_sad_entry_add_del_reply) \
3293 _(delete_loopback_reply) \
3294 _(bd_ip_mac_add_del_reply) \
3295 _(bd_ip_mac_flush_reply) \
3296 _(want_interface_events_reply) \
3297 _(sw_interface_clear_stats_reply) \
3298 _(ioam_enable_reply) \
3299 _(ioam_disable_reply) \
3300 _(af_packet_delete_reply) \
3301 _(policer_classify_set_interface_reply) \
3302 _(set_ipfix_exporter_reply) \
3303 _(set_ipfix_classify_stream_reply) \
3304 _(ipfix_classify_table_add_del_reply) \
3305 _(flow_classify_set_interface_reply) \
3306 _(sw_interface_span_enable_disable_reply) \
3307 _(pg_capture_reply) \
3308 _(pg_enable_disable_reply) \
3309 _(pg_interface_enable_disable_coalesce_reply) \
3310 _(ip_source_and_port_range_check_add_del_reply) \
3311 _(ip_source_and_port_range_check_interface_add_del_reply)\
3312 _(delete_subif_reply) \
3313 _(l2_interface_pbb_tag_rewrite_reply) \
3315 _(feature_enable_disable_reply) \
3316 _(feature_gso_enable_disable_reply) \
3317 _(sw_interface_tag_add_del_reply) \
3318 _(sw_interface_add_del_mac_address_reply) \
3319 _(hw_interface_set_mtu_reply) \
3320 _(p2p_ethernet_add_reply) \
3321 _(p2p_ethernet_del_reply) \
3322 _(tcp_configure_src_addresses_reply) \
3323 _(session_rule_add_del_reply) \
3324 _(ip_container_proxy_add_del_reply) \
3325 _(output_acl_set_interface_reply) \
3326 _(qos_record_enable_disable_reply) \
3330 static void vl_api_##n##_t_handler \
3331 (vl_api_##n##_t * mp) \
3333 vat_main_t * vam = &vat_main; \
3334 i32 retval = ntohl(mp->retval); \
3335 if (vam->async_mode) { \
3336 vam->async_errors += (retval < 0); \
3338 vam->retval = retval; \
3339 vam->result_ready = 1; \
3342 foreach_standard_reply_retval_handler;
3346 static void vl_api_##n##_t_handler_json \
3347 (vl_api_##n##_t * mp) \
3349 vat_main_t * vam = &vat_main; \
3350 vat_json_node_t node; \
3351 vat_json_init_object(&node); \
3352 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3353 vat_json_print(vam->ofp, &node); \
3354 vam->retval = ntohl(mp->retval); \
3355 vam->result_ready = 1; \
3357 foreach_standard_reply_retval_handler;
3361 * Table of message reply handlers, must include boilerplate handlers
3365 #define foreach_vpe_api_reply_msg \
3366 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3367 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3368 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3369 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3370 _(CONTROL_PING_REPLY, control_ping_reply) \
3371 _(CLI_REPLY, cli_reply) \
3372 _(CLI_INBAND_REPLY, cli_inband_reply) \
3373 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3374 sw_interface_add_del_address_reply) \
3375 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3376 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3377 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3378 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3379 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3380 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3381 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3382 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3383 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3384 sw_interface_set_l2_xconnect_reply) \
3385 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3386 sw_interface_set_l2_bridge_reply) \
3387 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3388 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3389 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3390 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3391 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3392 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3393 _(L2_FLAGS_REPLY, l2_flags_reply) \
3394 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3395 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3396 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3397 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3398 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3399 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3400 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3401 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3402 _(BOND_CREATE_REPLY, bond_create_reply) \
3403 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3404 _(BOND_DELETE_REPLY, bond_delete_reply) \
3405 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3406 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3407 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3408 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3409 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3410 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3411 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3412 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3413 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3414 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3415 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3416 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3417 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3418 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3419 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3420 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3421 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3422 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3423 sw_interface_set_unnumbered_reply) \
3424 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3425 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3426 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3427 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3428 sw_interface_ip6_enable_disable_reply) \
3429 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3430 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3431 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3432 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3433 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3434 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3435 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3436 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3437 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3438 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3439 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3440 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3441 classify_set_interface_ip_table_reply) \
3442 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3443 classify_set_interface_l2_tables_reply) \
3444 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3445 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3446 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3447 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3448 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3449 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3450 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3451 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3452 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3453 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3454 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3455 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
3456 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
3457 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3458 _(SHOW_VERSION_REPLY, show_version_reply) \
3459 _(SHOW_THREADS_REPLY, show_threads_reply) \
3460 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3461 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3462 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3463 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3464 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3465 _(L2_MACS_EVENT, l2_macs_event) \
3466 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3467 _(IP_ADDRESS_DETAILS, ip_address_details) \
3468 _(IP_DETAILS, ip_details) \
3469 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3470 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3471 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3472 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3473 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3474 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3475 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3476 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3477 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3478 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3479 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3480 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3481 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3482 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3483 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3484 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3485 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3486 _(AF_PACKET_DETAILS, af_packet_details) \
3487 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3488 _(POLICER_DETAILS, policer_details) \
3489 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3490 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3491 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3492 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3493 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3494 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3495 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3496 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3497 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3498 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3499 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3500 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3501 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3502 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3503 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3504 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3505 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3506 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3507 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3508 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3509 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3510 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3511 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3512 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3513 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3514 ip_source_and_port_range_check_add_del_reply) \
3515 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3516 ip_source_and_port_range_check_interface_add_del_reply) \
3517 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3518 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3519 _(SET_PUNT_REPLY, set_punt_reply) \
3520 _(IP_TABLE_DETAILS, ip_table_details) \
3521 _(IP_ROUTE_DETAILS, ip_route_details) \
3522 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3523 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3524 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3525 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3526 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3527 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3528 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3529 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3530 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3531 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3532 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3533 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3534 _(SESSION_RULES_DETAILS, session_rules_details) \
3535 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3536 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3537 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3538 _(FLOW_ADD_REPLY, flow_add_reply) \
3540 #define foreach_standalone_reply_msg \
3541 _(SW_INTERFACE_EVENT, sw_interface_event)
3549 #define STR_VTR_OP_CASE(op) \
3550 case L2_VTR_ ## op: \
3554 str_vtr_op (u32 vtr_op)
3558 STR_VTR_OP_CASE (DISABLED);
3559 STR_VTR_OP_CASE (PUSH_1);
3560 STR_VTR_OP_CASE (PUSH_2);
3561 STR_VTR_OP_CASE (POP_1);
3562 STR_VTR_OP_CASE (POP_2);
3563 STR_VTR_OP_CASE (TRANSLATE_1_1);
3564 STR_VTR_OP_CASE (TRANSLATE_1_2);
3565 STR_VTR_OP_CASE (TRANSLATE_2_1);
3566 STR_VTR_OP_CASE (TRANSLATE_2_2);
3573 dump_sub_interface_table (vat_main_t * vam)
3575 const sw_interface_subif_t *sub = NULL;
3577 if (vam->json_output)
3580 ("JSON output supported only for VPE API calls and dump_stats_table");
3585 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3586 "Interface", "sw_if_index",
3587 "sub id", "dot1ad", "tags", "outer id",
3588 "inner id", "exact", "default", "outer any", "inner any");
3590 vec_foreach (sub, vam->sw_if_subif_table)
3593 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3594 sub->interface_name,
3596 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3597 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3598 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3599 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3600 if (sub->vtr_op != L2_VTR_DISABLED)
3603 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3604 "tag1: %d tag2: %d ]",
3605 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3606 sub->vtr_tag1, sub->vtr_tag2);
3614 name_sort_cmp (void *a1, void *a2)
3616 name_sort_t *n1 = a1;
3617 name_sort_t *n2 = a2;
3619 return strcmp ((char *) n1->name, (char *) n2->name);
3623 dump_interface_table (vat_main_t * vam)
3626 name_sort_t *nses = 0, *ns;
3628 if (vam->json_output)
3631 ("JSON output supported only for VPE API calls and dump_stats_table");
3636 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3638 vec_add2 (nses, ns, 1);
3639 ns->name = (u8 *)(p->key);
3640 ns->value = (u32) p->value[0];
3644 vec_sort_with_function (nses, name_sort_cmp);
3646 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3647 vec_foreach (ns, nses)
3649 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3656 dump_ip_table (vat_main_t * vam, int is_ipv6)
3658 const ip_details_t *det = NULL;
3659 const ip_address_details_t *address = NULL;
3662 print (vam->ofp, "%-12s", "sw_if_index");
3664 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3671 print (vam->ofp, "%-12d", i);
3672 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3677 vec_foreach (address, det->addr)
3681 is_ipv6 ? format_ip6_address : format_ip4_address,
3682 address->ip, address->prefix_length);
3690 dump_ipv4_table (vat_main_t * vam)
3692 if (vam->json_output)
3695 ("JSON output supported only for VPE API calls and dump_stats_table");
3699 return dump_ip_table (vam, 0);
3703 dump_ipv6_table (vat_main_t * vam)
3705 if (vam->json_output)
3708 ("JSON output supported only for VPE API calls and dump_stats_table");
3712 return dump_ip_table (vam, 1);
3716 * Pass CLI buffers directly in the CLI_INBAND API message,
3717 * instead of an additional shared memory area.
3720 exec_inband (vat_main_t * vam)
3722 vl_api_cli_inband_t *mp;
3723 unformat_input_t *i = vam->input;
3726 if (vec_len (i->buffer) == 0)
3729 if (vam->exec_mode == 0 && unformat (i, "mode"))
3734 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3741 * In order for the CLI command to work, it
3742 * must be a vector ending in \n, not a C-string ending
3745 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3746 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3750 /* json responses may or may not include a useful reply... */
3751 if (vec_len (vam->cmd_reply))
3752 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3757 exec (vat_main_t * vam)
3759 return exec_inband (vam);
3763 api_create_loopback (vat_main_t * vam)
3765 unformat_input_t *i = vam->input;
3766 vl_api_create_loopback_t *mp;
3767 vl_api_create_loopback_instance_t *mp_lbi;
3770 u8 is_specified = 0;
3771 u32 user_instance = 0;
3774 clib_memset (mac_address, 0, sizeof (mac_address));
3776 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3778 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3780 if (unformat (i, "instance %d", &user_instance))
3788 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3789 mp_lbi->is_specified = is_specified;
3791 mp_lbi->user_instance = htonl (user_instance);
3793 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3798 /* Construct the API message */
3799 M (CREATE_LOOPBACK, mp);
3801 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3810 api_delete_loopback (vat_main_t * vam)
3812 unformat_input_t *i = vam->input;
3813 vl_api_delete_loopback_t *mp;
3814 u32 sw_if_index = ~0;
3817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3819 if (unformat (i, "sw_if_index %d", &sw_if_index))
3825 if (sw_if_index == ~0)
3827 errmsg ("missing sw_if_index");
3831 /* Construct the API message */
3832 M (DELETE_LOOPBACK, mp);
3833 mp->sw_if_index = ntohl (sw_if_index);
3841 api_want_interface_events (vat_main_t * vam)
3843 unformat_input_t *i = vam->input;
3844 vl_api_want_interface_events_t *mp;
3848 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3850 if (unformat (i, "enable"))
3852 else if (unformat (i, "disable"))
3860 errmsg ("missing enable|disable");
3864 M (WANT_INTERFACE_EVENTS, mp);
3865 mp->enable_disable = enable;
3867 vam->interface_event_display = enable;
3875 /* Note: non-static, called once to set up the initial intfc table */
3877 api_sw_interface_dump (vat_main_t * vam)
3879 vl_api_sw_interface_dump_t *mp;
3880 vl_api_control_ping_t *mp_ping;
3882 name_sort_t *nses = 0, *ns;
3883 sw_interface_subif_t *sub = NULL;
3886 /* Toss the old name table */
3888 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3890 vec_add2 (nses, ns, 1);
3891 ns->name = (u8 *)(p->key);
3892 ns->value = (u32) p->value[0];
3896 hash_free (vam->sw_if_index_by_interface_name);
3898 vec_foreach (ns, nses) vec_free (ns->name);
3902 vec_foreach (sub, vam->sw_if_subif_table)
3904 vec_free (sub->interface_name);
3906 vec_free (vam->sw_if_subif_table);
3908 /* recreate the interface name hash table */
3909 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3912 * Ask for all interface names. Otherwise, the epic catalog of
3913 * name filters becomes ridiculously long, and vat ends up needing
3914 * to be taught about new interface types.
3916 M (SW_INTERFACE_DUMP, mp);
3919 /* Use a control ping for synchronization */
3920 MPING (CONTROL_PING, mp_ping);
3928 api_sw_interface_set_flags (vat_main_t * vam)
3930 unformat_input_t *i = vam->input;
3931 vl_api_sw_interface_set_flags_t *mp;
3933 u8 sw_if_index_set = 0;
3937 /* Parse args required to build the message */
3938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3940 if (unformat (i, "admin-up"))
3942 else if (unformat (i, "admin-down"))
3945 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3946 sw_if_index_set = 1;
3947 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3948 sw_if_index_set = 1;
3953 if (sw_if_index_set == 0)
3955 errmsg ("missing interface name or sw_if_index");
3959 /* Construct the API message */
3960 M (SW_INTERFACE_SET_FLAGS, mp);
3961 mp->sw_if_index = ntohl (sw_if_index);
3962 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3967 /* Wait for a reply, return the good/bad news... */
3973 api_sw_interface_set_rx_mode (vat_main_t * vam)
3975 unformat_input_t *i = vam->input;
3976 vl_api_sw_interface_set_rx_mode_t *mp;
3978 u8 sw_if_index_set = 0;
3980 u8 queue_id_valid = 0;
3982 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3984 /* Parse args required to build the message */
3985 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3987 if (unformat (i, "queue %d", &queue_id))
3989 else if (unformat (i, "polling"))
3990 mode = VNET_HW_IF_RX_MODE_POLLING;
3991 else if (unformat (i, "interrupt"))
3992 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3993 else if (unformat (i, "adaptive"))
3994 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3996 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3997 sw_if_index_set = 1;
3998 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3999 sw_if_index_set = 1;
4004 if (sw_if_index_set == 0)
4006 errmsg ("missing interface name or sw_if_index");
4009 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
4011 errmsg ("missing rx-mode");
4015 /* Construct the API message */
4016 M (SW_INTERFACE_SET_RX_MODE, mp);
4017 mp->sw_if_index = ntohl (sw_if_index);
4018 mp->mode = (vl_api_rx_mode_t) mode;
4019 mp->queue_id_valid = queue_id_valid;
4020 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
4025 /* Wait for a reply, return the good/bad news... */
4031 api_sw_interface_set_rx_placement (vat_main_t * vam)
4033 unformat_input_t *i = vam->input;
4034 vl_api_sw_interface_set_rx_placement_t *mp;
4036 u8 sw_if_index_set = 0;
4039 u32 queue_id, thread_index;
4041 /* Parse args required to build the message */
4042 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4044 if (unformat (i, "queue %d", &queue_id))
4046 else if (unformat (i, "main"))
4048 else if (unformat (i, "worker %d", &thread_index))
4051 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4052 sw_if_index_set = 1;
4053 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4054 sw_if_index_set = 1;
4059 if (sw_if_index_set == 0)
4061 errmsg ("missing interface name or sw_if_index");
4067 /* Construct the API message */
4068 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4069 mp->sw_if_index = ntohl (sw_if_index);
4070 mp->worker_id = ntohl (thread_index);
4071 mp->queue_id = ntohl (queue_id);
4072 mp->is_main = is_main;
4076 /* Wait for a reply, return the good/bad news... */
4081 static void vl_api_sw_interface_rx_placement_details_t_handler
4082 (vl_api_sw_interface_rx_placement_details_t * mp)
4084 vat_main_t *vam = &vat_main;
4085 u32 worker_id = ntohl (mp->worker_id);
4088 "\n%-11d %-11s %-6d %-5d %-9s",
4089 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4090 worker_id, ntohl (mp->queue_id),
4092 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4095 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4096 (vl_api_sw_interface_rx_placement_details_t * mp)
4098 vat_main_t *vam = &vat_main;
4099 vat_json_node_t *node = NULL;
4101 if (VAT_JSON_ARRAY != vam->json_tree.type)
4103 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4104 vat_json_init_array (&vam->json_tree);
4106 node = vat_json_array_add (&vam->json_tree);
4108 vat_json_init_object (node);
4109 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4110 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4111 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4112 vat_json_object_add_uint (node, "mode", mp->mode);
4116 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4118 unformat_input_t *i = vam->input;
4119 vl_api_sw_interface_rx_placement_dump_t *mp;
4120 vl_api_control_ping_t *mp_ping;
4123 u8 sw_if_index_set = 0;
4125 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4127 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4129 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4136 "\n%-11s %-11s %-6s %-5s %-4s",
4137 "sw_if_index", "main/worker", "thread", "queue", "mode");
4139 /* Dump Interface rx placement */
4140 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4142 if (sw_if_index_set)
4143 mp->sw_if_index = htonl (sw_if_index);
4145 mp->sw_if_index = ~0;
4149 /* Use a control ping for synchronization */
4150 MPING (CONTROL_PING, mp_ping);
4158 api_sw_interface_clear_stats (vat_main_t * vam)
4160 unformat_input_t *i = vam->input;
4161 vl_api_sw_interface_clear_stats_t *mp;
4163 u8 sw_if_index_set = 0;
4166 /* Parse args required to build the message */
4167 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4169 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4170 sw_if_index_set = 1;
4171 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4172 sw_if_index_set = 1;
4177 /* Construct the API message */
4178 M (SW_INTERFACE_CLEAR_STATS, mp);
4180 if (sw_if_index_set == 1)
4181 mp->sw_if_index = ntohl (sw_if_index);
4183 mp->sw_if_index = ~0;
4188 /* Wait for a reply, return the good/bad news... */
4194 api_sw_interface_add_del_address (vat_main_t * vam)
4196 unformat_input_t *i = vam->input;
4197 vl_api_sw_interface_add_del_address_t *mp;
4199 u8 sw_if_index_set = 0;
4200 u8 is_add = 1, del_all = 0;
4201 u32 address_length = 0;
4202 u8 v4_address_set = 0;
4203 u8 v6_address_set = 0;
4204 ip4_address_t v4address;
4205 ip6_address_t v6address;
4208 /* Parse args required to build the message */
4209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4211 if (unformat (i, "del-all"))
4213 else if (unformat (i, "del"))
4216 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4217 sw_if_index_set = 1;
4218 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4219 sw_if_index_set = 1;
4220 else if (unformat (i, "%U/%d",
4221 unformat_ip4_address, &v4address, &address_length))
4223 else if (unformat (i, "%U/%d",
4224 unformat_ip6_address, &v6address, &address_length))
4230 if (sw_if_index_set == 0)
4232 errmsg ("missing interface name or sw_if_index");
4235 if (v4_address_set && v6_address_set)
4237 errmsg ("both v4 and v6 addresses set");
4240 if (!v4_address_set && !v6_address_set && !del_all)
4242 errmsg ("no addresses set");
4246 /* Construct the API message */
4247 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4249 mp->sw_if_index = ntohl (sw_if_index);
4250 mp->is_add = is_add;
4251 mp->del_all = del_all;
4254 mp->prefix.address.af = ADDRESS_IP6;
4255 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4259 mp->prefix.address.af = ADDRESS_IP4;
4260 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4262 mp->prefix.len = address_length;
4267 /* Wait for a reply, return good/bad news */
4273 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4275 unformat_input_t *i = vam->input;
4276 vl_api_sw_interface_set_mpls_enable_t *mp;
4278 u8 sw_if_index_set = 0;
4282 /* Parse args required to build the message */
4283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4285 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4286 sw_if_index_set = 1;
4287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4288 sw_if_index_set = 1;
4289 else if (unformat (i, "disable"))
4291 else if (unformat (i, "dis"))
4297 if (sw_if_index_set == 0)
4299 errmsg ("missing interface name or sw_if_index");
4303 /* Construct the API message */
4304 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4306 mp->sw_if_index = ntohl (sw_if_index);
4307 mp->enable = enable;
4312 /* Wait for a reply... */
4318 api_sw_interface_set_table (vat_main_t * vam)
4320 unformat_input_t *i = vam->input;
4321 vl_api_sw_interface_set_table_t *mp;
4322 u32 sw_if_index, vrf_id = 0;
4323 u8 sw_if_index_set = 0;
4327 /* Parse args required to build the message */
4328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4330 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4331 sw_if_index_set = 1;
4332 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4333 sw_if_index_set = 1;
4334 else if (unformat (i, "vrf %d", &vrf_id))
4336 else if (unformat (i, "ipv6"))
4342 if (sw_if_index_set == 0)
4344 errmsg ("missing interface name or sw_if_index");
4348 /* Construct the API message */
4349 M (SW_INTERFACE_SET_TABLE, mp);
4351 mp->sw_if_index = ntohl (sw_if_index);
4352 mp->is_ipv6 = is_ipv6;
4353 mp->vrf_id = ntohl (vrf_id);
4358 /* Wait for a reply... */
4363 static void vl_api_sw_interface_get_table_reply_t_handler
4364 (vl_api_sw_interface_get_table_reply_t * mp)
4366 vat_main_t *vam = &vat_main;
4368 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4370 vam->retval = ntohl (mp->retval);
4371 vam->result_ready = 1;
4375 static void vl_api_sw_interface_get_table_reply_t_handler_json
4376 (vl_api_sw_interface_get_table_reply_t * mp)
4378 vat_main_t *vam = &vat_main;
4379 vat_json_node_t node;
4381 vat_json_init_object (&node);
4382 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4383 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4385 vat_json_print (vam->ofp, &node);
4386 vat_json_free (&node);
4388 vam->retval = ntohl (mp->retval);
4389 vam->result_ready = 1;
4393 api_sw_interface_get_table (vat_main_t * vam)
4395 unformat_input_t *i = vam->input;
4396 vl_api_sw_interface_get_table_t *mp;
4398 u8 sw_if_index_set = 0;
4402 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4404 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4405 sw_if_index_set = 1;
4406 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4407 sw_if_index_set = 1;
4408 else if (unformat (i, "ipv6"))
4414 if (sw_if_index_set == 0)
4416 errmsg ("missing interface name or sw_if_index");
4420 M (SW_INTERFACE_GET_TABLE, mp);
4421 mp->sw_if_index = htonl (sw_if_index);
4422 mp->is_ipv6 = is_ipv6;
4430 api_sw_interface_set_vpath (vat_main_t * vam)
4432 unformat_input_t *i = vam->input;
4433 vl_api_sw_interface_set_vpath_t *mp;
4434 u32 sw_if_index = 0;
4435 u8 sw_if_index_set = 0;
4439 /* Parse args required to build the message */
4440 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4442 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4443 sw_if_index_set = 1;
4444 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4445 sw_if_index_set = 1;
4446 else if (unformat (i, "enable"))
4448 else if (unformat (i, "disable"))
4454 if (sw_if_index_set == 0)
4456 errmsg ("missing interface name or sw_if_index");
4460 /* Construct the API message */
4461 M (SW_INTERFACE_SET_VPATH, mp);
4463 mp->sw_if_index = ntohl (sw_if_index);
4464 mp->enable = is_enable;
4469 /* Wait for a reply... */
4475 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4477 unformat_input_t *i = vam->input;
4478 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4479 u32 sw_if_index = 0;
4480 u8 sw_if_index_set = 0;
4485 /* Parse args required to build the message */
4486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4488 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4489 sw_if_index_set = 1;
4490 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4491 sw_if_index_set = 1;
4492 else if (unformat (i, "enable"))
4494 else if (unformat (i, "disable"))
4496 else if (unformat (i, "ip4"))
4498 else if (unformat (i, "ip6"))
4504 if (sw_if_index_set == 0)
4506 errmsg ("missing interface name or sw_if_index");
4510 /* Construct the API message */
4511 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4513 mp->sw_if_index = ntohl (sw_if_index);
4514 mp->enable = is_enable;
4515 mp->is_ipv6 = is_ipv6;
4520 /* Wait for a reply... */
4526 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4528 unformat_input_t *i = vam->input;
4529 vl_api_sw_interface_set_l2_xconnect_t *mp;
4531 u8 rx_sw_if_index_set = 0;
4533 u8 tx_sw_if_index_set = 0;
4537 /* Parse args required to build the message */
4538 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4540 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4541 rx_sw_if_index_set = 1;
4542 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4543 tx_sw_if_index_set = 1;
4544 else if (unformat (i, "rx"))
4546 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4548 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4550 rx_sw_if_index_set = 1;
4555 else if (unformat (i, "tx"))
4557 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4559 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4561 tx_sw_if_index_set = 1;
4566 else if (unformat (i, "enable"))
4568 else if (unformat (i, "disable"))
4574 if (rx_sw_if_index_set == 0)
4576 errmsg ("missing rx interface name or rx_sw_if_index");
4580 if (enable && (tx_sw_if_index_set == 0))
4582 errmsg ("missing tx interface name or tx_sw_if_index");
4586 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4588 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4589 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4590 mp->enable = enable;
4598 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4600 unformat_input_t *i = vam->input;
4601 vl_api_sw_interface_set_l2_bridge_t *mp;
4602 vl_api_l2_port_type_t port_type;
4604 u8 rx_sw_if_index_set = 0;
4611 port_type = L2_API_PORT_TYPE_NORMAL;
4613 /* Parse args required to build the message */
4614 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4616 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4617 rx_sw_if_index_set = 1;
4618 else if (unformat (i, "bd_id %d", &bd_id))
4622 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4623 rx_sw_if_index_set = 1;
4624 else if (unformat (i, "shg %d", &shg))
4626 else if (unformat (i, "bvi"))
4627 port_type = L2_API_PORT_TYPE_BVI;
4628 else if (unformat (i, "uu-fwd"))
4629 port_type = L2_API_PORT_TYPE_UU_FWD;
4630 else if (unformat (i, "enable"))
4632 else if (unformat (i, "disable"))
4638 if (rx_sw_if_index_set == 0)
4640 errmsg ("missing rx interface name or sw_if_index");
4644 if (enable && (bd_id_set == 0))
4646 errmsg ("missing bridge domain");
4650 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4652 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4653 mp->bd_id = ntohl (bd_id);
4655 mp->port_type = ntohl (port_type);
4656 mp->enable = enable;
4664 api_bridge_domain_dump (vat_main_t * vam)
4666 unformat_input_t *i = vam->input;
4667 vl_api_bridge_domain_dump_t *mp;
4668 vl_api_control_ping_t *mp_ping;
4672 /* Parse args required to build the message */
4673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4675 if (unformat (i, "bd_id %d", &bd_id))
4681 M (BRIDGE_DOMAIN_DUMP, mp);
4682 mp->bd_id = ntohl (bd_id);
4685 /* Use a control ping for synchronization */
4686 MPING (CONTROL_PING, mp_ping);
4694 api_bridge_domain_add_del (vat_main_t * vam)
4696 unformat_input_t *i = vam->input;
4697 vl_api_bridge_domain_add_del_t *mp;
4700 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4705 /* Parse args required to build the message */
4706 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4708 if (unformat (i, "bd_id %d", &bd_id))
4710 else if (unformat (i, "flood %d", &flood))
4712 else if (unformat (i, "uu-flood %d", &uu_flood))
4714 else if (unformat (i, "forward %d", &forward))
4716 else if (unformat (i, "learn %d", &learn))
4718 else if (unformat (i, "arp-term %d", &arp_term))
4720 else if (unformat (i, "mac-age %d", &mac_age))
4722 else if (unformat (i, "bd-tag %s", &bd_tag))
4724 else if (unformat (i, "del"))
4727 flood = uu_flood = forward = learn = 0;
4735 errmsg ("missing bridge domain");
4742 errmsg ("mac age must be less than 256 ");
4747 if ((bd_tag) && (vec_len (bd_tag) > 63))
4749 errmsg ("bd-tag cannot be longer than 63");
4754 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4756 mp->bd_id = ntohl (bd_id);
4758 mp->uu_flood = uu_flood;
4759 mp->forward = forward;
4761 mp->arp_term = arp_term;
4762 mp->is_add = is_add;
4763 mp->mac_age = (u8) mac_age;
4766 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4767 mp->bd_tag[vec_len (bd_tag)] = 0;
4778 api_l2fib_flush_bd (vat_main_t * vam)
4780 unformat_input_t *i = vam->input;
4781 vl_api_l2fib_flush_bd_t *mp;
4785 /* Parse args required to build the message */
4786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4788 if (unformat (i, "bd_id %d", &bd_id));
4795 errmsg ("missing bridge domain");
4799 M (L2FIB_FLUSH_BD, mp);
4801 mp->bd_id = htonl (bd_id);
4809 api_l2fib_flush_int (vat_main_t * vam)
4811 unformat_input_t *i = vam->input;
4812 vl_api_l2fib_flush_int_t *mp;
4813 u32 sw_if_index = ~0;
4816 /* Parse args required to build the message */
4817 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4819 if (unformat (i, "sw_if_index %d", &sw_if_index));
4821 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4826 if (sw_if_index == ~0)
4828 errmsg ("missing interface name or sw_if_index");
4832 M (L2FIB_FLUSH_INT, mp);
4834 mp->sw_if_index = ntohl (sw_if_index);
4842 api_l2fib_add_del (vat_main_t * vam)
4844 unformat_input_t *i = vam->input;
4845 vl_api_l2fib_add_del_t *mp;
4851 u32 sw_if_index = 0;
4852 u8 sw_if_index_set = 0;
4861 /* Parse args required to build the message */
4862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4864 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4866 else if (unformat (i, "bd_id %d", &bd_id))
4868 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4869 sw_if_index_set = 1;
4870 else if (unformat (i, "sw_if"))
4872 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4875 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4876 sw_if_index_set = 1;
4881 else if (unformat (i, "static"))
4883 else if (unformat (i, "filter"))
4888 else if (unformat (i, "bvi"))
4893 else if (unformat (i, "del"))
4895 else if (unformat (i, "count %d", &count))
4903 errmsg ("missing mac address");
4909 errmsg ("missing bridge domain");
4913 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4915 errmsg ("missing interface name or sw_if_index");
4921 /* Turn on async mode */
4922 vam->async_mode = 1;
4923 vam->async_errors = 0;
4924 before = vat_time_now (vam);
4927 for (j = 0; j < count; j++)
4929 M (L2FIB_ADD_DEL, mp);
4931 clib_memcpy (mp->mac, mac, 6);
4932 mp->bd_id = ntohl (bd_id);
4933 mp->is_add = is_add;
4934 mp->sw_if_index = ntohl (sw_if_index);
4938 mp->static_mac = static_mac;
4939 mp->filter_mac = filter_mac;
4940 mp->bvi_mac = bvi_mac;
4942 increment_mac_address (mac);
4949 vl_api_control_ping_t *mp_ping;
4952 /* Shut off async mode */
4953 vam->async_mode = 0;
4955 MPING (CONTROL_PING, mp_ping);
4958 timeout = vat_time_now (vam) + 1.0;
4959 while (vat_time_now (vam) < timeout)
4960 if (vam->result_ready == 1)
4965 if (vam->retval == -99)
4968 if (vam->async_errors > 0)
4970 errmsg ("%d asynchronous errors", vam->async_errors);
4973 vam->async_errors = 0;
4974 after = vat_time_now (vam);
4976 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4977 count, after - before, count / (after - before));
4983 /* Wait for a reply... */
4987 /* Return the good/bad news */
4988 return (vam->retval);
4992 api_bridge_domain_set_mac_age (vat_main_t * vam)
4994 unformat_input_t *i = vam->input;
4995 vl_api_bridge_domain_set_mac_age_t *mp;
5000 /* Parse args required to build the message */
5001 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5003 if (unformat (i, "bd_id %d", &bd_id));
5004 else if (unformat (i, "mac-age %d", &mac_age));
5011 errmsg ("missing bridge domain");
5017 errmsg ("mac age must be less than 256 ");
5021 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
5023 mp->bd_id = htonl (bd_id);
5024 mp->mac_age = (u8) mac_age;
5032 api_l2_flags (vat_main_t * vam)
5034 unformat_input_t *i = vam->input;
5035 vl_api_l2_flags_t *mp;
5038 u8 sw_if_index_set = 0;
5042 /* Parse args required to build the message */
5043 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5045 if (unformat (i, "sw_if_index %d", &sw_if_index))
5046 sw_if_index_set = 1;
5047 else if (unformat (i, "sw_if"))
5049 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5052 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5053 sw_if_index_set = 1;
5058 else if (unformat (i, "learn"))
5060 else if (unformat (i, "forward"))
5062 else if (unformat (i, "flood"))
5064 else if (unformat (i, "uu-flood"))
5065 flags |= L2_UU_FLOOD;
5066 else if (unformat (i, "arp-term"))
5067 flags |= L2_ARP_TERM;
5068 else if (unformat (i, "off"))
5070 else if (unformat (i, "disable"))
5076 if (sw_if_index_set == 0)
5078 errmsg ("missing interface name or sw_if_index");
5084 mp->sw_if_index = ntohl (sw_if_index);
5085 mp->feature_bitmap = ntohl (flags);
5086 mp->is_set = is_set;
5094 api_bridge_flags (vat_main_t * vam)
5096 unformat_input_t *i = vam->input;
5097 vl_api_bridge_flags_t *mp;
5101 bd_flags_t flags = 0;
5104 /* Parse args required to build the message */
5105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5107 if (unformat (i, "bd_id %d", &bd_id))
5109 else if (unformat (i, "learn"))
5110 flags |= BRIDGE_API_FLAG_LEARN;
5111 else if (unformat (i, "forward"))
5112 flags |= BRIDGE_API_FLAG_FWD;
5113 else if (unformat (i, "flood"))
5114 flags |= BRIDGE_API_FLAG_FLOOD;
5115 else if (unformat (i, "uu-flood"))
5116 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5117 else if (unformat (i, "arp-term"))
5118 flags |= BRIDGE_API_FLAG_ARP_TERM;
5119 else if (unformat (i, "off"))
5121 else if (unformat (i, "disable"))
5129 errmsg ("missing bridge domain");
5133 M (BRIDGE_FLAGS, mp);
5135 mp->bd_id = ntohl (bd_id);
5136 mp->flags = ntohl (flags);
5137 mp->is_set = is_set;
5145 api_bd_ip_mac_add_del (vat_main_t * vam)
5147 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5148 vl_api_mac_address_t mac = { 0 };
5149 unformat_input_t *i = vam->input;
5150 vl_api_bd_ip_mac_add_del_t *mp;
5159 /* Parse args required to build the message */
5160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5162 if (unformat (i, "bd_id %d", &bd_id))
5166 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5170 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5174 else if (unformat (i, "del"))
5182 errmsg ("missing bridge domain");
5185 else if (ip_set == 0)
5187 errmsg ("missing IP address");
5190 else if (mac_set == 0)
5192 errmsg ("missing MAC address");
5196 M (BD_IP_MAC_ADD_DEL, mp);
5198 mp->entry.bd_id = ntohl (bd_id);
5199 mp->is_add = is_add;
5201 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5202 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5210 api_bd_ip_mac_flush (vat_main_t * vam)
5212 unformat_input_t *i = vam->input;
5213 vl_api_bd_ip_mac_flush_t *mp;
5218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5220 if (unformat (i, "bd_id %d", &bd_id))
5230 errmsg ("missing bridge domain");
5234 M (BD_IP_MAC_FLUSH, mp);
5236 mp->bd_id = ntohl (bd_id);
5243 static void vl_api_bd_ip_mac_details_t_handler
5244 (vl_api_bd_ip_mac_details_t * mp)
5246 vat_main_t *vam = &vat_main;
5250 ntohl (mp->entry.bd_id),
5251 format_vl_api_mac_address, mp->entry.mac,
5252 format_vl_api_address, &mp->entry.ip);
5255 static void vl_api_bd_ip_mac_details_t_handler_json
5256 (vl_api_bd_ip_mac_details_t * mp)
5258 vat_main_t *vam = &vat_main;
5259 vat_json_node_t *node = NULL;
5261 if (VAT_JSON_ARRAY != vam->json_tree.type)
5263 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5264 vat_json_init_array (&vam->json_tree);
5266 node = vat_json_array_add (&vam->json_tree);
5268 vat_json_init_object (node);
5269 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5270 vat_json_object_add_string_copy (node, "mac_address",
5271 format (0, "%U", format_vl_api_mac_address,
5275 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5276 vat_json_object_add_string_copy (node, "ip_address", ip);
5281 api_bd_ip_mac_dump (vat_main_t * vam)
5283 unformat_input_t *i = vam->input;
5284 vl_api_bd_ip_mac_dump_t *mp;
5285 vl_api_control_ping_t *mp_ping;
5290 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5292 if (unformat (i, "bd_id %d", &bd_id))
5301 "\n%-5s %-7s %-20s %-30s",
5302 "bd_id", "is_ipv6", "mac_address", "ip_address");
5304 /* Dump Bridge Domain Ip to Mac entries */
5305 M (BD_IP_MAC_DUMP, mp);
5308 mp->bd_id = htonl (bd_id);
5314 /* Use a control ping for synchronization */
5315 MPING (CONTROL_PING, mp_ping);
5323 api_tap_create_v2 (vat_main_t * vam)
5325 unformat_input_t *i = vam->input;
5326 vl_api_tap_create_v2_t *mp;
5330 u32 num_rx_queues = 0;
5331 u8 *host_if_name = 0;
5332 u8 host_if_name_set = 0;
5335 u8 host_mac_addr[6];
5336 u8 host_mac_addr_set = 0;
5337 u8 *host_bridge = 0;
5338 u8 host_bridge_set = 0;
5339 u8 host_ip4_prefix_set = 0;
5340 u8 host_ip6_prefix_set = 0;
5341 ip4_address_t host_ip4_addr;
5342 ip4_address_t host_ip4_gw;
5343 u8 host_ip4_gw_set = 0;
5344 u32 host_ip4_prefix_len = 0;
5345 ip6_address_t host_ip6_addr;
5346 ip6_address_t host_ip6_gw;
5347 u8 host_ip6_gw_set = 0;
5348 u32 host_ip6_prefix_len = 0;
5349 u32 host_mtu_size = 0;
5350 u8 host_mtu_set = 0;
5353 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5355 clib_memset (mac_address, 0, sizeof (mac_address));
5357 /* Parse args required to build the message */
5358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5360 if (unformat (i, "id %u", &id))
5364 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5366 else if (unformat (i, "host-if-name %s", &host_if_name))
5367 host_if_name_set = 1;
5368 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5370 else if (unformat (i, "host-ns %s", &host_ns))
5372 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5374 host_mac_addr_set = 1;
5375 else if (unformat (i, "host-bridge %s", &host_bridge))
5376 host_bridge_set = 1;
5377 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5378 &host_ip4_addr, &host_ip4_prefix_len))
5379 host_ip4_prefix_set = 1;
5380 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5381 &host_ip6_addr, &host_ip6_prefix_len))
5382 host_ip6_prefix_set = 1;
5383 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5385 host_ip4_gw_set = 1;
5386 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5388 host_ip6_gw_set = 1;
5389 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5391 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5393 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5395 else if (unformat (i, "no-gso"))
5396 tap_flags &= ~TAP_API_FLAG_GSO;
5397 else if (unformat (i, "gso"))
5398 tap_flags |= TAP_API_FLAG_GSO;
5399 else if (unformat (i, "csum-offload"))
5400 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5401 else if (unformat (i, "persist"))
5402 tap_flags |= TAP_API_FLAG_PERSIST;
5403 else if (unformat (i, "attach"))
5404 tap_flags |= TAP_API_FLAG_ATTACH;
5405 else if (unformat (i, "tun"))
5406 tap_flags |= TAP_API_FLAG_TUN;
5407 else if (unformat (i, "gro-coalesce"))
5408 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5409 else if (unformat (i, "packed"))
5410 tap_flags |= TAP_API_FLAG_PACKED;
5411 else if (unformat (i, "in-order"))
5412 tap_flags |= TAP_API_FLAG_IN_ORDER;
5417 if (vec_len (host_if_name) > 63)
5419 errmsg ("tap name too long. ");
5422 if (vec_len (host_ns) > 63)
5424 errmsg ("host name space too long. ");
5427 if (vec_len (host_bridge) > 63)
5429 errmsg ("host bridge name too long. ");
5432 if (host_ip4_prefix_len > 32)
5434 errmsg ("host ip4 prefix length not valid. ");
5437 if (host_ip6_prefix_len > 128)
5439 errmsg ("host ip6 prefix length not valid. ");
5442 if (!is_pow2 (rx_ring_sz))
5444 errmsg ("rx ring size must be power of 2. ");
5447 if (rx_ring_sz > 32768)
5449 errmsg ("rx ring size must be 32768 or lower. ");
5452 if (!is_pow2 (tx_ring_sz))
5454 errmsg ("tx ring size must be power of 2. ");
5457 if (tx_ring_sz > 32768)
5459 errmsg ("tx ring size must be 32768 or lower. ");
5462 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5464 errmsg ("host MTU size must be in between 64 and 65355. ");
5468 /* Construct the API message */
5469 M (TAP_CREATE_V2, mp);
5471 mp->id = ntohl (id);
5472 mp->use_random_mac = random_mac;
5473 mp->num_rx_queues = (u8) num_rx_queues;
5474 mp->tx_ring_sz = ntohs (tx_ring_sz);
5475 mp->rx_ring_sz = ntohs (rx_ring_sz);
5476 mp->host_mtu_set = host_mtu_set;
5477 mp->host_mtu_size = ntohl (host_mtu_size);
5478 mp->host_mac_addr_set = host_mac_addr_set;
5479 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5480 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5481 mp->host_ip4_gw_set = host_ip4_gw_set;
5482 mp->host_ip6_gw_set = host_ip6_gw_set;
5483 mp->tap_flags = ntohl (tap_flags);
5484 mp->host_namespace_set = host_ns_set;
5485 mp->host_if_name_set = host_if_name_set;
5486 mp->host_bridge_set = host_bridge_set;
5488 if (random_mac == 0)
5489 clib_memcpy (mp->mac_address, mac_address, 6);
5490 if (host_mac_addr_set)
5491 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5492 if (host_if_name_set)
5493 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5495 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5496 if (host_bridge_set)
5497 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5498 if (host_ip4_prefix_set)
5500 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5501 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5503 if (host_ip6_prefix_set)
5505 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5506 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5508 if (host_ip4_gw_set)
5509 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5510 if (host_ip6_gw_set)
5511 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5514 vec_free (host_if_name);
5515 vec_free (host_bridge);
5520 /* Wait for a reply... */
5526 api_tap_delete_v2 (vat_main_t * vam)
5528 unformat_input_t *i = vam->input;
5529 vl_api_tap_delete_v2_t *mp;
5530 u32 sw_if_index = ~0;
5531 u8 sw_if_index_set = 0;
5534 /* Parse args required to build the message */
5535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5537 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5538 sw_if_index_set = 1;
5539 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5540 sw_if_index_set = 1;
5545 if (sw_if_index_set == 0)
5547 errmsg ("missing vpp interface name. ");
5551 /* Construct the API message */
5552 M (TAP_DELETE_V2, mp);
5554 mp->sw_if_index = ntohl (sw_if_index);
5559 /* Wait for a reply... */
5565 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5567 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5570 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5573 addr->domain = x[0];
5576 addr->function = x[3];
5582 api_virtio_pci_create_v2 (vat_main_t * vam)
5584 unformat_input_t *i = vam->input;
5585 vl_api_virtio_pci_create_v2_t *mp;
5589 u64 features = (u64) ~ (0ULL);
5590 u32 virtio_flags = 0;
5593 clib_memset (mac_address, 0, sizeof (mac_address));
5595 /* Parse args required to build the message */
5596 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5598 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5602 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5604 else if (unformat (i, "features 0x%llx", &features))
5606 else if (unformat (i, "gso-enabled"))
5607 virtio_flags |= VIRTIO_API_FLAG_GSO;
5608 else if (unformat (i, "csum-offload-enabled"))
5609 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5610 else if (unformat (i, "gro-coalesce"))
5611 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5612 else if (unformat (i, "packed"))
5613 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5614 else if (unformat (i, "in-order"))
5615 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5616 else if (unformat (i, "buffering"))
5617 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5624 errmsg ("pci address must be non zero. ");
5628 /* Construct the API message */
5629 M (VIRTIO_PCI_CREATE_V2, mp);
5631 mp->use_random_mac = random_mac;
5633 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5634 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5635 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5636 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5638 mp->features = clib_host_to_net_u64 (features);
5639 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5641 if (random_mac == 0)
5642 clib_memcpy (mp->mac_address, mac_address, 6);
5647 /* Wait for a reply... */
5653 api_virtio_pci_delete (vat_main_t * vam)
5655 unformat_input_t *i = vam->input;
5656 vl_api_virtio_pci_delete_t *mp;
5657 u32 sw_if_index = ~0;
5658 u8 sw_if_index_set = 0;
5661 /* Parse args required to build the message */
5662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5664 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5665 sw_if_index_set = 1;
5666 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5667 sw_if_index_set = 1;
5672 if (sw_if_index_set == 0)
5674 errmsg ("missing vpp interface name. ");
5678 /* Construct the API message */
5679 M (VIRTIO_PCI_DELETE, mp);
5681 mp->sw_if_index = htonl (sw_if_index);
5686 /* Wait for a reply... */
5692 api_bond_create (vat_main_t * vam)
5694 unformat_input_t *i = vam->input;
5695 vl_api_bond_create_t *mp;
5705 clib_memset (mac_address, 0, sizeof (mac_address));
5708 /* Parse args required to build the message */
5709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5711 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5713 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5714 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5716 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5719 else if (unformat (i, "numa-only"))
5721 else if (unformat (i, "id %u", &id))
5727 if (mode_is_set == 0)
5729 errmsg ("Missing bond mode. ");
5733 /* Construct the API message */
5734 M (BOND_CREATE, mp);
5736 mp->use_custom_mac = custom_mac;
5738 mp->mode = htonl (mode);
5739 mp->lb = htonl (lb);
5740 mp->id = htonl (id);
5741 mp->numa_only = numa_only;
5744 clib_memcpy (mp->mac_address, mac_address, 6);
5749 /* Wait for a reply... */
5755 api_bond_create2 (vat_main_t * vam)
5757 unformat_input_t *i = vam->input;
5758 vl_api_bond_create2_t *mp;
5769 clib_memset (mac_address, 0, sizeof (mac_address));
5772 /* Parse args required to build the message */
5773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5775 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5777 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5778 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5780 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5783 else if (unformat (i, "numa-only"))
5785 else if (unformat (i, "gso"))
5787 else if (unformat (i, "id %u", &id))
5793 if (mode_is_set == 0)
5795 errmsg ("Missing bond mode. ");
5799 /* Construct the API message */
5800 M (BOND_CREATE2, mp);
5802 mp->use_custom_mac = custom_mac;
5804 mp->mode = htonl (mode);
5805 mp->lb = htonl (lb);
5806 mp->id = htonl (id);
5807 mp->numa_only = numa_only;
5808 mp->enable_gso = gso;
5811 clib_memcpy (mp->mac_address, mac_address, 6);
5816 /* Wait for a reply... */
5822 api_bond_delete (vat_main_t * vam)
5824 unformat_input_t *i = vam->input;
5825 vl_api_bond_delete_t *mp;
5826 u32 sw_if_index = ~0;
5827 u8 sw_if_index_set = 0;
5830 /* Parse args required to build the message */
5831 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5833 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5834 sw_if_index_set = 1;
5835 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5836 sw_if_index_set = 1;
5841 if (sw_if_index_set == 0)
5843 errmsg ("missing vpp interface name. ");
5847 /* Construct the API message */
5848 M (BOND_DELETE, mp);
5850 mp->sw_if_index = ntohl (sw_if_index);
5855 /* Wait for a reply... */
5861 api_bond_add_member (vat_main_t * vam)
5863 unformat_input_t *i = vam->input;
5864 vl_api_bond_add_member_t *mp;
5865 u32 bond_sw_if_index;
5869 u32 bond_sw_if_index_is_set = 0;
5871 u8 sw_if_index_is_set = 0;
5873 /* Parse args required to build the message */
5874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5876 if (unformat (i, "sw_if_index %d", &sw_if_index))
5877 sw_if_index_is_set = 1;
5878 else if (unformat (i, "bond %u", &bond_sw_if_index))
5879 bond_sw_if_index_is_set = 1;
5880 else if (unformat (i, "passive %d", &is_passive))
5882 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5888 if (bond_sw_if_index_is_set == 0)
5890 errmsg ("Missing bond sw_if_index. ");
5893 if (sw_if_index_is_set == 0)
5895 errmsg ("Missing member sw_if_index. ");
5899 /* Construct the API message */
5900 M (BOND_ADD_MEMBER, mp);
5902 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5903 mp->sw_if_index = ntohl (sw_if_index);
5904 mp->is_long_timeout = is_long_timeout;
5905 mp->is_passive = is_passive;
5910 /* Wait for a reply... */
5916 api_bond_detach_member (vat_main_t * vam)
5918 unformat_input_t *i = vam->input;
5919 vl_api_bond_detach_member_t *mp;
5920 u32 sw_if_index = ~0;
5921 u8 sw_if_index_set = 0;
5924 /* Parse args required to build the message */
5925 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5927 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5928 sw_if_index_set = 1;
5929 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5930 sw_if_index_set = 1;
5935 if (sw_if_index_set == 0)
5937 errmsg ("missing vpp interface name. ");
5941 /* Construct the API message */
5942 M (BOND_DETACH_MEMBER, mp);
5944 mp->sw_if_index = ntohl (sw_if_index);
5949 /* Wait for a reply... */
5955 api_ip_table_add_del (vat_main_t * vam)
5957 unformat_input_t *i = vam->input;
5958 vl_api_ip_table_add_del_t *mp;
5964 /* Parse args required to build the message */
5965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5967 if (unformat (i, "ipv6"))
5969 else if (unformat (i, "del"))
5971 else if (unformat (i, "add"))
5973 else if (unformat (i, "table %d", &table_id))
5977 clib_warning ("parse error '%U'", format_unformat_error, i);
5984 errmsg ("missing table-ID");
5988 /* Construct the API message */
5989 M (IP_TABLE_ADD_DEL, mp);
5991 mp->table.table_id = ntohl (table_id);
5992 mp->table.is_ip6 = is_ipv6;
5993 mp->is_add = is_add;
5998 /* Wait for a reply... */
6005 unformat_fib_path (unformat_input_t * input, va_list * args)
6007 vat_main_t *vam = va_arg (*args, vat_main_t *);
6008 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
6009 u32 weight, preference;
6010 mpls_label_t out_label;
6012 clib_memset (path, 0, sizeof (*path));
6014 path->sw_if_index = ~0;
6018 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6020 if (unformat (input, "%U %U",
6021 unformat_vl_api_ip4_address,
6022 &path->nh.address.ip4,
6023 api_unformat_sw_if_index, vam, &path->sw_if_index))
6025 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6027 else if (unformat (input, "%U %U",
6028 unformat_vl_api_ip6_address,
6029 &path->nh.address.ip6,
6030 api_unformat_sw_if_index, vam, &path->sw_if_index))
6032 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6034 else if (unformat (input, "weight %u", &weight))
6036 path->weight = weight;
6038 else if (unformat (input, "preference %u", &preference))
6040 path->preference = preference;
6042 else if (unformat (input, "%U next-hop-table %d",
6043 unformat_vl_api_ip4_address,
6044 &path->nh.address.ip4, &path->table_id))
6046 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6048 else if (unformat (input, "%U next-hop-table %d",
6049 unformat_vl_api_ip6_address,
6050 &path->nh.address.ip6, &path->table_id))
6052 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6054 else if (unformat (input, "%U",
6055 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6058 * the recursive next-hops are by default in the default table
6061 path->sw_if_index = ~0;
6062 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6064 else if (unformat (input, "%U",
6065 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6068 * the recursive next-hops are by default in the default table
6071 path->sw_if_index = ~0;
6072 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6074 else if (unformat (input, "resolve-via-host"))
6076 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6078 else if (unformat (input, "resolve-via-attached"))
6080 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6082 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6084 path->type = FIB_API_PATH_TYPE_LOCAL;
6085 path->sw_if_index = ~0;
6086 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6088 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6090 path->type = FIB_API_PATH_TYPE_LOCAL;
6091 path->sw_if_index = ~0;
6092 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6094 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6096 else if (unformat (input, "via-label %d", &path->nh.via_label))
6098 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6099 path->sw_if_index = ~0;
6101 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6103 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6104 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6106 else if (unformat (input, "local"))
6108 path->type = FIB_API_PATH_TYPE_LOCAL;
6110 else if (unformat (input, "out-labels"))
6112 while (unformat (input, "%d", &out_label))
6114 path->label_stack[path->n_labels].label = out_label;
6115 path->label_stack[path->n_labels].is_uniform = 0;
6116 path->label_stack[path->n_labels].ttl = 64;
6120 else if (unformat (input, "via"))
6122 /* new path, back up and return */
6123 unformat_put_input (input);
6124 unformat_put_input (input);
6125 unformat_put_input (input);
6126 unformat_put_input (input);
6135 path->proto = ntohl (path->proto);
6136 path->type = ntohl (path->type);
6137 path->flags = ntohl (path->flags);
6138 path->table_id = ntohl (path->table_id);
6139 path->sw_if_index = ntohl (path->sw_if_index);
6145 api_ip_route_add_del (vat_main_t * vam)
6147 unformat_input_t *i = vam->input;
6148 vl_api_ip_route_add_del_t *mp;
6151 u8 is_multipath = 0;
6154 vl_api_prefix_t pfx = { };
6155 vl_api_fib_path_t paths[8];
6159 u32 random_add_del = 0;
6160 u32 *random_vector = 0;
6161 u32 random_seed = 0xdeaddabe;
6163 /* Parse args required to build the message */
6164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6166 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6168 else if (unformat (i, "del"))
6170 else if (unformat (i, "add"))
6172 else if (unformat (i, "vrf %d", &vrf_id))
6174 else if (unformat (i, "count %d", &count))
6176 else if (unformat (i, "random"))
6178 else if (unformat (i, "multipath"))
6180 else if (unformat (i, "seed %d", &random_seed))
6184 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6187 if (8 == path_count)
6189 errmsg ("max 8 paths");
6195 clib_warning ("parse error '%U'", format_unformat_error, i);
6202 errmsg ("specify a path; via ...");
6205 if (prefix_set == 0)
6207 errmsg ("missing prefix");
6211 /* Generate a pile of unique, random routes */
6214 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6215 u32 this_random_address;
6218 random_hash = hash_create (count, sizeof (uword));
6220 hash_set (random_hash, i->as_u32, 1);
6221 for (j = 0; j <= count; j++)
6225 this_random_address = random_u32 (&random_seed);
6226 this_random_address =
6227 clib_host_to_net_u32 (this_random_address);
6229 while (hash_get (random_hash, this_random_address));
6230 vec_add1 (random_vector, this_random_address);
6231 hash_set (random_hash, this_random_address, 1);
6233 hash_free (random_hash);
6234 set_ip4_address (&pfx.address, random_vector[0]);
6239 /* Turn on async mode */
6240 vam->async_mode = 1;
6241 vam->async_errors = 0;
6242 before = vat_time_now (vam);
6245 for (j = 0; j < count; j++)
6247 /* Construct the API message */
6248 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6250 mp->is_add = is_add;
6251 mp->is_multipath = is_multipath;
6253 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6254 mp->route.table_id = ntohl (vrf_id);
6255 mp->route.n_paths = path_count;
6257 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6260 set_ip4_address (&pfx.address, random_vector[j + 1]);
6262 increment_address (&pfx.address);
6265 /* If we receive SIGTERM, stop now... */
6270 /* When testing multiple add/del ops, use a control-ping to sync */
6273 vl_api_control_ping_t *mp_ping;
6277 /* Shut off async mode */
6278 vam->async_mode = 0;
6280 MPING (CONTROL_PING, mp_ping);
6283 timeout = vat_time_now (vam) + 1.0;
6284 while (vat_time_now (vam) < timeout)
6285 if (vam->result_ready == 1)
6290 if (vam->retval == -99)
6293 if (vam->async_errors > 0)
6295 errmsg ("%d asynchronous errors", vam->async_errors);
6298 vam->async_errors = 0;
6299 after = vat_time_now (vam);
6301 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6305 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6306 count, after - before, count / (after - before));
6312 /* Wait for a reply... */
6317 /* Return the good/bad news */
6318 return (vam->retval);
6322 api_ip_mroute_add_del (vat_main_t * vam)
6324 unformat_input_t *i = vam->input;
6325 u8 path_set = 0, prefix_set = 0, is_add = 1;
6326 vl_api_ip_mroute_add_del_t *mp;
6327 mfib_entry_flags_t eflags = 0;
6328 vl_api_mfib_path_t path;
6329 vl_api_mprefix_t pfx = { };
6333 /* Parse args required to build the message */
6334 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6336 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6339 pfx.grp_address_length = htons (pfx.grp_address_length);
6341 else if (unformat (i, "del"))
6343 else if (unformat (i, "add"))
6345 else if (unformat (i, "vrf %d", &vrf_id))
6347 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6348 path.itf_flags = htonl (path.itf_flags);
6349 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6351 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6355 clib_warning ("parse error '%U'", format_unformat_error, i);
6360 if (prefix_set == 0)
6362 errmsg ("missing addresses\n");
6367 errmsg ("missing path\n");
6371 /* Construct the API message */
6372 M (IP_MROUTE_ADD_DEL, mp);
6374 mp->is_add = is_add;
6375 mp->is_multipath = 1;
6377 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6378 mp->route.table_id = htonl (vrf_id);
6379 mp->route.n_paths = 1;
6380 mp->route.entry_flags = htonl (eflags);
6382 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6386 /* Wait for a reply... */
6392 api_mpls_table_add_del (vat_main_t * vam)
6394 unformat_input_t *i = vam->input;
6395 vl_api_mpls_table_add_del_t *mp;
6400 /* Parse args required to build the message */
6401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6403 if (unformat (i, "table %d", &table_id))
6405 else if (unformat (i, "del"))
6407 else if (unformat (i, "add"))
6411 clib_warning ("parse error '%U'", format_unformat_error, i);
6418 errmsg ("missing table-ID");
6422 /* Construct the API message */
6423 M (MPLS_TABLE_ADD_DEL, mp);
6425 mp->mt_table.mt_table_id = ntohl (table_id);
6426 mp->mt_is_add = is_add;
6431 /* Wait for a reply... */
6438 api_mpls_route_add_del (vat_main_t * vam)
6440 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6441 mpls_label_t local_label = MPLS_LABEL_INVALID;
6442 unformat_input_t *i = vam->input;
6443 vl_api_mpls_route_add_del_t *mp;
6444 vl_api_fib_path_t paths[8];
6448 /* Parse args required to build the message */
6449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6451 if (unformat (i, "%d", &local_label))
6453 else if (unformat (i, "eos"))
6455 else if (unformat (i, "non-eos"))
6457 else if (unformat (i, "del"))
6459 else if (unformat (i, "add"))
6461 else if (unformat (i, "multipath"))
6463 else if (unformat (i, "count %d", &count))
6467 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6470 if (8 == path_count)
6472 errmsg ("max 8 paths");
6478 clib_warning ("parse error '%U'", format_unformat_error, i);
6485 errmsg ("specify a path; via ...");
6489 if (MPLS_LABEL_INVALID == local_label)
6491 errmsg ("missing label");
6497 /* Turn on async mode */
6498 vam->async_mode = 1;
6499 vam->async_errors = 0;
6500 before = vat_time_now (vam);
6503 for (j = 0; j < count; j++)
6505 /* Construct the API message */
6506 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6508 mp->mr_is_add = is_add;
6509 mp->mr_is_multipath = is_multipath;
6511 mp->mr_route.mr_label = local_label;
6512 mp->mr_route.mr_eos = is_eos;
6513 mp->mr_route.mr_table_id = 0;
6514 mp->mr_route.mr_n_paths = path_count;
6516 clib_memcpy (&mp->mr_route.mr_paths, paths,
6517 sizeof (paths[0]) * path_count);
6523 /* If we receive SIGTERM, stop now... */
6528 /* When testing multiple add/del ops, use a control-ping to sync */
6531 vl_api_control_ping_t *mp_ping;
6535 /* Shut off async mode */
6536 vam->async_mode = 0;
6538 MPING (CONTROL_PING, mp_ping);
6541 timeout = vat_time_now (vam) + 1.0;
6542 while (vat_time_now (vam) < timeout)
6543 if (vam->result_ready == 1)
6548 if (vam->retval == -99)
6551 if (vam->async_errors > 0)
6553 errmsg ("%d asynchronous errors", vam->async_errors);
6556 vam->async_errors = 0;
6557 after = vat_time_now (vam);
6559 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6563 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6564 count, after - before, count / (after - before));
6570 /* Wait for a reply... */
6575 /* Return the good/bad news */
6576 return (vam->retval);
6581 api_mpls_ip_bind_unbind (vat_main_t * vam)
6583 unformat_input_t *i = vam->input;
6584 vl_api_mpls_ip_bind_unbind_t *mp;
6585 u32 ip_table_id = 0;
6587 vl_api_prefix_t pfx;
6589 mpls_label_t local_label = MPLS_LABEL_INVALID;
6592 /* Parse args required to build the message */
6593 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6595 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6597 else if (unformat (i, "%d", &local_label))
6599 else if (unformat (i, "table-id %d", &ip_table_id))
6601 else if (unformat (i, "unbind"))
6603 else if (unformat (i, "bind"))
6607 clib_warning ("parse error '%U'", format_unformat_error, i);
6614 errmsg ("IP prefix not set");
6618 if (MPLS_LABEL_INVALID == local_label)
6620 errmsg ("missing label");
6624 /* Construct the API message */
6625 M (MPLS_IP_BIND_UNBIND, mp);
6627 mp->mb_is_bind = is_bind;
6628 mp->mb_ip_table_id = ntohl (ip_table_id);
6629 mp->mb_mpls_table_id = 0;
6630 mp->mb_label = ntohl (local_label);
6631 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6636 /* Wait for a reply... */
6643 api_sr_mpls_policy_add (vat_main_t * vam)
6645 unformat_input_t *i = vam->input;
6646 vl_api_sr_mpls_policy_add_t *mp;
6652 u32 *segments = NULL;
6655 /* Parse args required to build the message */
6656 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6658 if (unformat (i, "bsid %d", &bsid))
6660 else if (unformat (i, "weight %d", &weight))
6662 else if (unformat (i, "spray"))
6664 else if (unformat (i, "next %d", &sid))
6667 vec_add1 (segments, htonl (sid));
6671 clib_warning ("parse error '%U'", format_unformat_error, i);
6678 errmsg ("bsid not set");
6682 if (n_segments == 0)
6684 errmsg ("no sid in segment stack");
6688 /* Construct the API message */
6689 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6691 mp->bsid = htonl (bsid);
6692 mp->weight = htonl (weight);
6693 mp->is_spray = type;
6694 mp->n_segments = n_segments;
6695 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6696 vec_free (segments);
6701 /* Wait for a reply... */
6707 api_sr_mpls_policy_del (vat_main_t * vam)
6709 unformat_input_t *i = vam->input;
6710 vl_api_sr_mpls_policy_del_t *mp;
6714 /* Parse args required to build the message */
6715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6717 if (unformat (i, "bsid %d", &bsid))
6721 clib_warning ("parse error '%U'", format_unformat_error, i);
6728 errmsg ("bsid not set");
6732 /* Construct the API message */
6733 M (SR_MPLS_POLICY_DEL, mp);
6735 mp->bsid = htonl (bsid);
6740 /* Wait for a reply... */
6746 api_bier_table_add_del (vat_main_t * vam)
6748 unformat_input_t *i = vam->input;
6749 vl_api_bier_table_add_del_t *mp;
6751 u32 set = 0, sub_domain = 0, hdr_len = 3;
6752 mpls_label_t local_label = MPLS_LABEL_INVALID;
6755 /* Parse args required to build the message */
6756 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6758 if (unformat (i, "sub-domain %d", &sub_domain))
6760 else if (unformat (i, "set %d", &set))
6762 else if (unformat (i, "label %d", &local_label))
6764 else if (unformat (i, "hdr-len %d", &hdr_len))
6766 else if (unformat (i, "add"))
6768 else if (unformat (i, "del"))
6772 clib_warning ("parse error '%U'", format_unformat_error, i);
6777 if (MPLS_LABEL_INVALID == local_label)
6779 errmsg ("missing label\n");
6783 /* Construct the API message */
6784 M (BIER_TABLE_ADD_DEL, mp);
6786 mp->bt_is_add = is_add;
6787 mp->bt_label = ntohl (local_label);
6788 mp->bt_tbl_id.bt_set = set;
6789 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6790 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6795 /* Wait for a reply... */
6802 api_bier_route_add_del (vat_main_t * vam)
6804 unformat_input_t *i = vam->input;
6805 vl_api_bier_route_add_del_t *mp;
6807 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6808 ip4_address_t v4_next_hop_address;
6809 ip6_address_t v6_next_hop_address;
6810 u8 next_hop_set = 0;
6811 u8 next_hop_proto_is_ip4 = 1;
6812 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6815 /* Parse args required to build the message */
6816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6818 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6820 next_hop_proto_is_ip4 = 1;
6823 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6825 next_hop_proto_is_ip4 = 0;
6828 if (unformat (i, "sub-domain %d", &sub_domain))
6830 else if (unformat (i, "set %d", &set))
6832 else if (unformat (i, "hdr-len %d", &hdr_len))
6834 else if (unformat (i, "bp %d", &bp))
6836 else if (unformat (i, "add"))
6838 else if (unformat (i, "del"))
6840 else if (unformat (i, "out-label %d", &next_hop_out_label))
6844 clib_warning ("parse error '%U'", format_unformat_error, i);
6849 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6851 errmsg ("next hop / label set\n");
6856 errmsg ("bit=position not set\n");
6860 /* Construct the API message */
6861 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6863 mp->br_is_add = is_add;
6864 mp->br_route.br_tbl_id.bt_set = set;
6865 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6866 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6867 mp->br_route.br_bp = ntohs (bp);
6868 mp->br_route.br_n_paths = 1;
6869 mp->br_route.br_paths[0].n_labels = 1;
6870 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6871 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6872 FIB_API_PATH_NH_PROTO_IP4 :
6873 FIB_API_PATH_NH_PROTO_IP6);
6875 if (next_hop_proto_is_ip4)
6877 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6878 &v4_next_hop_address, sizeof (v4_next_hop_address));
6882 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6883 &v6_next_hop_address, sizeof (v6_next_hop_address));
6889 /* Wait for a reply... */
6896 api_mpls_tunnel_add_del (vat_main_t * vam)
6898 unformat_input_t *i = vam->input;
6899 vl_api_mpls_tunnel_add_del_t *mp;
6901 vl_api_fib_path_t paths[8];
6902 u32 sw_if_index = ~0;
6908 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6910 if (unformat (i, "add"))
6914 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6916 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6918 else if (unformat (i, "l2-only"))
6922 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6925 if (8 == path_count)
6927 errmsg ("max 8 paths");
6933 clib_warning ("parse error '%U'", format_unformat_error, i);
6938 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6940 mp->mt_is_add = is_add;
6941 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6942 mp->mt_tunnel.mt_l2_only = l2_only;
6943 mp->mt_tunnel.mt_is_multicast = 0;
6944 mp->mt_tunnel.mt_n_paths = path_count;
6946 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6947 sizeof (paths[0]) * path_count);
6955 api_sw_interface_set_unnumbered (vat_main_t * vam)
6957 unformat_input_t *i = vam->input;
6958 vl_api_sw_interface_set_unnumbered_t *mp;
6960 u32 unnum_sw_index = ~0;
6962 u8 sw_if_index_set = 0;
6965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6967 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6968 sw_if_index_set = 1;
6969 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6970 sw_if_index_set = 1;
6971 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6973 else if (unformat (i, "del"))
6977 clib_warning ("parse error '%U'", format_unformat_error, i);
6982 if (sw_if_index_set == 0)
6984 errmsg ("missing interface name or sw_if_index");
6988 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6990 mp->sw_if_index = ntohl (sw_if_index);
6991 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6992 mp->is_add = is_add;
7001 api_create_vlan_subif (vat_main_t * vam)
7003 unformat_input_t *i = vam->input;
7004 vl_api_create_vlan_subif_t *mp;
7006 u8 sw_if_index_set = 0;
7011 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7013 if (unformat (i, "sw_if_index %d", &sw_if_index))
7014 sw_if_index_set = 1;
7016 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7017 sw_if_index_set = 1;
7018 else if (unformat (i, "vlan %d", &vlan_id))
7022 clib_warning ("parse error '%U'", format_unformat_error, i);
7027 if (sw_if_index_set == 0)
7029 errmsg ("missing interface name or sw_if_index");
7033 if (vlan_id_set == 0)
7035 errmsg ("missing vlan_id");
7038 M (CREATE_VLAN_SUBIF, mp);
7040 mp->sw_if_index = ntohl (sw_if_index);
7041 mp->vlan_id = ntohl (vlan_id);
7048 #define foreach_create_subif_bit \
7055 _(outer_vlan_id_any) \
7056 _(inner_vlan_id_any)
7058 #define foreach_create_subif_flag \
7063 _(4, "exact_match") \
7064 _(5, "default_sub") \
7065 _(6, "outer_vlan_id_any") \
7066 _(7, "inner_vlan_id_any")
7069 api_create_subif (vat_main_t * vam)
7071 unformat_input_t *i = vam->input;
7072 vl_api_create_subif_t *mp;
7074 u8 sw_if_index_set = 0;
7077 u32 __attribute__ ((unused)) no_tags = 0;
7078 u32 __attribute__ ((unused)) one_tag = 0;
7079 u32 __attribute__ ((unused)) two_tags = 0;
7080 u32 __attribute__ ((unused)) dot1ad = 0;
7081 u32 __attribute__ ((unused)) exact_match = 0;
7082 u32 __attribute__ ((unused)) default_sub = 0;
7083 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7084 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7086 u16 outer_vlan_id = 0;
7087 u16 inner_vlan_id = 0;
7090 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7092 if (unformat (i, "sw_if_index %d", &sw_if_index))
7093 sw_if_index_set = 1;
7095 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7096 sw_if_index_set = 1;
7097 else if (unformat (i, "sub_id %d", &sub_id))
7099 else if (unformat (i, "outer_vlan_id %d", &tmp))
7100 outer_vlan_id = tmp;
7101 else if (unformat (i, "inner_vlan_id %d", &tmp))
7102 inner_vlan_id = tmp;
7104 #define _(a) else if (unformat (i, #a)) a = 1 ;
7105 foreach_create_subif_bit
7109 clib_warning ("parse error '%U'", format_unformat_error, i);
7114 if (sw_if_index_set == 0)
7116 errmsg ("missing interface name or sw_if_index");
7120 if (sub_id_set == 0)
7122 errmsg ("missing sub_id");
7125 M (CREATE_SUBIF, mp);
7127 mp->sw_if_index = ntohl (sw_if_index);
7128 mp->sub_id = ntohl (sub_id);
7130 #define _(a,b) mp->sub_if_flags |= (1 << a);
7131 foreach_create_subif_flag;
7134 mp->outer_vlan_id = ntohs (outer_vlan_id);
7135 mp->inner_vlan_id = ntohs (inner_vlan_id);
7143 api_ip_table_replace_begin (vat_main_t * vam)
7145 unformat_input_t *i = vam->input;
7146 vl_api_ip_table_replace_begin_t *mp;
7151 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7153 if (unformat (i, "table %d", &table_id))
7155 else if (unformat (i, "ipv6"))
7159 clib_warning ("parse error '%U'", format_unformat_error, i);
7164 M (IP_TABLE_REPLACE_BEGIN, mp);
7166 mp->table.table_id = ntohl (table_id);
7167 mp->table.is_ip6 = is_ipv6;
7175 api_ip_table_flush (vat_main_t * vam)
7177 unformat_input_t *i = vam->input;
7178 vl_api_ip_table_flush_t *mp;
7183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7185 if (unformat (i, "table %d", &table_id))
7187 else if (unformat (i, "ipv6"))
7191 clib_warning ("parse error '%U'", format_unformat_error, i);
7196 M (IP_TABLE_FLUSH, mp);
7198 mp->table.table_id = ntohl (table_id);
7199 mp->table.is_ip6 = is_ipv6;
7207 api_ip_table_replace_end (vat_main_t * vam)
7209 unformat_input_t *i = vam->input;
7210 vl_api_ip_table_replace_end_t *mp;
7215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7217 if (unformat (i, "table %d", &table_id))
7219 else if (unformat (i, "ipv6"))
7223 clib_warning ("parse error '%U'", format_unformat_error, i);
7228 M (IP_TABLE_REPLACE_END, mp);
7230 mp->table.table_id = ntohl (table_id);
7231 mp->table.is_ip6 = is_ipv6;
7239 api_set_ip_flow_hash (vat_main_t * vam)
7241 unformat_input_t *i = vam->input;
7242 vl_api_set_ip_flow_hash_t *mp;
7254 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7256 if (unformat (i, "vrf %d", &vrf_id))
7258 else if (unformat (i, "ipv6"))
7260 else if (unformat (i, "src"))
7262 else if (unformat (i, "dst"))
7264 else if (unformat (i, "sport"))
7266 else if (unformat (i, "dport"))
7268 else if (unformat (i, "proto"))
7270 else if (unformat (i, "reverse"))
7275 clib_warning ("parse error '%U'", format_unformat_error, i);
7280 if (vrf_id_set == 0)
7282 errmsg ("missing vrf id");
7286 M (SET_IP_FLOW_HASH, mp);
7292 mp->reverse = reverse;
7293 mp->vrf_id = ntohl (vrf_id);
7294 mp->is_ipv6 = is_ipv6;
7302 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7304 unformat_input_t *i = vam->input;
7305 vl_api_sw_interface_ip6_enable_disable_t *mp;
7307 u8 sw_if_index_set = 0;
7311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7313 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7314 sw_if_index_set = 1;
7315 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7316 sw_if_index_set = 1;
7317 else if (unformat (i, "enable"))
7319 else if (unformat (i, "disable"))
7323 clib_warning ("parse error '%U'", format_unformat_error, i);
7328 if (sw_if_index_set == 0)
7330 errmsg ("missing interface name or sw_if_index");
7334 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7336 mp->sw_if_index = ntohl (sw_if_index);
7337 mp->enable = enable;
7346 api_l2_patch_add_del (vat_main_t * vam)
7348 unformat_input_t *i = vam->input;
7349 vl_api_l2_patch_add_del_t *mp;
7351 u8 rx_sw_if_index_set = 0;
7353 u8 tx_sw_if_index_set = 0;
7357 /* Parse args required to build the message */
7358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7360 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7361 rx_sw_if_index_set = 1;
7362 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7363 tx_sw_if_index_set = 1;
7364 else if (unformat (i, "rx"))
7366 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7368 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7370 rx_sw_if_index_set = 1;
7375 else if (unformat (i, "tx"))
7377 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7379 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7381 tx_sw_if_index_set = 1;
7386 else if (unformat (i, "del"))
7392 if (rx_sw_if_index_set == 0)
7394 errmsg ("missing rx interface name or rx_sw_if_index");
7398 if (tx_sw_if_index_set == 0)
7400 errmsg ("missing tx interface name or tx_sw_if_index");
7404 M (L2_PATCH_ADD_DEL, mp);
7406 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7407 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7408 mp->is_add = is_add;
7416 u8 localsid_addr[16];
7425 api_sr_localsid_add_del (vat_main_t * vam)
7427 unformat_input_t *i = vam->input;
7428 vl_api_sr_localsid_add_del_t *mp;
7431 ip6_address_t localsid;
7435 u32 fib_table = ~(u32) 0;
7436 ip46_address_t nh_addr;
7437 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7439 bool nexthop_set = 0;
7443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7445 if (unformat (i, "del"))
7447 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7448 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7450 else if (unformat (i, "behavior %u", &behavior));
7451 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7452 else if (unformat (i, "fib-table %u", &fib_table));
7453 else if (unformat (i, "end.psp %u", &behavior));
7458 M (SR_LOCALSID_ADD_DEL, mp);
7460 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7464 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7466 mp->behavior = behavior;
7467 mp->sw_if_index = ntohl (sw_if_index);
7468 mp->fib_table = ntohl (fib_table);
7469 mp->end_psp = end_psp;
7470 mp->is_del = is_del;
7478 api_ioam_enable (vat_main_t * vam)
7480 unformat_input_t *input = vam->input;
7481 vl_api_ioam_enable_t *mp;
7483 int has_trace_option = 0;
7484 int has_pot_option = 0;
7485 int has_seqno_option = 0;
7486 int has_analyse_option = 0;
7489 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7491 if (unformat (input, "trace"))
7492 has_trace_option = 1;
7493 else if (unformat (input, "pot"))
7495 else if (unformat (input, "seqno"))
7496 has_seqno_option = 1;
7497 else if (unformat (input, "analyse"))
7498 has_analyse_option = 1;
7502 M (IOAM_ENABLE, mp);
7503 mp->id = htons (id);
7504 mp->seqno = has_seqno_option;
7505 mp->analyse = has_analyse_option;
7506 mp->pot_enable = has_pot_option;
7507 mp->trace_enable = has_trace_option;
7516 api_ioam_disable (vat_main_t * vam)
7518 vl_api_ioam_disable_t *mp;
7521 M (IOAM_DISABLE, mp);
7527 #define foreach_tcp_proto_field \
7531 #define foreach_udp_proto_field \
7535 #define foreach_ip4_proto_field \
7547 u16 src_port, dst_port;
7550 #if VPP_API_TEST_BUILTIN == 0
7552 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7554 u8 **maskp = va_arg (*args, u8 **);
7556 u8 found_something = 0;
7559 #define _(a) u8 a=0;
7560 foreach_tcp_proto_field;
7563 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7566 #define _(a) else if (unformat (input, #a)) a=1;
7567 foreach_tcp_proto_field
7573 #define _(a) found_something += a;
7574 foreach_tcp_proto_field;
7577 if (found_something == 0)
7580 vec_validate (mask, sizeof (*tcp) - 1);
7582 tcp = (tcp_header_t *) mask;
7584 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7585 foreach_tcp_proto_field;
7593 unformat_udp_mask (unformat_input_t * input, va_list * args)
7595 u8 **maskp = va_arg (*args, u8 **);
7597 u8 found_something = 0;
7600 #define _(a) u8 a=0;
7601 foreach_udp_proto_field;
7604 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7607 #define _(a) else if (unformat (input, #a)) a=1;
7608 foreach_udp_proto_field
7614 #define _(a) found_something += a;
7615 foreach_udp_proto_field;
7618 if (found_something == 0)
7621 vec_validate (mask, sizeof (*udp) - 1);
7623 udp = (udp_header_t *) mask;
7625 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7626 foreach_udp_proto_field;
7634 unformat_l4_mask (unformat_input_t * input, va_list * args)
7636 u8 **maskp = va_arg (*args, u8 **);
7637 u16 src_port = 0, dst_port = 0;
7638 tcpudp_header_t *tcpudp;
7640 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7642 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7644 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7646 else if (unformat (input, "src_port"))
7648 else if (unformat (input, "dst_port"))
7654 if (!src_port && !dst_port)
7658 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7660 tcpudp = (tcpudp_header_t *) mask;
7661 tcpudp->src_port = src_port;
7662 tcpudp->dst_port = dst_port;
7670 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7672 u8 **maskp = va_arg (*args, u8 **);
7674 u8 found_something = 0;
7677 #define _(a) u8 a=0;
7678 foreach_ip4_proto_field;
7684 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7686 if (unformat (input, "version"))
7688 else if (unformat (input, "hdr_length"))
7690 else if (unformat (input, "src"))
7692 else if (unformat (input, "dst"))
7694 else if (unformat (input, "proto"))
7697 #define _(a) else if (unformat (input, #a)) a=1;
7698 foreach_ip4_proto_field
7704 #define _(a) found_something += a;
7705 foreach_ip4_proto_field;
7708 if (found_something == 0)
7711 vec_validate (mask, sizeof (*ip) - 1);
7713 ip = (ip4_header_t *) mask;
7715 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7716 foreach_ip4_proto_field;
7719 ip->ip_version_and_header_length = 0;
7722 ip->ip_version_and_header_length |= 0xF0;
7725 ip->ip_version_and_header_length |= 0x0F;
7731 #define foreach_ip6_proto_field \
7739 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7741 u8 **maskp = va_arg (*args, u8 **);
7743 u8 found_something = 0;
7745 u32 ip_version_traffic_class_and_flow_label;
7747 #define _(a) u8 a=0;
7748 foreach_ip6_proto_field;
7751 u8 traffic_class = 0;
7754 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7756 if (unformat (input, "version"))
7758 else if (unformat (input, "traffic-class"))
7760 else if (unformat (input, "flow-label"))
7762 else if (unformat (input, "src"))
7764 else if (unformat (input, "dst"))
7766 else if (unformat (input, "proto"))
7769 #define _(a) else if (unformat (input, #a)) a=1;
7770 foreach_ip6_proto_field
7776 #define _(a) found_something += a;
7777 foreach_ip6_proto_field;
7780 if (found_something == 0)
7783 vec_validate (mask, sizeof (*ip) - 1);
7785 ip = (ip6_header_t *) mask;
7787 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7788 foreach_ip6_proto_field;
7791 ip_version_traffic_class_and_flow_label = 0;
7794 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7797 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7800 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7802 ip->ip_version_traffic_class_and_flow_label =
7803 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7810 unformat_l3_mask (unformat_input_t * input, va_list * args)
7812 u8 **maskp = va_arg (*args, u8 **);
7814 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7816 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7818 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7827 unformat_l2_mask (unformat_input_t * input, va_list * args)
7829 u8 **maskp = va_arg (*args, u8 **);
7844 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7846 if (unformat (input, "src"))
7848 else if (unformat (input, "dst"))
7850 else if (unformat (input, "proto"))
7852 else if (unformat (input, "tag1"))
7854 else if (unformat (input, "tag2"))
7856 else if (unformat (input, "ignore-tag1"))
7858 else if (unformat (input, "ignore-tag2"))
7860 else if (unformat (input, "cos1"))
7862 else if (unformat (input, "cos2"))
7864 else if (unformat (input, "dot1q"))
7866 else if (unformat (input, "dot1ad"))
7871 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7872 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7875 if (tag1 || ignore_tag1 || cos1 || dot1q)
7877 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7880 vec_validate (mask, len - 1);
7883 clib_memset (mask, 0xff, 6);
7886 clib_memset (mask + 6, 0xff, 6);
7890 /* inner vlan tag */
7899 mask[21] = mask[20] = 0xff;
7920 mask[16] = mask[17] = 0xff;
7930 mask[12] = mask[13] = 0xff;
7937 unformat_classify_mask (unformat_input_t * input, va_list * args)
7939 u8 **maskp = va_arg (*args, u8 **);
7940 u32 *skipp = va_arg (*args, u32 *);
7941 u32 *matchp = va_arg (*args, u32 *);
7949 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7951 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7953 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7955 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7957 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7971 if (mask || l2 || l3 || l4)
7975 /* "With a free Ethernet header in every package" */
7977 vec_validate (l2, 13);
7981 vec_append (mask, l3);
7986 vec_append (mask, l4);
7991 /* Scan forward looking for the first significant mask octet */
7992 for (i = 0; i < vec_len (mask); i++)
7996 /* compute (skip, match) params */
7997 *skipp = i / sizeof (u32x4);
7998 vec_delete (mask, *skipp * sizeof (u32x4), 0);
8000 /* Pad mask to an even multiple of the vector size */
8001 while (vec_len (mask) % sizeof (u32x4))
8004 match = vec_len (mask) / sizeof (u32x4);
8006 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8008 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8009 if (*tmp || *(tmp + 1))
8014 clib_warning ("BUG: match 0");
8016 _vec_len (mask) = match * sizeof (u32x4);
8026 #endif /* VPP_API_TEST_BUILTIN */
8028 #define foreach_l2_next \
8030 _(ethernet, ETHERNET_INPUT) \
8035 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8037 u32 *miss_next_indexp = va_arg (*args, u32 *);
8042 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8046 if (unformat (input, "%d", &tmp))
8055 *miss_next_indexp = next_index;
8059 #define foreach_ip_next \
8065 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8067 u32 *miss_next_indexp = va_arg (*args, u32 *);
8072 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8076 if (unformat (input, "%d", &tmp))
8085 *miss_next_indexp = next_index;
8089 #define foreach_acl_next \
8093 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8095 u32 *miss_next_indexp = va_arg (*args, u32 *);
8100 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8104 if (unformat (input, "permit"))
8109 else if (unformat (input, "%d", &tmp))
8118 *miss_next_indexp = next_index;
8123 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8125 u32 *r = va_arg (*args, u32 *);
8127 if (unformat (input, "conform-color"))
8128 *r = POLICE_CONFORM;
8129 else if (unformat (input, "exceed-color"))
8138 api_classify_add_del_table (vat_main_t * vam)
8140 unformat_input_t *i = vam->input;
8141 vl_api_classify_add_del_table_t *mp;
8148 u32 table_index = ~0;
8149 u32 next_table_index = ~0;
8150 u32 miss_next_index = ~0;
8151 u32 memory_size = 32 << 20;
8153 u32 current_data_flag = 0;
8154 int current_data_offset = 0;
8157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8159 if (unformat (i, "del"))
8161 else if (unformat (i, "del-chain"))
8166 else if (unformat (i, "buckets %d", &nbuckets))
8168 else if (unformat (i, "memory_size %d", &memory_size))
8170 else if (unformat (i, "skip %d", &skip))
8172 else if (unformat (i, "match %d", &match))
8174 else if (unformat (i, "table %d", &table_index))
8176 else if (unformat (i, "mask %U", unformat_classify_mask,
8177 &mask, &skip, &match))
8179 else if (unformat (i, "next-table %d", &next_table_index))
8181 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8184 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8187 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8190 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8192 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8198 if (is_add && mask == 0)
8200 errmsg ("Mask required");
8204 if (is_add && skip == ~0)
8206 errmsg ("skip count required");
8210 if (is_add && match == ~0)
8212 errmsg ("match count required");
8216 if (!is_add && table_index == ~0)
8218 errmsg ("table index required for delete");
8222 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8224 mp->is_add = is_add;
8225 mp->del_chain = del_chain;
8226 mp->table_index = ntohl (table_index);
8227 mp->nbuckets = ntohl (nbuckets);
8228 mp->memory_size = ntohl (memory_size);
8229 mp->skip_n_vectors = ntohl (skip);
8230 mp->match_n_vectors = ntohl (match);
8231 mp->next_table_index = ntohl (next_table_index);
8232 mp->miss_next_index = ntohl (miss_next_index);
8233 mp->current_data_flag = ntohl (current_data_flag);
8234 mp->current_data_offset = ntohl (current_data_offset);
8235 mp->mask_len = ntohl (vec_len (mask));
8236 clib_memcpy (mp->mask, mask, vec_len (mask));
8245 #if VPP_API_TEST_BUILTIN == 0
8247 unformat_l4_match (unformat_input_t * input, va_list * args)
8249 u8 **matchp = va_arg (*args, u8 **);
8251 u8 *proto_header = 0;
8257 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8259 if (unformat (input, "src_port %d", &src_port))
8261 else if (unformat (input, "dst_port %d", &dst_port))
8267 h.src_port = clib_host_to_net_u16 (src_port);
8268 h.dst_port = clib_host_to_net_u16 (dst_port);
8269 vec_validate (proto_header, sizeof (h) - 1);
8270 memcpy (proto_header, &h, sizeof (h));
8272 *matchp = proto_header;
8278 unformat_ip4_match (unformat_input_t * input, va_list * args)
8280 u8 **matchp = va_arg (*args, u8 **);
8287 int src = 0, dst = 0;
8288 ip4_address_t src_val, dst_val;
8295 int fragment_id = 0;
8296 u32 fragment_id_val;
8302 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8304 if (unformat (input, "version %d", &version_val))
8306 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8308 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8310 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8312 else if (unformat (input, "proto %d", &proto_val))
8314 else if (unformat (input, "tos %d", &tos_val))
8316 else if (unformat (input, "length %d", &length_val))
8318 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8320 else if (unformat (input, "ttl %d", &ttl_val))
8322 else if (unformat (input, "checksum %d", &checksum_val))
8328 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8329 + ttl + checksum == 0)
8333 * Aligned because we use the real comparison functions
8335 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8337 ip = (ip4_header_t *) match;
8339 /* These are realistically matched in practice */
8341 ip->src_address.as_u32 = src_val.as_u32;
8344 ip->dst_address.as_u32 = dst_val.as_u32;
8347 ip->protocol = proto_val;
8350 /* These are not, but they're included for completeness */
8352 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8355 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8361 ip->length = clib_host_to_net_u16 (length_val);
8367 ip->checksum = clib_host_to_net_u16 (checksum_val);
8374 unformat_ip6_match (unformat_input_t * input, va_list * args)
8376 u8 **matchp = va_arg (*args, u8 **);
8381 u8 traffic_class = 0;
8382 u32 traffic_class_val = 0;
8385 int src = 0, dst = 0;
8386 ip6_address_t src_val, dst_val;
8389 int payload_length = 0;
8390 u32 payload_length_val;
8393 u32 ip_version_traffic_class_and_flow_label;
8395 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8397 if (unformat (input, "version %d", &version_val))
8399 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8401 else if (unformat (input, "flow_label %d", &flow_label_val))
8403 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8405 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8407 else if (unformat (input, "proto %d", &proto_val))
8409 else if (unformat (input, "payload_length %d", &payload_length_val))
8411 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8417 if (version + traffic_class + flow_label + src + dst + proto +
8418 payload_length + hop_limit == 0)
8422 * Aligned because we use the real comparison functions
8424 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8426 ip = (ip6_header_t *) match;
8429 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8432 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8435 ip->protocol = proto_val;
8437 ip_version_traffic_class_and_flow_label = 0;
8440 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8443 ip_version_traffic_class_and_flow_label |=
8444 (traffic_class_val & 0xFF) << 20;
8447 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8449 ip->ip_version_traffic_class_and_flow_label =
8450 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8453 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8456 ip->hop_limit = hop_limit_val;
8463 unformat_l3_match (unformat_input_t * input, va_list * args)
8465 u8 **matchp = va_arg (*args, u8 **);
8467 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8469 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8471 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8480 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8482 u8 *tagp = va_arg (*args, u8 *);
8485 if (unformat (input, "%d", &tag))
8487 tagp[0] = (tag >> 8) & 0x0F;
8488 tagp[1] = tag & 0xFF;
8496 unformat_l2_match (unformat_input_t * input, va_list * args)
8498 u8 **matchp = va_arg (*args, u8 **);
8518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8520 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8523 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8525 else if (unformat (input, "proto %U",
8526 unformat_ethernet_type_host_byte_order, &proto_val))
8528 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8530 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8532 else if (unformat (input, "ignore-tag1"))
8534 else if (unformat (input, "ignore-tag2"))
8536 else if (unformat (input, "cos1 %d", &cos1_val))
8538 else if (unformat (input, "cos2 %d", &cos2_val))
8543 if ((src + dst + proto + tag1 + tag2 +
8544 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8547 if (tag1 || ignore_tag1 || cos1)
8549 if (tag2 || ignore_tag2 || cos2)
8552 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8555 clib_memcpy (match, dst_val, 6);
8558 clib_memcpy (match + 6, src_val, 6);
8562 /* inner vlan tag */
8563 match[19] = tag2_val[1];
8564 match[18] = tag2_val[0];
8566 match[18] |= (cos2_val & 0x7) << 5;
8569 match[21] = proto_val & 0xff;
8570 match[20] = proto_val >> 8;
8574 match[15] = tag1_val[1];
8575 match[14] = tag1_val[0];
8578 match[14] |= (cos1_val & 0x7) << 5;
8584 match[15] = tag1_val[1];
8585 match[14] = tag1_val[0];
8588 match[17] = proto_val & 0xff;
8589 match[16] = proto_val >> 8;
8592 match[14] |= (cos1_val & 0x7) << 5;
8598 match[18] |= (cos2_val & 0x7) << 5;
8600 match[14] |= (cos1_val & 0x7) << 5;
8603 match[13] = proto_val & 0xff;
8604 match[12] = proto_val >> 8;
8612 unformat_qos_source (unformat_input_t * input, va_list * args)
8614 int *qs = va_arg (*args, int *);
8616 if (unformat (input, "ip"))
8617 *qs = QOS_SOURCE_IP;
8618 else if (unformat (input, "mpls"))
8619 *qs = QOS_SOURCE_MPLS;
8620 else if (unformat (input, "ext"))
8621 *qs = QOS_SOURCE_EXT;
8622 else if (unformat (input, "vlan"))
8623 *qs = QOS_SOURCE_VLAN;
8632 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8634 u8 **matchp = va_arg (*args, u8 **);
8635 u32 skip_n_vectors = va_arg (*args, u32);
8636 u32 match_n_vectors = va_arg (*args, u32);
8643 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8645 if (unformat (input, "hex %U", unformat_hex_string, &match))
8647 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8649 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8651 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8665 if (match || l2 || l3 || l4)
8669 /* "Win a free Ethernet header in every packet" */
8671 vec_validate_aligned (l2, 13, sizeof (u32x4));
8675 vec_append_aligned (match, l3, sizeof (u32x4));
8680 vec_append_aligned (match, l4, sizeof (u32x4));
8685 /* Make sure the vector is big enough even if key is all 0's */
8686 vec_validate_aligned
8687 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8690 /* Set size, include skipped vectors */
8691 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8702 api_classify_add_del_session (vat_main_t * vam)
8704 unformat_input_t *i = vam->input;
8705 vl_api_classify_add_del_session_t *mp;
8707 u32 table_index = ~0;
8708 u32 hit_next_index = ~0;
8709 u32 opaque_index = ~0;
8712 u32 skip_n_vectors = 0;
8713 u32 match_n_vectors = 0;
8719 * Warning: you have to supply skip_n and match_n
8720 * because the API client cant simply look at the classify
8724 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8726 if (unformat (i, "del"))
8728 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8731 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8734 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8737 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8739 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8741 else if (unformat (i, "opaque-index %d", &opaque_index))
8743 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8745 else if (unformat (i, "match_n %d", &match_n_vectors))
8747 else if (unformat (i, "match %U", api_unformat_classify_match,
8748 &match, skip_n_vectors, match_n_vectors))
8750 else if (unformat (i, "advance %d", &advance))
8752 else if (unformat (i, "table-index %d", &table_index))
8754 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8756 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8758 else if (unformat (i, "action %d", &action))
8760 else if (unformat (i, "metadata %d", &metadata))
8766 if (table_index == ~0)
8768 errmsg ("Table index required");
8772 if (is_add && match == 0)
8774 errmsg ("Match value required");
8778 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8780 mp->is_add = is_add;
8781 mp->table_index = ntohl (table_index);
8782 mp->hit_next_index = ntohl (hit_next_index);
8783 mp->opaque_index = ntohl (opaque_index);
8784 mp->advance = ntohl (advance);
8785 mp->action = action;
8786 mp->metadata = ntohl (metadata);
8787 mp->match_len = ntohl (vec_len (match));
8788 clib_memcpy (mp->match, match, vec_len (match));
8797 api_classify_set_interface_ip_table (vat_main_t * vam)
8799 unformat_input_t *i = vam->input;
8800 vl_api_classify_set_interface_ip_table_t *mp;
8802 int sw_if_index_set;
8803 u32 table_index = ~0;
8807 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8809 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8810 sw_if_index_set = 1;
8811 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8812 sw_if_index_set = 1;
8813 else if (unformat (i, "table %d", &table_index))
8817 clib_warning ("parse error '%U'", format_unformat_error, i);
8822 if (sw_if_index_set == 0)
8824 errmsg ("missing interface name or sw_if_index");
8829 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8831 mp->sw_if_index = ntohl (sw_if_index);
8832 mp->table_index = ntohl (table_index);
8833 mp->is_ipv6 = is_ipv6;
8841 api_classify_set_interface_l2_tables (vat_main_t * vam)
8843 unformat_input_t *i = vam->input;
8844 vl_api_classify_set_interface_l2_tables_t *mp;
8846 int sw_if_index_set;
8847 u32 ip4_table_index = ~0;
8848 u32 ip6_table_index = ~0;
8849 u32 other_table_index = ~0;
8853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8855 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8856 sw_if_index_set = 1;
8857 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8858 sw_if_index_set = 1;
8859 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8861 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8863 else if (unformat (i, "other-table %d", &other_table_index))
8865 else if (unformat (i, "is-input %d", &is_input))
8869 clib_warning ("parse error '%U'", format_unformat_error, i);
8874 if (sw_if_index_set == 0)
8876 errmsg ("missing interface name or sw_if_index");
8881 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8883 mp->sw_if_index = ntohl (sw_if_index);
8884 mp->ip4_table_index = ntohl (ip4_table_index);
8885 mp->ip6_table_index = ntohl (ip6_table_index);
8886 mp->other_table_index = ntohl (other_table_index);
8887 mp->is_input = (u8) is_input;
8895 api_set_ipfix_exporter (vat_main_t * vam)
8897 unformat_input_t *i = vam->input;
8898 vl_api_set_ipfix_exporter_t *mp;
8899 ip4_address_t collector_address;
8900 u8 collector_address_set = 0;
8901 u32 collector_port = ~0;
8902 ip4_address_t src_address;
8903 u8 src_address_set = 0;
8906 u32 template_interval = ~0;
8907 u8 udp_checksum = 0;
8910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8912 if (unformat (i, "collector_address %U", unformat_ip4_address,
8913 &collector_address))
8914 collector_address_set = 1;
8915 else if (unformat (i, "collector_port %d", &collector_port))
8917 else if (unformat (i, "src_address %U", unformat_ip4_address,
8919 src_address_set = 1;
8920 else if (unformat (i, "vrf_id %d", &vrf_id))
8922 else if (unformat (i, "path_mtu %d", &path_mtu))
8924 else if (unformat (i, "template_interval %d", &template_interval))
8926 else if (unformat (i, "udp_checksum"))
8932 if (collector_address_set == 0)
8934 errmsg ("collector_address required");
8938 if (src_address_set == 0)
8940 errmsg ("src_address required");
8944 M (SET_IPFIX_EXPORTER, mp);
8946 memcpy (mp->collector_address.un.ip4, collector_address.data,
8947 sizeof (collector_address.data));
8948 mp->collector_port = htons ((u16) collector_port);
8949 memcpy (mp->src_address.un.ip4, src_address.data,
8950 sizeof (src_address.data));
8951 mp->vrf_id = htonl (vrf_id);
8952 mp->path_mtu = htonl (path_mtu);
8953 mp->template_interval = htonl (template_interval);
8954 mp->udp_checksum = udp_checksum;
8962 api_set_ipfix_classify_stream (vat_main_t * vam)
8964 unformat_input_t *i = vam->input;
8965 vl_api_set_ipfix_classify_stream_t *mp;
8967 u32 src_port = UDP_DST_PORT_ipfix;
8970 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8972 if (unformat (i, "domain %d", &domain_id))
8974 else if (unformat (i, "src_port %d", &src_port))
8978 errmsg ("unknown input `%U'", format_unformat_error, i);
8983 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8985 mp->domain_id = htonl (domain_id);
8986 mp->src_port = htons ((u16) src_port);
8994 api_ipfix_classify_table_add_del (vat_main_t * vam)
8996 unformat_input_t *i = vam->input;
8997 vl_api_ipfix_classify_table_add_del_t *mp;
8999 u32 classify_table_index = ~0;
9001 u8 transport_protocol = 255;
9004 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9006 if (unformat (i, "add"))
9008 else if (unformat (i, "del"))
9010 else if (unformat (i, "table %d", &classify_table_index))
9012 else if (unformat (i, "ip4"))
9014 else if (unformat (i, "ip6"))
9016 else if (unformat (i, "tcp"))
9017 transport_protocol = 6;
9018 else if (unformat (i, "udp"))
9019 transport_protocol = 17;
9022 errmsg ("unknown input `%U'", format_unformat_error, i);
9029 errmsg ("expecting: add|del");
9032 if (classify_table_index == ~0)
9034 errmsg ("classifier table not specified");
9037 if (ip_version == 0)
9039 errmsg ("IP version not specified");
9043 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9045 mp->is_add = is_add;
9046 mp->table_id = htonl (classify_table_index);
9047 mp->ip_version = ip_version;
9048 mp->transport_protocol = transport_protocol;
9056 api_get_node_index (vat_main_t * vam)
9058 unformat_input_t *i = vam->input;
9059 vl_api_get_node_index_t *mp;
9063 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9065 if (unformat (i, "node %s", &name))
9072 errmsg ("node name required");
9075 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9077 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9081 M (GET_NODE_INDEX, mp);
9082 clib_memcpy (mp->node_name, name, vec_len (name));
9091 api_get_next_index (vat_main_t * vam)
9093 unformat_input_t *i = vam->input;
9094 vl_api_get_next_index_t *mp;
9095 u8 *node_name = 0, *next_node_name = 0;
9098 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9100 if (unformat (i, "node-name %s", &node_name))
9102 else if (unformat (i, "next-node-name %s", &next_node_name))
9108 errmsg ("node name required");
9111 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9113 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9117 if (next_node_name == 0)
9119 errmsg ("next node name required");
9122 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9124 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9128 M (GET_NEXT_INDEX, mp);
9129 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9130 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9131 vec_free (node_name);
9132 vec_free (next_node_name);
9140 api_add_node_next (vat_main_t * vam)
9142 unformat_input_t *i = vam->input;
9143 vl_api_add_node_next_t *mp;
9148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9150 if (unformat (i, "node %s", &name))
9152 else if (unformat (i, "next %s", &next))
9159 errmsg ("node name required");
9162 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9164 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9169 errmsg ("next node required");
9172 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9174 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9178 M (ADD_NODE_NEXT, mp);
9179 clib_memcpy (mp->node_name, name, vec_len (name));
9180 clib_memcpy (mp->next_name, next, vec_len (next));
9189 static void vl_api_sw_interface_tap_v2_details_t_handler
9190 (vl_api_sw_interface_tap_v2_details_t * mp)
9192 vat_main_t *vam = &vat_main;
9195 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9196 mp->host_ip4_prefix.len);
9198 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9199 mp->host_ip6_prefix.len);
9202 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9203 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9204 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9205 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9206 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9212 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9213 (vl_api_sw_interface_tap_v2_details_t * mp)
9215 vat_main_t *vam = &vat_main;
9216 vat_json_node_t *node = NULL;
9218 if (VAT_JSON_ARRAY != vam->json_tree.type)
9220 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9221 vat_json_init_array (&vam->json_tree);
9223 node = vat_json_array_add (&vam->json_tree);
9225 vat_json_init_object (node);
9226 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9227 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9228 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9229 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9230 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9231 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9232 vat_json_object_add_string_copy (node, "host_mac_addr",
9233 format (0, "%U", format_ethernet_address,
9234 &mp->host_mac_addr));
9235 vat_json_object_add_string_copy (node, "host_namespace",
9236 mp->host_namespace);
9237 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9238 vat_json_object_add_string_copy (node, "host_ip4_addr",
9239 format (0, "%U/%d", format_ip4_address,
9240 mp->host_ip4_prefix.address,
9241 mp->host_ip4_prefix.len));
9242 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9243 format (0, "%U/%d", format_ip6_address,
9244 mp->host_ip6_prefix.address,
9245 mp->host_ip6_prefix.len));
9250 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9252 vl_api_sw_interface_tap_v2_dump_t *mp;
9253 vl_api_control_ping_t *mp_ping;
9257 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9258 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9259 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9262 /* Get list of tap interfaces */
9263 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9266 /* Use a control ping for synchronization */
9267 MPING (CONTROL_PING, mp_ping);
9274 static void vl_api_sw_interface_virtio_pci_details_t_handler
9275 (vl_api_sw_interface_virtio_pci_details_t * mp)
9277 vat_main_t *vam = &vat_main;
9292 addr.domain = ntohs (mp->pci_addr.domain);
9293 addr.bus = mp->pci_addr.bus;
9294 addr.slot = mp->pci_addr.slot;
9295 addr.function = mp->pci_addr.function;
9297 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9298 addr.slot, addr.function);
9301 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9302 pci_addr, ntohl (mp->sw_if_index),
9303 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9304 format_ethernet_address, mp->mac_addr,
9305 clib_net_to_host_u64 (mp->features));
9306 vec_free (pci_addr);
9309 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9310 (vl_api_sw_interface_virtio_pci_details_t * mp)
9312 vat_main_t *vam = &vat_main;
9313 vat_json_node_t *node = NULL;
9314 vlib_pci_addr_t pci_addr;
9316 if (VAT_JSON_ARRAY != vam->json_tree.type)
9318 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9319 vat_json_init_array (&vam->json_tree);
9321 node = vat_json_array_add (&vam->json_tree);
9323 pci_addr.domain = ntohs (mp->pci_addr.domain);
9324 pci_addr.bus = mp->pci_addr.bus;
9325 pci_addr.slot = mp->pci_addr.slot;
9326 pci_addr.function = mp->pci_addr.function;
9328 vat_json_init_object (node);
9329 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9330 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9331 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9332 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9333 vat_json_object_add_uint (node, "features",
9334 clib_net_to_host_u64 (mp->features));
9335 vat_json_object_add_string_copy (node, "mac_addr",
9336 format (0, "%U", format_ethernet_address,
9341 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9343 vl_api_sw_interface_virtio_pci_dump_t *mp;
9344 vl_api_control_ping_t *mp_ping;
9348 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9349 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9350 "mac_addr", "features");
9352 /* Get list of tap interfaces */
9353 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9356 /* Use a control ping for synchronization */
9357 MPING (CONTROL_PING, mp_ping);
9365 api_vxlan_offload_rx (vat_main_t * vam)
9367 unformat_input_t *line_input = vam->input;
9368 vl_api_vxlan_offload_rx_t *mp;
9369 u32 hw_if_index = ~0, rx_if_index = ~0;
9373 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9375 if (unformat (line_input, "del"))
9377 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9380 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9382 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9385 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9389 errmsg ("parse error '%U'", format_unformat_error, line_input);
9394 if (hw_if_index == ~0)
9396 errmsg ("no hw interface");
9400 if (rx_if_index == ~0)
9402 errmsg ("no rx tunnel");
9406 M (VXLAN_OFFLOAD_RX, mp);
9408 mp->hw_if_index = ntohl (hw_if_index);
9409 mp->sw_if_index = ntohl (rx_if_index);
9410 mp->enable = is_add;
9417 static uword unformat_vxlan_decap_next
9418 (unformat_input_t * input, va_list * args)
9420 u32 *result = va_arg (*args, u32 *);
9423 if (unformat (input, "l2"))
9424 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9425 else if (unformat (input, "%d", &tmp))
9433 api_vxlan_add_del_tunnel (vat_main_t * vam)
9435 unformat_input_t *line_input = vam->input;
9436 vl_api_vxlan_add_del_tunnel_t *mp;
9437 ip46_address_t src, dst;
9439 u8 ipv4_set = 0, ipv6_set = 0;
9444 u32 mcast_sw_if_index = ~0;
9445 u32 encap_vrf_id = 0;
9446 u32 decap_next_index = ~0;
9450 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9451 clib_memset (&src, 0, sizeof src);
9452 clib_memset (&dst, 0, sizeof dst);
9454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9456 if (unformat (line_input, "del"))
9458 else if (unformat (line_input, "instance %d", &instance))
9461 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9467 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9473 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9479 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9484 else if (unformat (line_input, "group %U %U",
9485 unformat_ip4_address, &dst.ip4,
9486 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9488 grp_set = dst_set = 1;
9491 else if (unformat (line_input, "group %U",
9492 unformat_ip4_address, &dst.ip4))
9494 grp_set = dst_set = 1;
9497 else if (unformat (line_input, "group %U %U",
9498 unformat_ip6_address, &dst.ip6,
9499 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9501 grp_set = dst_set = 1;
9504 else if (unformat (line_input, "group %U",
9505 unformat_ip6_address, &dst.ip6))
9507 grp_set = dst_set = 1;
9511 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9513 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9515 else if (unformat (line_input, "decap-next %U",
9516 unformat_vxlan_decap_next, &decap_next_index))
9518 else if (unformat (line_input, "vni %d", &vni))
9522 errmsg ("parse error '%U'", format_unformat_error, line_input);
9529 errmsg ("tunnel src address not specified");
9534 errmsg ("tunnel dst address not specified");
9538 if (grp_set && !ip46_address_is_multicast (&dst))
9540 errmsg ("tunnel group address not multicast");
9543 if (grp_set && mcast_sw_if_index == ~0)
9545 errmsg ("tunnel nonexistent multicast device");
9548 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9550 errmsg ("tunnel dst address must be unicast");
9555 if (ipv4_set && ipv6_set)
9557 errmsg ("both IPv4 and IPv6 addresses specified");
9561 if ((vni == 0) || (vni >> 24))
9563 errmsg ("vni not specified or out of range");
9567 M (VXLAN_ADD_DEL_TUNNEL, mp);
9571 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9572 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9576 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9577 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9579 mp->src_address.af = ipv6_set;
9580 mp->dst_address.af = ipv6_set;
9582 mp->instance = htonl (instance);
9583 mp->encap_vrf_id = ntohl (encap_vrf_id);
9584 mp->decap_next_index = ntohl (decap_next_index);
9585 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9586 mp->vni = ntohl (vni);
9587 mp->is_add = is_add;
9594 static void vl_api_vxlan_tunnel_details_t_handler
9595 (vl_api_vxlan_tunnel_details_t * mp)
9597 vat_main_t *vam = &vat_main;
9598 ip46_address_t src =
9599 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9600 ip46_address_t dst =
9601 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9603 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9604 ntohl (mp->sw_if_index),
9605 ntohl (mp->instance),
9606 format_ip46_address, &src, IP46_TYPE_ANY,
9607 format_ip46_address, &dst, IP46_TYPE_ANY,
9608 ntohl (mp->encap_vrf_id),
9609 ntohl (mp->decap_next_index), ntohl (mp->vni),
9610 ntohl (mp->mcast_sw_if_index));
9613 static void vl_api_vxlan_tunnel_details_t_handler_json
9614 (vl_api_vxlan_tunnel_details_t * mp)
9616 vat_main_t *vam = &vat_main;
9617 vat_json_node_t *node = NULL;
9619 if (VAT_JSON_ARRAY != vam->json_tree.type)
9621 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9622 vat_json_init_array (&vam->json_tree);
9624 node = vat_json_array_add (&vam->json_tree);
9626 vat_json_init_object (node);
9627 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9629 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9631 if (mp->src_address.af)
9633 struct in6_addr ip6;
9635 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9636 vat_json_object_add_ip6 (node, "src_address", ip6);
9637 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9638 vat_json_object_add_ip6 (node, "dst_address", ip6);
9644 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9645 vat_json_object_add_ip4 (node, "src_address", ip4);
9646 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9647 vat_json_object_add_ip4 (node, "dst_address", ip4);
9649 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9650 vat_json_object_add_uint (node, "decap_next_index",
9651 ntohl (mp->decap_next_index));
9652 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9653 vat_json_object_add_uint (node, "mcast_sw_if_index",
9654 ntohl (mp->mcast_sw_if_index));
9658 api_vxlan_tunnel_dump (vat_main_t * vam)
9660 unformat_input_t *i = vam->input;
9661 vl_api_vxlan_tunnel_dump_t *mp;
9662 vl_api_control_ping_t *mp_ping;
9664 u8 sw_if_index_set = 0;
9667 /* Parse args required to build the message */
9668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9670 if (unformat (i, "sw_if_index %d", &sw_if_index))
9671 sw_if_index_set = 1;
9676 if (sw_if_index_set == 0)
9681 if (!vam->json_output)
9683 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9684 "sw_if_index", "instance", "src_address", "dst_address",
9685 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9688 /* Get list of vxlan-tunnel interfaces */
9689 M (VXLAN_TUNNEL_DUMP, mp);
9691 mp->sw_if_index = htonl (sw_if_index);
9695 /* Use a control ping for synchronization */
9696 MPING (CONTROL_PING, mp_ping);
9704 api_l2_fib_clear_table (vat_main_t * vam)
9706 // unformat_input_t * i = vam->input;
9707 vl_api_l2_fib_clear_table_t *mp;
9710 M (L2_FIB_CLEAR_TABLE, mp);
9718 api_l2_interface_efp_filter (vat_main_t * vam)
9720 unformat_input_t *i = vam->input;
9721 vl_api_l2_interface_efp_filter_t *mp;
9724 u8 sw_if_index_set = 0;
9727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9729 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9730 sw_if_index_set = 1;
9731 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9732 sw_if_index_set = 1;
9733 else if (unformat (i, "enable"))
9735 else if (unformat (i, "disable"))
9739 clib_warning ("parse error '%U'", format_unformat_error, i);
9744 if (sw_if_index_set == 0)
9746 errmsg ("missing sw_if_index");
9750 M (L2_INTERFACE_EFP_FILTER, mp);
9752 mp->sw_if_index = ntohl (sw_if_index);
9753 mp->enable_disable = enable;
9760 #define foreach_vtr_op \
9761 _("disable", L2_VTR_DISABLED) \
9762 _("push-1", L2_VTR_PUSH_1) \
9763 _("push-2", L2_VTR_PUSH_2) \
9764 _("pop-1", L2_VTR_POP_1) \
9765 _("pop-2", L2_VTR_POP_2) \
9766 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9767 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9768 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9769 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9772 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9774 unformat_input_t *i = vam->input;
9775 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9777 u8 sw_if_index_set = 0;
9785 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9787 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9788 sw_if_index_set = 1;
9789 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9790 sw_if_index_set = 1;
9791 else if (unformat (i, "vtr_op %d", &vtr_op))
9793 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9796 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9798 else if (unformat (i, "tag1 %d", &tag1))
9800 else if (unformat (i, "tag2 %d", &tag2))
9804 clib_warning ("parse error '%U'", format_unformat_error, i);
9809 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9811 errmsg ("missing vtr operation or sw_if_index");
9815 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9816 mp->sw_if_index = ntohl (sw_if_index);
9817 mp->vtr_op = ntohl (vtr_op);
9818 mp->push_dot1q = ntohl (push_dot1q);
9819 mp->tag1 = ntohl (tag1);
9820 mp->tag2 = ntohl (tag2);
9828 api_create_vhost_user_if (vat_main_t * vam)
9830 unformat_input_t *i = vam->input;
9831 vl_api_create_vhost_user_if_t *mp;
9834 u8 file_name_set = 0;
9835 u32 custom_dev_instance = ~0;
9837 u8 use_custom_mac = 0;
9838 u8 disable_mrg_rxbuf = 0;
9839 u8 disable_indirect_desc = 0;
9842 u8 enable_packed = 0;
9845 /* Shut up coverity */
9846 clib_memset (hwaddr, 0, sizeof (hwaddr));
9848 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9850 if (unformat (i, "socket %s", &file_name))
9854 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9856 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9858 else if (unformat (i, "server"))
9860 else if (unformat (i, "disable_mrg_rxbuf"))
9861 disable_mrg_rxbuf = 1;
9862 else if (unformat (i, "disable_indirect_desc"))
9863 disable_indirect_desc = 1;
9864 else if (unformat (i, "gso"))
9866 else if (unformat (i, "packed"))
9868 else if (unformat (i, "tag %s", &tag))
9874 if (file_name_set == 0)
9876 errmsg ("missing socket file name");
9880 if (vec_len (file_name) > 255)
9882 errmsg ("socket file name too long");
9885 vec_add1 (file_name, 0);
9887 M (CREATE_VHOST_USER_IF, mp);
9889 mp->is_server = is_server;
9890 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9891 mp->disable_indirect_desc = disable_indirect_desc;
9892 mp->enable_gso = enable_gso;
9893 mp->enable_packed = enable_packed;
9894 mp->custom_dev_instance = ntohl (custom_dev_instance);
9895 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9896 vec_free (file_name);
9897 if (custom_dev_instance != ~0)
9900 mp->use_custom_mac = use_custom_mac;
9901 clib_memcpy (mp->mac_address, hwaddr, 6);
9903 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9912 api_modify_vhost_user_if (vat_main_t * vam)
9914 unformat_input_t *i = vam->input;
9915 vl_api_modify_vhost_user_if_t *mp;
9918 u8 file_name_set = 0;
9919 u32 custom_dev_instance = ~0;
9920 u8 sw_if_index_set = 0;
9921 u32 sw_if_index = (u32) ~ 0;
9923 u8 enable_packed = 0;
9926 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9928 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9929 sw_if_index_set = 1;
9930 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9931 sw_if_index_set = 1;
9932 else if (unformat (i, "socket %s", &file_name))
9936 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9938 else if (unformat (i, "server"))
9940 else if (unformat (i, "gso"))
9942 else if (unformat (i, "packed"))
9948 if (sw_if_index_set == 0)
9950 errmsg ("missing sw_if_index or interface name");
9954 if (file_name_set == 0)
9956 errmsg ("missing socket file name");
9960 if (vec_len (file_name) > 255)
9962 errmsg ("socket file name too long");
9965 vec_add1 (file_name, 0);
9967 M (MODIFY_VHOST_USER_IF, mp);
9969 mp->sw_if_index = ntohl (sw_if_index);
9970 mp->is_server = is_server;
9971 mp->enable_gso = enable_gso;
9972 mp->enable_packed = enable_packed;
9973 mp->custom_dev_instance = ntohl (custom_dev_instance);
9974 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9975 vec_free (file_name);
9976 if (custom_dev_instance != ~0)
9985 api_create_vhost_user_if_v2 (vat_main_t * vam)
9987 unformat_input_t *i = vam->input;
9988 vl_api_create_vhost_user_if_v2_t *mp;
9991 u8 file_name_set = 0;
9992 u32 custom_dev_instance = ~0;
9994 u8 use_custom_mac = 0;
9995 u8 disable_mrg_rxbuf = 0;
9996 u8 disable_indirect_desc = 0;
9999 u8 enable_packed = 0;
10000 u8 enable_event_idx = 0;
10003 /* Shut up coverity */
10004 clib_memset (hwaddr, 0, sizeof (hwaddr));
10006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10008 if (unformat (i, "socket %s", &file_name))
10012 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10014 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
10015 use_custom_mac = 1;
10016 else if (unformat (i, "server"))
10018 else if (unformat (i, "disable_mrg_rxbuf"))
10019 disable_mrg_rxbuf = 1;
10020 else if (unformat (i, "disable_indirect_desc"))
10021 disable_indirect_desc = 1;
10022 else if (unformat (i, "gso"))
10024 else if (unformat (i, "packed"))
10026 else if (unformat (i, "event-idx"))
10027 enable_event_idx = 1;
10028 else if (unformat (i, "tag %s", &tag))
10034 if (file_name_set == 0)
10036 errmsg ("missing socket file name");
10040 if (vec_len (file_name) > 255)
10042 errmsg ("socket file name too long");
10045 vec_add1 (file_name, 0);
10047 M (CREATE_VHOST_USER_IF_V2, mp);
10049 mp->is_server = is_server;
10050 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
10051 mp->disable_indirect_desc = disable_indirect_desc;
10052 mp->enable_gso = enable_gso;
10053 mp->enable_packed = enable_packed;
10054 mp->enable_event_idx = enable_event_idx;
10055 mp->custom_dev_instance = ntohl (custom_dev_instance);
10056 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10057 vec_free (file_name);
10058 if (custom_dev_instance != ~0)
10061 mp->use_custom_mac = use_custom_mac;
10062 clib_memcpy (mp->mac_address, hwaddr, 6);
10064 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10073 api_modify_vhost_user_if_v2 (vat_main_t * vam)
10075 unformat_input_t *i = vam->input;
10076 vl_api_modify_vhost_user_if_v2_t *mp;
10079 u8 file_name_set = 0;
10080 u32 custom_dev_instance = ~0;
10081 u8 sw_if_index_set = 0;
10082 u32 sw_if_index = (u32) ~ 0;
10084 u8 enable_packed = 0;
10085 u8 enable_event_idx = 0;
10088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10090 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10091 sw_if_index_set = 1;
10092 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10093 sw_if_index_set = 1;
10094 else if (unformat (i, "socket %s", &file_name))
10098 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10100 else if (unformat (i, "server"))
10102 else if (unformat (i, "gso"))
10104 else if (unformat (i, "packed"))
10106 else if (unformat (i, "event-idx"))
10107 enable_event_idx = 1;
10112 if (sw_if_index_set == 0)
10114 errmsg ("missing sw_if_index or interface name");
10118 if (file_name_set == 0)
10120 errmsg ("missing socket file name");
10124 if (vec_len (file_name) > 255)
10126 errmsg ("socket file name too long");
10129 vec_add1 (file_name, 0);
10131 M (MODIFY_VHOST_USER_IF_V2, mp);
10133 mp->sw_if_index = ntohl (sw_if_index);
10134 mp->is_server = is_server;
10135 mp->enable_gso = enable_gso;
10136 mp->enable_packed = enable_packed;
10137 mp->enable_event_idx = enable_event_idx;
10138 mp->custom_dev_instance = ntohl (custom_dev_instance);
10139 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10140 vec_free (file_name);
10141 if (custom_dev_instance != ~0)
10150 api_delete_vhost_user_if (vat_main_t * vam)
10152 unformat_input_t *i = vam->input;
10153 vl_api_delete_vhost_user_if_t *mp;
10154 u32 sw_if_index = ~0;
10155 u8 sw_if_index_set = 0;
10158 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10160 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10161 sw_if_index_set = 1;
10162 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10163 sw_if_index_set = 1;
10168 if (sw_if_index_set == 0)
10170 errmsg ("missing sw_if_index or interface name");
10175 M (DELETE_VHOST_USER_IF, mp);
10177 mp->sw_if_index = ntohl (sw_if_index);
10184 static void vl_api_sw_interface_vhost_user_details_t_handler
10185 (vl_api_sw_interface_vhost_user_details_t * mp)
10187 vat_main_t *vam = &vat_main;
10191 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10192 clib_net_to_host_u32
10193 (mp->features_last_32) <<
10196 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
10197 (char *) mp->interface_name, ntohl (mp->sw_if_index),
10198 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
10199 ntohl (mp->num_regions), (char *) mp->sock_filename);
10200 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10203 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10204 (vl_api_sw_interface_vhost_user_details_t * mp)
10206 vat_main_t *vam = &vat_main;
10207 vat_json_node_t *node = NULL;
10209 if (VAT_JSON_ARRAY != vam->json_tree.type)
10211 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10212 vat_json_init_array (&vam->json_tree);
10214 node = vat_json_array_add (&vam->json_tree);
10216 vat_json_init_object (node);
10217 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10218 vat_json_object_add_string_copy (node, "interface_name",
10219 mp->interface_name);
10220 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10221 ntohl (mp->virtio_net_hdr_sz));
10222 vat_json_object_add_uint (node, "features_first_32",
10223 clib_net_to_host_u32 (mp->features_first_32));
10224 vat_json_object_add_uint (node, "features_last_32",
10225 clib_net_to_host_u32 (mp->features_last_32));
10226 vat_json_object_add_uint (node, "is_server", mp->is_server);
10227 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10228 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10229 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10233 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10235 unformat_input_t *i = vam->input;
10236 vl_api_sw_interface_vhost_user_dump_t *mp;
10237 vl_api_control_ping_t *mp_ping;
10239 u32 sw_if_index = ~0;
10241 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10243 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10245 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10251 print (vam->ofp, "Interface name idx hdr_sz features "
10252 "server regions filename");
10254 /* Get list of vhost-user interfaces */
10255 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10256 mp->sw_if_index = ntohl (sw_if_index);
10259 /* Use a control ping for synchronization */
10260 MPING (CONTROL_PING, mp_ping);
10268 api_show_version (vat_main_t * vam)
10270 vl_api_show_version_t *mp;
10273 M (SHOW_VERSION, mp);
10282 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10284 unformat_input_t *line_input = vam->input;
10285 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10286 ip46_address_t local, remote;
10291 u32 mcast_sw_if_index = ~0;
10292 u32 encap_vrf_id = 0;
10293 u32 decap_vrf_id = 0;
10299 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10301 if (unformat (line_input, "del"))
10303 else if (unformat (line_input, "local %U",
10304 unformat_ip46_address, &local))
10308 else if (unformat (line_input, "remote %U",
10309 unformat_ip46_address, &remote))
10313 else if (unformat (line_input, "group %U %U",
10314 unformat_ip46_address, &remote,
10315 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10317 grp_set = remote_set = 1;
10319 else if (unformat (line_input, "group %U",
10320 unformat_ip46_address, &remote))
10322 grp_set = remote_set = 1;
10325 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10327 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10329 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10331 else if (unformat (line_input, "vni %d", &vni))
10333 else if (unformat (line_input, "next-ip4"))
10335 else if (unformat (line_input, "next-ip6"))
10337 else if (unformat (line_input, "next-ethernet"))
10339 else if (unformat (line_input, "next-nsh"))
10343 errmsg ("parse error '%U'", format_unformat_error, line_input);
10348 if (local_set == 0)
10350 errmsg ("tunnel local address not specified");
10353 if (remote_set == 0)
10355 errmsg ("tunnel remote address not specified");
10358 if (grp_set && mcast_sw_if_index == ~0)
10360 errmsg ("tunnel nonexistent multicast device");
10363 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10365 errmsg ("both IPv4 and IPv6 addresses specified");
10371 errmsg ("vni not specified");
10375 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10377 ip_address_encode (&local,
10378 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10379 IP46_TYPE_IP6, &mp->local);
10380 ip_address_encode (&remote,
10381 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10382 IP46_TYPE_IP6, &mp->remote);
10384 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10385 mp->encap_vrf_id = ntohl (encap_vrf_id);
10386 mp->decap_vrf_id = ntohl (decap_vrf_id);
10387 mp->protocol = protocol;
10388 mp->vni = ntohl (vni);
10389 mp->is_add = is_add;
10396 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10397 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10399 vat_main_t *vam = &vat_main;
10400 ip46_address_t local, remote;
10402 ip_address_decode (&mp->local, &local);
10403 ip_address_decode (&mp->remote, &remote);
10405 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10406 ntohl (mp->sw_if_index),
10407 format_ip46_address, &local, IP46_TYPE_ANY,
10408 format_ip46_address, &remote, IP46_TYPE_ANY,
10409 ntohl (mp->vni), mp->protocol,
10410 ntohl (mp->mcast_sw_if_index),
10411 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10415 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10416 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10418 vat_main_t *vam = &vat_main;
10419 vat_json_node_t *node = NULL;
10420 struct in_addr ip4;
10421 struct in6_addr ip6;
10422 ip46_address_t local, remote;
10424 ip_address_decode (&mp->local, &local);
10425 ip_address_decode (&mp->remote, &remote);
10427 if (VAT_JSON_ARRAY != vam->json_tree.type)
10429 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10430 vat_json_init_array (&vam->json_tree);
10432 node = vat_json_array_add (&vam->json_tree);
10434 vat_json_init_object (node);
10435 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10436 if (ip46_address_is_ip4 (&local))
10438 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10439 vat_json_object_add_ip4 (node, "local", ip4);
10440 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10441 vat_json_object_add_ip4 (node, "remote", ip4);
10445 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10446 vat_json_object_add_ip6 (node, "local", ip6);
10447 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10448 vat_json_object_add_ip6 (node, "remote", ip6);
10450 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10451 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10452 vat_json_object_add_uint (node, "mcast_sw_if_index",
10453 ntohl (mp->mcast_sw_if_index));
10454 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10455 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10456 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10460 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10462 unformat_input_t *i = vam->input;
10463 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10464 vl_api_control_ping_t *mp_ping;
10466 u8 sw_if_index_set = 0;
10469 /* Parse args required to build the message */
10470 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10472 if (unformat (i, "sw_if_index %d", &sw_if_index))
10473 sw_if_index_set = 1;
10478 if (sw_if_index_set == 0)
10483 if (!vam->json_output)
10485 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10486 "sw_if_index", "local", "remote", "vni",
10487 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10490 /* Get list of vxlan-tunnel interfaces */
10491 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10493 mp->sw_if_index = htonl (sw_if_index);
10497 /* Use a control ping for synchronization */
10498 MPING (CONTROL_PING, mp_ping);
10505 static void vl_api_l2_fib_table_details_t_handler
10506 (vl_api_l2_fib_table_details_t * mp)
10508 vat_main_t *vam = &vat_main;
10510 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10512 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10513 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10517 static void vl_api_l2_fib_table_details_t_handler_json
10518 (vl_api_l2_fib_table_details_t * mp)
10520 vat_main_t *vam = &vat_main;
10521 vat_json_node_t *node = NULL;
10523 if (VAT_JSON_ARRAY != vam->json_tree.type)
10525 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10526 vat_json_init_array (&vam->json_tree);
10528 node = vat_json_array_add (&vam->json_tree);
10530 vat_json_init_object (node);
10531 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10532 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10533 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10534 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10535 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10536 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10540 api_l2_fib_table_dump (vat_main_t * vam)
10542 unformat_input_t *i = vam->input;
10543 vl_api_l2_fib_table_dump_t *mp;
10544 vl_api_control_ping_t *mp_ping;
10549 /* Parse args required to build the message */
10550 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10552 if (unformat (i, "bd_id %d", &bd_id))
10558 if (bd_id_set == 0)
10560 errmsg ("missing bridge domain");
10564 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10566 /* Get list of l2 fib entries */
10567 M (L2_FIB_TABLE_DUMP, mp);
10569 mp->bd_id = ntohl (bd_id);
10572 /* Use a control ping for synchronization */
10573 MPING (CONTROL_PING, mp_ping);
10582 api_interface_name_renumber (vat_main_t * vam)
10584 unformat_input_t *line_input = vam->input;
10585 vl_api_interface_name_renumber_t *mp;
10586 u32 sw_if_index = ~0;
10587 u32 new_show_dev_instance = ~0;
10590 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10592 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10595 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10597 else if (unformat (line_input, "new_show_dev_instance %d",
10598 &new_show_dev_instance))
10604 if (sw_if_index == ~0)
10606 errmsg ("missing interface name or sw_if_index");
10610 if (new_show_dev_instance == ~0)
10612 errmsg ("missing new_show_dev_instance");
10616 M (INTERFACE_NAME_RENUMBER, mp);
10618 mp->sw_if_index = ntohl (sw_if_index);
10619 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10627 api_want_l2_macs_events (vat_main_t * vam)
10629 unformat_input_t *line_input = vam->input;
10630 vl_api_want_l2_macs_events_t *mp;
10631 u8 enable_disable = 1;
10632 u32 scan_delay = 0;
10633 u32 max_macs_in_event = 0;
10634 u32 learn_limit = 0;
10637 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10639 if (unformat (line_input, "learn-limit %d", &learn_limit))
10641 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10643 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10645 else if (unformat (line_input, "disable"))
10646 enable_disable = 0;
10651 M (WANT_L2_MACS_EVENTS, mp);
10652 mp->enable_disable = enable_disable;
10653 mp->pid = htonl (getpid ());
10654 mp->learn_limit = htonl (learn_limit);
10655 mp->scan_delay = (u8) scan_delay;
10656 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10663 api_input_acl_set_interface (vat_main_t * vam)
10665 unformat_input_t *i = vam->input;
10666 vl_api_input_acl_set_interface_t *mp;
10668 int sw_if_index_set;
10669 u32 ip4_table_index = ~0;
10670 u32 ip6_table_index = ~0;
10671 u32 l2_table_index = ~0;
10675 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10677 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10678 sw_if_index_set = 1;
10679 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10680 sw_if_index_set = 1;
10681 else if (unformat (i, "del"))
10683 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10685 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10687 else if (unformat (i, "l2-table %d", &l2_table_index))
10691 clib_warning ("parse error '%U'", format_unformat_error, i);
10696 if (sw_if_index_set == 0)
10698 errmsg ("missing interface name or sw_if_index");
10702 M (INPUT_ACL_SET_INTERFACE, mp);
10704 mp->sw_if_index = ntohl (sw_if_index);
10705 mp->ip4_table_index = ntohl (ip4_table_index);
10706 mp->ip6_table_index = ntohl (ip6_table_index);
10707 mp->l2_table_index = ntohl (l2_table_index);
10708 mp->is_add = is_add;
10716 api_output_acl_set_interface (vat_main_t * vam)
10718 unformat_input_t *i = vam->input;
10719 vl_api_output_acl_set_interface_t *mp;
10721 int sw_if_index_set;
10722 u32 ip4_table_index = ~0;
10723 u32 ip6_table_index = ~0;
10724 u32 l2_table_index = ~0;
10728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10730 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10731 sw_if_index_set = 1;
10732 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10733 sw_if_index_set = 1;
10734 else if (unformat (i, "del"))
10736 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10738 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10740 else if (unformat (i, "l2-table %d", &l2_table_index))
10744 clib_warning ("parse error '%U'", format_unformat_error, i);
10749 if (sw_if_index_set == 0)
10751 errmsg ("missing interface name or sw_if_index");
10755 M (OUTPUT_ACL_SET_INTERFACE, mp);
10757 mp->sw_if_index = ntohl (sw_if_index);
10758 mp->ip4_table_index = ntohl (ip4_table_index);
10759 mp->ip6_table_index = ntohl (ip6_table_index);
10760 mp->l2_table_index = ntohl (l2_table_index);
10761 mp->is_add = is_add;
10769 api_ip_address_dump (vat_main_t * vam)
10771 unformat_input_t *i = vam->input;
10772 vl_api_ip_address_dump_t *mp;
10773 vl_api_control_ping_t *mp_ping;
10774 u32 sw_if_index = ~0;
10775 u8 sw_if_index_set = 0;
10780 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10782 if (unformat (i, "sw_if_index %d", &sw_if_index))
10783 sw_if_index_set = 1;
10785 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10786 sw_if_index_set = 1;
10787 else if (unformat (i, "ipv4"))
10789 else if (unformat (i, "ipv6"))
10795 if (ipv4_set && ipv6_set)
10797 errmsg ("ipv4 and ipv6 flags cannot be both set");
10801 if ((!ipv4_set) && (!ipv6_set))
10803 errmsg ("no ipv4 nor ipv6 flag set");
10807 if (sw_if_index_set == 0)
10809 errmsg ("missing interface name or sw_if_index");
10813 vam->current_sw_if_index = sw_if_index;
10814 vam->is_ipv6 = ipv6_set;
10816 M (IP_ADDRESS_DUMP, mp);
10817 mp->sw_if_index = ntohl (sw_if_index);
10818 mp->is_ipv6 = ipv6_set;
10821 /* Use a control ping for synchronization */
10822 MPING (CONTROL_PING, mp_ping);
10830 api_ip_dump (vat_main_t * vam)
10832 vl_api_ip_dump_t *mp;
10833 vl_api_control_ping_t *mp_ping;
10834 unformat_input_t *in = vam->input;
10841 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10843 if (unformat (in, "ipv4"))
10845 else if (unformat (in, "ipv6"))
10851 if (ipv4_set && ipv6_set)
10853 errmsg ("ipv4 and ipv6 flags cannot be both set");
10857 if ((!ipv4_set) && (!ipv6_set))
10859 errmsg ("no ipv4 nor ipv6 flag set");
10863 is_ipv6 = ipv6_set;
10864 vam->is_ipv6 = is_ipv6;
10866 /* free old data */
10867 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10869 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10871 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10874 mp->is_ipv6 = ipv6_set;
10877 /* Use a control ping for synchronization */
10878 MPING (CONTROL_PING, mp_ping);
10886 api_ipsec_spd_add_del (vat_main_t * vam)
10888 unformat_input_t *i = vam->input;
10889 vl_api_ipsec_spd_add_del_t *mp;
10894 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10896 if (unformat (i, "spd_id %d", &spd_id))
10898 else if (unformat (i, "del"))
10902 clib_warning ("parse error '%U'", format_unformat_error, i);
10908 errmsg ("spd_id must be set");
10912 M (IPSEC_SPD_ADD_DEL, mp);
10914 mp->spd_id = ntohl (spd_id);
10915 mp->is_add = is_add;
10923 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10925 unformat_input_t *i = vam->input;
10926 vl_api_ipsec_interface_add_del_spd_t *mp;
10928 u8 sw_if_index_set = 0;
10929 u32 spd_id = (u32) ~ 0;
10933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10935 if (unformat (i, "del"))
10937 else if (unformat (i, "spd_id %d", &spd_id))
10940 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10941 sw_if_index_set = 1;
10942 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10943 sw_if_index_set = 1;
10946 clib_warning ("parse error '%U'", format_unformat_error, i);
10952 if (spd_id == (u32) ~ 0)
10954 errmsg ("spd_id must be set");
10958 if (sw_if_index_set == 0)
10960 errmsg ("missing interface name or sw_if_index");
10964 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10966 mp->spd_id = ntohl (spd_id);
10967 mp->sw_if_index = ntohl (sw_if_index);
10968 mp->is_add = is_add;
10976 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10978 unformat_input_t *i = vam->input;
10979 vl_api_ipsec_spd_entry_add_del_t *mp;
10980 u8 is_add = 1, is_outbound = 0;
10981 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10983 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10984 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10985 vl_api_address_t laddr_start = { }, laddr_stop =
10994 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10996 if (unformat (i, "del"))
10998 if (unformat (i, "outbound"))
11000 if (unformat (i, "inbound"))
11002 else if (unformat (i, "spd_id %d", &spd_id))
11004 else if (unformat (i, "sa_id %d", &sa_id))
11006 else if (unformat (i, "priority %d", &priority))
11008 else if (unformat (i, "protocol %d", &protocol))
11010 else if (unformat (i, "lport_start %d", &lport_start))
11012 else if (unformat (i, "lport_stop %d", &lport_stop))
11014 else if (unformat (i, "rport_start %d", &rport_start))
11016 else if (unformat (i, "rport_stop %d", &rport_stop))
11018 else if (unformat (i, "laddr_start %U",
11019 unformat_vl_api_address, &laddr_start))
11021 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
11024 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
11027 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
11031 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11033 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11035 clib_warning ("unsupported action: 'resolve'");
11041 clib_warning ("parse error '%U'", format_unformat_error, i);
11047 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
11049 mp->is_add = is_add;
11051 mp->entry.spd_id = ntohl (spd_id);
11052 mp->entry.priority = ntohl (priority);
11053 mp->entry.is_outbound = is_outbound;
11055 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
11056 sizeof (vl_api_address_t));
11057 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
11058 sizeof (vl_api_address_t));
11059 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
11060 sizeof (vl_api_address_t));
11061 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
11062 sizeof (vl_api_address_t));
11064 mp->entry.protocol = (u8) protocol;
11065 mp->entry.local_port_start = ntohs ((u16) lport_start);
11066 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
11067 mp->entry.remote_port_start = ntohs ((u16) rport_start);
11068 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
11069 mp->entry.policy = (u8) policy;
11070 mp->entry.sa_id = ntohl (sa_id);
11078 api_ipsec_sad_entry_add_del (vat_main_t * vam)
11080 unformat_input_t *i = vam->input;
11081 vl_api_ipsec_sad_entry_add_del_t *mp;
11082 u32 sad_id = 0, spi = 0;
11083 u8 *ck = 0, *ik = 0;
11086 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
11087 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
11088 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
11089 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
11090 vl_api_address_t tun_src, tun_dst;
11093 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11095 if (unformat (i, "del"))
11097 else if (unformat (i, "sad_id %d", &sad_id))
11099 else if (unformat (i, "spi %d", &spi))
11101 else if (unformat (i, "esp"))
11102 protocol = IPSEC_API_PROTO_ESP;
11104 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
11106 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11107 if (ADDRESS_IP6 == tun_src.af)
11108 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11111 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
11113 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11114 if (ADDRESS_IP6 == tun_src.af)
11115 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11118 if (unformat (i, "crypto_alg %U",
11119 unformat_ipsec_api_crypto_alg, &crypto_alg))
11121 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11123 else if (unformat (i, "integ_alg %U",
11124 unformat_ipsec_api_integ_alg, &integ_alg))
11126 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11130 clib_warning ("parse error '%U'", format_unformat_error, i);
11136 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
11138 mp->is_add = is_add;
11139 mp->entry.sad_id = ntohl (sad_id);
11140 mp->entry.protocol = protocol;
11141 mp->entry.spi = ntohl (spi);
11142 mp->entry.flags = flags;
11144 mp->entry.crypto_algorithm = crypto_alg;
11145 mp->entry.integrity_algorithm = integ_alg;
11146 mp->entry.crypto_key.length = vec_len (ck);
11147 mp->entry.integrity_key.length = vec_len (ik);
11149 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
11150 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
11152 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
11153 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
11156 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
11158 clib_memcpy (mp->entry.integrity_key.data, ik,
11159 mp->entry.integrity_key.length);
11161 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
11163 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
11164 sizeof (mp->entry.tunnel_src));
11165 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
11166 sizeof (mp->entry.tunnel_dst));
11175 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11177 vat_main_t *vam = &vat_main;
11179 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11180 "crypto_key %U integ_alg %u integ_key %U flags %x "
11181 "tunnel_src_addr %U tunnel_dst_addr %U "
11182 "salt %u seq_outbound %lu last_seq_inbound %lu "
11183 "replay_window %lu stat_index %u\n",
11184 ntohl (mp->entry.sad_id),
11185 ntohl (mp->sw_if_index),
11186 ntohl (mp->entry.spi),
11187 ntohl (mp->entry.protocol),
11188 ntohl (mp->entry.crypto_algorithm),
11189 format_hex_bytes, mp->entry.crypto_key.data,
11190 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11191 format_hex_bytes, mp->entry.integrity_key.data,
11192 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11193 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11194 &mp->entry.tunnel_dst, ntohl (mp->salt),
11195 clib_net_to_host_u64 (mp->seq_outbound),
11196 clib_net_to_host_u64 (mp->last_seq_inbound),
11197 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11200 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11201 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11203 static void vl_api_ipsec_sa_details_t_handler_json
11204 (vl_api_ipsec_sa_details_t * mp)
11206 vat_main_t *vam = &vat_main;
11207 vat_json_node_t *node = NULL;
11208 vl_api_ipsec_sad_flags_t flags;
11210 if (VAT_JSON_ARRAY != vam->json_tree.type)
11212 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11213 vat_json_init_array (&vam->json_tree);
11215 node = vat_json_array_add (&vam->json_tree);
11217 vat_json_init_object (node);
11218 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11219 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11220 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11221 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11222 vat_json_object_add_uint (node, "crypto_alg",
11223 ntohl (mp->entry.crypto_algorithm));
11224 vat_json_object_add_uint (node, "integ_alg",
11225 ntohl (mp->entry.integrity_algorithm));
11226 flags = ntohl (mp->entry.flags);
11227 vat_json_object_add_uint (node, "use_esn",
11228 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11229 vat_json_object_add_uint (node, "use_anti_replay",
11230 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11231 vat_json_object_add_uint (node, "is_tunnel",
11232 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11233 vat_json_object_add_uint (node, "is_tunnel_ip6",
11234 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11235 vat_json_object_add_uint (node, "udp_encap",
11236 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11237 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11238 mp->entry.crypto_key.length);
11239 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11240 mp->entry.integrity_key.length);
11241 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11242 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11243 vat_json_object_add_uint (node, "replay_window",
11244 clib_net_to_host_u64 (mp->replay_window));
11245 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11249 api_ipsec_sa_dump (vat_main_t * vam)
11251 unformat_input_t *i = vam->input;
11252 vl_api_ipsec_sa_dump_t *mp;
11253 vl_api_control_ping_t *mp_ping;
11257 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11259 if (unformat (i, "sa_id %d", &sa_id))
11263 clib_warning ("parse error '%U'", format_unformat_error, i);
11268 M (IPSEC_SA_DUMP, mp);
11270 mp->sa_id = ntohl (sa_id);
11274 /* Use a control ping for synchronization */
11275 M (CONTROL_PING, mp_ping);
11283 api_get_first_msg_id (vat_main_t * vam)
11285 vl_api_get_first_msg_id_t *mp;
11286 unformat_input_t *i = vam->input;
11291 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11293 if (unformat (i, "client %s", &name))
11301 errmsg ("missing client name");
11304 vec_add1 (name, 0);
11306 if (vec_len (name) > 63)
11308 errmsg ("client name too long");
11312 M (GET_FIRST_MSG_ID, mp);
11313 clib_memcpy (mp->name, name, vec_len (name));
11320 api_get_node_graph (vat_main_t * vam)
11322 vl_api_get_node_graph_t *mp;
11325 M (GET_NODE_GRAPH, mp);
11329 /* Wait for the reply */
11335 api_af_packet_create (vat_main_t * vam)
11337 unformat_input_t *i = vam->input;
11338 vl_api_af_packet_create_t *mp;
11339 u8 *host_if_name = 0;
11341 u8 random_hw_addr = 1;
11344 clib_memset (hw_addr, 0, sizeof (hw_addr));
11346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11348 if (unformat (i, "name %s", &host_if_name))
11349 vec_add1 (host_if_name, 0);
11350 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11351 random_hw_addr = 0;
11356 if (!vec_len (host_if_name))
11358 errmsg ("host-interface name must be specified");
11362 if (vec_len (host_if_name) > 64)
11364 errmsg ("host-interface name too long");
11368 M (AF_PACKET_CREATE, mp);
11370 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11371 clib_memcpy (mp->hw_addr, hw_addr, 6);
11372 mp->use_random_hw_addr = random_hw_addr;
11373 vec_free (host_if_name);
11381 fprintf (vam->ofp ? vam->ofp : stderr,
11382 " new sw_if_index = %d\n", vam->sw_if_index);
11389 api_af_packet_delete (vat_main_t * vam)
11391 unformat_input_t *i = vam->input;
11392 vl_api_af_packet_delete_t *mp;
11393 u8 *host_if_name = 0;
11396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11398 if (unformat (i, "name %s", &host_if_name))
11399 vec_add1 (host_if_name, 0);
11404 if (!vec_len (host_if_name))
11406 errmsg ("host-interface name must be specified");
11410 if (vec_len (host_if_name) > 64)
11412 errmsg ("host-interface name too long");
11416 M (AF_PACKET_DELETE, mp);
11418 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11419 vec_free (host_if_name);
11426 static void vl_api_af_packet_details_t_handler
11427 (vl_api_af_packet_details_t * mp)
11429 vat_main_t *vam = &vat_main;
11431 print (vam->ofp, "%-16s %d",
11432 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11435 static void vl_api_af_packet_details_t_handler_json
11436 (vl_api_af_packet_details_t * mp)
11438 vat_main_t *vam = &vat_main;
11439 vat_json_node_t *node = NULL;
11441 if (VAT_JSON_ARRAY != vam->json_tree.type)
11443 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11444 vat_json_init_array (&vam->json_tree);
11446 node = vat_json_array_add (&vam->json_tree);
11448 vat_json_init_object (node);
11449 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11450 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11454 api_af_packet_dump (vat_main_t * vam)
11456 vl_api_af_packet_dump_t *mp;
11457 vl_api_control_ping_t *mp_ping;
11460 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11461 /* Get list of tap interfaces */
11462 M (AF_PACKET_DUMP, mp);
11465 /* Use a control ping for synchronization */
11466 MPING (CONTROL_PING, mp_ping);
11474 api_policer_add_del (vat_main_t * vam)
11476 unformat_input_t *i = vam->input;
11477 vl_api_policer_add_del_t *mp;
11487 u8 color_aware = 0;
11488 qos_pol_action_params_st conform_action, exceed_action, violate_action;
11491 conform_action.action_type = QOS_ACTION_TRANSMIT;
11492 conform_action.dscp = 0;
11493 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
11494 exceed_action.dscp = 0;
11495 violate_action.action_type = QOS_ACTION_DROP;
11496 violate_action.dscp = 0;
11498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11500 if (unformat (i, "del"))
11502 else if (unformat (i, "name %s", &name))
11503 vec_add1 (name, 0);
11504 else if (unformat (i, "cir %u", &cir))
11506 else if (unformat (i, "eir %u", &eir))
11508 else if (unformat (i, "cb %u", &cb))
11510 else if (unformat (i, "eb %u", &eb))
11512 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11515 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11518 else if (unformat (i, "type %U", unformat_policer_type, &type))
11520 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11523 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11526 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11529 else if (unformat (i, "color-aware"))
11535 if (!vec_len (name))
11537 errmsg ("policer name must be specified");
11541 if (vec_len (name) > 64)
11543 errmsg ("policer name too long");
11547 M (POLICER_ADD_DEL, mp);
11549 clib_memcpy (mp->name, name, vec_len (name));
11551 mp->is_add = is_add;
11552 mp->cir = ntohl (cir);
11553 mp->eir = ntohl (eir);
11554 mp->cb = clib_net_to_host_u64 (cb);
11555 mp->eb = clib_net_to_host_u64 (eb);
11556 mp->rate_type = rate_type;
11557 mp->round_type = round_type;
11559 mp->conform_action.type =
11560 (vl_api_sse2_qos_action_type_t) conform_action.action_type;
11561 mp->conform_action.dscp = conform_action.dscp;
11562 mp->exceed_action.type =
11563 (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
11564 mp->exceed_action.dscp = exceed_action.dscp;
11565 mp->violate_action.type =
11566 (vl_api_sse2_qos_action_type_t) violate_action.action_type;
11567 mp->violate_action.dscp = violate_action.dscp;
11568 mp->color_aware = color_aware;
11576 api_policer_dump (vat_main_t * vam)
11578 unformat_input_t *i = vam->input;
11579 vl_api_policer_dump_t *mp;
11580 vl_api_control_ping_t *mp_ping;
11581 u8 *match_name = 0;
11582 u8 match_name_valid = 0;
11585 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11587 if (unformat (i, "name %s", &match_name))
11589 vec_add1 (match_name, 0);
11590 match_name_valid = 1;
11596 M (POLICER_DUMP, mp);
11597 mp->match_name_valid = match_name_valid;
11598 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11599 vec_free (match_name);
11603 /* Use a control ping for synchronization */
11604 MPING (CONTROL_PING, mp_ping);
11607 /* Wait for a reply... */
11613 api_policer_classify_set_interface (vat_main_t * vam)
11615 unformat_input_t *i = vam->input;
11616 vl_api_policer_classify_set_interface_t *mp;
11618 int sw_if_index_set;
11619 u32 ip4_table_index = ~0;
11620 u32 ip6_table_index = ~0;
11621 u32 l2_table_index = ~0;
11625 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11627 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11628 sw_if_index_set = 1;
11629 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11630 sw_if_index_set = 1;
11631 else if (unformat (i, "del"))
11633 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11635 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11637 else if (unformat (i, "l2-table %d", &l2_table_index))
11641 clib_warning ("parse error '%U'", format_unformat_error, i);
11646 if (sw_if_index_set == 0)
11648 errmsg ("missing interface name or sw_if_index");
11652 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
11654 mp->sw_if_index = ntohl (sw_if_index);
11655 mp->ip4_table_index = ntohl (ip4_table_index);
11656 mp->ip6_table_index = ntohl (ip6_table_index);
11657 mp->l2_table_index = ntohl (l2_table_index);
11658 mp->is_add = is_add;
11666 api_policer_classify_dump (vat_main_t * vam)
11668 unformat_input_t *i = vam->input;
11669 vl_api_policer_classify_dump_t *mp;
11670 vl_api_control_ping_t *mp_ping;
11671 u8 type = POLICER_CLASSIFY_N_TABLES;
11674 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
11678 errmsg ("classify table type must be specified");
11682 if (!vam->json_output)
11684 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
11687 M (POLICER_CLASSIFY_DUMP, mp);
11692 /* Use a control ping for synchronization */
11693 MPING (CONTROL_PING, mp_ping);
11696 /* Wait for a reply... */
11702 format_fib_api_path_nh_proto (u8 * s, va_list * args)
11704 vl_api_fib_path_nh_proto_t proto =
11705 va_arg (*args, vl_api_fib_path_nh_proto_t);
11709 case FIB_API_PATH_NH_PROTO_IP4:
11710 s = format (s, "ip4");
11712 case FIB_API_PATH_NH_PROTO_IP6:
11713 s = format (s, "ip6");
11715 case FIB_API_PATH_NH_PROTO_MPLS:
11716 s = format (s, "mpls");
11718 case FIB_API_PATH_NH_PROTO_BIER:
11719 s = format (s, "bier");
11721 case FIB_API_PATH_NH_PROTO_ETHERNET:
11722 s = format (s, "ethernet");
11730 format_vl_api_ip_address_union (u8 * s, va_list * args)
11732 vl_api_address_family_t af = va_arg (*args, int);
11733 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
11738 s = format (s, "%U", format_ip4_address, u->ip4);
11741 s = format (s, "%U", format_ip6_address, u->ip6);
11748 format_vl_api_fib_path_type (u8 * s, va_list * args)
11750 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
11754 case FIB_API_PATH_TYPE_NORMAL:
11755 s = format (s, "normal");
11757 case FIB_API_PATH_TYPE_LOCAL:
11758 s = format (s, "local");
11760 case FIB_API_PATH_TYPE_DROP:
11761 s = format (s, "drop");
11763 case FIB_API_PATH_TYPE_UDP_ENCAP:
11764 s = format (s, "udp-encap");
11766 case FIB_API_PATH_TYPE_BIER_IMP:
11767 s = format (s, "bier-imp");
11769 case FIB_API_PATH_TYPE_ICMP_UNREACH:
11770 s = format (s, "unreach");
11772 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
11773 s = format (s, "prohibit");
11775 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
11776 s = format (s, "src-lookup");
11778 case FIB_API_PATH_TYPE_DVR:
11779 s = format (s, "dvr");
11781 case FIB_API_PATH_TYPE_INTERFACE_RX:
11782 s = format (s, "interface-rx");
11784 case FIB_API_PATH_TYPE_CLASSIFY:
11785 s = format (s, "classify");
11793 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
11796 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
11797 ntohl (fp->weight), ntohl (fp->sw_if_index),
11798 format_vl_api_fib_path_type, fp->type,
11799 format_fib_api_path_nh_proto, fp->proto,
11800 format_vl_api_ip_address_union, &fp->nh.address);
11804 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
11805 vl_api_fib_path_t * fp)
11807 struct in_addr ip4;
11808 struct in6_addr ip6;
11810 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
11811 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
11812 vat_json_object_add_uint (node, "type", fp->type);
11813 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
11814 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
11816 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
11817 vat_json_object_add_ip4 (node, "next_hop", ip4);
11819 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
11821 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
11822 vat_json_object_add_ip6 (node, "next_hop", ip6);
11827 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
11829 vat_main_t *vam = &vat_main;
11830 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11831 vl_api_fib_path_t *fp;
11834 print (vam->ofp, "sw_if_index %d via:",
11835 ntohl (mp->mt_tunnel.mt_sw_if_index));
11836 fp = mp->mt_tunnel.mt_paths;
11837 for (i = 0; i < count; i++)
11839 vl_api_fib_path_print (vam, fp);
11843 print (vam->ofp, "");
11846 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
11847 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
11850 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
11852 vat_main_t *vam = &vat_main;
11853 vat_json_node_t *node = NULL;
11854 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11855 vl_api_fib_path_t *fp;
11858 if (VAT_JSON_ARRAY != vam->json_tree.type)
11860 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11861 vat_json_init_array (&vam->json_tree);
11863 node = vat_json_array_add (&vam->json_tree);
11865 vat_json_init_object (node);
11866 vat_json_object_add_uint (node, "sw_if_index",
11867 ntohl (mp->mt_tunnel.mt_sw_if_index));
11869 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
11871 fp = mp->mt_tunnel.mt_paths;
11872 for (i = 0; i < count; i++)
11874 vl_api_mpls_fib_path_json_print (node, fp);
11880 api_mpls_tunnel_dump (vat_main_t * vam)
11882 vl_api_mpls_tunnel_dump_t *mp;
11883 vl_api_control_ping_t *mp_ping;
11886 M (MPLS_TUNNEL_DUMP, mp);
11890 /* Use a control ping for synchronization */
11891 MPING (CONTROL_PING, mp_ping);
11898 #define vl_api_mpls_table_details_t_endian vl_noop_handler
11899 #define vl_api_mpls_table_details_t_print vl_noop_handler
11903 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
11905 vat_main_t *vam = &vat_main;
11907 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
11910 static void vl_api_mpls_table_details_t_handler_json
11911 (vl_api_mpls_table_details_t * mp)
11913 vat_main_t *vam = &vat_main;
11914 vat_json_node_t *node = NULL;
11916 if (VAT_JSON_ARRAY != vam->json_tree.type)
11918 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11919 vat_json_init_array (&vam->json_tree);
11921 node = vat_json_array_add (&vam->json_tree);
11923 vat_json_init_object (node);
11924 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
11928 api_mpls_table_dump (vat_main_t * vam)
11930 vl_api_mpls_table_dump_t *mp;
11931 vl_api_control_ping_t *mp_ping;
11934 M (MPLS_TABLE_DUMP, mp);
11937 /* Use a control ping for synchronization */
11938 MPING (CONTROL_PING, mp_ping);
11945 #define vl_api_mpls_route_details_t_endian vl_noop_handler
11946 #define vl_api_mpls_route_details_t_print vl_noop_handler
11949 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
11951 vat_main_t *vam = &vat_main;
11952 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
11953 vl_api_fib_path_t *fp;
11957 "table-id %d, label %u, ess_bit %u",
11958 ntohl (mp->mr_route.mr_table_id),
11959 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
11960 fp = mp->mr_route.mr_paths;
11961 for (i = 0; i < count; i++)
11963 vl_api_fib_path_print (vam, fp);
11968 static void vl_api_mpls_route_details_t_handler_json
11969 (vl_api_mpls_route_details_t * mp)
11971 vat_main_t *vam = &vat_main;
11972 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
11973 vat_json_node_t *node = NULL;
11974 vl_api_fib_path_t *fp;
11977 if (VAT_JSON_ARRAY != vam->json_tree.type)
11979 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11980 vat_json_init_array (&vam->json_tree);
11982 node = vat_json_array_add (&vam->json_tree);
11984 vat_json_init_object (node);
11985 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
11986 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
11987 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
11988 vat_json_object_add_uint (node, "path_count", count);
11989 fp = mp->mr_route.mr_paths;
11990 for (i = 0; i < count; i++)
11992 vl_api_mpls_fib_path_json_print (node, fp);
11998 api_mpls_route_dump (vat_main_t * vam)
12000 unformat_input_t *input = vam->input;
12001 vl_api_mpls_route_dump_t *mp;
12002 vl_api_control_ping_t *mp_ping;
12006 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12008 if (unformat (input, "table_id %d", &table_id))
12013 if (table_id == ~0)
12015 errmsg ("missing table id");
12019 M (MPLS_ROUTE_DUMP, mp);
12021 mp->table.mt_table_id = ntohl (table_id);
12024 /* Use a control ping for synchronization */
12025 MPING (CONTROL_PING, mp_ping);
12032 #define vl_api_ip_table_details_t_endian vl_noop_handler
12033 #define vl_api_ip_table_details_t_print vl_noop_handler
12036 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12038 vat_main_t *vam = &vat_main;
12041 "%s; table-id %d, prefix %U/%d",
12042 mp->table.name, ntohl (mp->table.table_id));
12046 static void vl_api_ip_table_details_t_handler_json
12047 (vl_api_ip_table_details_t * mp)
12049 vat_main_t *vam = &vat_main;
12050 vat_json_node_t *node = NULL;
12052 if (VAT_JSON_ARRAY != vam->json_tree.type)
12054 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12055 vat_json_init_array (&vam->json_tree);
12057 node = vat_json_array_add (&vam->json_tree);
12059 vat_json_init_object (node);
12060 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12064 api_ip_table_dump (vat_main_t * vam)
12066 vl_api_ip_table_dump_t *mp;
12067 vl_api_control_ping_t *mp_ping;
12070 M (IP_TABLE_DUMP, mp);
12073 /* Use a control ping for synchronization */
12074 MPING (CONTROL_PING, mp_ping);
12082 api_ip_mtable_dump (vat_main_t * vam)
12084 vl_api_ip_mtable_dump_t *mp;
12085 vl_api_control_ping_t *mp_ping;
12088 M (IP_MTABLE_DUMP, mp);
12091 /* Use a control ping for synchronization */
12092 MPING (CONTROL_PING, mp_ping);
12100 api_ip_mroute_dump (vat_main_t * vam)
12102 unformat_input_t *input = vam->input;
12103 vl_api_control_ping_t *mp_ping;
12104 vl_api_ip_mroute_dump_t *mp;
12109 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12111 if (unformat (input, "table_id %d", &table_id))
12113 else if (unformat (input, "ip6"))
12115 else if (unformat (input, "ip4"))
12120 if (table_id == ~0)
12122 errmsg ("missing table id");
12126 M (IP_MROUTE_DUMP, mp);
12127 mp->table.table_id = table_id;
12128 mp->table.is_ip6 = is_ip6;
12131 /* Use a control ping for synchronization */
12132 MPING (CONTROL_PING, mp_ping);
12139 #define vl_api_ip_route_details_t_endian vl_noop_handler
12140 #define vl_api_ip_route_details_t_print vl_noop_handler
12143 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12145 vat_main_t *vam = &vat_main;
12146 u8 count = mp->route.n_paths;
12147 vl_api_fib_path_t *fp;
12151 "table-id %d, prefix %U/%d",
12152 ntohl (mp->route.table_id),
12153 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12154 for (i = 0; i < count; i++)
12156 fp = &mp->route.paths[i];
12158 vl_api_fib_path_print (vam, fp);
12163 static void vl_api_ip_route_details_t_handler_json
12164 (vl_api_ip_route_details_t * mp)
12166 vat_main_t *vam = &vat_main;
12167 u8 count = mp->route.n_paths;
12168 vat_json_node_t *node = NULL;
12169 struct in_addr ip4;
12170 struct in6_addr ip6;
12171 vl_api_fib_path_t *fp;
12174 if (VAT_JSON_ARRAY != vam->json_tree.type)
12176 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12177 vat_json_init_array (&vam->json_tree);
12179 node = vat_json_array_add (&vam->json_tree);
12181 vat_json_init_object (node);
12182 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12183 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12185 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12186 vat_json_object_add_ip6 (node, "prefix", ip6);
12190 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12191 vat_json_object_add_ip4 (node, "prefix", ip4);
12193 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12194 vat_json_object_add_uint (node, "path_count", count);
12195 for (i = 0; i < count; i++)
12197 fp = &mp->route.paths[i];
12198 vl_api_mpls_fib_path_json_print (node, fp);
12203 api_ip_route_dump (vat_main_t * vam)
12205 unformat_input_t *input = vam->input;
12206 vl_api_ip_route_dump_t *mp;
12207 vl_api_control_ping_t *mp_ping;
12213 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12215 if (unformat (input, "table_id %d", &table_id))
12217 else if (unformat (input, "ip6"))
12219 else if (unformat (input, "ip4"))
12224 if (table_id == ~0)
12226 errmsg ("missing table id");
12230 M (IP_ROUTE_DUMP, mp);
12232 mp->table.table_id = table_id;
12233 mp->table.is_ip6 = is_ip6;
12237 /* Use a control ping for synchronization */
12238 MPING (CONTROL_PING, mp_ping);
12246 api_classify_table_ids (vat_main_t * vam)
12248 vl_api_classify_table_ids_t *mp;
12251 /* Construct the API message */
12252 M (CLASSIFY_TABLE_IDS, mp);
12261 api_classify_table_by_interface (vat_main_t * vam)
12263 unformat_input_t *input = vam->input;
12264 vl_api_classify_table_by_interface_t *mp;
12266 u32 sw_if_index = ~0;
12268 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12270 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12272 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12277 if (sw_if_index == ~0)
12279 errmsg ("missing interface name or sw_if_index");
12283 /* Construct the API message */
12284 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12286 mp->sw_if_index = ntohl (sw_if_index);
12294 api_classify_table_info (vat_main_t * vam)
12296 unformat_input_t *input = vam->input;
12297 vl_api_classify_table_info_t *mp;
12301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12303 if (unformat (input, "table_id %d", &table_id))
12308 if (table_id == ~0)
12310 errmsg ("missing table id");
12314 /* Construct the API message */
12315 M (CLASSIFY_TABLE_INFO, mp);
12317 mp->table_id = ntohl (table_id);
12325 api_classify_session_dump (vat_main_t * vam)
12327 unformat_input_t *input = vam->input;
12328 vl_api_classify_session_dump_t *mp;
12329 vl_api_control_ping_t *mp_ping;
12333 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12335 if (unformat (input, "table_id %d", &table_id))
12340 if (table_id == ~0)
12342 errmsg ("missing table id");
12346 /* Construct the API message */
12347 M (CLASSIFY_SESSION_DUMP, mp);
12349 mp->table_id = ntohl (table_id);
12352 /* Use a control ping for synchronization */
12353 MPING (CONTROL_PING, mp_ping);
12361 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12363 vat_main_t *vam = &vat_main;
12365 print (vam->ofp, "collector_address %U, collector_port %d, "
12366 "src_address %U, vrf_id %d, path_mtu %u, "
12367 "template_interval %u, udp_checksum %d",
12368 format_ip4_address, mp->collector_address,
12369 ntohs (mp->collector_port),
12370 format_ip4_address, mp->src_address,
12371 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12372 ntohl (mp->template_interval), mp->udp_checksum);
12375 vam->result_ready = 1;
12379 vl_api_ipfix_exporter_details_t_handler_json
12380 (vl_api_ipfix_exporter_details_t * mp)
12382 vat_main_t *vam = &vat_main;
12383 vat_json_node_t node;
12384 struct in_addr collector_address;
12385 struct in_addr src_address;
12387 vat_json_init_object (&node);
12388 clib_memcpy (&collector_address, &mp->collector_address,
12389 sizeof (collector_address));
12390 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12391 vat_json_object_add_uint (&node, "collector_port",
12392 ntohs (mp->collector_port));
12393 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12394 vat_json_object_add_ip4 (&node, "src_address", src_address);
12395 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12396 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12397 vat_json_object_add_uint (&node, "template_interval",
12398 ntohl (mp->template_interval));
12399 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12401 vat_json_print (vam->ofp, &node);
12402 vat_json_free (&node);
12404 vam->result_ready = 1;
12408 api_ipfix_exporter_dump (vat_main_t * vam)
12410 vl_api_ipfix_exporter_dump_t *mp;
12413 /* Construct the API message */
12414 M (IPFIX_EXPORTER_DUMP, mp);
12423 api_ipfix_classify_stream_dump (vat_main_t * vam)
12425 vl_api_ipfix_classify_stream_dump_t *mp;
12428 /* Construct the API message */
12429 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12440 vl_api_ipfix_classify_stream_details_t_handler
12441 (vl_api_ipfix_classify_stream_details_t * mp)
12443 vat_main_t *vam = &vat_main;
12444 print (vam->ofp, "domain_id %d, src_port %d",
12445 ntohl (mp->domain_id), ntohs (mp->src_port));
12447 vam->result_ready = 1;
12451 vl_api_ipfix_classify_stream_details_t_handler_json
12452 (vl_api_ipfix_classify_stream_details_t * mp)
12454 vat_main_t *vam = &vat_main;
12455 vat_json_node_t node;
12457 vat_json_init_object (&node);
12458 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12459 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12461 vat_json_print (vam->ofp, &node);
12462 vat_json_free (&node);
12464 vam->result_ready = 1;
12468 api_ipfix_classify_table_dump (vat_main_t * vam)
12470 vl_api_ipfix_classify_table_dump_t *mp;
12471 vl_api_control_ping_t *mp_ping;
12474 if (!vam->json_output)
12476 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12477 "transport_protocol");
12480 /* Construct the API message */
12481 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12486 /* Use a control ping for synchronization */
12487 MPING (CONTROL_PING, mp_ping);
12495 vl_api_ipfix_classify_table_details_t_handler
12496 (vl_api_ipfix_classify_table_details_t * mp)
12498 vat_main_t *vam = &vat_main;
12499 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12500 mp->transport_protocol);
12504 vl_api_ipfix_classify_table_details_t_handler_json
12505 (vl_api_ipfix_classify_table_details_t * mp)
12507 vat_json_node_t *node = NULL;
12508 vat_main_t *vam = &vat_main;
12510 if (VAT_JSON_ARRAY != vam->json_tree.type)
12512 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12513 vat_json_init_array (&vam->json_tree);
12516 node = vat_json_array_add (&vam->json_tree);
12517 vat_json_init_object (node);
12519 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12520 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12521 vat_json_object_add_uint (node, "transport_protocol",
12522 mp->transport_protocol);
12526 api_sw_interface_span_enable_disable (vat_main_t * vam)
12528 unformat_input_t *i = vam->input;
12529 vl_api_sw_interface_span_enable_disable_t *mp;
12530 u32 src_sw_if_index = ~0;
12531 u32 dst_sw_if_index = ~0;
12536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12539 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12541 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12545 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12547 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12549 else if (unformat (i, "disable"))
12551 else if (unformat (i, "rx"))
12553 else if (unformat (i, "tx"))
12555 else if (unformat (i, "both"))
12557 else if (unformat (i, "l2"))
12563 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12565 mp->sw_if_index_from = htonl (src_sw_if_index);
12566 mp->sw_if_index_to = htonl (dst_sw_if_index);
12576 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12579 vat_main_t *vam = &vat_main;
12580 u8 *sw_if_from_name = 0;
12581 u8 *sw_if_to_name = 0;
12582 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12583 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12584 char *states[] = { "none", "rx", "tx", "both" };
12588 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12590 if ((u32) p->value[0] == sw_if_index_from)
12592 sw_if_from_name = (u8 *)(p->key);
12596 if ((u32) p->value[0] == sw_if_index_to)
12598 sw_if_to_name = (u8 *)(p->key);
12599 if (sw_if_from_name)
12604 print (vam->ofp, "%20s => %20s (%s) %s",
12605 sw_if_from_name, sw_if_to_name, states[mp->state],
12606 mp->is_l2 ? "l2" : "device");
12610 vl_api_sw_interface_span_details_t_handler_json
12611 (vl_api_sw_interface_span_details_t * mp)
12613 vat_main_t *vam = &vat_main;
12614 vat_json_node_t *node = NULL;
12615 u8 *sw_if_from_name = 0;
12616 u8 *sw_if_to_name = 0;
12617 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12618 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12622 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12624 if ((u32) p->value[0] == sw_if_index_from)
12626 sw_if_from_name = (u8 *)(p->key);
12630 if ((u32) p->value[0] == sw_if_index_to)
12632 sw_if_to_name = (u8 *)(p->key);
12633 if (sw_if_from_name)
12639 if (VAT_JSON_ARRAY != vam->json_tree.type)
12641 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12642 vat_json_init_array (&vam->json_tree);
12644 node = vat_json_array_add (&vam->json_tree);
12646 vat_json_init_object (node);
12647 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12648 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12649 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12650 if (0 != sw_if_to_name)
12652 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
12654 vat_json_object_add_uint (node, "state", mp->state);
12655 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
12659 api_sw_interface_span_dump (vat_main_t * vam)
12661 unformat_input_t *input = vam->input;
12662 vl_api_sw_interface_span_dump_t *mp;
12663 vl_api_control_ping_t *mp_ping;
12667 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12669 if (unformat (input, "l2"))
12675 M (SW_INTERFACE_SPAN_DUMP, mp);
12679 /* Use a control ping for synchronization */
12680 MPING (CONTROL_PING, mp_ping);
12688 api_pg_create_interface (vat_main_t * vam)
12690 unformat_input_t *input = vam->input;
12691 vl_api_pg_create_interface_t *mp;
12693 u32 if_id = ~0, gso_size = 0;
12694 u8 gso_enabled = 0;
12696 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12698 if (unformat (input, "if_id %d", &if_id))
12700 else if (unformat (input, "gso-enabled"))
12703 if (unformat (input, "gso-size %u", &gso_size))
12707 errmsg ("missing gso-size");
12716 errmsg ("missing pg interface index");
12720 /* Construct the API message */
12721 M (PG_CREATE_INTERFACE, mp);
12723 mp->interface_id = ntohl (if_id);
12724 mp->gso_enabled = gso_enabled;
12732 api_pg_capture (vat_main_t * vam)
12734 unformat_input_t *input = vam->input;
12735 vl_api_pg_capture_t *mp;
12740 u8 pcap_file_set = 0;
12743 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12745 if (unformat (input, "if_id %d", &if_id))
12747 else if (unformat (input, "pcap %s", &pcap_file))
12749 else if (unformat (input, "count %d", &count))
12751 else if (unformat (input, "disable"))
12758 errmsg ("missing pg interface index");
12761 if (pcap_file_set > 0)
12763 if (vec_len (pcap_file) > 255)
12765 errmsg ("pcap file name is too long");
12770 /* Construct the API message */
12771 M (PG_CAPTURE, mp);
12773 mp->interface_id = ntohl (if_id);
12774 mp->is_enabled = enable;
12775 mp->count = ntohl (count);
12776 if (pcap_file_set != 0)
12778 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
12780 vec_free (pcap_file);
12788 api_pg_enable_disable (vat_main_t * vam)
12790 unformat_input_t *input = vam->input;
12791 vl_api_pg_enable_disable_t *mp;
12794 u8 stream_name_set = 0;
12795 u8 *stream_name = 0;
12797 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12799 if (unformat (input, "stream %s", &stream_name))
12800 stream_name_set = 1;
12801 else if (unformat (input, "disable"))
12807 if (stream_name_set > 0)
12809 if (vec_len (stream_name) > 255)
12811 errmsg ("stream name too long");
12816 /* Construct the API message */
12817 M (PG_ENABLE_DISABLE, mp);
12819 mp->is_enabled = enable;
12820 if (stream_name_set != 0)
12822 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
12824 vec_free (stream_name);
12832 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
12834 unformat_input_t *input = vam->input;
12835 vl_api_pg_interface_enable_disable_coalesce_t *mp;
12837 u32 sw_if_index = ~0;
12840 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12842 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12844 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12846 else if (unformat (input, "disable"))
12852 if (sw_if_index == ~0)
12854 errmsg ("Interface required but not specified");
12858 /* Construct the API message */
12859 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
12861 mp->coalesce_enabled = enable;
12862 mp->sw_if_index = htonl (sw_if_index);
12870 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
12872 unformat_input_t *input = vam->input;
12873 vl_api_ip_source_and_port_range_check_add_del_t *mp;
12875 u16 *low_ports = 0;
12876 u16 *high_ports = 0;
12879 vl_api_prefix_t prefix;
12886 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12888 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
12890 else if (unformat (input, "vrf %d", &vrf_id))
12892 else if (unformat (input, "del"))
12894 else if (unformat (input, "port %d", &tmp))
12896 if (tmp == 0 || tmp > 65535)
12898 errmsg ("port %d out of range", tmp);
12902 this_hi = this_low + 1;
12903 vec_add1 (low_ports, this_low);
12904 vec_add1 (high_ports, this_hi);
12906 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
12908 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
12910 errmsg ("incorrect range parameters");
12914 /* Note: in debug CLI +1 is added to high before
12915 passing to real fn that does "the work"
12916 (ip_source_and_port_range_check_add_del).
12917 This fn is a wrapper around the binary API fn a
12918 control plane will call, which expects this increment
12919 to have occurred. Hence letting the binary API control
12920 plane fn do the increment for consistency between VAT
12921 and other control planes.
12924 vec_add1 (low_ports, this_low);
12925 vec_add1 (high_ports, this_hi);
12931 if (prefix_set == 0)
12933 errmsg ("<address>/<mask> not specified");
12939 errmsg ("VRF ID required, not specified");
12946 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
12950 if (vec_len (low_ports) == 0)
12952 errmsg ("At least one port or port range required");
12956 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
12958 mp->is_add = is_add;
12960 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
12962 mp->number_of_ranges = vec_len (low_ports);
12964 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
12965 vec_free (low_ports);
12967 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
12968 vec_free (high_ports);
12970 mp->vrf_id = ntohl (vrf_id);
12978 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
12980 unformat_input_t *input = vam->input;
12981 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
12982 u32 sw_if_index = ~0;
12984 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
12985 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
12989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12991 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12993 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12995 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
12997 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
12999 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13001 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13003 else if (unformat (input, "del"))
13009 if (sw_if_index == ~0)
13011 errmsg ("Interface required but not specified");
13017 errmsg ("VRF ID required but not specified");
13021 if (tcp_out_vrf_id == 0
13022 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13025 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13029 /* Construct the API message */
13030 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13032 mp->sw_if_index = ntohl (sw_if_index);
13033 mp->is_add = is_add;
13034 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13035 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13036 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13037 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13042 /* Wait for a reply... */
13048 api_set_punt (vat_main_t * vam)
13050 unformat_input_t *i = vam->input;
13051 vl_api_address_family_t af;
13052 vl_api_set_punt_t *mp;
13058 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13060 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13062 else if (unformat (i, "protocol %d", &protocol))
13064 else if (unformat (i, "port %d", &port))
13066 else if (unformat (i, "del"))
13070 clib_warning ("parse error '%U'", format_unformat_error, i);
13077 mp->is_add = (u8) is_add;
13078 mp->punt.type = PUNT_API_TYPE_L4;
13079 mp->punt.punt.l4.af = af;
13080 mp->punt.punt.l4.protocol = (u8) protocol;
13081 mp->punt.punt.l4.port = htons ((u16) port);
13089 api_delete_subif (vat_main_t * vam)
13091 unformat_input_t *i = vam->input;
13092 vl_api_delete_subif_t *mp;
13093 u32 sw_if_index = ~0;
13096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13098 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13100 if (unformat (i, "sw_if_index %d", &sw_if_index))
13106 if (sw_if_index == ~0)
13108 errmsg ("missing sw_if_index");
13112 /* Construct the API message */
13113 M (DELETE_SUBIF, mp);
13114 mp->sw_if_index = ntohl (sw_if_index);
13121 #define foreach_pbb_vtr_op \
13122 _("disable", L2_VTR_DISABLED) \
13123 _("pop", L2_VTR_POP_2) \
13124 _("push", L2_VTR_PUSH_2)
13127 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13129 unformat_input_t *i = vam->input;
13130 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13131 u32 sw_if_index = ~0, vtr_op = ~0;
13132 u16 outer_tag = ~0;
13133 u8 dmac[6], smac[6];
13134 u8 dmac_set = 0, smac_set = 0;
13140 /* Shut up coverity */
13141 clib_memset (dmac, 0, sizeof (dmac));
13142 clib_memset (smac, 0, sizeof (smac));
13144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13146 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13148 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13150 else if (unformat (i, "vtr_op %d", &vtr_op))
13152 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13155 else if (unformat (i, "translate_pbb_stag"))
13157 if (unformat (i, "%d", &tmp))
13159 vtr_op = L2_VTR_TRANSLATE_2_1;
13165 ("translate_pbb_stag operation requires outer tag definition");
13169 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13171 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13173 else if (unformat (i, "sid %d", &sid))
13175 else if (unformat (i, "vlanid %d", &tmp))
13179 clib_warning ("parse error '%U'", format_unformat_error, i);
13184 if ((sw_if_index == ~0) || (vtr_op == ~0))
13186 errmsg ("missing sw_if_index or vtr operation");
13189 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13190 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13193 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13197 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13198 mp->sw_if_index = ntohl (sw_if_index);
13199 mp->vtr_op = ntohl (vtr_op);
13200 mp->outer_tag = ntohs (outer_tag);
13201 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13202 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13203 mp->b_vlanid = ntohs (vlanid);
13204 mp->i_sid = ntohl (sid);
13212 api_flow_classify_set_interface (vat_main_t * vam)
13214 unformat_input_t *i = vam->input;
13215 vl_api_flow_classify_set_interface_t *mp;
13217 int sw_if_index_set;
13218 u32 ip4_table_index = ~0;
13219 u32 ip6_table_index = ~0;
13223 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13225 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13226 sw_if_index_set = 1;
13227 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13228 sw_if_index_set = 1;
13229 else if (unformat (i, "del"))
13231 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13233 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13237 clib_warning ("parse error '%U'", format_unformat_error, i);
13242 if (sw_if_index_set == 0)
13244 errmsg ("missing interface name or sw_if_index");
13248 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13250 mp->sw_if_index = ntohl (sw_if_index);
13251 mp->ip4_table_index = ntohl (ip4_table_index);
13252 mp->ip6_table_index = ntohl (ip6_table_index);
13253 mp->is_add = is_add;
13261 api_flow_classify_dump (vat_main_t * vam)
13263 unformat_input_t *i = vam->input;
13264 vl_api_flow_classify_dump_t *mp;
13265 vl_api_control_ping_t *mp_ping;
13266 u8 type = FLOW_CLASSIFY_N_TABLES;
13269 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13273 errmsg ("classify table type must be specified");
13277 if (!vam->json_output)
13279 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13282 M (FLOW_CLASSIFY_DUMP, mp);
13287 /* Use a control ping for synchronization */
13288 MPING (CONTROL_PING, mp_ping);
13291 /* Wait for a reply... */
13297 api_feature_enable_disable (vat_main_t * vam)
13299 unformat_input_t *i = vam->input;
13300 vl_api_feature_enable_disable_t *mp;
13302 u8 *feature_name = 0;
13303 u32 sw_if_index = ~0;
13307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13309 if (unformat (i, "arc_name %s", &arc_name))
13311 else if (unformat (i, "feature_name %s", &feature_name))
13314 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13316 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13318 else if (unformat (i, "disable"))
13326 errmsg ("missing arc name");
13329 if (vec_len (arc_name) > 63)
13331 errmsg ("arc name too long");
13334 if (feature_name == 0)
13336 errmsg ("missing feature name");
13339 if (vec_len (feature_name) > 63)
13341 errmsg ("feature name too long");
13344 if (sw_if_index == ~0)
13346 errmsg ("missing interface name or sw_if_index");
13350 /* Construct the API message */
13351 M (FEATURE_ENABLE_DISABLE, mp);
13352 mp->sw_if_index = ntohl (sw_if_index);
13353 mp->enable = enable;
13354 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13355 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13356 vec_free (arc_name);
13357 vec_free (feature_name);
13365 api_feature_gso_enable_disable (vat_main_t * vam)
13367 unformat_input_t *i = vam->input;
13368 vl_api_feature_gso_enable_disable_t *mp;
13369 u32 sw_if_index = ~0;
13373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13375 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13377 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13379 else if (unformat (i, "enable"))
13381 else if (unformat (i, "disable"))
13387 if (sw_if_index == ~0)
13389 errmsg ("missing interface name or sw_if_index");
13393 /* Construct the API message */
13394 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13395 mp->sw_if_index = ntohl (sw_if_index);
13396 mp->enable_disable = enable;
13404 api_sw_interface_tag_add_del (vat_main_t * vam)
13406 unformat_input_t *i = vam->input;
13407 vl_api_sw_interface_tag_add_del_t *mp;
13408 u32 sw_if_index = ~0;
13413 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13415 if (unformat (i, "tag %s", &tag))
13417 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13419 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13421 else if (unformat (i, "del"))
13427 if (sw_if_index == ~0)
13429 errmsg ("missing interface name or sw_if_index");
13433 if (enable && (tag == 0))
13435 errmsg ("no tag specified");
13439 /* Construct the API message */
13440 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13441 mp->sw_if_index = ntohl (sw_if_index);
13442 mp->is_add = enable;
13444 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13453 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13455 unformat_input_t *i = vam->input;
13456 vl_api_mac_address_t mac = { 0 };
13457 vl_api_sw_interface_add_del_mac_address_t *mp;
13458 u32 sw_if_index = ~0;
13463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13465 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13467 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13469 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13471 else if (unformat (i, "del"))
13477 if (sw_if_index == ~0)
13479 errmsg ("missing interface name or sw_if_index");
13485 errmsg ("missing MAC address");
13489 /* Construct the API message */
13490 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13491 mp->sw_if_index = ntohl (sw_if_index);
13492 mp->is_add = is_add;
13493 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13500 static void vl_api_l2_xconnect_details_t_handler
13501 (vl_api_l2_xconnect_details_t * mp)
13503 vat_main_t *vam = &vat_main;
13505 print (vam->ofp, "%15d%15d",
13506 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13509 static void vl_api_l2_xconnect_details_t_handler_json
13510 (vl_api_l2_xconnect_details_t * mp)
13512 vat_main_t *vam = &vat_main;
13513 vat_json_node_t *node = NULL;
13515 if (VAT_JSON_ARRAY != vam->json_tree.type)
13517 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13518 vat_json_init_array (&vam->json_tree);
13520 node = vat_json_array_add (&vam->json_tree);
13522 vat_json_init_object (node);
13523 vat_json_object_add_uint (node, "rx_sw_if_index",
13524 ntohl (mp->rx_sw_if_index));
13525 vat_json_object_add_uint (node, "tx_sw_if_index",
13526 ntohl (mp->tx_sw_if_index));
13530 api_l2_xconnect_dump (vat_main_t * vam)
13532 vl_api_l2_xconnect_dump_t *mp;
13533 vl_api_control_ping_t *mp_ping;
13536 if (!vam->json_output)
13538 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13541 M (L2_XCONNECT_DUMP, mp);
13545 /* Use a control ping for synchronization */
13546 MPING (CONTROL_PING, mp_ping);
13554 api_hw_interface_set_mtu (vat_main_t * vam)
13556 unformat_input_t *i = vam->input;
13557 vl_api_hw_interface_set_mtu_t *mp;
13558 u32 sw_if_index = ~0;
13562 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13564 if (unformat (i, "mtu %d", &mtu))
13566 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13568 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13574 if (sw_if_index == ~0)
13576 errmsg ("missing interface name or sw_if_index");
13582 errmsg ("no mtu specified");
13586 /* Construct the API message */
13587 M (HW_INTERFACE_SET_MTU, mp);
13588 mp->sw_if_index = ntohl (sw_if_index);
13589 mp->mtu = ntohs ((u16) mtu);
13597 api_p2p_ethernet_add (vat_main_t * vam)
13599 unformat_input_t *i = vam->input;
13600 vl_api_p2p_ethernet_add_t *mp;
13601 u32 parent_if_index = ~0;
13607 clib_memset (remote_mac, 0, sizeof (remote_mac));
13608 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13610 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13612 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13616 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13618 else if (unformat (i, "sub_id %d", &sub_id))
13622 clib_warning ("parse error '%U'", format_unformat_error, i);
13627 if (parent_if_index == ~0)
13629 errmsg ("missing interface name or sw_if_index");
13634 errmsg ("missing remote mac address");
13639 errmsg ("missing sub-interface id");
13643 M (P2P_ETHERNET_ADD, mp);
13644 mp->parent_if_index = ntohl (parent_if_index);
13645 mp->subif_id = ntohl (sub_id);
13646 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13654 api_p2p_ethernet_del (vat_main_t * vam)
13656 unformat_input_t *i = vam->input;
13657 vl_api_p2p_ethernet_del_t *mp;
13658 u32 parent_if_index = ~0;
13663 clib_memset (remote_mac, 0, sizeof (remote_mac));
13664 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13666 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13668 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13672 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13676 clib_warning ("parse error '%U'", format_unformat_error, i);
13681 if (parent_if_index == ~0)
13683 errmsg ("missing interface name or sw_if_index");
13688 errmsg ("missing remote mac address");
13692 M (P2P_ETHERNET_DEL, mp);
13693 mp->parent_if_index = ntohl (parent_if_index);
13694 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13702 api_tcp_configure_src_addresses (vat_main_t * vam)
13704 vl_api_tcp_configure_src_addresses_t *mp;
13705 unformat_input_t *i = vam->input;
13706 vl_api_address_t first, last;
13711 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13713 if (unformat (i, "%U - %U",
13714 unformat_vl_api_address, &first,
13715 unformat_vl_api_address, &last))
13719 errmsg ("one range per message (range already set)");
13724 else if (unformat (i, "vrf %d", &vrf_id))
13730 if (range_set == 0)
13732 errmsg ("address range not set");
13736 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
13738 mp->vrf_id = ntohl (vrf_id);
13739 clib_memcpy (&mp->first_address, &first, sizeof (first));
13740 clib_memcpy (&mp->last_address, &last, sizeof (last));
13747 static void vl_api_app_namespace_add_del_reply_t_handler
13748 (vl_api_app_namespace_add_del_reply_t * mp)
13750 vat_main_t *vam = &vat_main;
13751 i32 retval = ntohl (mp->retval);
13752 if (vam->async_mode)
13754 vam->async_errors += (retval < 0);
13758 vam->retval = retval;
13760 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
13761 vam->result_ready = 1;
13765 static void vl_api_app_namespace_add_del_reply_t_handler_json
13766 (vl_api_app_namespace_add_del_reply_t * mp)
13768 vat_main_t *vam = &vat_main;
13769 vat_json_node_t node;
13771 vat_json_init_object (&node);
13772 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
13773 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
13775 vat_json_print (vam->ofp, &node);
13776 vat_json_free (&node);
13778 vam->retval = ntohl (mp->retval);
13779 vam->result_ready = 1;
13783 api_app_namespace_add_del (vat_main_t * vam)
13785 vl_api_app_namespace_add_del_t *mp;
13786 unformat_input_t *i = vam->input;
13787 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
13788 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
13792 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13794 if (unformat (i, "id %_%v%_", &ns_id))
13796 else if (unformat (i, "secret %lu", &secret))
13798 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13799 sw_if_index_set = 1;
13800 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
13802 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
13807 if (!ns_id || !secret_set || !sw_if_index_set)
13809 errmsg ("namespace id, secret and sw_if_index must be set");
13812 if (vec_len (ns_id) > 64)
13814 errmsg ("namespace id too long");
13817 M (APP_NAMESPACE_ADD_DEL, mp);
13819 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
13820 mp->secret = clib_host_to_net_u64 (secret);
13821 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
13822 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
13823 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
13831 api_sock_init_shm (vat_main_t * vam)
13833 #if VPP_API_TEST_BUILTIN == 0
13834 unformat_input_t *i = vam->input;
13835 vl_api_shm_elem_config_t *config = 0;
13836 u64 size = 64 << 20;
13839 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13841 if (unformat (i, "size %U", unformat_memory_size, &size))
13848 * Canned custom ring allocator config.
13849 * Should probably parse all of this
13851 vec_validate (config, 6);
13852 config[0].type = VL_API_VLIB_RING;
13853 config[0].size = 256;
13854 config[0].count = 32;
13856 config[1].type = VL_API_VLIB_RING;
13857 config[1].size = 1024;
13858 config[1].count = 16;
13860 config[2].type = VL_API_VLIB_RING;
13861 config[2].size = 4096;
13862 config[2].count = 2;
13864 config[3].type = VL_API_CLIENT_RING;
13865 config[3].size = 256;
13866 config[3].count = 32;
13868 config[4].type = VL_API_CLIENT_RING;
13869 config[4].size = 1024;
13870 config[4].count = 16;
13872 config[5].type = VL_API_CLIENT_RING;
13873 config[5].size = 4096;
13874 config[5].count = 2;
13876 config[6].type = VL_API_QUEUE;
13877 config[6].count = 128;
13878 config[6].size = sizeof (uword);
13880 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
13882 vam->client_index_invalid = 1;
13890 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
13892 vat_main_t *vam = &vat_main;
13893 fib_prefix_t lcl, rmt;
13895 ip_prefix_decode (&mp->lcl, &lcl);
13896 ip_prefix_decode (&mp->rmt, &rmt);
13898 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
13901 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
13902 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
13903 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
13904 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
13905 &rmt.fp_addr.ip4, rmt.fp_len,
13906 clib_net_to_host_u16 (mp->rmt_port),
13907 clib_net_to_host_u32 (mp->action_index), mp->tag);
13912 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
13913 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
13914 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
13915 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
13916 &rmt.fp_addr.ip6, rmt.fp_len,
13917 clib_net_to_host_u16 (mp->rmt_port),
13918 clib_net_to_host_u32 (mp->action_index), mp->tag);
13923 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
13926 vat_main_t *vam = &vat_main;
13927 vat_json_node_t *node = NULL;
13928 struct in6_addr ip6;
13929 struct in_addr ip4;
13931 fib_prefix_t lcl, rmt;
13933 ip_prefix_decode (&mp->lcl, &lcl);
13934 ip_prefix_decode (&mp->rmt, &rmt);
13936 if (VAT_JSON_ARRAY != vam->json_tree.type)
13938 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13939 vat_json_init_array (&vam->json_tree);
13941 node = vat_json_array_add (&vam->json_tree);
13942 vat_json_init_object (node);
13944 vat_json_object_add_uint (node, "appns_index",
13945 clib_net_to_host_u32 (mp->appns_index));
13946 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
13947 vat_json_object_add_uint (node, "scope", mp->scope);
13948 vat_json_object_add_uint (node, "action_index",
13949 clib_net_to_host_u32 (mp->action_index));
13950 vat_json_object_add_uint (node, "lcl_port",
13951 clib_net_to_host_u16 (mp->lcl_port));
13952 vat_json_object_add_uint (node, "rmt_port",
13953 clib_net_to_host_u16 (mp->rmt_port));
13954 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
13955 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
13956 vat_json_object_add_string_copy (node, "tag", mp->tag);
13957 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
13959 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
13960 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
13961 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
13962 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
13966 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
13967 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
13968 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
13969 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
13974 api_session_rule_add_del (vat_main_t * vam)
13976 vl_api_session_rule_add_del_t *mp;
13977 unformat_input_t *i = vam->input;
13978 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
13979 u32 appns_index = 0, scope = 0;
13980 ip4_address_t lcl_ip4, rmt_ip4;
13981 ip6_address_t lcl_ip6, rmt_ip6;
13982 u8 is_ip4 = 1, conn_set = 0;
13983 u8 is_add = 1, *tag = 0;
13985 fib_prefix_t lcl, rmt;
13987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13989 if (unformat (i, "del"))
13991 else if (unformat (i, "add"))
13993 else if (unformat (i, "proto tcp"))
13995 else if (unformat (i, "proto udp"))
13997 else if (unformat (i, "appns %d", &appns_index))
13999 else if (unformat (i, "scope %d", &scope))
14001 else if (unformat (i, "tag %_%v%_", &tag))
14005 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14006 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14014 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14015 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14021 else if (unformat (i, "action %d", &action))
14026 if (proto == ~0 || !conn_set || action == ~0)
14028 errmsg ("transport proto, connection and action must be set");
14034 errmsg ("scope should be 0-3");
14038 M (SESSION_RULE_ADD_DEL, mp);
14040 clib_memset (&lcl, 0, sizeof (lcl));
14041 clib_memset (&rmt, 0, sizeof (rmt));
14044 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14045 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14046 lcl.fp_len = lcl_plen;
14047 rmt.fp_len = rmt_plen;
14051 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14052 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14053 lcl.fp_len = lcl_plen;
14054 rmt.fp_len = rmt_plen;
14058 ip_prefix_encode (&lcl, &mp->lcl);
14059 ip_prefix_encode (&rmt, &mp->rmt);
14060 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14061 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14062 mp->transport_proto =
14063 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14064 mp->action_index = clib_host_to_net_u32 (action);
14065 mp->appns_index = clib_host_to_net_u32 (appns_index);
14067 mp->is_add = is_add;
14070 clib_memcpy (mp->tag, tag, vec_len (tag));
14080 api_session_rules_dump (vat_main_t * vam)
14082 vl_api_session_rules_dump_t *mp;
14083 vl_api_control_ping_t *mp_ping;
14086 if (!vam->json_output)
14088 print (vam->ofp, "%=20s", "Session Rules");
14091 M (SESSION_RULES_DUMP, mp);
14095 /* Use a control ping for synchronization */
14096 MPING (CONTROL_PING, mp_ping);
14099 /* Wait for a reply... */
14105 api_ip_container_proxy_add_del (vat_main_t * vam)
14107 vl_api_ip_container_proxy_add_del_t *mp;
14108 unformat_input_t *i = vam->input;
14109 u32 sw_if_index = ~0;
14110 vl_api_prefix_t pfx = { };
14114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14116 if (unformat (i, "del"))
14118 else if (unformat (i, "add"))
14120 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14122 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14127 if (sw_if_index == ~0 || pfx.len == 0)
14129 errmsg ("address and sw_if_index must be set");
14133 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14135 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14136 mp->is_add = is_add;
14137 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14145 api_qos_record_enable_disable (vat_main_t * vam)
14147 unformat_input_t *i = vam->input;
14148 vl_api_qos_record_enable_disable_t *mp;
14149 u32 sw_if_index, qs = 0xff;
14150 u8 sw_if_index_set = 0;
14154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14156 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14157 sw_if_index_set = 1;
14158 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14159 sw_if_index_set = 1;
14160 else if (unformat (i, "%U", unformat_qos_source, &qs))
14162 else if (unformat (i, "disable"))
14166 clib_warning ("parse error '%U'", format_unformat_error, i);
14171 if (sw_if_index_set == 0)
14173 errmsg ("missing interface name or sw_if_index");
14178 errmsg ("input location must be specified");
14182 M (QOS_RECORD_ENABLE_DISABLE, mp);
14184 mp->record.sw_if_index = ntohl (sw_if_index);
14185 mp->record.input_source = qs;
14186 mp->enable = enable;
14195 q_or_quit (vat_main_t * vam)
14197 #if VPP_API_TEST_BUILTIN == 0
14198 longjmp (vam->jump_buf, 1);
14200 return 0; /* not so much */
14204 q (vat_main_t * vam)
14206 return q_or_quit (vam);
14210 quit (vat_main_t * vam)
14212 return q_or_quit (vam);
14216 comment (vat_main_t * vam)
14222 elog_save (vat_main_t * vam)
14224 #if VPP_API_TEST_BUILTIN == 0
14225 elog_main_t *em = &vam->elog_main;
14226 unformat_input_t *i = vam->input;
14227 char *file, *chroot_file;
14228 clib_error_t *error;
14230 if (!unformat (i, "%s", &file))
14232 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14236 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14237 if (strstr (file, "..") || index (file, '/'))
14239 errmsg ("illegal characters in filename '%s'", file);
14243 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14247 errmsg ("Saving %wd of %wd events to %s",
14248 elog_n_events_in_buffer (em),
14249 elog_buffer_capacity (em), chroot_file);
14251 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14252 vec_free (chroot_file);
14255 clib_error_report (error);
14257 errmsg ("Use the vpp event loger...");
14264 elog_setup (vat_main_t * vam)
14266 #if VPP_API_TEST_BUILTIN == 0
14267 elog_main_t *em = &vam->elog_main;
14268 unformat_input_t *i = vam->input;
14269 u32 nevents = 128 << 10;
14271 (void) unformat (i, "nevents %d", &nevents);
14273 elog_init (em, nevents);
14274 vl_api_set_elog_main (em);
14275 vl_api_set_elog_trace_api_messages (1);
14276 errmsg ("Event logger initialized with %u events", nevents);
14278 errmsg ("Use the vpp event loger...");
14284 elog_enable (vat_main_t * vam)
14286 #if VPP_API_TEST_BUILTIN == 0
14287 elog_main_t *em = &vam->elog_main;
14289 elog_enable_disable (em, 1 /* enable */ );
14290 vl_api_set_elog_trace_api_messages (1);
14291 errmsg ("Event logger enabled...");
14293 errmsg ("Use the vpp event loger...");
14299 elog_disable (vat_main_t * vam)
14301 #if VPP_API_TEST_BUILTIN == 0
14302 elog_main_t *em = &vam->elog_main;
14304 elog_enable_disable (em, 0 /* enable */ );
14305 vl_api_set_elog_trace_api_messages (1);
14306 errmsg ("Event logger disabled...");
14308 errmsg ("Use the vpp event loger...");
14314 statseg (vat_main_t * vam)
14316 ssvm_private_t *ssvmp = &vam->stat_segment;
14317 ssvm_shared_header_t *shared_header = ssvmp->sh;
14318 vlib_counter_t **counters;
14319 u64 thread0_index1_packets;
14320 u64 thread0_index1_bytes;
14321 f64 vector_rate, input_rate;
14324 uword *counter_vector_by_name;
14325 if (vam->stat_segment_lockp == 0)
14327 errmsg ("Stat segment not mapped...");
14331 /* look up "/if/rx for sw_if_index 1 as a test */
14333 clib_spinlock_lock (vam->stat_segment_lockp);
14335 counter_vector_by_name = (uword *) shared_header->opaque[1];
14337 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14340 clib_spinlock_unlock (vam->stat_segment_lockp);
14341 errmsg ("/if/tx not found?");
14345 /* Fish per-thread vector of combined counters from shared memory */
14346 counters = (vlib_counter_t **) p[0];
14348 if (vec_len (counters[0]) < 2)
14350 clib_spinlock_unlock (vam->stat_segment_lockp);
14351 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14355 /* Read thread 0 sw_if_index 1 counter */
14356 thread0_index1_packets = counters[0][1].packets;
14357 thread0_index1_bytes = counters[0][1].bytes;
14359 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14362 clib_spinlock_unlock (vam->stat_segment_lockp);
14363 errmsg ("vector_rate not found?");
14367 vector_rate = *(f64 *) (p[0]);
14368 p = hash_get_mem (counter_vector_by_name, "input_rate");
14371 clib_spinlock_unlock (vam->stat_segment_lockp);
14372 errmsg ("input_rate not found?");
14375 input_rate = *(f64 *) (p[0]);
14377 clib_spinlock_unlock (vam->stat_segment_lockp);
14379 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14380 vector_rate, input_rate);
14381 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14382 thread0_index1_packets, thread0_index1_bytes);
14388 cmd_cmp (void *a1, void *a2)
14393 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14397 help (vat_main_t * vam)
14402 unformat_input_t *i = vam->input;
14405 if (unformat (i, "%s", &name))
14409 vec_add1 (name, 0);
14411 hs = hash_get_mem (vam->help_by_name, name);
14413 print (vam->ofp, "usage: %s %s", name, hs[0]);
14415 print (vam->ofp, "No such msg / command '%s'", name);
14420 print (vam->ofp, "Help is available for the following:");
14423 hash_foreach_pair (p, vam->function_by_name,
14425 vec_add1 (cmds, (u8 *)(p->key));
14429 vec_sort_with_function (cmds, cmd_cmp);
14431 for (j = 0; j < vec_len (cmds); j++)
14432 print (vam->ofp, "%s", cmds[j]);
14439 set (vat_main_t * vam)
14441 u8 *name = 0, *value = 0;
14442 unformat_input_t *i = vam->input;
14444 if (unformat (i, "%s", &name))
14446 /* The input buffer is a vector, not a string. */
14447 value = vec_dup (i->buffer);
14448 vec_delete (value, i->index, 0);
14449 /* Almost certainly has a trailing newline */
14450 if (value[vec_len (value) - 1] == '\n')
14451 value[vec_len (value) - 1] = 0;
14452 /* Make sure it's a proper string, one way or the other */
14453 vec_add1 (value, 0);
14454 (void) clib_macro_set_value (&vam->macro_main,
14455 (char *) name, (char *) value);
14458 errmsg ("usage: set <name> <value>");
14466 unset (vat_main_t * vam)
14470 if (unformat (vam->input, "%s", &name))
14471 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14472 errmsg ("unset: %s wasn't set", name);
14485 macro_sort_cmp (void *a1, void *a2)
14487 macro_sort_t *s1 = a1;
14488 macro_sort_t *s2 = a2;
14490 return strcmp ((char *) (s1->name), (char *) (s2->name));
14494 dump_macro_table (vat_main_t * vam)
14496 macro_sort_t *sort_me = 0, *sm;
14501 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14503 vec_add2 (sort_me, sm, 1);
14504 sm->name = (u8 *)(p->key);
14505 sm->value = (u8 *) (p->value[0]);
14509 vec_sort_with_function (sort_me, macro_sort_cmp);
14511 if (vec_len (sort_me))
14512 print (vam->ofp, "%-15s%s", "Name", "Value");
14514 print (vam->ofp, "The macro table is empty...");
14516 for (i = 0; i < vec_len (sort_me); i++)
14517 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14522 dump_node_table (vat_main_t * vam)
14525 vlib_node_t *node, *next_node;
14527 if (vec_len (vam->graph_nodes) == 0)
14529 print (vam->ofp, "Node table empty, issue get_node_graph...");
14533 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14535 node = vam->graph_nodes[0][i];
14536 print (vam->ofp, "[%d] %s", i, node->name);
14537 for (j = 0; j < vec_len (node->next_nodes); j++)
14539 if (node->next_nodes[j] != ~0)
14541 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14542 print (vam->ofp, " [%d] %s", j, next_node->name);
14550 value_sort_cmp (void *a1, void *a2)
14552 name_sort_t *n1 = a1;
14553 name_sort_t *n2 = a2;
14555 if (n1->value < n2->value)
14557 if (n1->value > n2->value)
14564 dump_msg_api_table (vat_main_t * vam)
14566 api_main_t *am = vlibapi_get_main ();
14567 name_sort_t *nses = 0, *ns;
14572 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14574 vec_add2 (nses, ns, 1);
14575 ns->name = (u8 *)(hp->key);
14576 ns->value = (u32) hp->value[0];
14580 vec_sort_with_function (nses, value_sort_cmp);
14582 for (i = 0; i < vec_len (nses); i++)
14583 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14589 get_msg_id (vat_main_t * vam)
14594 if (unformat (vam->input, "%s", &name_and_crc))
14596 message_index = vl_msg_api_get_msg_index (name_and_crc);
14597 if (message_index == ~0)
14599 print (vam->ofp, " '%s' not found", name_and_crc);
14602 print (vam->ofp, " '%s' has message index %d",
14603 name_and_crc, message_index);
14606 errmsg ("name_and_crc required...");
14611 search_node_table (vat_main_t * vam)
14613 unformat_input_t *line_input = vam->input;
14616 vlib_node_t *node, *next_node;
14619 if (vam->graph_node_index_by_name == 0)
14621 print (vam->ofp, "Node table empty, issue get_node_graph...");
14625 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14627 if (unformat (line_input, "%s", &node_to_find))
14629 vec_add1 (node_to_find, 0);
14630 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14633 print (vam->ofp, "%s not found...", node_to_find);
14636 node = vam->graph_nodes[0][p[0]];
14637 print (vam->ofp, "[%d] %s", p[0], node->name);
14638 for (j = 0; j < vec_len (node->next_nodes); j++)
14640 if (node->next_nodes[j] != ~0)
14642 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14643 print (vam->ofp, " [%d] %s", j, next_node->name);
14650 clib_warning ("parse error '%U'", format_unformat_error,
14656 vec_free (node_to_find);
14665 script (vat_main_t * vam)
14667 #if (VPP_API_TEST_BUILTIN==0)
14669 char *save_current_file;
14670 unformat_input_t save_input;
14671 jmp_buf save_jump_buf;
14672 u32 save_line_number;
14674 FILE *new_fp, *save_ifp;
14676 if (unformat (vam->input, "%s", &s))
14678 new_fp = fopen ((char *) s, "r");
14681 errmsg ("Couldn't open script file %s", s);
14688 errmsg ("Missing script name");
14692 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
14693 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
14694 save_ifp = vam->ifp;
14695 save_line_number = vam->input_line_number;
14696 save_current_file = (char *) vam->current_file;
14698 vam->input_line_number = 0;
14700 vam->current_file = s;
14703 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
14704 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
14705 vam->ifp = save_ifp;
14706 vam->input_line_number = save_line_number;
14707 vam->current_file = (u8 *) save_current_file;
14712 clib_warning ("use the exec command...");
14718 echo (vat_main_t * vam)
14720 print (vam->ofp, "%v", vam->input->buffer);
14724 /* List of API message constructors, CLI names map to api_xxx */
14725 #define foreach_vpe_api_msg \
14726 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
14727 _(sw_interface_dump,"") \
14728 _(sw_interface_set_flags, \
14729 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
14730 _(sw_interface_add_del_address, \
14731 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
14732 _(sw_interface_set_rx_mode, \
14733 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
14734 _(sw_interface_set_rx_placement, \
14735 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
14736 _(sw_interface_rx_placement_dump, \
14737 "[<intfc> | sw_if_index <id>]") \
14738 _(sw_interface_set_table, \
14739 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
14740 _(sw_interface_set_mpls_enable, \
14741 "<intfc> | sw_if_index [disable | dis]") \
14742 _(sw_interface_set_vpath, \
14743 "<intfc> | sw_if_index <id> enable | disable") \
14744 _(sw_interface_set_vxlan_bypass, \
14745 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
14746 _(sw_interface_set_l2_xconnect, \
14747 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14748 "enable | disable") \
14749 _(sw_interface_set_l2_bridge, \
14750 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
14751 "[shg <split-horizon-group>] [bvi]\n" \
14752 "enable | disable") \
14753 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
14754 _(bridge_domain_add_del, \
14755 "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") \
14756 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
14758 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
14759 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
14760 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
14762 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14764 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14766 "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]") \
14768 "<vpp-if-name> | sw_if_index <id>") \
14769 _(sw_interface_tap_v2_dump, "") \
14770 _(virtio_pci_create_v2, \
14771 "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]") \
14772 _(virtio_pci_delete, \
14773 "<vpp-if-name> | sw_if_index <id>") \
14774 _(sw_interface_virtio_pci_dump, "") \
14776 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
14777 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14780 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
14781 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14782 "[id <if-id>] [gso]") \
14784 "<vpp-if-name> | sw_if_index <id>") \
14785 _(bond_add_member, \
14786 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
14787 _(bond_detach_member, \
14788 "sw_if_index <n>") \
14789 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
14790 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
14791 _(sw_member_interface_dump, \
14792 "<vpp-if-name> | sw_if_index <id>") \
14793 _(ip_table_add_del, \
14794 "table <n> [ipv6] [add | del]\n") \
14795 _(ip_route_add_del, \
14796 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
14797 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
14798 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
14799 "[multipath] [count <n>] [del]") \
14800 _(ip_mroute_add_del, \
14801 "<src> <grp>/<mask> [table-id <n>]\n" \
14802 "[<intfc> | sw_if_index <id>] [local] [del]") \
14803 _(mpls_table_add_del, \
14804 "table <n> [add | del]\n") \
14805 _(mpls_route_add_del, \
14806 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
14807 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
14808 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
14809 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
14810 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
14811 "[count <n>] [del]") \
14812 _(mpls_ip_bind_unbind, \
14813 "<label> <addr/len>") \
14814 _(mpls_tunnel_add_del, \
14815 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
14816 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
14817 "[l2-only] [out-label <n>]") \
14818 _(sr_mpls_policy_add, \
14819 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
14820 _(sr_mpls_policy_del, \
14822 _(bier_table_add_del, \
14823 "<label> <sub-domain> <set> <bsl> [del]") \
14824 _(bier_route_add_del, \
14825 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
14826 "[<intfc> | sw_if_index <id>]" \
14827 "[weight <n>] [del] [multipath]") \
14828 _(sw_interface_set_unnumbered, \
14829 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
14830 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
14831 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
14832 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
14833 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
14834 "[outer_vlan_id_any][inner_vlan_id_any]") \
14835 _(ip_table_replace_begin, "table <n> [ipv6]") \
14836 _(ip_table_flush, "table <n> [ipv6]") \
14837 _(ip_table_replace_end, "table <n> [ipv6]") \
14838 _(set_ip_flow_hash, \
14839 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
14840 _(sw_interface_ip6_enable_disable, \
14841 "<intfc> | sw_if_index <id> enable | disable") \
14842 _(l2_patch_add_del, \
14843 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14844 "enable | disable") \
14845 _(sr_localsid_add_del, \
14846 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
14847 "fib-table <num> (end.psp) sw_if_index <num>") \
14848 _(classify_add_del_table, \
14849 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
14850 " [del] [del-chain] mask <mask-value>\n" \
14851 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
14852 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
14853 _(classify_add_del_session, \
14854 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
14855 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
14856 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
14857 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
14858 _(classify_set_interface_ip_table, \
14859 "<intfc> | sw_if_index <nn> table <nn>") \
14860 _(classify_set_interface_l2_tables, \
14861 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14862 " [other-table <nn>]") \
14863 _(get_node_index, "node <node-name") \
14864 _(add_node_next, "node <node-name> next <next-node-name>") \
14865 _(vxlan_offload_rx, \
14866 "hw { <interface name> | hw_if_index <nn>} " \
14867 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
14868 _(vxlan_add_del_tunnel, \
14869 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
14870 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
14871 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
14872 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14873 _(l2_fib_clear_table, "") \
14874 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
14875 _(l2_interface_vlan_tag_rewrite, \
14876 "<intfc> | sw_if_index <nn> \n" \
14877 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
14878 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
14879 _(create_vhost_user_if, \
14880 "socket <filename> [server] [renumber <dev_instance>] " \
14881 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14882 "[mac <mac_address>] [packed]") \
14883 _(modify_vhost_user_if, \
14884 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14885 "[server] [renumber <dev_instance>] [gso] [packed]") \
14886 _(create_vhost_user_if_v2, \
14887 "socket <filename> [server] [renumber <dev_instance>] " \
14888 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14889 "[mac <mac_address>] [packed] [event-idx]") \
14890 _(modify_vhost_user_if_v2, \
14891 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14892 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
14893 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
14894 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
14895 _(show_version, "") \
14896 _(show_threads, "") \
14897 _(vxlan_gpe_add_del_tunnel, \
14898 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
14899 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
14900 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
14901 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
14902 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14903 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
14904 _(interface_name_renumber, \
14905 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
14906 _(input_acl_set_interface, \
14907 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14908 " [l2-table <nn>] [del]") \
14909 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
14910 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
14911 _(ip_dump, "ipv4 | ipv6") \
14912 _(ipsec_spd_add_del, "spd_id <n> [del]") \
14913 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
14915 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
14916 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
14917 " integ_alg <alg> integ_key <hex>") \
14918 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
14919 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
14920 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
14921 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
14922 _(ipsec_sa_dump, "[sa_id <n>]") \
14923 _(delete_loopback,"sw_if_index <nn>") \
14924 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
14925 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
14926 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
14927 _(want_interface_events, "enable|disable") \
14928 _(get_first_msg_id, "client <name>") \
14929 _(get_node_graph, " ") \
14930 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
14931 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
14932 _(ioam_disable, "") \
14933 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
14934 _(af_packet_delete, "name <host interface name>") \
14935 _(af_packet_dump, "") \
14936 _(policer_add_del, "name <policer name> <params> [del]") \
14937 _(policer_dump, "[name <policer name>]") \
14938 _(policer_classify_set_interface, \
14939 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14940 " [l2-table <nn>] [del]") \
14941 _(policer_classify_dump, "type [ip4|ip6|l2]") \
14942 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
14943 _(mpls_table_dump, "") \
14944 _(mpls_route_dump, "table-id <ID>") \
14945 _(classify_table_ids, "") \
14946 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
14947 _(classify_table_info, "table_id <nn>") \
14948 _(classify_session_dump, "table_id <nn>") \
14949 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
14950 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
14951 "[template_interval <nn>] [udp_checksum]") \
14952 _(ipfix_exporter_dump, "") \
14953 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
14954 _(ipfix_classify_stream_dump, "") \
14955 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
14956 _(ipfix_classify_table_dump, "") \
14957 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
14958 _(sw_interface_span_dump, "[l2]") \
14959 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
14960 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
14961 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
14962 _(pg_enable_disable, "[stream <id>] disable") \
14963 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
14964 _(ip_source_and_port_range_check_add_del, \
14965 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
14966 _(ip_source_and_port_range_check_interface_add_del, \
14967 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
14968 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
14969 _(delete_subif,"<intfc> | sw_if_index <nn>") \
14970 _(l2_interface_pbb_tag_rewrite, \
14971 "<intfc> | sw_if_index <nn> \n" \
14972 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
14973 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
14974 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
14975 _(flow_classify_set_interface, \
14976 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
14977 _(flow_classify_dump, "type [ip4|ip6]") \
14978 _(ip_table_dump, "") \
14979 _(ip_route_dump, "table-id [ip4|ip6]") \
14980 _(ip_mtable_dump, "") \
14981 _(ip_mroute_dump, "table-id [ip4|ip6]") \
14982 _(feature_enable_disable, "arc_name <arc_name> " \
14983 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
14984 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
14985 "[enable | disable] ") \
14986 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
14988 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
14989 "mac <mac-address> [del]") \
14990 _(l2_xconnect_dump, "") \
14991 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
14992 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
14993 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
14994 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
14995 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
14996 _(sock_init_shm, "size <nnn>") \
14997 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
14998 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
14999 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15000 _(session_rules_dump, "") \
15001 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15002 _(output_acl_set_interface, \
15003 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15004 " [l2-table <nn>] [del]") \
15005 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15007 /* List of command functions, CLI names map directly to functions */
15008 #define foreach_cli_function \
15009 _(comment, "usage: comment <ignore-rest-of-line>") \
15010 _(dump_interface_table, "usage: dump_interface_table") \
15011 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15012 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15013 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15014 _(dump_macro_table, "usage: dump_macro_table ") \
15015 _(dump_node_table, "usage: dump_node_table") \
15016 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15017 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15018 _(elog_disable, "usage: elog_disable") \
15019 _(elog_enable, "usage: elog_enable") \
15020 _(elog_save, "usage: elog_save <filename>") \
15021 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15022 _(echo, "usage: echo <message>") \
15023 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15024 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15025 _(help, "usage: help") \
15026 _(q, "usage: quit") \
15027 _(quit, "usage: quit") \
15028 _(search_node_table, "usage: search_node_table <name>...") \
15029 _(set, "usage: set <variable-name> <value>") \
15030 _(script, "usage: script <file-name>") \
15031 _(statseg, "usage: statseg") \
15032 _(unset, "usage: unset <variable-name>")
15035 static void vl_api_##n##_t_handler_uni \
15036 (vl_api_##n##_t * mp) \
15038 vat_main_t * vam = &vat_main; \
15039 if (vam->json_output) { \
15040 vl_api_##n##_t_handler_json(mp); \
15042 vl_api_##n##_t_handler(mp); \
15045 foreach_vpe_api_reply_msg;
15046 #if VPP_API_TEST_BUILTIN == 0
15047 foreach_standalone_reply_msg;
15052 vat_api_hookup (vat_main_t * vam)
15055 vl_msg_api_set_handlers(VL_API_##N, #n, \
15056 vl_api_##n##_t_handler_uni, \
15058 vl_api_##n##_t_endian, \
15059 vl_api_##n##_t_print, \
15060 sizeof(vl_api_##n##_t), 1);
15061 foreach_vpe_api_reply_msg;
15062 #if VPP_API_TEST_BUILTIN == 0
15063 foreach_standalone_reply_msg;
15067 #if (VPP_API_TEST_BUILTIN==0)
15068 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15070 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15072 vam->function_by_name = hash_create_string (0, sizeof (uword));
15074 vam->help_by_name = hash_create_string (0, sizeof (uword));
15077 /* API messages we can send */
15078 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15079 foreach_vpe_api_msg;
15083 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15084 foreach_vpe_api_msg;
15087 /* CLI functions */
15088 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15089 foreach_cli_function;
15093 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15094 foreach_cli_function;
15098 #if VPP_API_TEST_BUILTIN
15099 static clib_error_t *
15100 vat_api_hookup_shim (vlib_main_t * vm)
15102 vat_api_hookup (&vat_main);
15106 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15110 * fd.io coding-style-patch-verification: ON
15113 * eval: (c-set-style "gnu")