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 _(cop_interface_enable_disable_reply) \
3298 _(cop_whitelist_enable_disable_reply) \
3299 _(sw_interface_clear_stats_reply) \
3300 _(ioam_enable_reply) \
3301 _(ioam_disable_reply) \
3302 _(af_packet_delete_reply) \
3303 _(policer_classify_set_interface_reply) \
3304 _(set_ipfix_exporter_reply) \
3305 _(set_ipfix_classify_stream_reply) \
3306 _(ipfix_classify_table_add_del_reply) \
3307 _(flow_classify_set_interface_reply) \
3308 _(sw_interface_span_enable_disable_reply) \
3309 _(pg_capture_reply) \
3310 _(pg_enable_disable_reply) \
3311 _(pg_interface_enable_disable_coalesce_reply) \
3312 _(ip_source_and_port_range_check_add_del_reply) \
3313 _(ip_source_and_port_range_check_interface_add_del_reply)\
3314 _(delete_subif_reply) \
3315 _(l2_interface_pbb_tag_rewrite_reply) \
3317 _(feature_enable_disable_reply) \
3318 _(feature_gso_enable_disable_reply) \
3319 _(sw_interface_tag_add_del_reply) \
3320 _(sw_interface_add_del_mac_address_reply) \
3321 _(hw_interface_set_mtu_reply) \
3322 _(p2p_ethernet_add_reply) \
3323 _(p2p_ethernet_del_reply) \
3324 _(tcp_configure_src_addresses_reply) \
3325 _(session_rule_add_del_reply) \
3326 _(ip_container_proxy_add_del_reply) \
3327 _(output_acl_set_interface_reply) \
3328 _(qos_record_enable_disable_reply) \
3332 static void vl_api_##n##_t_handler \
3333 (vl_api_##n##_t * mp) \
3335 vat_main_t * vam = &vat_main; \
3336 i32 retval = ntohl(mp->retval); \
3337 if (vam->async_mode) { \
3338 vam->async_errors += (retval < 0); \
3340 vam->retval = retval; \
3341 vam->result_ready = 1; \
3344 foreach_standard_reply_retval_handler;
3348 static void vl_api_##n##_t_handler_json \
3349 (vl_api_##n##_t * mp) \
3351 vat_main_t * vam = &vat_main; \
3352 vat_json_node_t node; \
3353 vat_json_init_object(&node); \
3354 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3355 vat_json_print(vam->ofp, &node); \
3356 vam->retval = ntohl(mp->retval); \
3357 vam->result_ready = 1; \
3359 foreach_standard_reply_retval_handler;
3363 * Table of message reply handlers, must include boilerplate handlers
3367 #define foreach_vpe_api_reply_msg \
3368 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3369 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3370 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3371 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3372 _(CONTROL_PING_REPLY, control_ping_reply) \
3373 _(CLI_REPLY, cli_reply) \
3374 _(CLI_INBAND_REPLY, cli_inband_reply) \
3375 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3376 sw_interface_add_del_address_reply) \
3377 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3378 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3379 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3380 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3381 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3382 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3383 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3384 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3385 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3386 sw_interface_set_l2_xconnect_reply) \
3387 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3388 sw_interface_set_l2_bridge_reply) \
3389 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3390 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3391 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3392 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3393 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3394 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3395 _(L2_FLAGS_REPLY, l2_flags_reply) \
3396 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3397 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3398 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3399 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3400 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3401 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3402 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3403 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3404 _(BOND_CREATE_REPLY, bond_create_reply) \
3405 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3406 _(BOND_DELETE_REPLY, bond_delete_reply) \
3407 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3408 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3409 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3410 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3411 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3412 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3413 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3414 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3415 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3416 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3417 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3418 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3419 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3420 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3421 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3422 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3423 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3424 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3425 sw_interface_set_unnumbered_reply) \
3426 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3427 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3428 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3429 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3430 sw_interface_ip6_enable_disable_reply) \
3431 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3432 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3433 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3434 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3435 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3436 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3437 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3438 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3439 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3440 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3441 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3442 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3443 classify_set_interface_ip_table_reply) \
3444 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3445 classify_set_interface_l2_tables_reply) \
3446 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3447 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3448 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3449 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3450 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3451 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3452 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3453 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3454 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3455 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3456 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3457 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
3458 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
3459 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3460 _(SHOW_VERSION_REPLY, show_version_reply) \
3461 _(SHOW_THREADS_REPLY, show_threads_reply) \
3462 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3463 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3464 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3465 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3466 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3467 _(L2_MACS_EVENT, l2_macs_event) \
3468 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3469 _(IP_ADDRESS_DETAILS, ip_address_details) \
3470 _(IP_DETAILS, ip_details) \
3471 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3472 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3473 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3474 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3475 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3476 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3477 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3478 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3479 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3480 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3481 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3482 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3483 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3484 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3485 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3486 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3487 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3488 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3489 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3490 _(AF_PACKET_DETAILS, af_packet_details) \
3491 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3492 _(POLICER_DETAILS, policer_details) \
3493 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3494 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3495 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3496 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3497 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3498 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3499 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3500 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3501 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3502 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3503 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3504 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3505 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3506 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3507 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3508 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3509 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3510 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3511 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3512 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3513 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3514 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3515 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3516 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3517 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3518 ip_source_and_port_range_check_add_del_reply) \
3519 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3520 ip_source_and_port_range_check_interface_add_del_reply) \
3521 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3522 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3523 _(SET_PUNT_REPLY, set_punt_reply) \
3524 _(IP_TABLE_DETAILS, ip_table_details) \
3525 _(IP_ROUTE_DETAILS, ip_route_details) \
3526 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3527 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3528 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3529 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3530 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3531 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3532 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3533 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3534 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3535 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3536 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3537 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3538 _(SESSION_RULES_DETAILS, session_rules_details) \
3539 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3540 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3541 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3542 _(FLOW_ADD_REPLY, flow_add_reply) \
3544 #define foreach_standalone_reply_msg \
3545 _(SW_INTERFACE_EVENT, sw_interface_event)
3553 #define STR_VTR_OP_CASE(op) \
3554 case L2_VTR_ ## op: \
3558 str_vtr_op (u32 vtr_op)
3562 STR_VTR_OP_CASE (DISABLED);
3563 STR_VTR_OP_CASE (PUSH_1);
3564 STR_VTR_OP_CASE (PUSH_2);
3565 STR_VTR_OP_CASE (POP_1);
3566 STR_VTR_OP_CASE (POP_2);
3567 STR_VTR_OP_CASE (TRANSLATE_1_1);
3568 STR_VTR_OP_CASE (TRANSLATE_1_2);
3569 STR_VTR_OP_CASE (TRANSLATE_2_1);
3570 STR_VTR_OP_CASE (TRANSLATE_2_2);
3577 dump_sub_interface_table (vat_main_t * vam)
3579 const sw_interface_subif_t *sub = NULL;
3581 if (vam->json_output)
3584 ("JSON output supported only for VPE API calls and dump_stats_table");
3589 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3590 "Interface", "sw_if_index",
3591 "sub id", "dot1ad", "tags", "outer id",
3592 "inner id", "exact", "default", "outer any", "inner any");
3594 vec_foreach (sub, vam->sw_if_subif_table)
3597 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3598 sub->interface_name,
3600 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3601 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3602 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3603 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3604 if (sub->vtr_op != L2_VTR_DISABLED)
3607 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3608 "tag1: %d tag2: %d ]",
3609 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3610 sub->vtr_tag1, sub->vtr_tag2);
3618 name_sort_cmp (void *a1, void *a2)
3620 name_sort_t *n1 = a1;
3621 name_sort_t *n2 = a2;
3623 return strcmp ((char *) n1->name, (char *) n2->name);
3627 dump_interface_table (vat_main_t * vam)
3630 name_sort_t *nses = 0, *ns;
3632 if (vam->json_output)
3635 ("JSON output supported only for VPE API calls and dump_stats_table");
3640 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3642 vec_add2 (nses, ns, 1);
3643 ns->name = (u8 *)(p->key);
3644 ns->value = (u32) p->value[0];
3648 vec_sort_with_function (nses, name_sort_cmp);
3650 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3651 vec_foreach (ns, nses)
3653 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3660 dump_ip_table (vat_main_t * vam, int is_ipv6)
3662 const ip_details_t *det = NULL;
3663 const ip_address_details_t *address = NULL;
3666 print (vam->ofp, "%-12s", "sw_if_index");
3668 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3675 print (vam->ofp, "%-12d", i);
3676 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3681 vec_foreach (address, det->addr)
3685 is_ipv6 ? format_ip6_address : format_ip4_address,
3686 address->ip, address->prefix_length);
3694 dump_ipv4_table (vat_main_t * vam)
3696 if (vam->json_output)
3699 ("JSON output supported only for VPE API calls and dump_stats_table");
3703 return dump_ip_table (vam, 0);
3707 dump_ipv6_table (vat_main_t * vam)
3709 if (vam->json_output)
3712 ("JSON output supported only for VPE API calls and dump_stats_table");
3716 return dump_ip_table (vam, 1);
3720 * Pass CLI buffers directly in the CLI_INBAND API message,
3721 * instead of an additional shared memory area.
3724 exec_inband (vat_main_t * vam)
3726 vl_api_cli_inband_t *mp;
3727 unformat_input_t *i = vam->input;
3730 if (vec_len (i->buffer) == 0)
3733 if (vam->exec_mode == 0 && unformat (i, "mode"))
3738 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3745 * In order for the CLI command to work, it
3746 * must be a vector ending in \n, not a C-string ending
3749 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3750 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3754 /* json responses may or may not include a useful reply... */
3755 if (vec_len (vam->cmd_reply))
3756 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3761 exec (vat_main_t * vam)
3763 return exec_inband (vam);
3767 api_create_loopback (vat_main_t * vam)
3769 unformat_input_t *i = vam->input;
3770 vl_api_create_loopback_t *mp;
3771 vl_api_create_loopback_instance_t *mp_lbi;
3774 u8 is_specified = 0;
3775 u32 user_instance = 0;
3778 clib_memset (mac_address, 0, sizeof (mac_address));
3780 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3782 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3784 if (unformat (i, "instance %d", &user_instance))
3792 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3793 mp_lbi->is_specified = is_specified;
3795 mp_lbi->user_instance = htonl (user_instance);
3797 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3802 /* Construct the API message */
3803 M (CREATE_LOOPBACK, mp);
3805 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3814 api_delete_loopback (vat_main_t * vam)
3816 unformat_input_t *i = vam->input;
3817 vl_api_delete_loopback_t *mp;
3818 u32 sw_if_index = ~0;
3821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3823 if (unformat (i, "sw_if_index %d", &sw_if_index))
3829 if (sw_if_index == ~0)
3831 errmsg ("missing sw_if_index");
3835 /* Construct the API message */
3836 M (DELETE_LOOPBACK, mp);
3837 mp->sw_if_index = ntohl (sw_if_index);
3845 api_want_interface_events (vat_main_t * vam)
3847 unformat_input_t *i = vam->input;
3848 vl_api_want_interface_events_t *mp;
3852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3854 if (unformat (i, "enable"))
3856 else if (unformat (i, "disable"))
3864 errmsg ("missing enable|disable");
3868 M (WANT_INTERFACE_EVENTS, mp);
3869 mp->enable_disable = enable;
3871 vam->interface_event_display = enable;
3879 /* Note: non-static, called once to set up the initial intfc table */
3881 api_sw_interface_dump (vat_main_t * vam)
3883 vl_api_sw_interface_dump_t *mp;
3884 vl_api_control_ping_t *mp_ping;
3886 name_sort_t *nses = 0, *ns;
3887 sw_interface_subif_t *sub = NULL;
3890 /* Toss the old name table */
3892 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3894 vec_add2 (nses, ns, 1);
3895 ns->name = (u8 *)(p->key);
3896 ns->value = (u32) p->value[0];
3900 hash_free (vam->sw_if_index_by_interface_name);
3902 vec_foreach (ns, nses) vec_free (ns->name);
3906 vec_foreach (sub, vam->sw_if_subif_table)
3908 vec_free (sub->interface_name);
3910 vec_free (vam->sw_if_subif_table);
3912 /* recreate the interface name hash table */
3913 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3916 * Ask for all interface names. Otherwise, the epic catalog of
3917 * name filters becomes ridiculously long, and vat ends up needing
3918 * to be taught about new interface types.
3920 M (SW_INTERFACE_DUMP, mp);
3923 /* Use a control ping for synchronization */
3924 MPING (CONTROL_PING, mp_ping);
3932 api_sw_interface_set_flags (vat_main_t * vam)
3934 unformat_input_t *i = vam->input;
3935 vl_api_sw_interface_set_flags_t *mp;
3937 u8 sw_if_index_set = 0;
3941 /* Parse args required to build the message */
3942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3944 if (unformat (i, "admin-up"))
3946 else if (unformat (i, "admin-down"))
3949 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3950 sw_if_index_set = 1;
3951 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3952 sw_if_index_set = 1;
3957 if (sw_if_index_set == 0)
3959 errmsg ("missing interface name or sw_if_index");
3963 /* Construct the API message */
3964 M (SW_INTERFACE_SET_FLAGS, mp);
3965 mp->sw_if_index = ntohl (sw_if_index);
3966 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3971 /* Wait for a reply, return the good/bad news... */
3977 api_sw_interface_set_rx_mode (vat_main_t * vam)
3979 unformat_input_t *i = vam->input;
3980 vl_api_sw_interface_set_rx_mode_t *mp;
3982 u8 sw_if_index_set = 0;
3984 u8 queue_id_valid = 0;
3986 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3988 /* Parse args required to build the message */
3989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3991 if (unformat (i, "queue %d", &queue_id))
3993 else if (unformat (i, "polling"))
3994 mode = VNET_HW_IF_RX_MODE_POLLING;
3995 else if (unformat (i, "interrupt"))
3996 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3997 else if (unformat (i, "adaptive"))
3998 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
4000 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4001 sw_if_index_set = 1;
4002 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4003 sw_if_index_set = 1;
4008 if (sw_if_index_set == 0)
4010 errmsg ("missing interface name or sw_if_index");
4013 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
4015 errmsg ("missing rx-mode");
4019 /* Construct the API message */
4020 M (SW_INTERFACE_SET_RX_MODE, mp);
4021 mp->sw_if_index = ntohl (sw_if_index);
4022 mp->mode = (vl_api_rx_mode_t) mode;
4023 mp->queue_id_valid = queue_id_valid;
4024 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
4029 /* Wait for a reply, return the good/bad news... */
4035 api_sw_interface_set_rx_placement (vat_main_t * vam)
4037 unformat_input_t *i = vam->input;
4038 vl_api_sw_interface_set_rx_placement_t *mp;
4040 u8 sw_if_index_set = 0;
4043 u32 queue_id, thread_index;
4045 /* Parse args required to build the message */
4046 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4048 if (unformat (i, "queue %d", &queue_id))
4050 else if (unformat (i, "main"))
4052 else if (unformat (i, "worker %d", &thread_index))
4055 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4056 sw_if_index_set = 1;
4057 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4058 sw_if_index_set = 1;
4063 if (sw_if_index_set == 0)
4065 errmsg ("missing interface name or sw_if_index");
4071 /* Construct the API message */
4072 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4073 mp->sw_if_index = ntohl (sw_if_index);
4074 mp->worker_id = ntohl (thread_index);
4075 mp->queue_id = ntohl (queue_id);
4076 mp->is_main = is_main;
4080 /* Wait for a reply, return the good/bad news... */
4085 static void vl_api_sw_interface_rx_placement_details_t_handler
4086 (vl_api_sw_interface_rx_placement_details_t * mp)
4088 vat_main_t *vam = &vat_main;
4089 u32 worker_id = ntohl (mp->worker_id);
4092 "\n%-11d %-11s %-6d %-5d %-9s",
4093 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4094 worker_id, ntohl (mp->queue_id),
4096 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4099 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4100 (vl_api_sw_interface_rx_placement_details_t * mp)
4102 vat_main_t *vam = &vat_main;
4103 vat_json_node_t *node = NULL;
4105 if (VAT_JSON_ARRAY != vam->json_tree.type)
4107 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4108 vat_json_init_array (&vam->json_tree);
4110 node = vat_json_array_add (&vam->json_tree);
4112 vat_json_init_object (node);
4113 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4114 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4115 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4116 vat_json_object_add_uint (node, "mode", mp->mode);
4120 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4122 unformat_input_t *i = vam->input;
4123 vl_api_sw_interface_rx_placement_dump_t *mp;
4124 vl_api_control_ping_t *mp_ping;
4127 u8 sw_if_index_set = 0;
4129 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4131 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4133 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4140 "\n%-11s %-11s %-6s %-5s %-4s",
4141 "sw_if_index", "main/worker", "thread", "queue", "mode");
4143 /* Dump Interface rx placement */
4144 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4146 if (sw_if_index_set)
4147 mp->sw_if_index = htonl (sw_if_index);
4149 mp->sw_if_index = ~0;
4153 /* Use a control ping for synchronization */
4154 MPING (CONTROL_PING, mp_ping);
4162 api_sw_interface_clear_stats (vat_main_t * vam)
4164 unformat_input_t *i = vam->input;
4165 vl_api_sw_interface_clear_stats_t *mp;
4167 u8 sw_if_index_set = 0;
4170 /* Parse args required to build the message */
4171 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4173 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4174 sw_if_index_set = 1;
4175 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4176 sw_if_index_set = 1;
4181 /* Construct the API message */
4182 M (SW_INTERFACE_CLEAR_STATS, mp);
4184 if (sw_if_index_set == 1)
4185 mp->sw_if_index = ntohl (sw_if_index);
4187 mp->sw_if_index = ~0;
4192 /* Wait for a reply, return the good/bad news... */
4198 api_sw_interface_add_del_address (vat_main_t * vam)
4200 unformat_input_t *i = vam->input;
4201 vl_api_sw_interface_add_del_address_t *mp;
4203 u8 sw_if_index_set = 0;
4204 u8 is_add = 1, del_all = 0;
4205 u32 address_length = 0;
4206 u8 v4_address_set = 0;
4207 u8 v6_address_set = 0;
4208 ip4_address_t v4address;
4209 ip6_address_t v6address;
4212 /* Parse args required to build the message */
4213 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4215 if (unformat (i, "del-all"))
4217 else if (unformat (i, "del"))
4220 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4221 sw_if_index_set = 1;
4222 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4223 sw_if_index_set = 1;
4224 else if (unformat (i, "%U/%d",
4225 unformat_ip4_address, &v4address, &address_length))
4227 else if (unformat (i, "%U/%d",
4228 unformat_ip6_address, &v6address, &address_length))
4234 if (sw_if_index_set == 0)
4236 errmsg ("missing interface name or sw_if_index");
4239 if (v4_address_set && v6_address_set)
4241 errmsg ("both v4 and v6 addresses set");
4244 if (!v4_address_set && !v6_address_set && !del_all)
4246 errmsg ("no addresses set");
4250 /* Construct the API message */
4251 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4253 mp->sw_if_index = ntohl (sw_if_index);
4254 mp->is_add = is_add;
4255 mp->del_all = del_all;
4258 mp->prefix.address.af = ADDRESS_IP6;
4259 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4263 mp->prefix.address.af = ADDRESS_IP4;
4264 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4266 mp->prefix.len = address_length;
4271 /* Wait for a reply, return good/bad news */
4277 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4279 unformat_input_t *i = vam->input;
4280 vl_api_sw_interface_set_mpls_enable_t *mp;
4282 u8 sw_if_index_set = 0;
4286 /* Parse args required to build the message */
4287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4289 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4290 sw_if_index_set = 1;
4291 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4292 sw_if_index_set = 1;
4293 else if (unformat (i, "disable"))
4295 else if (unformat (i, "dis"))
4301 if (sw_if_index_set == 0)
4303 errmsg ("missing interface name or sw_if_index");
4307 /* Construct the API message */
4308 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4310 mp->sw_if_index = ntohl (sw_if_index);
4311 mp->enable = enable;
4316 /* Wait for a reply... */
4322 api_sw_interface_set_table (vat_main_t * vam)
4324 unformat_input_t *i = vam->input;
4325 vl_api_sw_interface_set_table_t *mp;
4326 u32 sw_if_index, vrf_id = 0;
4327 u8 sw_if_index_set = 0;
4331 /* Parse args required to build the message */
4332 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4334 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4335 sw_if_index_set = 1;
4336 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4337 sw_if_index_set = 1;
4338 else if (unformat (i, "vrf %d", &vrf_id))
4340 else if (unformat (i, "ipv6"))
4346 if (sw_if_index_set == 0)
4348 errmsg ("missing interface name or sw_if_index");
4352 /* Construct the API message */
4353 M (SW_INTERFACE_SET_TABLE, mp);
4355 mp->sw_if_index = ntohl (sw_if_index);
4356 mp->is_ipv6 = is_ipv6;
4357 mp->vrf_id = ntohl (vrf_id);
4362 /* Wait for a reply... */
4367 static void vl_api_sw_interface_get_table_reply_t_handler
4368 (vl_api_sw_interface_get_table_reply_t * mp)
4370 vat_main_t *vam = &vat_main;
4372 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4374 vam->retval = ntohl (mp->retval);
4375 vam->result_ready = 1;
4379 static void vl_api_sw_interface_get_table_reply_t_handler_json
4380 (vl_api_sw_interface_get_table_reply_t * mp)
4382 vat_main_t *vam = &vat_main;
4383 vat_json_node_t node;
4385 vat_json_init_object (&node);
4386 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4387 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4389 vat_json_print (vam->ofp, &node);
4390 vat_json_free (&node);
4392 vam->retval = ntohl (mp->retval);
4393 vam->result_ready = 1;
4397 api_sw_interface_get_table (vat_main_t * vam)
4399 unformat_input_t *i = vam->input;
4400 vl_api_sw_interface_get_table_t *mp;
4402 u8 sw_if_index_set = 0;
4406 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4408 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4409 sw_if_index_set = 1;
4410 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4411 sw_if_index_set = 1;
4412 else if (unformat (i, "ipv6"))
4418 if (sw_if_index_set == 0)
4420 errmsg ("missing interface name or sw_if_index");
4424 M (SW_INTERFACE_GET_TABLE, mp);
4425 mp->sw_if_index = htonl (sw_if_index);
4426 mp->is_ipv6 = is_ipv6;
4434 api_sw_interface_set_vpath (vat_main_t * vam)
4436 unformat_input_t *i = vam->input;
4437 vl_api_sw_interface_set_vpath_t *mp;
4438 u32 sw_if_index = 0;
4439 u8 sw_if_index_set = 0;
4443 /* Parse args required to build the message */
4444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4446 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4447 sw_if_index_set = 1;
4448 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4449 sw_if_index_set = 1;
4450 else if (unformat (i, "enable"))
4452 else if (unformat (i, "disable"))
4458 if (sw_if_index_set == 0)
4460 errmsg ("missing interface name or sw_if_index");
4464 /* Construct the API message */
4465 M (SW_INTERFACE_SET_VPATH, mp);
4467 mp->sw_if_index = ntohl (sw_if_index);
4468 mp->enable = is_enable;
4473 /* Wait for a reply... */
4479 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4481 unformat_input_t *i = vam->input;
4482 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4483 u32 sw_if_index = 0;
4484 u8 sw_if_index_set = 0;
4489 /* Parse args required to build the message */
4490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4492 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4493 sw_if_index_set = 1;
4494 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4495 sw_if_index_set = 1;
4496 else if (unformat (i, "enable"))
4498 else if (unformat (i, "disable"))
4500 else if (unformat (i, "ip4"))
4502 else if (unformat (i, "ip6"))
4508 if (sw_if_index_set == 0)
4510 errmsg ("missing interface name or sw_if_index");
4514 /* Construct the API message */
4515 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4517 mp->sw_if_index = ntohl (sw_if_index);
4518 mp->enable = is_enable;
4519 mp->is_ipv6 = is_ipv6;
4524 /* Wait for a reply... */
4530 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4532 unformat_input_t *i = vam->input;
4533 vl_api_sw_interface_set_l2_xconnect_t *mp;
4535 u8 rx_sw_if_index_set = 0;
4537 u8 tx_sw_if_index_set = 0;
4541 /* Parse args required to build the message */
4542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4544 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4545 rx_sw_if_index_set = 1;
4546 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4547 tx_sw_if_index_set = 1;
4548 else if (unformat (i, "rx"))
4550 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4552 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4554 rx_sw_if_index_set = 1;
4559 else if (unformat (i, "tx"))
4561 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4563 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4565 tx_sw_if_index_set = 1;
4570 else if (unformat (i, "enable"))
4572 else if (unformat (i, "disable"))
4578 if (rx_sw_if_index_set == 0)
4580 errmsg ("missing rx interface name or rx_sw_if_index");
4584 if (enable && (tx_sw_if_index_set == 0))
4586 errmsg ("missing tx interface name or tx_sw_if_index");
4590 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4592 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4593 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4594 mp->enable = enable;
4602 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4604 unformat_input_t *i = vam->input;
4605 vl_api_sw_interface_set_l2_bridge_t *mp;
4606 vl_api_l2_port_type_t port_type;
4608 u8 rx_sw_if_index_set = 0;
4615 port_type = L2_API_PORT_TYPE_NORMAL;
4617 /* Parse args required to build the message */
4618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4620 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4621 rx_sw_if_index_set = 1;
4622 else if (unformat (i, "bd_id %d", &bd_id))
4626 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4627 rx_sw_if_index_set = 1;
4628 else if (unformat (i, "shg %d", &shg))
4630 else if (unformat (i, "bvi"))
4631 port_type = L2_API_PORT_TYPE_BVI;
4632 else if (unformat (i, "uu-fwd"))
4633 port_type = L2_API_PORT_TYPE_UU_FWD;
4634 else if (unformat (i, "enable"))
4636 else if (unformat (i, "disable"))
4642 if (rx_sw_if_index_set == 0)
4644 errmsg ("missing rx interface name or sw_if_index");
4648 if (enable && (bd_id_set == 0))
4650 errmsg ("missing bridge domain");
4654 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4656 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4657 mp->bd_id = ntohl (bd_id);
4659 mp->port_type = ntohl (port_type);
4660 mp->enable = enable;
4668 api_bridge_domain_dump (vat_main_t * vam)
4670 unformat_input_t *i = vam->input;
4671 vl_api_bridge_domain_dump_t *mp;
4672 vl_api_control_ping_t *mp_ping;
4676 /* Parse args required to build the message */
4677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4679 if (unformat (i, "bd_id %d", &bd_id))
4685 M (BRIDGE_DOMAIN_DUMP, mp);
4686 mp->bd_id = ntohl (bd_id);
4689 /* Use a control ping for synchronization */
4690 MPING (CONTROL_PING, mp_ping);
4698 api_bridge_domain_add_del (vat_main_t * vam)
4700 unformat_input_t *i = vam->input;
4701 vl_api_bridge_domain_add_del_t *mp;
4704 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4709 /* Parse args required to build the message */
4710 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4712 if (unformat (i, "bd_id %d", &bd_id))
4714 else if (unformat (i, "flood %d", &flood))
4716 else if (unformat (i, "uu-flood %d", &uu_flood))
4718 else if (unformat (i, "forward %d", &forward))
4720 else if (unformat (i, "learn %d", &learn))
4722 else if (unformat (i, "arp-term %d", &arp_term))
4724 else if (unformat (i, "mac-age %d", &mac_age))
4726 else if (unformat (i, "bd-tag %s", &bd_tag))
4728 else if (unformat (i, "del"))
4731 flood = uu_flood = forward = learn = 0;
4739 errmsg ("missing bridge domain");
4746 errmsg ("mac age must be less than 256 ");
4751 if ((bd_tag) && (vec_len (bd_tag) > 63))
4753 errmsg ("bd-tag cannot be longer than 63");
4758 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4760 mp->bd_id = ntohl (bd_id);
4762 mp->uu_flood = uu_flood;
4763 mp->forward = forward;
4765 mp->arp_term = arp_term;
4766 mp->is_add = is_add;
4767 mp->mac_age = (u8) mac_age;
4770 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4771 mp->bd_tag[vec_len (bd_tag)] = 0;
4782 api_l2fib_flush_bd (vat_main_t * vam)
4784 unformat_input_t *i = vam->input;
4785 vl_api_l2fib_flush_bd_t *mp;
4789 /* Parse args required to build the message */
4790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4792 if (unformat (i, "bd_id %d", &bd_id));
4799 errmsg ("missing bridge domain");
4803 M (L2FIB_FLUSH_BD, mp);
4805 mp->bd_id = htonl (bd_id);
4813 api_l2fib_flush_int (vat_main_t * vam)
4815 unformat_input_t *i = vam->input;
4816 vl_api_l2fib_flush_int_t *mp;
4817 u32 sw_if_index = ~0;
4820 /* Parse args required to build the message */
4821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4823 if (unformat (i, "sw_if_index %d", &sw_if_index));
4825 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4830 if (sw_if_index == ~0)
4832 errmsg ("missing interface name or sw_if_index");
4836 M (L2FIB_FLUSH_INT, mp);
4838 mp->sw_if_index = ntohl (sw_if_index);
4846 api_l2fib_add_del (vat_main_t * vam)
4848 unformat_input_t *i = vam->input;
4849 vl_api_l2fib_add_del_t *mp;
4855 u32 sw_if_index = 0;
4856 u8 sw_if_index_set = 0;
4865 /* Parse args required to build the message */
4866 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4868 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4870 else if (unformat (i, "bd_id %d", &bd_id))
4872 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4873 sw_if_index_set = 1;
4874 else if (unformat (i, "sw_if"))
4876 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4879 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4880 sw_if_index_set = 1;
4885 else if (unformat (i, "static"))
4887 else if (unformat (i, "filter"))
4892 else if (unformat (i, "bvi"))
4897 else if (unformat (i, "del"))
4899 else if (unformat (i, "count %d", &count))
4907 errmsg ("missing mac address");
4913 errmsg ("missing bridge domain");
4917 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4919 errmsg ("missing interface name or sw_if_index");
4925 /* Turn on async mode */
4926 vam->async_mode = 1;
4927 vam->async_errors = 0;
4928 before = vat_time_now (vam);
4931 for (j = 0; j < count; j++)
4933 M (L2FIB_ADD_DEL, mp);
4935 clib_memcpy (mp->mac, mac, 6);
4936 mp->bd_id = ntohl (bd_id);
4937 mp->is_add = is_add;
4938 mp->sw_if_index = ntohl (sw_if_index);
4942 mp->static_mac = static_mac;
4943 mp->filter_mac = filter_mac;
4944 mp->bvi_mac = bvi_mac;
4946 increment_mac_address (mac);
4953 vl_api_control_ping_t *mp_ping;
4956 /* Shut off async mode */
4957 vam->async_mode = 0;
4959 MPING (CONTROL_PING, mp_ping);
4962 timeout = vat_time_now (vam) + 1.0;
4963 while (vat_time_now (vam) < timeout)
4964 if (vam->result_ready == 1)
4969 if (vam->retval == -99)
4972 if (vam->async_errors > 0)
4974 errmsg ("%d asynchronous errors", vam->async_errors);
4977 vam->async_errors = 0;
4978 after = vat_time_now (vam);
4980 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4981 count, after - before, count / (after - before));
4987 /* Wait for a reply... */
4991 /* Return the good/bad news */
4992 return (vam->retval);
4996 api_bridge_domain_set_mac_age (vat_main_t * vam)
4998 unformat_input_t *i = vam->input;
4999 vl_api_bridge_domain_set_mac_age_t *mp;
5004 /* Parse args required to build the message */
5005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5007 if (unformat (i, "bd_id %d", &bd_id));
5008 else if (unformat (i, "mac-age %d", &mac_age));
5015 errmsg ("missing bridge domain");
5021 errmsg ("mac age must be less than 256 ");
5025 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
5027 mp->bd_id = htonl (bd_id);
5028 mp->mac_age = (u8) mac_age;
5036 api_l2_flags (vat_main_t * vam)
5038 unformat_input_t *i = vam->input;
5039 vl_api_l2_flags_t *mp;
5042 u8 sw_if_index_set = 0;
5046 /* Parse args required to build the message */
5047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5049 if (unformat (i, "sw_if_index %d", &sw_if_index))
5050 sw_if_index_set = 1;
5051 else if (unformat (i, "sw_if"))
5053 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5056 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5057 sw_if_index_set = 1;
5062 else if (unformat (i, "learn"))
5064 else if (unformat (i, "forward"))
5066 else if (unformat (i, "flood"))
5068 else if (unformat (i, "uu-flood"))
5069 flags |= L2_UU_FLOOD;
5070 else if (unformat (i, "arp-term"))
5071 flags |= L2_ARP_TERM;
5072 else if (unformat (i, "off"))
5074 else if (unformat (i, "disable"))
5080 if (sw_if_index_set == 0)
5082 errmsg ("missing interface name or sw_if_index");
5088 mp->sw_if_index = ntohl (sw_if_index);
5089 mp->feature_bitmap = ntohl (flags);
5090 mp->is_set = is_set;
5098 api_bridge_flags (vat_main_t * vam)
5100 unformat_input_t *i = vam->input;
5101 vl_api_bridge_flags_t *mp;
5105 bd_flags_t flags = 0;
5108 /* Parse args required to build the message */
5109 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5111 if (unformat (i, "bd_id %d", &bd_id))
5113 else if (unformat (i, "learn"))
5114 flags |= BRIDGE_API_FLAG_LEARN;
5115 else if (unformat (i, "forward"))
5116 flags |= BRIDGE_API_FLAG_FWD;
5117 else if (unformat (i, "flood"))
5118 flags |= BRIDGE_API_FLAG_FLOOD;
5119 else if (unformat (i, "uu-flood"))
5120 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5121 else if (unformat (i, "arp-term"))
5122 flags |= BRIDGE_API_FLAG_ARP_TERM;
5123 else if (unformat (i, "off"))
5125 else if (unformat (i, "disable"))
5133 errmsg ("missing bridge domain");
5137 M (BRIDGE_FLAGS, mp);
5139 mp->bd_id = ntohl (bd_id);
5140 mp->flags = ntohl (flags);
5141 mp->is_set = is_set;
5149 api_bd_ip_mac_add_del (vat_main_t * vam)
5151 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5152 vl_api_mac_address_t mac = { 0 };
5153 unformat_input_t *i = vam->input;
5154 vl_api_bd_ip_mac_add_del_t *mp;
5163 /* Parse args required to build the message */
5164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5166 if (unformat (i, "bd_id %d", &bd_id))
5170 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5174 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5178 else if (unformat (i, "del"))
5186 errmsg ("missing bridge domain");
5189 else if (ip_set == 0)
5191 errmsg ("missing IP address");
5194 else if (mac_set == 0)
5196 errmsg ("missing MAC address");
5200 M (BD_IP_MAC_ADD_DEL, mp);
5202 mp->entry.bd_id = ntohl (bd_id);
5203 mp->is_add = is_add;
5205 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5206 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5214 api_bd_ip_mac_flush (vat_main_t * vam)
5216 unformat_input_t *i = vam->input;
5217 vl_api_bd_ip_mac_flush_t *mp;
5222 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5224 if (unformat (i, "bd_id %d", &bd_id))
5234 errmsg ("missing bridge domain");
5238 M (BD_IP_MAC_FLUSH, mp);
5240 mp->bd_id = ntohl (bd_id);
5247 static void vl_api_bd_ip_mac_details_t_handler
5248 (vl_api_bd_ip_mac_details_t * mp)
5250 vat_main_t *vam = &vat_main;
5254 ntohl (mp->entry.bd_id),
5255 format_vl_api_mac_address, mp->entry.mac,
5256 format_vl_api_address, &mp->entry.ip);
5259 static void vl_api_bd_ip_mac_details_t_handler_json
5260 (vl_api_bd_ip_mac_details_t * mp)
5262 vat_main_t *vam = &vat_main;
5263 vat_json_node_t *node = NULL;
5265 if (VAT_JSON_ARRAY != vam->json_tree.type)
5267 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5268 vat_json_init_array (&vam->json_tree);
5270 node = vat_json_array_add (&vam->json_tree);
5272 vat_json_init_object (node);
5273 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5274 vat_json_object_add_string_copy (node, "mac_address",
5275 format (0, "%U", format_vl_api_mac_address,
5279 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5280 vat_json_object_add_string_copy (node, "ip_address", ip);
5285 api_bd_ip_mac_dump (vat_main_t * vam)
5287 unformat_input_t *i = vam->input;
5288 vl_api_bd_ip_mac_dump_t *mp;
5289 vl_api_control_ping_t *mp_ping;
5294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5296 if (unformat (i, "bd_id %d", &bd_id))
5305 "\n%-5s %-7s %-20s %-30s",
5306 "bd_id", "is_ipv6", "mac_address", "ip_address");
5308 /* Dump Bridge Domain Ip to Mac entries */
5309 M (BD_IP_MAC_DUMP, mp);
5312 mp->bd_id = htonl (bd_id);
5318 /* Use a control ping for synchronization */
5319 MPING (CONTROL_PING, mp_ping);
5327 api_tap_create_v2 (vat_main_t * vam)
5329 unformat_input_t *i = vam->input;
5330 vl_api_tap_create_v2_t *mp;
5334 u32 num_rx_queues = 0;
5335 u8 *host_if_name = 0;
5336 u8 host_if_name_set = 0;
5339 u8 host_mac_addr[6];
5340 u8 host_mac_addr_set = 0;
5341 u8 *host_bridge = 0;
5342 u8 host_bridge_set = 0;
5343 u8 host_ip4_prefix_set = 0;
5344 u8 host_ip6_prefix_set = 0;
5345 ip4_address_t host_ip4_addr;
5346 ip4_address_t host_ip4_gw;
5347 u8 host_ip4_gw_set = 0;
5348 u32 host_ip4_prefix_len = 0;
5349 ip6_address_t host_ip6_addr;
5350 ip6_address_t host_ip6_gw;
5351 u8 host_ip6_gw_set = 0;
5352 u32 host_ip6_prefix_len = 0;
5353 u32 host_mtu_size = 0;
5354 u8 host_mtu_set = 0;
5357 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5359 clib_memset (mac_address, 0, sizeof (mac_address));
5361 /* Parse args required to build the message */
5362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5364 if (unformat (i, "id %u", &id))
5368 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5370 else if (unformat (i, "host-if-name %s", &host_if_name))
5371 host_if_name_set = 1;
5372 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5374 else if (unformat (i, "host-ns %s", &host_ns))
5376 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5378 host_mac_addr_set = 1;
5379 else if (unformat (i, "host-bridge %s", &host_bridge))
5380 host_bridge_set = 1;
5381 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5382 &host_ip4_addr, &host_ip4_prefix_len))
5383 host_ip4_prefix_set = 1;
5384 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5385 &host_ip6_addr, &host_ip6_prefix_len))
5386 host_ip6_prefix_set = 1;
5387 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5389 host_ip4_gw_set = 1;
5390 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5392 host_ip6_gw_set = 1;
5393 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5395 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5397 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5399 else if (unformat (i, "no-gso"))
5400 tap_flags &= ~TAP_API_FLAG_GSO;
5401 else if (unformat (i, "gso"))
5402 tap_flags |= TAP_API_FLAG_GSO;
5403 else if (unformat (i, "csum-offload"))
5404 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5405 else if (unformat (i, "persist"))
5406 tap_flags |= TAP_API_FLAG_PERSIST;
5407 else if (unformat (i, "attach"))
5408 tap_flags |= TAP_API_FLAG_ATTACH;
5409 else if (unformat (i, "tun"))
5410 tap_flags |= TAP_API_FLAG_TUN;
5411 else if (unformat (i, "gro-coalesce"))
5412 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5413 else if (unformat (i, "packed"))
5414 tap_flags |= TAP_API_FLAG_PACKED;
5415 else if (unformat (i, "in-order"))
5416 tap_flags |= TAP_API_FLAG_IN_ORDER;
5421 if (vec_len (host_if_name) > 63)
5423 errmsg ("tap name too long. ");
5426 if (vec_len (host_ns) > 63)
5428 errmsg ("host name space too long. ");
5431 if (vec_len (host_bridge) > 63)
5433 errmsg ("host bridge name too long. ");
5436 if (host_ip4_prefix_len > 32)
5438 errmsg ("host ip4 prefix length not valid. ");
5441 if (host_ip6_prefix_len > 128)
5443 errmsg ("host ip6 prefix length not valid. ");
5446 if (!is_pow2 (rx_ring_sz))
5448 errmsg ("rx ring size must be power of 2. ");
5451 if (rx_ring_sz > 32768)
5453 errmsg ("rx ring size must be 32768 or lower. ");
5456 if (!is_pow2 (tx_ring_sz))
5458 errmsg ("tx ring size must be power of 2. ");
5461 if (tx_ring_sz > 32768)
5463 errmsg ("tx ring size must be 32768 or lower. ");
5466 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5468 errmsg ("host MTU size must be in between 64 and 65355. ");
5472 /* Construct the API message */
5473 M (TAP_CREATE_V2, mp);
5475 mp->id = ntohl (id);
5476 mp->use_random_mac = random_mac;
5477 mp->num_rx_queues = (u8) num_rx_queues;
5478 mp->tx_ring_sz = ntohs (tx_ring_sz);
5479 mp->rx_ring_sz = ntohs (rx_ring_sz);
5480 mp->host_mtu_set = host_mtu_set;
5481 mp->host_mtu_size = ntohl (host_mtu_size);
5482 mp->host_mac_addr_set = host_mac_addr_set;
5483 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5484 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5485 mp->host_ip4_gw_set = host_ip4_gw_set;
5486 mp->host_ip6_gw_set = host_ip6_gw_set;
5487 mp->tap_flags = ntohl (tap_flags);
5488 mp->host_namespace_set = host_ns_set;
5489 mp->host_if_name_set = host_if_name_set;
5490 mp->host_bridge_set = host_bridge_set;
5492 if (random_mac == 0)
5493 clib_memcpy (mp->mac_address, mac_address, 6);
5494 if (host_mac_addr_set)
5495 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5496 if (host_if_name_set)
5497 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5499 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5500 if (host_bridge_set)
5501 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5502 if (host_ip4_prefix_set)
5504 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5505 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5507 if (host_ip6_prefix_set)
5509 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5510 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5512 if (host_ip4_gw_set)
5513 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5514 if (host_ip6_gw_set)
5515 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5518 vec_free (host_if_name);
5519 vec_free (host_bridge);
5524 /* Wait for a reply... */
5530 api_tap_delete_v2 (vat_main_t * vam)
5532 unformat_input_t *i = vam->input;
5533 vl_api_tap_delete_v2_t *mp;
5534 u32 sw_if_index = ~0;
5535 u8 sw_if_index_set = 0;
5538 /* Parse args required to build the message */
5539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5541 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5542 sw_if_index_set = 1;
5543 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5544 sw_if_index_set = 1;
5549 if (sw_if_index_set == 0)
5551 errmsg ("missing vpp interface name. ");
5555 /* Construct the API message */
5556 M (TAP_DELETE_V2, mp);
5558 mp->sw_if_index = ntohl (sw_if_index);
5563 /* Wait for a reply... */
5569 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5571 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5574 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5577 addr->domain = x[0];
5580 addr->function = x[3];
5586 api_virtio_pci_create_v2 (vat_main_t * vam)
5588 unformat_input_t *i = vam->input;
5589 vl_api_virtio_pci_create_v2_t *mp;
5593 u64 features = (u64) ~ (0ULL);
5594 u32 virtio_flags = 0;
5597 clib_memset (mac_address, 0, sizeof (mac_address));
5599 /* Parse args required to build the message */
5600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5602 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5606 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5608 else if (unformat (i, "features 0x%llx", &features))
5610 else if (unformat (i, "gso-enabled"))
5611 virtio_flags |= VIRTIO_API_FLAG_GSO;
5612 else if (unformat (i, "csum-offload-enabled"))
5613 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5614 else if (unformat (i, "gro-coalesce"))
5615 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5616 else if (unformat (i, "packed"))
5617 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5618 else if (unformat (i, "in-order"))
5619 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5620 else if (unformat (i, "buffering"))
5621 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5628 errmsg ("pci address must be non zero. ");
5632 /* Construct the API message */
5633 M (VIRTIO_PCI_CREATE_V2, mp);
5635 mp->use_random_mac = random_mac;
5637 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5638 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5639 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5640 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5642 mp->features = clib_host_to_net_u64 (features);
5643 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5645 if (random_mac == 0)
5646 clib_memcpy (mp->mac_address, mac_address, 6);
5651 /* Wait for a reply... */
5657 api_virtio_pci_delete (vat_main_t * vam)
5659 unformat_input_t *i = vam->input;
5660 vl_api_virtio_pci_delete_t *mp;
5661 u32 sw_if_index = ~0;
5662 u8 sw_if_index_set = 0;
5665 /* Parse args required to build the message */
5666 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5668 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5669 sw_if_index_set = 1;
5670 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5671 sw_if_index_set = 1;
5676 if (sw_if_index_set == 0)
5678 errmsg ("missing vpp interface name. ");
5682 /* Construct the API message */
5683 M (VIRTIO_PCI_DELETE, mp);
5685 mp->sw_if_index = htonl (sw_if_index);
5690 /* Wait for a reply... */
5696 api_bond_create (vat_main_t * vam)
5698 unformat_input_t *i = vam->input;
5699 vl_api_bond_create_t *mp;
5709 clib_memset (mac_address, 0, sizeof (mac_address));
5712 /* Parse args required to build the message */
5713 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5715 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5717 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5718 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5720 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5723 else if (unformat (i, "numa-only"))
5725 else if (unformat (i, "id %u", &id))
5731 if (mode_is_set == 0)
5733 errmsg ("Missing bond mode. ");
5737 /* Construct the API message */
5738 M (BOND_CREATE, mp);
5740 mp->use_custom_mac = custom_mac;
5742 mp->mode = htonl (mode);
5743 mp->lb = htonl (lb);
5744 mp->id = htonl (id);
5745 mp->numa_only = numa_only;
5748 clib_memcpy (mp->mac_address, mac_address, 6);
5753 /* Wait for a reply... */
5759 api_bond_create2 (vat_main_t * vam)
5761 unformat_input_t *i = vam->input;
5762 vl_api_bond_create2_t *mp;
5773 clib_memset (mac_address, 0, sizeof (mac_address));
5776 /* Parse args required to build the message */
5777 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5779 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5781 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5782 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5784 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5787 else if (unformat (i, "numa-only"))
5789 else if (unformat (i, "gso"))
5791 else if (unformat (i, "id %u", &id))
5797 if (mode_is_set == 0)
5799 errmsg ("Missing bond mode. ");
5803 /* Construct the API message */
5804 M (BOND_CREATE2, mp);
5806 mp->use_custom_mac = custom_mac;
5808 mp->mode = htonl (mode);
5809 mp->lb = htonl (lb);
5810 mp->id = htonl (id);
5811 mp->numa_only = numa_only;
5812 mp->enable_gso = gso;
5815 clib_memcpy (mp->mac_address, mac_address, 6);
5820 /* Wait for a reply... */
5826 api_bond_delete (vat_main_t * vam)
5828 unformat_input_t *i = vam->input;
5829 vl_api_bond_delete_t *mp;
5830 u32 sw_if_index = ~0;
5831 u8 sw_if_index_set = 0;
5834 /* Parse args required to build the message */
5835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5837 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5838 sw_if_index_set = 1;
5839 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5840 sw_if_index_set = 1;
5845 if (sw_if_index_set == 0)
5847 errmsg ("missing vpp interface name. ");
5851 /* Construct the API message */
5852 M (BOND_DELETE, mp);
5854 mp->sw_if_index = ntohl (sw_if_index);
5859 /* Wait for a reply... */
5865 api_bond_add_member (vat_main_t * vam)
5867 unformat_input_t *i = vam->input;
5868 vl_api_bond_add_member_t *mp;
5869 u32 bond_sw_if_index;
5873 u32 bond_sw_if_index_is_set = 0;
5875 u8 sw_if_index_is_set = 0;
5877 /* Parse args required to build the message */
5878 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5880 if (unformat (i, "sw_if_index %d", &sw_if_index))
5881 sw_if_index_is_set = 1;
5882 else if (unformat (i, "bond %u", &bond_sw_if_index))
5883 bond_sw_if_index_is_set = 1;
5884 else if (unformat (i, "passive %d", &is_passive))
5886 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5892 if (bond_sw_if_index_is_set == 0)
5894 errmsg ("Missing bond sw_if_index. ");
5897 if (sw_if_index_is_set == 0)
5899 errmsg ("Missing member sw_if_index. ");
5903 /* Construct the API message */
5904 M (BOND_ADD_MEMBER, mp);
5906 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5907 mp->sw_if_index = ntohl (sw_if_index);
5908 mp->is_long_timeout = is_long_timeout;
5909 mp->is_passive = is_passive;
5914 /* Wait for a reply... */
5920 api_bond_detach_member (vat_main_t * vam)
5922 unformat_input_t *i = vam->input;
5923 vl_api_bond_detach_member_t *mp;
5924 u32 sw_if_index = ~0;
5925 u8 sw_if_index_set = 0;
5928 /* Parse args required to build the message */
5929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5931 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5932 sw_if_index_set = 1;
5933 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5934 sw_if_index_set = 1;
5939 if (sw_if_index_set == 0)
5941 errmsg ("missing vpp interface name. ");
5945 /* Construct the API message */
5946 M (BOND_DETACH_MEMBER, mp);
5948 mp->sw_if_index = ntohl (sw_if_index);
5953 /* Wait for a reply... */
5959 api_ip_table_add_del (vat_main_t * vam)
5961 unformat_input_t *i = vam->input;
5962 vl_api_ip_table_add_del_t *mp;
5968 /* Parse args required to build the message */
5969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5971 if (unformat (i, "ipv6"))
5973 else if (unformat (i, "del"))
5975 else if (unformat (i, "add"))
5977 else if (unformat (i, "table %d", &table_id))
5981 clib_warning ("parse error '%U'", format_unformat_error, i);
5988 errmsg ("missing table-ID");
5992 /* Construct the API message */
5993 M (IP_TABLE_ADD_DEL, mp);
5995 mp->table.table_id = ntohl (table_id);
5996 mp->table.is_ip6 = is_ipv6;
5997 mp->is_add = is_add;
6002 /* Wait for a reply... */
6009 unformat_fib_path (unformat_input_t * input, va_list * args)
6011 vat_main_t *vam = va_arg (*args, vat_main_t *);
6012 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
6013 u32 weight, preference;
6014 mpls_label_t out_label;
6016 clib_memset (path, 0, sizeof (*path));
6018 path->sw_if_index = ~0;
6022 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6024 if (unformat (input, "%U %U",
6025 unformat_vl_api_ip4_address,
6026 &path->nh.address.ip4,
6027 api_unformat_sw_if_index, vam, &path->sw_if_index))
6029 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6031 else if (unformat (input, "%U %U",
6032 unformat_vl_api_ip6_address,
6033 &path->nh.address.ip6,
6034 api_unformat_sw_if_index, vam, &path->sw_if_index))
6036 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6038 else if (unformat (input, "weight %u", &weight))
6040 path->weight = weight;
6042 else if (unformat (input, "preference %u", &preference))
6044 path->preference = preference;
6046 else if (unformat (input, "%U next-hop-table %d",
6047 unformat_vl_api_ip4_address,
6048 &path->nh.address.ip4, &path->table_id))
6050 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6052 else if (unformat (input, "%U next-hop-table %d",
6053 unformat_vl_api_ip6_address,
6054 &path->nh.address.ip6, &path->table_id))
6056 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6058 else if (unformat (input, "%U",
6059 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6062 * the recursive next-hops are by default in the default table
6065 path->sw_if_index = ~0;
6066 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6068 else if (unformat (input, "%U",
6069 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6072 * the recursive next-hops are by default in the default table
6075 path->sw_if_index = ~0;
6076 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6078 else if (unformat (input, "resolve-via-host"))
6080 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6082 else if (unformat (input, "resolve-via-attached"))
6084 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6086 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6088 path->type = FIB_API_PATH_TYPE_LOCAL;
6089 path->sw_if_index = ~0;
6090 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6092 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6094 path->type = FIB_API_PATH_TYPE_LOCAL;
6095 path->sw_if_index = ~0;
6096 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6098 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6100 else if (unformat (input, "via-label %d", &path->nh.via_label))
6102 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6103 path->sw_if_index = ~0;
6105 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6107 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6108 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6110 else if (unformat (input, "local"))
6112 path->type = FIB_API_PATH_TYPE_LOCAL;
6114 else if (unformat (input, "out-labels"))
6116 while (unformat (input, "%d", &out_label))
6118 path->label_stack[path->n_labels].label = out_label;
6119 path->label_stack[path->n_labels].is_uniform = 0;
6120 path->label_stack[path->n_labels].ttl = 64;
6124 else if (unformat (input, "via"))
6126 /* new path, back up and return */
6127 unformat_put_input (input);
6128 unformat_put_input (input);
6129 unformat_put_input (input);
6130 unformat_put_input (input);
6139 path->proto = ntohl (path->proto);
6140 path->type = ntohl (path->type);
6141 path->flags = ntohl (path->flags);
6142 path->table_id = ntohl (path->table_id);
6143 path->sw_if_index = ntohl (path->sw_if_index);
6149 api_ip_route_add_del (vat_main_t * vam)
6151 unformat_input_t *i = vam->input;
6152 vl_api_ip_route_add_del_t *mp;
6155 u8 is_multipath = 0;
6158 vl_api_prefix_t pfx = { };
6159 vl_api_fib_path_t paths[8];
6163 u32 random_add_del = 0;
6164 u32 *random_vector = 0;
6165 u32 random_seed = 0xdeaddabe;
6167 /* Parse args required to build the message */
6168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6170 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6172 else if (unformat (i, "del"))
6174 else if (unformat (i, "add"))
6176 else if (unformat (i, "vrf %d", &vrf_id))
6178 else if (unformat (i, "count %d", &count))
6180 else if (unformat (i, "random"))
6182 else if (unformat (i, "multipath"))
6184 else if (unformat (i, "seed %d", &random_seed))
6188 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6191 if (8 == path_count)
6193 errmsg ("max 8 paths");
6199 clib_warning ("parse error '%U'", format_unformat_error, i);
6206 errmsg ("specify a path; via ...");
6209 if (prefix_set == 0)
6211 errmsg ("missing prefix");
6215 /* Generate a pile of unique, random routes */
6218 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6219 u32 this_random_address;
6222 random_hash = hash_create (count, sizeof (uword));
6224 hash_set (random_hash, i->as_u32, 1);
6225 for (j = 0; j <= count; j++)
6229 this_random_address = random_u32 (&random_seed);
6230 this_random_address =
6231 clib_host_to_net_u32 (this_random_address);
6233 while (hash_get (random_hash, this_random_address));
6234 vec_add1 (random_vector, this_random_address);
6235 hash_set (random_hash, this_random_address, 1);
6237 hash_free (random_hash);
6238 set_ip4_address (&pfx.address, random_vector[0]);
6243 /* Turn on async mode */
6244 vam->async_mode = 1;
6245 vam->async_errors = 0;
6246 before = vat_time_now (vam);
6249 for (j = 0; j < count; j++)
6251 /* Construct the API message */
6252 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6254 mp->is_add = is_add;
6255 mp->is_multipath = is_multipath;
6257 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6258 mp->route.table_id = ntohl (vrf_id);
6259 mp->route.n_paths = path_count;
6261 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6264 set_ip4_address (&pfx.address, random_vector[j + 1]);
6266 increment_address (&pfx.address);
6269 /* If we receive SIGTERM, stop now... */
6274 /* When testing multiple add/del ops, use a control-ping to sync */
6277 vl_api_control_ping_t *mp_ping;
6281 /* Shut off async mode */
6282 vam->async_mode = 0;
6284 MPING (CONTROL_PING, mp_ping);
6287 timeout = vat_time_now (vam) + 1.0;
6288 while (vat_time_now (vam) < timeout)
6289 if (vam->result_ready == 1)
6294 if (vam->retval == -99)
6297 if (vam->async_errors > 0)
6299 errmsg ("%d asynchronous errors", vam->async_errors);
6302 vam->async_errors = 0;
6303 after = vat_time_now (vam);
6305 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6309 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6310 count, after - before, count / (after - before));
6316 /* Wait for a reply... */
6321 /* Return the good/bad news */
6322 return (vam->retval);
6326 api_ip_mroute_add_del (vat_main_t * vam)
6328 unformat_input_t *i = vam->input;
6329 u8 path_set = 0, prefix_set = 0, is_add = 1;
6330 vl_api_ip_mroute_add_del_t *mp;
6331 mfib_entry_flags_t eflags = 0;
6332 vl_api_mfib_path_t path;
6333 vl_api_mprefix_t pfx = { };
6337 /* Parse args required to build the message */
6338 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6340 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6343 pfx.grp_address_length = htons (pfx.grp_address_length);
6345 else if (unformat (i, "del"))
6347 else if (unformat (i, "add"))
6349 else if (unformat (i, "vrf %d", &vrf_id))
6351 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6352 path.itf_flags = htonl (path.itf_flags);
6353 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6355 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6359 clib_warning ("parse error '%U'", format_unformat_error, i);
6364 if (prefix_set == 0)
6366 errmsg ("missing addresses\n");
6371 errmsg ("missing path\n");
6375 /* Construct the API message */
6376 M (IP_MROUTE_ADD_DEL, mp);
6378 mp->is_add = is_add;
6379 mp->is_multipath = 1;
6381 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6382 mp->route.table_id = htonl (vrf_id);
6383 mp->route.n_paths = 1;
6384 mp->route.entry_flags = htonl (eflags);
6386 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6390 /* Wait for a reply... */
6396 api_mpls_table_add_del (vat_main_t * vam)
6398 unformat_input_t *i = vam->input;
6399 vl_api_mpls_table_add_del_t *mp;
6404 /* Parse args required to build the message */
6405 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6407 if (unformat (i, "table %d", &table_id))
6409 else if (unformat (i, "del"))
6411 else if (unformat (i, "add"))
6415 clib_warning ("parse error '%U'", format_unformat_error, i);
6422 errmsg ("missing table-ID");
6426 /* Construct the API message */
6427 M (MPLS_TABLE_ADD_DEL, mp);
6429 mp->mt_table.mt_table_id = ntohl (table_id);
6430 mp->mt_is_add = is_add;
6435 /* Wait for a reply... */
6442 api_mpls_route_add_del (vat_main_t * vam)
6444 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6445 mpls_label_t local_label = MPLS_LABEL_INVALID;
6446 unformat_input_t *i = vam->input;
6447 vl_api_mpls_route_add_del_t *mp;
6448 vl_api_fib_path_t paths[8];
6452 /* Parse args required to build the message */
6453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6455 if (unformat (i, "%d", &local_label))
6457 else if (unformat (i, "eos"))
6459 else if (unformat (i, "non-eos"))
6461 else if (unformat (i, "del"))
6463 else if (unformat (i, "add"))
6465 else if (unformat (i, "multipath"))
6467 else if (unformat (i, "count %d", &count))
6471 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6474 if (8 == path_count)
6476 errmsg ("max 8 paths");
6482 clib_warning ("parse error '%U'", format_unformat_error, i);
6489 errmsg ("specify a path; via ...");
6493 if (MPLS_LABEL_INVALID == local_label)
6495 errmsg ("missing label");
6501 /* Turn on async mode */
6502 vam->async_mode = 1;
6503 vam->async_errors = 0;
6504 before = vat_time_now (vam);
6507 for (j = 0; j < count; j++)
6509 /* Construct the API message */
6510 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6512 mp->mr_is_add = is_add;
6513 mp->mr_is_multipath = is_multipath;
6515 mp->mr_route.mr_label = local_label;
6516 mp->mr_route.mr_eos = is_eos;
6517 mp->mr_route.mr_table_id = 0;
6518 mp->mr_route.mr_n_paths = path_count;
6520 clib_memcpy (&mp->mr_route.mr_paths, paths,
6521 sizeof (paths[0]) * path_count);
6527 /* If we receive SIGTERM, stop now... */
6532 /* When testing multiple add/del ops, use a control-ping to sync */
6535 vl_api_control_ping_t *mp_ping;
6539 /* Shut off async mode */
6540 vam->async_mode = 0;
6542 MPING (CONTROL_PING, mp_ping);
6545 timeout = vat_time_now (vam) + 1.0;
6546 while (vat_time_now (vam) < timeout)
6547 if (vam->result_ready == 1)
6552 if (vam->retval == -99)
6555 if (vam->async_errors > 0)
6557 errmsg ("%d asynchronous errors", vam->async_errors);
6560 vam->async_errors = 0;
6561 after = vat_time_now (vam);
6563 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6567 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6568 count, after - before, count / (after - before));
6574 /* Wait for a reply... */
6579 /* Return the good/bad news */
6580 return (vam->retval);
6585 api_mpls_ip_bind_unbind (vat_main_t * vam)
6587 unformat_input_t *i = vam->input;
6588 vl_api_mpls_ip_bind_unbind_t *mp;
6589 u32 ip_table_id = 0;
6591 vl_api_prefix_t pfx;
6593 mpls_label_t local_label = MPLS_LABEL_INVALID;
6596 /* Parse args required to build the message */
6597 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6599 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6601 else if (unformat (i, "%d", &local_label))
6603 else if (unformat (i, "table-id %d", &ip_table_id))
6605 else if (unformat (i, "unbind"))
6607 else if (unformat (i, "bind"))
6611 clib_warning ("parse error '%U'", format_unformat_error, i);
6618 errmsg ("IP prefix not set");
6622 if (MPLS_LABEL_INVALID == local_label)
6624 errmsg ("missing label");
6628 /* Construct the API message */
6629 M (MPLS_IP_BIND_UNBIND, mp);
6631 mp->mb_is_bind = is_bind;
6632 mp->mb_ip_table_id = ntohl (ip_table_id);
6633 mp->mb_mpls_table_id = 0;
6634 mp->mb_label = ntohl (local_label);
6635 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6640 /* Wait for a reply... */
6647 api_sr_mpls_policy_add (vat_main_t * vam)
6649 unformat_input_t *i = vam->input;
6650 vl_api_sr_mpls_policy_add_t *mp;
6656 u32 *segments = NULL;
6659 /* Parse args required to build the message */
6660 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6662 if (unformat (i, "bsid %d", &bsid))
6664 else if (unformat (i, "weight %d", &weight))
6666 else if (unformat (i, "spray"))
6668 else if (unformat (i, "next %d", &sid))
6671 vec_add1 (segments, htonl (sid));
6675 clib_warning ("parse error '%U'", format_unformat_error, i);
6682 errmsg ("bsid not set");
6686 if (n_segments == 0)
6688 errmsg ("no sid in segment stack");
6692 /* Construct the API message */
6693 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6695 mp->bsid = htonl (bsid);
6696 mp->weight = htonl (weight);
6697 mp->is_spray = type;
6698 mp->n_segments = n_segments;
6699 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6700 vec_free (segments);
6705 /* Wait for a reply... */
6711 api_sr_mpls_policy_del (vat_main_t * vam)
6713 unformat_input_t *i = vam->input;
6714 vl_api_sr_mpls_policy_del_t *mp;
6718 /* Parse args required to build the message */
6719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6721 if (unformat (i, "bsid %d", &bsid))
6725 clib_warning ("parse error '%U'", format_unformat_error, i);
6732 errmsg ("bsid not set");
6736 /* Construct the API message */
6737 M (SR_MPLS_POLICY_DEL, mp);
6739 mp->bsid = htonl (bsid);
6744 /* Wait for a reply... */
6750 api_bier_table_add_del (vat_main_t * vam)
6752 unformat_input_t *i = vam->input;
6753 vl_api_bier_table_add_del_t *mp;
6755 u32 set = 0, sub_domain = 0, hdr_len = 3;
6756 mpls_label_t local_label = MPLS_LABEL_INVALID;
6759 /* Parse args required to build the message */
6760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6762 if (unformat (i, "sub-domain %d", &sub_domain))
6764 else if (unformat (i, "set %d", &set))
6766 else if (unformat (i, "label %d", &local_label))
6768 else if (unformat (i, "hdr-len %d", &hdr_len))
6770 else if (unformat (i, "add"))
6772 else if (unformat (i, "del"))
6776 clib_warning ("parse error '%U'", format_unformat_error, i);
6781 if (MPLS_LABEL_INVALID == local_label)
6783 errmsg ("missing label\n");
6787 /* Construct the API message */
6788 M (BIER_TABLE_ADD_DEL, mp);
6790 mp->bt_is_add = is_add;
6791 mp->bt_label = ntohl (local_label);
6792 mp->bt_tbl_id.bt_set = set;
6793 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6794 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6799 /* Wait for a reply... */
6806 api_bier_route_add_del (vat_main_t * vam)
6808 unformat_input_t *i = vam->input;
6809 vl_api_bier_route_add_del_t *mp;
6811 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6812 ip4_address_t v4_next_hop_address;
6813 ip6_address_t v6_next_hop_address;
6814 u8 next_hop_set = 0;
6815 u8 next_hop_proto_is_ip4 = 1;
6816 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6819 /* Parse args required to build the message */
6820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6822 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6824 next_hop_proto_is_ip4 = 1;
6827 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6829 next_hop_proto_is_ip4 = 0;
6832 if (unformat (i, "sub-domain %d", &sub_domain))
6834 else if (unformat (i, "set %d", &set))
6836 else if (unformat (i, "hdr-len %d", &hdr_len))
6838 else if (unformat (i, "bp %d", &bp))
6840 else if (unformat (i, "add"))
6842 else if (unformat (i, "del"))
6844 else if (unformat (i, "out-label %d", &next_hop_out_label))
6848 clib_warning ("parse error '%U'", format_unformat_error, i);
6853 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6855 errmsg ("next hop / label set\n");
6860 errmsg ("bit=position not set\n");
6864 /* Construct the API message */
6865 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6867 mp->br_is_add = is_add;
6868 mp->br_route.br_tbl_id.bt_set = set;
6869 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6870 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6871 mp->br_route.br_bp = ntohs (bp);
6872 mp->br_route.br_n_paths = 1;
6873 mp->br_route.br_paths[0].n_labels = 1;
6874 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6875 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6876 FIB_API_PATH_NH_PROTO_IP4 :
6877 FIB_API_PATH_NH_PROTO_IP6);
6879 if (next_hop_proto_is_ip4)
6881 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6882 &v4_next_hop_address, sizeof (v4_next_hop_address));
6886 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6887 &v6_next_hop_address, sizeof (v6_next_hop_address));
6893 /* Wait for a reply... */
6900 api_mpls_tunnel_add_del (vat_main_t * vam)
6902 unformat_input_t *i = vam->input;
6903 vl_api_mpls_tunnel_add_del_t *mp;
6905 vl_api_fib_path_t paths[8];
6906 u32 sw_if_index = ~0;
6912 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6914 if (unformat (i, "add"))
6918 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6920 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6922 else if (unformat (i, "l2-only"))
6926 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6929 if (8 == path_count)
6931 errmsg ("max 8 paths");
6937 clib_warning ("parse error '%U'", format_unformat_error, i);
6942 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6944 mp->mt_is_add = is_add;
6945 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6946 mp->mt_tunnel.mt_l2_only = l2_only;
6947 mp->mt_tunnel.mt_is_multicast = 0;
6948 mp->mt_tunnel.mt_n_paths = path_count;
6950 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6951 sizeof (paths[0]) * path_count);
6959 api_sw_interface_set_unnumbered (vat_main_t * vam)
6961 unformat_input_t *i = vam->input;
6962 vl_api_sw_interface_set_unnumbered_t *mp;
6964 u32 unnum_sw_index = ~0;
6966 u8 sw_if_index_set = 0;
6969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6971 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6972 sw_if_index_set = 1;
6973 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6974 sw_if_index_set = 1;
6975 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6977 else if (unformat (i, "del"))
6981 clib_warning ("parse error '%U'", format_unformat_error, i);
6986 if (sw_if_index_set == 0)
6988 errmsg ("missing interface name or sw_if_index");
6992 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6994 mp->sw_if_index = ntohl (sw_if_index);
6995 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6996 mp->is_add = is_add;
7005 api_create_vlan_subif (vat_main_t * vam)
7007 unformat_input_t *i = vam->input;
7008 vl_api_create_vlan_subif_t *mp;
7010 u8 sw_if_index_set = 0;
7015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7017 if (unformat (i, "sw_if_index %d", &sw_if_index))
7018 sw_if_index_set = 1;
7020 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7021 sw_if_index_set = 1;
7022 else if (unformat (i, "vlan %d", &vlan_id))
7026 clib_warning ("parse error '%U'", format_unformat_error, i);
7031 if (sw_if_index_set == 0)
7033 errmsg ("missing interface name or sw_if_index");
7037 if (vlan_id_set == 0)
7039 errmsg ("missing vlan_id");
7042 M (CREATE_VLAN_SUBIF, mp);
7044 mp->sw_if_index = ntohl (sw_if_index);
7045 mp->vlan_id = ntohl (vlan_id);
7052 #define foreach_create_subif_bit \
7059 _(outer_vlan_id_any) \
7060 _(inner_vlan_id_any)
7062 #define foreach_create_subif_flag \
7067 _(4, "exact_match") \
7068 _(5, "default_sub") \
7069 _(6, "outer_vlan_id_any") \
7070 _(7, "inner_vlan_id_any")
7073 api_create_subif (vat_main_t * vam)
7075 unformat_input_t *i = vam->input;
7076 vl_api_create_subif_t *mp;
7078 u8 sw_if_index_set = 0;
7081 u32 __attribute__ ((unused)) no_tags = 0;
7082 u32 __attribute__ ((unused)) one_tag = 0;
7083 u32 __attribute__ ((unused)) two_tags = 0;
7084 u32 __attribute__ ((unused)) dot1ad = 0;
7085 u32 __attribute__ ((unused)) exact_match = 0;
7086 u32 __attribute__ ((unused)) default_sub = 0;
7087 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7088 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7090 u16 outer_vlan_id = 0;
7091 u16 inner_vlan_id = 0;
7094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7096 if (unformat (i, "sw_if_index %d", &sw_if_index))
7097 sw_if_index_set = 1;
7099 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7100 sw_if_index_set = 1;
7101 else if (unformat (i, "sub_id %d", &sub_id))
7103 else if (unformat (i, "outer_vlan_id %d", &tmp))
7104 outer_vlan_id = tmp;
7105 else if (unformat (i, "inner_vlan_id %d", &tmp))
7106 inner_vlan_id = tmp;
7108 #define _(a) else if (unformat (i, #a)) a = 1 ;
7109 foreach_create_subif_bit
7113 clib_warning ("parse error '%U'", format_unformat_error, i);
7118 if (sw_if_index_set == 0)
7120 errmsg ("missing interface name or sw_if_index");
7124 if (sub_id_set == 0)
7126 errmsg ("missing sub_id");
7129 M (CREATE_SUBIF, mp);
7131 mp->sw_if_index = ntohl (sw_if_index);
7132 mp->sub_id = ntohl (sub_id);
7134 #define _(a,b) mp->sub_if_flags |= (1 << a);
7135 foreach_create_subif_flag;
7138 mp->outer_vlan_id = ntohs (outer_vlan_id);
7139 mp->inner_vlan_id = ntohs (inner_vlan_id);
7147 api_ip_table_replace_begin (vat_main_t * vam)
7149 unformat_input_t *i = vam->input;
7150 vl_api_ip_table_replace_begin_t *mp;
7155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7157 if (unformat (i, "table %d", &table_id))
7159 else if (unformat (i, "ipv6"))
7163 clib_warning ("parse error '%U'", format_unformat_error, i);
7168 M (IP_TABLE_REPLACE_BEGIN, mp);
7170 mp->table.table_id = ntohl (table_id);
7171 mp->table.is_ip6 = is_ipv6;
7179 api_ip_table_flush (vat_main_t * vam)
7181 unformat_input_t *i = vam->input;
7182 vl_api_ip_table_flush_t *mp;
7187 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7189 if (unformat (i, "table %d", &table_id))
7191 else if (unformat (i, "ipv6"))
7195 clib_warning ("parse error '%U'", format_unformat_error, i);
7200 M (IP_TABLE_FLUSH, mp);
7202 mp->table.table_id = ntohl (table_id);
7203 mp->table.is_ip6 = is_ipv6;
7211 api_ip_table_replace_end (vat_main_t * vam)
7213 unformat_input_t *i = vam->input;
7214 vl_api_ip_table_replace_end_t *mp;
7219 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7221 if (unformat (i, "table %d", &table_id))
7223 else if (unformat (i, "ipv6"))
7227 clib_warning ("parse error '%U'", format_unformat_error, i);
7232 M (IP_TABLE_REPLACE_END, mp);
7234 mp->table.table_id = ntohl (table_id);
7235 mp->table.is_ip6 = is_ipv6;
7243 api_set_ip_flow_hash (vat_main_t * vam)
7245 unformat_input_t *i = vam->input;
7246 vl_api_set_ip_flow_hash_t *mp;
7258 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7260 if (unformat (i, "vrf %d", &vrf_id))
7262 else if (unformat (i, "ipv6"))
7264 else if (unformat (i, "src"))
7266 else if (unformat (i, "dst"))
7268 else if (unformat (i, "sport"))
7270 else if (unformat (i, "dport"))
7272 else if (unformat (i, "proto"))
7274 else if (unformat (i, "reverse"))
7279 clib_warning ("parse error '%U'", format_unformat_error, i);
7284 if (vrf_id_set == 0)
7286 errmsg ("missing vrf id");
7290 M (SET_IP_FLOW_HASH, mp);
7296 mp->reverse = reverse;
7297 mp->vrf_id = ntohl (vrf_id);
7298 mp->is_ipv6 = is_ipv6;
7306 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7308 unformat_input_t *i = vam->input;
7309 vl_api_sw_interface_ip6_enable_disable_t *mp;
7311 u8 sw_if_index_set = 0;
7315 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7317 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7318 sw_if_index_set = 1;
7319 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7320 sw_if_index_set = 1;
7321 else if (unformat (i, "enable"))
7323 else if (unformat (i, "disable"))
7327 clib_warning ("parse error '%U'", format_unformat_error, i);
7332 if (sw_if_index_set == 0)
7334 errmsg ("missing interface name or sw_if_index");
7338 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7340 mp->sw_if_index = ntohl (sw_if_index);
7341 mp->enable = enable;
7350 api_l2_patch_add_del (vat_main_t * vam)
7352 unformat_input_t *i = vam->input;
7353 vl_api_l2_patch_add_del_t *mp;
7355 u8 rx_sw_if_index_set = 0;
7357 u8 tx_sw_if_index_set = 0;
7361 /* Parse args required to build the message */
7362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7364 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7365 rx_sw_if_index_set = 1;
7366 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7367 tx_sw_if_index_set = 1;
7368 else if (unformat (i, "rx"))
7370 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7372 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7374 rx_sw_if_index_set = 1;
7379 else if (unformat (i, "tx"))
7381 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7383 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7385 tx_sw_if_index_set = 1;
7390 else if (unformat (i, "del"))
7396 if (rx_sw_if_index_set == 0)
7398 errmsg ("missing rx interface name or rx_sw_if_index");
7402 if (tx_sw_if_index_set == 0)
7404 errmsg ("missing tx interface name or tx_sw_if_index");
7408 M (L2_PATCH_ADD_DEL, mp);
7410 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7411 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7412 mp->is_add = is_add;
7420 u8 localsid_addr[16];
7429 api_sr_localsid_add_del (vat_main_t * vam)
7431 unformat_input_t *i = vam->input;
7432 vl_api_sr_localsid_add_del_t *mp;
7435 ip6_address_t localsid;
7439 u32 fib_table = ~(u32) 0;
7440 ip46_address_t nh_addr;
7441 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7443 bool nexthop_set = 0;
7447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7449 if (unformat (i, "del"))
7451 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7452 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7454 else if (unformat (i, "behavior %u", &behavior));
7455 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7456 else if (unformat (i, "fib-table %u", &fib_table));
7457 else if (unformat (i, "end.psp %u", &behavior));
7462 M (SR_LOCALSID_ADD_DEL, mp);
7464 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7468 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7470 mp->behavior = behavior;
7471 mp->sw_if_index = ntohl (sw_if_index);
7472 mp->fib_table = ntohl (fib_table);
7473 mp->end_psp = end_psp;
7474 mp->is_del = is_del;
7482 api_ioam_enable (vat_main_t * vam)
7484 unformat_input_t *input = vam->input;
7485 vl_api_ioam_enable_t *mp;
7487 int has_trace_option = 0;
7488 int has_pot_option = 0;
7489 int has_seqno_option = 0;
7490 int has_analyse_option = 0;
7493 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7495 if (unformat (input, "trace"))
7496 has_trace_option = 1;
7497 else if (unformat (input, "pot"))
7499 else if (unformat (input, "seqno"))
7500 has_seqno_option = 1;
7501 else if (unformat (input, "analyse"))
7502 has_analyse_option = 1;
7506 M (IOAM_ENABLE, mp);
7507 mp->id = htons (id);
7508 mp->seqno = has_seqno_option;
7509 mp->analyse = has_analyse_option;
7510 mp->pot_enable = has_pot_option;
7511 mp->trace_enable = has_trace_option;
7520 api_ioam_disable (vat_main_t * vam)
7522 vl_api_ioam_disable_t *mp;
7525 M (IOAM_DISABLE, mp);
7531 #define foreach_tcp_proto_field \
7535 #define foreach_udp_proto_field \
7539 #define foreach_ip4_proto_field \
7551 u16 src_port, dst_port;
7554 #if VPP_API_TEST_BUILTIN == 0
7556 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7558 u8 **maskp = va_arg (*args, u8 **);
7560 u8 found_something = 0;
7563 #define _(a) u8 a=0;
7564 foreach_tcp_proto_field;
7567 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7570 #define _(a) else if (unformat (input, #a)) a=1;
7571 foreach_tcp_proto_field
7577 #define _(a) found_something += a;
7578 foreach_tcp_proto_field;
7581 if (found_something == 0)
7584 vec_validate (mask, sizeof (*tcp) - 1);
7586 tcp = (tcp_header_t *) mask;
7588 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7589 foreach_tcp_proto_field;
7597 unformat_udp_mask (unformat_input_t * input, va_list * args)
7599 u8 **maskp = va_arg (*args, u8 **);
7601 u8 found_something = 0;
7604 #define _(a) u8 a=0;
7605 foreach_udp_proto_field;
7608 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7611 #define _(a) else if (unformat (input, #a)) a=1;
7612 foreach_udp_proto_field
7618 #define _(a) found_something += a;
7619 foreach_udp_proto_field;
7622 if (found_something == 0)
7625 vec_validate (mask, sizeof (*udp) - 1);
7627 udp = (udp_header_t *) mask;
7629 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7630 foreach_udp_proto_field;
7638 unformat_l4_mask (unformat_input_t * input, va_list * args)
7640 u8 **maskp = va_arg (*args, u8 **);
7641 u16 src_port = 0, dst_port = 0;
7642 tcpudp_header_t *tcpudp;
7644 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7646 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7648 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7650 else if (unformat (input, "src_port"))
7652 else if (unformat (input, "dst_port"))
7658 if (!src_port && !dst_port)
7662 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7664 tcpudp = (tcpudp_header_t *) mask;
7665 tcpudp->src_port = src_port;
7666 tcpudp->dst_port = dst_port;
7674 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7676 u8 **maskp = va_arg (*args, u8 **);
7678 u8 found_something = 0;
7681 #define _(a) u8 a=0;
7682 foreach_ip4_proto_field;
7688 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7690 if (unformat (input, "version"))
7692 else if (unformat (input, "hdr_length"))
7694 else if (unformat (input, "src"))
7696 else if (unformat (input, "dst"))
7698 else if (unformat (input, "proto"))
7701 #define _(a) else if (unformat (input, #a)) a=1;
7702 foreach_ip4_proto_field
7708 #define _(a) found_something += a;
7709 foreach_ip4_proto_field;
7712 if (found_something == 0)
7715 vec_validate (mask, sizeof (*ip) - 1);
7717 ip = (ip4_header_t *) mask;
7719 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7720 foreach_ip4_proto_field;
7723 ip->ip_version_and_header_length = 0;
7726 ip->ip_version_and_header_length |= 0xF0;
7729 ip->ip_version_and_header_length |= 0x0F;
7735 #define foreach_ip6_proto_field \
7743 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7745 u8 **maskp = va_arg (*args, u8 **);
7747 u8 found_something = 0;
7749 u32 ip_version_traffic_class_and_flow_label;
7751 #define _(a) u8 a=0;
7752 foreach_ip6_proto_field;
7755 u8 traffic_class = 0;
7758 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7760 if (unformat (input, "version"))
7762 else if (unformat (input, "traffic-class"))
7764 else if (unformat (input, "flow-label"))
7766 else if (unformat (input, "src"))
7768 else if (unformat (input, "dst"))
7770 else if (unformat (input, "proto"))
7773 #define _(a) else if (unformat (input, #a)) a=1;
7774 foreach_ip6_proto_field
7780 #define _(a) found_something += a;
7781 foreach_ip6_proto_field;
7784 if (found_something == 0)
7787 vec_validate (mask, sizeof (*ip) - 1);
7789 ip = (ip6_header_t *) mask;
7791 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7792 foreach_ip6_proto_field;
7795 ip_version_traffic_class_and_flow_label = 0;
7798 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7801 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7804 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7806 ip->ip_version_traffic_class_and_flow_label =
7807 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7814 unformat_l3_mask (unformat_input_t * input, va_list * args)
7816 u8 **maskp = va_arg (*args, u8 **);
7818 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7820 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7822 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7831 unformat_l2_mask (unformat_input_t * input, va_list * args)
7833 u8 **maskp = va_arg (*args, u8 **);
7848 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7850 if (unformat (input, "src"))
7852 else if (unformat (input, "dst"))
7854 else if (unformat (input, "proto"))
7856 else if (unformat (input, "tag1"))
7858 else if (unformat (input, "tag2"))
7860 else if (unformat (input, "ignore-tag1"))
7862 else if (unformat (input, "ignore-tag2"))
7864 else if (unformat (input, "cos1"))
7866 else if (unformat (input, "cos2"))
7868 else if (unformat (input, "dot1q"))
7870 else if (unformat (input, "dot1ad"))
7875 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7876 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7879 if (tag1 || ignore_tag1 || cos1 || dot1q)
7881 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7884 vec_validate (mask, len - 1);
7887 clib_memset (mask, 0xff, 6);
7890 clib_memset (mask + 6, 0xff, 6);
7894 /* inner vlan tag */
7903 mask[21] = mask[20] = 0xff;
7924 mask[16] = mask[17] = 0xff;
7934 mask[12] = mask[13] = 0xff;
7941 unformat_classify_mask (unformat_input_t * input, va_list * args)
7943 u8 **maskp = va_arg (*args, u8 **);
7944 u32 *skipp = va_arg (*args, u32 *);
7945 u32 *matchp = va_arg (*args, u32 *);
7953 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7955 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7957 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7959 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7961 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7975 if (mask || l2 || l3 || l4)
7979 /* "With a free Ethernet header in every package" */
7981 vec_validate (l2, 13);
7985 vec_append (mask, l3);
7990 vec_append (mask, l4);
7995 /* Scan forward looking for the first significant mask octet */
7996 for (i = 0; i < vec_len (mask); i++)
8000 /* compute (skip, match) params */
8001 *skipp = i / sizeof (u32x4);
8002 vec_delete (mask, *skipp * sizeof (u32x4), 0);
8004 /* Pad mask to an even multiple of the vector size */
8005 while (vec_len (mask) % sizeof (u32x4))
8008 match = vec_len (mask) / sizeof (u32x4);
8010 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8012 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8013 if (*tmp || *(tmp + 1))
8018 clib_warning ("BUG: match 0");
8020 _vec_len (mask) = match * sizeof (u32x4);
8030 #endif /* VPP_API_TEST_BUILTIN */
8032 #define foreach_l2_next \
8034 _(ethernet, ETHERNET_INPUT) \
8039 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8041 u32 *miss_next_indexp = va_arg (*args, u32 *);
8046 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8050 if (unformat (input, "%d", &tmp))
8059 *miss_next_indexp = next_index;
8063 #define foreach_ip_next \
8069 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8071 u32 *miss_next_indexp = va_arg (*args, u32 *);
8076 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8080 if (unformat (input, "%d", &tmp))
8089 *miss_next_indexp = next_index;
8093 #define foreach_acl_next \
8097 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8099 u32 *miss_next_indexp = va_arg (*args, u32 *);
8104 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8108 if (unformat (input, "permit"))
8113 else if (unformat (input, "%d", &tmp))
8122 *miss_next_indexp = next_index;
8127 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8129 u32 *r = va_arg (*args, u32 *);
8131 if (unformat (input, "conform-color"))
8132 *r = POLICE_CONFORM;
8133 else if (unformat (input, "exceed-color"))
8142 api_classify_add_del_table (vat_main_t * vam)
8144 unformat_input_t *i = vam->input;
8145 vl_api_classify_add_del_table_t *mp;
8152 u32 table_index = ~0;
8153 u32 next_table_index = ~0;
8154 u32 miss_next_index = ~0;
8155 u32 memory_size = 32 << 20;
8157 u32 current_data_flag = 0;
8158 int current_data_offset = 0;
8161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8163 if (unformat (i, "del"))
8165 else if (unformat (i, "del-chain"))
8170 else if (unformat (i, "buckets %d", &nbuckets))
8172 else if (unformat (i, "memory_size %d", &memory_size))
8174 else if (unformat (i, "skip %d", &skip))
8176 else if (unformat (i, "match %d", &match))
8178 else if (unformat (i, "table %d", &table_index))
8180 else if (unformat (i, "mask %U", unformat_classify_mask,
8181 &mask, &skip, &match))
8183 else if (unformat (i, "next-table %d", &next_table_index))
8185 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8188 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8191 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8194 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8196 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8202 if (is_add && mask == 0)
8204 errmsg ("Mask required");
8208 if (is_add && skip == ~0)
8210 errmsg ("skip count required");
8214 if (is_add && match == ~0)
8216 errmsg ("match count required");
8220 if (!is_add && table_index == ~0)
8222 errmsg ("table index required for delete");
8226 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8228 mp->is_add = is_add;
8229 mp->del_chain = del_chain;
8230 mp->table_index = ntohl (table_index);
8231 mp->nbuckets = ntohl (nbuckets);
8232 mp->memory_size = ntohl (memory_size);
8233 mp->skip_n_vectors = ntohl (skip);
8234 mp->match_n_vectors = ntohl (match);
8235 mp->next_table_index = ntohl (next_table_index);
8236 mp->miss_next_index = ntohl (miss_next_index);
8237 mp->current_data_flag = ntohl (current_data_flag);
8238 mp->current_data_offset = ntohl (current_data_offset);
8239 mp->mask_len = ntohl (vec_len (mask));
8240 clib_memcpy (mp->mask, mask, vec_len (mask));
8249 #if VPP_API_TEST_BUILTIN == 0
8251 unformat_l4_match (unformat_input_t * input, va_list * args)
8253 u8 **matchp = va_arg (*args, u8 **);
8255 u8 *proto_header = 0;
8261 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8263 if (unformat (input, "src_port %d", &src_port))
8265 else if (unformat (input, "dst_port %d", &dst_port))
8271 h.src_port = clib_host_to_net_u16 (src_port);
8272 h.dst_port = clib_host_to_net_u16 (dst_port);
8273 vec_validate (proto_header, sizeof (h) - 1);
8274 memcpy (proto_header, &h, sizeof (h));
8276 *matchp = proto_header;
8282 unformat_ip4_match (unformat_input_t * input, va_list * args)
8284 u8 **matchp = va_arg (*args, u8 **);
8291 int src = 0, dst = 0;
8292 ip4_address_t src_val, dst_val;
8299 int fragment_id = 0;
8300 u32 fragment_id_val;
8306 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8308 if (unformat (input, "version %d", &version_val))
8310 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8312 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8314 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8316 else if (unformat (input, "proto %d", &proto_val))
8318 else if (unformat (input, "tos %d", &tos_val))
8320 else if (unformat (input, "length %d", &length_val))
8322 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8324 else if (unformat (input, "ttl %d", &ttl_val))
8326 else if (unformat (input, "checksum %d", &checksum_val))
8332 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8333 + ttl + checksum == 0)
8337 * Aligned because we use the real comparison functions
8339 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8341 ip = (ip4_header_t *) match;
8343 /* These are realistically matched in practice */
8345 ip->src_address.as_u32 = src_val.as_u32;
8348 ip->dst_address.as_u32 = dst_val.as_u32;
8351 ip->protocol = proto_val;
8354 /* These are not, but they're included for completeness */
8356 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8359 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8365 ip->length = clib_host_to_net_u16 (length_val);
8371 ip->checksum = clib_host_to_net_u16 (checksum_val);
8378 unformat_ip6_match (unformat_input_t * input, va_list * args)
8380 u8 **matchp = va_arg (*args, u8 **);
8385 u8 traffic_class = 0;
8386 u32 traffic_class_val = 0;
8389 int src = 0, dst = 0;
8390 ip6_address_t src_val, dst_val;
8393 int payload_length = 0;
8394 u32 payload_length_val;
8397 u32 ip_version_traffic_class_and_flow_label;
8399 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8401 if (unformat (input, "version %d", &version_val))
8403 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8405 else if (unformat (input, "flow_label %d", &flow_label_val))
8407 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8409 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8411 else if (unformat (input, "proto %d", &proto_val))
8413 else if (unformat (input, "payload_length %d", &payload_length_val))
8415 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8421 if (version + traffic_class + flow_label + src + dst + proto +
8422 payload_length + hop_limit == 0)
8426 * Aligned because we use the real comparison functions
8428 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8430 ip = (ip6_header_t *) match;
8433 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8436 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8439 ip->protocol = proto_val;
8441 ip_version_traffic_class_and_flow_label = 0;
8444 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8447 ip_version_traffic_class_and_flow_label |=
8448 (traffic_class_val & 0xFF) << 20;
8451 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8453 ip->ip_version_traffic_class_and_flow_label =
8454 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8457 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8460 ip->hop_limit = hop_limit_val;
8467 unformat_l3_match (unformat_input_t * input, va_list * args)
8469 u8 **matchp = va_arg (*args, u8 **);
8471 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8473 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8475 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8484 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8486 u8 *tagp = va_arg (*args, u8 *);
8489 if (unformat (input, "%d", &tag))
8491 tagp[0] = (tag >> 8) & 0x0F;
8492 tagp[1] = tag & 0xFF;
8500 unformat_l2_match (unformat_input_t * input, va_list * args)
8502 u8 **matchp = va_arg (*args, u8 **);
8522 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8524 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8527 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8529 else if (unformat (input, "proto %U",
8530 unformat_ethernet_type_host_byte_order, &proto_val))
8532 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8534 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8536 else if (unformat (input, "ignore-tag1"))
8538 else if (unformat (input, "ignore-tag2"))
8540 else if (unformat (input, "cos1 %d", &cos1_val))
8542 else if (unformat (input, "cos2 %d", &cos2_val))
8547 if ((src + dst + proto + tag1 + tag2 +
8548 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8551 if (tag1 || ignore_tag1 || cos1)
8553 if (tag2 || ignore_tag2 || cos2)
8556 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8559 clib_memcpy (match, dst_val, 6);
8562 clib_memcpy (match + 6, src_val, 6);
8566 /* inner vlan tag */
8567 match[19] = tag2_val[1];
8568 match[18] = tag2_val[0];
8570 match[18] |= (cos2_val & 0x7) << 5;
8573 match[21] = proto_val & 0xff;
8574 match[20] = proto_val >> 8;
8578 match[15] = tag1_val[1];
8579 match[14] = tag1_val[0];
8582 match[14] |= (cos1_val & 0x7) << 5;
8588 match[15] = tag1_val[1];
8589 match[14] = tag1_val[0];
8592 match[17] = proto_val & 0xff;
8593 match[16] = proto_val >> 8;
8596 match[14] |= (cos1_val & 0x7) << 5;
8602 match[18] |= (cos2_val & 0x7) << 5;
8604 match[14] |= (cos1_val & 0x7) << 5;
8607 match[13] = proto_val & 0xff;
8608 match[12] = proto_val >> 8;
8616 unformat_qos_source (unformat_input_t * input, va_list * args)
8618 int *qs = va_arg (*args, int *);
8620 if (unformat (input, "ip"))
8621 *qs = QOS_SOURCE_IP;
8622 else if (unformat (input, "mpls"))
8623 *qs = QOS_SOURCE_MPLS;
8624 else if (unformat (input, "ext"))
8625 *qs = QOS_SOURCE_EXT;
8626 else if (unformat (input, "vlan"))
8627 *qs = QOS_SOURCE_VLAN;
8636 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8638 u8 **matchp = va_arg (*args, u8 **);
8639 u32 skip_n_vectors = va_arg (*args, u32);
8640 u32 match_n_vectors = va_arg (*args, u32);
8647 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8649 if (unformat (input, "hex %U", unformat_hex_string, &match))
8651 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8653 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8655 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8669 if (match || l2 || l3 || l4)
8673 /* "Win a free Ethernet header in every packet" */
8675 vec_validate_aligned (l2, 13, sizeof (u32x4));
8679 vec_append_aligned (match, l3, sizeof (u32x4));
8684 vec_append_aligned (match, l4, sizeof (u32x4));
8689 /* Make sure the vector is big enough even if key is all 0's */
8690 vec_validate_aligned
8691 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8694 /* Set size, include skipped vectors */
8695 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8706 api_classify_add_del_session (vat_main_t * vam)
8708 unformat_input_t *i = vam->input;
8709 vl_api_classify_add_del_session_t *mp;
8711 u32 table_index = ~0;
8712 u32 hit_next_index = ~0;
8713 u32 opaque_index = ~0;
8716 u32 skip_n_vectors = 0;
8717 u32 match_n_vectors = 0;
8723 * Warning: you have to supply skip_n and match_n
8724 * because the API client cant simply look at the classify
8728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8730 if (unformat (i, "del"))
8732 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8735 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8738 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8741 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8743 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8745 else if (unformat (i, "opaque-index %d", &opaque_index))
8747 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8749 else if (unformat (i, "match_n %d", &match_n_vectors))
8751 else if (unformat (i, "match %U", api_unformat_classify_match,
8752 &match, skip_n_vectors, match_n_vectors))
8754 else if (unformat (i, "advance %d", &advance))
8756 else if (unformat (i, "table-index %d", &table_index))
8758 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8760 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8762 else if (unformat (i, "action %d", &action))
8764 else if (unformat (i, "metadata %d", &metadata))
8770 if (table_index == ~0)
8772 errmsg ("Table index required");
8776 if (is_add && match == 0)
8778 errmsg ("Match value required");
8782 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8784 mp->is_add = is_add;
8785 mp->table_index = ntohl (table_index);
8786 mp->hit_next_index = ntohl (hit_next_index);
8787 mp->opaque_index = ntohl (opaque_index);
8788 mp->advance = ntohl (advance);
8789 mp->action = action;
8790 mp->metadata = ntohl (metadata);
8791 mp->match_len = ntohl (vec_len (match));
8792 clib_memcpy (mp->match, match, vec_len (match));
8801 api_classify_set_interface_ip_table (vat_main_t * vam)
8803 unformat_input_t *i = vam->input;
8804 vl_api_classify_set_interface_ip_table_t *mp;
8806 int sw_if_index_set;
8807 u32 table_index = ~0;
8811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8813 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8814 sw_if_index_set = 1;
8815 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8816 sw_if_index_set = 1;
8817 else if (unformat (i, "table %d", &table_index))
8821 clib_warning ("parse error '%U'", format_unformat_error, i);
8826 if (sw_if_index_set == 0)
8828 errmsg ("missing interface name or sw_if_index");
8833 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8835 mp->sw_if_index = ntohl (sw_if_index);
8836 mp->table_index = ntohl (table_index);
8837 mp->is_ipv6 = is_ipv6;
8845 api_classify_set_interface_l2_tables (vat_main_t * vam)
8847 unformat_input_t *i = vam->input;
8848 vl_api_classify_set_interface_l2_tables_t *mp;
8850 int sw_if_index_set;
8851 u32 ip4_table_index = ~0;
8852 u32 ip6_table_index = ~0;
8853 u32 other_table_index = ~0;
8857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8859 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8860 sw_if_index_set = 1;
8861 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8862 sw_if_index_set = 1;
8863 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8865 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8867 else if (unformat (i, "other-table %d", &other_table_index))
8869 else if (unformat (i, "is-input %d", &is_input))
8873 clib_warning ("parse error '%U'", format_unformat_error, i);
8878 if (sw_if_index_set == 0)
8880 errmsg ("missing interface name or sw_if_index");
8885 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8887 mp->sw_if_index = ntohl (sw_if_index);
8888 mp->ip4_table_index = ntohl (ip4_table_index);
8889 mp->ip6_table_index = ntohl (ip6_table_index);
8890 mp->other_table_index = ntohl (other_table_index);
8891 mp->is_input = (u8) is_input;
8899 api_set_ipfix_exporter (vat_main_t * vam)
8901 unformat_input_t *i = vam->input;
8902 vl_api_set_ipfix_exporter_t *mp;
8903 ip4_address_t collector_address;
8904 u8 collector_address_set = 0;
8905 u32 collector_port = ~0;
8906 ip4_address_t src_address;
8907 u8 src_address_set = 0;
8910 u32 template_interval = ~0;
8911 u8 udp_checksum = 0;
8914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8916 if (unformat (i, "collector_address %U", unformat_ip4_address,
8917 &collector_address))
8918 collector_address_set = 1;
8919 else if (unformat (i, "collector_port %d", &collector_port))
8921 else if (unformat (i, "src_address %U", unformat_ip4_address,
8923 src_address_set = 1;
8924 else if (unformat (i, "vrf_id %d", &vrf_id))
8926 else if (unformat (i, "path_mtu %d", &path_mtu))
8928 else if (unformat (i, "template_interval %d", &template_interval))
8930 else if (unformat (i, "udp_checksum"))
8936 if (collector_address_set == 0)
8938 errmsg ("collector_address required");
8942 if (src_address_set == 0)
8944 errmsg ("src_address required");
8948 M (SET_IPFIX_EXPORTER, mp);
8950 memcpy (mp->collector_address.un.ip4, collector_address.data,
8951 sizeof (collector_address.data));
8952 mp->collector_port = htons ((u16) collector_port);
8953 memcpy (mp->src_address.un.ip4, src_address.data,
8954 sizeof (src_address.data));
8955 mp->vrf_id = htonl (vrf_id);
8956 mp->path_mtu = htonl (path_mtu);
8957 mp->template_interval = htonl (template_interval);
8958 mp->udp_checksum = udp_checksum;
8966 api_set_ipfix_classify_stream (vat_main_t * vam)
8968 unformat_input_t *i = vam->input;
8969 vl_api_set_ipfix_classify_stream_t *mp;
8971 u32 src_port = UDP_DST_PORT_ipfix;
8974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8976 if (unformat (i, "domain %d", &domain_id))
8978 else if (unformat (i, "src_port %d", &src_port))
8982 errmsg ("unknown input `%U'", format_unformat_error, i);
8987 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8989 mp->domain_id = htonl (domain_id);
8990 mp->src_port = htons ((u16) src_port);
8998 api_ipfix_classify_table_add_del (vat_main_t * vam)
9000 unformat_input_t *i = vam->input;
9001 vl_api_ipfix_classify_table_add_del_t *mp;
9003 u32 classify_table_index = ~0;
9005 u8 transport_protocol = 255;
9008 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9010 if (unformat (i, "add"))
9012 else if (unformat (i, "del"))
9014 else if (unformat (i, "table %d", &classify_table_index))
9016 else if (unformat (i, "ip4"))
9018 else if (unformat (i, "ip6"))
9020 else if (unformat (i, "tcp"))
9021 transport_protocol = 6;
9022 else if (unformat (i, "udp"))
9023 transport_protocol = 17;
9026 errmsg ("unknown input `%U'", format_unformat_error, i);
9033 errmsg ("expecting: add|del");
9036 if (classify_table_index == ~0)
9038 errmsg ("classifier table not specified");
9041 if (ip_version == 0)
9043 errmsg ("IP version not specified");
9047 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9049 mp->is_add = is_add;
9050 mp->table_id = htonl (classify_table_index);
9051 mp->ip_version = ip_version;
9052 mp->transport_protocol = transport_protocol;
9060 api_get_node_index (vat_main_t * vam)
9062 unformat_input_t *i = vam->input;
9063 vl_api_get_node_index_t *mp;
9067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9069 if (unformat (i, "node %s", &name))
9076 errmsg ("node name required");
9079 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9081 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9085 M (GET_NODE_INDEX, mp);
9086 clib_memcpy (mp->node_name, name, vec_len (name));
9095 api_get_next_index (vat_main_t * vam)
9097 unformat_input_t *i = vam->input;
9098 vl_api_get_next_index_t *mp;
9099 u8 *node_name = 0, *next_node_name = 0;
9102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9104 if (unformat (i, "node-name %s", &node_name))
9106 else if (unformat (i, "next-node-name %s", &next_node_name))
9112 errmsg ("node name required");
9115 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9117 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9121 if (next_node_name == 0)
9123 errmsg ("next node name required");
9126 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9128 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9132 M (GET_NEXT_INDEX, mp);
9133 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9134 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9135 vec_free (node_name);
9136 vec_free (next_node_name);
9144 api_add_node_next (vat_main_t * vam)
9146 unformat_input_t *i = vam->input;
9147 vl_api_add_node_next_t *mp;
9152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9154 if (unformat (i, "node %s", &name))
9156 else if (unformat (i, "next %s", &next))
9163 errmsg ("node name required");
9166 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9168 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9173 errmsg ("next node required");
9176 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9178 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9182 M (ADD_NODE_NEXT, mp);
9183 clib_memcpy (mp->node_name, name, vec_len (name));
9184 clib_memcpy (mp->next_name, next, vec_len (next));
9193 static void vl_api_sw_interface_tap_v2_details_t_handler
9194 (vl_api_sw_interface_tap_v2_details_t * mp)
9196 vat_main_t *vam = &vat_main;
9199 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9200 mp->host_ip4_prefix.len);
9202 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9203 mp->host_ip6_prefix.len);
9206 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9207 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9208 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9209 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9210 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9216 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9217 (vl_api_sw_interface_tap_v2_details_t * mp)
9219 vat_main_t *vam = &vat_main;
9220 vat_json_node_t *node = NULL;
9222 if (VAT_JSON_ARRAY != vam->json_tree.type)
9224 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9225 vat_json_init_array (&vam->json_tree);
9227 node = vat_json_array_add (&vam->json_tree);
9229 vat_json_init_object (node);
9230 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9231 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9232 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9233 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9234 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9235 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9236 vat_json_object_add_string_copy (node, "host_mac_addr",
9237 format (0, "%U", format_ethernet_address,
9238 &mp->host_mac_addr));
9239 vat_json_object_add_string_copy (node, "host_namespace",
9240 mp->host_namespace);
9241 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9242 vat_json_object_add_string_copy (node, "host_ip4_addr",
9243 format (0, "%U/%d", format_ip4_address,
9244 mp->host_ip4_prefix.address,
9245 mp->host_ip4_prefix.len));
9246 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9247 format (0, "%U/%d", format_ip6_address,
9248 mp->host_ip6_prefix.address,
9249 mp->host_ip6_prefix.len));
9254 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9256 vl_api_sw_interface_tap_v2_dump_t *mp;
9257 vl_api_control_ping_t *mp_ping;
9261 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9262 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9263 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9266 /* Get list of tap interfaces */
9267 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9270 /* Use a control ping for synchronization */
9271 MPING (CONTROL_PING, mp_ping);
9278 static void vl_api_sw_interface_virtio_pci_details_t_handler
9279 (vl_api_sw_interface_virtio_pci_details_t * mp)
9281 vat_main_t *vam = &vat_main;
9296 addr.domain = ntohs (mp->pci_addr.domain);
9297 addr.bus = mp->pci_addr.bus;
9298 addr.slot = mp->pci_addr.slot;
9299 addr.function = mp->pci_addr.function;
9301 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9302 addr.slot, addr.function);
9305 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9306 pci_addr, ntohl (mp->sw_if_index),
9307 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9308 format_ethernet_address, mp->mac_addr,
9309 clib_net_to_host_u64 (mp->features));
9310 vec_free (pci_addr);
9313 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9314 (vl_api_sw_interface_virtio_pci_details_t * mp)
9316 vat_main_t *vam = &vat_main;
9317 vat_json_node_t *node = NULL;
9318 vlib_pci_addr_t pci_addr;
9320 if (VAT_JSON_ARRAY != vam->json_tree.type)
9322 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9323 vat_json_init_array (&vam->json_tree);
9325 node = vat_json_array_add (&vam->json_tree);
9327 pci_addr.domain = ntohs (mp->pci_addr.domain);
9328 pci_addr.bus = mp->pci_addr.bus;
9329 pci_addr.slot = mp->pci_addr.slot;
9330 pci_addr.function = mp->pci_addr.function;
9332 vat_json_init_object (node);
9333 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9334 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9335 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9336 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9337 vat_json_object_add_uint (node, "features",
9338 clib_net_to_host_u64 (mp->features));
9339 vat_json_object_add_string_copy (node, "mac_addr",
9340 format (0, "%U", format_ethernet_address,
9345 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9347 vl_api_sw_interface_virtio_pci_dump_t *mp;
9348 vl_api_control_ping_t *mp_ping;
9352 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9353 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9354 "mac_addr", "features");
9356 /* Get list of tap interfaces */
9357 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9360 /* Use a control ping for synchronization */
9361 MPING (CONTROL_PING, mp_ping);
9369 api_vxlan_offload_rx (vat_main_t * vam)
9371 unformat_input_t *line_input = vam->input;
9372 vl_api_vxlan_offload_rx_t *mp;
9373 u32 hw_if_index = ~0, rx_if_index = ~0;
9377 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9379 if (unformat (line_input, "del"))
9381 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9384 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9386 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9389 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9393 errmsg ("parse error '%U'", format_unformat_error, line_input);
9398 if (hw_if_index == ~0)
9400 errmsg ("no hw interface");
9404 if (rx_if_index == ~0)
9406 errmsg ("no rx tunnel");
9410 M (VXLAN_OFFLOAD_RX, mp);
9412 mp->hw_if_index = ntohl (hw_if_index);
9413 mp->sw_if_index = ntohl (rx_if_index);
9414 mp->enable = is_add;
9421 static uword unformat_vxlan_decap_next
9422 (unformat_input_t * input, va_list * args)
9424 u32 *result = va_arg (*args, u32 *);
9427 if (unformat (input, "l2"))
9428 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9429 else if (unformat (input, "%d", &tmp))
9437 api_vxlan_add_del_tunnel (vat_main_t * vam)
9439 unformat_input_t *line_input = vam->input;
9440 vl_api_vxlan_add_del_tunnel_t *mp;
9441 ip46_address_t src, dst;
9443 u8 ipv4_set = 0, ipv6_set = 0;
9448 u32 mcast_sw_if_index = ~0;
9449 u32 encap_vrf_id = 0;
9450 u32 decap_next_index = ~0;
9454 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9455 clib_memset (&src, 0, sizeof src);
9456 clib_memset (&dst, 0, sizeof dst);
9458 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9460 if (unformat (line_input, "del"))
9462 else if (unformat (line_input, "instance %d", &instance))
9465 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9471 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9477 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9483 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9488 else if (unformat (line_input, "group %U %U",
9489 unformat_ip4_address, &dst.ip4,
9490 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9492 grp_set = dst_set = 1;
9495 else if (unformat (line_input, "group %U",
9496 unformat_ip4_address, &dst.ip4))
9498 grp_set = dst_set = 1;
9501 else if (unformat (line_input, "group %U %U",
9502 unformat_ip6_address, &dst.ip6,
9503 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9505 grp_set = dst_set = 1;
9508 else if (unformat (line_input, "group %U",
9509 unformat_ip6_address, &dst.ip6))
9511 grp_set = dst_set = 1;
9515 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9517 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9519 else if (unformat (line_input, "decap-next %U",
9520 unformat_vxlan_decap_next, &decap_next_index))
9522 else if (unformat (line_input, "vni %d", &vni))
9526 errmsg ("parse error '%U'", format_unformat_error, line_input);
9533 errmsg ("tunnel src address not specified");
9538 errmsg ("tunnel dst address not specified");
9542 if (grp_set && !ip46_address_is_multicast (&dst))
9544 errmsg ("tunnel group address not multicast");
9547 if (grp_set && mcast_sw_if_index == ~0)
9549 errmsg ("tunnel nonexistent multicast device");
9552 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9554 errmsg ("tunnel dst address must be unicast");
9559 if (ipv4_set && ipv6_set)
9561 errmsg ("both IPv4 and IPv6 addresses specified");
9565 if ((vni == 0) || (vni >> 24))
9567 errmsg ("vni not specified or out of range");
9571 M (VXLAN_ADD_DEL_TUNNEL, mp);
9575 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9576 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9580 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9581 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9583 mp->src_address.af = ipv6_set;
9584 mp->dst_address.af = ipv6_set;
9586 mp->instance = htonl (instance);
9587 mp->encap_vrf_id = ntohl (encap_vrf_id);
9588 mp->decap_next_index = ntohl (decap_next_index);
9589 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9590 mp->vni = ntohl (vni);
9591 mp->is_add = is_add;
9598 static void vl_api_vxlan_tunnel_details_t_handler
9599 (vl_api_vxlan_tunnel_details_t * mp)
9601 vat_main_t *vam = &vat_main;
9602 ip46_address_t src =
9603 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9604 ip46_address_t dst =
9605 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9607 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9608 ntohl (mp->sw_if_index),
9609 ntohl (mp->instance),
9610 format_ip46_address, &src, IP46_TYPE_ANY,
9611 format_ip46_address, &dst, IP46_TYPE_ANY,
9612 ntohl (mp->encap_vrf_id),
9613 ntohl (mp->decap_next_index), ntohl (mp->vni),
9614 ntohl (mp->mcast_sw_if_index));
9617 static void vl_api_vxlan_tunnel_details_t_handler_json
9618 (vl_api_vxlan_tunnel_details_t * mp)
9620 vat_main_t *vam = &vat_main;
9621 vat_json_node_t *node = NULL;
9623 if (VAT_JSON_ARRAY != vam->json_tree.type)
9625 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9626 vat_json_init_array (&vam->json_tree);
9628 node = vat_json_array_add (&vam->json_tree);
9630 vat_json_init_object (node);
9631 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9633 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9635 if (mp->src_address.af)
9637 struct in6_addr ip6;
9639 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9640 vat_json_object_add_ip6 (node, "src_address", ip6);
9641 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9642 vat_json_object_add_ip6 (node, "dst_address", ip6);
9648 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9649 vat_json_object_add_ip4 (node, "src_address", ip4);
9650 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9651 vat_json_object_add_ip4 (node, "dst_address", ip4);
9653 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9654 vat_json_object_add_uint (node, "decap_next_index",
9655 ntohl (mp->decap_next_index));
9656 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9657 vat_json_object_add_uint (node, "mcast_sw_if_index",
9658 ntohl (mp->mcast_sw_if_index));
9662 api_vxlan_tunnel_dump (vat_main_t * vam)
9664 unformat_input_t *i = vam->input;
9665 vl_api_vxlan_tunnel_dump_t *mp;
9666 vl_api_control_ping_t *mp_ping;
9668 u8 sw_if_index_set = 0;
9671 /* Parse args required to build the message */
9672 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9674 if (unformat (i, "sw_if_index %d", &sw_if_index))
9675 sw_if_index_set = 1;
9680 if (sw_if_index_set == 0)
9685 if (!vam->json_output)
9687 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9688 "sw_if_index", "instance", "src_address", "dst_address",
9689 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9692 /* Get list of vxlan-tunnel interfaces */
9693 M (VXLAN_TUNNEL_DUMP, mp);
9695 mp->sw_if_index = htonl (sw_if_index);
9699 /* Use a control ping for synchronization */
9700 MPING (CONTROL_PING, mp_ping);
9708 api_l2_fib_clear_table (vat_main_t * vam)
9710 // unformat_input_t * i = vam->input;
9711 vl_api_l2_fib_clear_table_t *mp;
9714 M (L2_FIB_CLEAR_TABLE, mp);
9722 api_l2_interface_efp_filter (vat_main_t * vam)
9724 unformat_input_t *i = vam->input;
9725 vl_api_l2_interface_efp_filter_t *mp;
9728 u8 sw_if_index_set = 0;
9731 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9733 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9734 sw_if_index_set = 1;
9735 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9736 sw_if_index_set = 1;
9737 else if (unformat (i, "enable"))
9739 else if (unformat (i, "disable"))
9743 clib_warning ("parse error '%U'", format_unformat_error, i);
9748 if (sw_if_index_set == 0)
9750 errmsg ("missing sw_if_index");
9754 M (L2_INTERFACE_EFP_FILTER, mp);
9756 mp->sw_if_index = ntohl (sw_if_index);
9757 mp->enable_disable = enable;
9764 #define foreach_vtr_op \
9765 _("disable", L2_VTR_DISABLED) \
9766 _("push-1", L2_VTR_PUSH_1) \
9767 _("push-2", L2_VTR_PUSH_2) \
9768 _("pop-1", L2_VTR_POP_1) \
9769 _("pop-2", L2_VTR_POP_2) \
9770 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9771 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9772 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9773 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9776 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9778 unformat_input_t *i = vam->input;
9779 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9781 u8 sw_if_index_set = 0;
9789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9791 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9792 sw_if_index_set = 1;
9793 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9794 sw_if_index_set = 1;
9795 else if (unformat (i, "vtr_op %d", &vtr_op))
9797 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9800 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9802 else if (unformat (i, "tag1 %d", &tag1))
9804 else if (unformat (i, "tag2 %d", &tag2))
9808 clib_warning ("parse error '%U'", format_unformat_error, i);
9813 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9815 errmsg ("missing vtr operation or sw_if_index");
9819 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9820 mp->sw_if_index = ntohl (sw_if_index);
9821 mp->vtr_op = ntohl (vtr_op);
9822 mp->push_dot1q = ntohl (push_dot1q);
9823 mp->tag1 = ntohl (tag1);
9824 mp->tag2 = ntohl (tag2);
9832 api_create_vhost_user_if (vat_main_t * vam)
9834 unformat_input_t *i = vam->input;
9835 vl_api_create_vhost_user_if_t *mp;
9838 u8 file_name_set = 0;
9839 u32 custom_dev_instance = ~0;
9841 u8 use_custom_mac = 0;
9842 u8 disable_mrg_rxbuf = 0;
9843 u8 disable_indirect_desc = 0;
9846 u8 enable_packed = 0;
9849 /* Shut up coverity */
9850 clib_memset (hwaddr, 0, sizeof (hwaddr));
9852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9854 if (unformat (i, "socket %s", &file_name))
9858 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9860 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9862 else if (unformat (i, "server"))
9864 else if (unformat (i, "disable_mrg_rxbuf"))
9865 disable_mrg_rxbuf = 1;
9866 else if (unformat (i, "disable_indirect_desc"))
9867 disable_indirect_desc = 1;
9868 else if (unformat (i, "gso"))
9870 else if (unformat (i, "packed"))
9872 else if (unformat (i, "tag %s", &tag))
9878 if (file_name_set == 0)
9880 errmsg ("missing socket file name");
9884 if (vec_len (file_name) > 255)
9886 errmsg ("socket file name too long");
9889 vec_add1 (file_name, 0);
9891 M (CREATE_VHOST_USER_IF, mp);
9893 mp->is_server = is_server;
9894 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9895 mp->disable_indirect_desc = disable_indirect_desc;
9896 mp->enable_gso = enable_gso;
9897 mp->enable_packed = enable_packed;
9898 mp->custom_dev_instance = ntohl (custom_dev_instance);
9899 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9900 vec_free (file_name);
9901 if (custom_dev_instance != ~0)
9904 mp->use_custom_mac = use_custom_mac;
9905 clib_memcpy (mp->mac_address, hwaddr, 6);
9907 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9916 api_modify_vhost_user_if (vat_main_t * vam)
9918 unformat_input_t *i = vam->input;
9919 vl_api_modify_vhost_user_if_t *mp;
9922 u8 file_name_set = 0;
9923 u32 custom_dev_instance = ~0;
9924 u8 sw_if_index_set = 0;
9925 u32 sw_if_index = (u32) ~ 0;
9927 u8 enable_packed = 0;
9930 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9932 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9933 sw_if_index_set = 1;
9934 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9935 sw_if_index_set = 1;
9936 else if (unformat (i, "socket %s", &file_name))
9940 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9942 else if (unformat (i, "server"))
9944 else if (unformat (i, "gso"))
9946 else if (unformat (i, "packed"))
9952 if (sw_if_index_set == 0)
9954 errmsg ("missing sw_if_index or interface name");
9958 if (file_name_set == 0)
9960 errmsg ("missing socket file name");
9964 if (vec_len (file_name) > 255)
9966 errmsg ("socket file name too long");
9969 vec_add1 (file_name, 0);
9971 M (MODIFY_VHOST_USER_IF, mp);
9973 mp->sw_if_index = ntohl (sw_if_index);
9974 mp->is_server = is_server;
9975 mp->enable_gso = enable_gso;
9976 mp->enable_packed = enable_packed;
9977 mp->custom_dev_instance = ntohl (custom_dev_instance);
9978 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9979 vec_free (file_name);
9980 if (custom_dev_instance != ~0)
9989 api_create_vhost_user_if_v2 (vat_main_t * vam)
9991 unformat_input_t *i = vam->input;
9992 vl_api_create_vhost_user_if_v2_t *mp;
9995 u8 file_name_set = 0;
9996 u32 custom_dev_instance = ~0;
9998 u8 use_custom_mac = 0;
9999 u8 disable_mrg_rxbuf = 0;
10000 u8 disable_indirect_desc = 0;
10003 u8 enable_packed = 0;
10004 u8 enable_event_idx = 0;
10007 /* Shut up coverity */
10008 clib_memset (hwaddr, 0, sizeof (hwaddr));
10010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10012 if (unformat (i, "socket %s", &file_name))
10016 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10018 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
10019 use_custom_mac = 1;
10020 else if (unformat (i, "server"))
10022 else if (unformat (i, "disable_mrg_rxbuf"))
10023 disable_mrg_rxbuf = 1;
10024 else if (unformat (i, "disable_indirect_desc"))
10025 disable_indirect_desc = 1;
10026 else if (unformat (i, "gso"))
10028 else if (unformat (i, "packed"))
10030 else if (unformat (i, "event-idx"))
10031 enable_event_idx = 1;
10032 else if (unformat (i, "tag %s", &tag))
10038 if (file_name_set == 0)
10040 errmsg ("missing socket file name");
10044 if (vec_len (file_name) > 255)
10046 errmsg ("socket file name too long");
10049 vec_add1 (file_name, 0);
10051 M (CREATE_VHOST_USER_IF_V2, mp);
10053 mp->is_server = is_server;
10054 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
10055 mp->disable_indirect_desc = disable_indirect_desc;
10056 mp->enable_gso = enable_gso;
10057 mp->enable_packed = enable_packed;
10058 mp->enable_event_idx = enable_event_idx;
10059 mp->custom_dev_instance = ntohl (custom_dev_instance);
10060 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10061 vec_free (file_name);
10062 if (custom_dev_instance != ~0)
10065 mp->use_custom_mac = use_custom_mac;
10066 clib_memcpy (mp->mac_address, hwaddr, 6);
10068 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10077 api_modify_vhost_user_if_v2 (vat_main_t * vam)
10079 unformat_input_t *i = vam->input;
10080 vl_api_modify_vhost_user_if_v2_t *mp;
10083 u8 file_name_set = 0;
10084 u32 custom_dev_instance = ~0;
10085 u8 sw_if_index_set = 0;
10086 u32 sw_if_index = (u32) ~ 0;
10088 u8 enable_packed = 0;
10089 u8 enable_event_idx = 0;
10092 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10094 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10095 sw_if_index_set = 1;
10096 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10097 sw_if_index_set = 1;
10098 else if (unformat (i, "socket %s", &file_name))
10102 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10104 else if (unformat (i, "server"))
10106 else if (unformat (i, "gso"))
10108 else if (unformat (i, "packed"))
10110 else if (unformat (i, "event-idx"))
10111 enable_event_idx = 1;
10116 if (sw_if_index_set == 0)
10118 errmsg ("missing sw_if_index or interface name");
10122 if (file_name_set == 0)
10124 errmsg ("missing socket file name");
10128 if (vec_len (file_name) > 255)
10130 errmsg ("socket file name too long");
10133 vec_add1 (file_name, 0);
10135 M (MODIFY_VHOST_USER_IF_V2, mp);
10137 mp->sw_if_index = ntohl (sw_if_index);
10138 mp->is_server = is_server;
10139 mp->enable_gso = enable_gso;
10140 mp->enable_packed = enable_packed;
10141 mp->enable_event_idx = enable_event_idx;
10142 mp->custom_dev_instance = ntohl (custom_dev_instance);
10143 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10144 vec_free (file_name);
10145 if (custom_dev_instance != ~0)
10154 api_delete_vhost_user_if (vat_main_t * vam)
10156 unformat_input_t *i = vam->input;
10157 vl_api_delete_vhost_user_if_t *mp;
10158 u32 sw_if_index = ~0;
10159 u8 sw_if_index_set = 0;
10162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10164 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10165 sw_if_index_set = 1;
10166 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10167 sw_if_index_set = 1;
10172 if (sw_if_index_set == 0)
10174 errmsg ("missing sw_if_index or interface name");
10179 M (DELETE_VHOST_USER_IF, mp);
10181 mp->sw_if_index = ntohl (sw_if_index);
10188 static void vl_api_sw_interface_vhost_user_details_t_handler
10189 (vl_api_sw_interface_vhost_user_details_t * mp)
10191 vat_main_t *vam = &vat_main;
10195 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10196 clib_net_to_host_u32
10197 (mp->features_last_32) <<
10200 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
10201 (char *) mp->interface_name, ntohl (mp->sw_if_index),
10202 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
10203 ntohl (mp->num_regions), (char *) mp->sock_filename);
10204 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10207 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10208 (vl_api_sw_interface_vhost_user_details_t * mp)
10210 vat_main_t *vam = &vat_main;
10211 vat_json_node_t *node = NULL;
10213 if (VAT_JSON_ARRAY != vam->json_tree.type)
10215 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10216 vat_json_init_array (&vam->json_tree);
10218 node = vat_json_array_add (&vam->json_tree);
10220 vat_json_init_object (node);
10221 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10222 vat_json_object_add_string_copy (node, "interface_name",
10223 mp->interface_name);
10224 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10225 ntohl (mp->virtio_net_hdr_sz));
10226 vat_json_object_add_uint (node, "features_first_32",
10227 clib_net_to_host_u32 (mp->features_first_32));
10228 vat_json_object_add_uint (node, "features_last_32",
10229 clib_net_to_host_u32 (mp->features_last_32));
10230 vat_json_object_add_uint (node, "is_server", mp->is_server);
10231 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10232 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10233 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10237 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10239 unformat_input_t *i = vam->input;
10240 vl_api_sw_interface_vhost_user_dump_t *mp;
10241 vl_api_control_ping_t *mp_ping;
10243 u32 sw_if_index = ~0;
10245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10247 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10249 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10255 print (vam->ofp, "Interface name idx hdr_sz features "
10256 "server regions filename");
10258 /* Get list of vhost-user interfaces */
10259 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10260 mp->sw_if_index = ntohl (sw_if_index);
10263 /* Use a control ping for synchronization */
10264 MPING (CONTROL_PING, mp_ping);
10272 api_show_version (vat_main_t * vam)
10274 vl_api_show_version_t *mp;
10277 M (SHOW_VERSION, mp);
10286 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10288 unformat_input_t *line_input = vam->input;
10289 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10290 ip46_address_t local, remote;
10295 u32 mcast_sw_if_index = ~0;
10296 u32 encap_vrf_id = 0;
10297 u32 decap_vrf_id = 0;
10303 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10305 if (unformat (line_input, "del"))
10307 else if (unformat (line_input, "local %U",
10308 unformat_ip46_address, &local))
10312 else if (unformat (line_input, "remote %U",
10313 unformat_ip46_address, &remote))
10317 else if (unformat (line_input, "group %U %U",
10318 unformat_ip46_address, &remote,
10319 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10321 grp_set = remote_set = 1;
10323 else if (unformat (line_input, "group %U",
10324 unformat_ip46_address, &remote))
10326 grp_set = remote_set = 1;
10329 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10331 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10333 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10335 else if (unformat (line_input, "vni %d", &vni))
10337 else if (unformat (line_input, "next-ip4"))
10339 else if (unformat (line_input, "next-ip6"))
10341 else if (unformat (line_input, "next-ethernet"))
10343 else if (unformat (line_input, "next-nsh"))
10347 errmsg ("parse error '%U'", format_unformat_error, line_input);
10352 if (local_set == 0)
10354 errmsg ("tunnel local address not specified");
10357 if (remote_set == 0)
10359 errmsg ("tunnel remote address not specified");
10362 if (grp_set && mcast_sw_if_index == ~0)
10364 errmsg ("tunnel nonexistent multicast device");
10367 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10369 errmsg ("both IPv4 and IPv6 addresses specified");
10375 errmsg ("vni not specified");
10379 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10381 ip_address_encode (&local,
10382 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10383 IP46_TYPE_IP6, &mp->local);
10384 ip_address_encode (&remote,
10385 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10386 IP46_TYPE_IP6, &mp->remote);
10388 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10389 mp->encap_vrf_id = ntohl (encap_vrf_id);
10390 mp->decap_vrf_id = ntohl (decap_vrf_id);
10391 mp->protocol = protocol;
10392 mp->vni = ntohl (vni);
10393 mp->is_add = is_add;
10400 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10401 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10403 vat_main_t *vam = &vat_main;
10404 ip46_address_t local, remote;
10406 ip_address_decode (&mp->local, &local);
10407 ip_address_decode (&mp->remote, &remote);
10409 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10410 ntohl (mp->sw_if_index),
10411 format_ip46_address, &local, IP46_TYPE_ANY,
10412 format_ip46_address, &remote, IP46_TYPE_ANY,
10413 ntohl (mp->vni), mp->protocol,
10414 ntohl (mp->mcast_sw_if_index),
10415 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10419 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10420 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10422 vat_main_t *vam = &vat_main;
10423 vat_json_node_t *node = NULL;
10424 struct in_addr ip4;
10425 struct in6_addr ip6;
10426 ip46_address_t local, remote;
10428 ip_address_decode (&mp->local, &local);
10429 ip_address_decode (&mp->remote, &remote);
10431 if (VAT_JSON_ARRAY != vam->json_tree.type)
10433 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10434 vat_json_init_array (&vam->json_tree);
10436 node = vat_json_array_add (&vam->json_tree);
10438 vat_json_init_object (node);
10439 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10440 if (ip46_address_is_ip4 (&local))
10442 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10443 vat_json_object_add_ip4 (node, "local", ip4);
10444 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10445 vat_json_object_add_ip4 (node, "remote", ip4);
10449 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10450 vat_json_object_add_ip6 (node, "local", ip6);
10451 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10452 vat_json_object_add_ip6 (node, "remote", ip6);
10454 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10455 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10456 vat_json_object_add_uint (node, "mcast_sw_if_index",
10457 ntohl (mp->mcast_sw_if_index));
10458 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10459 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10460 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10464 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10466 unformat_input_t *i = vam->input;
10467 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10468 vl_api_control_ping_t *mp_ping;
10470 u8 sw_if_index_set = 0;
10473 /* Parse args required to build the message */
10474 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10476 if (unformat (i, "sw_if_index %d", &sw_if_index))
10477 sw_if_index_set = 1;
10482 if (sw_if_index_set == 0)
10487 if (!vam->json_output)
10489 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10490 "sw_if_index", "local", "remote", "vni",
10491 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10494 /* Get list of vxlan-tunnel interfaces */
10495 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10497 mp->sw_if_index = htonl (sw_if_index);
10501 /* Use a control ping for synchronization */
10502 MPING (CONTROL_PING, mp_ping);
10509 static void vl_api_l2_fib_table_details_t_handler
10510 (vl_api_l2_fib_table_details_t * mp)
10512 vat_main_t *vam = &vat_main;
10514 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10516 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10517 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10521 static void vl_api_l2_fib_table_details_t_handler_json
10522 (vl_api_l2_fib_table_details_t * mp)
10524 vat_main_t *vam = &vat_main;
10525 vat_json_node_t *node = NULL;
10527 if (VAT_JSON_ARRAY != vam->json_tree.type)
10529 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10530 vat_json_init_array (&vam->json_tree);
10532 node = vat_json_array_add (&vam->json_tree);
10534 vat_json_init_object (node);
10535 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10536 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10537 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10538 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10539 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10540 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10544 api_l2_fib_table_dump (vat_main_t * vam)
10546 unformat_input_t *i = vam->input;
10547 vl_api_l2_fib_table_dump_t *mp;
10548 vl_api_control_ping_t *mp_ping;
10553 /* Parse args required to build the message */
10554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10556 if (unformat (i, "bd_id %d", &bd_id))
10562 if (bd_id_set == 0)
10564 errmsg ("missing bridge domain");
10568 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10570 /* Get list of l2 fib entries */
10571 M (L2_FIB_TABLE_DUMP, mp);
10573 mp->bd_id = ntohl (bd_id);
10576 /* Use a control ping for synchronization */
10577 MPING (CONTROL_PING, mp_ping);
10586 api_interface_name_renumber (vat_main_t * vam)
10588 unformat_input_t *line_input = vam->input;
10589 vl_api_interface_name_renumber_t *mp;
10590 u32 sw_if_index = ~0;
10591 u32 new_show_dev_instance = ~0;
10594 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10596 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10599 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10601 else if (unformat (line_input, "new_show_dev_instance %d",
10602 &new_show_dev_instance))
10608 if (sw_if_index == ~0)
10610 errmsg ("missing interface name or sw_if_index");
10614 if (new_show_dev_instance == ~0)
10616 errmsg ("missing new_show_dev_instance");
10620 M (INTERFACE_NAME_RENUMBER, mp);
10622 mp->sw_if_index = ntohl (sw_if_index);
10623 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10631 api_want_l2_macs_events (vat_main_t * vam)
10633 unformat_input_t *line_input = vam->input;
10634 vl_api_want_l2_macs_events_t *mp;
10635 u8 enable_disable = 1;
10636 u32 scan_delay = 0;
10637 u32 max_macs_in_event = 0;
10638 u32 learn_limit = 0;
10641 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10643 if (unformat (line_input, "learn-limit %d", &learn_limit))
10645 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10647 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10649 else if (unformat (line_input, "disable"))
10650 enable_disable = 0;
10655 M (WANT_L2_MACS_EVENTS, mp);
10656 mp->enable_disable = enable_disable;
10657 mp->pid = htonl (getpid ());
10658 mp->learn_limit = htonl (learn_limit);
10659 mp->scan_delay = (u8) scan_delay;
10660 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10667 api_input_acl_set_interface (vat_main_t * vam)
10669 unformat_input_t *i = vam->input;
10670 vl_api_input_acl_set_interface_t *mp;
10672 int sw_if_index_set;
10673 u32 ip4_table_index = ~0;
10674 u32 ip6_table_index = ~0;
10675 u32 l2_table_index = ~0;
10679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10681 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10682 sw_if_index_set = 1;
10683 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10684 sw_if_index_set = 1;
10685 else if (unformat (i, "del"))
10687 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10689 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10691 else if (unformat (i, "l2-table %d", &l2_table_index))
10695 clib_warning ("parse error '%U'", format_unformat_error, i);
10700 if (sw_if_index_set == 0)
10702 errmsg ("missing interface name or sw_if_index");
10706 M (INPUT_ACL_SET_INTERFACE, mp);
10708 mp->sw_if_index = ntohl (sw_if_index);
10709 mp->ip4_table_index = ntohl (ip4_table_index);
10710 mp->ip6_table_index = ntohl (ip6_table_index);
10711 mp->l2_table_index = ntohl (l2_table_index);
10712 mp->is_add = is_add;
10720 api_output_acl_set_interface (vat_main_t * vam)
10722 unformat_input_t *i = vam->input;
10723 vl_api_output_acl_set_interface_t *mp;
10725 int sw_if_index_set;
10726 u32 ip4_table_index = ~0;
10727 u32 ip6_table_index = ~0;
10728 u32 l2_table_index = ~0;
10732 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10734 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10735 sw_if_index_set = 1;
10736 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10737 sw_if_index_set = 1;
10738 else if (unformat (i, "del"))
10740 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10742 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10744 else if (unformat (i, "l2-table %d", &l2_table_index))
10748 clib_warning ("parse error '%U'", format_unformat_error, i);
10753 if (sw_if_index_set == 0)
10755 errmsg ("missing interface name or sw_if_index");
10759 M (OUTPUT_ACL_SET_INTERFACE, mp);
10761 mp->sw_if_index = ntohl (sw_if_index);
10762 mp->ip4_table_index = ntohl (ip4_table_index);
10763 mp->ip6_table_index = ntohl (ip6_table_index);
10764 mp->l2_table_index = ntohl (l2_table_index);
10765 mp->is_add = is_add;
10773 api_ip_address_dump (vat_main_t * vam)
10775 unformat_input_t *i = vam->input;
10776 vl_api_ip_address_dump_t *mp;
10777 vl_api_control_ping_t *mp_ping;
10778 u32 sw_if_index = ~0;
10779 u8 sw_if_index_set = 0;
10784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10786 if (unformat (i, "sw_if_index %d", &sw_if_index))
10787 sw_if_index_set = 1;
10789 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10790 sw_if_index_set = 1;
10791 else if (unformat (i, "ipv4"))
10793 else if (unformat (i, "ipv6"))
10799 if (ipv4_set && ipv6_set)
10801 errmsg ("ipv4 and ipv6 flags cannot be both set");
10805 if ((!ipv4_set) && (!ipv6_set))
10807 errmsg ("no ipv4 nor ipv6 flag set");
10811 if (sw_if_index_set == 0)
10813 errmsg ("missing interface name or sw_if_index");
10817 vam->current_sw_if_index = sw_if_index;
10818 vam->is_ipv6 = ipv6_set;
10820 M (IP_ADDRESS_DUMP, mp);
10821 mp->sw_if_index = ntohl (sw_if_index);
10822 mp->is_ipv6 = ipv6_set;
10825 /* Use a control ping for synchronization */
10826 MPING (CONTROL_PING, mp_ping);
10834 api_ip_dump (vat_main_t * vam)
10836 vl_api_ip_dump_t *mp;
10837 vl_api_control_ping_t *mp_ping;
10838 unformat_input_t *in = vam->input;
10845 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10847 if (unformat (in, "ipv4"))
10849 else if (unformat (in, "ipv6"))
10855 if (ipv4_set && ipv6_set)
10857 errmsg ("ipv4 and ipv6 flags cannot be both set");
10861 if ((!ipv4_set) && (!ipv6_set))
10863 errmsg ("no ipv4 nor ipv6 flag set");
10867 is_ipv6 = ipv6_set;
10868 vam->is_ipv6 = is_ipv6;
10870 /* free old data */
10871 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10873 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10875 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10878 mp->is_ipv6 = ipv6_set;
10881 /* Use a control ping for synchronization */
10882 MPING (CONTROL_PING, mp_ping);
10890 api_ipsec_spd_add_del (vat_main_t * vam)
10892 unformat_input_t *i = vam->input;
10893 vl_api_ipsec_spd_add_del_t *mp;
10898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10900 if (unformat (i, "spd_id %d", &spd_id))
10902 else if (unformat (i, "del"))
10906 clib_warning ("parse error '%U'", format_unformat_error, i);
10912 errmsg ("spd_id must be set");
10916 M (IPSEC_SPD_ADD_DEL, mp);
10918 mp->spd_id = ntohl (spd_id);
10919 mp->is_add = is_add;
10927 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10929 unformat_input_t *i = vam->input;
10930 vl_api_ipsec_interface_add_del_spd_t *mp;
10932 u8 sw_if_index_set = 0;
10933 u32 spd_id = (u32) ~ 0;
10937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10939 if (unformat (i, "del"))
10941 else if (unformat (i, "spd_id %d", &spd_id))
10944 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10945 sw_if_index_set = 1;
10946 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10947 sw_if_index_set = 1;
10950 clib_warning ("parse error '%U'", format_unformat_error, i);
10956 if (spd_id == (u32) ~ 0)
10958 errmsg ("spd_id must be set");
10962 if (sw_if_index_set == 0)
10964 errmsg ("missing interface name or sw_if_index");
10968 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10970 mp->spd_id = ntohl (spd_id);
10971 mp->sw_if_index = ntohl (sw_if_index);
10972 mp->is_add = is_add;
10980 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10982 unformat_input_t *i = vam->input;
10983 vl_api_ipsec_spd_entry_add_del_t *mp;
10984 u8 is_add = 1, is_outbound = 0;
10985 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10987 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10988 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10989 vl_api_address_t laddr_start = { }, laddr_stop =
10998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11000 if (unformat (i, "del"))
11002 if (unformat (i, "outbound"))
11004 if (unformat (i, "inbound"))
11006 else if (unformat (i, "spd_id %d", &spd_id))
11008 else if (unformat (i, "sa_id %d", &sa_id))
11010 else if (unformat (i, "priority %d", &priority))
11012 else if (unformat (i, "protocol %d", &protocol))
11014 else if (unformat (i, "lport_start %d", &lport_start))
11016 else if (unformat (i, "lport_stop %d", &lport_stop))
11018 else if (unformat (i, "rport_start %d", &rport_start))
11020 else if (unformat (i, "rport_stop %d", &rport_stop))
11022 else if (unformat (i, "laddr_start %U",
11023 unformat_vl_api_address, &laddr_start))
11025 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
11028 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
11031 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
11035 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11037 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11039 clib_warning ("unsupported action: 'resolve'");
11045 clib_warning ("parse error '%U'", format_unformat_error, i);
11051 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
11053 mp->is_add = is_add;
11055 mp->entry.spd_id = ntohl (spd_id);
11056 mp->entry.priority = ntohl (priority);
11057 mp->entry.is_outbound = is_outbound;
11059 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
11060 sizeof (vl_api_address_t));
11061 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
11062 sizeof (vl_api_address_t));
11063 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
11064 sizeof (vl_api_address_t));
11065 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
11066 sizeof (vl_api_address_t));
11068 mp->entry.protocol = (u8) protocol;
11069 mp->entry.local_port_start = ntohs ((u16) lport_start);
11070 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
11071 mp->entry.remote_port_start = ntohs ((u16) rport_start);
11072 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
11073 mp->entry.policy = (u8) policy;
11074 mp->entry.sa_id = ntohl (sa_id);
11082 api_ipsec_sad_entry_add_del (vat_main_t * vam)
11084 unformat_input_t *i = vam->input;
11085 vl_api_ipsec_sad_entry_add_del_t *mp;
11086 u32 sad_id = 0, spi = 0;
11087 u8 *ck = 0, *ik = 0;
11090 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
11091 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
11092 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
11093 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
11094 vl_api_address_t tun_src, tun_dst;
11097 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11099 if (unformat (i, "del"))
11101 else if (unformat (i, "sad_id %d", &sad_id))
11103 else if (unformat (i, "spi %d", &spi))
11105 else if (unformat (i, "esp"))
11106 protocol = IPSEC_API_PROTO_ESP;
11108 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
11110 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11111 if (ADDRESS_IP6 == tun_src.af)
11112 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11115 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
11117 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11118 if (ADDRESS_IP6 == tun_src.af)
11119 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11122 if (unformat (i, "crypto_alg %U",
11123 unformat_ipsec_api_crypto_alg, &crypto_alg))
11125 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11127 else if (unformat (i, "integ_alg %U",
11128 unformat_ipsec_api_integ_alg, &integ_alg))
11130 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11134 clib_warning ("parse error '%U'", format_unformat_error, i);
11140 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
11142 mp->is_add = is_add;
11143 mp->entry.sad_id = ntohl (sad_id);
11144 mp->entry.protocol = protocol;
11145 mp->entry.spi = ntohl (spi);
11146 mp->entry.flags = flags;
11148 mp->entry.crypto_algorithm = crypto_alg;
11149 mp->entry.integrity_algorithm = integ_alg;
11150 mp->entry.crypto_key.length = vec_len (ck);
11151 mp->entry.integrity_key.length = vec_len (ik);
11153 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
11154 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
11156 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
11157 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
11160 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
11162 clib_memcpy (mp->entry.integrity_key.data, ik,
11163 mp->entry.integrity_key.length);
11165 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
11167 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
11168 sizeof (mp->entry.tunnel_src));
11169 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
11170 sizeof (mp->entry.tunnel_dst));
11179 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11181 vat_main_t *vam = &vat_main;
11183 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11184 "crypto_key %U integ_alg %u integ_key %U flags %x "
11185 "tunnel_src_addr %U tunnel_dst_addr %U "
11186 "salt %u seq_outbound %lu last_seq_inbound %lu "
11187 "replay_window %lu stat_index %u\n",
11188 ntohl (mp->entry.sad_id),
11189 ntohl (mp->sw_if_index),
11190 ntohl (mp->entry.spi),
11191 ntohl (mp->entry.protocol),
11192 ntohl (mp->entry.crypto_algorithm),
11193 format_hex_bytes, mp->entry.crypto_key.data,
11194 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11195 format_hex_bytes, mp->entry.integrity_key.data,
11196 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11197 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11198 &mp->entry.tunnel_dst, ntohl (mp->salt),
11199 clib_net_to_host_u64 (mp->seq_outbound),
11200 clib_net_to_host_u64 (mp->last_seq_inbound),
11201 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11204 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11205 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11207 static void vl_api_ipsec_sa_details_t_handler_json
11208 (vl_api_ipsec_sa_details_t * mp)
11210 vat_main_t *vam = &vat_main;
11211 vat_json_node_t *node = NULL;
11212 vl_api_ipsec_sad_flags_t flags;
11214 if (VAT_JSON_ARRAY != vam->json_tree.type)
11216 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11217 vat_json_init_array (&vam->json_tree);
11219 node = vat_json_array_add (&vam->json_tree);
11221 vat_json_init_object (node);
11222 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11223 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11224 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11225 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11226 vat_json_object_add_uint (node, "crypto_alg",
11227 ntohl (mp->entry.crypto_algorithm));
11228 vat_json_object_add_uint (node, "integ_alg",
11229 ntohl (mp->entry.integrity_algorithm));
11230 flags = ntohl (mp->entry.flags);
11231 vat_json_object_add_uint (node, "use_esn",
11232 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11233 vat_json_object_add_uint (node, "use_anti_replay",
11234 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11235 vat_json_object_add_uint (node, "is_tunnel",
11236 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11237 vat_json_object_add_uint (node, "is_tunnel_ip6",
11238 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11239 vat_json_object_add_uint (node, "udp_encap",
11240 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11241 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11242 mp->entry.crypto_key.length);
11243 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11244 mp->entry.integrity_key.length);
11245 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11246 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11247 vat_json_object_add_uint (node, "replay_window",
11248 clib_net_to_host_u64 (mp->replay_window));
11249 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11253 api_ipsec_sa_dump (vat_main_t * vam)
11255 unformat_input_t *i = vam->input;
11256 vl_api_ipsec_sa_dump_t *mp;
11257 vl_api_control_ping_t *mp_ping;
11261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11263 if (unformat (i, "sa_id %d", &sa_id))
11267 clib_warning ("parse error '%U'", format_unformat_error, i);
11272 M (IPSEC_SA_DUMP, mp);
11274 mp->sa_id = ntohl (sa_id);
11278 /* Use a control ping for synchronization */
11279 M (CONTROL_PING, mp_ping);
11287 api_get_first_msg_id (vat_main_t * vam)
11289 vl_api_get_first_msg_id_t *mp;
11290 unformat_input_t *i = vam->input;
11295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11297 if (unformat (i, "client %s", &name))
11305 errmsg ("missing client name");
11308 vec_add1 (name, 0);
11310 if (vec_len (name) > 63)
11312 errmsg ("client name too long");
11316 M (GET_FIRST_MSG_ID, mp);
11317 clib_memcpy (mp->name, name, vec_len (name));
11324 api_cop_interface_enable_disable (vat_main_t * vam)
11326 unformat_input_t *line_input = vam->input;
11327 vl_api_cop_interface_enable_disable_t *mp;
11328 u32 sw_if_index = ~0;
11329 u8 enable_disable = 1;
11332 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11334 if (unformat (line_input, "disable"))
11335 enable_disable = 0;
11336 if (unformat (line_input, "enable"))
11337 enable_disable = 1;
11338 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11339 vam, &sw_if_index))
11341 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11347 if (sw_if_index == ~0)
11349 errmsg ("missing interface name or sw_if_index");
11353 /* Construct the API message */
11354 M (COP_INTERFACE_ENABLE_DISABLE, mp);
11355 mp->sw_if_index = ntohl (sw_if_index);
11356 mp->enable_disable = enable_disable;
11360 /* Wait for the reply */
11366 api_cop_whitelist_enable_disable (vat_main_t * vam)
11368 unformat_input_t *line_input = vam->input;
11369 vl_api_cop_whitelist_enable_disable_t *mp;
11370 u32 sw_if_index = ~0;
11371 u8 ip4 = 0, ip6 = 0, default_cop = 0;
11375 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11377 if (unformat (line_input, "ip4"))
11379 else if (unformat (line_input, "ip6"))
11381 else if (unformat (line_input, "default"))
11383 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11384 vam, &sw_if_index))
11386 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11388 else if (unformat (line_input, "fib-id %d", &fib_id))
11394 if (sw_if_index == ~0)
11396 errmsg ("missing interface name or sw_if_index");
11400 /* Construct the API message */
11401 M (COP_WHITELIST_ENABLE_DISABLE, mp);
11402 mp->sw_if_index = ntohl (sw_if_index);
11403 mp->fib_id = ntohl (fib_id);
11406 mp->default_cop = default_cop;
11410 /* Wait for the reply */
11416 api_get_node_graph (vat_main_t * vam)
11418 vl_api_get_node_graph_t *mp;
11421 M (GET_NODE_GRAPH, mp);
11425 /* Wait for the reply */
11431 api_af_packet_create (vat_main_t * vam)
11433 unformat_input_t *i = vam->input;
11434 vl_api_af_packet_create_t *mp;
11435 u8 *host_if_name = 0;
11437 u8 random_hw_addr = 1;
11440 clib_memset (hw_addr, 0, sizeof (hw_addr));
11442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11444 if (unformat (i, "name %s", &host_if_name))
11445 vec_add1 (host_if_name, 0);
11446 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11447 random_hw_addr = 0;
11452 if (!vec_len (host_if_name))
11454 errmsg ("host-interface name must be specified");
11458 if (vec_len (host_if_name) > 64)
11460 errmsg ("host-interface name too long");
11464 M (AF_PACKET_CREATE, mp);
11466 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11467 clib_memcpy (mp->hw_addr, hw_addr, 6);
11468 mp->use_random_hw_addr = random_hw_addr;
11469 vec_free (host_if_name);
11477 fprintf (vam->ofp ? vam->ofp : stderr,
11478 " new sw_if_index = %d\n", vam->sw_if_index);
11485 api_af_packet_delete (vat_main_t * vam)
11487 unformat_input_t *i = vam->input;
11488 vl_api_af_packet_delete_t *mp;
11489 u8 *host_if_name = 0;
11492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11494 if (unformat (i, "name %s", &host_if_name))
11495 vec_add1 (host_if_name, 0);
11500 if (!vec_len (host_if_name))
11502 errmsg ("host-interface name must be specified");
11506 if (vec_len (host_if_name) > 64)
11508 errmsg ("host-interface name too long");
11512 M (AF_PACKET_DELETE, mp);
11514 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11515 vec_free (host_if_name);
11522 static void vl_api_af_packet_details_t_handler
11523 (vl_api_af_packet_details_t * mp)
11525 vat_main_t *vam = &vat_main;
11527 print (vam->ofp, "%-16s %d",
11528 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11531 static void vl_api_af_packet_details_t_handler_json
11532 (vl_api_af_packet_details_t * mp)
11534 vat_main_t *vam = &vat_main;
11535 vat_json_node_t *node = NULL;
11537 if (VAT_JSON_ARRAY != vam->json_tree.type)
11539 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11540 vat_json_init_array (&vam->json_tree);
11542 node = vat_json_array_add (&vam->json_tree);
11544 vat_json_init_object (node);
11545 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11546 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11550 api_af_packet_dump (vat_main_t * vam)
11552 vl_api_af_packet_dump_t *mp;
11553 vl_api_control_ping_t *mp_ping;
11556 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11557 /* Get list of tap interfaces */
11558 M (AF_PACKET_DUMP, mp);
11561 /* Use a control ping for synchronization */
11562 MPING (CONTROL_PING, mp_ping);
11570 api_policer_add_del (vat_main_t * vam)
11572 unformat_input_t *i = vam->input;
11573 vl_api_policer_add_del_t *mp;
11583 u8 color_aware = 0;
11584 qos_pol_action_params_st conform_action, exceed_action, violate_action;
11587 conform_action.action_type = QOS_ACTION_TRANSMIT;
11588 conform_action.dscp = 0;
11589 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
11590 exceed_action.dscp = 0;
11591 violate_action.action_type = QOS_ACTION_DROP;
11592 violate_action.dscp = 0;
11594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11596 if (unformat (i, "del"))
11598 else if (unformat (i, "name %s", &name))
11599 vec_add1 (name, 0);
11600 else if (unformat (i, "cir %u", &cir))
11602 else if (unformat (i, "eir %u", &eir))
11604 else if (unformat (i, "cb %u", &cb))
11606 else if (unformat (i, "eb %u", &eb))
11608 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11611 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11614 else if (unformat (i, "type %U", unformat_policer_type, &type))
11616 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11619 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11622 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11625 else if (unformat (i, "color-aware"))
11631 if (!vec_len (name))
11633 errmsg ("policer name must be specified");
11637 if (vec_len (name) > 64)
11639 errmsg ("policer name too long");
11643 M (POLICER_ADD_DEL, mp);
11645 clib_memcpy (mp->name, name, vec_len (name));
11647 mp->is_add = is_add;
11648 mp->cir = ntohl (cir);
11649 mp->eir = ntohl (eir);
11650 mp->cb = clib_net_to_host_u64 (cb);
11651 mp->eb = clib_net_to_host_u64 (eb);
11652 mp->rate_type = rate_type;
11653 mp->round_type = round_type;
11655 mp->conform_action.type = conform_action.action_type;
11656 mp->conform_action.dscp = conform_action.dscp;
11657 mp->exceed_action.type = exceed_action.action_type;
11658 mp->exceed_action.dscp = exceed_action.dscp;
11659 mp->violate_action.type = violate_action.action_type;
11660 mp->violate_action.dscp = violate_action.dscp;
11661 mp->color_aware = color_aware;
11669 api_policer_dump (vat_main_t * vam)
11671 unformat_input_t *i = vam->input;
11672 vl_api_policer_dump_t *mp;
11673 vl_api_control_ping_t *mp_ping;
11674 u8 *match_name = 0;
11675 u8 match_name_valid = 0;
11678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11680 if (unformat (i, "name %s", &match_name))
11682 vec_add1 (match_name, 0);
11683 match_name_valid = 1;
11689 M (POLICER_DUMP, mp);
11690 mp->match_name_valid = match_name_valid;
11691 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11692 vec_free (match_name);
11696 /* Use a control ping for synchronization */
11697 MPING (CONTROL_PING, mp_ping);
11700 /* Wait for a reply... */
11706 api_policer_classify_set_interface (vat_main_t * vam)
11708 unformat_input_t *i = vam->input;
11709 vl_api_policer_classify_set_interface_t *mp;
11711 int sw_if_index_set;
11712 u32 ip4_table_index = ~0;
11713 u32 ip6_table_index = ~0;
11714 u32 l2_table_index = ~0;
11718 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11720 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11721 sw_if_index_set = 1;
11722 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11723 sw_if_index_set = 1;
11724 else if (unformat (i, "del"))
11726 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11728 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11730 else if (unformat (i, "l2-table %d", &l2_table_index))
11734 clib_warning ("parse error '%U'", format_unformat_error, i);
11739 if (sw_if_index_set == 0)
11741 errmsg ("missing interface name or sw_if_index");
11745 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
11747 mp->sw_if_index = ntohl (sw_if_index);
11748 mp->ip4_table_index = ntohl (ip4_table_index);
11749 mp->ip6_table_index = ntohl (ip6_table_index);
11750 mp->l2_table_index = ntohl (l2_table_index);
11751 mp->is_add = is_add;
11759 api_policer_classify_dump (vat_main_t * vam)
11761 unformat_input_t *i = vam->input;
11762 vl_api_policer_classify_dump_t *mp;
11763 vl_api_control_ping_t *mp_ping;
11764 u8 type = POLICER_CLASSIFY_N_TABLES;
11767 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
11771 errmsg ("classify table type must be specified");
11775 if (!vam->json_output)
11777 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
11780 M (POLICER_CLASSIFY_DUMP, mp);
11785 /* Use a control ping for synchronization */
11786 MPING (CONTROL_PING, mp_ping);
11789 /* Wait for a reply... */
11795 format_fib_api_path_nh_proto (u8 * s, va_list * args)
11797 vl_api_fib_path_nh_proto_t proto =
11798 va_arg (*args, vl_api_fib_path_nh_proto_t);
11802 case FIB_API_PATH_NH_PROTO_IP4:
11803 s = format (s, "ip4");
11805 case FIB_API_PATH_NH_PROTO_IP6:
11806 s = format (s, "ip6");
11808 case FIB_API_PATH_NH_PROTO_MPLS:
11809 s = format (s, "mpls");
11811 case FIB_API_PATH_NH_PROTO_BIER:
11812 s = format (s, "bier");
11814 case FIB_API_PATH_NH_PROTO_ETHERNET:
11815 s = format (s, "ethernet");
11823 format_vl_api_ip_address_union (u8 * s, va_list * args)
11825 vl_api_address_family_t af = va_arg (*args, int);
11826 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
11831 s = format (s, "%U", format_ip4_address, u->ip4);
11834 s = format (s, "%U", format_ip6_address, u->ip6);
11841 format_vl_api_fib_path_type (u8 * s, va_list * args)
11843 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
11847 case FIB_API_PATH_TYPE_NORMAL:
11848 s = format (s, "normal");
11850 case FIB_API_PATH_TYPE_LOCAL:
11851 s = format (s, "local");
11853 case FIB_API_PATH_TYPE_DROP:
11854 s = format (s, "drop");
11856 case FIB_API_PATH_TYPE_UDP_ENCAP:
11857 s = format (s, "udp-encap");
11859 case FIB_API_PATH_TYPE_BIER_IMP:
11860 s = format (s, "bier-imp");
11862 case FIB_API_PATH_TYPE_ICMP_UNREACH:
11863 s = format (s, "unreach");
11865 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
11866 s = format (s, "prohibit");
11868 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
11869 s = format (s, "src-lookup");
11871 case FIB_API_PATH_TYPE_DVR:
11872 s = format (s, "dvr");
11874 case FIB_API_PATH_TYPE_INTERFACE_RX:
11875 s = format (s, "interface-rx");
11877 case FIB_API_PATH_TYPE_CLASSIFY:
11878 s = format (s, "classify");
11886 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
11889 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
11890 ntohl (fp->weight), ntohl (fp->sw_if_index),
11891 format_vl_api_fib_path_type, fp->type,
11892 format_fib_api_path_nh_proto, fp->proto,
11893 format_vl_api_ip_address_union, &fp->nh.address);
11897 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
11898 vl_api_fib_path_t * fp)
11900 struct in_addr ip4;
11901 struct in6_addr ip6;
11903 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
11904 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
11905 vat_json_object_add_uint (node, "type", fp->type);
11906 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
11907 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
11909 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
11910 vat_json_object_add_ip4 (node, "next_hop", ip4);
11912 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
11914 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
11915 vat_json_object_add_ip6 (node, "next_hop", ip6);
11920 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
11922 vat_main_t *vam = &vat_main;
11923 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11924 vl_api_fib_path_t *fp;
11927 print (vam->ofp, "sw_if_index %d via:",
11928 ntohl (mp->mt_tunnel.mt_sw_if_index));
11929 fp = mp->mt_tunnel.mt_paths;
11930 for (i = 0; i < count; i++)
11932 vl_api_fib_path_print (vam, fp);
11936 print (vam->ofp, "");
11939 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
11940 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
11943 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
11945 vat_main_t *vam = &vat_main;
11946 vat_json_node_t *node = NULL;
11947 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11948 vl_api_fib_path_t *fp;
11951 if (VAT_JSON_ARRAY != vam->json_tree.type)
11953 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11954 vat_json_init_array (&vam->json_tree);
11956 node = vat_json_array_add (&vam->json_tree);
11958 vat_json_init_object (node);
11959 vat_json_object_add_uint (node, "sw_if_index",
11960 ntohl (mp->mt_tunnel.mt_sw_if_index));
11962 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
11964 fp = mp->mt_tunnel.mt_paths;
11965 for (i = 0; i < count; i++)
11967 vl_api_mpls_fib_path_json_print (node, fp);
11973 api_mpls_tunnel_dump (vat_main_t * vam)
11975 vl_api_mpls_tunnel_dump_t *mp;
11976 vl_api_control_ping_t *mp_ping;
11979 M (MPLS_TUNNEL_DUMP, mp);
11983 /* Use a control ping for synchronization */
11984 MPING (CONTROL_PING, mp_ping);
11991 #define vl_api_mpls_table_details_t_endian vl_noop_handler
11992 #define vl_api_mpls_table_details_t_print vl_noop_handler
11996 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
11998 vat_main_t *vam = &vat_main;
12000 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
12003 static void vl_api_mpls_table_details_t_handler_json
12004 (vl_api_mpls_table_details_t * mp)
12006 vat_main_t *vam = &vat_main;
12007 vat_json_node_t *node = NULL;
12009 if (VAT_JSON_ARRAY != vam->json_tree.type)
12011 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12012 vat_json_init_array (&vam->json_tree);
12014 node = vat_json_array_add (&vam->json_tree);
12016 vat_json_init_object (node);
12017 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
12021 api_mpls_table_dump (vat_main_t * vam)
12023 vl_api_mpls_table_dump_t *mp;
12024 vl_api_control_ping_t *mp_ping;
12027 M (MPLS_TABLE_DUMP, mp);
12030 /* Use a control ping for synchronization */
12031 MPING (CONTROL_PING, mp_ping);
12038 #define vl_api_mpls_route_details_t_endian vl_noop_handler
12039 #define vl_api_mpls_route_details_t_print vl_noop_handler
12042 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
12044 vat_main_t *vam = &vat_main;
12045 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
12046 vl_api_fib_path_t *fp;
12050 "table-id %d, label %u, ess_bit %u",
12051 ntohl (mp->mr_route.mr_table_id),
12052 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
12053 fp = mp->mr_route.mr_paths;
12054 for (i = 0; i < count; i++)
12056 vl_api_fib_path_print (vam, fp);
12061 static void vl_api_mpls_route_details_t_handler_json
12062 (vl_api_mpls_route_details_t * mp)
12064 vat_main_t *vam = &vat_main;
12065 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
12066 vat_json_node_t *node = NULL;
12067 vl_api_fib_path_t *fp;
12070 if (VAT_JSON_ARRAY != vam->json_tree.type)
12072 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12073 vat_json_init_array (&vam->json_tree);
12075 node = vat_json_array_add (&vam->json_tree);
12077 vat_json_init_object (node);
12078 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
12079 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
12080 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
12081 vat_json_object_add_uint (node, "path_count", count);
12082 fp = mp->mr_route.mr_paths;
12083 for (i = 0; i < count; i++)
12085 vl_api_mpls_fib_path_json_print (node, fp);
12091 api_mpls_route_dump (vat_main_t * vam)
12093 unformat_input_t *input = vam->input;
12094 vl_api_mpls_route_dump_t *mp;
12095 vl_api_control_ping_t *mp_ping;
12099 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12101 if (unformat (input, "table_id %d", &table_id))
12106 if (table_id == ~0)
12108 errmsg ("missing table id");
12112 M (MPLS_ROUTE_DUMP, mp);
12114 mp->table.mt_table_id = ntohl (table_id);
12117 /* Use a control ping for synchronization */
12118 MPING (CONTROL_PING, mp_ping);
12125 #define vl_api_ip_table_details_t_endian vl_noop_handler
12126 #define vl_api_ip_table_details_t_print vl_noop_handler
12129 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12131 vat_main_t *vam = &vat_main;
12134 "%s; table-id %d, prefix %U/%d",
12135 mp->table.name, ntohl (mp->table.table_id));
12139 static void vl_api_ip_table_details_t_handler_json
12140 (vl_api_ip_table_details_t * mp)
12142 vat_main_t *vam = &vat_main;
12143 vat_json_node_t *node = NULL;
12145 if (VAT_JSON_ARRAY != vam->json_tree.type)
12147 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12148 vat_json_init_array (&vam->json_tree);
12150 node = vat_json_array_add (&vam->json_tree);
12152 vat_json_init_object (node);
12153 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12157 api_ip_table_dump (vat_main_t * vam)
12159 vl_api_ip_table_dump_t *mp;
12160 vl_api_control_ping_t *mp_ping;
12163 M (IP_TABLE_DUMP, mp);
12166 /* Use a control ping for synchronization */
12167 MPING (CONTROL_PING, mp_ping);
12175 api_ip_mtable_dump (vat_main_t * vam)
12177 vl_api_ip_mtable_dump_t *mp;
12178 vl_api_control_ping_t *mp_ping;
12181 M (IP_MTABLE_DUMP, mp);
12184 /* Use a control ping for synchronization */
12185 MPING (CONTROL_PING, mp_ping);
12193 api_ip_mroute_dump (vat_main_t * vam)
12195 unformat_input_t *input = vam->input;
12196 vl_api_control_ping_t *mp_ping;
12197 vl_api_ip_mroute_dump_t *mp;
12202 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12204 if (unformat (input, "table_id %d", &table_id))
12206 else if (unformat (input, "ip6"))
12208 else if (unformat (input, "ip4"))
12213 if (table_id == ~0)
12215 errmsg ("missing table id");
12219 M (IP_MROUTE_DUMP, mp);
12220 mp->table.table_id = table_id;
12221 mp->table.is_ip6 = is_ip6;
12224 /* Use a control ping for synchronization */
12225 MPING (CONTROL_PING, mp_ping);
12232 #define vl_api_ip_route_details_t_endian vl_noop_handler
12233 #define vl_api_ip_route_details_t_print vl_noop_handler
12236 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12238 vat_main_t *vam = &vat_main;
12239 u8 count = mp->route.n_paths;
12240 vl_api_fib_path_t *fp;
12244 "table-id %d, prefix %U/%d",
12245 ntohl (mp->route.table_id),
12246 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12247 for (i = 0; i < count; i++)
12249 fp = &mp->route.paths[i];
12251 vl_api_fib_path_print (vam, fp);
12256 static void vl_api_ip_route_details_t_handler_json
12257 (vl_api_ip_route_details_t * mp)
12259 vat_main_t *vam = &vat_main;
12260 u8 count = mp->route.n_paths;
12261 vat_json_node_t *node = NULL;
12262 struct in_addr ip4;
12263 struct in6_addr ip6;
12264 vl_api_fib_path_t *fp;
12267 if (VAT_JSON_ARRAY != vam->json_tree.type)
12269 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12270 vat_json_init_array (&vam->json_tree);
12272 node = vat_json_array_add (&vam->json_tree);
12274 vat_json_init_object (node);
12275 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12276 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12278 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12279 vat_json_object_add_ip6 (node, "prefix", ip6);
12283 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12284 vat_json_object_add_ip4 (node, "prefix", ip4);
12286 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12287 vat_json_object_add_uint (node, "path_count", count);
12288 for (i = 0; i < count; i++)
12290 fp = &mp->route.paths[i];
12291 vl_api_mpls_fib_path_json_print (node, fp);
12296 api_ip_route_dump (vat_main_t * vam)
12298 unformat_input_t *input = vam->input;
12299 vl_api_ip_route_dump_t *mp;
12300 vl_api_control_ping_t *mp_ping;
12306 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12308 if (unformat (input, "table_id %d", &table_id))
12310 else if (unformat (input, "ip6"))
12312 else if (unformat (input, "ip4"))
12317 if (table_id == ~0)
12319 errmsg ("missing table id");
12323 M (IP_ROUTE_DUMP, mp);
12325 mp->table.table_id = table_id;
12326 mp->table.is_ip6 = is_ip6;
12330 /* Use a control ping for synchronization */
12331 MPING (CONTROL_PING, mp_ping);
12339 api_classify_table_ids (vat_main_t * vam)
12341 vl_api_classify_table_ids_t *mp;
12344 /* Construct the API message */
12345 M (CLASSIFY_TABLE_IDS, mp);
12354 api_classify_table_by_interface (vat_main_t * vam)
12356 unformat_input_t *input = vam->input;
12357 vl_api_classify_table_by_interface_t *mp;
12359 u32 sw_if_index = ~0;
12361 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12363 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12365 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12370 if (sw_if_index == ~0)
12372 errmsg ("missing interface name or sw_if_index");
12376 /* Construct the API message */
12377 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12379 mp->sw_if_index = ntohl (sw_if_index);
12387 api_classify_table_info (vat_main_t * vam)
12389 unformat_input_t *input = vam->input;
12390 vl_api_classify_table_info_t *mp;
12394 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12396 if (unformat (input, "table_id %d", &table_id))
12401 if (table_id == ~0)
12403 errmsg ("missing table id");
12407 /* Construct the API message */
12408 M (CLASSIFY_TABLE_INFO, mp);
12410 mp->table_id = ntohl (table_id);
12418 api_classify_session_dump (vat_main_t * vam)
12420 unformat_input_t *input = vam->input;
12421 vl_api_classify_session_dump_t *mp;
12422 vl_api_control_ping_t *mp_ping;
12426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12428 if (unformat (input, "table_id %d", &table_id))
12433 if (table_id == ~0)
12435 errmsg ("missing table id");
12439 /* Construct the API message */
12440 M (CLASSIFY_SESSION_DUMP, mp);
12442 mp->table_id = ntohl (table_id);
12445 /* Use a control ping for synchronization */
12446 MPING (CONTROL_PING, mp_ping);
12454 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12456 vat_main_t *vam = &vat_main;
12458 print (vam->ofp, "collector_address %U, collector_port %d, "
12459 "src_address %U, vrf_id %d, path_mtu %u, "
12460 "template_interval %u, udp_checksum %d",
12461 format_ip4_address, mp->collector_address,
12462 ntohs (mp->collector_port),
12463 format_ip4_address, mp->src_address,
12464 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12465 ntohl (mp->template_interval), mp->udp_checksum);
12468 vam->result_ready = 1;
12472 vl_api_ipfix_exporter_details_t_handler_json
12473 (vl_api_ipfix_exporter_details_t * mp)
12475 vat_main_t *vam = &vat_main;
12476 vat_json_node_t node;
12477 struct in_addr collector_address;
12478 struct in_addr src_address;
12480 vat_json_init_object (&node);
12481 clib_memcpy (&collector_address, &mp->collector_address,
12482 sizeof (collector_address));
12483 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12484 vat_json_object_add_uint (&node, "collector_port",
12485 ntohs (mp->collector_port));
12486 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12487 vat_json_object_add_ip4 (&node, "src_address", src_address);
12488 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12489 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12490 vat_json_object_add_uint (&node, "template_interval",
12491 ntohl (mp->template_interval));
12492 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12494 vat_json_print (vam->ofp, &node);
12495 vat_json_free (&node);
12497 vam->result_ready = 1;
12501 api_ipfix_exporter_dump (vat_main_t * vam)
12503 vl_api_ipfix_exporter_dump_t *mp;
12506 /* Construct the API message */
12507 M (IPFIX_EXPORTER_DUMP, mp);
12516 api_ipfix_classify_stream_dump (vat_main_t * vam)
12518 vl_api_ipfix_classify_stream_dump_t *mp;
12521 /* Construct the API message */
12522 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12533 vl_api_ipfix_classify_stream_details_t_handler
12534 (vl_api_ipfix_classify_stream_details_t * mp)
12536 vat_main_t *vam = &vat_main;
12537 print (vam->ofp, "domain_id %d, src_port %d",
12538 ntohl (mp->domain_id), ntohs (mp->src_port));
12540 vam->result_ready = 1;
12544 vl_api_ipfix_classify_stream_details_t_handler_json
12545 (vl_api_ipfix_classify_stream_details_t * mp)
12547 vat_main_t *vam = &vat_main;
12548 vat_json_node_t node;
12550 vat_json_init_object (&node);
12551 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12552 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12554 vat_json_print (vam->ofp, &node);
12555 vat_json_free (&node);
12557 vam->result_ready = 1;
12561 api_ipfix_classify_table_dump (vat_main_t * vam)
12563 vl_api_ipfix_classify_table_dump_t *mp;
12564 vl_api_control_ping_t *mp_ping;
12567 if (!vam->json_output)
12569 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12570 "transport_protocol");
12573 /* Construct the API message */
12574 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12579 /* Use a control ping for synchronization */
12580 MPING (CONTROL_PING, mp_ping);
12588 vl_api_ipfix_classify_table_details_t_handler
12589 (vl_api_ipfix_classify_table_details_t * mp)
12591 vat_main_t *vam = &vat_main;
12592 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12593 mp->transport_protocol);
12597 vl_api_ipfix_classify_table_details_t_handler_json
12598 (vl_api_ipfix_classify_table_details_t * mp)
12600 vat_json_node_t *node = NULL;
12601 vat_main_t *vam = &vat_main;
12603 if (VAT_JSON_ARRAY != vam->json_tree.type)
12605 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12606 vat_json_init_array (&vam->json_tree);
12609 node = vat_json_array_add (&vam->json_tree);
12610 vat_json_init_object (node);
12612 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12613 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12614 vat_json_object_add_uint (node, "transport_protocol",
12615 mp->transport_protocol);
12619 api_sw_interface_span_enable_disable (vat_main_t * vam)
12621 unformat_input_t *i = vam->input;
12622 vl_api_sw_interface_span_enable_disable_t *mp;
12623 u32 src_sw_if_index = ~0;
12624 u32 dst_sw_if_index = ~0;
12629 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12632 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12634 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12638 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12640 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12642 else if (unformat (i, "disable"))
12644 else if (unformat (i, "rx"))
12646 else if (unformat (i, "tx"))
12648 else if (unformat (i, "both"))
12650 else if (unformat (i, "l2"))
12656 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12658 mp->sw_if_index_from = htonl (src_sw_if_index);
12659 mp->sw_if_index_to = htonl (dst_sw_if_index);
12669 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12672 vat_main_t *vam = &vat_main;
12673 u8 *sw_if_from_name = 0;
12674 u8 *sw_if_to_name = 0;
12675 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12676 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12677 char *states[] = { "none", "rx", "tx", "both" };
12681 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12683 if ((u32) p->value[0] == sw_if_index_from)
12685 sw_if_from_name = (u8 *)(p->key);
12689 if ((u32) p->value[0] == sw_if_index_to)
12691 sw_if_to_name = (u8 *)(p->key);
12692 if (sw_if_from_name)
12697 print (vam->ofp, "%20s => %20s (%s) %s",
12698 sw_if_from_name, sw_if_to_name, states[mp->state],
12699 mp->is_l2 ? "l2" : "device");
12703 vl_api_sw_interface_span_details_t_handler_json
12704 (vl_api_sw_interface_span_details_t * mp)
12706 vat_main_t *vam = &vat_main;
12707 vat_json_node_t *node = NULL;
12708 u8 *sw_if_from_name = 0;
12709 u8 *sw_if_to_name = 0;
12710 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12711 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12715 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12717 if ((u32) p->value[0] == sw_if_index_from)
12719 sw_if_from_name = (u8 *)(p->key);
12723 if ((u32) p->value[0] == sw_if_index_to)
12725 sw_if_to_name = (u8 *)(p->key);
12726 if (sw_if_from_name)
12732 if (VAT_JSON_ARRAY != vam->json_tree.type)
12734 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12735 vat_json_init_array (&vam->json_tree);
12737 node = vat_json_array_add (&vam->json_tree);
12739 vat_json_init_object (node);
12740 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12741 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12742 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12743 if (0 != sw_if_to_name)
12745 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
12747 vat_json_object_add_uint (node, "state", mp->state);
12748 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
12752 api_sw_interface_span_dump (vat_main_t * vam)
12754 unformat_input_t *input = vam->input;
12755 vl_api_sw_interface_span_dump_t *mp;
12756 vl_api_control_ping_t *mp_ping;
12760 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12762 if (unformat (input, "l2"))
12768 M (SW_INTERFACE_SPAN_DUMP, mp);
12772 /* Use a control ping for synchronization */
12773 MPING (CONTROL_PING, mp_ping);
12781 api_pg_create_interface (vat_main_t * vam)
12783 unformat_input_t *input = vam->input;
12784 vl_api_pg_create_interface_t *mp;
12786 u32 if_id = ~0, gso_size = 0;
12787 u8 gso_enabled = 0;
12789 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12791 if (unformat (input, "if_id %d", &if_id))
12793 else if (unformat (input, "gso-enabled"))
12796 if (unformat (input, "gso-size %u", &gso_size))
12800 errmsg ("missing gso-size");
12809 errmsg ("missing pg interface index");
12813 /* Construct the API message */
12814 M (PG_CREATE_INTERFACE, mp);
12816 mp->interface_id = ntohl (if_id);
12817 mp->gso_enabled = gso_enabled;
12825 api_pg_capture (vat_main_t * vam)
12827 unformat_input_t *input = vam->input;
12828 vl_api_pg_capture_t *mp;
12833 u8 pcap_file_set = 0;
12836 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12838 if (unformat (input, "if_id %d", &if_id))
12840 else if (unformat (input, "pcap %s", &pcap_file))
12842 else if (unformat (input, "count %d", &count))
12844 else if (unformat (input, "disable"))
12851 errmsg ("missing pg interface index");
12854 if (pcap_file_set > 0)
12856 if (vec_len (pcap_file) > 255)
12858 errmsg ("pcap file name is too long");
12863 /* Construct the API message */
12864 M (PG_CAPTURE, mp);
12866 mp->interface_id = ntohl (if_id);
12867 mp->is_enabled = enable;
12868 mp->count = ntohl (count);
12869 if (pcap_file_set != 0)
12871 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
12873 vec_free (pcap_file);
12881 api_pg_enable_disable (vat_main_t * vam)
12883 unformat_input_t *input = vam->input;
12884 vl_api_pg_enable_disable_t *mp;
12887 u8 stream_name_set = 0;
12888 u8 *stream_name = 0;
12890 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12892 if (unformat (input, "stream %s", &stream_name))
12893 stream_name_set = 1;
12894 else if (unformat (input, "disable"))
12900 if (stream_name_set > 0)
12902 if (vec_len (stream_name) > 255)
12904 errmsg ("stream name too long");
12909 /* Construct the API message */
12910 M (PG_ENABLE_DISABLE, mp);
12912 mp->is_enabled = enable;
12913 if (stream_name_set != 0)
12915 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
12917 vec_free (stream_name);
12925 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
12927 unformat_input_t *input = vam->input;
12928 vl_api_pg_interface_enable_disable_coalesce_t *mp;
12930 u32 sw_if_index = ~0;
12933 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12935 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12937 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12939 else if (unformat (input, "disable"))
12945 if (sw_if_index == ~0)
12947 errmsg ("Interface required but not specified");
12951 /* Construct the API message */
12952 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
12954 mp->coalesce_enabled = enable;
12955 mp->sw_if_index = htonl (sw_if_index);
12963 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
12965 unformat_input_t *input = vam->input;
12966 vl_api_ip_source_and_port_range_check_add_del_t *mp;
12968 u16 *low_ports = 0;
12969 u16 *high_ports = 0;
12972 vl_api_prefix_t prefix;
12979 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12981 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
12983 else if (unformat (input, "vrf %d", &vrf_id))
12985 else if (unformat (input, "del"))
12987 else if (unformat (input, "port %d", &tmp))
12989 if (tmp == 0 || tmp > 65535)
12991 errmsg ("port %d out of range", tmp);
12995 this_hi = this_low + 1;
12996 vec_add1 (low_ports, this_low);
12997 vec_add1 (high_ports, this_hi);
12999 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13001 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
13003 errmsg ("incorrect range parameters");
13007 /* Note: in debug CLI +1 is added to high before
13008 passing to real fn that does "the work"
13009 (ip_source_and_port_range_check_add_del).
13010 This fn is a wrapper around the binary API fn a
13011 control plane will call, which expects this increment
13012 to have occurred. Hence letting the binary API control
13013 plane fn do the increment for consistency between VAT
13014 and other control planes.
13017 vec_add1 (low_ports, this_low);
13018 vec_add1 (high_ports, this_hi);
13024 if (prefix_set == 0)
13026 errmsg ("<address>/<mask> not specified");
13032 errmsg ("VRF ID required, not specified");
13039 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13043 if (vec_len (low_ports) == 0)
13045 errmsg ("At least one port or port range required");
13049 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
13051 mp->is_add = is_add;
13053 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
13055 mp->number_of_ranges = vec_len (low_ports);
13057 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
13058 vec_free (low_ports);
13060 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
13061 vec_free (high_ports);
13063 mp->vrf_id = ntohl (vrf_id);
13071 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13073 unformat_input_t *input = vam->input;
13074 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13075 u32 sw_if_index = ~0;
13077 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
13078 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
13082 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13084 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13086 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13088 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
13090 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
13092 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13094 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13096 else if (unformat (input, "del"))
13102 if (sw_if_index == ~0)
13104 errmsg ("Interface required but not specified");
13110 errmsg ("VRF ID required but not specified");
13114 if (tcp_out_vrf_id == 0
13115 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13118 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13122 /* Construct the API message */
13123 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13125 mp->sw_if_index = ntohl (sw_if_index);
13126 mp->is_add = is_add;
13127 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13128 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13129 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13130 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13135 /* Wait for a reply... */
13141 api_set_punt (vat_main_t * vam)
13143 unformat_input_t *i = vam->input;
13144 vl_api_address_family_t af;
13145 vl_api_set_punt_t *mp;
13151 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13153 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13155 else if (unformat (i, "protocol %d", &protocol))
13157 else if (unformat (i, "port %d", &port))
13159 else if (unformat (i, "del"))
13163 clib_warning ("parse error '%U'", format_unformat_error, i);
13170 mp->is_add = (u8) is_add;
13171 mp->punt.type = PUNT_API_TYPE_L4;
13172 mp->punt.punt.l4.af = af;
13173 mp->punt.punt.l4.protocol = (u8) protocol;
13174 mp->punt.punt.l4.port = htons ((u16) port);
13182 api_delete_subif (vat_main_t * vam)
13184 unformat_input_t *i = vam->input;
13185 vl_api_delete_subif_t *mp;
13186 u32 sw_if_index = ~0;
13189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13191 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13193 if (unformat (i, "sw_if_index %d", &sw_if_index))
13199 if (sw_if_index == ~0)
13201 errmsg ("missing sw_if_index");
13205 /* Construct the API message */
13206 M (DELETE_SUBIF, mp);
13207 mp->sw_if_index = ntohl (sw_if_index);
13214 #define foreach_pbb_vtr_op \
13215 _("disable", L2_VTR_DISABLED) \
13216 _("pop", L2_VTR_POP_2) \
13217 _("push", L2_VTR_PUSH_2)
13220 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13222 unformat_input_t *i = vam->input;
13223 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13224 u32 sw_if_index = ~0, vtr_op = ~0;
13225 u16 outer_tag = ~0;
13226 u8 dmac[6], smac[6];
13227 u8 dmac_set = 0, smac_set = 0;
13233 /* Shut up coverity */
13234 clib_memset (dmac, 0, sizeof (dmac));
13235 clib_memset (smac, 0, sizeof (smac));
13237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13239 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13241 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13243 else if (unformat (i, "vtr_op %d", &vtr_op))
13245 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13248 else if (unformat (i, "translate_pbb_stag"))
13250 if (unformat (i, "%d", &tmp))
13252 vtr_op = L2_VTR_TRANSLATE_2_1;
13258 ("translate_pbb_stag operation requires outer tag definition");
13262 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13264 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13266 else if (unformat (i, "sid %d", &sid))
13268 else if (unformat (i, "vlanid %d", &tmp))
13272 clib_warning ("parse error '%U'", format_unformat_error, i);
13277 if ((sw_if_index == ~0) || (vtr_op == ~0))
13279 errmsg ("missing sw_if_index or vtr operation");
13282 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13283 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13286 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13290 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13291 mp->sw_if_index = ntohl (sw_if_index);
13292 mp->vtr_op = ntohl (vtr_op);
13293 mp->outer_tag = ntohs (outer_tag);
13294 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13295 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13296 mp->b_vlanid = ntohs (vlanid);
13297 mp->i_sid = ntohl (sid);
13305 api_flow_classify_set_interface (vat_main_t * vam)
13307 unformat_input_t *i = vam->input;
13308 vl_api_flow_classify_set_interface_t *mp;
13310 int sw_if_index_set;
13311 u32 ip4_table_index = ~0;
13312 u32 ip6_table_index = ~0;
13316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13318 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13319 sw_if_index_set = 1;
13320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13321 sw_if_index_set = 1;
13322 else if (unformat (i, "del"))
13324 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13326 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13330 clib_warning ("parse error '%U'", format_unformat_error, i);
13335 if (sw_if_index_set == 0)
13337 errmsg ("missing interface name or sw_if_index");
13341 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13343 mp->sw_if_index = ntohl (sw_if_index);
13344 mp->ip4_table_index = ntohl (ip4_table_index);
13345 mp->ip6_table_index = ntohl (ip6_table_index);
13346 mp->is_add = is_add;
13354 api_flow_classify_dump (vat_main_t * vam)
13356 unformat_input_t *i = vam->input;
13357 vl_api_flow_classify_dump_t *mp;
13358 vl_api_control_ping_t *mp_ping;
13359 u8 type = FLOW_CLASSIFY_N_TABLES;
13362 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13366 errmsg ("classify table type must be specified");
13370 if (!vam->json_output)
13372 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13375 M (FLOW_CLASSIFY_DUMP, mp);
13380 /* Use a control ping for synchronization */
13381 MPING (CONTROL_PING, mp_ping);
13384 /* Wait for a reply... */
13390 api_feature_enable_disable (vat_main_t * vam)
13392 unformat_input_t *i = vam->input;
13393 vl_api_feature_enable_disable_t *mp;
13395 u8 *feature_name = 0;
13396 u32 sw_if_index = ~0;
13400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13402 if (unformat (i, "arc_name %s", &arc_name))
13404 else if (unformat (i, "feature_name %s", &feature_name))
13407 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13409 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13411 else if (unformat (i, "disable"))
13419 errmsg ("missing arc name");
13422 if (vec_len (arc_name) > 63)
13424 errmsg ("arc name too long");
13427 if (feature_name == 0)
13429 errmsg ("missing feature name");
13432 if (vec_len (feature_name) > 63)
13434 errmsg ("feature name too long");
13437 if (sw_if_index == ~0)
13439 errmsg ("missing interface name or sw_if_index");
13443 /* Construct the API message */
13444 M (FEATURE_ENABLE_DISABLE, mp);
13445 mp->sw_if_index = ntohl (sw_if_index);
13446 mp->enable = enable;
13447 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13448 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13449 vec_free (arc_name);
13450 vec_free (feature_name);
13458 api_feature_gso_enable_disable (vat_main_t * vam)
13460 unformat_input_t *i = vam->input;
13461 vl_api_feature_gso_enable_disable_t *mp;
13462 u32 sw_if_index = ~0;
13466 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13468 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13470 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13472 else if (unformat (i, "enable"))
13474 else if (unformat (i, "disable"))
13480 if (sw_if_index == ~0)
13482 errmsg ("missing interface name or sw_if_index");
13486 /* Construct the API message */
13487 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13488 mp->sw_if_index = ntohl (sw_if_index);
13489 mp->enable_disable = enable;
13497 api_sw_interface_tag_add_del (vat_main_t * vam)
13499 unformat_input_t *i = vam->input;
13500 vl_api_sw_interface_tag_add_del_t *mp;
13501 u32 sw_if_index = ~0;
13506 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13508 if (unformat (i, "tag %s", &tag))
13510 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13512 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13514 else if (unformat (i, "del"))
13520 if (sw_if_index == ~0)
13522 errmsg ("missing interface name or sw_if_index");
13526 if (enable && (tag == 0))
13528 errmsg ("no tag specified");
13532 /* Construct the API message */
13533 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13534 mp->sw_if_index = ntohl (sw_if_index);
13535 mp->is_add = enable;
13537 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13546 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13548 unformat_input_t *i = vam->input;
13549 vl_api_mac_address_t mac = { 0 };
13550 vl_api_sw_interface_add_del_mac_address_t *mp;
13551 u32 sw_if_index = ~0;
13556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13558 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13560 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13562 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13564 else if (unformat (i, "del"))
13570 if (sw_if_index == ~0)
13572 errmsg ("missing interface name or sw_if_index");
13578 errmsg ("missing MAC address");
13582 /* Construct the API message */
13583 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13584 mp->sw_if_index = ntohl (sw_if_index);
13585 mp->is_add = is_add;
13586 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13593 static void vl_api_l2_xconnect_details_t_handler
13594 (vl_api_l2_xconnect_details_t * mp)
13596 vat_main_t *vam = &vat_main;
13598 print (vam->ofp, "%15d%15d",
13599 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13602 static void vl_api_l2_xconnect_details_t_handler_json
13603 (vl_api_l2_xconnect_details_t * mp)
13605 vat_main_t *vam = &vat_main;
13606 vat_json_node_t *node = NULL;
13608 if (VAT_JSON_ARRAY != vam->json_tree.type)
13610 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13611 vat_json_init_array (&vam->json_tree);
13613 node = vat_json_array_add (&vam->json_tree);
13615 vat_json_init_object (node);
13616 vat_json_object_add_uint (node, "rx_sw_if_index",
13617 ntohl (mp->rx_sw_if_index));
13618 vat_json_object_add_uint (node, "tx_sw_if_index",
13619 ntohl (mp->tx_sw_if_index));
13623 api_l2_xconnect_dump (vat_main_t * vam)
13625 vl_api_l2_xconnect_dump_t *mp;
13626 vl_api_control_ping_t *mp_ping;
13629 if (!vam->json_output)
13631 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13634 M (L2_XCONNECT_DUMP, mp);
13638 /* Use a control ping for synchronization */
13639 MPING (CONTROL_PING, mp_ping);
13647 api_hw_interface_set_mtu (vat_main_t * vam)
13649 unformat_input_t *i = vam->input;
13650 vl_api_hw_interface_set_mtu_t *mp;
13651 u32 sw_if_index = ~0;
13655 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13657 if (unformat (i, "mtu %d", &mtu))
13659 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13661 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13667 if (sw_if_index == ~0)
13669 errmsg ("missing interface name or sw_if_index");
13675 errmsg ("no mtu specified");
13679 /* Construct the API message */
13680 M (HW_INTERFACE_SET_MTU, mp);
13681 mp->sw_if_index = ntohl (sw_if_index);
13682 mp->mtu = ntohs ((u16) mtu);
13690 api_p2p_ethernet_add (vat_main_t * vam)
13692 unformat_input_t *i = vam->input;
13693 vl_api_p2p_ethernet_add_t *mp;
13694 u32 parent_if_index = ~0;
13700 clib_memset (remote_mac, 0, sizeof (remote_mac));
13701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13703 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13705 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13709 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13711 else if (unformat (i, "sub_id %d", &sub_id))
13715 clib_warning ("parse error '%U'", format_unformat_error, i);
13720 if (parent_if_index == ~0)
13722 errmsg ("missing interface name or sw_if_index");
13727 errmsg ("missing remote mac address");
13732 errmsg ("missing sub-interface id");
13736 M (P2P_ETHERNET_ADD, mp);
13737 mp->parent_if_index = ntohl (parent_if_index);
13738 mp->subif_id = ntohl (sub_id);
13739 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13747 api_p2p_ethernet_del (vat_main_t * vam)
13749 unformat_input_t *i = vam->input;
13750 vl_api_p2p_ethernet_del_t *mp;
13751 u32 parent_if_index = ~0;
13756 clib_memset (remote_mac, 0, sizeof (remote_mac));
13757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13759 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13761 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13765 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13769 clib_warning ("parse error '%U'", format_unformat_error, i);
13774 if (parent_if_index == ~0)
13776 errmsg ("missing interface name or sw_if_index");
13781 errmsg ("missing remote mac address");
13785 M (P2P_ETHERNET_DEL, mp);
13786 mp->parent_if_index = ntohl (parent_if_index);
13787 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13795 api_tcp_configure_src_addresses (vat_main_t * vam)
13797 vl_api_tcp_configure_src_addresses_t *mp;
13798 unformat_input_t *i = vam->input;
13799 vl_api_address_t first, last;
13804 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13806 if (unformat (i, "%U - %U",
13807 unformat_vl_api_address, &first,
13808 unformat_vl_api_address, &last))
13812 errmsg ("one range per message (range already set)");
13817 else if (unformat (i, "vrf %d", &vrf_id))
13823 if (range_set == 0)
13825 errmsg ("address range not set");
13829 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
13831 mp->vrf_id = ntohl (vrf_id);
13832 clib_memcpy (&mp->first_address, &first, sizeof (first));
13833 clib_memcpy (&mp->last_address, &last, sizeof (last));
13840 static void vl_api_app_namespace_add_del_reply_t_handler
13841 (vl_api_app_namespace_add_del_reply_t * mp)
13843 vat_main_t *vam = &vat_main;
13844 i32 retval = ntohl (mp->retval);
13845 if (vam->async_mode)
13847 vam->async_errors += (retval < 0);
13851 vam->retval = retval;
13853 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
13854 vam->result_ready = 1;
13858 static void vl_api_app_namespace_add_del_reply_t_handler_json
13859 (vl_api_app_namespace_add_del_reply_t * mp)
13861 vat_main_t *vam = &vat_main;
13862 vat_json_node_t node;
13864 vat_json_init_object (&node);
13865 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
13866 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
13868 vat_json_print (vam->ofp, &node);
13869 vat_json_free (&node);
13871 vam->retval = ntohl (mp->retval);
13872 vam->result_ready = 1;
13876 api_app_namespace_add_del (vat_main_t * vam)
13878 vl_api_app_namespace_add_del_t *mp;
13879 unformat_input_t *i = vam->input;
13880 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
13881 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
13885 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13887 if (unformat (i, "id %_%v%_", &ns_id))
13889 else if (unformat (i, "secret %lu", &secret))
13891 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13892 sw_if_index_set = 1;
13893 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
13895 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
13900 if (!ns_id || !secret_set || !sw_if_index_set)
13902 errmsg ("namespace id, secret and sw_if_index must be set");
13905 if (vec_len (ns_id) > 64)
13907 errmsg ("namespace id too long");
13910 M (APP_NAMESPACE_ADD_DEL, mp);
13912 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
13913 mp->secret = clib_host_to_net_u64 (secret);
13914 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
13915 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
13916 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
13924 api_sock_init_shm (vat_main_t * vam)
13926 #if VPP_API_TEST_BUILTIN == 0
13927 unformat_input_t *i = vam->input;
13928 vl_api_shm_elem_config_t *config = 0;
13929 u64 size = 64 << 20;
13932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13934 if (unformat (i, "size %U", unformat_memory_size, &size))
13941 * Canned custom ring allocator config.
13942 * Should probably parse all of this
13944 vec_validate (config, 6);
13945 config[0].type = VL_API_VLIB_RING;
13946 config[0].size = 256;
13947 config[0].count = 32;
13949 config[1].type = VL_API_VLIB_RING;
13950 config[1].size = 1024;
13951 config[1].count = 16;
13953 config[2].type = VL_API_VLIB_RING;
13954 config[2].size = 4096;
13955 config[2].count = 2;
13957 config[3].type = VL_API_CLIENT_RING;
13958 config[3].size = 256;
13959 config[3].count = 32;
13961 config[4].type = VL_API_CLIENT_RING;
13962 config[4].size = 1024;
13963 config[4].count = 16;
13965 config[5].type = VL_API_CLIENT_RING;
13966 config[5].size = 4096;
13967 config[5].count = 2;
13969 config[6].type = VL_API_QUEUE;
13970 config[6].count = 128;
13971 config[6].size = sizeof (uword);
13973 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
13975 vam->client_index_invalid = 1;
13983 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
13985 vat_main_t *vam = &vat_main;
13986 fib_prefix_t lcl, rmt;
13988 ip_prefix_decode (&mp->lcl, &lcl);
13989 ip_prefix_decode (&mp->rmt, &rmt);
13991 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
13994 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
13995 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
13996 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
13997 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
13998 &rmt.fp_addr.ip4, rmt.fp_len,
13999 clib_net_to_host_u16 (mp->rmt_port),
14000 clib_net_to_host_u32 (mp->action_index), mp->tag);
14005 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14006 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14007 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
14008 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
14009 &rmt.fp_addr.ip6, rmt.fp_len,
14010 clib_net_to_host_u16 (mp->rmt_port),
14011 clib_net_to_host_u32 (mp->action_index), mp->tag);
14016 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
14019 vat_main_t *vam = &vat_main;
14020 vat_json_node_t *node = NULL;
14021 struct in6_addr ip6;
14022 struct in_addr ip4;
14024 fib_prefix_t lcl, rmt;
14026 ip_prefix_decode (&mp->lcl, &lcl);
14027 ip_prefix_decode (&mp->rmt, &rmt);
14029 if (VAT_JSON_ARRAY != vam->json_tree.type)
14031 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14032 vat_json_init_array (&vam->json_tree);
14034 node = vat_json_array_add (&vam->json_tree);
14035 vat_json_init_object (node);
14037 vat_json_object_add_uint (node, "appns_index",
14038 clib_net_to_host_u32 (mp->appns_index));
14039 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
14040 vat_json_object_add_uint (node, "scope", mp->scope);
14041 vat_json_object_add_uint (node, "action_index",
14042 clib_net_to_host_u32 (mp->action_index));
14043 vat_json_object_add_uint (node, "lcl_port",
14044 clib_net_to_host_u16 (mp->lcl_port));
14045 vat_json_object_add_uint (node, "rmt_port",
14046 clib_net_to_host_u16 (mp->rmt_port));
14047 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
14048 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
14049 vat_json_object_add_string_copy (node, "tag", mp->tag);
14050 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14052 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
14053 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
14054 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
14055 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
14059 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
14060 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
14061 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
14062 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
14067 api_session_rule_add_del (vat_main_t * vam)
14069 vl_api_session_rule_add_del_t *mp;
14070 unformat_input_t *i = vam->input;
14071 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
14072 u32 appns_index = 0, scope = 0;
14073 ip4_address_t lcl_ip4, rmt_ip4;
14074 ip6_address_t lcl_ip6, rmt_ip6;
14075 u8 is_ip4 = 1, conn_set = 0;
14076 u8 is_add = 1, *tag = 0;
14078 fib_prefix_t lcl, rmt;
14080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14082 if (unformat (i, "del"))
14084 else if (unformat (i, "add"))
14086 else if (unformat (i, "proto tcp"))
14088 else if (unformat (i, "proto udp"))
14090 else if (unformat (i, "appns %d", &appns_index))
14092 else if (unformat (i, "scope %d", &scope))
14094 else if (unformat (i, "tag %_%v%_", &tag))
14098 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14099 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14107 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14108 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14114 else if (unformat (i, "action %d", &action))
14119 if (proto == ~0 || !conn_set || action == ~0)
14121 errmsg ("transport proto, connection and action must be set");
14127 errmsg ("scope should be 0-3");
14131 M (SESSION_RULE_ADD_DEL, mp);
14133 clib_memset (&lcl, 0, sizeof (lcl));
14134 clib_memset (&rmt, 0, sizeof (rmt));
14137 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14138 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14139 lcl.fp_len = lcl_plen;
14140 rmt.fp_len = rmt_plen;
14144 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14145 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14146 lcl.fp_len = lcl_plen;
14147 rmt.fp_len = rmt_plen;
14151 ip_prefix_encode (&lcl, &mp->lcl);
14152 ip_prefix_encode (&rmt, &mp->rmt);
14153 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14154 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14155 mp->transport_proto =
14156 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14157 mp->action_index = clib_host_to_net_u32 (action);
14158 mp->appns_index = clib_host_to_net_u32 (appns_index);
14160 mp->is_add = is_add;
14163 clib_memcpy (mp->tag, tag, vec_len (tag));
14173 api_session_rules_dump (vat_main_t * vam)
14175 vl_api_session_rules_dump_t *mp;
14176 vl_api_control_ping_t *mp_ping;
14179 if (!vam->json_output)
14181 print (vam->ofp, "%=20s", "Session Rules");
14184 M (SESSION_RULES_DUMP, mp);
14188 /* Use a control ping for synchronization */
14189 MPING (CONTROL_PING, mp_ping);
14192 /* Wait for a reply... */
14198 api_ip_container_proxy_add_del (vat_main_t * vam)
14200 vl_api_ip_container_proxy_add_del_t *mp;
14201 unformat_input_t *i = vam->input;
14202 u32 sw_if_index = ~0;
14203 vl_api_prefix_t pfx = { };
14207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14209 if (unformat (i, "del"))
14211 else if (unformat (i, "add"))
14213 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14215 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14220 if (sw_if_index == ~0 || pfx.len == 0)
14222 errmsg ("address and sw_if_index must be set");
14226 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14228 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14229 mp->is_add = is_add;
14230 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14238 api_qos_record_enable_disable (vat_main_t * vam)
14240 unformat_input_t *i = vam->input;
14241 vl_api_qos_record_enable_disable_t *mp;
14242 u32 sw_if_index, qs = 0xff;
14243 u8 sw_if_index_set = 0;
14247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14249 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14250 sw_if_index_set = 1;
14251 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14252 sw_if_index_set = 1;
14253 else if (unformat (i, "%U", unformat_qos_source, &qs))
14255 else if (unformat (i, "disable"))
14259 clib_warning ("parse error '%U'", format_unformat_error, i);
14264 if (sw_if_index_set == 0)
14266 errmsg ("missing interface name or sw_if_index");
14271 errmsg ("input location must be specified");
14275 M (QOS_RECORD_ENABLE_DISABLE, mp);
14277 mp->record.sw_if_index = ntohl (sw_if_index);
14278 mp->record.input_source = qs;
14279 mp->enable = enable;
14288 q_or_quit (vat_main_t * vam)
14290 #if VPP_API_TEST_BUILTIN == 0
14291 longjmp (vam->jump_buf, 1);
14293 return 0; /* not so much */
14297 q (vat_main_t * vam)
14299 return q_or_quit (vam);
14303 quit (vat_main_t * vam)
14305 return q_or_quit (vam);
14309 comment (vat_main_t * vam)
14315 elog_save (vat_main_t * vam)
14317 #if VPP_API_TEST_BUILTIN == 0
14318 elog_main_t *em = &vam->elog_main;
14319 unformat_input_t *i = vam->input;
14320 char *file, *chroot_file;
14321 clib_error_t *error;
14323 if (!unformat (i, "%s", &file))
14325 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14329 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14330 if (strstr (file, "..") || index (file, '/'))
14332 errmsg ("illegal characters in filename '%s'", file);
14336 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14340 errmsg ("Saving %wd of %wd events to %s",
14341 elog_n_events_in_buffer (em),
14342 elog_buffer_capacity (em), chroot_file);
14344 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14345 vec_free (chroot_file);
14348 clib_error_report (error);
14350 errmsg ("Use the vpp event loger...");
14357 elog_setup (vat_main_t * vam)
14359 #if VPP_API_TEST_BUILTIN == 0
14360 elog_main_t *em = &vam->elog_main;
14361 unformat_input_t *i = vam->input;
14362 u32 nevents = 128 << 10;
14364 (void) unformat (i, "nevents %d", &nevents);
14366 elog_init (em, nevents);
14367 vl_api_set_elog_main (em);
14368 vl_api_set_elog_trace_api_messages (1);
14369 errmsg ("Event logger initialized with %u events", nevents);
14371 errmsg ("Use the vpp event loger...");
14377 elog_enable (vat_main_t * vam)
14379 #if VPP_API_TEST_BUILTIN == 0
14380 elog_main_t *em = &vam->elog_main;
14382 elog_enable_disable (em, 1 /* enable */ );
14383 vl_api_set_elog_trace_api_messages (1);
14384 errmsg ("Event logger enabled...");
14386 errmsg ("Use the vpp event loger...");
14392 elog_disable (vat_main_t * vam)
14394 #if VPP_API_TEST_BUILTIN == 0
14395 elog_main_t *em = &vam->elog_main;
14397 elog_enable_disable (em, 0 /* enable */ );
14398 vl_api_set_elog_trace_api_messages (1);
14399 errmsg ("Event logger disabled...");
14401 errmsg ("Use the vpp event loger...");
14407 statseg (vat_main_t * vam)
14409 ssvm_private_t *ssvmp = &vam->stat_segment;
14410 ssvm_shared_header_t *shared_header = ssvmp->sh;
14411 vlib_counter_t **counters;
14412 u64 thread0_index1_packets;
14413 u64 thread0_index1_bytes;
14414 f64 vector_rate, input_rate;
14417 uword *counter_vector_by_name;
14418 if (vam->stat_segment_lockp == 0)
14420 errmsg ("Stat segment not mapped...");
14424 /* look up "/if/rx for sw_if_index 1 as a test */
14426 clib_spinlock_lock (vam->stat_segment_lockp);
14428 counter_vector_by_name = (uword *) shared_header->opaque[1];
14430 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14433 clib_spinlock_unlock (vam->stat_segment_lockp);
14434 errmsg ("/if/tx not found?");
14438 /* Fish per-thread vector of combined counters from shared memory */
14439 counters = (vlib_counter_t **) p[0];
14441 if (vec_len (counters[0]) < 2)
14443 clib_spinlock_unlock (vam->stat_segment_lockp);
14444 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14448 /* Read thread 0 sw_if_index 1 counter */
14449 thread0_index1_packets = counters[0][1].packets;
14450 thread0_index1_bytes = counters[0][1].bytes;
14452 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14455 clib_spinlock_unlock (vam->stat_segment_lockp);
14456 errmsg ("vector_rate not found?");
14460 vector_rate = *(f64 *) (p[0]);
14461 p = hash_get_mem (counter_vector_by_name, "input_rate");
14464 clib_spinlock_unlock (vam->stat_segment_lockp);
14465 errmsg ("input_rate not found?");
14468 input_rate = *(f64 *) (p[0]);
14470 clib_spinlock_unlock (vam->stat_segment_lockp);
14472 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14473 vector_rate, input_rate);
14474 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14475 thread0_index1_packets, thread0_index1_bytes);
14481 cmd_cmp (void *a1, void *a2)
14486 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14490 help (vat_main_t * vam)
14495 unformat_input_t *i = vam->input;
14498 if (unformat (i, "%s", &name))
14502 vec_add1 (name, 0);
14504 hs = hash_get_mem (vam->help_by_name, name);
14506 print (vam->ofp, "usage: %s %s", name, hs[0]);
14508 print (vam->ofp, "No such msg / command '%s'", name);
14513 print (vam->ofp, "Help is available for the following:");
14516 hash_foreach_pair (p, vam->function_by_name,
14518 vec_add1 (cmds, (u8 *)(p->key));
14522 vec_sort_with_function (cmds, cmd_cmp);
14524 for (j = 0; j < vec_len (cmds); j++)
14525 print (vam->ofp, "%s", cmds[j]);
14532 set (vat_main_t * vam)
14534 u8 *name = 0, *value = 0;
14535 unformat_input_t *i = vam->input;
14537 if (unformat (i, "%s", &name))
14539 /* The input buffer is a vector, not a string. */
14540 value = vec_dup (i->buffer);
14541 vec_delete (value, i->index, 0);
14542 /* Almost certainly has a trailing newline */
14543 if (value[vec_len (value) - 1] == '\n')
14544 value[vec_len (value) - 1] = 0;
14545 /* Make sure it's a proper string, one way or the other */
14546 vec_add1 (value, 0);
14547 (void) clib_macro_set_value (&vam->macro_main,
14548 (char *) name, (char *) value);
14551 errmsg ("usage: set <name> <value>");
14559 unset (vat_main_t * vam)
14563 if (unformat (vam->input, "%s", &name))
14564 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14565 errmsg ("unset: %s wasn't set", name);
14578 macro_sort_cmp (void *a1, void *a2)
14580 macro_sort_t *s1 = a1;
14581 macro_sort_t *s2 = a2;
14583 return strcmp ((char *) (s1->name), (char *) (s2->name));
14587 dump_macro_table (vat_main_t * vam)
14589 macro_sort_t *sort_me = 0, *sm;
14594 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14596 vec_add2 (sort_me, sm, 1);
14597 sm->name = (u8 *)(p->key);
14598 sm->value = (u8 *) (p->value[0]);
14602 vec_sort_with_function (sort_me, macro_sort_cmp);
14604 if (vec_len (sort_me))
14605 print (vam->ofp, "%-15s%s", "Name", "Value");
14607 print (vam->ofp, "The macro table is empty...");
14609 for (i = 0; i < vec_len (sort_me); i++)
14610 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14615 dump_node_table (vat_main_t * vam)
14618 vlib_node_t *node, *next_node;
14620 if (vec_len (vam->graph_nodes) == 0)
14622 print (vam->ofp, "Node table empty, issue get_node_graph...");
14626 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14628 node = vam->graph_nodes[0][i];
14629 print (vam->ofp, "[%d] %s", i, node->name);
14630 for (j = 0; j < vec_len (node->next_nodes); j++)
14632 if (node->next_nodes[j] != ~0)
14634 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14635 print (vam->ofp, " [%d] %s", j, next_node->name);
14643 value_sort_cmp (void *a1, void *a2)
14645 name_sort_t *n1 = a1;
14646 name_sort_t *n2 = a2;
14648 if (n1->value < n2->value)
14650 if (n1->value > n2->value)
14657 dump_msg_api_table (vat_main_t * vam)
14659 api_main_t *am = vlibapi_get_main ();
14660 name_sort_t *nses = 0, *ns;
14665 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14667 vec_add2 (nses, ns, 1);
14668 ns->name = (u8 *)(hp->key);
14669 ns->value = (u32) hp->value[0];
14673 vec_sort_with_function (nses, value_sort_cmp);
14675 for (i = 0; i < vec_len (nses); i++)
14676 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14682 get_msg_id (vat_main_t * vam)
14687 if (unformat (vam->input, "%s", &name_and_crc))
14689 message_index = vl_msg_api_get_msg_index (name_and_crc);
14690 if (message_index == ~0)
14692 print (vam->ofp, " '%s' not found", name_and_crc);
14695 print (vam->ofp, " '%s' has message index %d",
14696 name_and_crc, message_index);
14699 errmsg ("name_and_crc required...");
14704 search_node_table (vat_main_t * vam)
14706 unformat_input_t *line_input = vam->input;
14709 vlib_node_t *node, *next_node;
14712 if (vam->graph_node_index_by_name == 0)
14714 print (vam->ofp, "Node table empty, issue get_node_graph...");
14718 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14720 if (unformat (line_input, "%s", &node_to_find))
14722 vec_add1 (node_to_find, 0);
14723 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14726 print (vam->ofp, "%s not found...", node_to_find);
14729 node = vam->graph_nodes[0][p[0]];
14730 print (vam->ofp, "[%d] %s", p[0], node->name);
14731 for (j = 0; j < vec_len (node->next_nodes); j++)
14733 if (node->next_nodes[j] != ~0)
14735 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14736 print (vam->ofp, " [%d] %s", j, next_node->name);
14743 clib_warning ("parse error '%U'", format_unformat_error,
14749 vec_free (node_to_find);
14758 script (vat_main_t * vam)
14760 #if (VPP_API_TEST_BUILTIN==0)
14762 char *save_current_file;
14763 unformat_input_t save_input;
14764 jmp_buf save_jump_buf;
14765 u32 save_line_number;
14767 FILE *new_fp, *save_ifp;
14769 if (unformat (vam->input, "%s", &s))
14771 new_fp = fopen ((char *) s, "r");
14774 errmsg ("Couldn't open script file %s", s);
14781 errmsg ("Missing script name");
14785 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
14786 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
14787 save_ifp = vam->ifp;
14788 save_line_number = vam->input_line_number;
14789 save_current_file = (char *) vam->current_file;
14791 vam->input_line_number = 0;
14793 vam->current_file = s;
14796 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
14797 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
14798 vam->ifp = save_ifp;
14799 vam->input_line_number = save_line_number;
14800 vam->current_file = (u8 *) save_current_file;
14805 clib_warning ("use the exec command...");
14811 echo (vat_main_t * vam)
14813 print (vam->ofp, "%v", vam->input->buffer);
14817 /* List of API message constructors, CLI names map to api_xxx */
14818 #define foreach_vpe_api_msg \
14819 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
14820 _(sw_interface_dump,"") \
14821 _(sw_interface_set_flags, \
14822 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
14823 _(sw_interface_add_del_address, \
14824 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
14825 _(sw_interface_set_rx_mode, \
14826 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
14827 _(sw_interface_set_rx_placement, \
14828 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
14829 _(sw_interface_rx_placement_dump, \
14830 "[<intfc> | sw_if_index <id>]") \
14831 _(sw_interface_set_table, \
14832 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
14833 _(sw_interface_set_mpls_enable, \
14834 "<intfc> | sw_if_index [disable | dis]") \
14835 _(sw_interface_set_vpath, \
14836 "<intfc> | sw_if_index <id> enable | disable") \
14837 _(sw_interface_set_vxlan_bypass, \
14838 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
14839 _(sw_interface_set_l2_xconnect, \
14840 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14841 "enable | disable") \
14842 _(sw_interface_set_l2_bridge, \
14843 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
14844 "[shg <split-horizon-group>] [bvi]\n" \
14845 "enable | disable") \
14846 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
14847 _(bridge_domain_add_del, \
14848 "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") \
14849 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
14851 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
14852 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
14853 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
14855 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14857 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14859 "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]") \
14861 "<vpp-if-name> | sw_if_index <id>") \
14862 _(sw_interface_tap_v2_dump, "") \
14863 _(virtio_pci_create_v2, \
14864 "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]") \
14865 _(virtio_pci_delete, \
14866 "<vpp-if-name> | sw_if_index <id>") \
14867 _(sw_interface_virtio_pci_dump, "") \
14869 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
14870 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14873 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
14874 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14875 "[id <if-id>] [gso]") \
14877 "<vpp-if-name> | sw_if_index <id>") \
14878 _(bond_add_member, \
14879 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
14880 _(bond_detach_member, \
14881 "sw_if_index <n>") \
14882 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
14883 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
14884 _(sw_member_interface_dump, \
14885 "<vpp-if-name> | sw_if_index <id>") \
14886 _(ip_table_add_del, \
14887 "table <n> [ipv6] [add | del]\n") \
14888 _(ip_route_add_del, \
14889 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
14890 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
14891 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
14892 "[multipath] [count <n>] [del]") \
14893 _(ip_mroute_add_del, \
14894 "<src> <grp>/<mask> [table-id <n>]\n" \
14895 "[<intfc> | sw_if_index <id>] [local] [del]") \
14896 _(mpls_table_add_del, \
14897 "table <n> [add | del]\n") \
14898 _(mpls_route_add_del, \
14899 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
14900 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
14901 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
14902 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
14903 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
14904 "[count <n>] [del]") \
14905 _(mpls_ip_bind_unbind, \
14906 "<label> <addr/len>") \
14907 _(mpls_tunnel_add_del, \
14908 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
14909 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
14910 "[l2-only] [out-label <n>]") \
14911 _(sr_mpls_policy_add, \
14912 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
14913 _(sr_mpls_policy_del, \
14915 _(bier_table_add_del, \
14916 "<label> <sub-domain> <set> <bsl> [del]") \
14917 _(bier_route_add_del, \
14918 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
14919 "[<intfc> | sw_if_index <id>]" \
14920 "[weight <n>] [del] [multipath]") \
14921 _(sw_interface_set_unnumbered, \
14922 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
14923 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
14924 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
14925 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
14926 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
14927 "[outer_vlan_id_any][inner_vlan_id_any]") \
14928 _(ip_table_replace_begin, "table <n> [ipv6]") \
14929 _(ip_table_flush, "table <n> [ipv6]") \
14930 _(ip_table_replace_end, "table <n> [ipv6]") \
14931 _(set_ip_flow_hash, \
14932 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
14933 _(sw_interface_ip6_enable_disable, \
14934 "<intfc> | sw_if_index <id> enable | disable") \
14935 _(l2_patch_add_del, \
14936 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14937 "enable | disable") \
14938 _(sr_localsid_add_del, \
14939 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
14940 "fib-table <num> (end.psp) sw_if_index <num>") \
14941 _(classify_add_del_table, \
14942 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
14943 " [del] [del-chain] mask <mask-value>\n" \
14944 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
14945 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
14946 _(classify_add_del_session, \
14947 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
14948 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
14949 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
14950 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
14951 _(classify_set_interface_ip_table, \
14952 "<intfc> | sw_if_index <nn> table <nn>") \
14953 _(classify_set_interface_l2_tables, \
14954 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14955 " [other-table <nn>]") \
14956 _(get_node_index, "node <node-name") \
14957 _(add_node_next, "node <node-name> next <next-node-name>") \
14958 _(vxlan_offload_rx, \
14959 "hw { <interface name> | hw_if_index <nn>} " \
14960 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
14961 _(vxlan_add_del_tunnel, \
14962 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
14963 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
14964 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
14965 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14966 _(l2_fib_clear_table, "") \
14967 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
14968 _(l2_interface_vlan_tag_rewrite, \
14969 "<intfc> | sw_if_index <nn> \n" \
14970 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
14971 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
14972 _(create_vhost_user_if, \
14973 "socket <filename> [server] [renumber <dev_instance>] " \
14974 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14975 "[mac <mac_address>] [packed]") \
14976 _(modify_vhost_user_if, \
14977 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14978 "[server] [renumber <dev_instance>] [gso] [packed]") \
14979 _(create_vhost_user_if_v2, \
14980 "socket <filename> [server] [renumber <dev_instance>] " \
14981 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14982 "[mac <mac_address>] [packed] [event-idx]") \
14983 _(modify_vhost_user_if_v2, \
14984 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14985 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
14986 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
14987 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
14988 _(show_version, "") \
14989 _(show_threads, "") \
14990 _(vxlan_gpe_add_del_tunnel, \
14991 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
14992 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
14993 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
14994 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
14995 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14996 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
14997 _(interface_name_renumber, \
14998 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
14999 _(input_acl_set_interface, \
15000 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15001 " [l2-table <nn>] [del]") \
15002 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
15003 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15004 _(ip_dump, "ipv4 | ipv6") \
15005 _(ipsec_spd_add_del, "spd_id <n> [del]") \
15006 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15008 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15009 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15010 " integ_alg <alg> integ_key <hex>") \
15011 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
15012 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15013 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15014 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
15015 _(ipsec_sa_dump, "[sa_id <n>]") \
15016 _(delete_loopback,"sw_if_index <nn>") \
15017 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15018 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
15019 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
15020 _(want_interface_events, "enable|disable") \
15021 _(get_first_msg_id, "client <name>") \
15022 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15023 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
15024 "fib-id <nn> [ip4][ip6][default]") \
15025 _(get_node_graph, " ") \
15026 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
15027 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15028 _(ioam_disable, "") \
15029 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
15030 _(af_packet_delete, "name <host interface name>") \
15031 _(af_packet_dump, "") \
15032 _(policer_add_del, "name <policer name> <params> [del]") \
15033 _(policer_dump, "[name <policer name>]") \
15034 _(policer_classify_set_interface, \
15035 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15036 " [l2-table <nn>] [del]") \
15037 _(policer_classify_dump, "type [ip4|ip6|l2]") \
15038 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
15039 _(mpls_table_dump, "") \
15040 _(mpls_route_dump, "table-id <ID>") \
15041 _(classify_table_ids, "") \
15042 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15043 _(classify_table_info, "table_id <nn>") \
15044 _(classify_session_dump, "table_id <nn>") \
15045 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15046 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15047 "[template_interval <nn>] [udp_checksum]") \
15048 _(ipfix_exporter_dump, "") \
15049 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15050 _(ipfix_classify_stream_dump, "") \
15051 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
15052 _(ipfix_classify_table_dump, "") \
15053 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
15054 _(sw_interface_span_dump, "[l2]") \
15055 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15056 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
15057 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
15058 _(pg_enable_disable, "[stream <id>] disable") \
15059 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
15060 _(ip_source_and_port_range_check_add_del, \
15061 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15062 _(ip_source_and_port_range_check_interface_add_del, \
15063 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
15064 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15065 _(delete_subif,"<intfc> | sw_if_index <nn>") \
15066 _(l2_interface_pbb_tag_rewrite, \
15067 "<intfc> | sw_if_index <nn> \n" \
15068 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15069 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15070 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
15071 _(flow_classify_set_interface, \
15072 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
15073 _(flow_classify_dump, "type [ip4|ip6]") \
15074 _(ip_table_dump, "") \
15075 _(ip_route_dump, "table-id [ip4|ip6]") \
15076 _(ip_mtable_dump, "") \
15077 _(ip_mroute_dump, "table-id [ip4|ip6]") \
15078 _(feature_enable_disable, "arc_name <arc_name> " \
15079 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
15080 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
15081 "[enable | disable] ") \
15082 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
15084 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
15085 "mac <mac-address> [del]") \
15086 _(l2_xconnect_dump, "") \
15087 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
15088 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
15089 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
15090 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
15091 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
15092 _(sock_init_shm, "size <nnn>") \
15093 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
15094 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
15095 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15096 _(session_rules_dump, "") \
15097 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15098 _(output_acl_set_interface, \
15099 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15100 " [l2-table <nn>] [del]") \
15101 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15103 /* List of command functions, CLI names map directly to functions */
15104 #define foreach_cli_function \
15105 _(comment, "usage: comment <ignore-rest-of-line>") \
15106 _(dump_interface_table, "usage: dump_interface_table") \
15107 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15108 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15109 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15110 _(dump_macro_table, "usage: dump_macro_table ") \
15111 _(dump_node_table, "usage: dump_node_table") \
15112 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15113 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15114 _(elog_disable, "usage: elog_disable") \
15115 _(elog_enable, "usage: elog_enable") \
15116 _(elog_save, "usage: elog_save <filename>") \
15117 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15118 _(echo, "usage: echo <message>") \
15119 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15120 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15121 _(help, "usage: help") \
15122 _(q, "usage: quit") \
15123 _(quit, "usage: quit") \
15124 _(search_node_table, "usage: search_node_table <name>...") \
15125 _(set, "usage: set <variable-name> <value>") \
15126 _(script, "usage: script <file-name>") \
15127 _(statseg, "usage: statseg") \
15128 _(unset, "usage: unset <variable-name>")
15131 static void vl_api_##n##_t_handler_uni \
15132 (vl_api_##n##_t * mp) \
15134 vat_main_t * vam = &vat_main; \
15135 if (vam->json_output) { \
15136 vl_api_##n##_t_handler_json(mp); \
15138 vl_api_##n##_t_handler(mp); \
15141 foreach_vpe_api_reply_msg;
15142 #if VPP_API_TEST_BUILTIN == 0
15143 foreach_standalone_reply_msg;
15148 vat_api_hookup (vat_main_t * vam)
15151 vl_msg_api_set_handlers(VL_API_##N, #n, \
15152 vl_api_##n##_t_handler_uni, \
15154 vl_api_##n##_t_endian, \
15155 vl_api_##n##_t_print, \
15156 sizeof(vl_api_##n##_t), 1);
15157 foreach_vpe_api_reply_msg;
15158 #if VPP_API_TEST_BUILTIN == 0
15159 foreach_standalone_reply_msg;
15163 #if (VPP_API_TEST_BUILTIN==0)
15164 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15166 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15168 vam->function_by_name = hash_create_string (0, sizeof (uword));
15170 vam->help_by_name = hash_create_string (0, sizeof (uword));
15173 /* API messages we can send */
15174 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15175 foreach_vpe_api_msg;
15179 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15180 foreach_vpe_api_msg;
15183 /* CLI functions */
15184 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15185 foreach_cli_function;
15189 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15190 foreach_cli_function;
15194 #if VPP_API_TEST_BUILTIN
15195 static clib_error_t *
15196 vat_api_hookup_shim (vlib_main_t * vm)
15198 vat_api_hookup (&vat_main);
15202 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15206 * fd.io coding-style-patch-verification: ON
15209 * eval: (c-set-style "gnu")