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"))
483 *r = SSE2_QOS_RATE_KBPS;
484 else if (unformat (input, "pps"))
485 *r = SSE2_QOS_RATE_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 = SSE2_QOS_ROUND_TO_CLOSEST;
498 else if (unformat (input, "up"))
499 *r = SSE2_QOS_ROUND_TO_UP;
500 else if (unformat (input, "down"))
501 *r = SSE2_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 = SSE2_QOS_POLICER_TYPE_1R2C;
514 else if (unformat (input, "1r3c"))
515 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
516 else if (unformat (input, "2r3c-2698"))
517 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
518 else if (unformat (input, "2r3c-4115"))
519 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
520 else if (unformat (input, "2r3c-mef5cf1"))
521 *r = SSE2_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,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
542 unformat_policer_action_type (unformat_input_t * input, va_list * va)
544 sse2_qos_pol_action_params_st *a
545 = va_arg (*va, sse2_qos_pol_action_params_st *);
547 if (unformat (input, "drop"))
548 a->action_type = SSE2_QOS_ACTION_DROP;
549 else if (unformat (input, "transmit"))
550 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
551 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
552 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
559 unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
561 u32 *r = va_arg (*va, u32 *);
564 if (unformat (input, "ip4"))
565 tid = POLICER_CLASSIFY_TABLE_IP4;
566 else if (unformat (input, "ip6"))
567 tid = POLICER_CLASSIFY_TABLE_IP6;
568 else if (unformat (input, "l2"))
569 tid = POLICER_CLASSIFY_TABLE_L2;
578 unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
580 u32 *r = va_arg (*va, u32 *);
583 if (unformat (input, "ip4"))
584 tid = FLOW_CLASSIFY_TABLE_IP4;
585 else if (unformat (input, "ip6"))
586 tid = FLOW_CLASSIFY_TABLE_IP6;
594 #if (VPP_API_TEST_BUILTIN==0)
596 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
597 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
598 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
599 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
602 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
604 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
605 mfib_itf_attribute_t attr;
608 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
610 if (unformat (input, mfib_itf_flag_long_names[attr]))
611 *iflags |= (1 << attr);
613 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
615 if (unformat (input, mfib_itf_flag_names[attr]))
616 *iflags |= (1 << attr);
619 return (old == *iflags ? 0 : 1);
623 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
625 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
626 mfib_entry_attribute_t attr;
629 FOR_EACH_MFIB_ATTRIBUTE (attr)
631 if (unformat (input, mfib_flag_long_names[attr]))
632 *eflags |= (1 << attr);
634 FOR_EACH_MFIB_ATTRIBUTE (attr)
636 if (unformat (input, mfib_flag_names[attr]))
637 *eflags |= (1 << attr);
640 return (old == *eflags ? 0 : 1);
644 format_ip4_address (u8 * s, va_list * args)
646 u8 *a = va_arg (*args, u8 *);
647 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
651 format_ip6_address (u8 * s, va_list * args)
653 ip6_address_t *a = va_arg (*args, ip6_address_t *);
654 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
656 i_max_n_zero = ARRAY_LEN (a->as_u16);
658 i_first_zero = i_max_n_zero;
660 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
662 u32 is_zero = a->as_u16[i] == 0;
663 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
669 if ((!is_zero && n_zeros > max_n_zeros)
670 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
672 i_max_n_zero = i_first_zero;
673 max_n_zeros = n_zeros;
674 i_first_zero = ARRAY_LEN (a->as_u16);
679 last_double_colon = 0;
680 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
682 if (i == i_max_n_zero && max_n_zeros > 1)
684 s = format (s, "::");
685 i += max_n_zeros - 1;
686 last_double_colon = 1;
690 s = format (s, "%s%x",
691 (last_double_colon || i == 0) ? "" : ":",
692 clib_net_to_host_u16 (a->as_u16[i]));
693 last_double_colon = 0;
700 /* Format an IP46 address. */
702 format_ip46_address (u8 * s, va_list * args)
704 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
705 ip46_type_t type = va_arg (*args, ip46_type_t);
711 is_ip4 = ip46_address_is_ip4 (ip46);
722 format (s, "%U", format_ip4_address, &ip46->ip4) :
723 format (s, "%U", format_ip6_address, &ip46->ip6);
727 format_ethernet_address (u8 * s, va_list * args)
729 u8 *a = va_arg (*args, u8 *);
731 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
732 a[0], a[1], a[2], a[3], a[4], a[5]);
737 increment_v4_address (vl_api_ip4_address_t * i)
739 ip4_address_t *a = (ip4_address_t *) i;
742 v = ntohl (a->as_u32) + 1;
743 a->as_u32 = ntohl (v);
747 increment_v6_address (vl_api_ip6_address_t * i)
749 ip6_address_t *a = (ip6_address_t *) i;
752 v0 = clib_net_to_host_u64 (a->as_u64[0]);
753 v1 = clib_net_to_host_u64 (a->as_u64[1]);
758 a->as_u64[0] = clib_net_to_host_u64 (v0);
759 a->as_u64[1] = clib_net_to_host_u64 (v1);
763 increment_address (vl_api_address_t * a)
765 if (a->af == ADDRESS_IP4)
766 increment_v4_address (&a->un.ip4);
767 else if (a->af == ADDRESS_IP6)
768 increment_v6_address (&a->un.ip6);
772 set_ip4_address (vl_api_address_t * a, u32 v)
774 if (a->af == ADDRESS_IP4)
776 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
782 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
785 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
787 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
788 sizeof (ip6_address_t));
792 increment_mac_address (u8 * mac)
794 u64 tmp = *((u64 *) mac);
795 tmp = clib_net_to_host_u64 (tmp);
796 tmp += 1 << 16; /* skip unused (least significant) octets */
797 tmp = clib_host_to_net_u64 (tmp);
799 clib_memcpy (mac, &tmp, 6);
803 vat_json_object_add_address (vat_json_node_t * node,
804 const char *str, const vl_api_address_t * addr)
806 if (ADDRESS_IP6 == addr->af)
810 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
811 vat_json_object_add_ip6 (node, str, ip6);
817 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
818 vat_json_object_add_ip4 (node, str, ip4);
823 vat_json_object_add_prefix (vat_json_node_t * node,
824 const vl_api_prefix_t * prefix)
826 vat_json_object_add_uint (node, "len", prefix->len);
827 vat_json_object_add_address (node, "address", &prefix->address);
830 static void vl_api_create_loopback_reply_t_handler
831 (vl_api_create_loopback_reply_t * mp)
833 vat_main_t *vam = &vat_main;
834 i32 retval = ntohl (mp->retval);
836 vam->retval = retval;
837 vam->regenerate_interface_table = 1;
838 vam->sw_if_index = ntohl (mp->sw_if_index);
839 vam->result_ready = 1;
842 static void vl_api_create_loopback_reply_t_handler_json
843 (vl_api_create_loopback_reply_t * mp)
845 vat_main_t *vam = &vat_main;
846 vat_json_node_t node;
848 vat_json_init_object (&node);
849 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
850 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
852 vat_json_print (vam->ofp, &node);
853 vat_json_free (&node);
854 vam->retval = ntohl (mp->retval);
855 vam->result_ready = 1;
858 static void vl_api_create_loopback_instance_reply_t_handler
859 (vl_api_create_loopback_instance_reply_t * mp)
861 vat_main_t *vam = &vat_main;
862 i32 retval = ntohl (mp->retval);
864 vam->retval = retval;
865 vam->regenerate_interface_table = 1;
866 vam->sw_if_index = ntohl (mp->sw_if_index);
867 vam->result_ready = 1;
870 static void vl_api_create_loopback_instance_reply_t_handler_json
871 (vl_api_create_loopback_instance_reply_t * mp)
873 vat_main_t *vam = &vat_main;
874 vat_json_node_t node;
876 vat_json_init_object (&node);
877 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
878 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
880 vat_json_print (vam->ofp, &node);
881 vat_json_free (&node);
882 vam->retval = ntohl (mp->retval);
883 vam->result_ready = 1;
886 static void vl_api_af_packet_create_reply_t_handler
887 (vl_api_af_packet_create_reply_t * mp)
889 vat_main_t *vam = &vat_main;
890 i32 retval = ntohl (mp->retval);
892 vam->retval = retval;
893 vam->regenerate_interface_table = 1;
894 vam->sw_if_index = ntohl (mp->sw_if_index);
895 vam->result_ready = 1;
898 static void vl_api_af_packet_create_reply_t_handler_json
899 (vl_api_af_packet_create_reply_t * mp)
901 vat_main_t *vam = &vat_main;
902 vat_json_node_t node;
904 vat_json_init_object (&node);
905 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
906 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
908 vat_json_print (vam->ofp, &node);
909 vat_json_free (&node);
911 vam->retval = ntohl (mp->retval);
912 vam->result_ready = 1;
915 static void vl_api_create_vlan_subif_reply_t_handler
916 (vl_api_create_vlan_subif_reply_t * mp)
918 vat_main_t *vam = &vat_main;
919 i32 retval = ntohl (mp->retval);
921 vam->retval = retval;
922 vam->regenerate_interface_table = 1;
923 vam->sw_if_index = ntohl (mp->sw_if_index);
924 vam->result_ready = 1;
927 static void vl_api_create_vlan_subif_reply_t_handler_json
928 (vl_api_create_vlan_subif_reply_t * mp)
930 vat_main_t *vam = &vat_main;
931 vat_json_node_t node;
933 vat_json_init_object (&node);
934 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
935 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
937 vat_json_print (vam->ofp, &node);
938 vat_json_free (&node);
940 vam->retval = ntohl (mp->retval);
941 vam->result_ready = 1;
944 static void vl_api_create_subif_reply_t_handler
945 (vl_api_create_subif_reply_t * mp)
947 vat_main_t *vam = &vat_main;
948 i32 retval = ntohl (mp->retval);
950 vam->retval = retval;
951 vam->regenerate_interface_table = 1;
952 vam->sw_if_index = ntohl (mp->sw_if_index);
953 vam->result_ready = 1;
956 static void vl_api_create_subif_reply_t_handler_json
957 (vl_api_create_subif_reply_t * mp)
959 vat_main_t *vam = &vat_main;
960 vat_json_node_t node;
962 vat_json_init_object (&node);
963 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
964 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
966 vat_json_print (vam->ofp, &node);
967 vat_json_free (&node);
969 vam->retval = ntohl (mp->retval);
970 vam->result_ready = 1;
973 static void vl_api_interface_name_renumber_reply_t_handler
974 (vl_api_interface_name_renumber_reply_t * mp)
976 vat_main_t *vam = &vat_main;
977 i32 retval = ntohl (mp->retval);
979 vam->retval = retval;
980 vam->regenerate_interface_table = 1;
981 vam->result_ready = 1;
984 static void vl_api_interface_name_renumber_reply_t_handler_json
985 (vl_api_interface_name_renumber_reply_t * mp)
987 vat_main_t *vam = &vat_main;
988 vat_json_node_t node;
990 vat_json_init_object (&node);
991 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
993 vat_json_print (vam->ofp, &node);
994 vat_json_free (&node);
996 vam->retval = ntohl (mp->retval);
997 vam->result_ready = 1;
1001 * Special-case: build the interface table, maintain
1002 * the next loopback sw_if_index vbl.
1004 static void vl_api_sw_interface_details_t_handler
1005 (vl_api_sw_interface_details_t * mp)
1007 vat_main_t *vam = &vat_main;
1008 u8 *s = format (0, "%s%c", mp->interface_name, 0);
1010 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1011 ntohl (mp->sw_if_index));
1013 /* In sub interface case, fill the sub interface table entry */
1014 if (mp->sw_if_index != mp->sup_sw_if_index)
1016 sw_interface_subif_t *sub = NULL;
1018 vec_add2 (vam->sw_if_subif_table, sub, 1);
1020 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1021 strncpy ((char *) sub->interface_name, (char *) s,
1022 vec_len (sub->interface_name));
1023 sub->sw_if_index = ntohl (mp->sw_if_index);
1024 sub->sub_id = ntohl (mp->sub_id);
1026 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1028 sub->sub_number_of_tags = mp->sub_number_of_tags;
1029 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1030 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
1032 /* vlan tag rewrite */
1033 sub->vtr_op = ntohl (mp->vtr_op);
1034 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1035 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1036 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1040 static void vl_api_sw_interface_details_t_handler_json
1041 (vl_api_sw_interface_details_t * mp)
1043 vat_main_t *vam = &vat_main;
1044 vat_json_node_t *node = NULL;
1046 if (VAT_JSON_ARRAY != vam->json_tree.type)
1048 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1049 vat_json_init_array (&vam->json_tree);
1051 node = vat_json_array_add (&vam->json_tree);
1053 vat_json_init_object (node);
1054 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1055 vat_json_object_add_uint (node, "sup_sw_if_index",
1056 ntohl (mp->sup_sw_if_index));
1057 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1058 sizeof (mp->l2_address));
1059 vat_json_object_add_string_copy (node, "interface_name",
1060 mp->interface_name);
1061 vat_json_object_add_string_copy (node, "interface_dev_type",
1062 mp->interface_dev_type);
1063 vat_json_object_add_uint (node, "flags", mp->flags);
1064 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1065 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1066 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1067 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1068 vat_json_object_add_uint (node, "sub_number_of_tags",
1069 mp->sub_number_of_tags);
1070 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1071 ntohs (mp->sub_outer_vlan_id));
1072 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1073 ntohs (mp->sub_inner_vlan_id));
1074 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1075 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1076 vat_json_object_add_uint (node, "vtr_push_dot1q",
1077 ntohl (mp->vtr_push_dot1q));
1078 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1079 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1080 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1082 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1084 format_ethernet_address,
1086 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1088 format_ethernet_address,
1090 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1091 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1095 #if VPP_API_TEST_BUILTIN == 0
1096 static void vl_api_sw_interface_event_t_handler
1097 (vl_api_sw_interface_event_t * mp)
1099 vat_main_t *vam = &vat_main;
1100 if (vam->interface_event_display)
1101 errmsg ("interface flags: sw_if_index %d %s %s",
1102 ntohl (mp->sw_if_index),
1103 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1104 "admin-up" : "admin-down",
1105 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1106 "link-up" : "link-down");
1110 __clib_unused static void
1111 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1113 /* JSON output not supported */
1117 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1119 vat_main_t *vam = &vat_main;
1120 i32 retval = ntohl (mp->retval);
1122 vam->retval = retval;
1123 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1124 vam->result_ready = 1;
1128 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1130 vat_main_t *vam = &vat_main;
1131 vat_json_node_t node;
1135 vat_json_init_object (&node);
1136 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1137 vat_json_object_add_uint (&node, "reply_in_shmem",
1138 ntohl (mp->reply_in_shmem));
1139 /* Toss the shared-memory original... */
1140 oldheap = vl_msg_push_heap ();
1142 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1145 vl_msg_pop_heap (oldheap);
1147 vat_json_print (vam->ofp, &node);
1148 vat_json_free (&node);
1150 vam->retval = ntohl (mp->retval);
1151 vam->result_ready = 1;
1155 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1157 vat_main_t *vam = &vat_main;
1158 i32 retval = ntohl (mp->retval);
1160 vec_reset_length (vam->cmd_reply);
1162 vam->retval = retval;
1164 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1165 vam->result_ready = 1;
1169 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1171 vat_main_t *vam = &vat_main;
1172 vat_json_node_t node;
1173 u8 *reply = 0; /* reply vector */
1175 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1176 vec_reset_length (vam->cmd_reply);
1178 vat_json_init_object (&node);
1179 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1180 vat_json_object_add_string_copy (&node, "reply", reply);
1182 vat_json_print (vam->ofp, &node);
1183 vat_json_free (&node);
1186 vam->retval = ntohl (mp->retval);
1187 vam->result_ready = 1;
1190 static void vl_api_classify_add_del_table_reply_t_handler
1191 (vl_api_classify_add_del_table_reply_t * mp)
1193 vat_main_t *vam = &vat_main;
1194 i32 retval = ntohl (mp->retval);
1195 if (vam->async_mode)
1197 vam->async_errors += (retval < 0);
1201 vam->retval = retval;
1203 ((mp->new_table_index != 0xFFFFFFFF) ||
1204 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1205 (mp->match_n_vectors != 0xFFFFFFFF)))
1207 * Note: this is just barely thread-safe, depends on
1208 * the main thread spinning waiting for an answer...
1210 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1211 ntohl (mp->new_table_index),
1212 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1213 vam->result_ready = 1;
1217 static void vl_api_classify_add_del_table_reply_t_handler_json
1218 (vl_api_classify_add_del_table_reply_t * mp)
1220 vat_main_t *vam = &vat_main;
1221 vat_json_node_t node;
1223 vat_json_init_object (&node);
1224 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1225 vat_json_object_add_uint (&node, "new_table_index",
1226 ntohl (mp->new_table_index));
1227 vat_json_object_add_uint (&node, "skip_n_vectors",
1228 ntohl (mp->skip_n_vectors));
1229 vat_json_object_add_uint (&node, "match_n_vectors",
1230 ntohl (mp->match_n_vectors));
1232 vat_json_print (vam->ofp, &node);
1233 vat_json_free (&node);
1235 vam->retval = ntohl (mp->retval);
1236 vam->result_ready = 1;
1239 static void vl_api_get_node_index_reply_t_handler
1240 (vl_api_get_node_index_reply_t * mp)
1242 vat_main_t *vam = &vat_main;
1243 i32 retval = ntohl (mp->retval);
1244 if (vam->async_mode)
1246 vam->async_errors += (retval < 0);
1250 vam->retval = retval;
1252 errmsg ("node index %d", ntohl (mp->node_index));
1253 vam->result_ready = 1;
1257 static void vl_api_get_node_index_reply_t_handler_json
1258 (vl_api_get_node_index_reply_t * mp)
1260 vat_main_t *vam = &vat_main;
1261 vat_json_node_t node;
1263 vat_json_init_object (&node);
1264 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1265 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1267 vat_json_print (vam->ofp, &node);
1268 vat_json_free (&node);
1270 vam->retval = ntohl (mp->retval);
1271 vam->result_ready = 1;
1274 static void vl_api_get_next_index_reply_t_handler
1275 (vl_api_get_next_index_reply_t * mp)
1277 vat_main_t *vam = &vat_main;
1278 i32 retval = ntohl (mp->retval);
1279 if (vam->async_mode)
1281 vam->async_errors += (retval < 0);
1285 vam->retval = retval;
1287 errmsg ("next node index %d", ntohl (mp->next_index));
1288 vam->result_ready = 1;
1292 static void vl_api_get_next_index_reply_t_handler_json
1293 (vl_api_get_next_index_reply_t * mp)
1295 vat_main_t *vam = &vat_main;
1296 vat_json_node_t node;
1298 vat_json_init_object (&node);
1299 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1300 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1302 vat_json_print (vam->ofp, &node);
1303 vat_json_free (&node);
1305 vam->retval = ntohl (mp->retval);
1306 vam->result_ready = 1;
1309 static void vl_api_add_node_next_reply_t_handler
1310 (vl_api_add_node_next_reply_t * mp)
1312 vat_main_t *vam = &vat_main;
1313 i32 retval = ntohl (mp->retval);
1314 if (vam->async_mode)
1316 vam->async_errors += (retval < 0);
1320 vam->retval = retval;
1322 errmsg ("next index %d", ntohl (mp->next_index));
1323 vam->result_ready = 1;
1327 static void vl_api_add_node_next_reply_t_handler_json
1328 (vl_api_add_node_next_reply_t * mp)
1330 vat_main_t *vam = &vat_main;
1331 vat_json_node_t node;
1333 vat_json_init_object (&node);
1334 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1335 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1337 vat_json_print (vam->ofp, &node);
1338 vat_json_free (&node);
1340 vam->retval = ntohl (mp->retval);
1341 vam->result_ready = 1;
1344 static void vl_api_show_version_reply_t_handler
1345 (vl_api_show_version_reply_t * mp)
1347 vat_main_t *vam = &vat_main;
1348 i32 retval = ntohl (mp->retval);
1352 errmsg (" program: %s", mp->program);
1353 errmsg (" version: %s", mp->version);
1354 errmsg (" build date: %s", mp->build_date);
1355 errmsg ("build directory: %s", mp->build_directory);
1357 vam->retval = retval;
1358 vam->result_ready = 1;
1361 static void vl_api_show_version_reply_t_handler_json
1362 (vl_api_show_version_reply_t * mp)
1364 vat_main_t *vam = &vat_main;
1365 vat_json_node_t node;
1367 vat_json_init_object (&node);
1368 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1369 vat_json_object_add_string_copy (&node, "program", mp->program);
1370 vat_json_object_add_string_copy (&node, "version", mp->version);
1371 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1372 vat_json_object_add_string_copy (&node, "build_directory",
1373 mp->build_directory);
1375 vat_json_print (vam->ofp, &node);
1376 vat_json_free (&node);
1378 vam->retval = ntohl (mp->retval);
1379 vam->result_ready = 1;
1382 static void vl_api_show_threads_reply_t_handler
1383 (vl_api_show_threads_reply_t * mp)
1385 vat_main_t *vam = &vat_main;
1386 i32 retval = ntohl (mp->retval);
1390 count = ntohl (mp->count);
1392 for (i = 0; i < count; i++)
1394 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1395 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1396 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1397 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1398 ntohl (mp->thread_data[i].cpu_socket));
1400 vam->retval = retval;
1401 vam->result_ready = 1;
1404 static void vl_api_show_threads_reply_t_handler_json
1405 (vl_api_show_threads_reply_t * mp)
1407 vat_main_t *vam = &vat_main;
1408 vat_json_node_t node;
1409 vl_api_thread_data_t *td;
1410 i32 retval = ntohl (mp->retval);
1414 count = ntohl (mp->count);
1416 vat_json_init_object (&node);
1417 vat_json_object_add_int (&node, "retval", retval);
1418 vat_json_object_add_uint (&node, "count", count);
1420 for (i = 0; i < count; i++)
1422 td = &mp->thread_data[i];
1423 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1424 vat_json_object_add_string_copy (&node, "name", td->name);
1425 vat_json_object_add_string_copy (&node, "type", td->type);
1426 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1427 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1428 vat_json_object_add_int (&node, "core", ntohl (td->id));
1429 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1432 vat_json_print (vam->ofp, &node);
1433 vat_json_free (&node);
1435 vam->retval = retval;
1436 vam->result_ready = 1;
1440 api_show_threads (vat_main_t * vam)
1442 vl_api_show_threads_t *mp;
1446 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1447 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1449 M (SHOW_THREADS, mp);
1457 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1459 u32 n_macs = ntohl (mp->n_macs);
1460 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1461 ntohl (mp->pid), mp->client_index, n_macs);
1463 for (i = 0; i < n_macs; i++)
1465 vl_api_mac_entry_t *mac = &mp->mac[i];
1466 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1467 i + 1, ntohl (mac->sw_if_index),
1468 format_ethernet_address, mac->mac_addr, mac->action);
1475 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1477 /* JSON output not supported */
1480 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1481 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1484 * Special-case: build the bridge domain table, maintain
1485 * the next bd id vbl.
1487 static void vl_api_bridge_domain_details_t_handler
1488 (vl_api_bridge_domain_details_t * mp)
1490 vat_main_t *vam = &vat_main;
1491 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1494 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1495 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1497 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1498 ntohl (mp->bd_id), mp->learn, mp->forward,
1499 mp->flood, ntohl (mp->bvi_sw_if_index),
1500 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1504 vl_api_bridge_domain_sw_if_t *sw_ifs;
1505 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1508 sw_ifs = mp->sw_if_details;
1509 for (i = 0; i < n_sw_ifs; i++)
1515 sw_if_index = ntohl (sw_ifs->sw_if_index);
1518 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1520 if ((u32) p->value[0] == sw_if_index)
1522 sw_if_name = (u8 *)(p->key);
1527 print (vam->ofp, "%7d %3d %s", sw_if_index,
1528 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1529 "sw_if_index not found!");
1536 static void vl_api_bridge_domain_details_t_handler_json
1537 (vl_api_bridge_domain_details_t * mp)
1539 vat_main_t *vam = &vat_main;
1540 vat_json_node_t *node, *array = NULL;
1541 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1543 if (VAT_JSON_ARRAY != vam->json_tree.type)
1545 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1546 vat_json_init_array (&vam->json_tree);
1548 node = vat_json_array_add (&vam->json_tree);
1550 vat_json_init_object (node);
1551 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1552 vat_json_object_add_uint (node, "flood", mp->flood);
1553 vat_json_object_add_uint (node, "forward", mp->forward);
1554 vat_json_object_add_uint (node, "learn", mp->learn);
1555 vat_json_object_add_uint (node, "bvi_sw_if_index",
1556 ntohl (mp->bvi_sw_if_index));
1557 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1558 array = vat_json_object_add (node, "sw_if");
1559 vat_json_init_array (array);
1565 vl_api_bridge_domain_sw_if_t *sw_ifs;
1568 sw_ifs = mp->sw_if_details;
1569 for (i = 0; i < n_sw_ifs; i++)
1571 node = vat_json_array_add (array);
1572 vat_json_init_object (node);
1573 vat_json_object_add_uint (node, "sw_if_index",
1574 ntohl (sw_ifs->sw_if_index));
1575 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1581 static void vl_api_control_ping_reply_t_handler
1582 (vl_api_control_ping_reply_t * mp)
1584 vat_main_t *vam = &vat_main;
1585 i32 retval = ntohl (mp->retval);
1586 if (vam->async_mode)
1588 vam->async_errors += (retval < 0);
1592 vam->retval = retval;
1593 vam->result_ready = 1;
1595 if (vam->socket_client_main)
1596 vam->socket_client_main->control_pings_outstanding--;
1599 static void vl_api_control_ping_reply_t_handler_json
1600 (vl_api_control_ping_reply_t * mp)
1602 vat_main_t *vam = &vat_main;
1603 i32 retval = ntohl (mp->retval);
1605 if (VAT_JSON_NONE != vam->json_tree.type)
1607 vat_json_print (vam->ofp, &vam->json_tree);
1608 vat_json_free (&vam->json_tree);
1609 vam->json_tree.type = VAT_JSON_NONE;
1614 vat_json_init_array (&vam->json_tree);
1615 vat_json_print (vam->ofp, &vam->json_tree);
1616 vam->json_tree.type = VAT_JSON_NONE;
1619 vam->retval = retval;
1620 vam->result_ready = 1;
1624 vl_api_bridge_domain_set_mac_age_reply_t_handler
1625 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1627 vat_main_t *vam = &vat_main;
1628 i32 retval = ntohl (mp->retval);
1629 if (vam->async_mode)
1631 vam->async_errors += (retval < 0);
1635 vam->retval = retval;
1636 vam->result_ready = 1;
1640 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1641 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1643 vat_main_t *vam = &vat_main;
1644 vat_json_node_t node;
1646 vat_json_init_object (&node);
1647 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1649 vat_json_print (vam->ofp, &node);
1650 vat_json_free (&node);
1652 vam->retval = ntohl (mp->retval);
1653 vam->result_ready = 1;
1657 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1659 vat_main_t *vam = &vat_main;
1660 i32 retval = ntohl (mp->retval);
1661 if (vam->async_mode)
1663 vam->async_errors += (retval < 0);
1667 vam->retval = retval;
1668 vam->result_ready = 1;
1672 static void vl_api_l2_flags_reply_t_handler_json
1673 (vl_api_l2_flags_reply_t * mp)
1675 vat_main_t *vam = &vat_main;
1676 vat_json_node_t node;
1678 vat_json_init_object (&node);
1679 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1680 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1681 ntohl (mp->resulting_feature_bitmap));
1683 vat_json_print (vam->ofp, &node);
1684 vat_json_free (&node);
1686 vam->retval = ntohl (mp->retval);
1687 vam->result_ready = 1;
1690 static void vl_api_bridge_flags_reply_t_handler
1691 (vl_api_bridge_flags_reply_t * mp)
1693 vat_main_t *vam = &vat_main;
1694 i32 retval = ntohl (mp->retval);
1695 if (vam->async_mode)
1697 vam->async_errors += (retval < 0);
1701 vam->retval = retval;
1702 vam->result_ready = 1;
1706 static void vl_api_bridge_flags_reply_t_handler_json
1707 (vl_api_bridge_flags_reply_t * mp)
1709 vat_main_t *vam = &vat_main;
1710 vat_json_node_t node;
1712 vat_json_init_object (&node);
1713 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1714 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1715 ntohl (mp->resulting_feature_bitmap));
1717 vat_json_print (vam->ofp, &node);
1718 vat_json_free (&node);
1720 vam->retval = ntohl (mp->retval);
1721 vam->result_ready = 1;
1725 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1727 vat_main_t *vam = &vat_main;
1728 i32 retval = ntohl (mp->retval);
1729 if (vam->async_mode)
1731 vam->async_errors += (retval < 0);
1735 vam->retval = retval;
1736 vam->sw_if_index = ntohl (mp->sw_if_index);
1737 vam->result_ready = 1;
1742 static void vl_api_tap_create_v2_reply_t_handler_json
1743 (vl_api_tap_create_v2_reply_t * mp)
1745 vat_main_t *vam = &vat_main;
1746 vat_json_node_t node;
1748 vat_json_init_object (&node);
1749 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1750 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1752 vat_json_print (vam->ofp, &node);
1753 vat_json_free (&node);
1755 vam->retval = ntohl (mp->retval);
1756 vam->result_ready = 1;
1761 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1763 vat_main_t *vam = &vat_main;
1764 i32 retval = ntohl (mp->retval);
1765 if (vam->async_mode)
1767 vam->async_errors += (retval < 0);
1771 vam->retval = retval;
1772 vam->result_ready = 1;
1776 static void vl_api_tap_delete_v2_reply_t_handler_json
1777 (vl_api_tap_delete_v2_reply_t * mp)
1779 vat_main_t *vam = &vat_main;
1780 vat_json_node_t node;
1782 vat_json_init_object (&node);
1783 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1785 vat_json_print (vam->ofp, &node);
1786 vat_json_free (&node);
1788 vam->retval = ntohl (mp->retval);
1789 vam->result_ready = 1;
1793 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1796 vat_main_t *vam = &vat_main;
1797 i32 retval = ntohl (mp->retval);
1798 if (vam->async_mode)
1800 vam->async_errors += (retval < 0);
1804 vam->retval = retval;
1805 vam->sw_if_index = ntohl (mp->sw_if_index);
1806 vam->result_ready = 1;
1810 static void vl_api_virtio_pci_create_reply_t_handler_json
1811 (vl_api_virtio_pci_create_reply_t * mp)
1813 vat_main_t *vam = &vat_main;
1814 vat_json_node_t node;
1816 vat_json_init_object (&node);
1817 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1818 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1820 vat_json_print (vam->ofp, &node);
1821 vat_json_free (&node);
1823 vam->retval = ntohl (mp->retval);
1824 vam->result_ready = 1;
1829 vl_api_virtio_pci_create_v2_reply_t_handler
1830 (vl_api_virtio_pci_create_v2_reply_t * mp)
1832 vat_main_t *vam = &vat_main;
1833 i32 retval = ntohl (mp->retval);
1834 if (vam->async_mode)
1836 vam->async_errors += (retval < 0);
1840 vam->retval = retval;
1841 vam->sw_if_index = ntohl (mp->sw_if_index);
1842 vam->result_ready = 1;
1846 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1847 (vl_api_virtio_pci_create_v2_reply_t * mp)
1849 vat_main_t *vam = &vat_main;
1850 vat_json_node_t node;
1852 vat_json_init_object (&node);
1853 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1854 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1856 vat_json_print (vam->ofp, &node);
1857 vat_json_free (&node);
1859 vam->retval = ntohl (mp->retval);
1860 vam->result_ready = 1;
1864 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1867 vat_main_t *vam = &vat_main;
1868 i32 retval = ntohl (mp->retval);
1869 if (vam->async_mode)
1871 vam->async_errors += (retval < 0);
1875 vam->retval = retval;
1876 vam->result_ready = 1;
1880 static void vl_api_virtio_pci_delete_reply_t_handler_json
1881 (vl_api_virtio_pci_delete_reply_t * mp)
1883 vat_main_t *vam = &vat_main;
1884 vat_json_node_t node;
1886 vat_json_init_object (&node);
1887 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1889 vat_json_print (vam->ofp, &node);
1890 vat_json_free (&node);
1892 vam->retval = ntohl (mp->retval);
1893 vam->result_ready = 1;
1897 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1899 vat_main_t *vam = &vat_main;
1900 i32 retval = ntohl (mp->retval);
1902 if (vam->async_mode)
1904 vam->async_errors += (retval < 0);
1908 vam->retval = retval;
1909 vam->sw_if_index = ntohl (mp->sw_if_index);
1910 vam->result_ready = 1;
1914 static void vl_api_bond_create_reply_t_handler_json
1915 (vl_api_bond_create_reply_t * mp)
1917 vat_main_t *vam = &vat_main;
1918 vat_json_node_t node;
1920 vat_json_init_object (&node);
1921 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1922 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1924 vat_json_print (vam->ofp, &node);
1925 vat_json_free (&node);
1927 vam->retval = ntohl (mp->retval);
1928 vam->result_ready = 1;
1932 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1934 vat_main_t *vam = &vat_main;
1935 i32 retval = ntohl (mp->retval);
1937 if (vam->async_mode)
1939 vam->async_errors += (retval < 0);
1943 vam->retval = retval;
1944 vam->sw_if_index = ntohl (mp->sw_if_index);
1945 vam->result_ready = 1;
1949 static void vl_api_bond_create2_reply_t_handler_json
1950 (vl_api_bond_create2_reply_t * mp)
1952 vat_main_t *vam = &vat_main;
1953 vat_json_node_t node;
1955 vat_json_init_object (&node);
1956 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1957 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1959 vat_json_print (vam->ofp, &node);
1960 vat_json_free (&node);
1962 vam->retval = ntohl (mp->retval);
1963 vam->result_ready = 1;
1967 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1969 vat_main_t *vam = &vat_main;
1970 i32 retval = ntohl (mp->retval);
1972 if (vam->async_mode)
1974 vam->async_errors += (retval < 0);
1978 vam->retval = retval;
1979 vam->result_ready = 1;
1983 static void vl_api_bond_delete_reply_t_handler_json
1984 (vl_api_bond_delete_reply_t * mp)
1986 vat_main_t *vam = &vat_main;
1987 vat_json_node_t node;
1989 vat_json_init_object (&node);
1990 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1992 vat_json_print (vam->ofp, &node);
1993 vat_json_free (&node);
1995 vam->retval = ntohl (mp->retval);
1996 vam->result_ready = 1;
2000 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
2002 vat_main_t *vam = &vat_main;
2003 i32 retval = ntohl (mp->retval);
2005 if (vam->async_mode)
2007 vam->async_errors += (retval < 0);
2011 vam->retval = retval;
2012 vam->result_ready = 1;
2016 static void vl_api_bond_add_member_reply_t_handler_json
2017 (vl_api_bond_add_member_reply_t * mp)
2019 vat_main_t *vam = &vat_main;
2020 vat_json_node_t node;
2022 vat_json_init_object (&node);
2023 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2025 vat_json_print (vam->ofp, &node);
2026 vat_json_free (&node);
2028 vam->retval = ntohl (mp->retval);
2029 vam->result_ready = 1;
2033 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
2036 vat_main_t *vam = &vat_main;
2037 i32 retval = ntohl (mp->retval);
2039 if (vam->async_mode)
2041 vam->async_errors += (retval < 0);
2045 vam->retval = retval;
2046 vam->result_ready = 1;
2050 static void vl_api_bond_detach_member_reply_t_handler_json
2051 (vl_api_bond_detach_member_reply_t * mp)
2053 vat_main_t *vam = &vat_main;
2054 vat_json_node_t node;
2056 vat_json_init_object (&node);
2057 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2059 vat_json_print (vam->ofp, &node);
2060 vat_json_free (&node);
2062 vam->retval = ntohl (mp->retval);
2063 vam->result_ready = 1;
2067 api_sw_interface_set_bond_weight (vat_main_t * vam)
2069 unformat_input_t *i = vam->input;
2070 vl_api_sw_interface_set_bond_weight_t *mp;
2071 u32 sw_if_index = ~0;
2073 u8 weight_enter = 0;
2076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2078 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2080 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2082 else if (unformat (i, "weight %u", &weight))
2088 if (sw_if_index == ~0)
2090 errmsg ("missing interface name or sw_if_index");
2093 if (weight_enter == 0)
2095 errmsg ("missing valid weight");
2099 /* Construct the API message */
2100 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2101 mp->sw_if_index = ntohl (sw_if_index);
2102 mp->weight = ntohl (weight);
2109 static void vl_api_sw_bond_interface_details_t_handler
2110 (vl_api_sw_bond_interface_details_t * mp)
2112 vat_main_t *vam = &vat_main;
2115 "%-16s %-12d %-12U %-13U %-14u %-14u",
2116 mp->interface_name, ntohl (mp->sw_if_index),
2117 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2118 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2121 static void vl_api_sw_bond_interface_details_t_handler_json
2122 (vl_api_sw_bond_interface_details_t * mp)
2124 vat_main_t *vam = &vat_main;
2125 vat_json_node_t *node = NULL;
2127 if (VAT_JSON_ARRAY != vam->json_tree.type)
2129 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2130 vat_json_init_array (&vam->json_tree);
2132 node = vat_json_array_add (&vam->json_tree);
2134 vat_json_init_object (node);
2135 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2136 vat_json_object_add_string_copy (node, "interface_name",
2137 mp->interface_name);
2138 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2139 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2140 vat_json_object_add_uint (node, "active_members",
2141 ntohl (mp->active_members));
2142 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2146 api_sw_bond_interface_dump (vat_main_t * vam)
2148 unformat_input_t *i = vam->input;
2149 vl_api_sw_bond_interface_dump_t *mp;
2150 vl_api_control_ping_t *mp_ping;
2152 u32 sw_if_index = ~0;
2154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2156 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2158 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2165 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2166 "interface name", "sw_if_index", "mode", "load balance",
2167 "active members", "members");
2169 /* Get list of bond interfaces */
2170 M (SW_BOND_INTERFACE_DUMP, mp);
2171 mp->sw_if_index = ntohl (sw_if_index);
2174 /* Use a control ping for synchronization */
2175 MPING (CONTROL_PING, mp_ping);
2182 static void vl_api_sw_member_interface_details_t_handler
2183 (vl_api_sw_member_interface_details_t * mp)
2185 vat_main_t *vam = &vat_main;
2188 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2189 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2190 ntohl (mp->weight), mp->is_local_numa);
2193 static void vl_api_sw_member_interface_details_t_handler_json
2194 (vl_api_sw_member_interface_details_t * mp)
2196 vat_main_t *vam = &vat_main;
2197 vat_json_node_t *node = NULL;
2199 if (VAT_JSON_ARRAY != vam->json_tree.type)
2201 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2202 vat_json_init_array (&vam->json_tree);
2204 node = vat_json_array_add (&vam->json_tree);
2206 vat_json_init_object (node);
2207 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2208 vat_json_object_add_string_copy (node, "interface_name",
2209 mp->interface_name);
2210 vat_json_object_add_uint (node, "passive", mp->is_passive);
2211 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2212 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2213 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2217 api_sw_member_interface_dump (vat_main_t * vam)
2219 unformat_input_t *i = vam->input;
2220 vl_api_sw_member_interface_dump_t *mp;
2221 vl_api_control_ping_t *mp_ping;
2222 u32 sw_if_index = ~0;
2223 u8 sw_if_index_set = 0;
2226 /* Parse args required to build the message */
2227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2229 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2230 sw_if_index_set = 1;
2231 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2232 sw_if_index_set = 1;
2237 if (sw_if_index_set == 0)
2239 errmsg ("missing vpp interface name. ");
2244 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2245 "member interface name", "sw_if_index", "passive", "long_timeout",
2246 "weight", "local numa");
2248 /* Get list of bond interfaces */
2249 M (SW_MEMBER_INTERFACE_DUMP, mp);
2250 mp->sw_if_index = ntohl (sw_if_index);
2253 /* Use a control ping for synchronization */
2254 MPING (CONTROL_PING, mp_ping);
2261 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2262 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2264 vat_main_t *vam = &vat_main;
2265 i32 retval = ntohl (mp->retval);
2266 if (vam->async_mode)
2268 vam->async_errors += (retval < 0);
2272 vam->retval = retval;
2273 vam->sw_if_index = ntohl (mp->sw_if_index);
2274 vam->result_ready = 1;
2276 vam->regenerate_interface_table = 1;
2279 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2280 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2282 vat_main_t *vam = &vat_main;
2283 vat_json_node_t node;
2285 vat_json_init_object (&node);
2286 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2287 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2288 ntohl (mp->sw_if_index));
2290 vat_json_print (vam->ofp, &node);
2291 vat_json_free (&node);
2293 vam->retval = ntohl (mp->retval);
2294 vam->result_ready = 1;
2297 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2298 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2300 vat_main_t *vam = &vat_main;
2301 i32 retval = ntohl (mp->retval);
2302 if (vam->async_mode)
2304 vam->async_errors += (retval < 0);
2308 vam->retval = retval;
2309 vam->sw_if_index = ntohl (mp->sw_if_index);
2310 vam->result_ready = 1;
2312 vam->regenerate_interface_table = 1;
2315 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2316 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2318 vat_main_t *vam = &vat_main;
2319 vat_json_node_t node;
2321 vat_json_init_object (&node);
2322 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2323 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2325 vat_json_print (vam->ofp, &node);
2326 vat_json_free (&node);
2328 vam->retval = ntohl (mp->retval);
2329 vam->result_ready = 1;
2332 static void vl_api_vxlan_offload_rx_reply_t_handler
2333 (vl_api_vxlan_offload_rx_reply_t * mp)
2335 vat_main_t *vam = &vat_main;
2336 i32 retval = ntohl (mp->retval);
2337 if (vam->async_mode)
2339 vam->async_errors += (retval < 0);
2343 vam->retval = retval;
2344 vam->result_ready = 1;
2348 static void vl_api_vxlan_offload_rx_reply_t_handler_json
2349 (vl_api_vxlan_offload_rx_reply_t * mp)
2351 vat_main_t *vam = &vat_main;
2352 vat_json_node_t node;
2354 vat_json_init_object (&node);
2355 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2357 vat_json_print (vam->ofp, &node);
2358 vat_json_free (&node);
2360 vam->retval = ntohl (mp->retval);
2361 vam->result_ready = 1;
2364 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2365 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2367 vat_main_t *vam = &vat_main;
2368 i32 retval = ntohl (mp->retval);
2369 if (vam->async_mode)
2371 vam->async_errors += (retval < 0);
2375 vam->retval = retval;
2376 vam->sw_if_index = ntohl (mp->sw_if_index);
2377 vam->result_ready = 1;
2379 vam->regenerate_interface_table = 1;
2382 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2383 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2385 vat_main_t *vam = &vat_main;
2386 vat_json_node_t node;
2388 vat_json_init_object (&node);
2389 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2390 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2392 vat_json_print (vam->ofp, &node);
2393 vat_json_free (&node);
2395 vam->retval = ntohl (mp->retval);
2396 vam->result_ready = 1;
2399 static void vl_api_create_vhost_user_if_reply_t_handler
2400 (vl_api_create_vhost_user_if_reply_t * mp)
2402 vat_main_t *vam = &vat_main;
2403 i32 retval = ntohl (mp->retval);
2404 if (vam->async_mode)
2406 vam->async_errors += (retval < 0);
2410 vam->retval = retval;
2411 vam->sw_if_index = ntohl (mp->sw_if_index);
2412 vam->result_ready = 1;
2414 vam->regenerate_interface_table = 1;
2417 static void vl_api_create_vhost_user_if_reply_t_handler_json
2418 (vl_api_create_vhost_user_if_reply_t * mp)
2420 vat_main_t *vam = &vat_main;
2421 vat_json_node_t node;
2423 vat_json_init_object (&node);
2424 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2425 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2427 vat_json_print (vam->ofp, &node);
2428 vat_json_free (&node);
2430 vam->retval = ntohl (mp->retval);
2431 vam->result_ready = 1;
2434 static void vl_api_ip_address_details_t_handler
2435 (vl_api_ip_address_details_t * mp)
2437 vat_main_t *vam = &vat_main;
2438 static ip_address_details_t empty_ip_address_details = { {0} };
2439 ip_address_details_t *address = NULL;
2440 ip_details_t *current_ip_details = NULL;
2441 ip_details_t *details = NULL;
2443 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2445 if (!details || vam->current_sw_if_index >= vec_len (details)
2446 || !details[vam->current_sw_if_index].present)
2448 errmsg ("ip address details arrived but not stored");
2449 errmsg ("ip_dump should be called first");
2453 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2455 #define addresses (current_ip_details->addr)
2457 vec_validate_init_empty (addresses, vec_len (addresses),
2458 empty_ip_address_details);
2460 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2462 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2463 address->prefix_length = mp->prefix.len;
2467 static void vl_api_ip_address_details_t_handler_json
2468 (vl_api_ip_address_details_t * mp)
2470 vat_main_t *vam = &vat_main;
2471 vat_json_node_t *node = NULL;
2473 if (VAT_JSON_ARRAY != vam->json_tree.type)
2475 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2476 vat_json_init_array (&vam->json_tree);
2478 node = vat_json_array_add (&vam->json_tree);
2480 vat_json_init_object (node);
2481 vat_json_object_add_prefix (node, &mp->prefix);
2485 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2487 vat_main_t *vam = &vat_main;
2488 static ip_details_t empty_ip_details = { 0 };
2489 ip_details_t *ip = NULL;
2490 u32 sw_if_index = ~0;
2492 sw_if_index = ntohl (mp->sw_if_index);
2494 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2495 sw_if_index, empty_ip_details);
2497 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2504 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2506 vat_main_t *vam = &vat_main;
2508 if (VAT_JSON_ARRAY != vam->json_tree.type)
2510 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2511 vat_json_init_array (&vam->json_tree);
2513 vat_json_array_add_uint (&vam->json_tree,
2514 clib_net_to_host_u32 (mp->sw_if_index));
2517 static void vl_api_get_first_msg_id_reply_t_handler
2518 (vl_api_get_first_msg_id_reply_t * mp)
2520 vat_main_t *vam = &vat_main;
2521 i32 retval = ntohl (mp->retval);
2523 if (vam->async_mode)
2525 vam->async_errors += (retval < 0);
2529 vam->retval = retval;
2530 vam->result_ready = 1;
2534 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2538 static void vl_api_get_first_msg_id_reply_t_handler_json
2539 (vl_api_get_first_msg_id_reply_t * mp)
2541 vat_main_t *vam = &vat_main;
2542 vat_json_node_t node;
2544 vat_json_init_object (&node);
2545 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2546 vat_json_object_add_uint (&node, "first_msg_id",
2547 (uint) ntohs (mp->first_msg_id));
2549 vat_json_print (vam->ofp, &node);
2550 vat_json_free (&node);
2552 vam->retval = ntohl (mp->retval);
2553 vam->result_ready = 1;
2556 static void vl_api_get_node_graph_reply_t_handler
2557 (vl_api_get_node_graph_reply_t * mp)
2559 vat_main_t *vam = &vat_main;
2560 i32 retval = ntohl (mp->retval);
2561 u8 *pvt_copy, *reply;
2566 if (vam->async_mode)
2568 vam->async_errors += (retval < 0);
2572 vam->retval = retval;
2573 vam->result_ready = 1;
2576 /* "Should never happen..." */
2580 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2581 pvt_copy = vec_dup (reply);
2583 /* Toss the shared-memory original... */
2584 oldheap = vl_msg_push_heap ();
2588 vl_msg_pop_heap (oldheap);
2590 if (vam->graph_nodes)
2592 hash_free (vam->graph_node_index_by_name);
2594 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2596 node = vam->graph_nodes[0][i];
2597 vec_free (node->name);
2598 vec_free (node->next_nodes);
2601 vec_free (vam->graph_nodes[0]);
2602 vec_free (vam->graph_nodes);
2605 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2606 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2607 vec_free (pvt_copy);
2609 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2611 node = vam->graph_nodes[0][i];
2612 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2616 static void vl_api_get_node_graph_reply_t_handler_json
2617 (vl_api_get_node_graph_reply_t * mp)
2619 vat_main_t *vam = &vat_main;
2621 vat_json_node_t node;
2624 /* $$$$ make this real? */
2625 vat_json_init_object (&node);
2626 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2627 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2629 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2631 /* Toss the shared-memory original... */
2632 oldheap = vl_msg_push_heap ();
2636 vl_msg_pop_heap (oldheap);
2638 vat_json_print (vam->ofp, &node);
2639 vat_json_free (&node);
2641 vam->retval = ntohl (mp->retval);
2642 vam->result_ready = 1;
2646 format_policer_type (u8 * s, va_list * va)
2648 u32 i = va_arg (*va, u32);
2650 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2651 s = format (s, "1r2c");
2652 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2653 s = format (s, "1r3c");
2654 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2655 s = format (s, "2r3c-2698");
2656 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2657 s = format (s, "2r3c-4115");
2658 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2659 s = format (s, "2r3c-mef5cf1");
2661 s = format (s, "ILLEGAL");
2666 format_policer_rate_type (u8 * s, va_list * va)
2668 u32 i = va_arg (*va, u32);
2670 if (i == SSE2_QOS_RATE_KBPS)
2671 s = format (s, "kbps");
2672 else if (i == SSE2_QOS_RATE_PPS)
2673 s = format (s, "pps");
2675 s = format (s, "ILLEGAL");
2680 format_policer_round_type (u8 * s, va_list * va)
2682 u32 i = va_arg (*va, u32);
2684 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2685 s = format (s, "closest");
2686 else if (i == SSE2_QOS_ROUND_TO_UP)
2687 s = format (s, "up");
2688 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2689 s = format (s, "down");
2691 s = format (s, "ILLEGAL");
2696 format_policer_action_type (u8 * s, va_list * va)
2698 u32 i = va_arg (*va, u32);
2700 if (i == SSE2_QOS_ACTION_DROP)
2701 s = format (s, "drop");
2702 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2703 s = format (s, "transmit");
2704 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2705 s = format (s, "mark-and-transmit");
2707 s = format (s, "ILLEGAL");
2712 format_dscp (u8 * s, va_list * va)
2714 u32 i = va_arg (*va, u32);
2719 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2723 return format (s, "ILLEGAL");
2725 s = format (s, "%s", t);
2730 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2732 vat_main_t *vam = &vat_main;
2733 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2735 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2736 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2738 conform_dscp_str = format (0, "");
2740 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2741 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2743 exceed_dscp_str = format (0, "");
2745 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2746 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2748 violate_dscp_str = format (0, "");
2750 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2751 "rate type %U, round type %U, %s rate, %s color-aware, "
2752 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2753 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2754 "conform action %U%s, exceed action %U%s, violate action %U%s",
2756 format_policer_type, mp->type,
2759 clib_net_to_host_u64 (mp->cb),
2760 clib_net_to_host_u64 (mp->eb),
2761 format_policer_rate_type, mp->rate_type,
2762 format_policer_round_type, mp->round_type,
2763 mp->single_rate ? "single" : "dual",
2764 mp->color_aware ? "is" : "not",
2765 ntohl (mp->cir_tokens_per_period),
2766 ntohl (mp->pir_tokens_per_period),
2768 ntohl (mp->current_limit),
2769 ntohl (mp->current_bucket),
2770 ntohl (mp->extended_limit),
2771 ntohl (mp->extended_bucket),
2772 clib_net_to_host_u64 (mp->last_update_time),
2773 format_policer_action_type, mp->conform_action.type,
2775 format_policer_action_type, mp->exceed_action.type,
2777 format_policer_action_type, mp->violate_action.type,
2780 vec_free (conform_dscp_str);
2781 vec_free (exceed_dscp_str);
2782 vec_free (violate_dscp_str);
2785 static void vl_api_policer_details_t_handler_json
2786 (vl_api_policer_details_t * mp)
2788 vat_main_t *vam = &vat_main;
2789 vat_json_node_t *node;
2790 u8 *rate_type_str, *round_type_str, *type_str;
2791 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2793 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2795 format (0, "%U", format_policer_round_type, mp->round_type);
2796 type_str = format (0, "%U", format_policer_type, mp->type);
2797 conform_action_str = format (0, "%U", format_policer_action_type,
2798 mp->conform_action.type);
2799 exceed_action_str = format (0, "%U", format_policer_action_type,
2800 mp->exceed_action.type);
2801 violate_action_str = format (0, "%U", format_policer_action_type,
2802 mp->violate_action.type);
2804 if (VAT_JSON_ARRAY != vam->json_tree.type)
2806 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2807 vat_json_init_array (&vam->json_tree);
2809 node = vat_json_array_add (&vam->json_tree);
2811 vat_json_init_object (node);
2812 vat_json_object_add_string_copy (node, "name", mp->name);
2813 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2814 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2815 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2816 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2817 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2818 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2819 vat_json_object_add_string_copy (node, "type", type_str);
2820 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2821 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2822 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2823 vat_json_object_add_uint (node, "cir_tokens_per_period",
2824 ntohl (mp->cir_tokens_per_period));
2825 vat_json_object_add_uint (node, "eir_tokens_per_period",
2826 ntohl (mp->pir_tokens_per_period));
2827 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2828 vat_json_object_add_uint (node, "current_bucket",
2829 ntohl (mp->current_bucket));
2830 vat_json_object_add_uint (node, "extended_limit",
2831 ntohl (mp->extended_limit));
2832 vat_json_object_add_uint (node, "extended_bucket",
2833 ntohl (mp->extended_bucket));
2834 vat_json_object_add_uint (node, "last_update_time",
2835 ntohl (mp->last_update_time));
2836 vat_json_object_add_string_copy (node, "conform_action",
2837 conform_action_str);
2838 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2840 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2841 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2842 vec_free (dscp_str);
2844 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2845 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2847 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2848 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2849 vec_free (dscp_str);
2851 vat_json_object_add_string_copy (node, "violate_action",
2852 violate_action_str);
2853 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2855 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2856 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2857 vec_free (dscp_str);
2860 vec_free (rate_type_str);
2861 vec_free (round_type_str);
2862 vec_free (type_str);
2863 vec_free (conform_action_str);
2864 vec_free (exceed_action_str);
2865 vec_free (violate_action_str);
2869 vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
2872 vat_main_t *vam = &vat_main;
2873 int i, count = ntohl (mp->count);
2876 print (vam->ofp, "classify table ids (%d) : ", count);
2877 for (i = 0; i < count; i++)
2879 print (vam->ofp, "%d", ntohl (mp->ids[i]));
2880 print (vam->ofp, (i < count - 1) ? "," : "");
2882 vam->retval = ntohl (mp->retval);
2883 vam->result_ready = 1;
2887 vl_api_classify_table_ids_reply_t_handler_json
2888 (vl_api_classify_table_ids_reply_t * mp)
2890 vat_main_t *vam = &vat_main;
2891 int i, count = ntohl (mp->count);
2895 vat_json_node_t node;
2897 vat_json_init_object (&node);
2898 for (i = 0; i < count; i++)
2900 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
2902 vat_json_print (vam->ofp, &node);
2903 vat_json_free (&node);
2905 vam->retval = ntohl (mp->retval);
2906 vam->result_ready = 1;
2910 vl_api_classify_table_by_interface_reply_t_handler
2911 (vl_api_classify_table_by_interface_reply_t * mp)
2913 vat_main_t *vam = &vat_main;
2916 table_id = ntohl (mp->l2_table_id);
2918 print (vam->ofp, "l2 table id : %d", table_id);
2920 print (vam->ofp, "l2 table id : No input ACL tables configured");
2921 table_id = ntohl (mp->ip4_table_id);
2923 print (vam->ofp, "ip4 table id : %d", table_id);
2925 print (vam->ofp, "ip4 table id : No input ACL tables configured");
2926 table_id = ntohl (mp->ip6_table_id);
2928 print (vam->ofp, "ip6 table id : %d", table_id);
2930 print (vam->ofp, "ip6 table id : No input ACL tables configured");
2931 vam->retval = ntohl (mp->retval);
2932 vam->result_ready = 1;
2936 vl_api_classify_table_by_interface_reply_t_handler_json
2937 (vl_api_classify_table_by_interface_reply_t * mp)
2939 vat_main_t *vam = &vat_main;
2940 vat_json_node_t node;
2942 vat_json_init_object (&node);
2944 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
2945 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
2946 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
2948 vat_json_print (vam->ofp, &node);
2949 vat_json_free (&node);
2951 vam->retval = ntohl (mp->retval);
2952 vam->result_ready = 1;
2955 static void vl_api_policer_add_del_reply_t_handler
2956 (vl_api_policer_add_del_reply_t * mp)
2958 vat_main_t *vam = &vat_main;
2959 i32 retval = ntohl (mp->retval);
2960 if (vam->async_mode)
2962 vam->async_errors += (retval < 0);
2966 vam->retval = retval;
2967 vam->result_ready = 1;
2968 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2970 * Note: this is just barely thread-safe, depends on
2971 * the main thread spinning waiting for an answer...
2973 errmsg ("policer index %d", ntohl (mp->policer_index));
2977 static void vl_api_policer_add_del_reply_t_handler_json
2978 (vl_api_policer_add_del_reply_t * mp)
2980 vat_main_t *vam = &vat_main;
2981 vat_json_node_t node;
2983 vat_json_init_object (&node);
2984 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2985 vat_json_object_add_uint (&node, "policer_index",
2986 ntohl (mp->policer_index));
2988 vat_json_print (vam->ofp, &node);
2989 vat_json_free (&node);
2991 vam->retval = ntohl (mp->retval);
2992 vam->result_ready = 1;
2995 /* Format hex dump. */
2997 format_hex_bytes (u8 * s, va_list * va)
2999 u8 *bytes = va_arg (*va, u8 *);
3000 int n_bytes = va_arg (*va, int);
3003 /* Print short or long form depending on byte count. */
3004 uword short_form = n_bytes <= 32;
3005 u32 indent = format_get_indent (s);
3010 for (i = 0; i < n_bytes; i++)
3012 if (!short_form && (i % 32) == 0)
3013 s = format (s, "%08x: ", i);
3014 s = format (s, "%02x", bytes[i]);
3015 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3016 s = format (s, "\n%U", format_white_space, indent);
3023 vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3026 vat_main_t *vam = &vat_main;
3027 i32 retval = ntohl (mp->retval);
3030 print (vam->ofp, "classify table info :");
3031 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
3032 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3033 ntohl (mp->miss_next_index));
3034 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
3035 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3036 ntohl (mp->match_n_vectors));
3037 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
3038 ntohl (mp->mask_length));
3040 vam->retval = retval;
3041 vam->result_ready = 1;
3045 vl_api_classify_table_info_reply_t_handler_json
3046 (vl_api_classify_table_info_reply_t * mp)
3048 vat_main_t *vam = &vat_main;
3049 vat_json_node_t node;
3051 i32 retval = ntohl (mp->retval);
3054 vat_json_init_object (&node);
3056 vat_json_object_add_int (&node, "sessions",
3057 ntohl (mp->active_sessions));
3058 vat_json_object_add_int (&node, "nexttbl",
3059 ntohl (mp->next_table_index));
3060 vat_json_object_add_int (&node, "nextnode",
3061 ntohl (mp->miss_next_index));
3062 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3063 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3064 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3065 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3066 ntohl (mp->mask_length), 0);
3067 vat_json_object_add_string_copy (&node, "mask", s);
3069 vat_json_print (vam->ofp, &node);
3070 vat_json_free (&node);
3072 vam->retval = ntohl (mp->retval);
3073 vam->result_ready = 1;
3077 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3080 vat_main_t *vam = &vat_main;
3082 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3083 ntohl (mp->hit_next_index), ntohl (mp->advance),
3084 ntohl (mp->opaque_index));
3085 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
3086 ntohl (mp->match_length));
3090 vl_api_classify_session_details_t_handler_json
3091 (vl_api_classify_session_details_t * mp)
3093 vat_main_t *vam = &vat_main;
3094 vat_json_node_t *node = NULL;
3096 if (VAT_JSON_ARRAY != vam->json_tree.type)
3098 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3099 vat_json_init_array (&vam->json_tree);
3101 node = vat_json_array_add (&vam->json_tree);
3103 vat_json_init_object (node);
3104 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3105 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3106 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3108 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3110 vat_json_object_add_string_copy (node, "match", s);
3113 static void vl_api_pg_create_interface_reply_t_handler
3114 (vl_api_pg_create_interface_reply_t * mp)
3116 vat_main_t *vam = &vat_main;
3118 vam->retval = ntohl (mp->retval);
3119 vam->result_ready = 1;
3122 static void vl_api_pg_create_interface_reply_t_handler_json
3123 (vl_api_pg_create_interface_reply_t * mp)
3125 vat_main_t *vam = &vat_main;
3126 vat_json_node_t node;
3128 i32 retval = ntohl (mp->retval);
3131 vat_json_init_object (&node);
3133 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
3135 vat_json_print (vam->ofp, &node);
3136 vat_json_free (&node);
3138 vam->retval = ntohl (mp->retval);
3139 vam->result_ready = 1;
3142 static void vl_api_policer_classify_details_t_handler
3143 (vl_api_policer_classify_details_t * mp)
3145 vat_main_t *vam = &vat_main;
3147 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3148 ntohl (mp->table_index));
3151 static void vl_api_policer_classify_details_t_handler_json
3152 (vl_api_policer_classify_details_t * mp)
3154 vat_main_t *vam = &vat_main;
3155 vat_json_node_t *node;
3157 if (VAT_JSON_ARRAY != vam->json_tree.type)
3159 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3160 vat_json_init_array (&vam->json_tree);
3162 node = vat_json_array_add (&vam->json_tree);
3164 vat_json_init_object (node);
3165 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3166 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3169 static void vl_api_flow_classify_details_t_handler
3170 (vl_api_flow_classify_details_t * mp)
3172 vat_main_t *vam = &vat_main;
3174 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3175 ntohl (mp->table_index));
3178 static void vl_api_flow_classify_details_t_handler_json
3179 (vl_api_flow_classify_details_t * mp)
3181 vat_main_t *vam = &vat_main;
3182 vat_json_node_t *node;
3184 if (VAT_JSON_ARRAY != vam->json_tree.type)
3186 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3187 vat_json_init_array (&vam->json_tree);
3189 node = vat_json_array_add (&vam->json_tree);
3191 vat_json_init_object (node);
3192 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3193 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3197 * Generate boilerplate reply handlers, which
3198 * dig the return value out of the xxx_reply_t API message,
3199 * stick it into vam->retval, and set vam->result_ready
3201 * Could also do this by pointing N message decode slots at
3202 * a single function, but that could break in subtle ways.
3205 #define foreach_standard_reply_retval_handler \
3206 _(sw_interface_set_flags_reply) \
3207 _(sw_interface_add_del_address_reply) \
3208 _(sw_interface_set_rx_mode_reply) \
3209 _(sw_interface_set_rx_placement_reply) \
3210 _(sw_interface_set_table_reply) \
3211 _(sw_interface_set_mpls_enable_reply) \
3212 _(sw_interface_set_vpath_reply) \
3213 _(sw_interface_set_vxlan_bypass_reply) \
3214 _(sw_interface_set_vxlan_gpe_bypass_reply) \
3215 _(sw_interface_set_l2_bridge_reply) \
3216 _(sw_interface_set_bond_weight_reply) \
3217 _(bridge_domain_add_del_reply) \
3218 _(sw_interface_set_l2_xconnect_reply) \
3219 _(l2fib_add_del_reply) \
3220 _(l2fib_flush_int_reply) \
3221 _(l2fib_flush_bd_reply) \
3222 _(ip_route_add_del_reply) \
3223 _(ip_table_add_del_reply) \
3224 _(ip_table_replace_begin_reply) \
3225 _(ip_table_flush_reply) \
3226 _(ip_table_replace_end_reply) \
3227 _(ip_mroute_add_del_reply) \
3228 _(mpls_route_add_del_reply) \
3229 _(mpls_table_add_del_reply) \
3230 _(mpls_ip_bind_unbind_reply) \
3231 _(bier_route_add_del_reply) \
3232 _(bier_table_add_del_reply) \
3233 _(sw_interface_set_unnumbered_reply) \
3234 _(set_ip_flow_hash_reply) \
3235 _(sw_interface_ip6_enable_disable_reply) \
3236 _(l2_patch_add_del_reply) \
3237 _(sr_mpls_policy_add_reply) \
3238 _(sr_mpls_policy_mod_reply) \
3239 _(sr_mpls_policy_del_reply) \
3240 _(sr_policy_add_reply) \
3241 _(sr_policy_mod_reply) \
3242 _(sr_policy_del_reply) \
3243 _(sr_localsid_add_del_reply) \
3244 _(sr_steering_add_del_reply) \
3245 _(classify_add_del_session_reply) \
3246 _(classify_set_interface_ip_table_reply) \
3247 _(classify_set_interface_l2_tables_reply) \
3248 _(l2_fib_clear_table_reply) \
3249 _(l2_interface_efp_filter_reply) \
3250 _(l2_interface_vlan_tag_rewrite_reply) \
3251 _(modify_vhost_user_if_reply) \
3252 _(delete_vhost_user_if_reply) \
3253 _(want_l2_macs_events_reply) \
3254 _(input_acl_set_interface_reply) \
3255 _(ipsec_spd_add_del_reply) \
3256 _(ipsec_interface_add_del_spd_reply) \
3257 _(ipsec_spd_entry_add_del_reply) \
3258 _(ipsec_sad_entry_add_del_reply) \
3259 _(ipsec_tunnel_if_add_del_reply) \
3260 _(ipsec_tunnel_if_set_sa_reply) \
3261 _(delete_loopback_reply) \
3262 _(bd_ip_mac_add_del_reply) \
3263 _(bd_ip_mac_flush_reply) \
3264 _(want_interface_events_reply) \
3265 _(cop_interface_enable_disable_reply) \
3266 _(cop_whitelist_enable_disable_reply) \
3267 _(sw_interface_clear_stats_reply) \
3268 _(ioam_enable_reply) \
3269 _(ioam_disable_reply) \
3270 _(af_packet_delete_reply) \
3271 _(policer_classify_set_interface_reply) \
3272 _(set_ipfix_exporter_reply) \
3273 _(set_ipfix_classify_stream_reply) \
3274 _(ipfix_classify_table_add_del_reply) \
3275 _(flow_classify_set_interface_reply) \
3276 _(sw_interface_span_enable_disable_reply) \
3277 _(pg_capture_reply) \
3278 _(pg_enable_disable_reply) \
3279 _(pg_interface_enable_disable_coalesce_reply) \
3280 _(ip_source_and_port_range_check_add_del_reply) \
3281 _(ip_source_and_port_range_check_interface_add_del_reply)\
3282 _(delete_subif_reply) \
3283 _(l2_interface_pbb_tag_rewrite_reply) \
3285 _(feature_enable_disable_reply) \
3286 _(feature_gso_enable_disable_reply) \
3287 _(sw_interface_tag_add_del_reply) \
3288 _(sw_interface_add_del_mac_address_reply) \
3289 _(hw_interface_set_mtu_reply) \
3290 _(p2p_ethernet_add_reply) \
3291 _(p2p_ethernet_del_reply) \
3292 _(tcp_configure_src_addresses_reply) \
3293 _(session_rule_add_del_reply) \
3294 _(ip_container_proxy_add_del_reply) \
3295 _(output_acl_set_interface_reply) \
3296 _(qos_record_enable_disable_reply) \
3300 static void vl_api_##n##_t_handler \
3301 (vl_api_##n##_t * mp) \
3303 vat_main_t * vam = &vat_main; \
3304 i32 retval = ntohl(mp->retval); \
3305 if (vam->async_mode) { \
3306 vam->async_errors += (retval < 0); \
3308 vam->retval = retval; \
3309 vam->result_ready = 1; \
3312 foreach_standard_reply_retval_handler;
3316 static void vl_api_##n##_t_handler_json \
3317 (vl_api_##n##_t * mp) \
3319 vat_main_t * vam = &vat_main; \
3320 vat_json_node_t node; \
3321 vat_json_init_object(&node); \
3322 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3323 vat_json_print(vam->ofp, &node); \
3324 vam->retval = ntohl(mp->retval); \
3325 vam->result_ready = 1; \
3327 foreach_standard_reply_retval_handler;
3331 * Table of message reply handlers, must include boilerplate handlers
3335 #define foreach_vpe_api_reply_msg \
3336 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3337 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3338 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3339 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3340 _(CONTROL_PING_REPLY, control_ping_reply) \
3341 _(CLI_REPLY, cli_reply) \
3342 _(CLI_INBAND_REPLY, cli_inband_reply) \
3343 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3344 sw_interface_add_del_address_reply) \
3345 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3346 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3347 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3348 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3349 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3350 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3351 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3352 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3353 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3354 sw_interface_set_l2_xconnect_reply) \
3355 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3356 sw_interface_set_l2_bridge_reply) \
3357 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3358 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3359 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3360 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3361 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3362 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3363 _(L2_FLAGS_REPLY, l2_flags_reply) \
3364 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3365 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3366 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3367 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3368 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3369 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3370 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3371 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3372 _(BOND_CREATE_REPLY, bond_create_reply) \
3373 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3374 _(BOND_DELETE_REPLY, bond_delete_reply) \
3375 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3376 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3377 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3378 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3379 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3380 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3381 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3382 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3383 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3384 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3385 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3386 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3387 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3388 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3389 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3390 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3391 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3392 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3393 sw_interface_set_unnumbered_reply) \
3394 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3395 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3396 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3397 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3398 sw_interface_ip6_enable_disable_reply) \
3399 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3400 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3401 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3402 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3403 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3404 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3405 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3406 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3407 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3408 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3409 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3410 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3411 classify_set_interface_ip_table_reply) \
3412 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3413 classify_set_interface_l2_tables_reply) \
3414 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3415 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3416 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3417 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3418 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3419 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3420 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3421 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3422 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3423 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3424 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3425 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3426 _(SHOW_VERSION_REPLY, show_version_reply) \
3427 _(SHOW_THREADS_REPLY, show_threads_reply) \
3428 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3429 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3430 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3431 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3432 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3433 _(L2_MACS_EVENT, l2_macs_event) \
3434 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3435 _(IP_ADDRESS_DETAILS, ip_address_details) \
3436 _(IP_DETAILS, ip_details) \
3437 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3438 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3439 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3440 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3441 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3442 _(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
3443 _(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
3444 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3445 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3446 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3447 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3448 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3449 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3450 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3451 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3452 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3453 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3454 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3455 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3456 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3457 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3458 _(AF_PACKET_DETAILS, af_packet_details) \
3459 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3460 _(POLICER_DETAILS, policer_details) \
3461 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3462 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3463 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3464 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3465 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3466 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3467 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3468 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3469 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3470 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3471 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3472 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3473 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3474 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3475 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3476 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3477 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3478 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3479 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3480 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3481 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3482 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3483 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3484 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3485 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3486 ip_source_and_port_range_check_add_del_reply) \
3487 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3488 ip_source_and_port_range_check_interface_add_del_reply) \
3489 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3490 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3491 _(SET_PUNT_REPLY, set_punt_reply) \
3492 _(IP_TABLE_DETAILS, ip_table_details) \
3493 _(IP_ROUTE_DETAILS, ip_route_details) \
3494 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3495 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3496 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3497 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3498 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3499 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3500 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3501 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3502 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3503 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3504 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3505 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3506 _(SESSION_RULES_DETAILS, session_rules_details) \
3507 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3508 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3509 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3510 _(FLOW_ADD_REPLY, flow_add_reply) \
3512 #define foreach_standalone_reply_msg \
3513 _(SW_INTERFACE_EVENT, sw_interface_event)
3521 #define STR_VTR_OP_CASE(op) \
3522 case L2_VTR_ ## op: \
3526 str_vtr_op (u32 vtr_op)
3530 STR_VTR_OP_CASE (DISABLED);
3531 STR_VTR_OP_CASE (PUSH_1);
3532 STR_VTR_OP_CASE (PUSH_2);
3533 STR_VTR_OP_CASE (POP_1);
3534 STR_VTR_OP_CASE (POP_2);
3535 STR_VTR_OP_CASE (TRANSLATE_1_1);
3536 STR_VTR_OP_CASE (TRANSLATE_1_2);
3537 STR_VTR_OP_CASE (TRANSLATE_2_1);
3538 STR_VTR_OP_CASE (TRANSLATE_2_2);
3545 dump_sub_interface_table (vat_main_t * vam)
3547 const sw_interface_subif_t *sub = NULL;
3549 if (vam->json_output)
3552 ("JSON output supported only for VPE API calls and dump_stats_table");
3557 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3558 "Interface", "sw_if_index",
3559 "sub id", "dot1ad", "tags", "outer id",
3560 "inner id", "exact", "default", "outer any", "inner any");
3562 vec_foreach (sub, vam->sw_if_subif_table)
3565 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3566 sub->interface_name,
3568 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3569 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3570 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3571 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3572 if (sub->vtr_op != L2_VTR_DISABLED)
3575 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3576 "tag1: %d tag2: %d ]",
3577 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3578 sub->vtr_tag1, sub->vtr_tag2);
3586 name_sort_cmp (void *a1, void *a2)
3588 name_sort_t *n1 = a1;
3589 name_sort_t *n2 = a2;
3591 return strcmp ((char *) n1->name, (char *) n2->name);
3595 dump_interface_table (vat_main_t * vam)
3598 name_sort_t *nses = 0, *ns;
3600 if (vam->json_output)
3603 ("JSON output supported only for VPE API calls and dump_stats_table");
3608 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3610 vec_add2 (nses, ns, 1);
3611 ns->name = (u8 *)(p->key);
3612 ns->value = (u32) p->value[0];
3616 vec_sort_with_function (nses, name_sort_cmp);
3618 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3619 vec_foreach (ns, nses)
3621 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3628 dump_ip_table (vat_main_t * vam, int is_ipv6)
3630 const ip_details_t *det = NULL;
3631 const ip_address_details_t *address = NULL;
3634 print (vam->ofp, "%-12s", "sw_if_index");
3636 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3643 print (vam->ofp, "%-12d", i);
3644 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3649 vec_foreach (address, det->addr)
3653 is_ipv6 ? format_ip6_address : format_ip4_address,
3654 address->ip, address->prefix_length);
3662 dump_ipv4_table (vat_main_t * vam)
3664 if (vam->json_output)
3667 ("JSON output supported only for VPE API calls and dump_stats_table");
3671 return dump_ip_table (vam, 0);
3675 dump_ipv6_table (vat_main_t * vam)
3677 if (vam->json_output)
3680 ("JSON output supported only for VPE API calls and dump_stats_table");
3684 return dump_ip_table (vam, 1);
3688 * Pass CLI buffers directly in the CLI_INBAND API message,
3689 * instead of an additional shared memory area.
3692 exec_inband (vat_main_t * vam)
3694 vl_api_cli_inband_t *mp;
3695 unformat_input_t *i = vam->input;
3698 if (vec_len (i->buffer) == 0)
3701 if (vam->exec_mode == 0 && unformat (i, "mode"))
3706 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3713 * In order for the CLI command to work, it
3714 * must be a vector ending in \n, not a C-string ending
3717 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3718 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3722 /* json responses may or may not include a useful reply... */
3723 if (vec_len (vam->cmd_reply))
3724 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3729 exec (vat_main_t * vam)
3731 return exec_inband (vam);
3735 api_create_loopback (vat_main_t * vam)
3737 unformat_input_t *i = vam->input;
3738 vl_api_create_loopback_t *mp;
3739 vl_api_create_loopback_instance_t *mp_lbi;
3742 u8 is_specified = 0;
3743 u32 user_instance = 0;
3746 clib_memset (mac_address, 0, sizeof (mac_address));
3748 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3750 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3752 if (unformat (i, "instance %d", &user_instance))
3760 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3761 mp_lbi->is_specified = is_specified;
3763 mp_lbi->user_instance = htonl (user_instance);
3765 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3770 /* Construct the API message */
3771 M (CREATE_LOOPBACK, mp);
3773 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3782 api_delete_loopback (vat_main_t * vam)
3784 unformat_input_t *i = vam->input;
3785 vl_api_delete_loopback_t *mp;
3786 u32 sw_if_index = ~0;
3789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3791 if (unformat (i, "sw_if_index %d", &sw_if_index))
3797 if (sw_if_index == ~0)
3799 errmsg ("missing sw_if_index");
3803 /* Construct the API message */
3804 M (DELETE_LOOPBACK, mp);
3805 mp->sw_if_index = ntohl (sw_if_index);
3813 api_want_interface_events (vat_main_t * vam)
3815 unformat_input_t *i = vam->input;
3816 vl_api_want_interface_events_t *mp;
3820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3822 if (unformat (i, "enable"))
3824 else if (unformat (i, "disable"))
3832 errmsg ("missing enable|disable");
3836 M (WANT_INTERFACE_EVENTS, mp);
3837 mp->enable_disable = enable;
3839 vam->interface_event_display = enable;
3847 /* Note: non-static, called once to set up the initial intfc table */
3849 api_sw_interface_dump (vat_main_t * vam)
3851 vl_api_sw_interface_dump_t *mp;
3852 vl_api_control_ping_t *mp_ping;
3854 name_sort_t *nses = 0, *ns;
3855 sw_interface_subif_t *sub = NULL;
3858 /* Toss the old name table */
3860 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3862 vec_add2 (nses, ns, 1);
3863 ns->name = (u8 *)(p->key);
3864 ns->value = (u32) p->value[0];
3868 hash_free (vam->sw_if_index_by_interface_name);
3870 vec_foreach (ns, nses) vec_free (ns->name);
3874 vec_foreach (sub, vam->sw_if_subif_table)
3876 vec_free (sub->interface_name);
3878 vec_free (vam->sw_if_subif_table);
3880 /* recreate the interface name hash table */
3881 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3884 * Ask for all interface names. Otherwise, the epic catalog of
3885 * name filters becomes ridiculously long, and vat ends up needing
3886 * to be taught about new interface types.
3888 M (SW_INTERFACE_DUMP, mp);
3891 /* Use a control ping for synchronization */
3892 MPING (CONTROL_PING, mp_ping);
3900 api_sw_interface_set_flags (vat_main_t * vam)
3902 unformat_input_t *i = vam->input;
3903 vl_api_sw_interface_set_flags_t *mp;
3905 u8 sw_if_index_set = 0;
3909 /* Parse args required to build the message */
3910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3912 if (unformat (i, "admin-up"))
3914 else if (unformat (i, "admin-down"))
3917 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3918 sw_if_index_set = 1;
3919 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3920 sw_if_index_set = 1;
3925 if (sw_if_index_set == 0)
3927 errmsg ("missing interface name or sw_if_index");
3931 /* Construct the API message */
3932 M (SW_INTERFACE_SET_FLAGS, mp);
3933 mp->sw_if_index = ntohl (sw_if_index);
3934 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3939 /* Wait for a reply, return the good/bad news... */
3945 api_sw_interface_set_rx_mode (vat_main_t * vam)
3947 unformat_input_t *i = vam->input;
3948 vl_api_sw_interface_set_rx_mode_t *mp;
3950 u8 sw_if_index_set = 0;
3952 u8 queue_id_valid = 0;
3954 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3956 /* Parse args required to build the message */
3957 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3959 if (unformat (i, "queue %d", &queue_id))
3961 else if (unformat (i, "polling"))
3962 mode = VNET_HW_IF_RX_MODE_POLLING;
3963 else if (unformat (i, "interrupt"))
3964 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3965 else if (unformat (i, "adaptive"))
3966 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3968 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3969 sw_if_index_set = 1;
3970 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3971 sw_if_index_set = 1;
3976 if (sw_if_index_set == 0)
3978 errmsg ("missing interface name or sw_if_index");
3981 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3983 errmsg ("missing rx-mode");
3987 /* Construct the API message */
3988 M (SW_INTERFACE_SET_RX_MODE, mp);
3989 mp->sw_if_index = ntohl (sw_if_index);
3990 mp->mode = (vl_api_rx_mode_t) mode;
3991 mp->queue_id_valid = queue_id_valid;
3992 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3997 /* Wait for a reply, return the good/bad news... */
4003 api_sw_interface_set_rx_placement (vat_main_t * vam)
4005 unformat_input_t *i = vam->input;
4006 vl_api_sw_interface_set_rx_placement_t *mp;
4008 u8 sw_if_index_set = 0;
4011 u32 queue_id, thread_index;
4013 /* Parse args required to build the message */
4014 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4016 if (unformat (i, "queue %d", &queue_id))
4018 else if (unformat (i, "main"))
4020 else if (unformat (i, "worker %d", &thread_index))
4023 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4024 sw_if_index_set = 1;
4025 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4026 sw_if_index_set = 1;
4031 if (sw_if_index_set == 0)
4033 errmsg ("missing interface name or sw_if_index");
4039 /* Construct the API message */
4040 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4041 mp->sw_if_index = ntohl (sw_if_index);
4042 mp->worker_id = ntohl (thread_index);
4043 mp->queue_id = ntohl (queue_id);
4044 mp->is_main = is_main;
4048 /* Wait for a reply, return the good/bad news... */
4053 static void vl_api_sw_interface_rx_placement_details_t_handler
4054 (vl_api_sw_interface_rx_placement_details_t * mp)
4056 vat_main_t *vam = &vat_main;
4057 u32 worker_id = ntohl (mp->worker_id);
4060 "\n%-11d %-11s %-6d %-5d %-9s",
4061 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4062 worker_id, ntohl (mp->queue_id),
4064 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4067 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4068 (vl_api_sw_interface_rx_placement_details_t * mp)
4070 vat_main_t *vam = &vat_main;
4071 vat_json_node_t *node = NULL;
4073 if (VAT_JSON_ARRAY != vam->json_tree.type)
4075 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4076 vat_json_init_array (&vam->json_tree);
4078 node = vat_json_array_add (&vam->json_tree);
4080 vat_json_init_object (node);
4081 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4082 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4083 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4084 vat_json_object_add_uint (node, "mode", mp->mode);
4088 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4090 unformat_input_t *i = vam->input;
4091 vl_api_sw_interface_rx_placement_dump_t *mp;
4092 vl_api_control_ping_t *mp_ping;
4095 u8 sw_if_index_set = 0;
4097 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4099 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4101 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4108 "\n%-11s %-11s %-6s %-5s %-4s",
4109 "sw_if_index", "main/worker", "thread", "queue", "mode");
4111 /* Dump Interface rx placement */
4112 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4114 if (sw_if_index_set)
4115 mp->sw_if_index = htonl (sw_if_index);
4117 mp->sw_if_index = ~0;
4121 /* Use a control ping for synchronization */
4122 MPING (CONTROL_PING, mp_ping);
4130 api_sw_interface_clear_stats (vat_main_t * vam)
4132 unformat_input_t *i = vam->input;
4133 vl_api_sw_interface_clear_stats_t *mp;
4135 u8 sw_if_index_set = 0;
4138 /* Parse args required to build the message */
4139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4141 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4142 sw_if_index_set = 1;
4143 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4144 sw_if_index_set = 1;
4149 /* Construct the API message */
4150 M (SW_INTERFACE_CLEAR_STATS, mp);
4152 if (sw_if_index_set == 1)
4153 mp->sw_if_index = ntohl (sw_if_index);
4155 mp->sw_if_index = ~0;
4160 /* Wait for a reply, return the good/bad news... */
4166 api_sw_interface_add_del_address (vat_main_t * vam)
4168 unformat_input_t *i = vam->input;
4169 vl_api_sw_interface_add_del_address_t *mp;
4171 u8 sw_if_index_set = 0;
4172 u8 is_add = 1, del_all = 0;
4173 u32 address_length = 0;
4174 u8 v4_address_set = 0;
4175 u8 v6_address_set = 0;
4176 ip4_address_t v4address;
4177 ip6_address_t v6address;
4180 /* Parse args required to build the message */
4181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4183 if (unformat (i, "del-all"))
4185 else if (unformat (i, "del"))
4188 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4189 sw_if_index_set = 1;
4190 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4191 sw_if_index_set = 1;
4192 else if (unformat (i, "%U/%d",
4193 unformat_ip4_address, &v4address, &address_length))
4195 else if (unformat (i, "%U/%d",
4196 unformat_ip6_address, &v6address, &address_length))
4202 if (sw_if_index_set == 0)
4204 errmsg ("missing interface name or sw_if_index");
4207 if (v4_address_set && v6_address_set)
4209 errmsg ("both v4 and v6 addresses set");
4212 if (!v4_address_set && !v6_address_set && !del_all)
4214 errmsg ("no addresses set");
4218 /* Construct the API message */
4219 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4221 mp->sw_if_index = ntohl (sw_if_index);
4222 mp->is_add = is_add;
4223 mp->del_all = del_all;
4226 mp->prefix.address.af = ADDRESS_IP6;
4227 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4231 mp->prefix.address.af = ADDRESS_IP4;
4232 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4234 mp->prefix.len = address_length;
4239 /* Wait for a reply, return good/bad news */
4245 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4247 unformat_input_t *i = vam->input;
4248 vl_api_sw_interface_set_mpls_enable_t *mp;
4250 u8 sw_if_index_set = 0;
4254 /* Parse args required to build the message */
4255 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4257 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4258 sw_if_index_set = 1;
4259 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4260 sw_if_index_set = 1;
4261 else if (unformat (i, "disable"))
4263 else if (unformat (i, "dis"))
4269 if (sw_if_index_set == 0)
4271 errmsg ("missing interface name or sw_if_index");
4275 /* Construct the API message */
4276 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4278 mp->sw_if_index = ntohl (sw_if_index);
4279 mp->enable = enable;
4284 /* Wait for a reply... */
4290 api_sw_interface_set_table (vat_main_t * vam)
4292 unformat_input_t *i = vam->input;
4293 vl_api_sw_interface_set_table_t *mp;
4294 u32 sw_if_index, vrf_id = 0;
4295 u8 sw_if_index_set = 0;
4299 /* Parse args required to build the message */
4300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4302 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4303 sw_if_index_set = 1;
4304 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4305 sw_if_index_set = 1;
4306 else if (unformat (i, "vrf %d", &vrf_id))
4308 else if (unformat (i, "ipv6"))
4314 if (sw_if_index_set == 0)
4316 errmsg ("missing interface name or sw_if_index");
4320 /* Construct the API message */
4321 M (SW_INTERFACE_SET_TABLE, mp);
4323 mp->sw_if_index = ntohl (sw_if_index);
4324 mp->is_ipv6 = is_ipv6;
4325 mp->vrf_id = ntohl (vrf_id);
4330 /* Wait for a reply... */
4335 static void vl_api_sw_interface_get_table_reply_t_handler
4336 (vl_api_sw_interface_get_table_reply_t * mp)
4338 vat_main_t *vam = &vat_main;
4340 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4342 vam->retval = ntohl (mp->retval);
4343 vam->result_ready = 1;
4347 static void vl_api_sw_interface_get_table_reply_t_handler_json
4348 (vl_api_sw_interface_get_table_reply_t * mp)
4350 vat_main_t *vam = &vat_main;
4351 vat_json_node_t node;
4353 vat_json_init_object (&node);
4354 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4355 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4357 vat_json_print (vam->ofp, &node);
4358 vat_json_free (&node);
4360 vam->retval = ntohl (mp->retval);
4361 vam->result_ready = 1;
4365 api_sw_interface_get_table (vat_main_t * vam)
4367 unformat_input_t *i = vam->input;
4368 vl_api_sw_interface_get_table_t *mp;
4370 u8 sw_if_index_set = 0;
4374 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4376 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4377 sw_if_index_set = 1;
4378 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4379 sw_if_index_set = 1;
4380 else if (unformat (i, "ipv6"))
4386 if (sw_if_index_set == 0)
4388 errmsg ("missing interface name or sw_if_index");
4392 M (SW_INTERFACE_GET_TABLE, mp);
4393 mp->sw_if_index = htonl (sw_if_index);
4394 mp->is_ipv6 = is_ipv6;
4402 api_sw_interface_set_vpath (vat_main_t * vam)
4404 unformat_input_t *i = vam->input;
4405 vl_api_sw_interface_set_vpath_t *mp;
4406 u32 sw_if_index = 0;
4407 u8 sw_if_index_set = 0;
4411 /* Parse args required to build the message */
4412 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4414 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4415 sw_if_index_set = 1;
4416 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4417 sw_if_index_set = 1;
4418 else if (unformat (i, "enable"))
4420 else if (unformat (i, "disable"))
4426 if (sw_if_index_set == 0)
4428 errmsg ("missing interface name or sw_if_index");
4432 /* Construct the API message */
4433 M (SW_INTERFACE_SET_VPATH, mp);
4435 mp->sw_if_index = ntohl (sw_if_index);
4436 mp->enable = is_enable;
4441 /* Wait for a reply... */
4447 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4449 unformat_input_t *i = vam->input;
4450 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4451 u32 sw_if_index = 0;
4452 u8 sw_if_index_set = 0;
4457 /* Parse args required to build the message */
4458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4460 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4461 sw_if_index_set = 1;
4462 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4463 sw_if_index_set = 1;
4464 else if (unformat (i, "enable"))
4466 else if (unformat (i, "disable"))
4468 else if (unformat (i, "ip4"))
4470 else if (unformat (i, "ip6"))
4476 if (sw_if_index_set == 0)
4478 errmsg ("missing interface name or sw_if_index");
4482 /* Construct the API message */
4483 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4485 mp->sw_if_index = ntohl (sw_if_index);
4486 mp->enable = is_enable;
4487 mp->is_ipv6 = is_ipv6;
4492 /* Wait for a reply... */
4498 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4500 unformat_input_t *i = vam->input;
4501 vl_api_sw_interface_set_l2_xconnect_t *mp;
4503 u8 rx_sw_if_index_set = 0;
4505 u8 tx_sw_if_index_set = 0;
4509 /* Parse args required to build the message */
4510 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4512 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4513 rx_sw_if_index_set = 1;
4514 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4515 tx_sw_if_index_set = 1;
4516 else if (unformat (i, "rx"))
4518 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4520 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4522 rx_sw_if_index_set = 1;
4527 else if (unformat (i, "tx"))
4529 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4531 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4533 tx_sw_if_index_set = 1;
4538 else if (unformat (i, "enable"))
4540 else if (unformat (i, "disable"))
4546 if (rx_sw_if_index_set == 0)
4548 errmsg ("missing rx interface name or rx_sw_if_index");
4552 if (enable && (tx_sw_if_index_set == 0))
4554 errmsg ("missing tx interface name or tx_sw_if_index");
4558 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4560 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4561 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4562 mp->enable = enable;
4570 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4572 unformat_input_t *i = vam->input;
4573 vl_api_sw_interface_set_l2_bridge_t *mp;
4574 vl_api_l2_port_type_t port_type;
4576 u8 rx_sw_if_index_set = 0;
4583 port_type = L2_API_PORT_TYPE_NORMAL;
4585 /* Parse args required to build the message */
4586 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4588 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4589 rx_sw_if_index_set = 1;
4590 else if (unformat (i, "bd_id %d", &bd_id))
4594 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4595 rx_sw_if_index_set = 1;
4596 else if (unformat (i, "shg %d", &shg))
4598 else if (unformat (i, "bvi"))
4599 port_type = L2_API_PORT_TYPE_BVI;
4600 else if (unformat (i, "uu-fwd"))
4601 port_type = L2_API_PORT_TYPE_UU_FWD;
4602 else if (unformat (i, "enable"))
4604 else if (unformat (i, "disable"))
4610 if (rx_sw_if_index_set == 0)
4612 errmsg ("missing rx interface name or sw_if_index");
4616 if (enable && (bd_id_set == 0))
4618 errmsg ("missing bridge domain");
4622 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4624 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4625 mp->bd_id = ntohl (bd_id);
4627 mp->port_type = ntohl (port_type);
4628 mp->enable = enable;
4636 api_bridge_domain_dump (vat_main_t * vam)
4638 unformat_input_t *i = vam->input;
4639 vl_api_bridge_domain_dump_t *mp;
4640 vl_api_control_ping_t *mp_ping;
4644 /* Parse args required to build the message */
4645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4647 if (unformat (i, "bd_id %d", &bd_id))
4653 M (BRIDGE_DOMAIN_DUMP, mp);
4654 mp->bd_id = ntohl (bd_id);
4657 /* Use a control ping for synchronization */
4658 MPING (CONTROL_PING, mp_ping);
4666 api_bridge_domain_add_del (vat_main_t * vam)
4668 unformat_input_t *i = vam->input;
4669 vl_api_bridge_domain_add_del_t *mp;
4672 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4677 /* Parse args required to build the message */
4678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4680 if (unformat (i, "bd_id %d", &bd_id))
4682 else if (unformat (i, "flood %d", &flood))
4684 else if (unformat (i, "uu-flood %d", &uu_flood))
4686 else if (unformat (i, "forward %d", &forward))
4688 else if (unformat (i, "learn %d", &learn))
4690 else if (unformat (i, "arp-term %d", &arp_term))
4692 else if (unformat (i, "mac-age %d", &mac_age))
4694 else if (unformat (i, "bd-tag %s", &bd_tag))
4696 else if (unformat (i, "del"))
4699 flood = uu_flood = forward = learn = 0;
4707 errmsg ("missing bridge domain");
4714 errmsg ("mac age must be less than 256 ");
4719 if ((bd_tag) && (vec_len (bd_tag) > 63))
4721 errmsg ("bd-tag cannot be longer than 63");
4726 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4728 mp->bd_id = ntohl (bd_id);
4730 mp->uu_flood = uu_flood;
4731 mp->forward = forward;
4733 mp->arp_term = arp_term;
4734 mp->is_add = is_add;
4735 mp->mac_age = (u8) mac_age;
4738 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4739 mp->bd_tag[vec_len (bd_tag)] = 0;
4750 api_l2fib_flush_bd (vat_main_t * vam)
4752 unformat_input_t *i = vam->input;
4753 vl_api_l2fib_flush_bd_t *mp;
4757 /* Parse args required to build the message */
4758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4760 if (unformat (i, "bd_id %d", &bd_id));
4767 errmsg ("missing bridge domain");
4771 M (L2FIB_FLUSH_BD, mp);
4773 mp->bd_id = htonl (bd_id);
4781 api_l2fib_flush_int (vat_main_t * vam)
4783 unformat_input_t *i = vam->input;
4784 vl_api_l2fib_flush_int_t *mp;
4785 u32 sw_if_index = ~0;
4788 /* Parse args required to build the message */
4789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4791 if (unformat (i, "sw_if_index %d", &sw_if_index));
4793 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4798 if (sw_if_index == ~0)
4800 errmsg ("missing interface name or sw_if_index");
4804 M (L2FIB_FLUSH_INT, mp);
4806 mp->sw_if_index = ntohl (sw_if_index);
4814 api_l2fib_add_del (vat_main_t * vam)
4816 unformat_input_t *i = vam->input;
4817 vl_api_l2fib_add_del_t *mp;
4823 u32 sw_if_index = 0;
4824 u8 sw_if_index_set = 0;
4833 /* Parse args required to build the message */
4834 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4836 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4838 else if (unformat (i, "bd_id %d", &bd_id))
4840 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4841 sw_if_index_set = 1;
4842 else if (unformat (i, "sw_if"))
4844 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4847 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4848 sw_if_index_set = 1;
4853 else if (unformat (i, "static"))
4855 else if (unformat (i, "filter"))
4860 else if (unformat (i, "bvi"))
4865 else if (unformat (i, "del"))
4867 else if (unformat (i, "count %d", &count))
4875 errmsg ("missing mac address");
4881 errmsg ("missing bridge domain");
4885 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4887 errmsg ("missing interface name or sw_if_index");
4893 /* Turn on async mode */
4894 vam->async_mode = 1;
4895 vam->async_errors = 0;
4896 before = vat_time_now (vam);
4899 for (j = 0; j < count; j++)
4901 M (L2FIB_ADD_DEL, mp);
4903 clib_memcpy (mp->mac, mac, 6);
4904 mp->bd_id = ntohl (bd_id);
4905 mp->is_add = is_add;
4906 mp->sw_if_index = ntohl (sw_if_index);
4910 mp->static_mac = static_mac;
4911 mp->filter_mac = filter_mac;
4912 mp->bvi_mac = bvi_mac;
4914 increment_mac_address (mac);
4921 vl_api_control_ping_t *mp_ping;
4924 /* Shut off async mode */
4925 vam->async_mode = 0;
4927 MPING (CONTROL_PING, mp_ping);
4930 timeout = vat_time_now (vam) + 1.0;
4931 while (vat_time_now (vam) < timeout)
4932 if (vam->result_ready == 1)
4937 if (vam->retval == -99)
4940 if (vam->async_errors > 0)
4942 errmsg ("%d asynchronous errors", vam->async_errors);
4945 vam->async_errors = 0;
4946 after = vat_time_now (vam);
4948 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4949 count, after - before, count / (after - before));
4955 /* Wait for a reply... */
4959 /* Return the good/bad news */
4960 return (vam->retval);
4964 api_bridge_domain_set_mac_age (vat_main_t * vam)
4966 unformat_input_t *i = vam->input;
4967 vl_api_bridge_domain_set_mac_age_t *mp;
4972 /* Parse args required to build the message */
4973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4975 if (unformat (i, "bd_id %d", &bd_id));
4976 else if (unformat (i, "mac-age %d", &mac_age));
4983 errmsg ("missing bridge domain");
4989 errmsg ("mac age must be less than 256 ");
4993 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4995 mp->bd_id = htonl (bd_id);
4996 mp->mac_age = (u8) mac_age;
5004 api_l2_flags (vat_main_t * vam)
5006 unformat_input_t *i = vam->input;
5007 vl_api_l2_flags_t *mp;
5010 u8 sw_if_index_set = 0;
5014 /* Parse args required to build the message */
5015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5017 if (unformat (i, "sw_if_index %d", &sw_if_index))
5018 sw_if_index_set = 1;
5019 else if (unformat (i, "sw_if"))
5021 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5024 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5025 sw_if_index_set = 1;
5030 else if (unformat (i, "learn"))
5032 else if (unformat (i, "forward"))
5034 else if (unformat (i, "flood"))
5036 else if (unformat (i, "uu-flood"))
5037 flags |= L2_UU_FLOOD;
5038 else if (unformat (i, "arp-term"))
5039 flags |= L2_ARP_TERM;
5040 else if (unformat (i, "off"))
5042 else if (unformat (i, "disable"))
5048 if (sw_if_index_set == 0)
5050 errmsg ("missing interface name or sw_if_index");
5056 mp->sw_if_index = ntohl (sw_if_index);
5057 mp->feature_bitmap = ntohl (flags);
5058 mp->is_set = is_set;
5066 api_bridge_flags (vat_main_t * vam)
5068 unformat_input_t *i = vam->input;
5069 vl_api_bridge_flags_t *mp;
5073 bd_flags_t flags = 0;
5076 /* Parse args required to build the message */
5077 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5079 if (unformat (i, "bd_id %d", &bd_id))
5081 else if (unformat (i, "learn"))
5082 flags |= BRIDGE_API_FLAG_LEARN;
5083 else if (unformat (i, "forward"))
5084 flags |= BRIDGE_API_FLAG_FWD;
5085 else if (unformat (i, "flood"))
5086 flags |= BRIDGE_API_FLAG_FLOOD;
5087 else if (unformat (i, "uu-flood"))
5088 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5089 else if (unformat (i, "arp-term"))
5090 flags |= BRIDGE_API_FLAG_ARP_TERM;
5091 else if (unformat (i, "off"))
5093 else if (unformat (i, "disable"))
5101 errmsg ("missing bridge domain");
5105 M (BRIDGE_FLAGS, mp);
5107 mp->bd_id = ntohl (bd_id);
5108 mp->flags = ntohl (flags);
5109 mp->is_set = is_set;
5117 api_bd_ip_mac_add_del (vat_main_t * vam)
5119 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5120 vl_api_mac_address_t mac = { 0 };
5121 unformat_input_t *i = vam->input;
5122 vl_api_bd_ip_mac_add_del_t *mp;
5131 /* Parse args required to build the message */
5132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5134 if (unformat (i, "bd_id %d", &bd_id))
5138 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5142 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5146 else if (unformat (i, "del"))
5154 errmsg ("missing bridge domain");
5157 else if (ip_set == 0)
5159 errmsg ("missing IP address");
5162 else if (mac_set == 0)
5164 errmsg ("missing MAC address");
5168 M (BD_IP_MAC_ADD_DEL, mp);
5170 mp->entry.bd_id = ntohl (bd_id);
5171 mp->is_add = is_add;
5173 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5174 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5182 api_bd_ip_mac_flush (vat_main_t * vam)
5184 unformat_input_t *i = vam->input;
5185 vl_api_bd_ip_mac_flush_t *mp;
5190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5192 if (unformat (i, "bd_id %d", &bd_id))
5202 errmsg ("missing bridge domain");
5206 M (BD_IP_MAC_FLUSH, mp);
5208 mp->bd_id = ntohl (bd_id);
5215 static void vl_api_bd_ip_mac_details_t_handler
5216 (vl_api_bd_ip_mac_details_t * mp)
5218 vat_main_t *vam = &vat_main;
5222 ntohl (mp->entry.bd_id),
5223 format_vl_api_mac_address, mp->entry.mac,
5224 format_vl_api_address, &mp->entry.ip);
5227 static void vl_api_bd_ip_mac_details_t_handler_json
5228 (vl_api_bd_ip_mac_details_t * mp)
5230 vat_main_t *vam = &vat_main;
5231 vat_json_node_t *node = NULL;
5233 if (VAT_JSON_ARRAY != vam->json_tree.type)
5235 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5236 vat_json_init_array (&vam->json_tree);
5238 node = vat_json_array_add (&vam->json_tree);
5240 vat_json_init_object (node);
5241 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5242 vat_json_object_add_string_copy (node, "mac_address",
5243 format (0, "%U", format_vl_api_mac_address,
5247 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5248 vat_json_object_add_string_copy (node, "ip_address", ip);
5253 api_bd_ip_mac_dump (vat_main_t * vam)
5255 unformat_input_t *i = vam->input;
5256 vl_api_bd_ip_mac_dump_t *mp;
5257 vl_api_control_ping_t *mp_ping;
5262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5264 if (unformat (i, "bd_id %d", &bd_id))
5273 "\n%-5s %-7s %-20s %-30s",
5274 "bd_id", "is_ipv6", "mac_address", "ip_address");
5276 /* Dump Bridge Domain Ip to Mac entries */
5277 M (BD_IP_MAC_DUMP, mp);
5280 mp->bd_id = htonl (bd_id);
5286 /* Use a control ping for synchronization */
5287 MPING (CONTROL_PING, mp_ping);
5295 api_tap_create_v2 (vat_main_t * vam)
5297 unformat_input_t *i = vam->input;
5298 vl_api_tap_create_v2_t *mp;
5302 u32 num_rx_queues = 0;
5303 u8 *host_if_name = 0;
5304 u8 host_if_name_set = 0;
5307 u8 host_mac_addr[6];
5308 u8 host_mac_addr_set = 0;
5309 u8 *host_bridge = 0;
5310 u8 host_bridge_set = 0;
5311 u8 host_ip4_prefix_set = 0;
5312 u8 host_ip6_prefix_set = 0;
5313 ip4_address_t host_ip4_addr;
5314 ip4_address_t host_ip4_gw;
5315 u8 host_ip4_gw_set = 0;
5316 u32 host_ip4_prefix_len = 0;
5317 ip6_address_t host_ip6_addr;
5318 ip6_address_t host_ip6_gw;
5319 u8 host_ip6_gw_set = 0;
5320 u32 host_ip6_prefix_len = 0;
5321 u32 host_mtu_size = 0;
5322 u8 host_mtu_set = 0;
5325 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5327 clib_memset (mac_address, 0, sizeof (mac_address));
5329 /* Parse args required to build the message */
5330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5332 if (unformat (i, "id %u", &id))
5336 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5338 else if (unformat (i, "host-if-name %s", &host_if_name))
5339 host_if_name_set = 1;
5340 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5342 else if (unformat (i, "host-ns %s", &host_ns))
5344 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5346 host_mac_addr_set = 1;
5347 else if (unformat (i, "host-bridge %s", &host_bridge))
5348 host_bridge_set = 1;
5349 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5350 &host_ip4_addr, &host_ip4_prefix_len))
5351 host_ip4_prefix_set = 1;
5352 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5353 &host_ip6_addr, &host_ip6_prefix_len))
5354 host_ip6_prefix_set = 1;
5355 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5357 host_ip4_gw_set = 1;
5358 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5360 host_ip6_gw_set = 1;
5361 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5363 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5365 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5367 else if (unformat (i, "no-gso"))
5368 tap_flags &= ~TAP_API_FLAG_GSO;
5369 else if (unformat (i, "gso"))
5370 tap_flags |= TAP_API_FLAG_GSO;
5371 else if (unformat (i, "csum-offload"))
5372 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5373 else if (unformat (i, "persist"))
5374 tap_flags |= TAP_API_FLAG_PERSIST;
5375 else if (unformat (i, "attach"))
5376 tap_flags |= TAP_API_FLAG_ATTACH;
5377 else if (unformat (i, "tun"))
5378 tap_flags |= TAP_API_FLAG_TUN;
5379 else if (unformat (i, "gro-coalesce"))
5380 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5381 else if (unformat (i, "packed"))
5382 tap_flags |= TAP_API_FLAG_PACKED;
5383 else if (unformat (i, "in-order"))
5384 tap_flags |= TAP_API_FLAG_IN_ORDER;
5389 if (vec_len (host_if_name) > 63)
5391 errmsg ("tap name too long. ");
5394 if (vec_len (host_ns) > 63)
5396 errmsg ("host name space too long. ");
5399 if (vec_len (host_bridge) > 63)
5401 errmsg ("host bridge name too long. ");
5404 if (host_ip4_prefix_len > 32)
5406 errmsg ("host ip4 prefix length not valid. ");
5409 if (host_ip6_prefix_len > 128)
5411 errmsg ("host ip6 prefix length not valid. ");
5414 if (!is_pow2 (rx_ring_sz))
5416 errmsg ("rx ring size must be power of 2. ");
5419 if (rx_ring_sz > 32768)
5421 errmsg ("rx ring size must be 32768 or lower. ");
5424 if (!is_pow2 (tx_ring_sz))
5426 errmsg ("tx ring size must be power of 2. ");
5429 if (tx_ring_sz > 32768)
5431 errmsg ("tx ring size must be 32768 or lower. ");
5434 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5436 errmsg ("host MTU size must be in between 64 and 65355. ");
5440 /* Construct the API message */
5441 M (TAP_CREATE_V2, mp);
5443 mp->id = ntohl (id);
5444 mp->use_random_mac = random_mac;
5445 mp->num_rx_queues = (u8) num_rx_queues;
5446 mp->tx_ring_sz = ntohs (tx_ring_sz);
5447 mp->rx_ring_sz = ntohs (rx_ring_sz);
5448 mp->host_mtu_set = host_mtu_set;
5449 mp->host_mtu_size = ntohl (host_mtu_size);
5450 mp->host_mac_addr_set = host_mac_addr_set;
5451 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5452 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5453 mp->host_ip4_gw_set = host_ip4_gw_set;
5454 mp->host_ip6_gw_set = host_ip6_gw_set;
5455 mp->tap_flags = ntohl (tap_flags);
5456 mp->host_namespace_set = host_ns_set;
5457 mp->host_if_name_set = host_if_name_set;
5458 mp->host_bridge_set = host_bridge_set;
5460 if (random_mac == 0)
5461 clib_memcpy (mp->mac_address, mac_address, 6);
5462 if (host_mac_addr_set)
5463 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5464 if (host_if_name_set)
5465 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5467 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5468 if (host_bridge_set)
5469 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5470 if (host_ip4_prefix_set)
5472 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5473 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5475 if (host_ip6_prefix_set)
5477 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5478 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5480 if (host_ip4_gw_set)
5481 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5482 if (host_ip6_gw_set)
5483 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5486 vec_free (host_if_name);
5487 vec_free (host_bridge);
5492 /* Wait for a reply... */
5498 api_tap_delete_v2 (vat_main_t * vam)
5500 unformat_input_t *i = vam->input;
5501 vl_api_tap_delete_v2_t *mp;
5502 u32 sw_if_index = ~0;
5503 u8 sw_if_index_set = 0;
5506 /* Parse args required to build the message */
5507 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5509 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5510 sw_if_index_set = 1;
5511 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5512 sw_if_index_set = 1;
5517 if (sw_if_index_set == 0)
5519 errmsg ("missing vpp interface name. ");
5523 /* Construct the API message */
5524 M (TAP_DELETE_V2, mp);
5526 mp->sw_if_index = ntohl (sw_if_index);
5531 /* Wait for a reply... */
5537 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5539 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5542 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5545 addr->domain = x[0];
5548 addr->function = x[3];
5554 api_virtio_pci_create_v2 (vat_main_t * vam)
5556 unformat_input_t *i = vam->input;
5557 vl_api_virtio_pci_create_v2_t *mp;
5561 u64 features = (u64) ~ (0ULL);
5562 u32 virtio_flags = 0;
5565 clib_memset (mac_address, 0, sizeof (mac_address));
5567 /* Parse args required to build the message */
5568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5570 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5574 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5576 else if (unformat (i, "features 0x%llx", &features))
5578 else if (unformat (i, "gso-enabled"))
5579 virtio_flags |= VIRTIO_API_FLAG_GSO;
5580 else if (unformat (i, "csum-offload-enabled"))
5581 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5582 else if (unformat (i, "gro-coalesce"))
5583 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5584 else if (unformat (i, "packed"))
5585 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5586 else if (unformat (i, "in-order"))
5587 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5588 else if (unformat (i, "buffering"))
5589 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5596 errmsg ("pci address must be non zero. ");
5600 /* Construct the API message */
5601 M (VIRTIO_PCI_CREATE_V2, mp);
5603 mp->use_random_mac = random_mac;
5605 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5606 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5607 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5608 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5610 mp->features = clib_host_to_net_u64 (features);
5611 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5613 if (random_mac == 0)
5614 clib_memcpy (mp->mac_address, mac_address, 6);
5619 /* Wait for a reply... */
5625 api_virtio_pci_delete (vat_main_t * vam)
5627 unformat_input_t *i = vam->input;
5628 vl_api_virtio_pci_delete_t *mp;
5629 u32 sw_if_index = ~0;
5630 u8 sw_if_index_set = 0;
5633 /* Parse args required to build the message */
5634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5636 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5637 sw_if_index_set = 1;
5638 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5639 sw_if_index_set = 1;
5644 if (sw_if_index_set == 0)
5646 errmsg ("missing vpp interface name. ");
5650 /* Construct the API message */
5651 M (VIRTIO_PCI_DELETE, mp);
5653 mp->sw_if_index = htonl (sw_if_index);
5658 /* Wait for a reply... */
5664 api_bond_create (vat_main_t * vam)
5666 unformat_input_t *i = vam->input;
5667 vl_api_bond_create_t *mp;
5677 clib_memset (mac_address, 0, sizeof (mac_address));
5680 /* Parse args required to build the message */
5681 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5683 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5685 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5686 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5688 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5691 else if (unformat (i, "numa-only"))
5693 else if (unformat (i, "id %u", &id))
5699 if (mode_is_set == 0)
5701 errmsg ("Missing bond mode. ");
5705 /* Construct the API message */
5706 M (BOND_CREATE, mp);
5708 mp->use_custom_mac = custom_mac;
5710 mp->mode = htonl (mode);
5711 mp->lb = htonl (lb);
5712 mp->id = htonl (id);
5713 mp->numa_only = numa_only;
5716 clib_memcpy (mp->mac_address, mac_address, 6);
5721 /* Wait for a reply... */
5727 api_bond_create2 (vat_main_t * vam)
5729 unformat_input_t *i = vam->input;
5730 vl_api_bond_create2_t *mp;
5741 clib_memset (mac_address, 0, sizeof (mac_address));
5744 /* Parse args required to build the message */
5745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5747 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5749 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5750 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5752 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5755 else if (unformat (i, "numa-only"))
5757 else if (unformat (i, "gso"))
5759 else if (unformat (i, "id %u", &id))
5765 if (mode_is_set == 0)
5767 errmsg ("Missing bond mode. ");
5771 /* Construct the API message */
5772 M (BOND_CREATE2, mp);
5774 mp->use_custom_mac = custom_mac;
5776 mp->mode = htonl (mode);
5777 mp->lb = htonl (lb);
5778 mp->id = htonl (id);
5779 mp->numa_only = numa_only;
5780 mp->enable_gso = gso;
5783 clib_memcpy (mp->mac_address, mac_address, 6);
5788 /* Wait for a reply... */
5794 api_bond_delete (vat_main_t * vam)
5796 unformat_input_t *i = vam->input;
5797 vl_api_bond_delete_t *mp;
5798 u32 sw_if_index = ~0;
5799 u8 sw_if_index_set = 0;
5802 /* Parse args required to build the message */
5803 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5805 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5806 sw_if_index_set = 1;
5807 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5808 sw_if_index_set = 1;
5813 if (sw_if_index_set == 0)
5815 errmsg ("missing vpp interface name. ");
5819 /* Construct the API message */
5820 M (BOND_DELETE, mp);
5822 mp->sw_if_index = ntohl (sw_if_index);
5827 /* Wait for a reply... */
5833 api_bond_add_member (vat_main_t * vam)
5835 unformat_input_t *i = vam->input;
5836 vl_api_bond_add_member_t *mp;
5837 u32 bond_sw_if_index;
5841 u32 bond_sw_if_index_is_set = 0;
5843 u8 sw_if_index_is_set = 0;
5845 /* Parse args required to build the message */
5846 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5848 if (unformat (i, "sw_if_index %d", &sw_if_index))
5849 sw_if_index_is_set = 1;
5850 else if (unformat (i, "bond %u", &bond_sw_if_index))
5851 bond_sw_if_index_is_set = 1;
5852 else if (unformat (i, "passive %d", &is_passive))
5854 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5860 if (bond_sw_if_index_is_set == 0)
5862 errmsg ("Missing bond sw_if_index. ");
5865 if (sw_if_index_is_set == 0)
5867 errmsg ("Missing member sw_if_index. ");
5871 /* Construct the API message */
5872 M (BOND_ADD_MEMBER, mp);
5874 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5875 mp->sw_if_index = ntohl (sw_if_index);
5876 mp->is_long_timeout = is_long_timeout;
5877 mp->is_passive = is_passive;
5882 /* Wait for a reply... */
5888 api_bond_detach_member (vat_main_t * vam)
5890 unformat_input_t *i = vam->input;
5891 vl_api_bond_detach_member_t *mp;
5892 u32 sw_if_index = ~0;
5893 u8 sw_if_index_set = 0;
5896 /* Parse args required to build the message */
5897 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5899 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5900 sw_if_index_set = 1;
5901 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5902 sw_if_index_set = 1;
5907 if (sw_if_index_set == 0)
5909 errmsg ("missing vpp interface name. ");
5913 /* Construct the API message */
5914 M (BOND_DETACH_MEMBER, mp);
5916 mp->sw_if_index = ntohl (sw_if_index);
5921 /* Wait for a reply... */
5927 api_ip_table_add_del (vat_main_t * vam)
5929 unformat_input_t *i = vam->input;
5930 vl_api_ip_table_add_del_t *mp;
5936 /* Parse args required to build the message */
5937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5939 if (unformat (i, "ipv6"))
5941 else if (unformat (i, "del"))
5943 else if (unformat (i, "add"))
5945 else if (unformat (i, "table %d", &table_id))
5949 clib_warning ("parse error '%U'", format_unformat_error, i);
5956 errmsg ("missing table-ID");
5960 /* Construct the API message */
5961 M (IP_TABLE_ADD_DEL, mp);
5963 mp->table.table_id = ntohl (table_id);
5964 mp->table.is_ip6 = is_ipv6;
5965 mp->is_add = is_add;
5970 /* Wait for a reply... */
5977 unformat_fib_path (unformat_input_t * input, va_list * args)
5979 vat_main_t *vam = va_arg (*args, vat_main_t *);
5980 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5981 u32 weight, preference;
5982 mpls_label_t out_label;
5984 clib_memset (path, 0, sizeof (*path));
5986 path->sw_if_index = ~0;
5990 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5992 if (unformat (input, "%U %U",
5993 unformat_vl_api_ip4_address,
5994 &path->nh.address.ip4,
5995 api_unformat_sw_if_index, vam, &path->sw_if_index))
5997 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5999 else if (unformat (input, "%U %U",
6000 unformat_vl_api_ip6_address,
6001 &path->nh.address.ip6,
6002 api_unformat_sw_if_index, vam, &path->sw_if_index))
6004 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6006 else if (unformat (input, "weight %u", &weight))
6008 path->weight = weight;
6010 else if (unformat (input, "preference %u", &preference))
6012 path->preference = preference;
6014 else if (unformat (input, "%U next-hop-table %d",
6015 unformat_vl_api_ip4_address,
6016 &path->nh.address.ip4, &path->table_id))
6018 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6020 else if (unformat (input, "%U next-hop-table %d",
6021 unformat_vl_api_ip6_address,
6022 &path->nh.address.ip6, &path->table_id))
6024 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6026 else if (unformat (input, "%U",
6027 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6030 * the recursive next-hops are by default in the default table
6033 path->sw_if_index = ~0;
6034 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6036 else if (unformat (input, "%U",
6037 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6040 * the recursive next-hops are by default in the default table
6043 path->sw_if_index = ~0;
6044 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6046 else if (unformat (input, "resolve-via-host"))
6048 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6050 else if (unformat (input, "resolve-via-attached"))
6052 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6054 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6056 path->type = FIB_API_PATH_TYPE_LOCAL;
6057 path->sw_if_index = ~0;
6058 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6060 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6062 path->type = FIB_API_PATH_TYPE_LOCAL;
6063 path->sw_if_index = ~0;
6064 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6066 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6068 else if (unformat (input, "via-label %d", &path->nh.via_label))
6070 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6071 path->sw_if_index = ~0;
6073 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6075 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6076 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6078 else if (unformat (input, "local"))
6080 path->type = FIB_API_PATH_TYPE_LOCAL;
6082 else if (unformat (input, "out-labels"))
6084 while (unformat (input, "%d", &out_label))
6086 path->label_stack[path->n_labels].label = out_label;
6087 path->label_stack[path->n_labels].is_uniform = 0;
6088 path->label_stack[path->n_labels].ttl = 64;
6092 else if (unformat (input, "via"))
6094 /* new path, back up and return */
6095 unformat_put_input (input);
6096 unformat_put_input (input);
6097 unformat_put_input (input);
6098 unformat_put_input (input);
6107 path->proto = ntohl (path->proto);
6108 path->type = ntohl (path->type);
6109 path->flags = ntohl (path->flags);
6110 path->table_id = ntohl (path->table_id);
6111 path->sw_if_index = ntohl (path->sw_if_index);
6117 api_ip_route_add_del (vat_main_t * vam)
6119 unformat_input_t *i = vam->input;
6120 vl_api_ip_route_add_del_t *mp;
6123 u8 is_multipath = 0;
6126 vl_api_prefix_t pfx = { };
6127 vl_api_fib_path_t paths[8];
6131 u32 random_add_del = 0;
6132 u32 *random_vector = 0;
6133 u32 random_seed = 0xdeaddabe;
6135 /* Parse args required to build the message */
6136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6138 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6140 else if (unformat (i, "del"))
6142 else if (unformat (i, "add"))
6144 else if (unformat (i, "vrf %d", &vrf_id))
6146 else if (unformat (i, "count %d", &count))
6148 else if (unformat (i, "random"))
6150 else if (unformat (i, "multipath"))
6152 else if (unformat (i, "seed %d", &random_seed))
6156 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6159 if (8 == path_count)
6161 errmsg ("max 8 paths");
6167 clib_warning ("parse error '%U'", format_unformat_error, i);
6174 errmsg ("specify a path; via ...");
6177 if (prefix_set == 0)
6179 errmsg ("missing prefix");
6183 /* Generate a pile of unique, random routes */
6186 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6187 u32 this_random_address;
6190 random_hash = hash_create (count, sizeof (uword));
6192 hash_set (random_hash, i->as_u32, 1);
6193 for (j = 0; j <= count; j++)
6197 this_random_address = random_u32 (&random_seed);
6198 this_random_address =
6199 clib_host_to_net_u32 (this_random_address);
6201 while (hash_get (random_hash, this_random_address));
6202 vec_add1 (random_vector, this_random_address);
6203 hash_set (random_hash, this_random_address, 1);
6205 hash_free (random_hash);
6206 set_ip4_address (&pfx.address, random_vector[0]);
6211 /* Turn on async mode */
6212 vam->async_mode = 1;
6213 vam->async_errors = 0;
6214 before = vat_time_now (vam);
6217 for (j = 0; j < count; j++)
6219 /* Construct the API message */
6220 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6222 mp->is_add = is_add;
6223 mp->is_multipath = is_multipath;
6225 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6226 mp->route.table_id = ntohl (vrf_id);
6227 mp->route.n_paths = path_count;
6229 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6232 set_ip4_address (&pfx.address, random_vector[j + 1]);
6234 increment_address (&pfx.address);
6237 /* If we receive SIGTERM, stop now... */
6242 /* When testing multiple add/del ops, use a control-ping to sync */
6245 vl_api_control_ping_t *mp_ping;
6249 /* Shut off async mode */
6250 vam->async_mode = 0;
6252 MPING (CONTROL_PING, mp_ping);
6255 timeout = vat_time_now (vam) + 1.0;
6256 while (vat_time_now (vam) < timeout)
6257 if (vam->result_ready == 1)
6262 if (vam->retval == -99)
6265 if (vam->async_errors > 0)
6267 errmsg ("%d asynchronous errors", vam->async_errors);
6270 vam->async_errors = 0;
6271 after = vat_time_now (vam);
6273 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6277 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6278 count, after - before, count / (after - before));
6284 /* Wait for a reply... */
6289 /* Return the good/bad news */
6290 return (vam->retval);
6294 api_ip_mroute_add_del (vat_main_t * vam)
6296 unformat_input_t *i = vam->input;
6297 u8 path_set = 0, prefix_set = 0, is_add = 1;
6298 vl_api_ip_mroute_add_del_t *mp;
6299 mfib_entry_flags_t eflags = 0;
6300 vl_api_mfib_path_t path;
6301 vl_api_mprefix_t pfx = { };
6305 /* Parse args required to build the message */
6306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6308 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6311 pfx.grp_address_length = htons (pfx.grp_address_length);
6313 else if (unformat (i, "del"))
6315 else if (unformat (i, "add"))
6317 else if (unformat (i, "vrf %d", &vrf_id))
6319 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6320 path.itf_flags = htonl (path.itf_flags);
6321 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6323 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6327 clib_warning ("parse error '%U'", format_unformat_error, i);
6332 if (prefix_set == 0)
6334 errmsg ("missing addresses\n");
6339 errmsg ("missing path\n");
6343 /* Construct the API message */
6344 M (IP_MROUTE_ADD_DEL, mp);
6346 mp->is_add = is_add;
6347 mp->is_multipath = 1;
6349 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6350 mp->route.table_id = htonl (vrf_id);
6351 mp->route.n_paths = 1;
6352 mp->route.entry_flags = htonl (eflags);
6354 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6358 /* Wait for a reply... */
6364 api_mpls_table_add_del (vat_main_t * vam)
6366 unformat_input_t *i = vam->input;
6367 vl_api_mpls_table_add_del_t *mp;
6372 /* Parse args required to build the message */
6373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6375 if (unformat (i, "table %d", &table_id))
6377 else if (unformat (i, "del"))
6379 else if (unformat (i, "add"))
6383 clib_warning ("parse error '%U'", format_unformat_error, i);
6390 errmsg ("missing table-ID");
6394 /* Construct the API message */
6395 M (MPLS_TABLE_ADD_DEL, mp);
6397 mp->mt_table.mt_table_id = ntohl (table_id);
6398 mp->mt_is_add = is_add;
6403 /* Wait for a reply... */
6410 api_mpls_route_add_del (vat_main_t * vam)
6412 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6413 mpls_label_t local_label = MPLS_LABEL_INVALID;
6414 unformat_input_t *i = vam->input;
6415 vl_api_mpls_route_add_del_t *mp;
6416 vl_api_fib_path_t paths[8];
6420 /* Parse args required to build the message */
6421 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6423 if (unformat (i, "%d", &local_label))
6425 else if (unformat (i, "eos"))
6427 else if (unformat (i, "non-eos"))
6429 else if (unformat (i, "del"))
6431 else if (unformat (i, "add"))
6433 else if (unformat (i, "multipath"))
6435 else if (unformat (i, "count %d", &count))
6439 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6442 if (8 == path_count)
6444 errmsg ("max 8 paths");
6450 clib_warning ("parse error '%U'", format_unformat_error, i);
6457 errmsg ("specify a path; via ...");
6461 if (MPLS_LABEL_INVALID == local_label)
6463 errmsg ("missing label");
6469 /* Turn on async mode */
6470 vam->async_mode = 1;
6471 vam->async_errors = 0;
6472 before = vat_time_now (vam);
6475 for (j = 0; j < count; j++)
6477 /* Construct the API message */
6478 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6480 mp->mr_is_add = is_add;
6481 mp->mr_is_multipath = is_multipath;
6483 mp->mr_route.mr_label = local_label;
6484 mp->mr_route.mr_eos = is_eos;
6485 mp->mr_route.mr_table_id = 0;
6486 mp->mr_route.mr_n_paths = path_count;
6488 clib_memcpy (&mp->mr_route.mr_paths, paths,
6489 sizeof (paths[0]) * path_count);
6495 /* If we receive SIGTERM, stop now... */
6500 /* When testing multiple add/del ops, use a control-ping to sync */
6503 vl_api_control_ping_t *mp_ping;
6507 /* Shut off async mode */
6508 vam->async_mode = 0;
6510 MPING (CONTROL_PING, mp_ping);
6513 timeout = vat_time_now (vam) + 1.0;
6514 while (vat_time_now (vam) < timeout)
6515 if (vam->result_ready == 1)
6520 if (vam->retval == -99)
6523 if (vam->async_errors > 0)
6525 errmsg ("%d asynchronous errors", vam->async_errors);
6528 vam->async_errors = 0;
6529 after = vat_time_now (vam);
6531 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6535 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6536 count, after - before, count / (after - before));
6542 /* Wait for a reply... */
6547 /* Return the good/bad news */
6548 return (vam->retval);
6553 api_mpls_ip_bind_unbind (vat_main_t * vam)
6555 unformat_input_t *i = vam->input;
6556 vl_api_mpls_ip_bind_unbind_t *mp;
6557 u32 ip_table_id = 0;
6559 vl_api_prefix_t pfx;
6561 mpls_label_t local_label = MPLS_LABEL_INVALID;
6564 /* Parse args required to build the message */
6565 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6567 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6569 else if (unformat (i, "%d", &local_label))
6571 else if (unformat (i, "table-id %d", &ip_table_id))
6573 else if (unformat (i, "unbind"))
6575 else if (unformat (i, "bind"))
6579 clib_warning ("parse error '%U'", format_unformat_error, i);
6586 errmsg ("IP prefix not set");
6590 if (MPLS_LABEL_INVALID == local_label)
6592 errmsg ("missing label");
6596 /* Construct the API message */
6597 M (MPLS_IP_BIND_UNBIND, mp);
6599 mp->mb_is_bind = is_bind;
6600 mp->mb_ip_table_id = ntohl (ip_table_id);
6601 mp->mb_mpls_table_id = 0;
6602 mp->mb_label = ntohl (local_label);
6603 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6608 /* Wait for a reply... */
6615 api_sr_mpls_policy_add (vat_main_t * vam)
6617 unformat_input_t *i = vam->input;
6618 vl_api_sr_mpls_policy_add_t *mp;
6624 u32 *segments = NULL;
6627 /* Parse args required to build the message */
6628 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6630 if (unformat (i, "bsid %d", &bsid))
6632 else if (unformat (i, "weight %d", &weight))
6634 else if (unformat (i, "spray"))
6636 else if (unformat (i, "next %d", &sid))
6639 vec_add1 (segments, htonl (sid));
6643 clib_warning ("parse error '%U'", format_unformat_error, i);
6650 errmsg ("bsid not set");
6654 if (n_segments == 0)
6656 errmsg ("no sid in segment stack");
6660 /* Construct the API message */
6661 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6663 mp->bsid = htonl (bsid);
6664 mp->weight = htonl (weight);
6665 mp->is_spray = type;
6666 mp->n_segments = n_segments;
6667 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6668 vec_free (segments);
6673 /* Wait for a reply... */
6679 api_sr_mpls_policy_del (vat_main_t * vam)
6681 unformat_input_t *i = vam->input;
6682 vl_api_sr_mpls_policy_del_t *mp;
6686 /* Parse args required to build the message */
6687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6689 if (unformat (i, "bsid %d", &bsid))
6693 clib_warning ("parse error '%U'", format_unformat_error, i);
6700 errmsg ("bsid not set");
6704 /* Construct the API message */
6705 M (SR_MPLS_POLICY_DEL, mp);
6707 mp->bsid = htonl (bsid);
6712 /* Wait for a reply... */
6718 api_bier_table_add_del (vat_main_t * vam)
6720 unformat_input_t *i = vam->input;
6721 vl_api_bier_table_add_del_t *mp;
6723 u32 set = 0, sub_domain = 0, hdr_len = 3;
6724 mpls_label_t local_label = MPLS_LABEL_INVALID;
6727 /* Parse args required to build the message */
6728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6730 if (unformat (i, "sub-domain %d", &sub_domain))
6732 else if (unformat (i, "set %d", &set))
6734 else if (unformat (i, "label %d", &local_label))
6736 else if (unformat (i, "hdr-len %d", &hdr_len))
6738 else if (unformat (i, "add"))
6740 else if (unformat (i, "del"))
6744 clib_warning ("parse error '%U'", format_unformat_error, i);
6749 if (MPLS_LABEL_INVALID == local_label)
6751 errmsg ("missing label\n");
6755 /* Construct the API message */
6756 M (BIER_TABLE_ADD_DEL, mp);
6758 mp->bt_is_add = is_add;
6759 mp->bt_label = ntohl (local_label);
6760 mp->bt_tbl_id.bt_set = set;
6761 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6762 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6767 /* Wait for a reply... */
6774 api_bier_route_add_del (vat_main_t * vam)
6776 unformat_input_t *i = vam->input;
6777 vl_api_bier_route_add_del_t *mp;
6779 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6780 ip4_address_t v4_next_hop_address;
6781 ip6_address_t v6_next_hop_address;
6782 u8 next_hop_set = 0;
6783 u8 next_hop_proto_is_ip4 = 1;
6784 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6787 /* Parse args required to build the message */
6788 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6790 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6792 next_hop_proto_is_ip4 = 1;
6795 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6797 next_hop_proto_is_ip4 = 0;
6800 if (unformat (i, "sub-domain %d", &sub_domain))
6802 else if (unformat (i, "set %d", &set))
6804 else if (unformat (i, "hdr-len %d", &hdr_len))
6806 else if (unformat (i, "bp %d", &bp))
6808 else if (unformat (i, "add"))
6810 else if (unformat (i, "del"))
6812 else if (unformat (i, "out-label %d", &next_hop_out_label))
6816 clib_warning ("parse error '%U'", format_unformat_error, i);
6821 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6823 errmsg ("next hop / label set\n");
6828 errmsg ("bit=position not set\n");
6832 /* Construct the API message */
6833 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6835 mp->br_is_add = is_add;
6836 mp->br_route.br_tbl_id.bt_set = set;
6837 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6838 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6839 mp->br_route.br_bp = ntohs (bp);
6840 mp->br_route.br_n_paths = 1;
6841 mp->br_route.br_paths[0].n_labels = 1;
6842 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6843 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6844 FIB_API_PATH_NH_PROTO_IP4 :
6845 FIB_API_PATH_NH_PROTO_IP6);
6847 if (next_hop_proto_is_ip4)
6849 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6850 &v4_next_hop_address, sizeof (v4_next_hop_address));
6854 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6855 &v6_next_hop_address, sizeof (v6_next_hop_address));
6861 /* Wait for a reply... */
6868 api_mpls_tunnel_add_del (vat_main_t * vam)
6870 unformat_input_t *i = vam->input;
6871 vl_api_mpls_tunnel_add_del_t *mp;
6873 vl_api_fib_path_t paths[8];
6874 u32 sw_if_index = ~0;
6880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6882 if (unformat (i, "add"))
6886 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6888 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6890 else if (unformat (i, "l2-only"))
6894 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6897 if (8 == path_count)
6899 errmsg ("max 8 paths");
6905 clib_warning ("parse error '%U'", format_unformat_error, i);
6910 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6912 mp->mt_is_add = is_add;
6913 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6914 mp->mt_tunnel.mt_l2_only = l2_only;
6915 mp->mt_tunnel.mt_is_multicast = 0;
6916 mp->mt_tunnel.mt_n_paths = path_count;
6918 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6919 sizeof (paths[0]) * path_count);
6927 api_sw_interface_set_unnumbered (vat_main_t * vam)
6929 unformat_input_t *i = vam->input;
6930 vl_api_sw_interface_set_unnumbered_t *mp;
6932 u32 unnum_sw_index = ~0;
6934 u8 sw_if_index_set = 0;
6937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6939 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6940 sw_if_index_set = 1;
6941 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6942 sw_if_index_set = 1;
6943 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6945 else if (unformat (i, "del"))
6949 clib_warning ("parse error '%U'", format_unformat_error, i);
6954 if (sw_if_index_set == 0)
6956 errmsg ("missing interface name or sw_if_index");
6960 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6962 mp->sw_if_index = ntohl (sw_if_index);
6963 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6964 mp->is_add = is_add;
6973 api_create_vlan_subif (vat_main_t * vam)
6975 unformat_input_t *i = vam->input;
6976 vl_api_create_vlan_subif_t *mp;
6978 u8 sw_if_index_set = 0;
6983 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6985 if (unformat (i, "sw_if_index %d", &sw_if_index))
6986 sw_if_index_set = 1;
6988 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6989 sw_if_index_set = 1;
6990 else if (unformat (i, "vlan %d", &vlan_id))
6994 clib_warning ("parse error '%U'", format_unformat_error, i);
6999 if (sw_if_index_set == 0)
7001 errmsg ("missing interface name or sw_if_index");
7005 if (vlan_id_set == 0)
7007 errmsg ("missing vlan_id");
7010 M (CREATE_VLAN_SUBIF, mp);
7012 mp->sw_if_index = ntohl (sw_if_index);
7013 mp->vlan_id = ntohl (vlan_id);
7020 #define foreach_create_subif_bit \
7027 _(outer_vlan_id_any) \
7028 _(inner_vlan_id_any)
7030 #define foreach_create_subif_flag \
7035 _(4, "exact_match") \
7036 _(5, "default_sub") \
7037 _(6, "outer_vlan_id_any") \
7038 _(7, "inner_vlan_id_any")
7041 api_create_subif (vat_main_t * vam)
7043 unformat_input_t *i = vam->input;
7044 vl_api_create_subif_t *mp;
7046 u8 sw_if_index_set = 0;
7049 u32 __attribute__ ((unused)) no_tags = 0;
7050 u32 __attribute__ ((unused)) one_tag = 0;
7051 u32 __attribute__ ((unused)) two_tags = 0;
7052 u32 __attribute__ ((unused)) dot1ad = 0;
7053 u32 __attribute__ ((unused)) exact_match = 0;
7054 u32 __attribute__ ((unused)) default_sub = 0;
7055 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7056 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7058 u16 outer_vlan_id = 0;
7059 u16 inner_vlan_id = 0;
7062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7064 if (unformat (i, "sw_if_index %d", &sw_if_index))
7065 sw_if_index_set = 1;
7067 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7068 sw_if_index_set = 1;
7069 else if (unformat (i, "sub_id %d", &sub_id))
7071 else if (unformat (i, "outer_vlan_id %d", &tmp))
7072 outer_vlan_id = tmp;
7073 else if (unformat (i, "inner_vlan_id %d", &tmp))
7074 inner_vlan_id = tmp;
7076 #define _(a) else if (unformat (i, #a)) a = 1 ;
7077 foreach_create_subif_bit
7081 clib_warning ("parse error '%U'", format_unformat_error, i);
7086 if (sw_if_index_set == 0)
7088 errmsg ("missing interface name or sw_if_index");
7092 if (sub_id_set == 0)
7094 errmsg ("missing sub_id");
7097 M (CREATE_SUBIF, mp);
7099 mp->sw_if_index = ntohl (sw_if_index);
7100 mp->sub_id = ntohl (sub_id);
7102 #define _(a,b) mp->sub_if_flags |= (1 << a);
7103 foreach_create_subif_flag;
7106 mp->outer_vlan_id = ntohs (outer_vlan_id);
7107 mp->inner_vlan_id = ntohs (inner_vlan_id);
7115 api_ip_table_replace_begin (vat_main_t * vam)
7117 unformat_input_t *i = vam->input;
7118 vl_api_ip_table_replace_begin_t *mp;
7123 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7125 if (unformat (i, "table %d", &table_id))
7127 else if (unformat (i, "ipv6"))
7131 clib_warning ("parse error '%U'", format_unformat_error, i);
7136 M (IP_TABLE_REPLACE_BEGIN, mp);
7138 mp->table.table_id = ntohl (table_id);
7139 mp->table.is_ip6 = is_ipv6;
7147 api_ip_table_flush (vat_main_t * vam)
7149 unformat_input_t *i = vam->input;
7150 vl_api_ip_table_flush_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_FLUSH, mp);
7170 mp->table.table_id = ntohl (table_id);
7171 mp->table.is_ip6 = is_ipv6;
7179 api_ip_table_replace_end (vat_main_t * vam)
7181 unformat_input_t *i = vam->input;
7182 vl_api_ip_table_replace_end_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_REPLACE_END, mp);
7202 mp->table.table_id = ntohl (table_id);
7203 mp->table.is_ip6 = is_ipv6;
7211 api_set_ip_flow_hash (vat_main_t * vam)
7213 unformat_input_t *i = vam->input;
7214 vl_api_set_ip_flow_hash_t *mp;
7226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7228 if (unformat (i, "vrf %d", &vrf_id))
7230 else if (unformat (i, "ipv6"))
7232 else if (unformat (i, "src"))
7234 else if (unformat (i, "dst"))
7236 else if (unformat (i, "sport"))
7238 else if (unformat (i, "dport"))
7240 else if (unformat (i, "proto"))
7242 else if (unformat (i, "reverse"))
7247 clib_warning ("parse error '%U'", format_unformat_error, i);
7252 if (vrf_id_set == 0)
7254 errmsg ("missing vrf id");
7258 M (SET_IP_FLOW_HASH, mp);
7264 mp->reverse = reverse;
7265 mp->vrf_id = ntohl (vrf_id);
7266 mp->is_ipv6 = is_ipv6;
7274 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7276 unformat_input_t *i = vam->input;
7277 vl_api_sw_interface_ip6_enable_disable_t *mp;
7279 u8 sw_if_index_set = 0;
7283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7285 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7286 sw_if_index_set = 1;
7287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7288 sw_if_index_set = 1;
7289 else if (unformat (i, "enable"))
7291 else if (unformat (i, "disable"))
7295 clib_warning ("parse error '%U'", format_unformat_error, i);
7300 if (sw_if_index_set == 0)
7302 errmsg ("missing interface name or sw_if_index");
7306 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7308 mp->sw_if_index = ntohl (sw_if_index);
7309 mp->enable = enable;
7318 api_l2_patch_add_del (vat_main_t * vam)
7320 unformat_input_t *i = vam->input;
7321 vl_api_l2_patch_add_del_t *mp;
7323 u8 rx_sw_if_index_set = 0;
7325 u8 tx_sw_if_index_set = 0;
7329 /* Parse args required to build the message */
7330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7332 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7333 rx_sw_if_index_set = 1;
7334 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7335 tx_sw_if_index_set = 1;
7336 else if (unformat (i, "rx"))
7338 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7340 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7342 rx_sw_if_index_set = 1;
7347 else if (unformat (i, "tx"))
7349 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7351 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7353 tx_sw_if_index_set = 1;
7358 else if (unformat (i, "del"))
7364 if (rx_sw_if_index_set == 0)
7366 errmsg ("missing rx interface name or rx_sw_if_index");
7370 if (tx_sw_if_index_set == 0)
7372 errmsg ("missing tx interface name or tx_sw_if_index");
7376 M (L2_PATCH_ADD_DEL, mp);
7378 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7379 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7380 mp->is_add = is_add;
7388 u8 localsid_addr[16];
7397 api_sr_localsid_add_del (vat_main_t * vam)
7399 unformat_input_t *i = vam->input;
7400 vl_api_sr_localsid_add_del_t *mp;
7403 ip6_address_t localsid;
7407 u32 fib_table = ~(u32) 0;
7408 ip46_address_t nh_addr;
7409 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7411 bool nexthop_set = 0;
7415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7417 if (unformat (i, "del"))
7419 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7420 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7422 else if (unformat (i, "behavior %u", &behavior));
7423 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7424 else if (unformat (i, "fib-table %u", &fib_table));
7425 else if (unformat (i, "end.psp %u", &behavior));
7430 M (SR_LOCALSID_ADD_DEL, mp);
7432 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7436 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7438 mp->behavior = behavior;
7439 mp->sw_if_index = ntohl (sw_if_index);
7440 mp->fib_table = ntohl (fib_table);
7441 mp->end_psp = end_psp;
7442 mp->is_del = is_del;
7450 api_ioam_enable (vat_main_t * vam)
7452 unformat_input_t *input = vam->input;
7453 vl_api_ioam_enable_t *mp;
7455 int has_trace_option = 0;
7456 int has_pot_option = 0;
7457 int has_seqno_option = 0;
7458 int has_analyse_option = 0;
7461 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7463 if (unformat (input, "trace"))
7464 has_trace_option = 1;
7465 else if (unformat (input, "pot"))
7467 else if (unformat (input, "seqno"))
7468 has_seqno_option = 1;
7469 else if (unformat (input, "analyse"))
7470 has_analyse_option = 1;
7474 M (IOAM_ENABLE, mp);
7475 mp->id = htons (id);
7476 mp->seqno = has_seqno_option;
7477 mp->analyse = has_analyse_option;
7478 mp->pot_enable = has_pot_option;
7479 mp->trace_enable = has_trace_option;
7488 api_ioam_disable (vat_main_t * vam)
7490 vl_api_ioam_disable_t *mp;
7493 M (IOAM_DISABLE, mp);
7499 #define foreach_tcp_proto_field \
7503 #define foreach_udp_proto_field \
7507 #define foreach_ip4_proto_field \
7519 u16 src_port, dst_port;
7522 #if VPP_API_TEST_BUILTIN == 0
7524 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7526 u8 **maskp = va_arg (*args, u8 **);
7528 u8 found_something = 0;
7531 #define _(a) u8 a=0;
7532 foreach_tcp_proto_field;
7535 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7538 #define _(a) else if (unformat (input, #a)) a=1;
7539 foreach_tcp_proto_field
7545 #define _(a) found_something += a;
7546 foreach_tcp_proto_field;
7549 if (found_something == 0)
7552 vec_validate (mask, sizeof (*tcp) - 1);
7554 tcp = (tcp_header_t *) mask;
7556 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7557 foreach_tcp_proto_field;
7565 unformat_udp_mask (unformat_input_t * input, va_list * args)
7567 u8 **maskp = va_arg (*args, u8 **);
7569 u8 found_something = 0;
7572 #define _(a) u8 a=0;
7573 foreach_udp_proto_field;
7576 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7579 #define _(a) else if (unformat (input, #a)) a=1;
7580 foreach_udp_proto_field
7586 #define _(a) found_something += a;
7587 foreach_udp_proto_field;
7590 if (found_something == 0)
7593 vec_validate (mask, sizeof (*udp) - 1);
7595 udp = (udp_header_t *) mask;
7597 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7598 foreach_udp_proto_field;
7606 unformat_l4_mask (unformat_input_t * input, va_list * args)
7608 u8 **maskp = va_arg (*args, u8 **);
7609 u16 src_port = 0, dst_port = 0;
7610 tcpudp_header_t *tcpudp;
7612 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7614 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7616 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7618 else if (unformat (input, "src_port"))
7620 else if (unformat (input, "dst_port"))
7626 if (!src_port && !dst_port)
7630 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7632 tcpudp = (tcpudp_header_t *) mask;
7633 tcpudp->src_port = src_port;
7634 tcpudp->dst_port = dst_port;
7642 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7644 u8 **maskp = va_arg (*args, u8 **);
7646 u8 found_something = 0;
7649 #define _(a) u8 a=0;
7650 foreach_ip4_proto_field;
7656 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7658 if (unformat (input, "version"))
7660 else if (unformat (input, "hdr_length"))
7662 else if (unformat (input, "src"))
7664 else if (unformat (input, "dst"))
7666 else if (unformat (input, "proto"))
7669 #define _(a) else if (unformat (input, #a)) a=1;
7670 foreach_ip4_proto_field
7676 #define _(a) found_something += a;
7677 foreach_ip4_proto_field;
7680 if (found_something == 0)
7683 vec_validate (mask, sizeof (*ip) - 1);
7685 ip = (ip4_header_t *) mask;
7687 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7688 foreach_ip4_proto_field;
7691 ip->ip_version_and_header_length = 0;
7694 ip->ip_version_and_header_length |= 0xF0;
7697 ip->ip_version_and_header_length |= 0x0F;
7703 #define foreach_ip6_proto_field \
7711 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7713 u8 **maskp = va_arg (*args, u8 **);
7715 u8 found_something = 0;
7717 u32 ip_version_traffic_class_and_flow_label;
7719 #define _(a) u8 a=0;
7720 foreach_ip6_proto_field;
7723 u8 traffic_class = 0;
7726 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7728 if (unformat (input, "version"))
7730 else if (unformat (input, "traffic-class"))
7732 else if (unformat (input, "flow-label"))
7734 else if (unformat (input, "src"))
7736 else if (unformat (input, "dst"))
7738 else if (unformat (input, "proto"))
7741 #define _(a) else if (unformat (input, #a)) a=1;
7742 foreach_ip6_proto_field
7748 #define _(a) found_something += a;
7749 foreach_ip6_proto_field;
7752 if (found_something == 0)
7755 vec_validate (mask, sizeof (*ip) - 1);
7757 ip = (ip6_header_t *) mask;
7759 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7760 foreach_ip6_proto_field;
7763 ip_version_traffic_class_and_flow_label = 0;
7766 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7769 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7772 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7774 ip->ip_version_traffic_class_and_flow_label =
7775 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7782 unformat_l3_mask (unformat_input_t * input, va_list * args)
7784 u8 **maskp = va_arg (*args, u8 **);
7786 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7788 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7790 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7799 unformat_l2_mask (unformat_input_t * input, va_list * args)
7801 u8 **maskp = va_arg (*args, u8 **);
7816 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7818 if (unformat (input, "src"))
7820 else if (unformat (input, "dst"))
7822 else if (unformat (input, "proto"))
7824 else if (unformat (input, "tag1"))
7826 else if (unformat (input, "tag2"))
7828 else if (unformat (input, "ignore-tag1"))
7830 else if (unformat (input, "ignore-tag2"))
7832 else if (unformat (input, "cos1"))
7834 else if (unformat (input, "cos2"))
7836 else if (unformat (input, "dot1q"))
7838 else if (unformat (input, "dot1ad"))
7843 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7844 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7847 if (tag1 || ignore_tag1 || cos1 || dot1q)
7849 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7852 vec_validate (mask, len - 1);
7855 clib_memset (mask, 0xff, 6);
7858 clib_memset (mask + 6, 0xff, 6);
7862 /* inner vlan tag */
7871 mask[21] = mask[20] = 0xff;
7892 mask[16] = mask[17] = 0xff;
7902 mask[12] = mask[13] = 0xff;
7909 unformat_classify_mask (unformat_input_t * input, va_list * args)
7911 u8 **maskp = va_arg (*args, u8 **);
7912 u32 *skipp = va_arg (*args, u32 *);
7913 u32 *matchp = va_arg (*args, u32 *);
7921 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7923 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7925 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7927 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7929 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7943 if (mask || l2 || l3 || l4)
7947 /* "With a free Ethernet header in every package" */
7949 vec_validate (l2, 13);
7953 vec_append (mask, l3);
7958 vec_append (mask, l4);
7963 /* Scan forward looking for the first significant mask octet */
7964 for (i = 0; i < vec_len (mask); i++)
7968 /* compute (skip, match) params */
7969 *skipp = i / sizeof (u32x4);
7970 vec_delete (mask, *skipp * sizeof (u32x4), 0);
7972 /* Pad mask to an even multiple of the vector size */
7973 while (vec_len (mask) % sizeof (u32x4))
7976 match = vec_len (mask) / sizeof (u32x4);
7978 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
7980 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
7981 if (*tmp || *(tmp + 1))
7986 clib_warning ("BUG: match 0");
7988 _vec_len (mask) = match * sizeof (u32x4);
7998 #endif /* VPP_API_TEST_BUILTIN */
8000 #define foreach_l2_next \
8002 _(ethernet, ETHERNET_INPUT) \
8007 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8009 u32 *miss_next_indexp = va_arg (*args, u32 *);
8014 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8018 if (unformat (input, "%d", &tmp))
8027 *miss_next_indexp = next_index;
8031 #define foreach_ip_next \
8037 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8039 u32 *miss_next_indexp = va_arg (*args, u32 *);
8044 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8048 if (unformat (input, "%d", &tmp))
8057 *miss_next_indexp = next_index;
8061 #define foreach_acl_next \
8065 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8067 u32 *miss_next_indexp = va_arg (*args, u32 *);
8072 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8076 if (unformat (input, "permit"))
8081 else if (unformat (input, "%d", &tmp))
8090 *miss_next_indexp = next_index;
8095 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8097 u32 *r = va_arg (*args, u32 *);
8099 if (unformat (input, "conform-color"))
8100 *r = POLICE_CONFORM;
8101 else if (unformat (input, "exceed-color"))
8110 api_classify_add_del_table (vat_main_t * vam)
8112 unformat_input_t *i = vam->input;
8113 vl_api_classify_add_del_table_t *mp;
8120 u32 table_index = ~0;
8121 u32 next_table_index = ~0;
8122 u32 miss_next_index = ~0;
8123 u32 memory_size = 32 << 20;
8125 u32 current_data_flag = 0;
8126 int current_data_offset = 0;
8129 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8131 if (unformat (i, "del"))
8133 else if (unformat (i, "del-chain"))
8138 else if (unformat (i, "buckets %d", &nbuckets))
8140 else if (unformat (i, "memory_size %d", &memory_size))
8142 else if (unformat (i, "skip %d", &skip))
8144 else if (unformat (i, "match %d", &match))
8146 else if (unformat (i, "table %d", &table_index))
8148 else if (unformat (i, "mask %U", unformat_classify_mask,
8149 &mask, &skip, &match))
8151 else if (unformat (i, "next-table %d", &next_table_index))
8153 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8156 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8159 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8162 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8164 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8170 if (is_add && mask == 0)
8172 errmsg ("Mask required");
8176 if (is_add && skip == ~0)
8178 errmsg ("skip count required");
8182 if (is_add && match == ~0)
8184 errmsg ("match count required");
8188 if (!is_add && table_index == ~0)
8190 errmsg ("table index required for delete");
8194 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8196 mp->is_add = is_add;
8197 mp->del_chain = del_chain;
8198 mp->table_index = ntohl (table_index);
8199 mp->nbuckets = ntohl (nbuckets);
8200 mp->memory_size = ntohl (memory_size);
8201 mp->skip_n_vectors = ntohl (skip);
8202 mp->match_n_vectors = ntohl (match);
8203 mp->next_table_index = ntohl (next_table_index);
8204 mp->miss_next_index = ntohl (miss_next_index);
8205 mp->current_data_flag = ntohl (current_data_flag);
8206 mp->current_data_offset = ntohl (current_data_offset);
8207 mp->mask_len = ntohl (vec_len (mask));
8208 clib_memcpy (mp->mask, mask, vec_len (mask));
8217 #if VPP_API_TEST_BUILTIN == 0
8219 unformat_l4_match (unformat_input_t * input, va_list * args)
8221 u8 **matchp = va_arg (*args, u8 **);
8223 u8 *proto_header = 0;
8229 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8231 if (unformat (input, "src_port %d", &src_port))
8233 else if (unformat (input, "dst_port %d", &dst_port))
8239 h.src_port = clib_host_to_net_u16 (src_port);
8240 h.dst_port = clib_host_to_net_u16 (dst_port);
8241 vec_validate (proto_header, sizeof (h) - 1);
8242 memcpy (proto_header, &h, sizeof (h));
8244 *matchp = proto_header;
8250 unformat_ip4_match (unformat_input_t * input, va_list * args)
8252 u8 **matchp = va_arg (*args, u8 **);
8259 int src = 0, dst = 0;
8260 ip4_address_t src_val, dst_val;
8267 int fragment_id = 0;
8268 u32 fragment_id_val;
8274 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8276 if (unformat (input, "version %d", &version_val))
8278 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8280 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8282 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8284 else if (unformat (input, "proto %d", &proto_val))
8286 else if (unformat (input, "tos %d", &tos_val))
8288 else if (unformat (input, "length %d", &length_val))
8290 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8292 else if (unformat (input, "ttl %d", &ttl_val))
8294 else if (unformat (input, "checksum %d", &checksum_val))
8300 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8301 + ttl + checksum == 0)
8305 * Aligned because we use the real comparison functions
8307 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8309 ip = (ip4_header_t *) match;
8311 /* These are realistically matched in practice */
8313 ip->src_address.as_u32 = src_val.as_u32;
8316 ip->dst_address.as_u32 = dst_val.as_u32;
8319 ip->protocol = proto_val;
8322 /* These are not, but they're included for completeness */
8324 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8327 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8333 ip->length = clib_host_to_net_u16 (length_val);
8339 ip->checksum = clib_host_to_net_u16 (checksum_val);
8346 unformat_ip6_match (unformat_input_t * input, va_list * args)
8348 u8 **matchp = va_arg (*args, u8 **);
8353 u8 traffic_class = 0;
8354 u32 traffic_class_val = 0;
8357 int src = 0, dst = 0;
8358 ip6_address_t src_val, dst_val;
8361 int payload_length = 0;
8362 u32 payload_length_val;
8365 u32 ip_version_traffic_class_and_flow_label;
8367 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8369 if (unformat (input, "version %d", &version_val))
8371 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8373 else if (unformat (input, "flow_label %d", &flow_label_val))
8375 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8377 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8379 else if (unformat (input, "proto %d", &proto_val))
8381 else if (unformat (input, "payload_length %d", &payload_length_val))
8383 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8389 if (version + traffic_class + flow_label + src + dst + proto +
8390 payload_length + hop_limit == 0)
8394 * Aligned because we use the real comparison functions
8396 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8398 ip = (ip6_header_t *) match;
8401 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8404 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8407 ip->protocol = proto_val;
8409 ip_version_traffic_class_and_flow_label = 0;
8412 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8415 ip_version_traffic_class_and_flow_label |=
8416 (traffic_class_val & 0xFF) << 20;
8419 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8421 ip->ip_version_traffic_class_and_flow_label =
8422 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8425 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8428 ip->hop_limit = hop_limit_val;
8435 unformat_l3_match (unformat_input_t * input, va_list * args)
8437 u8 **matchp = va_arg (*args, u8 **);
8439 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8441 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8443 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8452 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8454 u8 *tagp = va_arg (*args, u8 *);
8457 if (unformat (input, "%d", &tag))
8459 tagp[0] = (tag >> 8) & 0x0F;
8460 tagp[1] = tag & 0xFF;
8468 unformat_l2_match (unformat_input_t * input, va_list * args)
8470 u8 **matchp = va_arg (*args, u8 **);
8490 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8492 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8495 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8497 else if (unformat (input, "proto %U",
8498 unformat_ethernet_type_host_byte_order, &proto_val))
8500 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8502 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8504 else if (unformat (input, "ignore-tag1"))
8506 else if (unformat (input, "ignore-tag2"))
8508 else if (unformat (input, "cos1 %d", &cos1_val))
8510 else if (unformat (input, "cos2 %d", &cos2_val))
8515 if ((src + dst + proto + tag1 + tag2 +
8516 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8519 if (tag1 || ignore_tag1 || cos1)
8521 if (tag2 || ignore_tag2 || cos2)
8524 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8527 clib_memcpy (match, dst_val, 6);
8530 clib_memcpy (match + 6, src_val, 6);
8534 /* inner vlan tag */
8535 match[19] = tag2_val[1];
8536 match[18] = tag2_val[0];
8538 match[18] |= (cos2_val & 0x7) << 5;
8541 match[21] = proto_val & 0xff;
8542 match[20] = proto_val >> 8;
8546 match[15] = tag1_val[1];
8547 match[14] = tag1_val[0];
8550 match[14] |= (cos1_val & 0x7) << 5;
8556 match[15] = tag1_val[1];
8557 match[14] = tag1_val[0];
8560 match[17] = proto_val & 0xff;
8561 match[16] = proto_val >> 8;
8564 match[14] |= (cos1_val & 0x7) << 5;
8570 match[18] |= (cos2_val & 0x7) << 5;
8572 match[14] |= (cos1_val & 0x7) << 5;
8575 match[13] = proto_val & 0xff;
8576 match[12] = proto_val >> 8;
8584 unformat_qos_source (unformat_input_t * input, va_list * args)
8586 int *qs = va_arg (*args, int *);
8588 if (unformat (input, "ip"))
8589 *qs = QOS_SOURCE_IP;
8590 else if (unformat (input, "mpls"))
8591 *qs = QOS_SOURCE_MPLS;
8592 else if (unformat (input, "ext"))
8593 *qs = QOS_SOURCE_EXT;
8594 else if (unformat (input, "vlan"))
8595 *qs = QOS_SOURCE_VLAN;
8604 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8606 u8 **matchp = va_arg (*args, u8 **);
8607 u32 skip_n_vectors = va_arg (*args, u32);
8608 u32 match_n_vectors = va_arg (*args, u32);
8615 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8617 if (unformat (input, "hex %U", unformat_hex_string, &match))
8619 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8621 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8623 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8637 if (match || l2 || l3 || l4)
8641 /* "Win a free Ethernet header in every packet" */
8643 vec_validate_aligned (l2, 13, sizeof (u32x4));
8647 vec_append_aligned (match, l3, sizeof (u32x4));
8652 vec_append_aligned (match, l4, sizeof (u32x4));
8657 /* Make sure the vector is big enough even if key is all 0's */
8658 vec_validate_aligned
8659 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8662 /* Set size, include skipped vectors */
8663 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8674 api_classify_add_del_session (vat_main_t * vam)
8676 unformat_input_t *i = vam->input;
8677 vl_api_classify_add_del_session_t *mp;
8679 u32 table_index = ~0;
8680 u32 hit_next_index = ~0;
8681 u32 opaque_index = ~0;
8684 u32 skip_n_vectors = 0;
8685 u32 match_n_vectors = 0;
8691 * Warning: you have to supply skip_n and match_n
8692 * because the API client cant simply look at the classify
8696 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8698 if (unformat (i, "del"))
8700 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8703 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8706 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8709 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8711 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8713 else if (unformat (i, "opaque-index %d", &opaque_index))
8715 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8717 else if (unformat (i, "match_n %d", &match_n_vectors))
8719 else if (unformat (i, "match %U", api_unformat_classify_match,
8720 &match, skip_n_vectors, match_n_vectors))
8722 else if (unformat (i, "advance %d", &advance))
8724 else if (unformat (i, "table-index %d", &table_index))
8726 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8728 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8730 else if (unformat (i, "action %d", &action))
8732 else if (unformat (i, "metadata %d", &metadata))
8738 if (table_index == ~0)
8740 errmsg ("Table index required");
8744 if (is_add && match == 0)
8746 errmsg ("Match value required");
8750 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8752 mp->is_add = is_add;
8753 mp->table_index = ntohl (table_index);
8754 mp->hit_next_index = ntohl (hit_next_index);
8755 mp->opaque_index = ntohl (opaque_index);
8756 mp->advance = ntohl (advance);
8757 mp->action = action;
8758 mp->metadata = ntohl (metadata);
8759 mp->match_len = ntohl (vec_len (match));
8760 clib_memcpy (mp->match, match, vec_len (match));
8769 api_classify_set_interface_ip_table (vat_main_t * vam)
8771 unformat_input_t *i = vam->input;
8772 vl_api_classify_set_interface_ip_table_t *mp;
8774 int sw_if_index_set;
8775 u32 table_index = ~0;
8779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8781 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8782 sw_if_index_set = 1;
8783 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8784 sw_if_index_set = 1;
8785 else if (unformat (i, "table %d", &table_index))
8789 clib_warning ("parse error '%U'", format_unformat_error, i);
8794 if (sw_if_index_set == 0)
8796 errmsg ("missing interface name or sw_if_index");
8801 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8803 mp->sw_if_index = ntohl (sw_if_index);
8804 mp->table_index = ntohl (table_index);
8805 mp->is_ipv6 = is_ipv6;
8813 api_classify_set_interface_l2_tables (vat_main_t * vam)
8815 unformat_input_t *i = vam->input;
8816 vl_api_classify_set_interface_l2_tables_t *mp;
8818 int sw_if_index_set;
8819 u32 ip4_table_index = ~0;
8820 u32 ip6_table_index = ~0;
8821 u32 other_table_index = ~0;
8825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8827 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8828 sw_if_index_set = 1;
8829 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8830 sw_if_index_set = 1;
8831 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8833 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8835 else if (unformat (i, "other-table %d", &other_table_index))
8837 else if (unformat (i, "is-input %d", &is_input))
8841 clib_warning ("parse error '%U'", format_unformat_error, i);
8846 if (sw_if_index_set == 0)
8848 errmsg ("missing interface name or sw_if_index");
8853 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8855 mp->sw_if_index = ntohl (sw_if_index);
8856 mp->ip4_table_index = ntohl (ip4_table_index);
8857 mp->ip6_table_index = ntohl (ip6_table_index);
8858 mp->other_table_index = ntohl (other_table_index);
8859 mp->is_input = (u8) is_input;
8867 api_set_ipfix_exporter (vat_main_t * vam)
8869 unformat_input_t *i = vam->input;
8870 vl_api_set_ipfix_exporter_t *mp;
8871 ip4_address_t collector_address;
8872 u8 collector_address_set = 0;
8873 u32 collector_port = ~0;
8874 ip4_address_t src_address;
8875 u8 src_address_set = 0;
8878 u32 template_interval = ~0;
8879 u8 udp_checksum = 0;
8882 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8884 if (unformat (i, "collector_address %U", unformat_ip4_address,
8885 &collector_address))
8886 collector_address_set = 1;
8887 else if (unformat (i, "collector_port %d", &collector_port))
8889 else if (unformat (i, "src_address %U", unformat_ip4_address,
8891 src_address_set = 1;
8892 else if (unformat (i, "vrf_id %d", &vrf_id))
8894 else if (unformat (i, "path_mtu %d", &path_mtu))
8896 else if (unformat (i, "template_interval %d", &template_interval))
8898 else if (unformat (i, "udp_checksum"))
8904 if (collector_address_set == 0)
8906 errmsg ("collector_address required");
8910 if (src_address_set == 0)
8912 errmsg ("src_address required");
8916 M (SET_IPFIX_EXPORTER, mp);
8918 memcpy (mp->collector_address.un.ip4, collector_address.data,
8919 sizeof (collector_address.data));
8920 mp->collector_port = htons ((u16) collector_port);
8921 memcpy (mp->src_address.un.ip4, src_address.data,
8922 sizeof (src_address.data));
8923 mp->vrf_id = htonl (vrf_id);
8924 mp->path_mtu = htonl (path_mtu);
8925 mp->template_interval = htonl (template_interval);
8926 mp->udp_checksum = udp_checksum;
8934 api_set_ipfix_classify_stream (vat_main_t * vam)
8936 unformat_input_t *i = vam->input;
8937 vl_api_set_ipfix_classify_stream_t *mp;
8939 u32 src_port = UDP_DST_PORT_ipfix;
8942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8944 if (unformat (i, "domain %d", &domain_id))
8946 else if (unformat (i, "src_port %d", &src_port))
8950 errmsg ("unknown input `%U'", format_unformat_error, i);
8955 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8957 mp->domain_id = htonl (domain_id);
8958 mp->src_port = htons ((u16) src_port);
8966 api_ipfix_classify_table_add_del (vat_main_t * vam)
8968 unformat_input_t *i = vam->input;
8969 vl_api_ipfix_classify_table_add_del_t *mp;
8971 u32 classify_table_index = ~0;
8973 u8 transport_protocol = 255;
8976 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8978 if (unformat (i, "add"))
8980 else if (unformat (i, "del"))
8982 else if (unformat (i, "table %d", &classify_table_index))
8984 else if (unformat (i, "ip4"))
8986 else if (unformat (i, "ip6"))
8988 else if (unformat (i, "tcp"))
8989 transport_protocol = 6;
8990 else if (unformat (i, "udp"))
8991 transport_protocol = 17;
8994 errmsg ("unknown input `%U'", format_unformat_error, i);
9001 errmsg ("expecting: add|del");
9004 if (classify_table_index == ~0)
9006 errmsg ("classifier table not specified");
9009 if (ip_version == 0)
9011 errmsg ("IP version not specified");
9015 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9017 mp->is_add = is_add;
9018 mp->table_id = htonl (classify_table_index);
9019 mp->ip_version = ip_version;
9020 mp->transport_protocol = transport_protocol;
9028 api_get_node_index (vat_main_t * vam)
9030 unformat_input_t *i = vam->input;
9031 vl_api_get_node_index_t *mp;
9035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9037 if (unformat (i, "node %s", &name))
9044 errmsg ("node name required");
9047 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9049 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9053 M (GET_NODE_INDEX, mp);
9054 clib_memcpy (mp->node_name, name, vec_len (name));
9063 api_get_next_index (vat_main_t * vam)
9065 unformat_input_t *i = vam->input;
9066 vl_api_get_next_index_t *mp;
9067 u8 *node_name = 0, *next_node_name = 0;
9070 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9072 if (unformat (i, "node-name %s", &node_name))
9074 else if (unformat (i, "next-node-name %s", &next_node_name))
9080 errmsg ("node name required");
9083 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9085 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9089 if (next_node_name == 0)
9091 errmsg ("next node name required");
9094 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9096 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9100 M (GET_NEXT_INDEX, mp);
9101 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9102 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9103 vec_free (node_name);
9104 vec_free (next_node_name);
9112 api_add_node_next (vat_main_t * vam)
9114 unformat_input_t *i = vam->input;
9115 vl_api_add_node_next_t *mp;
9120 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9122 if (unformat (i, "node %s", &name))
9124 else if (unformat (i, "next %s", &next))
9131 errmsg ("node name required");
9134 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9136 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9141 errmsg ("next node required");
9144 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9146 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9150 M (ADD_NODE_NEXT, mp);
9151 clib_memcpy (mp->node_name, name, vec_len (name));
9152 clib_memcpy (mp->next_name, next, vec_len (next));
9161 static void vl_api_sw_interface_tap_v2_details_t_handler
9162 (vl_api_sw_interface_tap_v2_details_t * mp)
9164 vat_main_t *vam = &vat_main;
9167 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9168 mp->host_ip4_prefix.len);
9170 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9171 mp->host_ip6_prefix.len);
9174 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9175 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9176 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9177 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9178 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9184 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9185 (vl_api_sw_interface_tap_v2_details_t * mp)
9187 vat_main_t *vam = &vat_main;
9188 vat_json_node_t *node = NULL;
9190 if (VAT_JSON_ARRAY != vam->json_tree.type)
9192 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9193 vat_json_init_array (&vam->json_tree);
9195 node = vat_json_array_add (&vam->json_tree);
9197 vat_json_init_object (node);
9198 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9199 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9200 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9201 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9202 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9203 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9204 vat_json_object_add_string_copy (node, "host_mac_addr",
9205 format (0, "%U", format_ethernet_address,
9206 &mp->host_mac_addr));
9207 vat_json_object_add_string_copy (node, "host_namespace",
9208 mp->host_namespace);
9209 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9210 vat_json_object_add_string_copy (node, "host_ip4_addr",
9211 format (0, "%U/%d", format_ip4_address,
9212 mp->host_ip4_prefix.address,
9213 mp->host_ip4_prefix.len));
9214 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9215 format (0, "%U/%d", format_ip6_address,
9216 mp->host_ip6_prefix.address,
9217 mp->host_ip6_prefix.len));
9222 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9224 vl_api_sw_interface_tap_v2_dump_t *mp;
9225 vl_api_control_ping_t *mp_ping;
9229 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9230 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9231 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9234 /* Get list of tap interfaces */
9235 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9238 /* Use a control ping for synchronization */
9239 MPING (CONTROL_PING, mp_ping);
9246 static void vl_api_sw_interface_virtio_pci_details_t_handler
9247 (vl_api_sw_interface_virtio_pci_details_t * mp)
9249 vat_main_t *vam = &vat_main;
9264 addr.domain = ntohs (mp->pci_addr.domain);
9265 addr.bus = mp->pci_addr.bus;
9266 addr.slot = mp->pci_addr.slot;
9267 addr.function = mp->pci_addr.function;
9269 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9270 addr.slot, addr.function);
9273 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9274 pci_addr, ntohl (mp->sw_if_index),
9275 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9276 format_ethernet_address, mp->mac_addr,
9277 clib_net_to_host_u64 (mp->features));
9278 vec_free (pci_addr);
9281 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9282 (vl_api_sw_interface_virtio_pci_details_t * mp)
9284 vat_main_t *vam = &vat_main;
9285 vat_json_node_t *node = NULL;
9286 vlib_pci_addr_t pci_addr;
9288 if (VAT_JSON_ARRAY != vam->json_tree.type)
9290 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9291 vat_json_init_array (&vam->json_tree);
9293 node = vat_json_array_add (&vam->json_tree);
9295 pci_addr.domain = ntohs (mp->pci_addr.domain);
9296 pci_addr.bus = mp->pci_addr.bus;
9297 pci_addr.slot = mp->pci_addr.slot;
9298 pci_addr.function = mp->pci_addr.function;
9300 vat_json_init_object (node);
9301 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9302 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9303 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9304 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9305 vat_json_object_add_uint (node, "features",
9306 clib_net_to_host_u64 (mp->features));
9307 vat_json_object_add_string_copy (node, "mac_addr",
9308 format (0, "%U", format_ethernet_address,
9313 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9315 vl_api_sw_interface_virtio_pci_dump_t *mp;
9316 vl_api_control_ping_t *mp_ping;
9320 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9321 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9322 "mac_addr", "features");
9324 /* Get list of tap interfaces */
9325 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9328 /* Use a control ping for synchronization */
9329 MPING (CONTROL_PING, mp_ping);
9337 api_vxlan_offload_rx (vat_main_t * vam)
9339 unformat_input_t *line_input = vam->input;
9340 vl_api_vxlan_offload_rx_t *mp;
9341 u32 hw_if_index = ~0, rx_if_index = ~0;
9345 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9347 if (unformat (line_input, "del"))
9349 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9352 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9354 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9357 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9361 errmsg ("parse error '%U'", format_unformat_error, line_input);
9366 if (hw_if_index == ~0)
9368 errmsg ("no hw interface");
9372 if (rx_if_index == ~0)
9374 errmsg ("no rx tunnel");
9378 M (VXLAN_OFFLOAD_RX, mp);
9380 mp->hw_if_index = ntohl (hw_if_index);
9381 mp->sw_if_index = ntohl (rx_if_index);
9382 mp->enable = is_add;
9389 static uword unformat_vxlan_decap_next
9390 (unformat_input_t * input, va_list * args)
9392 u32 *result = va_arg (*args, u32 *);
9395 if (unformat (input, "l2"))
9396 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9397 else if (unformat (input, "%d", &tmp))
9405 api_vxlan_add_del_tunnel (vat_main_t * vam)
9407 unformat_input_t *line_input = vam->input;
9408 vl_api_vxlan_add_del_tunnel_t *mp;
9409 ip46_address_t src, dst;
9411 u8 ipv4_set = 0, ipv6_set = 0;
9416 u32 mcast_sw_if_index = ~0;
9417 u32 encap_vrf_id = 0;
9418 u32 decap_next_index = ~0;
9422 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9423 clib_memset (&src, 0, sizeof src);
9424 clib_memset (&dst, 0, sizeof dst);
9426 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9428 if (unformat (line_input, "del"))
9430 else if (unformat (line_input, "instance %d", &instance))
9433 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9439 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9445 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9451 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9456 else if (unformat (line_input, "group %U %U",
9457 unformat_ip4_address, &dst.ip4,
9458 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9460 grp_set = dst_set = 1;
9463 else if (unformat (line_input, "group %U",
9464 unformat_ip4_address, &dst.ip4))
9466 grp_set = dst_set = 1;
9469 else if (unformat (line_input, "group %U %U",
9470 unformat_ip6_address, &dst.ip6,
9471 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9473 grp_set = dst_set = 1;
9476 else if (unformat (line_input, "group %U",
9477 unformat_ip6_address, &dst.ip6))
9479 grp_set = dst_set = 1;
9483 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9485 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9487 else if (unformat (line_input, "decap-next %U",
9488 unformat_vxlan_decap_next, &decap_next_index))
9490 else if (unformat (line_input, "vni %d", &vni))
9494 errmsg ("parse error '%U'", format_unformat_error, line_input);
9501 errmsg ("tunnel src address not specified");
9506 errmsg ("tunnel dst address not specified");
9510 if (grp_set && !ip46_address_is_multicast (&dst))
9512 errmsg ("tunnel group address not multicast");
9515 if (grp_set && mcast_sw_if_index == ~0)
9517 errmsg ("tunnel nonexistent multicast device");
9520 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9522 errmsg ("tunnel dst address must be unicast");
9527 if (ipv4_set && ipv6_set)
9529 errmsg ("both IPv4 and IPv6 addresses specified");
9533 if ((vni == 0) || (vni >> 24))
9535 errmsg ("vni not specified or out of range");
9539 M (VXLAN_ADD_DEL_TUNNEL, mp);
9543 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9544 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9548 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9549 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9551 mp->src_address.af = ipv6_set;
9552 mp->dst_address.af = ipv6_set;
9554 mp->instance = htonl (instance);
9555 mp->encap_vrf_id = ntohl (encap_vrf_id);
9556 mp->decap_next_index = ntohl (decap_next_index);
9557 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9558 mp->vni = ntohl (vni);
9559 mp->is_add = is_add;
9566 static void vl_api_vxlan_tunnel_details_t_handler
9567 (vl_api_vxlan_tunnel_details_t * mp)
9569 vat_main_t *vam = &vat_main;
9570 ip46_address_t src =
9571 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9572 ip46_address_t dst =
9573 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9575 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9576 ntohl (mp->sw_if_index),
9577 ntohl (mp->instance),
9578 format_ip46_address, &src, IP46_TYPE_ANY,
9579 format_ip46_address, &dst, IP46_TYPE_ANY,
9580 ntohl (mp->encap_vrf_id),
9581 ntohl (mp->decap_next_index), ntohl (mp->vni),
9582 ntohl (mp->mcast_sw_if_index));
9585 static void vl_api_vxlan_tunnel_details_t_handler_json
9586 (vl_api_vxlan_tunnel_details_t * mp)
9588 vat_main_t *vam = &vat_main;
9589 vat_json_node_t *node = NULL;
9591 if (VAT_JSON_ARRAY != vam->json_tree.type)
9593 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9594 vat_json_init_array (&vam->json_tree);
9596 node = vat_json_array_add (&vam->json_tree);
9598 vat_json_init_object (node);
9599 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9601 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9603 if (mp->src_address.af)
9605 struct in6_addr ip6;
9607 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9608 vat_json_object_add_ip6 (node, "src_address", ip6);
9609 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9610 vat_json_object_add_ip6 (node, "dst_address", ip6);
9616 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9617 vat_json_object_add_ip4 (node, "src_address", ip4);
9618 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9619 vat_json_object_add_ip4 (node, "dst_address", ip4);
9621 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9622 vat_json_object_add_uint (node, "decap_next_index",
9623 ntohl (mp->decap_next_index));
9624 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9625 vat_json_object_add_uint (node, "mcast_sw_if_index",
9626 ntohl (mp->mcast_sw_if_index));
9630 api_vxlan_tunnel_dump (vat_main_t * vam)
9632 unformat_input_t *i = vam->input;
9633 vl_api_vxlan_tunnel_dump_t *mp;
9634 vl_api_control_ping_t *mp_ping;
9636 u8 sw_if_index_set = 0;
9639 /* Parse args required to build the message */
9640 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9642 if (unformat (i, "sw_if_index %d", &sw_if_index))
9643 sw_if_index_set = 1;
9648 if (sw_if_index_set == 0)
9653 if (!vam->json_output)
9655 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9656 "sw_if_index", "instance", "src_address", "dst_address",
9657 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9660 /* Get list of vxlan-tunnel interfaces */
9661 M (VXLAN_TUNNEL_DUMP, mp);
9663 mp->sw_if_index = htonl (sw_if_index);
9667 /* Use a control ping for synchronization */
9668 MPING (CONTROL_PING, mp_ping);
9676 api_l2_fib_clear_table (vat_main_t * vam)
9678 // unformat_input_t * i = vam->input;
9679 vl_api_l2_fib_clear_table_t *mp;
9682 M (L2_FIB_CLEAR_TABLE, mp);
9690 api_l2_interface_efp_filter (vat_main_t * vam)
9692 unformat_input_t *i = vam->input;
9693 vl_api_l2_interface_efp_filter_t *mp;
9696 u8 sw_if_index_set = 0;
9699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9701 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9702 sw_if_index_set = 1;
9703 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9704 sw_if_index_set = 1;
9705 else if (unformat (i, "enable"))
9707 else if (unformat (i, "disable"))
9711 clib_warning ("parse error '%U'", format_unformat_error, i);
9716 if (sw_if_index_set == 0)
9718 errmsg ("missing sw_if_index");
9722 M (L2_INTERFACE_EFP_FILTER, mp);
9724 mp->sw_if_index = ntohl (sw_if_index);
9725 mp->enable_disable = enable;
9732 #define foreach_vtr_op \
9733 _("disable", L2_VTR_DISABLED) \
9734 _("push-1", L2_VTR_PUSH_1) \
9735 _("push-2", L2_VTR_PUSH_2) \
9736 _("pop-1", L2_VTR_POP_1) \
9737 _("pop-2", L2_VTR_POP_2) \
9738 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9739 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9740 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9741 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9744 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9746 unformat_input_t *i = vam->input;
9747 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9749 u8 sw_if_index_set = 0;
9757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9759 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9760 sw_if_index_set = 1;
9761 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9762 sw_if_index_set = 1;
9763 else if (unformat (i, "vtr_op %d", &vtr_op))
9765 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9768 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9770 else if (unformat (i, "tag1 %d", &tag1))
9772 else if (unformat (i, "tag2 %d", &tag2))
9776 clib_warning ("parse error '%U'", format_unformat_error, i);
9781 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9783 errmsg ("missing vtr operation or sw_if_index");
9787 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9788 mp->sw_if_index = ntohl (sw_if_index);
9789 mp->vtr_op = ntohl (vtr_op);
9790 mp->push_dot1q = ntohl (push_dot1q);
9791 mp->tag1 = ntohl (tag1);
9792 mp->tag2 = ntohl (tag2);
9800 api_create_vhost_user_if (vat_main_t * vam)
9802 unformat_input_t *i = vam->input;
9803 vl_api_create_vhost_user_if_t *mp;
9806 u8 file_name_set = 0;
9807 u32 custom_dev_instance = ~0;
9809 u8 use_custom_mac = 0;
9810 u8 disable_mrg_rxbuf = 0;
9811 u8 disable_indirect_desc = 0;
9814 u8 enable_packed = 0;
9817 /* Shut up coverity */
9818 clib_memset (hwaddr, 0, sizeof (hwaddr));
9820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9822 if (unformat (i, "socket %s", &file_name))
9826 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9828 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9830 else if (unformat (i, "server"))
9832 else if (unformat (i, "disable_mrg_rxbuf"))
9833 disable_mrg_rxbuf = 1;
9834 else if (unformat (i, "disable_indirect_desc"))
9835 disable_indirect_desc = 1;
9836 else if (unformat (i, "gso"))
9838 else if (unformat (i, "packed"))
9840 else if (unformat (i, "tag %s", &tag))
9846 if (file_name_set == 0)
9848 errmsg ("missing socket file name");
9852 if (vec_len (file_name) > 255)
9854 errmsg ("socket file name too long");
9857 vec_add1 (file_name, 0);
9859 M (CREATE_VHOST_USER_IF, mp);
9861 mp->is_server = is_server;
9862 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9863 mp->disable_indirect_desc = disable_indirect_desc;
9864 mp->enable_gso = enable_gso;
9865 mp->enable_packed = enable_packed;
9866 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9867 vec_free (file_name);
9868 if (custom_dev_instance != ~0)
9871 mp->custom_dev_instance = ntohl (custom_dev_instance);
9874 mp->use_custom_mac = use_custom_mac;
9875 clib_memcpy (mp->mac_address, hwaddr, 6);
9877 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9886 api_modify_vhost_user_if (vat_main_t * vam)
9888 unformat_input_t *i = vam->input;
9889 vl_api_modify_vhost_user_if_t *mp;
9892 u8 file_name_set = 0;
9893 u32 custom_dev_instance = ~0;
9894 u8 sw_if_index_set = 0;
9895 u32 sw_if_index = (u32) ~ 0;
9897 u8 enable_packed = 0;
9900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9902 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9903 sw_if_index_set = 1;
9904 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9905 sw_if_index_set = 1;
9906 else if (unformat (i, "socket %s", &file_name))
9910 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9912 else if (unformat (i, "server"))
9914 else if (unformat (i, "gso"))
9916 else if (unformat (i, "packed"))
9922 if (sw_if_index_set == 0)
9924 errmsg ("missing sw_if_index or interface name");
9928 if (file_name_set == 0)
9930 errmsg ("missing socket file name");
9934 if (vec_len (file_name) > 255)
9936 errmsg ("socket file name too long");
9939 vec_add1 (file_name, 0);
9941 M (MODIFY_VHOST_USER_IF, mp);
9943 mp->sw_if_index = ntohl (sw_if_index);
9944 mp->is_server = is_server;
9945 mp->enable_gso = enable_gso;
9946 mp->enable_packed = enable_packed;
9947 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9948 vec_free (file_name);
9949 if (custom_dev_instance != ~0)
9952 mp->custom_dev_instance = ntohl (custom_dev_instance);
9961 api_delete_vhost_user_if (vat_main_t * vam)
9963 unformat_input_t *i = vam->input;
9964 vl_api_delete_vhost_user_if_t *mp;
9965 u32 sw_if_index = ~0;
9966 u8 sw_if_index_set = 0;
9969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9971 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9972 sw_if_index_set = 1;
9973 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9974 sw_if_index_set = 1;
9979 if (sw_if_index_set == 0)
9981 errmsg ("missing sw_if_index or interface name");
9986 M (DELETE_VHOST_USER_IF, mp);
9988 mp->sw_if_index = ntohl (sw_if_index);
9995 static void vl_api_sw_interface_vhost_user_details_t_handler
9996 (vl_api_sw_interface_vhost_user_details_t * mp)
9998 vat_main_t *vam = &vat_main;
10002 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10003 clib_net_to_host_u32
10004 (mp->features_last_32) <<
10007 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
10008 (char *) mp->interface_name,
10009 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10010 features, mp->is_server,
10011 ntohl (mp->num_regions), (char *) mp->sock_filename);
10012 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10015 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10016 (vl_api_sw_interface_vhost_user_details_t * mp)
10018 vat_main_t *vam = &vat_main;
10019 vat_json_node_t *node = NULL;
10021 if (VAT_JSON_ARRAY != vam->json_tree.type)
10023 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10024 vat_json_init_array (&vam->json_tree);
10026 node = vat_json_array_add (&vam->json_tree);
10028 vat_json_init_object (node);
10029 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10030 vat_json_object_add_string_copy (node, "interface_name",
10031 mp->interface_name);
10032 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10033 ntohl (mp->virtio_net_hdr_sz));
10034 vat_json_object_add_uint (node, "features_first_32",
10035 clib_net_to_host_u32 (mp->features_first_32));
10036 vat_json_object_add_uint (node, "features_last_32",
10037 clib_net_to_host_u32 (mp->features_last_32));
10038 vat_json_object_add_uint (node, "is_server", mp->is_server);
10039 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10040 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10041 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10045 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10047 unformat_input_t *i = vam->input;
10048 vl_api_sw_interface_vhost_user_dump_t *mp;
10049 vl_api_control_ping_t *mp_ping;
10051 u32 sw_if_index = ~0;
10053 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10055 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10057 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10064 "Interface name idx hdr_sz features server regions filename");
10066 /* Get list of vhost-user interfaces */
10067 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10068 mp->sw_if_index = ntohl (sw_if_index);
10071 /* Use a control ping for synchronization */
10072 MPING (CONTROL_PING, mp_ping);
10080 api_show_version (vat_main_t * vam)
10082 vl_api_show_version_t *mp;
10085 M (SHOW_VERSION, mp);
10094 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10096 unformat_input_t *line_input = vam->input;
10097 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10098 ip46_address_t local, remote;
10103 u32 mcast_sw_if_index = ~0;
10104 u32 encap_vrf_id = 0;
10105 u32 decap_vrf_id = 0;
10111 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10113 if (unformat (line_input, "del"))
10115 else if (unformat (line_input, "local %U",
10116 unformat_ip46_address, &local))
10120 else if (unformat (line_input, "remote %U",
10121 unformat_ip46_address, &remote))
10125 else if (unformat (line_input, "group %U %U",
10126 unformat_ip46_address, &remote,
10127 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10129 grp_set = remote_set = 1;
10131 else if (unformat (line_input, "group %U",
10132 unformat_ip46_address, &remote))
10134 grp_set = remote_set = 1;
10137 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10139 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10141 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10143 else if (unformat (line_input, "vni %d", &vni))
10145 else if (unformat (line_input, "next-ip4"))
10147 else if (unformat (line_input, "next-ip6"))
10149 else if (unformat (line_input, "next-ethernet"))
10151 else if (unformat (line_input, "next-nsh"))
10155 errmsg ("parse error '%U'", format_unformat_error, line_input);
10160 if (local_set == 0)
10162 errmsg ("tunnel local address not specified");
10165 if (remote_set == 0)
10167 errmsg ("tunnel remote address not specified");
10170 if (grp_set && mcast_sw_if_index == ~0)
10172 errmsg ("tunnel nonexistent multicast device");
10175 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10177 errmsg ("both IPv4 and IPv6 addresses specified");
10183 errmsg ("vni not specified");
10187 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10189 ip_address_encode (&local,
10190 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10191 IP46_TYPE_IP6, &mp->local);
10192 ip_address_encode (&remote,
10193 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10194 IP46_TYPE_IP6, &mp->remote);
10196 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10197 mp->encap_vrf_id = ntohl (encap_vrf_id);
10198 mp->decap_vrf_id = ntohl (decap_vrf_id);
10199 mp->protocol = protocol;
10200 mp->vni = ntohl (vni);
10201 mp->is_add = is_add;
10208 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10209 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10211 vat_main_t *vam = &vat_main;
10212 ip46_address_t local, remote;
10214 ip_address_decode (&mp->local, &local);
10215 ip_address_decode (&mp->remote, &remote);
10217 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10218 ntohl (mp->sw_if_index),
10219 format_ip46_address, &local, IP46_TYPE_ANY,
10220 format_ip46_address, &remote, IP46_TYPE_ANY,
10221 ntohl (mp->vni), mp->protocol,
10222 ntohl (mp->mcast_sw_if_index),
10223 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10227 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10228 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10230 vat_main_t *vam = &vat_main;
10231 vat_json_node_t *node = NULL;
10232 struct in_addr ip4;
10233 struct in6_addr ip6;
10234 ip46_address_t local, remote;
10236 ip_address_decode (&mp->local, &local);
10237 ip_address_decode (&mp->remote, &remote);
10239 if (VAT_JSON_ARRAY != vam->json_tree.type)
10241 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10242 vat_json_init_array (&vam->json_tree);
10244 node = vat_json_array_add (&vam->json_tree);
10246 vat_json_init_object (node);
10247 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10248 if (ip46_address_is_ip4 (&local))
10250 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10251 vat_json_object_add_ip4 (node, "local", ip4);
10252 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10253 vat_json_object_add_ip4 (node, "remote", ip4);
10257 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10258 vat_json_object_add_ip6 (node, "local", ip6);
10259 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10260 vat_json_object_add_ip6 (node, "remote", ip6);
10262 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10263 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10264 vat_json_object_add_uint (node, "mcast_sw_if_index",
10265 ntohl (mp->mcast_sw_if_index));
10266 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10267 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10268 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10272 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10274 unformat_input_t *i = vam->input;
10275 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10276 vl_api_control_ping_t *mp_ping;
10278 u8 sw_if_index_set = 0;
10281 /* Parse args required to build the message */
10282 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10284 if (unformat (i, "sw_if_index %d", &sw_if_index))
10285 sw_if_index_set = 1;
10290 if (sw_if_index_set == 0)
10295 if (!vam->json_output)
10297 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10298 "sw_if_index", "local", "remote", "vni",
10299 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10302 /* Get list of vxlan-tunnel interfaces */
10303 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10305 mp->sw_if_index = htonl (sw_if_index);
10309 /* Use a control ping for synchronization */
10310 MPING (CONTROL_PING, mp_ping);
10317 static void vl_api_l2_fib_table_details_t_handler
10318 (vl_api_l2_fib_table_details_t * mp)
10320 vat_main_t *vam = &vat_main;
10322 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10324 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10325 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10329 static void vl_api_l2_fib_table_details_t_handler_json
10330 (vl_api_l2_fib_table_details_t * mp)
10332 vat_main_t *vam = &vat_main;
10333 vat_json_node_t *node = NULL;
10335 if (VAT_JSON_ARRAY != vam->json_tree.type)
10337 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10338 vat_json_init_array (&vam->json_tree);
10340 node = vat_json_array_add (&vam->json_tree);
10342 vat_json_init_object (node);
10343 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10344 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10345 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10346 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10347 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10348 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10352 api_l2_fib_table_dump (vat_main_t * vam)
10354 unformat_input_t *i = vam->input;
10355 vl_api_l2_fib_table_dump_t *mp;
10356 vl_api_control_ping_t *mp_ping;
10361 /* Parse args required to build the message */
10362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10364 if (unformat (i, "bd_id %d", &bd_id))
10370 if (bd_id_set == 0)
10372 errmsg ("missing bridge domain");
10376 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10378 /* Get list of l2 fib entries */
10379 M (L2_FIB_TABLE_DUMP, mp);
10381 mp->bd_id = ntohl (bd_id);
10384 /* Use a control ping for synchronization */
10385 MPING (CONTROL_PING, mp_ping);
10394 api_interface_name_renumber (vat_main_t * vam)
10396 unformat_input_t *line_input = vam->input;
10397 vl_api_interface_name_renumber_t *mp;
10398 u32 sw_if_index = ~0;
10399 u32 new_show_dev_instance = ~0;
10402 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10404 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10407 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10409 else if (unformat (line_input, "new_show_dev_instance %d",
10410 &new_show_dev_instance))
10416 if (sw_if_index == ~0)
10418 errmsg ("missing interface name or sw_if_index");
10422 if (new_show_dev_instance == ~0)
10424 errmsg ("missing new_show_dev_instance");
10428 M (INTERFACE_NAME_RENUMBER, mp);
10430 mp->sw_if_index = ntohl (sw_if_index);
10431 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10439 api_want_l2_macs_events (vat_main_t * vam)
10441 unformat_input_t *line_input = vam->input;
10442 vl_api_want_l2_macs_events_t *mp;
10443 u8 enable_disable = 1;
10444 u32 scan_delay = 0;
10445 u32 max_macs_in_event = 0;
10446 u32 learn_limit = 0;
10449 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10451 if (unformat (line_input, "learn-limit %d", &learn_limit))
10453 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10455 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10457 else if (unformat (line_input, "disable"))
10458 enable_disable = 0;
10463 M (WANT_L2_MACS_EVENTS, mp);
10464 mp->enable_disable = enable_disable;
10465 mp->pid = htonl (getpid ());
10466 mp->learn_limit = htonl (learn_limit);
10467 mp->scan_delay = (u8) scan_delay;
10468 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10475 api_input_acl_set_interface (vat_main_t * vam)
10477 unformat_input_t *i = vam->input;
10478 vl_api_input_acl_set_interface_t *mp;
10480 int sw_if_index_set;
10481 u32 ip4_table_index = ~0;
10482 u32 ip6_table_index = ~0;
10483 u32 l2_table_index = ~0;
10487 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10489 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10490 sw_if_index_set = 1;
10491 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10492 sw_if_index_set = 1;
10493 else if (unformat (i, "del"))
10495 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10497 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10499 else if (unformat (i, "l2-table %d", &l2_table_index))
10503 clib_warning ("parse error '%U'", format_unformat_error, i);
10508 if (sw_if_index_set == 0)
10510 errmsg ("missing interface name or sw_if_index");
10514 M (INPUT_ACL_SET_INTERFACE, mp);
10516 mp->sw_if_index = ntohl (sw_if_index);
10517 mp->ip4_table_index = ntohl (ip4_table_index);
10518 mp->ip6_table_index = ntohl (ip6_table_index);
10519 mp->l2_table_index = ntohl (l2_table_index);
10520 mp->is_add = is_add;
10528 api_output_acl_set_interface (vat_main_t * vam)
10530 unformat_input_t *i = vam->input;
10531 vl_api_output_acl_set_interface_t *mp;
10533 int sw_if_index_set;
10534 u32 ip4_table_index = ~0;
10535 u32 ip6_table_index = ~0;
10536 u32 l2_table_index = ~0;
10540 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10542 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10543 sw_if_index_set = 1;
10544 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10545 sw_if_index_set = 1;
10546 else if (unformat (i, "del"))
10548 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10550 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10552 else if (unformat (i, "l2-table %d", &l2_table_index))
10556 clib_warning ("parse error '%U'", format_unformat_error, i);
10561 if (sw_if_index_set == 0)
10563 errmsg ("missing interface name or sw_if_index");
10567 M (OUTPUT_ACL_SET_INTERFACE, mp);
10569 mp->sw_if_index = ntohl (sw_if_index);
10570 mp->ip4_table_index = ntohl (ip4_table_index);
10571 mp->ip6_table_index = ntohl (ip6_table_index);
10572 mp->l2_table_index = ntohl (l2_table_index);
10573 mp->is_add = is_add;
10581 api_ip_address_dump (vat_main_t * vam)
10583 unformat_input_t *i = vam->input;
10584 vl_api_ip_address_dump_t *mp;
10585 vl_api_control_ping_t *mp_ping;
10586 u32 sw_if_index = ~0;
10587 u8 sw_if_index_set = 0;
10592 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10594 if (unformat (i, "sw_if_index %d", &sw_if_index))
10595 sw_if_index_set = 1;
10597 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10598 sw_if_index_set = 1;
10599 else if (unformat (i, "ipv4"))
10601 else if (unformat (i, "ipv6"))
10607 if (ipv4_set && ipv6_set)
10609 errmsg ("ipv4 and ipv6 flags cannot be both set");
10613 if ((!ipv4_set) && (!ipv6_set))
10615 errmsg ("no ipv4 nor ipv6 flag set");
10619 if (sw_if_index_set == 0)
10621 errmsg ("missing interface name or sw_if_index");
10625 vam->current_sw_if_index = sw_if_index;
10626 vam->is_ipv6 = ipv6_set;
10628 M (IP_ADDRESS_DUMP, mp);
10629 mp->sw_if_index = ntohl (sw_if_index);
10630 mp->is_ipv6 = ipv6_set;
10633 /* Use a control ping for synchronization */
10634 MPING (CONTROL_PING, mp_ping);
10642 api_ip_dump (vat_main_t * vam)
10644 vl_api_ip_dump_t *mp;
10645 vl_api_control_ping_t *mp_ping;
10646 unformat_input_t *in = vam->input;
10653 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10655 if (unformat (in, "ipv4"))
10657 else if (unformat (in, "ipv6"))
10663 if (ipv4_set && ipv6_set)
10665 errmsg ("ipv4 and ipv6 flags cannot be both set");
10669 if ((!ipv4_set) && (!ipv6_set))
10671 errmsg ("no ipv4 nor ipv6 flag set");
10675 is_ipv6 = ipv6_set;
10676 vam->is_ipv6 = is_ipv6;
10678 /* free old data */
10679 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10681 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10683 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10686 mp->is_ipv6 = ipv6_set;
10689 /* Use a control ping for synchronization */
10690 MPING (CONTROL_PING, mp_ping);
10698 api_ipsec_spd_add_del (vat_main_t * vam)
10700 unformat_input_t *i = vam->input;
10701 vl_api_ipsec_spd_add_del_t *mp;
10706 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10708 if (unformat (i, "spd_id %d", &spd_id))
10710 else if (unformat (i, "del"))
10714 clib_warning ("parse error '%U'", format_unformat_error, i);
10720 errmsg ("spd_id must be set");
10724 M (IPSEC_SPD_ADD_DEL, mp);
10726 mp->spd_id = ntohl (spd_id);
10727 mp->is_add = is_add;
10735 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10737 unformat_input_t *i = vam->input;
10738 vl_api_ipsec_interface_add_del_spd_t *mp;
10740 u8 sw_if_index_set = 0;
10741 u32 spd_id = (u32) ~ 0;
10745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10747 if (unformat (i, "del"))
10749 else if (unformat (i, "spd_id %d", &spd_id))
10752 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10753 sw_if_index_set = 1;
10754 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10755 sw_if_index_set = 1;
10758 clib_warning ("parse error '%U'", format_unformat_error, i);
10764 if (spd_id == (u32) ~ 0)
10766 errmsg ("spd_id must be set");
10770 if (sw_if_index_set == 0)
10772 errmsg ("missing interface name or sw_if_index");
10776 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10778 mp->spd_id = ntohl (spd_id);
10779 mp->sw_if_index = ntohl (sw_if_index);
10780 mp->is_add = is_add;
10788 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10790 unformat_input_t *i = vam->input;
10791 vl_api_ipsec_spd_entry_add_del_t *mp;
10792 u8 is_add = 1, is_outbound = 0;
10793 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10795 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10796 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10797 vl_api_address_t laddr_start = { }, laddr_stop =
10806 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10808 if (unformat (i, "del"))
10810 if (unformat (i, "outbound"))
10812 if (unformat (i, "inbound"))
10814 else if (unformat (i, "spd_id %d", &spd_id))
10816 else if (unformat (i, "sa_id %d", &sa_id))
10818 else if (unformat (i, "priority %d", &priority))
10820 else if (unformat (i, "protocol %d", &protocol))
10822 else if (unformat (i, "lport_start %d", &lport_start))
10824 else if (unformat (i, "lport_stop %d", &lport_stop))
10826 else if (unformat (i, "rport_start %d", &rport_start))
10828 else if (unformat (i, "rport_stop %d", &rport_stop))
10830 else if (unformat (i, "laddr_start %U",
10831 unformat_vl_api_address, &laddr_start))
10833 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
10836 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
10839 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
10843 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
10845 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
10847 clib_warning ("unsupported action: 'resolve'");
10853 clib_warning ("parse error '%U'", format_unformat_error, i);
10859 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
10861 mp->is_add = is_add;
10863 mp->entry.spd_id = ntohl (spd_id);
10864 mp->entry.priority = ntohl (priority);
10865 mp->entry.is_outbound = is_outbound;
10867 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
10868 sizeof (vl_api_address_t));
10869 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
10870 sizeof (vl_api_address_t));
10871 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
10872 sizeof (vl_api_address_t));
10873 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
10874 sizeof (vl_api_address_t));
10876 mp->entry.protocol = (u8) protocol;
10877 mp->entry.local_port_start = ntohs ((u16) lport_start);
10878 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
10879 mp->entry.remote_port_start = ntohs ((u16) rport_start);
10880 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
10881 mp->entry.policy = (u8) policy;
10882 mp->entry.sa_id = ntohl (sa_id);
10890 api_ipsec_sad_entry_add_del (vat_main_t * vam)
10892 unformat_input_t *i = vam->input;
10893 vl_api_ipsec_sad_entry_add_del_t *mp;
10894 u32 sad_id = 0, spi = 0;
10895 u8 *ck = 0, *ik = 0;
10898 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
10899 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
10900 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
10901 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
10902 vl_api_address_t tun_src, tun_dst;
10905 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10907 if (unformat (i, "del"))
10909 else if (unformat (i, "sad_id %d", &sad_id))
10911 else if (unformat (i, "spi %d", &spi))
10913 else if (unformat (i, "esp"))
10914 protocol = IPSEC_API_PROTO_ESP;
10916 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
10918 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
10919 if (ADDRESS_IP6 == tun_src.af)
10920 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
10923 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
10925 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
10926 if (ADDRESS_IP6 == tun_src.af)
10927 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
10930 if (unformat (i, "crypto_alg %U",
10931 unformat_ipsec_api_crypto_alg, &crypto_alg))
10933 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
10935 else if (unformat (i, "integ_alg %U",
10936 unformat_ipsec_api_integ_alg, &integ_alg))
10938 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
10942 clib_warning ("parse error '%U'", format_unformat_error, i);
10948 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
10950 mp->is_add = is_add;
10951 mp->entry.sad_id = ntohl (sad_id);
10952 mp->entry.protocol = protocol;
10953 mp->entry.spi = ntohl (spi);
10954 mp->entry.flags = flags;
10956 mp->entry.crypto_algorithm = crypto_alg;
10957 mp->entry.integrity_algorithm = integ_alg;
10958 mp->entry.crypto_key.length = vec_len (ck);
10959 mp->entry.integrity_key.length = vec_len (ik);
10961 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
10962 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
10964 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
10965 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
10968 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
10970 clib_memcpy (mp->entry.integrity_key.data, ik,
10971 mp->entry.integrity_key.length);
10973 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
10975 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
10976 sizeof (mp->entry.tunnel_src));
10977 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
10978 sizeof (mp->entry.tunnel_dst));
10987 api_ipsec_tunnel_if_add_del (vat_main_t * vam)
10989 unformat_input_t *i = vam->input;
10990 vl_api_ipsec_tunnel_if_add_del_t *mp;
10991 u32 local_spi = 0, remote_spi = 0;
10992 u32 crypto_alg = 0, integ_alg = 0;
10993 u8 *lck = NULL, *rck = NULL;
10994 u8 *lik = NULL, *rik = NULL;
10995 vl_api_address_t local_ip = { 0 };
10996 vl_api_address_t remote_ip = { 0 };
11000 u8 anti_replay = 0;
11006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11008 if (unformat (i, "del"))
11010 else if (unformat (i, "esn"))
11012 else if (unformat (i, "anti-replay"))
11014 else if (unformat (i, "count %d", &count))
11016 else if (unformat (i, "local_spi %d", &local_spi))
11018 else if (unformat (i, "remote_spi %d", &remote_spi))
11021 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
11024 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
11026 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
11029 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
11031 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
11033 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
11037 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
11039 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
11041 errmsg ("unsupported crypto-alg: '%U'\n",
11042 format_ipsec_crypto_alg, crypto_alg);
11048 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
11050 if (integ_alg >= IPSEC_INTEG_N_ALG)
11052 errmsg ("unsupported integ-alg: '%U'\n",
11053 format_ipsec_integ_alg, integ_alg);
11057 else if (unformat (i, "instance %u", &instance))
11061 errmsg ("parse error '%U'\n", format_unformat_error, i);
11068 /* Turn on async mode */
11069 vam->async_mode = 1;
11070 vam->async_errors = 0;
11071 before = vat_time_now (vam);
11074 for (jj = 0; jj < count; jj++)
11076 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
11078 mp->is_add = is_add;
11080 mp->anti_replay = anti_replay;
11083 increment_address (&remote_ip);
11085 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
11086 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
11088 mp->local_spi = htonl (local_spi + jj);
11089 mp->remote_spi = htonl (remote_spi + jj);
11090 mp->crypto_alg = (u8) crypto_alg;
11092 mp->local_crypto_key_len = 0;
11095 mp->local_crypto_key_len = vec_len (lck);
11096 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
11097 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
11098 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
11101 mp->remote_crypto_key_len = 0;
11104 mp->remote_crypto_key_len = vec_len (rck);
11105 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
11106 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
11107 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
11110 mp->integ_alg = (u8) integ_alg;
11112 mp->local_integ_key_len = 0;
11115 mp->local_integ_key_len = vec_len (lik);
11116 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
11117 mp->local_integ_key_len = sizeof (mp->local_integ_key);
11118 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
11121 mp->remote_integ_key_len = 0;
11124 mp->remote_integ_key_len = vec_len (rik);
11125 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
11126 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
11127 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
11132 mp->renumber = renumber;
11133 mp->show_instance = ntohl (instance);
11138 /* When testing multiple add/del ops, use a control-ping to sync */
11141 vl_api_control_ping_t *mp_ping;
11145 /* Shut off async mode */
11146 vam->async_mode = 0;
11148 MPING (CONTROL_PING, mp_ping);
11151 timeout = vat_time_now (vam) + 1.0;
11152 while (vat_time_now (vam) < timeout)
11153 if (vam->result_ready == 1)
11158 if (vam->retval == -99)
11159 errmsg ("timeout");
11161 if (vam->async_errors > 0)
11163 errmsg ("%d asynchronous errors", vam->async_errors);
11166 vam->async_errors = 0;
11167 after = vat_time_now (vam);
11169 /* slim chance, but we might have eaten SIGTERM on the first iteration */
11173 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
11174 count, after - before, count / (after - before));
11178 /* Wait for a reply... */
11187 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11189 vat_main_t *vam = &vat_main;
11191 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11192 "crypto_key %U integ_alg %u integ_key %U flags %x "
11193 "tunnel_src_addr %U tunnel_dst_addr %U "
11194 "salt %u seq_outbound %lu last_seq_inbound %lu "
11195 "replay_window %lu stat_index %u\n",
11196 ntohl (mp->entry.sad_id),
11197 ntohl (mp->sw_if_index),
11198 ntohl (mp->entry.spi),
11199 ntohl (mp->entry.protocol),
11200 ntohl (mp->entry.crypto_algorithm),
11201 format_hex_bytes, mp->entry.crypto_key.data,
11202 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11203 format_hex_bytes, mp->entry.integrity_key.data,
11204 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11205 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11206 &mp->entry.tunnel_dst, ntohl (mp->salt),
11207 clib_net_to_host_u64 (mp->seq_outbound),
11208 clib_net_to_host_u64 (mp->last_seq_inbound),
11209 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11212 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11213 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11215 static void vl_api_ipsec_sa_details_t_handler_json
11216 (vl_api_ipsec_sa_details_t * mp)
11218 vat_main_t *vam = &vat_main;
11219 vat_json_node_t *node = NULL;
11220 vl_api_ipsec_sad_flags_t flags;
11222 if (VAT_JSON_ARRAY != vam->json_tree.type)
11224 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11225 vat_json_init_array (&vam->json_tree);
11227 node = vat_json_array_add (&vam->json_tree);
11229 vat_json_init_object (node);
11230 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11231 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11232 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11233 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11234 vat_json_object_add_uint (node, "crypto_alg",
11235 ntohl (mp->entry.crypto_algorithm));
11236 vat_json_object_add_uint (node, "integ_alg",
11237 ntohl (mp->entry.integrity_algorithm));
11238 flags = ntohl (mp->entry.flags);
11239 vat_json_object_add_uint (node, "use_esn",
11240 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11241 vat_json_object_add_uint (node, "use_anti_replay",
11242 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11243 vat_json_object_add_uint (node, "is_tunnel",
11244 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11245 vat_json_object_add_uint (node, "is_tunnel_ip6",
11246 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11247 vat_json_object_add_uint (node, "udp_encap",
11248 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11249 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11250 mp->entry.crypto_key.length);
11251 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11252 mp->entry.integrity_key.length);
11253 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11254 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11255 vat_json_object_add_uint (node, "replay_window",
11256 clib_net_to_host_u64 (mp->replay_window));
11257 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11261 api_ipsec_sa_dump (vat_main_t * vam)
11263 unformat_input_t *i = vam->input;
11264 vl_api_ipsec_sa_dump_t *mp;
11265 vl_api_control_ping_t *mp_ping;
11269 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11271 if (unformat (i, "sa_id %d", &sa_id))
11275 clib_warning ("parse error '%U'", format_unformat_error, i);
11280 M (IPSEC_SA_DUMP, mp);
11282 mp->sa_id = ntohl (sa_id);
11286 /* Use a control ping for synchronization */
11287 M (CONTROL_PING, mp_ping);
11295 api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
11297 unformat_input_t *i = vam->input;
11298 vl_api_ipsec_tunnel_if_set_sa_t *mp;
11299 u32 sw_if_index = ~0;
11301 u8 is_outbound = (u8) ~ 0;
11304 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11306 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11308 else if (unformat (i, "sa_id %d", &sa_id))
11310 else if (unformat (i, "outbound"))
11312 else if (unformat (i, "inbound"))
11316 clib_warning ("parse error '%U'", format_unformat_error, i);
11321 if (sw_if_index == ~0)
11323 errmsg ("interface must be specified");
11329 errmsg ("SA ID must be specified");
11333 M (IPSEC_TUNNEL_IF_SET_SA, mp);
11335 mp->sw_if_index = htonl (sw_if_index);
11336 mp->sa_id = htonl (sa_id);
11337 mp->is_outbound = is_outbound;
11346 api_get_first_msg_id (vat_main_t * vam)
11348 vl_api_get_first_msg_id_t *mp;
11349 unformat_input_t *i = vam->input;
11354 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11356 if (unformat (i, "client %s", &name))
11364 errmsg ("missing client name");
11367 vec_add1 (name, 0);
11369 if (vec_len (name) > 63)
11371 errmsg ("client name too long");
11375 M (GET_FIRST_MSG_ID, mp);
11376 clib_memcpy (mp->name, name, vec_len (name));
11383 api_cop_interface_enable_disable (vat_main_t * vam)
11385 unformat_input_t *line_input = vam->input;
11386 vl_api_cop_interface_enable_disable_t *mp;
11387 u32 sw_if_index = ~0;
11388 u8 enable_disable = 1;
11391 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11393 if (unformat (line_input, "disable"))
11394 enable_disable = 0;
11395 if (unformat (line_input, "enable"))
11396 enable_disable = 1;
11397 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11398 vam, &sw_if_index))
11400 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11406 if (sw_if_index == ~0)
11408 errmsg ("missing interface name or sw_if_index");
11412 /* Construct the API message */
11413 M (COP_INTERFACE_ENABLE_DISABLE, mp);
11414 mp->sw_if_index = ntohl (sw_if_index);
11415 mp->enable_disable = enable_disable;
11419 /* Wait for the reply */
11425 api_cop_whitelist_enable_disable (vat_main_t * vam)
11427 unformat_input_t *line_input = vam->input;
11428 vl_api_cop_whitelist_enable_disable_t *mp;
11429 u32 sw_if_index = ~0;
11430 u8 ip4 = 0, ip6 = 0, default_cop = 0;
11434 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11436 if (unformat (line_input, "ip4"))
11438 else if (unformat (line_input, "ip6"))
11440 else if (unformat (line_input, "default"))
11442 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11443 vam, &sw_if_index))
11445 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11447 else if (unformat (line_input, "fib-id %d", &fib_id))
11453 if (sw_if_index == ~0)
11455 errmsg ("missing interface name or sw_if_index");
11459 /* Construct the API message */
11460 M (COP_WHITELIST_ENABLE_DISABLE, mp);
11461 mp->sw_if_index = ntohl (sw_if_index);
11462 mp->fib_id = ntohl (fib_id);
11465 mp->default_cop = default_cop;
11469 /* Wait for the reply */
11475 api_get_node_graph (vat_main_t * vam)
11477 vl_api_get_node_graph_t *mp;
11480 M (GET_NODE_GRAPH, mp);
11484 /* Wait for the reply */
11490 api_af_packet_create (vat_main_t * vam)
11492 unformat_input_t *i = vam->input;
11493 vl_api_af_packet_create_t *mp;
11494 u8 *host_if_name = 0;
11496 u8 random_hw_addr = 1;
11499 clib_memset (hw_addr, 0, sizeof (hw_addr));
11501 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11503 if (unformat (i, "name %s", &host_if_name))
11504 vec_add1 (host_if_name, 0);
11505 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11506 random_hw_addr = 0;
11511 if (!vec_len (host_if_name))
11513 errmsg ("host-interface name must be specified");
11517 if (vec_len (host_if_name) > 64)
11519 errmsg ("host-interface name too long");
11523 M (AF_PACKET_CREATE, mp);
11525 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11526 clib_memcpy (mp->hw_addr, hw_addr, 6);
11527 mp->use_random_hw_addr = random_hw_addr;
11528 vec_free (host_if_name);
11536 fprintf (vam->ofp ? vam->ofp : stderr,
11537 " new sw_if_index = %d\n", vam->sw_if_index);
11544 api_af_packet_delete (vat_main_t * vam)
11546 unformat_input_t *i = vam->input;
11547 vl_api_af_packet_delete_t *mp;
11548 u8 *host_if_name = 0;
11551 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11553 if (unformat (i, "name %s", &host_if_name))
11554 vec_add1 (host_if_name, 0);
11559 if (!vec_len (host_if_name))
11561 errmsg ("host-interface name must be specified");
11565 if (vec_len (host_if_name) > 64)
11567 errmsg ("host-interface name too long");
11571 M (AF_PACKET_DELETE, mp);
11573 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11574 vec_free (host_if_name);
11581 static void vl_api_af_packet_details_t_handler
11582 (vl_api_af_packet_details_t * mp)
11584 vat_main_t *vam = &vat_main;
11586 print (vam->ofp, "%-16s %d",
11587 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11590 static void vl_api_af_packet_details_t_handler_json
11591 (vl_api_af_packet_details_t * mp)
11593 vat_main_t *vam = &vat_main;
11594 vat_json_node_t *node = NULL;
11596 if (VAT_JSON_ARRAY != vam->json_tree.type)
11598 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11599 vat_json_init_array (&vam->json_tree);
11601 node = vat_json_array_add (&vam->json_tree);
11603 vat_json_init_object (node);
11604 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11605 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11609 api_af_packet_dump (vat_main_t * vam)
11611 vl_api_af_packet_dump_t *mp;
11612 vl_api_control_ping_t *mp_ping;
11615 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11616 /* Get list of tap interfaces */
11617 M (AF_PACKET_DUMP, mp);
11620 /* Use a control ping for synchronization */
11621 MPING (CONTROL_PING, mp_ping);
11629 api_policer_add_del (vat_main_t * vam)
11631 unformat_input_t *i = vam->input;
11632 vl_api_policer_add_del_t *mp;
11642 u8 color_aware = 0;
11643 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
11646 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
11647 conform_action.dscp = 0;
11648 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
11649 exceed_action.dscp = 0;
11650 violate_action.action_type = SSE2_QOS_ACTION_DROP;
11651 violate_action.dscp = 0;
11653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11655 if (unformat (i, "del"))
11657 else if (unformat (i, "name %s", &name))
11658 vec_add1 (name, 0);
11659 else if (unformat (i, "cir %u", &cir))
11661 else if (unformat (i, "eir %u", &eir))
11663 else if (unformat (i, "cb %u", &cb))
11665 else if (unformat (i, "eb %u", &eb))
11667 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11670 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11673 else if (unformat (i, "type %U", unformat_policer_type, &type))
11675 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11678 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11681 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11684 else if (unformat (i, "color-aware"))
11690 if (!vec_len (name))
11692 errmsg ("policer name must be specified");
11696 if (vec_len (name) > 64)
11698 errmsg ("policer name too long");
11702 M (POLICER_ADD_DEL, mp);
11704 clib_memcpy (mp->name, name, vec_len (name));
11706 mp->is_add = is_add;
11707 mp->cir = ntohl (cir);
11708 mp->eir = ntohl (eir);
11709 mp->cb = clib_net_to_host_u64 (cb);
11710 mp->eb = clib_net_to_host_u64 (eb);
11711 mp->rate_type = rate_type;
11712 mp->round_type = round_type;
11714 mp->conform_action.type = conform_action.action_type;
11715 mp->conform_action.dscp = conform_action.dscp;
11716 mp->exceed_action.type = exceed_action.action_type;
11717 mp->exceed_action.dscp = exceed_action.dscp;
11718 mp->violate_action.type = violate_action.action_type;
11719 mp->violate_action.dscp = violate_action.dscp;
11720 mp->color_aware = color_aware;
11728 api_policer_dump (vat_main_t * vam)
11730 unformat_input_t *i = vam->input;
11731 vl_api_policer_dump_t *mp;
11732 vl_api_control_ping_t *mp_ping;
11733 u8 *match_name = 0;
11734 u8 match_name_valid = 0;
11737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11739 if (unformat (i, "name %s", &match_name))
11741 vec_add1 (match_name, 0);
11742 match_name_valid = 1;
11748 M (POLICER_DUMP, mp);
11749 mp->match_name_valid = match_name_valid;
11750 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11751 vec_free (match_name);
11755 /* Use a control ping for synchronization */
11756 MPING (CONTROL_PING, mp_ping);
11759 /* Wait for a reply... */
11765 api_policer_classify_set_interface (vat_main_t * vam)
11767 unformat_input_t *i = vam->input;
11768 vl_api_policer_classify_set_interface_t *mp;
11770 int sw_if_index_set;
11771 u32 ip4_table_index = ~0;
11772 u32 ip6_table_index = ~0;
11773 u32 l2_table_index = ~0;
11777 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11779 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11780 sw_if_index_set = 1;
11781 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11782 sw_if_index_set = 1;
11783 else if (unformat (i, "del"))
11785 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11787 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11789 else if (unformat (i, "l2-table %d", &l2_table_index))
11793 clib_warning ("parse error '%U'", format_unformat_error, i);
11798 if (sw_if_index_set == 0)
11800 errmsg ("missing interface name or sw_if_index");
11804 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
11806 mp->sw_if_index = ntohl (sw_if_index);
11807 mp->ip4_table_index = ntohl (ip4_table_index);
11808 mp->ip6_table_index = ntohl (ip6_table_index);
11809 mp->l2_table_index = ntohl (l2_table_index);
11810 mp->is_add = is_add;
11818 api_policer_classify_dump (vat_main_t * vam)
11820 unformat_input_t *i = vam->input;
11821 vl_api_policer_classify_dump_t *mp;
11822 vl_api_control_ping_t *mp_ping;
11823 u8 type = POLICER_CLASSIFY_N_TABLES;
11826 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
11830 errmsg ("classify table type must be specified");
11834 if (!vam->json_output)
11836 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
11839 M (POLICER_CLASSIFY_DUMP, mp);
11844 /* Use a control ping for synchronization */
11845 MPING (CONTROL_PING, mp_ping);
11848 /* Wait for a reply... */
11854 format_fib_api_path_nh_proto (u8 * s, va_list * args)
11856 vl_api_fib_path_nh_proto_t proto =
11857 va_arg (*args, vl_api_fib_path_nh_proto_t);
11861 case FIB_API_PATH_NH_PROTO_IP4:
11862 s = format (s, "ip4");
11864 case FIB_API_PATH_NH_PROTO_IP6:
11865 s = format (s, "ip6");
11867 case FIB_API_PATH_NH_PROTO_MPLS:
11868 s = format (s, "mpls");
11870 case FIB_API_PATH_NH_PROTO_BIER:
11871 s = format (s, "bier");
11873 case FIB_API_PATH_NH_PROTO_ETHERNET:
11874 s = format (s, "ethernet");
11882 format_vl_api_ip_address_union (u8 * s, va_list * args)
11884 vl_api_address_family_t af = va_arg (*args, int);
11885 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
11890 s = format (s, "%U", format_ip4_address, u->ip4);
11893 s = format (s, "%U", format_ip6_address, u->ip6);
11900 format_vl_api_fib_path_type (u8 * s, va_list * args)
11902 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
11906 case FIB_API_PATH_TYPE_NORMAL:
11907 s = format (s, "normal");
11909 case FIB_API_PATH_TYPE_LOCAL:
11910 s = format (s, "local");
11912 case FIB_API_PATH_TYPE_DROP:
11913 s = format (s, "drop");
11915 case FIB_API_PATH_TYPE_UDP_ENCAP:
11916 s = format (s, "udp-encap");
11918 case FIB_API_PATH_TYPE_BIER_IMP:
11919 s = format (s, "bier-imp");
11921 case FIB_API_PATH_TYPE_ICMP_UNREACH:
11922 s = format (s, "unreach");
11924 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
11925 s = format (s, "prohibit");
11927 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
11928 s = format (s, "src-lookup");
11930 case FIB_API_PATH_TYPE_DVR:
11931 s = format (s, "dvr");
11933 case FIB_API_PATH_TYPE_INTERFACE_RX:
11934 s = format (s, "interface-rx");
11936 case FIB_API_PATH_TYPE_CLASSIFY:
11937 s = format (s, "classify");
11945 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
11948 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
11949 ntohl (fp->weight), ntohl (fp->sw_if_index),
11950 format_vl_api_fib_path_type, fp->type,
11951 format_fib_api_path_nh_proto, fp->proto,
11952 format_vl_api_ip_address_union, &fp->nh.address);
11956 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
11957 vl_api_fib_path_t * fp)
11959 struct in_addr ip4;
11960 struct in6_addr ip6;
11962 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
11963 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
11964 vat_json_object_add_uint (node, "type", fp->type);
11965 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
11966 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
11968 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
11969 vat_json_object_add_ip4 (node, "next_hop", ip4);
11971 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
11973 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
11974 vat_json_object_add_ip6 (node, "next_hop", ip6);
11979 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
11981 vat_main_t *vam = &vat_main;
11982 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11983 vl_api_fib_path_t *fp;
11986 print (vam->ofp, "sw_if_index %d via:",
11987 ntohl (mp->mt_tunnel.mt_sw_if_index));
11988 fp = mp->mt_tunnel.mt_paths;
11989 for (i = 0; i < count; i++)
11991 vl_api_fib_path_print (vam, fp);
11995 print (vam->ofp, "");
11998 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
11999 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
12002 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
12004 vat_main_t *vam = &vat_main;
12005 vat_json_node_t *node = NULL;
12006 int count = ntohl (mp->mt_tunnel.mt_n_paths);
12007 vl_api_fib_path_t *fp;
12010 if (VAT_JSON_ARRAY != vam->json_tree.type)
12012 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12013 vat_json_init_array (&vam->json_tree);
12015 node = vat_json_array_add (&vam->json_tree);
12017 vat_json_init_object (node);
12018 vat_json_object_add_uint (node, "sw_if_index",
12019 ntohl (mp->mt_tunnel.mt_sw_if_index));
12021 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
12023 fp = mp->mt_tunnel.mt_paths;
12024 for (i = 0; i < count; i++)
12026 vl_api_mpls_fib_path_json_print (node, fp);
12032 api_mpls_tunnel_dump (vat_main_t * vam)
12034 vl_api_mpls_tunnel_dump_t *mp;
12035 vl_api_control_ping_t *mp_ping;
12038 M (MPLS_TUNNEL_DUMP, mp);
12042 /* Use a control ping for synchronization */
12043 MPING (CONTROL_PING, mp_ping);
12050 #define vl_api_mpls_table_details_t_endian vl_noop_handler
12051 #define vl_api_mpls_table_details_t_print vl_noop_handler
12055 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
12057 vat_main_t *vam = &vat_main;
12059 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
12062 static void vl_api_mpls_table_details_t_handler_json
12063 (vl_api_mpls_table_details_t * mp)
12065 vat_main_t *vam = &vat_main;
12066 vat_json_node_t *node = NULL;
12068 if (VAT_JSON_ARRAY != vam->json_tree.type)
12070 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12071 vat_json_init_array (&vam->json_tree);
12073 node = vat_json_array_add (&vam->json_tree);
12075 vat_json_init_object (node);
12076 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
12080 api_mpls_table_dump (vat_main_t * vam)
12082 vl_api_mpls_table_dump_t *mp;
12083 vl_api_control_ping_t *mp_ping;
12086 M (MPLS_TABLE_DUMP, mp);
12089 /* Use a control ping for synchronization */
12090 MPING (CONTROL_PING, mp_ping);
12097 #define vl_api_mpls_route_details_t_endian vl_noop_handler
12098 #define vl_api_mpls_route_details_t_print vl_noop_handler
12101 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
12103 vat_main_t *vam = &vat_main;
12104 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
12105 vl_api_fib_path_t *fp;
12109 "table-id %d, label %u, ess_bit %u",
12110 ntohl (mp->mr_route.mr_table_id),
12111 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
12112 fp = mp->mr_route.mr_paths;
12113 for (i = 0; i < count; i++)
12115 vl_api_fib_path_print (vam, fp);
12120 static void vl_api_mpls_route_details_t_handler_json
12121 (vl_api_mpls_route_details_t * mp)
12123 vat_main_t *vam = &vat_main;
12124 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
12125 vat_json_node_t *node = NULL;
12126 vl_api_fib_path_t *fp;
12129 if (VAT_JSON_ARRAY != vam->json_tree.type)
12131 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12132 vat_json_init_array (&vam->json_tree);
12134 node = vat_json_array_add (&vam->json_tree);
12136 vat_json_init_object (node);
12137 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
12138 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
12139 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
12140 vat_json_object_add_uint (node, "path_count", count);
12141 fp = mp->mr_route.mr_paths;
12142 for (i = 0; i < count; i++)
12144 vl_api_mpls_fib_path_json_print (node, fp);
12150 api_mpls_route_dump (vat_main_t * vam)
12152 unformat_input_t *input = vam->input;
12153 vl_api_mpls_route_dump_t *mp;
12154 vl_api_control_ping_t *mp_ping;
12158 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12160 if (unformat (input, "table_id %d", &table_id))
12165 if (table_id == ~0)
12167 errmsg ("missing table id");
12171 M (MPLS_ROUTE_DUMP, mp);
12173 mp->table.mt_table_id = ntohl (table_id);
12176 /* Use a control ping for synchronization */
12177 MPING (CONTROL_PING, mp_ping);
12184 #define vl_api_ip_table_details_t_endian vl_noop_handler
12185 #define vl_api_ip_table_details_t_print vl_noop_handler
12188 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12190 vat_main_t *vam = &vat_main;
12193 "%s; table-id %d, prefix %U/%d",
12194 mp->table.name, ntohl (mp->table.table_id));
12198 static void vl_api_ip_table_details_t_handler_json
12199 (vl_api_ip_table_details_t * mp)
12201 vat_main_t *vam = &vat_main;
12202 vat_json_node_t *node = NULL;
12204 if (VAT_JSON_ARRAY != vam->json_tree.type)
12206 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12207 vat_json_init_array (&vam->json_tree);
12209 node = vat_json_array_add (&vam->json_tree);
12211 vat_json_init_object (node);
12212 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12216 api_ip_table_dump (vat_main_t * vam)
12218 vl_api_ip_table_dump_t *mp;
12219 vl_api_control_ping_t *mp_ping;
12222 M (IP_TABLE_DUMP, mp);
12225 /* Use a control ping for synchronization */
12226 MPING (CONTROL_PING, mp_ping);
12234 api_ip_mtable_dump (vat_main_t * vam)
12236 vl_api_ip_mtable_dump_t *mp;
12237 vl_api_control_ping_t *mp_ping;
12240 M (IP_MTABLE_DUMP, mp);
12243 /* Use a control ping for synchronization */
12244 MPING (CONTROL_PING, mp_ping);
12252 api_ip_mroute_dump (vat_main_t * vam)
12254 unformat_input_t *input = vam->input;
12255 vl_api_control_ping_t *mp_ping;
12256 vl_api_ip_mroute_dump_t *mp;
12261 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12263 if (unformat (input, "table_id %d", &table_id))
12265 else if (unformat (input, "ip6"))
12267 else if (unformat (input, "ip4"))
12272 if (table_id == ~0)
12274 errmsg ("missing table id");
12278 M (IP_MROUTE_DUMP, mp);
12279 mp->table.table_id = table_id;
12280 mp->table.is_ip6 = is_ip6;
12283 /* Use a control ping for synchronization */
12284 MPING (CONTROL_PING, mp_ping);
12291 #define vl_api_ip_route_details_t_endian vl_noop_handler
12292 #define vl_api_ip_route_details_t_print vl_noop_handler
12295 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12297 vat_main_t *vam = &vat_main;
12298 u8 count = mp->route.n_paths;
12299 vl_api_fib_path_t *fp;
12303 "table-id %d, prefix %U/%d",
12304 ntohl (mp->route.table_id),
12305 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12306 for (i = 0; i < count; i++)
12308 fp = &mp->route.paths[i];
12310 vl_api_fib_path_print (vam, fp);
12315 static void vl_api_ip_route_details_t_handler_json
12316 (vl_api_ip_route_details_t * mp)
12318 vat_main_t *vam = &vat_main;
12319 u8 count = mp->route.n_paths;
12320 vat_json_node_t *node = NULL;
12321 struct in_addr ip4;
12322 struct in6_addr ip6;
12323 vl_api_fib_path_t *fp;
12326 if (VAT_JSON_ARRAY != vam->json_tree.type)
12328 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12329 vat_json_init_array (&vam->json_tree);
12331 node = vat_json_array_add (&vam->json_tree);
12333 vat_json_init_object (node);
12334 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12335 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12337 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12338 vat_json_object_add_ip6 (node, "prefix", ip6);
12342 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12343 vat_json_object_add_ip4 (node, "prefix", ip4);
12345 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12346 vat_json_object_add_uint (node, "path_count", count);
12347 for (i = 0; i < count; i++)
12349 fp = &mp->route.paths[i];
12350 vl_api_mpls_fib_path_json_print (node, fp);
12355 api_ip_route_dump (vat_main_t * vam)
12357 unformat_input_t *input = vam->input;
12358 vl_api_ip_route_dump_t *mp;
12359 vl_api_control_ping_t *mp_ping;
12365 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12367 if (unformat (input, "table_id %d", &table_id))
12369 else if (unformat (input, "ip6"))
12371 else if (unformat (input, "ip4"))
12376 if (table_id == ~0)
12378 errmsg ("missing table id");
12382 M (IP_ROUTE_DUMP, mp);
12384 mp->table.table_id = table_id;
12385 mp->table.is_ip6 = is_ip6;
12389 /* Use a control ping for synchronization */
12390 MPING (CONTROL_PING, mp_ping);
12398 api_classify_table_ids (vat_main_t * vam)
12400 vl_api_classify_table_ids_t *mp;
12403 /* Construct the API message */
12404 M (CLASSIFY_TABLE_IDS, mp);
12413 api_classify_table_by_interface (vat_main_t * vam)
12415 unformat_input_t *input = vam->input;
12416 vl_api_classify_table_by_interface_t *mp;
12418 u32 sw_if_index = ~0;
12420 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12422 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12424 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12429 if (sw_if_index == ~0)
12431 errmsg ("missing interface name or sw_if_index");
12435 /* Construct the API message */
12436 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12438 mp->sw_if_index = ntohl (sw_if_index);
12446 api_classify_table_info (vat_main_t * vam)
12448 unformat_input_t *input = vam->input;
12449 vl_api_classify_table_info_t *mp;
12453 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12455 if (unformat (input, "table_id %d", &table_id))
12460 if (table_id == ~0)
12462 errmsg ("missing table id");
12466 /* Construct the API message */
12467 M (CLASSIFY_TABLE_INFO, mp);
12469 mp->table_id = ntohl (table_id);
12477 api_classify_session_dump (vat_main_t * vam)
12479 unformat_input_t *input = vam->input;
12480 vl_api_classify_session_dump_t *mp;
12481 vl_api_control_ping_t *mp_ping;
12485 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12487 if (unformat (input, "table_id %d", &table_id))
12492 if (table_id == ~0)
12494 errmsg ("missing table id");
12498 /* Construct the API message */
12499 M (CLASSIFY_SESSION_DUMP, mp);
12501 mp->table_id = ntohl (table_id);
12504 /* Use a control ping for synchronization */
12505 MPING (CONTROL_PING, mp_ping);
12513 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12515 vat_main_t *vam = &vat_main;
12517 print (vam->ofp, "collector_address %U, collector_port %d, "
12518 "src_address %U, vrf_id %d, path_mtu %u, "
12519 "template_interval %u, udp_checksum %d",
12520 format_ip4_address, mp->collector_address,
12521 ntohs (mp->collector_port),
12522 format_ip4_address, mp->src_address,
12523 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12524 ntohl (mp->template_interval), mp->udp_checksum);
12527 vam->result_ready = 1;
12531 vl_api_ipfix_exporter_details_t_handler_json
12532 (vl_api_ipfix_exporter_details_t * mp)
12534 vat_main_t *vam = &vat_main;
12535 vat_json_node_t node;
12536 struct in_addr collector_address;
12537 struct in_addr src_address;
12539 vat_json_init_object (&node);
12540 clib_memcpy (&collector_address, &mp->collector_address,
12541 sizeof (collector_address));
12542 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12543 vat_json_object_add_uint (&node, "collector_port",
12544 ntohs (mp->collector_port));
12545 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12546 vat_json_object_add_ip4 (&node, "src_address", src_address);
12547 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12548 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12549 vat_json_object_add_uint (&node, "template_interval",
12550 ntohl (mp->template_interval));
12551 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12553 vat_json_print (vam->ofp, &node);
12554 vat_json_free (&node);
12556 vam->result_ready = 1;
12560 api_ipfix_exporter_dump (vat_main_t * vam)
12562 vl_api_ipfix_exporter_dump_t *mp;
12565 /* Construct the API message */
12566 M (IPFIX_EXPORTER_DUMP, mp);
12575 api_ipfix_classify_stream_dump (vat_main_t * vam)
12577 vl_api_ipfix_classify_stream_dump_t *mp;
12580 /* Construct the API message */
12581 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12592 vl_api_ipfix_classify_stream_details_t_handler
12593 (vl_api_ipfix_classify_stream_details_t * mp)
12595 vat_main_t *vam = &vat_main;
12596 print (vam->ofp, "domain_id %d, src_port %d",
12597 ntohl (mp->domain_id), ntohs (mp->src_port));
12599 vam->result_ready = 1;
12603 vl_api_ipfix_classify_stream_details_t_handler_json
12604 (vl_api_ipfix_classify_stream_details_t * mp)
12606 vat_main_t *vam = &vat_main;
12607 vat_json_node_t node;
12609 vat_json_init_object (&node);
12610 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12611 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12613 vat_json_print (vam->ofp, &node);
12614 vat_json_free (&node);
12616 vam->result_ready = 1;
12620 api_ipfix_classify_table_dump (vat_main_t * vam)
12622 vl_api_ipfix_classify_table_dump_t *mp;
12623 vl_api_control_ping_t *mp_ping;
12626 if (!vam->json_output)
12628 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12629 "transport_protocol");
12632 /* Construct the API message */
12633 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12638 /* Use a control ping for synchronization */
12639 MPING (CONTROL_PING, mp_ping);
12647 vl_api_ipfix_classify_table_details_t_handler
12648 (vl_api_ipfix_classify_table_details_t * mp)
12650 vat_main_t *vam = &vat_main;
12651 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12652 mp->transport_protocol);
12656 vl_api_ipfix_classify_table_details_t_handler_json
12657 (vl_api_ipfix_classify_table_details_t * mp)
12659 vat_json_node_t *node = NULL;
12660 vat_main_t *vam = &vat_main;
12662 if (VAT_JSON_ARRAY != vam->json_tree.type)
12664 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12665 vat_json_init_array (&vam->json_tree);
12668 node = vat_json_array_add (&vam->json_tree);
12669 vat_json_init_object (node);
12671 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12672 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12673 vat_json_object_add_uint (node, "transport_protocol",
12674 mp->transport_protocol);
12678 api_sw_interface_span_enable_disable (vat_main_t * vam)
12680 unformat_input_t *i = vam->input;
12681 vl_api_sw_interface_span_enable_disable_t *mp;
12682 u32 src_sw_if_index = ~0;
12683 u32 dst_sw_if_index = ~0;
12688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12691 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12693 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12697 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12699 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12701 else if (unformat (i, "disable"))
12703 else if (unformat (i, "rx"))
12705 else if (unformat (i, "tx"))
12707 else if (unformat (i, "both"))
12709 else if (unformat (i, "l2"))
12715 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12717 mp->sw_if_index_from = htonl (src_sw_if_index);
12718 mp->sw_if_index_to = htonl (dst_sw_if_index);
12728 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12731 vat_main_t *vam = &vat_main;
12732 u8 *sw_if_from_name = 0;
12733 u8 *sw_if_to_name = 0;
12734 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12735 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12736 char *states[] = { "none", "rx", "tx", "both" };
12740 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12742 if ((u32) p->value[0] == sw_if_index_from)
12744 sw_if_from_name = (u8 *)(p->key);
12748 if ((u32) p->value[0] == sw_if_index_to)
12750 sw_if_to_name = (u8 *)(p->key);
12751 if (sw_if_from_name)
12756 print (vam->ofp, "%20s => %20s (%s) %s",
12757 sw_if_from_name, sw_if_to_name, states[mp->state],
12758 mp->is_l2 ? "l2" : "device");
12762 vl_api_sw_interface_span_details_t_handler_json
12763 (vl_api_sw_interface_span_details_t * mp)
12765 vat_main_t *vam = &vat_main;
12766 vat_json_node_t *node = NULL;
12767 u8 *sw_if_from_name = 0;
12768 u8 *sw_if_to_name = 0;
12769 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12770 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12774 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12776 if ((u32) p->value[0] == sw_if_index_from)
12778 sw_if_from_name = (u8 *)(p->key);
12782 if ((u32) p->value[0] == sw_if_index_to)
12784 sw_if_to_name = (u8 *)(p->key);
12785 if (sw_if_from_name)
12791 if (VAT_JSON_ARRAY != vam->json_tree.type)
12793 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12794 vat_json_init_array (&vam->json_tree);
12796 node = vat_json_array_add (&vam->json_tree);
12798 vat_json_init_object (node);
12799 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12800 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12801 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12802 if (0 != sw_if_to_name)
12804 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
12806 vat_json_object_add_uint (node, "state", mp->state);
12807 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
12811 api_sw_interface_span_dump (vat_main_t * vam)
12813 unformat_input_t *input = vam->input;
12814 vl_api_sw_interface_span_dump_t *mp;
12815 vl_api_control_ping_t *mp_ping;
12819 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12821 if (unformat (input, "l2"))
12827 M (SW_INTERFACE_SPAN_DUMP, mp);
12831 /* Use a control ping for synchronization */
12832 MPING (CONTROL_PING, mp_ping);
12840 api_pg_create_interface (vat_main_t * vam)
12842 unformat_input_t *input = vam->input;
12843 vl_api_pg_create_interface_t *mp;
12845 u32 if_id = ~0, gso_size = 0;
12846 u8 gso_enabled = 0;
12848 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12850 if (unformat (input, "if_id %d", &if_id))
12852 else if (unformat (input, "gso-enabled"))
12855 if (unformat (input, "gso-size %u", &gso_size))
12859 errmsg ("missing gso-size");
12868 errmsg ("missing pg interface index");
12872 /* Construct the API message */
12873 M (PG_CREATE_INTERFACE, mp);
12875 mp->interface_id = ntohl (if_id);
12876 mp->gso_enabled = gso_enabled;
12884 api_pg_capture (vat_main_t * vam)
12886 unformat_input_t *input = vam->input;
12887 vl_api_pg_capture_t *mp;
12892 u8 pcap_file_set = 0;
12895 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12897 if (unformat (input, "if_id %d", &if_id))
12899 else if (unformat (input, "pcap %s", &pcap_file))
12901 else if (unformat (input, "count %d", &count))
12903 else if (unformat (input, "disable"))
12910 errmsg ("missing pg interface index");
12913 if (pcap_file_set > 0)
12915 if (vec_len (pcap_file) > 255)
12917 errmsg ("pcap file name is too long");
12922 /* Construct the API message */
12923 M (PG_CAPTURE, mp);
12925 mp->interface_id = ntohl (if_id);
12926 mp->is_enabled = enable;
12927 mp->count = ntohl (count);
12928 if (pcap_file_set != 0)
12930 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
12932 vec_free (pcap_file);
12940 api_pg_enable_disable (vat_main_t * vam)
12942 unformat_input_t *input = vam->input;
12943 vl_api_pg_enable_disable_t *mp;
12946 u8 stream_name_set = 0;
12947 u8 *stream_name = 0;
12949 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12951 if (unformat (input, "stream %s", &stream_name))
12952 stream_name_set = 1;
12953 else if (unformat (input, "disable"))
12959 if (stream_name_set > 0)
12961 if (vec_len (stream_name) > 255)
12963 errmsg ("stream name too long");
12968 /* Construct the API message */
12969 M (PG_ENABLE_DISABLE, mp);
12971 mp->is_enabled = enable;
12972 if (stream_name_set != 0)
12974 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
12976 vec_free (stream_name);
12984 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
12986 unformat_input_t *input = vam->input;
12987 vl_api_pg_interface_enable_disable_coalesce_t *mp;
12989 u32 sw_if_index = ~0;
12992 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12994 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12996 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12998 else if (unformat (input, "disable"))
13004 if (sw_if_index == ~0)
13006 errmsg ("Interface required but not specified");
13010 /* Construct the API message */
13011 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
13013 mp->coalesce_enabled = enable;
13014 mp->sw_if_index = htonl (sw_if_index);
13022 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
13024 unformat_input_t *input = vam->input;
13025 vl_api_ip_source_and_port_range_check_add_del_t *mp;
13027 u16 *low_ports = 0;
13028 u16 *high_ports = 0;
13031 vl_api_prefix_t prefix;
13038 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13040 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
13042 else if (unformat (input, "vrf %d", &vrf_id))
13044 else if (unformat (input, "del"))
13046 else if (unformat (input, "port %d", &tmp))
13048 if (tmp == 0 || tmp > 65535)
13050 errmsg ("port %d out of range", tmp);
13054 this_hi = this_low + 1;
13055 vec_add1 (low_ports, this_low);
13056 vec_add1 (high_ports, this_hi);
13058 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13060 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
13062 errmsg ("incorrect range parameters");
13066 /* Note: in debug CLI +1 is added to high before
13067 passing to real fn that does "the work"
13068 (ip_source_and_port_range_check_add_del).
13069 This fn is a wrapper around the binary API fn a
13070 control plane will call, which expects this increment
13071 to have occurred. Hence letting the binary API control
13072 plane fn do the increment for consistency between VAT
13073 and other control planes.
13076 vec_add1 (low_ports, this_low);
13077 vec_add1 (high_ports, this_hi);
13083 if (prefix_set == 0)
13085 errmsg ("<address>/<mask> not specified");
13091 errmsg ("VRF ID required, not specified");
13098 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13102 if (vec_len (low_ports) == 0)
13104 errmsg ("At least one port or port range required");
13108 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
13110 mp->is_add = is_add;
13112 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
13114 mp->number_of_ranges = vec_len (low_ports);
13116 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
13117 vec_free (low_ports);
13119 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
13120 vec_free (high_ports);
13122 mp->vrf_id = ntohl (vrf_id);
13130 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13132 unformat_input_t *input = vam->input;
13133 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13134 u32 sw_if_index = ~0;
13136 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
13137 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
13141 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13143 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13145 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13147 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
13149 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
13151 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13153 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13155 else if (unformat (input, "del"))
13161 if (sw_if_index == ~0)
13163 errmsg ("Interface required but not specified");
13169 errmsg ("VRF ID required but not specified");
13173 if (tcp_out_vrf_id == 0
13174 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13177 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13181 /* Construct the API message */
13182 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13184 mp->sw_if_index = ntohl (sw_if_index);
13185 mp->is_add = is_add;
13186 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13187 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13188 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13189 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13194 /* Wait for a reply... */
13200 api_set_punt (vat_main_t * vam)
13202 unformat_input_t *i = vam->input;
13203 vl_api_address_family_t af;
13204 vl_api_set_punt_t *mp;
13210 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13212 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13214 else if (unformat (i, "protocol %d", &protocol))
13216 else if (unformat (i, "port %d", &port))
13218 else if (unformat (i, "del"))
13222 clib_warning ("parse error '%U'", format_unformat_error, i);
13229 mp->is_add = (u8) is_add;
13230 mp->punt.type = PUNT_API_TYPE_L4;
13231 mp->punt.punt.l4.af = af;
13232 mp->punt.punt.l4.protocol = (u8) protocol;
13233 mp->punt.punt.l4.port = htons ((u16) port);
13241 api_delete_subif (vat_main_t * vam)
13243 unformat_input_t *i = vam->input;
13244 vl_api_delete_subif_t *mp;
13245 u32 sw_if_index = ~0;
13248 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13250 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13252 if (unformat (i, "sw_if_index %d", &sw_if_index))
13258 if (sw_if_index == ~0)
13260 errmsg ("missing sw_if_index");
13264 /* Construct the API message */
13265 M (DELETE_SUBIF, mp);
13266 mp->sw_if_index = ntohl (sw_if_index);
13273 #define foreach_pbb_vtr_op \
13274 _("disable", L2_VTR_DISABLED) \
13275 _("pop", L2_VTR_POP_2) \
13276 _("push", L2_VTR_PUSH_2)
13279 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13281 unformat_input_t *i = vam->input;
13282 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13283 u32 sw_if_index = ~0, vtr_op = ~0;
13284 u16 outer_tag = ~0;
13285 u8 dmac[6], smac[6];
13286 u8 dmac_set = 0, smac_set = 0;
13292 /* Shut up coverity */
13293 clib_memset (dmac, 0, sizeof (dmac));
13294 clib_memset (smac, 0, sizeof (smac));
13296 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13298 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13300 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13302 else if (unformat (i, "vtr_op %d", &vtr_op))
13304 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13307 else if (unformat (i, "translate_pbb_stag"))
13309 if (unformat (i, "%d", &tmp))
13311 vtr_op = L2_VTR_TRANSLATE_2_1;
13317 ("translate_pbb_stag operation requires outer tag definition");
13321 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13323 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13325 else if (unformat (i, "sid %d", &sid))
13327 else if (unformat (i, "vlanid %d", &tmp))
13331 clib_warning ("parse error '%U'", format_unformat_error, i);
13336 if ((sw_if_index == ~0) || (vtr_op == ~0))
13338 errmsg ("missing sw_if_index or vtr operation");
13341 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13342 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13345 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13349 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13350 mp->sw_if_index = ntohl (sw_if_index);
13351 mp->vtr_op = ntohl (vtr_op);
13352 mp->outer_tag = ntohs (outer_tag);
13353 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13354 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13355 mp->b_vlanid = ntohs (vlanid);
13356 mp->i_sid = ntohl (sid);
13364 api_flow_classify_set_interface (vat_main_t * vam)
13366 unformat_input_t *i = vam->input;
13367 vl_api_flow_classify_set_interface_t *mp;
13369 int sw_if_index_set;
13370 u32 ip4_table_index = ~0;
13371 u32 ip6_table_index = ~0;
13375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13377 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13378 sw_if_index_set = 1;
13379 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13380 sw_if_index_set = 1;
13381 else if (unformat (i, "del"))
13383 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13385 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13389 clib_warning ("parse error '%U'", format_unformat_error, i);
13394 if (sw_if_index_set == 0)
13396 errmsg ("missing interface name or sw_if_index");
13400 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13402 mp->sw_if_index = ntohl (sw_if_index);
13403 mp->ip4_table_index = ntohl (ip4_table_index);
13404 mp->ip6_table_index = ntohl (ip6_table_index);
13405 mp->is_add = is_add;
13413 api_flow_classify_dump (vat_main_t * vam)
13415 unformat_input_t *i = vam->input;
13416 vl_api_flow_classify_dump_t *mp;
13417 vl_api_control_ping_t *mp_ping;
13418 u8 type = FLOW_CLASSIFY_N_TABLES;
13421 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13425 errmsg ("classify table type must be specified");
13429 if (!vam->json_output)
13431 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13434 M (FLOW_CLASSIFY_DUMP, mp);
13439 /* Use a control ping for synchronization */
13440 MPING (CONTROL_PING, mp_ping);
13443 /* Wait for a reply... */
13449 api_feature_enable_disable (vat_main_t * vam)
13451 unformat_input_t *i = vam->input;
13452 vl_api_feature_enable_disable_t *mp;
13454 u8 *feature_name = 0;
13455 u32 sw_if_index = ~0;
13459 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13461 if (unformat (i, "arc_name %s", &arc_name))
13463 else if (unformat (i, "feature_name %s", &feature_name))
13466 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13468 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13470 else if (unformat (i, "disable"))
13478 errmsg ("missing arc name");
13481 if (vec_len (arc_name) > 63)
13483 errmsg ("arc name too long");
13486 if (feature_name == 0)
13488 errmsg ("missing feature name");
13491 if (vec_len (feature_name) > 63)
13493 errmsg ("feature name too long");
13496 if (sw_if_index == ~0)
13498 errmsg ("missing interface name or sw_if_index");
13502 /* Construct the API message */
13503 M (FEATURE_ENABLE_DISABLE, mp);
13504 mp->sw_if_index = ntohl (sw_if_index);
13505 mp->enable = enable;
13506 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13507 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13508 vec_free (arc_name);
13509 vec_free (feature_name);
13517 api_feature_gso_enable_disable (vat_main_t * vam)
13519 unformat_input_t *i = vam->input;
13520 vl_api_feature_gso_enable_disable_t *mp;
13521 u32 sw_if_index = ~0;
13525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13527 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13531 else if (unformat (i, "enable"))
13533 else if (unformat (i, "disable"))
13539 if (sw_if_index == ~0)
13541 errmsg ("missing interface name or sw_if_index");
13545 /* Construct the API message */
13546 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13547 mp->sw_if_index = ntohl (sw_if_index);
13548 mp->enable_disable = enable;
13556 api_sw_interface_tag_add_del (vat_main_t * vam)
13558 unformat_input_t *i = vam->input;
13559 vl_api_sw_interface_tag_add_del_t *mp;
13560 u32 sw_if_index = ~0;
13565 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13567 if (unformat (i, "tag %s", &tag))
13569 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13571 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13573 else if (unformat (i, "del"))
13579 if (sw_if_index == ~0)
13581 errmsg ("missing interface name or sw_if_index");
13585 if (enable && (tag == 0))
13587 errmsg ("no tag specified");
13591 /* Construct the API message */
13592 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13593 mp->sw_if_index = ntohl (sw_if_index);
13594 mp->is_add = enable;
13596 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13605 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13607 unformat_input_t *i = vam->input;
13608 vl_api_mac_address_t mac = { 0 };
13609 vl_api_sw_interface_add_del_mac_address_t *mp;
13610 u32 sw_if_index = ~0;
13615 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13617 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13619 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13621 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13623 else if (unformat (i, "del"))
13629 if (sw_if_index == ~0)
13631 errmsg ("missing interface name or sw_if_index");
13637 errmsg ("missing MAC address");
13641 /* Construct the API message */
13642 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13643 mp->sw_if_index = ntohl (sw_if_index);
13644 mp->is_add = is_add;
13645 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13652 static void vl_api_l2_xconnect_details_t_handler
13653 (vl_api_l2_xconnect_details_t * mp)
13655 vat_main_t *vam = &vat_main;
13657 print (vam->ofp, "%15d%15d",
13658 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13661 static void vl_api_l2_xconnect_details_t_handler_json
13662 (vl_api_l2_xconnect_details_t * mp)
13664 vat_main_t *vam = &vat_main;
13665 vat_json_node_t *node = NULL;
13667 if (VAT_JSON_ARRAY != vam->json_tree.type)
13669 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13670 vat_json_init_array (&vam->json_tree);
13672 node = vat_json_array_add (&vam->json_tree);
13674 vat_json_init_object (node);
13675 vat_json_object_add_uint (node, "rx_sw_if_index",
13676 ntohl (mp->rx_sw_if_index));
13677 vat_json_object_add_uint (node, "tx_sw_if_index",
13678 ntohl (mp->tx_sw_if_index));
13682 api_l2_xconnect_dump (vat_main_t * vam)
13684 vl_api_l2_xconnect_dump_t *mp;
13685 vl_api_control_ping_t *mp_ping;
13688 if (!vam->json_output)
13690 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13693 M (L2_XCONNECT_DUMP, mp);
13697 /* Use a control ping for synchronization */
13698 MPING (CONTROL_PING, mp_ping);
13706 api_hw_interface_set_mtu (vat_main_t * vam)
13708 unformat_input_t *i = vam->input;
13709 vl_api_hw_interface_set_mtu_t *mp;
13710 u32 sw_if_index = ~0;
13714 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13716 if (unformat (i, "mtu %d", &mtu))
13718 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13720 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13726 if (sw_if_index == ~0)
13728 errmsg ("missing interface name or sw_if_index");
13734 errmsg ("no mtu specified");
13738 /* Construct the API message */
13739 M (HW_INTERFACE_SET_MTU, mp);
13740 mp->sw_if_index = ntohl (sw_if_index);
13741 mp->mtu = ntohs ((u16) mtu);
13749 api_p2p_ethernet_add (vat_main_t * vam)
13751 unformat_input_t *i = vam->input;
13752 vl_api_p2p_ethernet_add_t *mp;
13753 u32 parent_if_index = ~0;
13759 clib_memset (remote_mac, 0, sizeof (remote_mac));
13760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13762 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13764 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13768 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13770 else if (unformat (i, "sub_id %d", &sub_id))
13774 clib_warning ("parse error '%U'", format_unformat_error, i);
13779 if (parent_if_index == ~0)
13781 errmsg ("missing interface name or sw_if_index");
13786 errmsg ("missing remote mac address");
13791 errmsg ("missing sub-interface id");
13795 M (P2P_ETHERNET_ADD, mp);
13796 mp->parent_if_index = ntohl (parent_if_index);
13797 mp->subif_id = ntohl (sub_id);
13798 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13806 api_p2p_ethernet_del (vat_main_t * vam)
13808 unformat_input_t *i = vam->input;
13809 vl_api_p2p_ethernet_del_t *mp;
13810 u32 parent_if_index = ~0;
13815 clib_memset (remote_mac, 0, sizeof (remote_mac));
13816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13818 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13820 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13824 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13828 clib_warning ("parse error '%U'", format_unformat_error, i);
13833 if (parent_if_index == ~0)
13835 errmsg ("missing interface name or sw_if_index");
13840 errmsg ("missing remote mac address");
13844 M (P2P_ETHERNET_DEL, mp);
13845 mp->parent_if_index = ntohl (parent_if_index);
13846 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13854 api_tcp_configure_src_addresses (vat_main_t * vam)
13856 vl_api_tcp_configure_src_addresses_t *mp;
13857 unformat_input_t *i = vam->input;
13858 vl_api_address_t first, last;
13863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13865 if (unformat (i, "%U - %U",
13866 unformat_vl_api_address, &first,
13867 unformat_vl_api_address, &last))
13871 errmsg ("one range per message (range already set)");
13876 else if (unformat (i, "vrf %d", &vrf_id))
13882 if (range_set == 0)
13884 errmsg ("address range not set");
13888 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
13890 mp->vrf_id = ntohl (vrf_id);
13891 clib_memcpy (&mp->first_address, &first, sizeof (first));
13892 clib_memcpy (&mp->last_address, &last, sizeof (last));
13899 static void vl_api_app_namespace_add_del_reply_t_handler
13900 (vl_api_app_namespace_add_del_reply_t * mp)
13902 vat_main_t *vam = &vat_main;
13903 i32 retval = ntohl (mp->retval);
13904 if (vam->async_mode)
13906 vam->async_errors += (retval < 0);
13910 vam->retval = retval;
13912 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
13913 vam->result_ready = 1;
13917 static void vl_api_app_namespace_add_del_reply_t_handler_json
13918 (vl_api_app_namespace_add_del_reply_t * mp)
13920 vat_main_t *vam = &vat_main;
13921 vat_json_node_t node;
13923 vat_json_init_object (&node);
13924 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
13925 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
13927 vat_json_print (vam->ofp, &node);
13928 vat_json_free (&node);
13930 vam->retval = ntohl (mp->retval);
13931 vam->result_ready = 1;
13935 api_app_namespace_add_del (vat_main_t * vam)
13937 vl_api_app_namespace_add_del_t *mp;
13938 unformat_input_t *i = vam->input;
13939 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
13940 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
13944 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13946 if (unformat (i, "id %_%v%_", &ns_id))
13948 else if (unformat (i, "secret %lu", &secret))
13950 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13951 sw_if_index_set = 1;
13952 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
13954 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
13959 if (!ns_id || !secret_set || !sw_if_index_set)
13961 errmsg ("namespace id, secret and sw_if_index must be set");
13964 if (vec_len (ns_id) > 64)
13966 errmsg ("namespace id too long");
13969 M (APP_NAMESPACE_ADD_DEL, mp);
13971 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
13972 mp->secret = clib_host_to_net_u64 (secret);
13973 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
13974 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
13975 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
13983 api_sock_init_shm (vat_main_t * vam)
13985 #if VPP_API_TEST_BUILTIN == 0
13986 unformat_input_t *i = vam->input;
13987 vl_api_shm_elem_config_t *config = 0;
13988 u64 size = 64 << 20;
13991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13993 if (unformat (i, "size %U", unformat_memory_size, &size))
14000 * Canned custom ring allocator config.
14001 * Should probably parse all of this
14003 vec_validate (config, 6);
14004 config[0].type = VL_API_VLIB_RING;
14005 config[0].size = 256;
14006 config[0].count = 32;
14008 config[1].type = VL_API_VLIB_RING;
14009 config[1].size = 1024;
14010 config[1].count = 16;
14012 config[2].type = VL_API_VLIB_RING;
14013 config[2].size = 4096;
14014 config[2].count = 2;
14016 config[3].type = VL_API_CLIENT_RING;
14017 config[3].size = 256;
14018 config[3].count = 32;
14020 config[4].type = VL_API_CLIENT_RING;
14021 config[4].size = 1024;
14022 config[4].count = 16;
14024 config[5].type = VL_API_CLIENT_RING;
14025 config[5].size = 4096;
14026 config[5].count = 2;
14028 config[6].type = VL_API_QUEUE;
14029 config[6].count = 128;
14030 config[6].size = sizeof (uword);
14032 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
14034 vam->client_index_invalid = 1;
14042 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
14044 vat_main_t *vam = &vat_main;
14045 fib_prefix_t lcl, rmt;
14047 ip_prefix_decode (&mp->lcl, &lcl);
14048 ip_prefix_decode (&mp->rmt, &rmt);
14050 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14053 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14054 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14055 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
14056 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
14057 &rmt.fp_addr.ip4, rmt.fp_len,
14058 clib_net_to_host_u16 (mp->rmt_port),
14059 clib_net_to_host_u32 (mp->action_index), mp->tag);
14064 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14065 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14066 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
14067 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
14068 &rmt.fp_addr.ip6, rmt.fp_len,
14069 clib_net_to_host_u16 (mp->rmt_port),
14070 clib_net_to_host_u32 (mp->action_index), mp->tag);
14075 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
14078 vat_main_t *vam = &vat_main;
14079 vat_json_node_t *node = NULL;
14080 struct in6_addr ip6;
14081 struct in_addr ip4;
14083 fib_prefix_t lcl, rmt;
14085 ip_prefix_decode (&mp->lcl, &lcl);
14086 ip_prefix_decode (&mp->rmt, &rmt);
14088 if (VAT_JSON_ARRAY != vam->json_tree.type)
14090 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14091 vat_json_init_array (&vam->json_tree);
14093 node = vat_json_array_add (&vam->json_tree);
14094 vat_json_init_object (node);
14096 vat_json_object_add_uint (node, "appns_index",
14097 clib_net_to_host_u32 (mp->appns_index));
14098 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
14099 vat_json_object_add_uint (node, "scope", mp->scope);
14100 vat_json_object_add_uint (node, "action_index",
14101 clib_net_to_host_u32 (mp->action_index));
14102 vat_json_object_add_uint (node, "lcl_port",
14103 clib_net_to_host_u16 (mp->lcl_port));
14104 vat_json_object_add_uint (node, "rmt_port",
14105 clib_net_to_host_u16 (mp->rmt_port));
14106 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
14107 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
14108 vat_json_object_add_string_copy (node, "tag", mp->tag);
14109 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14111 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
14112 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
14113 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
14114 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
14118 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
14119 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
14120 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
14121 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
14126 api_session_rule_add_del (vat_main_t * vam)
14128 vl_api_session_rule_add_del_t *mp;
14129 unformat_input_t *i = vam->input;
14130 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
14131 u32 appns_index = 0, scope = 0;
14132 ip4_address_t lcl_ip4, rmt_ip4;
14133 ip6_address_t lcl_ip6, rmt_ip6;
14134 u8 is_ip4 = 1, conn_set = 0;
14135 u8 is_add = 1, *tag = 0;
14137 fib_prefix_t lcl, rmt;
14139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14141 if (unformat (i, "del"))
14143 else if (unformat (i, "add"))
14145 else if (unformat (i, "proto tcp"))
14147 else if (unformat (i, "proto udp"))
14149 else if (unformat (i, "appns %d", &appns_index))
14151 else if (unformat (i, "scope %d", &scope))
14153 else if (unformat (i, "tag %_%v%_", &tag))
14157 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14158 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14166 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14167 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14173 else if (unformat (i, "action %d", &action))
14178 if (proto == ~0 || !conn_set || action == ~0)
14180 errmsg ("transport proto, connection and action must be set");
14186 errmsg ("scope should be 0-3");
14190 M (SESSION_RULE_ADD_DEL, mp);
14192 clib_memset (&lcl, 0, sizeof (lcl));
14193 clib_memset (&rmt, 0, sizeof (rmt));
14196 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14197 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14198 lcl.fp_len = lcl_plen;
14199 rmt.fp_len = rmt_plen;
14203 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14204 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14205 lcl.fp_len = lcl_plen;
14206 rmt.fp_len = rmt_plen;
14210 ip_prefix_encode (&lcl, &mp->lcl);
14211 ip_prefix_encode (&rmt, &mp->rmt);
14212 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14213 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14214 mp->transport_proto =
14215 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14216 mp->action_index = clib_host_to_net_u32 (action);
14217 mp->appns_index = clib_host_to_net_u32 (appns_index);
14219 mp->is_add = is_add;
14222 clib_memcpy (mp->tag, tag, vec_len (tag));
14232 api_session_rules_dump (vat_main_t * vam)
14234 vl_api_session_rules_dump_t *mp;
14235 vl_api_control_ping_t *mp_ping;
14238 if (!vam->json_output)
14240 print (vam->ofp, "%=20s", "Session Rules");
14243 M (SESSION_RULES_DUMP, mp);
14247 /* Use a control ping for synchronization */
14248 MPING (CONTROL_PING, mp_ping);
14251 /* Wait for a reply... */
14257 api_ip_container_proxy_add_del (vat_main_t * vam)
14259 vl_api_ip_container_proxy_add_del_t *mp;
14260 unformat_input_t *i = vam->input;
14261 u32 sw_if_index = ~0;
14262 vl_api_prefix_t pfx = { };
14266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14268 if (unformat (i, "del"))
14270 else if (unformat (i, "add"))
14272 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14274 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14279 if (sw_if_index == ~0 || pfx.len == 0)
14281 errmsg ("address and sw_if_index must be set");
14285 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14287 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14288 mp->is_add = is_add;
14289 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14297 api_qos_record_enable_disable (vat_main_t * vam)
14299 unformat_input_t *i = vam->input;
14300 vl_api_qos_record_enable_disable_t *mp;
14301 u32 sw_if_index, qs = 0xff;
14302 u8 sw_if_index_set = 0;
14306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14308 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14309 sw_if_index_set = 1;
14310 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14311 sw_if_index_set = 1;
14312 else if (unformat (i, "%U", unformat_qos_source, &qs))
14314 else if (unformat (i, "disable"))
14318 clib_warning ("parse error '%U'", format_unformat_error, i);
14323 if (sw_if_index_set == 0)
14325 errmsg ("missing interface name or sw_if_index");
14330 errmsg ("input location must be specified");
14334 M (QOS_RECORD_ENABLE_DISABLE, mp);
14336 mp->record.sw_if_index = ntohl (sw_if_index);
14337 mp->record.input_source = qs;
14338 mp->enable = enable;
14347 q_or_quit (vat_main_t * vam)
14349 #if VPP_API_TEST_BUILTIN == 0
14350 longjmp (vam->jump_buf, 1);
14352 return 0; /* not so much */
14356 q (vat_main_t * vam)
14358 return q_or_quit (vam);
14362 quit (vat_main_t * vam)
14364 return q_or_quit (vam);
14368 comment (vat_main_t * vam)
14374 elog_save (vat_main_t * vam)
14376 #if VPP_API_TEST_BUILTIN == 0
14377 elog_main_t *em = &vam->elog_main;
14378 unformat_input_t *i = vam->input;
14379 char *file, *chroot_file;
14380 clib_error_t *error;
14382 if (!unformat (i, "%s", &file))
14384 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14388 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14389 if (strstr (file, "..") || index (file, '/'))
14391 errmsg ("illegal characters in filename '%s'", file);
14395 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14399 errmsg ("Saving %wd of %wd events to %s",
14400 elog_n_events_in_buffer (em),
14401 elog_buffer_capacity (em), chroot_file);
14403 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14404 vec_free (chroot_file);
14407 clib_error_report (error);
14409 errmsg ("Use the vpp event loger...");
14416 elog_setup (vat_main_t * vam)
14418 #if VPP_API_TEST_BUILTIN == 0
14419 elog_main_t *em = &vam->elog_main;
14420 unformat_input_t *i = vam->input;
14421 u32 nevents = 128 << 10;
14423 (void) unformat (i, "nevents %d", &nevents);
14425 elog_init (em, nevents);
14426 vl_api_set_elog_main (em);
14427 vl_api_set_elog_trace_api_messages (1);
14428 errmsg ("Event logger initialized with %u events", nevents);
14430 errmsg ("Use the vpp event loger...");
14436 elog_enable (vat_main_t * vam)
14438 #if VPP_API_TEST_BUILTIN == 0
14439 elog_main_t *em = &vam->elog_main;
14441 elog_enable_disable (em, 1 /* enable */ );
14442 vl_api_set_elog_trace_api_messages (1);
14443 errmsg ("Event logger enabled...");
14445 errmsg ("Use the vpp event loger...");
14451 elog_disable (vat_main_t * vam)
14453 #if VPP_API_TEST_BUILTIN == 0
14454 elog_main_t *em = &vam->elog_main;
14456 elog_enable_disable (em, 0 /* enable */ );
14457 vl_api_set_elog_trace_api_messages (1);
14458 errmsg ("Event logger disabled...");
14460 errmsg ("Use the vpp event loger...");
14466 statseg (vat_main_t * vam)
14468 ssvm_private_t *ssvmp = &vam->stat_segment;
14469 ssvm_shared_header_t *shared_header = ssvmp->sh;
14470 vlib_counter_t **counters;
14471 u64 thread0_index1_packets;
14472 u64 thread0_index1_bytes;
14473 f64 vector_rate, input_rate;
14476 uword *counter_vector_by_name;
14477 if (vam->stat_segment_lockp == 0)
14479 errmsg ("Stat segment not mapped...");
14483 /* look up "/if/rx for sw_if_index 1 as a test */
14485 clib_spinlock_lock (vam->stat_segment_lockp);
14487 counter_vector_by_name = (uword *) shared_header->opaque[1];
14489 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14492 clib_spinlock_unlock (vam->stat_segment_lockp);
14493 errmsg ("/if/tx not found?");
14497 /* Fish per-thread vector of combined counters from shared memory */
14498 counters = (vlib_counter_t **) p[0];
14500 if (vec_len (counters[0]) < 2)
14502 clib_spinlock_unlock (vam->stat_segment_lockp);
14503 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14507 /* Read thread 0 sw_if_index 1 counter */
14508 thread0_index1_packets = counters[0][1].packets;
14509 thread0_index1_bytes = counters[0][1].bytes;
14511 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14514 clib_spinlock_unlock (vam->stat_segment_lockp);
14515 errmsg ("vector_rate not found?");
14519 vector_rate = *(f64 *) (p[0]);
14520 p = hash_get_mem (counter_vector_by_name, "input_rate");
14523 clib_spinlock_unlock (vam->stat_segment_lockp);
14524 errmsg ("input_rate not found?");
14527 input_rate = *(f64 *) (p[0]);
14529 clib_spinlock_unlock (vam->stat_segment_lockp);
14531 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14532 vector_rate, input_rate);
14533 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14534 thread0_index1_packets, thread0_index1_bytes);
14540 cmd_cmp (void *a1, void *a2)
14545 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14549 help (vat_main_t * vam)
14554 unformat_input_t *i = vam->input;
14557 if (unformat (i, "%s", &name))
14561 vec_add1 (name, 0);
14563 hs = hash_get_mem (vam->help_by_name, name);
14565 print (vam->ofp, "usage: %s %s", name, hs[0]);
14567 print (vam->ofp, "No such msg / command '%s'", name);
14572 print (vam->ofp, "Help is available for the following:");
14575 hash_foreach_pair (p, vam->function_by_name,
14577 vec_add1 (cmds, (u8 *)(p->key));
14581 vec_sort_with_function (cmds, cmd_cmp);
14583 for (j = 0; j < vec_len (cmds); j++)
14584 print (vam->ofp, "%s", cmds[j]);
14591 set (vat_main_t * vam)
14593 u8 *name = 0, *value = 0;
14594 unformat_input_t *i = vam->input;
14596 if (unformat (i, "%s", &name))
14598 /* The input buffer is a vector, not a string. */
14599 value = vec_dup (i->buffer);
14600 vec_delete (value, i->index, 0);
14601 /* Almost certainly has a trailing newline */
14602 if (value[vec_len (value) - 1] == '\n')
14603 value[vec_len (value) - 1] = 0;
14604 /* Make sure it's a proper string, one way or the other */
14605 vec_add1 (value, 0);
14606 (void) clib_macro_set_value (&vam->macro_main,
14607 (char *) name, (char *) value);
14610 errmsg ("usage: set <name> <value>");
14618 unset (vat_main_t * vam)
14622 if (unformat (vam->input, "%s", &name))
14623 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14624 errmsg ("unset: %s wasn't set", name);
14637 macro_sort_cmp (void *a1, void *a2)
14639 macro_sort_t *s1 = a1;
14640 macro_sort_t *s2 = a2;
14642 return strcmp ((char *) (s1->name), (char *) (s2->name));
14646 dump_macro_table (vat_main_t * vam)
14648 macro_sort_t *sort_me = 0, *sm;
14653 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14655 vec_add2 (sort_me, sm, 1);
14656 sm->name = (u8 *)(p->key);
14657 sm->value = (u8 *) (p->value[0]);
14661 vec_sort_with_function (sort_me, macro_sort_cmp);
14663 if (vec_len (sort_me))
14664 print (vam->ofp, "%-15s%s", "Name", "Value");
14666 print (vam->ofp, "The macro table is empty...");
14668 for (i = 0; i < vec_len (sort_me); i++)
14669 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14674 dump_node_table (vat_main_t * vam)
14677 vlib_node_t *node, *next_node;
14679 if (vec_len (vam->graph_nodes) == 0)
14681 print (vam->ofp, "Node table empty, issue get_node_graph...");
14685 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14687 node = vam->graph_nodes[0][i];
14688 print (vam->ofp, "[%d] %s", i, node->name);
14689 for (j = 0; j < vec_len (node->next_nodes); j++)
14691 if (node->next_nodes[j] != ~0)
14693 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14694 print (vam->ofp, " [%d] %s", j, next_node->name);
14702 value_sort_cmp (void *a1, void *a2)
14704 name_sort_t *n1 = a1;
14705 name_sort_t *n2 = a2;
14707 if (n1->value < n2->value)
14709 if (n1->value > n2->value)
14716 dump_msg_api_table (vat_main_t * vam)
14718 api_main_t *am = vlibapi_get_main ();
14719 name_sort_t *nses = 0, *ns;
14724 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14726 vec_add2 (nses, ns, 1);
14727 ns->name = (u8 *)(hp->key);
14728 ns->value = (u32) hp->value[0];
14732 vec_sort_with_function (nses, value_sort_cmp);
14734 for (i = 0; i < vec_len (nses); i++)
14735 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14741 get_msg_id (vat_main_t * vam)
14746 if (unformat (vam->input, "%s", &name_and_crc))
14748 message_index = vl_msg_api_get_msg_index (name_and_crc);
14749 if (message_index == ~0)
14751 print (vam->ofp, " '%s' not found", name_and_crc);
14754 print (vam->ofp, " '%s' has message index %d",
14755 name_and_crc, message_index);
14758 errmsg ("name_and_crc required...");
14763 search_node_table (vat_main_t * vam)
14765 unformat_input_t *line_input = vam->input;
14768 vlib_node_t *node, *next_node;
14771 if (vam->graph_node_index_by_name == 0)
14773 print (vam->ofp, "Node table empty, issue get_node_graph...");
14777 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14779 if (unformat (line_input, "%s", &node_to_find))
14781 vec_add1 (node_to_find, 0);
14782 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14785 print (vam->ofp, "%s not found...", node_to_find);
14788 node = vam->graph_nodes[0][p[0]];
14789 print (vam->ofp, "[%d] %s", p[0], node->name);
14790 for (j = 0; j < vec_len (node->next_nodes); j++)
14792 if (node->next_nodes[j] != ~0)
14794 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14795 print (vam->ofp, " [%d] %s", j, next_node->name);
14802 clib_warning ("parse error '%U'", format_unformat_error,
14808 vec_free (node_to_find);
14817 script (vat_main_t * vam)
14819 #if (VPP_API_TEST_BUILTIN==0)
14821 char *save_current_file;
14822 unformat_input_t save_input;
14823 jmp_buf save_jump_buf;
14824 u32 save_line_number;
14826 FILE *new_fp, *save_ifp;
14828 if (unformat (vam->input, "%s", &s))
14830 new_fp = fopen ((char *) s, "r");
14833 errmsg ("Couldn't open script file %s", s);
14840 errmsg ("Missing script name");
14844 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
14845 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
14846 save_ifp = vam->ifp;
14847 save_line_number = vam->input_line_number;
14848 save_current_file = (char *) vam->current_file;
14850 vam->input_line_number = 0;
14852 vam->current_file = s;
14855 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
14856 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
14857 vam->ifp = save_ifp;
14858 vam->input_line_number = save_line_number;
14859 vam->current_file = (u8 *) save_current_file;
14864 clib_warning ("use the exec command...");
14870 echo (vat_main_t * vam)
14872 print (vam->ofp, "%v", vam->input->buffer);
14876 /* List of API message constructors, CLI names map to api_xxx */
14877 #define foreach_vpe_api_msg \
14878 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
14879 _(sw_interface_dump,"") \
14880 _(sw_interface_set_flags, \
14881 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
14882 _(sw_interface_add_del_address, \
14883 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
14884 _(sw_interface_set_rx_mode, \
14885 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
14886 _(sw_interface_set_rx_placement, \
14887 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
14888 _(sw_interface_rx_placement_dump, \
14889 "[<intfc> | sw_if_index <id>]") \
14890 _(sw_interface_set_table, \
14891 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
14892 _(sw_interface_set_mpls_enable, \
14893 "<intfc> | sw_if_index [disable | dis]") \
14894 _(sw_interface_set_vpath, \
14895 "<intfc> | sw_if_index <id> enable | disable") \
14896 _(sw_interface_set_vxlan_bypass, \
14897 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
14898 _(sw_interface_set_l2_xconnect, \
14899 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14900 "enable | disable") \
14901 _(sw_interface_set_l2_bridge, \
14902 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
14903 "[shg <split-horizon-group>] [bvi]\n" \
14904 "enable | disable") \
14905 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
14906 _(bridge_domain_add_del, \
14907 "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") \
14908 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
14910 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
14911 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
14912 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
14914 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14916 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14918 "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]") \
14920 "<vpp-if-name> | sw_if_index <id>") \
14921 _(sw_interface_tap_v2_dump, "") \
14922 _(virtio_pci_create_v2, \
14923 "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]") \
14924 _(virtio_pci_delete, \
14925 "<vpp-if-name> | sw_if_index <id>") \
14926 _(sw_interface_virtio_pci_dump, "") \
14928 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
14929 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14932 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
14933 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14934 "[id <if-id>] [gso]") \
14936 "<vpp-if-name> | sw_if_index <id>") \
14937 _(bond_add_member, \
14938 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
14939 _(bond_detach_member, \
14940 "sw_if_index <n>") \
14941 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
14942 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
14943 _(sw_member_interface_dump, \
14944 "<vpp-if-name> | sw_if_index <id>") \
14945 _(ip_table_add_del, \
14946 "table <n> [ipv6] [add | del]\n") \
14947 _(ip_route_add_del, \
14948 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
14949 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
14950 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
14951 "[multipath] [count <n>] [del]") \
14952 _(ip_mroute_add_del, \
14953 "<src> <grp>/<mask> [table-id <n>]\n" \
14954 "[<intfc> | sw_if_index <id>] [local] [del]") \
14955 _(mpls_table_add_del, \
14956 "table <n> [add | del]\n") \
14957 _(mpls_route_add_del, \
14958 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
14959 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
14960 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
14961 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
14962 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
14963 "[count <n>] [del]") \
14964 _(mpls_ip_bind_unbind, \
14965 "<label> <addr/len>") \
14966 _(mpls_tunnel_add_del, \
14967 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
14968 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
14969 "[l2-only] [out-label <n>]") \
14970 _(sr_mpls_policy_add, \
14971 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
14972 _(sr_mpls_policy_del, \
14974 _(bier_table_add_del, \
14975 "<label> <sub-domain> <set> <bsl> [del]") \
14976 _(bier_route_add_del, \
14977 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
14978 "[<intfc> | sw_if_index <id>]" \
14979 "[weight <n>] [del] [multipath]") \
14980 _(sw_interface_set_unnumbered, \
14981 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
14982 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
14983 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
14984 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
14985 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
14986 "[outer_vlan_id_any][inner_vlan_id_any]") \
14987 _(ip_table_replace_begin, "table <n> [ipv6]") \
14988 _(ip_table_flush, "table <n> [ipv6]") \
14989 _(ip_table_replace_end, "table <n> [ipv6]") \
14990 _(set_ip_flow_hash, \
14991 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
14992 _(sw_interface_ip6_enable_disable, \
14993 "<intfc> | sw_if_index <id> enable | disable") \
14994 _(l2_patch_add_del, \
14995 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14996 "enable | disable") \
14997 _(sr_localsid_add_del, \
14998 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
14999 "fib-table <num> (end.psp) sw_if_index <num>") \
15000 _(classify_add_del_table, \
15001 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15002 " [del] [del-chain] mask <mask-value>\n" \
15003 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
15004 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
15005 _(classify_add_del_session, \
15006 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15007 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15008 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
15009 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
15010 _(classify_set_interface_ip_table, \
15011 "<intfc> | sw_if_index <nn> table <nn>") \
15012 _(classify_set_interface_l2_tables, \
15013 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15014 " [other-table <nn>]") \
15015 _(get_node_index, "node <node-name") \
15016 _(add_node_next, "node <node-name> next <next-node-name>") \
15017 _(vxlan_offload_rx, \
15018 "hw { <interface name> | hw_if_index <nn>} " \
15019 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
15020 _(vxlan_add_del_tunnel, \
15021 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
15022 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
15023 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
15024 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15025 _(l2_fib_clear_table, "") \
15026 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15027 _(l2_interface_vlan_tag_rewrite, \
15028 "<intfc> | sw_if_index <nn> \n" \
15029 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15030 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15031 _(create_vhost_user_if, \
15032 "socket <filename> [server] [renumber <dev_instance>] " \
15033 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
15034 "[mac <mac_address>] [packed]") \
15035 _(modify_vhost_user_if, \
15036 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15037 "[server] [renumber <dev_instance>] [gso] [packed]") \
15038 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15039 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
15040 _(show_version, "") \
15041 _(show_threads, "") \
15042 _(vxlan_gpe_add_del_tunnel, \
15043 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
15044 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
15045 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
15046 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
15047 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15048 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
15049 _(interface_name_renumber, \
15050 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15051 _(input_acl_set_interface, \
15052 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15053 " [l2-table <nn>] [del]") \
15054 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
15055 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15056 _(ip_dump, "ipv4 | ipv6") \
15057 _(ipsec_spd_add_del, "spd_id <n> [del]") \
15058 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15060 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15061 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15062 " integ_alg <alg> integ_key <hex>") \
15063 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
15064 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15065 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15066 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
15067 _(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
15068 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
15069 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
15070 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
15071 " [instance <n>]") \
15072 _(ipsec_sa_dump, "[sa_id <n>]") \
15073 _(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
15074 _(delete_loopback,"sw_if_index <nn>") \
15075 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15076 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
15077 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
15078 _(want_interface_events, "enable|disable") \
15079 _(get_first_msg_id, "client <name>") \
15080 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15081 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
15082 "fib-id <nn> [ip4][ip6][default]") \
15083 _(get_node_graph, " ") \
15084 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
15085 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15086 _(ioam_disable, "") \
15087 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
15088 _(af_packet_delete, "name <host interface name>") \
15089 _(af_packet_dump, "") \
15090 _(policer_add_del, "name <policer name> <params> [del]") \
15091 _(policer_dump, "[name <policer name>]") \
15092 _(policer_classify_set_interface, \
15093 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15094 " [l2-table <nn>] [del]") \
15095 _(policer_classify_dump, "type [ip4|ip6|l2]") \
15096 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
15097 _(mpls_table_dump, "") \
15098 _(mpls_route_dump, "table-id <ID>") \
15099 _(classify_table_ids, "") \
15100 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15101 _(classify_table_info, "table_id <nn>") \
15102 _(classify_session_dump, "table_id <nn>") \
15103 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15104 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15105 "[template_interval <nn>] [udp_checksum]") \
15106 _(ipfix_exporter_dump, "") \
15107 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15108 _(ipfix_classify_stream_dump, "") \
15109 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
15110 _(ipfix_classify_table_dump, "") \
15111 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
15112 _(sw_interface_span_dump, "[l2]") \
15113 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15114 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
15115 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
15116 _(pg_enable_disable, "[stream <id>] disable") \
15117 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
15118 _(ip_source_and_port_range_check_add_del, \
15119 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15120 _(ip_source_and_port_range_check_interface_add_del, \
15121 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
15122 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15123 _(delete_subif,"<intfc> | sw_if_index <nn>") \
15124 _(l2_interface_pbb_tag_rewrite, \
15125 "<intfc> | sw_if_index <nn> \n" \
15126 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15127 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15128 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
15129 _(flow_classify_set_interface, \
15130 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
15131 _(flow_classify_dump, "type [ip4|ip6]") \
15132 _(ip_table_dump, "") \
15133 _(ip_route_dump, "table-id [ip4|ip6]") \
15134 _(ip_mtable_dump, "") \
15135 _(ip_mroute_dump, "table-id [ip4|ip6]") \
15136 _(feature_enable_disable, "arc_name <arc_name> " \
15137 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
15138 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
15139 "[enable | disable] ") \
15140 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
15142 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
15143 "mac <mac-address> [del]") \
15144 _(l2_xconnect_dump, "") \
15145 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
15146 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
15147 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
15148 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
15149 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
15150 _(sock_init_shm, "size <nnn>") \
15151 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
15152 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
15153 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15154 _(session_rules_dump, "") \
15155 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15156 _(output_acl_set_interface, \
15157 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15158 " [l2-table <nn>] [del]") \
15159 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15161 /* List of command functions, CLI names map directly to functions */
15162 #define foreach_cli_function \
15163 _(comment, "usage: comment <ignore-rest-of-line>") \
15164 _(dump_interface_table, "usage: dump_interface_table") \
15165 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15166 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15167 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15168 _(dump_macro_table, "usage: dump_macro_table ") \
15169 _(dump_node_table, "usage: dump_node_table") \
15170 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15171 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15172 _(elog_disable, "usage: elog_disable") \
15173 _(elog_enable, "usage: elog_enable") \
15174 _(elog_save, "usage: elog_save <filename>") \
15175 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15176 _(echo, "usage: echo <message>") \
15177 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15178 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15179 _(help, "usage: help") \
15180 _(q, "usage: quit") \
15181 _(quit, "usage: quit") \
15182 _(search_node_table, "usage: search_node_table <name>...") \
15183 _(set, "usage: set <variable-name> <value>") \
15184 _(script, "usage: script <file-name>") \
15185 _(statseg, "usage: statseg") \
15186 _(unset, "usage: unset <variable-name>")
15189 static void vl_api_##n##_t_handler_uni \
15190 (vl_api_##n##_t * mp) \
15192 vat_main_t * vam = &vat_main; \
15193 if (vam->json_output) { \
15194 vl_api_##n##_t_handler_json(mp); \
15196 vl_api_##n##_t_handler(mp); \
15199 foreach_vpe_api_reply_msg;
15200 #if VPP_API_TEST_BUILTIN == 0
15201 foreach_standalone_reply_msg;
15206 vat_api_hookup (vat_main_t * vam)
15209 vl_msg_api_set_handlers(VL_API_##N, #n, \
15210 vl_api_##n##_t_handler_uni, \
15212 vl_api_##n##_t_endian, \
15213 vl_api_##n##_t_print, \
15214 sizeof(vl_api_##n##_t), 1);
15215 foreach_vpe_api_reply_msg;
15216 #if VPP_API_TEST_BUILTIN == 0
15217 foreach_standalone_reply_msg;
15221 #if (VPP_API_TEST_BUILTIN==0)
15222 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15224 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15226 vam->function_by_name = hash_create_string (0, sizeof (uword));
15228 vam->help_by_name = hash_create_string (0, sizeof (uword));
15231 /* API messages we can send */
15232 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15233 foreach_vpe_api_msg;
15237 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15238 foreach_vpe_api_msg;
15241 /* CLI functions */
15242 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15243 foreach_cli_function;
15247 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15248 foreach_cli_function;
15252 #if VPP_API_TEST_BUILTIN
15253 static clib_error_t *
15254 vat_api_hookup_shim (vlib_main_t * vm)
15256 vat_api_hookup (&vat_main);
15260 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15264 * fd.io coding-style-patch-verification: ON
15267 * eval: (c-set-style "gnu")