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_create_vhost_user_if_v2_reply_t_handler
2435 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2437 vat_main_t *vam = &vat_main;
2438 i32 retval = ntohl (mp->retval);
2439 if (vam->async_mode)
2441 vam->async_errors += (retval < 0);
2445 vam->retval = retval;
2446 vam->sw_if_index = ntohl (mp->sw_if_index);
2447 vam->result_ready = 1;
2449 vam->regenerate_interface_table = 1;
2452 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2453 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2455 vat_main_t *vam = &vat_main;
2456 vat_json_node_t node;
2458 vat_json_init_object (&node);
2459 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2460 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2462 vat_json_print (vam->ofp, &node);
2463 vat_json_free (&node);
2465 vam->retval = ntohl (mp->retval);
2466 vam->result_ready = 1;
2469 static void vl_api_ip_address_details_t_handler
2470 (vl_api_ip_address_details_t * mp)
2472 vat_main_t *vam = &vat_main;
2473 static ip_address_details_t empty_ip_address_details = { {0} };
2474 ip_address_details_t *address = NULL;
2475 ip_details_t *current_ip_details = NULL;
2476 ip_details_t *details = NULL;
2478 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2480 if (!details || vam->current_sw_if_index >= vec_len (details)
2481 || !details[vam->current_sw_if_index].present)
2483 errmsg ("ip address details arrived but not stored");
2484 errmsg ("ip_dump should be called first");
2488 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2490 #define addresses (current_ip_details->addr)
2492 vec_validate_init_empty (addresses, vec_len (addresses),
2493 empty_ip_address_details);
2495 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2497 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2498 address->prefix_length = mp->prefix.len;
2502 static void vl_api_ip_address_details_t_handler_json
2503 (vl_api_ip_address_details_t * mp)
2505 vat_main_t *vam = &vat_main;
2506 vat_json_node_t *node = NULL;
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 node = vat_json_array_add (&vam->json_tree);
2515 vat_json_init_object (node);
2516 vat_json_object_add_prefix (node, &mp->prefix);
2520 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2522 vat_main_t *vam = &vat_main;
2523 static ip_details_t empty_ip_details = { 0 };
2524 ip_details_t *ip = NULL;
2525 u32 sw_if_index = ~0;
2527 sw_if_index = ntohl (mp->sw_if_index);
2529 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2530 sw_if_index, empty_ip_details);
2532 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2539 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2541 vat_main_t *vam = &vat_main;
2543 if (VAT_JSON_ARRAY != vam->json_tree.type)
2545 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2546 vat_json_init_array (&vam->json_tree);
2548 vat_json_array_add_uint (&vam->json_tree,
2549 clib_net_to_host_u32 (mp->sw_if_index));
2552 static void vl_api_get_first_msg_id_reply_t_handler
2553 (vl_api_get_first_msg_id_reply_t * mp)
2555 vat_main_t *vam = &vat_main;
2556 i32 retval = ntohl (mp->retval);
2558 if (vam->async_mode)
2560 vam->async_errors += (retval < 0);
2564 vam->retval = retval;
2565 vam->result_ready = 1;
2569 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2573 static void vl_api_get_first_msg_id_reply_t_handler_json
2574 (vl_api_get_first_msg_id_reply_t * mp)
2576 vat_main_t *vam = &vat_main;
2577 vat_json_node_t node;
2579 vat_json_init_object (&node);
2580 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2581 vat_json_object_add_uint (&node, "first_msg_id",
2582 (uint) ntohs (mp->first_msg_id));
2584 vat_json_print (vam->ofp, &node);
2585 vat_json_free (&node);
2587 vam->retval = ntohl (mp->retval);
2588 vam->result_ready = 1;
2591 static void vl_api_get_node_graph_reply_t_handler
2592 (vl_api_get_node_graph_reply_t * mp)
2594 vat_main_t *vam = &vat_main;
2595 i32 retval = ntohl (mp->retval);
2596 u8 *pvt_copy, *reply;
2601 if (vam->async_mode)
2603 vam->async_errors += (retval < 0);
2607 vam->retval = retval;
2608 vam->result_ready = 1;
2611 /* "Should never happen..." */
2615 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2616 pvt_copy = vec_dup (reply);
2618 /* Toss the shared-memory original... */
2619 oldheap = vl_msg_push_heap ();
2623 vl_msg_pop_heap (oldheap);
2625 if (vam->graph_nodes)
2627 hash_free (vam->graph_node_index_by_name);
2629 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2631 node = vam->graph_nodes[0][i];
2632 vec_free (node->name);
2633 vec_free (node->next_nodes);
2636 vec_free (vam->graph_nodes[0]);
2637 vec_free (vam->graph_nodes);
2640 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2641 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2642 vec_free (pvt_copy);
2644 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2646 node = vam->graph_nodes[0][i];
2647 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2651 static void vl_api_get_node_graph_reply_t_handler_json
2652 (vl_api_get_node_graph_reply_t * mp)
2654 vat_main_t *vam = &vat_main;
2656 vat_json_node_t node;
2659 /* $$$$ make this real? */
2660 vat_json_init_object (&node);
2661 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2662 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2664 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2666 /* Toss the shared-memory original... */
2667 oldheap = vl_msg_push_heap ();
2671 vl_msg_pop_heap (oldheap);
2673 vat_json_print (vam->ofp, &node);
2674 vat_json_free (&node);
2676 vam->retval = ntohl (mp->retval);
2677 vam->result_ready = 1;
2681 format_policer_type (u8 * s, va_list * va)
2683 u32 i = va_arg (*va, u32);
2685 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2686 s = format (s, "1r2c");
2687 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2688 s = format (s, "1r3c");
2689 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2690 s = format (s, "2r3c-2698");
2691 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2692 s = format (s, "2r3c-4115");
2693 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2694 s = format (s, "2r3c-mef5cf1");
2696 s = format (s, "ILLEGAL");
2701 format_policer_rate_type (u8 * s, va_list * va)
2703 u32 i = va_arg (*va, u32);
2705 if (i == SSE2_QOS_RATE_KBPS)
2706 s = format (s, "kbps");
2707 else if (i == SSE2_QOS_RATE_PPS)
2708 s = format (s, "pps");
2710 s = format (s, "ILLEGAL");
2715 format_policer_round_type (u8 * s, va_list * va)
2717 u32 i = va_arg (*va, u32);
2719 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2720 s = format (s, "closest");
2721 else if (i == SSE2_QOS_ROUND_TO_UP)
2722 s = format (s, "up");
2723 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2724 s = format (s, "down");
2726 s = format (s, "ILLEGAL");
2731 format_policer_action_type (u8 * s, va_list * va)
2733 u32 i = va_arg (*va, u32);
2735 if (i == SSE2_QOS_ACTION_DROP)
2736 s = format (s, "drop");
2737 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2738 s = format (s, "transmit");
2739 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2740 s = format (s, "mark-and-transmit");
2742 s = format (s, "ILLEGAL");
2747 format_dscp (u8 * s, va_list * va)
2749 u32 i = va_arg (*va, u32);
2754 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2758 return format (s, "ILLEGAL");
2760 s = format (s, "%s", t);
2765 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2767 vat_main_t *vam = &vat_main;
2768 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2770 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2771 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2773 conform_dscp_str = format (0, "");
2775 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2776 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2778 exceed_dscp_str = format (0, "");
2780 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2781 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2783 violate_dscp_str = format (0, "");
2785 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2786 "rate type %U, round type %U, %s rate, %s color-aware, "
2787 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2788 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2789 "conform action %U%s, exceed action %U%s, violate action %U%s",
2791 format_policer_type, mp->type,
2794 clib_net_to_host_u64 (mp->cb),
2795 clib_net_to_host_u64 (mp->eb),
2796 format_policer_rate_type, mp->rate_type,
2797 format_policer_round_type, mp->round_type,
2798 mp->single_rate ? "single" : "dual",
2799 mp->color_aware ? "is" : "not",
2800 ntohl (mp->cir_tokens_per_period),
2801 ntohl (mp->pir_tokens_per_period),
2803 ntohl (mp->current_limit),
2804 ntohl (mp->current_bucket),
2805 ntohl (mp->extended_limit),
2806 ntohl (mp->extended_bucket),
2807 clib_net_to_host_u64 (mp->last_update_time),
2808 format_policer_action_type, mp->conform_action.type,
2810 format_policer_action_type, mp->exceed_action.type,
2812 format_policer_action_type, mp->violate_action.type,
2815 vec_free (conform_dscp_str);
2816 vec_free (exceed_dscp_str);
2817 vec_free (violate_dscp_str);
2820 static void vl_api_policer_details_t_handler_json
2821 (vl_api_policer_details_t * mp)
2823 vat_main_t *vam = &vat_main;
2824 vat_json_node_t *node;
2825 u8 *rate_type_str, *round_type_str, *type_str;
2826 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2828 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2830 format (0, "%U", format_policer_round_type, mp->round_type);
2831 type_str = format (0, "%U", format_policer_type, mp->type);
2832 conform_action_str = format (0, "%U", format_policer_action_type,
2833 mp->conform_action.type);
2834 exceed_action_str = format (0, "%U", format_policer_action_type,
2835 mp->exceed_action.type);
2836 violate_action_str = format (0, "%U", format_policer_action_type,
2837 mp->violate_action.type);
2839 if (VAT_JSON_ARRAY != vam->json_tree.type)
2841 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2842 vat_json_init_array (&vam->json_tree);
2844 node = vat_json_array_add (&vam->json_tree);
2846 vat_json_init_object (node);
2847 vat_json_object_add_string_copy (node, "name", mp->name);
2848 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2849 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2850 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2851 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2852 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2853 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2854 vat_json_object_add_string_copy (node, "type", type_str);
2855 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2856 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2857 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2858 vat_json_object_add_uint (node, "cir_tokens_per_period",
2859 ntohl (mp->cir_tokens_per_period));
2860 vat_json_object_add_uint (node, "eir_tokens_per_period",
2861 ntohl (mp->pir_tokens_per_period));
2862 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2863 vat_json_object_add_uint (node, "current_bucket",
2864 ntohl (mp->current_bucket));
2865 vat_json_object_add_uint (node, "extended_limit",
2866 ntohl (mp->extended_limit));
2867 vat_json_object_add_uint (node, "extended_bucket",
2868 ntohl (mp->extended_bucket));
2869 vat_json_object_add_uint (node, "last_update_time",
2870 ntohl (mp->last_update_time));
2871 vat_json_object_add_string_copy (node, "conform_action",
2872 conform_action_str);
2873 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2875 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2876 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2877 vec_free (dscp_str);
2879 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2880 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2882 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2883 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2884 vec_free (dscp_str);
2886 vat_json_object_add_string_copy (node, "violate_action",
2887 violate_action_str);
2888 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2890 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2891 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2892 vec_free (dscp_str);
2895 vec_free (rate_type_str);
2896 vec_free (round_type_str);
2897 vec_free (type_str);
2898 vec_free (conform_action_str);
2899 vec_free (exceed_action_str);
2900 vec_free (violate_action_str);
2904 vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
2907 vat_main_t *vam = &vat_main;
2908 int i, count = ntohl (mp->count);
2911 print (vam->ofp, "classify table ids (%d) : ", count);
2912 for (i = 0; i < count; i++)
2914 print (vam->ofp, "%d", ntohl (mp->ids[i]));
2915 print (vam->ofp, (i < count - 1) ? "," : "");
2917 vam->retval = ntohl (mp->retval);
2918 vam->result_ready = 1;
2922 vl_api_classify_table_ids_reply_t_handler_json
2923 (vl_api_classify_table_ids_reply_t * mp)
2925 vat_main_t *vam = &vat_main;
2926 int i, count = ntohl (mp->count);
2930 vat_json_node_t node;
2932 vat_json_init_object (&node);
2933 for (i = 0; i < count; i++)
2935 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
2937 vat_json_print (vam->ofp, &node);
2938 vat_json_free (&node);
2940 vam->retval = ntohl (mp->retval);
2941 vam->result_ready = 1;
2945 vl_api_classify_table_by_interface_reply_t_handler
2946 (vl_api_classify_table_by_interface_reply_t * mp)
2948 vat_main_t *vam = &vat_main;
2951 table_id = ntohl (mp->l2_table_id);
2953 print (vam->ofp, "l2 table id : %d", table_id);
2955 print (vam->ofp, "l2 table id : No input ACL tables configured");
2956 table_id = ntohl (mp->ip4_table_id);
2958 print (vam->ofp, "ip4 table id : %d", table_id);
2960 print (vam->ofp, "ip4 table id : No input ACL tables configured");
2961 table_id = ntohl (mp->ip6_table_id);
2963 print (vam->ofp, "ip6 table id : %d", table_id);
2965 print (vam->ofp, "ip6 table id : No input ACL tables configured");
2966 vam->retval = ntohl (mp->retval);
2967 vam->result_ready = 1;
2971 vl_api_classify_table_by_interface_reply_t_handler_json
2972 (vl_api_classify_table_by_interface_reply_t * mp)
2974 vat_main_t *vam = &vat_main;
2975 vat_json_node_t node;
2977 vat_json_init_object (&node);
2979 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
2980 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
2981 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
2983 vat_json_print (vam->ofp, &node);
2984 vat_json_free (&node);
2986 vam->retval = ntohl (mp->retval);
2987 vam->result_ready = 1;
2990 static void vl_api_policer_add_del_reply_t_handler
2991 (vl_api_policer_add_del_reply_t * mp)
2993 vat_main_t *vam = &vat_main;
2994 i32 retval = ntohl (mp->retval);
2995 if (vam->async_mode)
2997 vam->async_errors += (retval < 0);
3001 vam->retval = retval;
3002 vam->result_ready = 1;
3003 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3005 * Note: this is just barely thread-safe, depends on
3006 * the main thread spinning waiting for an answer...
3008 errmsg ("policer index %d", ntohl (mp->policer_index));
3012 static void vl_api_policer_add_del_reply_t_handler_json
3013 (vl_api_policer_add_del_reply_t * mp)
3015 vat_main_t *vam = &vat_main;
3016 vat_json_node_t node;
3018 vat_json_init_object (&node);
3019 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3020 vat_json_object_add_uint (&node, "policer_index",
3021 ntohl (mp->policer_index));
3023 vat_json_print (vam->ofp, &node);
3024 vat_json_free (&node);
3026 vam->retval = ntohl (mp->retval);
3027 vam->result_ready = 1;
3030 /* Format hex dump. */
3032 format_hex_bytes (u8 * s, va_list * va)
3034 u8 *bytes = va_arg (*va, u8 *);
3035 int n_bytes = va_arg (*va, int);
3038 /* Print short or long form depending on byte count. */
3039 uword short_form = n_bytes <= 32;
3040 u32 indent = format_get_indent (s);
3045 for (i = 0; i < n_bytes; i++)
3047 if (!short_form && (i % 32) == 0)
3048 s = format (s, "%08x: ", i);
3049 s = format (s, "%02x", bytes[i]);
3050 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3051 s = format (s, "\n%U", format_white_space, indent);
3058 vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3061 vat_main_t *vam = &vat_main;
3062 i32 retval = ntohl (mp->retval);
3065 print (vam->ofp, "classify table info :");
3066 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
3067 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3068 ntohl (mp->miss_next_index));
3069 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
3070 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3071 ntohl (mp->match_n_vectors));
3072 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
3073 ntohl (mp->mask_length));
3075 vam->retval = retval;
3076 vam->result_ready = 1;
3080 vl_api_classify_table_info_reply_t_handler_json
3081 (vl_api_classify_table_info_reply_t * mp)
3083 vat_main_t *vam = &vat_main;
3084 vat_json_node_t node;
3086 i32 retval = ntohl (mp->retval);
3089 vat_json_init_object (&node);
3091 vat_json_object_add_int (&node, "sessions",
3092 ntohl (mp->active_sessions));
3093 vat_json_object_add_int (&node, "nexttbl",
3094 ntohl (mp->next_table_index));
3095 vat_json_object_add_int (&node, "nextnode",
3096 ntohl (mp->miss_next_index));
3097 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3098 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3099 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3100 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3101 ntohl (mp->mask_length), 0);
3102 vat_json_object_add_string_copy (&node, "mask", s);
3104 vat_json_print (vam->ofp, &node);
3105 vat_json_free (&node);
3107 vam->retval = ntohl (mp->retval);
3108 vam->result_ready = 1;
3112 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3115 vat_main_t *vam = &vat_main;
3117 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3118 ntohl (mp->hit_next_index), ntohl (mp->advance),
3119 ntohl (mp->opaque_index));
3120 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
3121 ntohl (mp->match_length));
3125 vl_api_classify_session_details_t_handler_json
3126 (vl_api_classify_session_details_t * mp)
3128 vat_main_t *vam = &vat_main;
3129 vat_json_node_t *node = NULL;
3131 if (VAT_JSON_ARRAY != vam->json_tree.type)
3133 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3134 vat_json_init_array (&vam->json_tree);
3136 node = vat_json_array_add (&vam->json_tree);
3138 vat_json_init_object (node);
3139 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3140 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3141 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3143 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3145 vat_json_object_add_string_copy (node, "match", s);
3148 static void vl_api_pg_create_interface_reply_t_handler
3149 (vl_api_pg_create_interface_reply_t * mp)
3151 vat_main_t *vam = &vat_main;
3153 vam->retval = ntohl (mp->retval);
3154 vam->result_ready = 1;
3157 static void vl_api_pg_create_interface_reply_t_handler_json
3158 (vl_api_pg_create_interface_reply_t * mp)
3160 vat_main_t *vam = &vat_main;
3161 vat_json_node_t node;
3163 i32 retval = ntohl (mp->retval);
3166 vat_json_init_object (&node);
3168 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
3170 vat_json_print (vam->ofp, &node);
3171 vat_json_free (&node);
3173 vam->retval = ntohl (mp->retval);
3174 vam->result_ready = 1;
3177 static void vl_api_policer_classify_details_t_handler
3178 (vl_api_policer_classify_details_t * mp)
3180 vat_main_t *vam = &vat_main;
3182 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3183 ntohl (mp->table_index));
3186 static void vl_api_policer_classify_details_t_handler_json
3187 (vl_api_policer_classify_details_t * mp)
3189 vat_main_t *vam = &vat_main;
3190 vat_json_node_t *node;
3192 if (VAT_JSON_ARRAY != vam->json_tree.type)
3194 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3195 vat_json_init_array (&vam->json_tree);
3197 node = vat_json_array_add (&vam->json_tree);
3199 vat_json_init_object (node);
3200 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3201 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3204 static void vl_api_flow_classify_details_t_handler
3205 (vl_api_flow_classify_details_t * mp)
3207 vat_main_t *vam = &vat_main;
3209 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3210 ntohl (mp->table_index));
3213 static void vl_api_flow_classify_details_t_handler_json
3214 (vl_api_flow_classify_details_t * mp)
3216 vat_main_t *vam = &vat_main;
3217 vat_json_node_t *node;
3219 if (VAT_JSON_ARRAY != vam->json_tree.type)
3221 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3222 vat_json_init_array (&vam->json_tree);
3224 node = vat_json_array_add (&vam->json_tree);
3226 vat_json_init_object (node);
3227 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3228 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3232 * Generate boilerplate reply handlers, which
3233 * dig the return value out of the xxx_reply_t API message,
3234 * stick it into vam->retval, and set vam->result_ready
3236 * Could also do this by pointing N message decode slots at
3237 * a single function, but that could break in subtle ways.
3240 #define foreach_standard_reply_retval_handler \
3241 _(sw_interface_set_flags_reply) \
3242 _(sw_interface_add_del_address_reply) \
3243 _(sw_interface_set_rx_mode_reply) \
3244 _(sw_interface_set_rx_placement_reply) \
3245 _(sw_interface_set_table_reply) \
3246 _(sw_interface_set_mpls_enable_reply) \
3247 _(sw_interface_set_vpath_reply) \
3248 _(sw_interface_set_vxlan_bypass_reply) \
3249 _(sw_interface_set_vxlan_gpe_bypass_reply) \
3250 _(sw_interface_set_l2_bridge_reply) \
3251 _(sw_interface_set_bond_weight_reply) \
3252 _(bridge_domain_add_del_reply) \
3253 _(sw_interface_set_l2_xconnect_reply) \
3254 _(l2fib_add_del_reply) \
3255 _(l2fib_flush_int_reply) \
3256 _(l2fib_flush_bd_reply) \
3257 _(ip_route_add_del_reply) \
3258 _(ip_table_add_del_reply) \
3259 _(ip_table_replace_begin_reply) \
3260 _(ip_table_flush_reply) \
3261 _(ip_table_replace_end_reply) \
3262 _(ip_mroute_add_del_reply) \
3263 _(mpls_route_add_del_reply) \
3264 _(mpls_table_add_del_reply) \
3265 _(mpls_ip_bind_unbind_reply) \
3266 _(bier_route_add_del_reply) \
3267 _(bier_table_add_del_reply) \
3268 _(sw_interface_set_unnumbered_reply) \
3269 _(set_ip_flow_hash_reply) \
3270 _(sw_interface_ip6_enable_disable_reply) \
3271 _(l2_patch_add_del_reply) \
3272 _(sr_mpls_policy_add_reply) \
3273 _(sr_mpls_policy_mod_reply) \
3274 _(sr_mpls_policy_del_reply) \
3275 _(sr_policy_add_reply) \
3276 _(sr_policy_mod_reply) \
3277 _(sr_policy_del_reply) \
3278 _(sr_localsid_add_del_reply) \
3279 _(sr_steering_add_del_reply) \
3280 _(classify_add_del_session_reply) \
3281 _(classify_set_interface_ip_table_reply) \
3282 _(classify_set_interface_l2_tables_reply) \
3283 _(l2_fib_clear_table_reply) \
3284 _(l2_interface_efp_filter_reply) \
3285 _(l2_interface_vlan_tag_rewrite_reply) \
3286 _(modify_vhost_user_if_reply) \
3287 _(modify_vhost_user_if_v2_reply) \
3288 _(delete_vhost_user_if_reply) \
3289 _(want_l2_macs_events_reply) \
3290 _(input_acl_set_interface_reply) \
3291 _(ipsec_spd_add_del_reply) \
3292 _(ipsec_interface_add_del_spd_reply) \
3293 _(ipsec_spd_entry_add_del_reply) \
3294 _(ipsec_sad_entry_add_del_reply) \
3295 _(delete_loopback_reply) \
3296 _(bd_ip_mac_add_del_reply) \
3297 _(bd_ip_mac_flush_reply) \
3298 _(want_interface_events_reply) \
3299 _(cop_interface_enable_disable_reply) \
3300 _(cop_whitelist_enable_disable_reply) \
3301 _(sw_interface_clear_stats_reply) \
3302 _(ioam_enable_reply) \
3303 _(ioam_disable_reply) \
3304 _(af_packet_delete_reply) \
3305 _(policer_classify_set_interface_reply) \
3306 _(set_ipfix_exporter_reply) \
3307 _(set_ipfix_classify_stream_reply) \
3308 _(ipfix_classify_table_add_del_reply) \
3309 _(flow_classify_set_interface_reply) \
3310 _(sw_interface_span_enable_disable_reply) \
3311 _(pg_capture_reply) \
3312 _(pg_enable_disable_reply) \
3313 _(pg_interface_enable_disable_coalesce_reply) \
3314 _(ip_source_and_port_range_check_add_del_reply) \
3315 _(ip_source_and_port_range_check_interface_add_del_reply)\
3316 _(delete_subif_reply) \
3317 _(l2_interface_pbb_tag_rewrite_reply) \
3319 _(feature_enable_disable_reply) \
3320 _(feature_gso_enable_disable_reply) \
3321 _(sw_interface_tag_add_del_reply) \
3322 _(sw_interface_add_del_mac_address_reply) \
3323 _(hw_interface_set_mtu_reply) \
3324 _(p2p_ethernet_add_reply) \
3325 _(p2p_ethernet_del_reply) \
3326 _(tcp_configure_src_addresses_reply) \
3327 _(session_rule_add_del_reply) \
3328 _(ip_container_proxy_add_del_reply) \
3329 _(output_acl_set_interface_reply) \
3330 _(qos_record_enable_disable_reply) \
3334 static void vl_api_##n##_t_handler \
3335 (vl_api_##n##_t * mp) \
3337 vat_main_t * vam = &vat_main; \
3338 i32 retval = ntohl(mp->retval); \
3339 if (vam->async_mode) { \
3340 vam->async_errors += (retval < 0); \
3342 vam->retval = retval; \
3343 vam->result_ready = 1; \
3346 foreach_standard_reply_retval_handler;
3350 static void vl_api_##n##_t_handler_json \
3351 (vl_api_##n##_t * mp) \
3353 vat_main_t * vam = &vat_main; \
3354 vat_json_node_t node; \
3355 vat_json_init_object(&node); \
3356 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3357 vat_json_print(vam->ofp, &node); \
3358 vam->retval = ntohl(mp->retval); \
3359 vam->result_ready = 1; \
3361 foreach_standard_reply_retval_handler;
3365 * Table of message reply handlers, must include boilerplate handlers
3369 #define foreach_vpe_api_reply_msg \
3370 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3371 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3372 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3373 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3374 _(CONTROL_PING_REPLY, control_ping_reply) \
3375 _(CLI_REPLY, cli_reply) \
3376 _(CLI_INBAND_REPLY, cli_inband_reply) \
3377 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3378 sw_interface_add_del_address_reply) \
3379 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3380 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3381 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3382 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3383 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3384 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3385 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3386 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3387 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3388 sw_interface_set_l2_xconnect_reply) \
3389 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3390 sw_interface_set_l2_bridge_reply) \
3391 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3392 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3393 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3394 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3395 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3396 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3397 _(L2_FLAGS_REPLY, l2_flags_reply) \
3398 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3399 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3400 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3401 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3402 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3403 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3404 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3405 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3406 _(BOND_CREATE_REPLY, bond_create_reply) \
3407 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3408 _(BOND_DELETE_REPLY, bond_delete_reply) \
3409 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3410 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3411 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3412 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3413 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3414 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3415 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3416 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3417 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3418 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3419 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3420 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3421 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3422 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3423 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3424 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3425 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3426 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3427 sw_interface_set_unnumbered_reply) \
3428 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3429 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3430 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3431 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3432 sw_interface_ip6_enable_disable_reply) \
3433 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3434 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3435 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3436 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3437 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3438 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3439 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3440 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3441 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3442 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3443 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3444 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3445 classify_set_interface_ip_table_reply) \
3446 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3447 classify_set_interface_l2_tables_reply) \
3448 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3449 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3450 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3451 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3452 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3453 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3454 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3455 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3456 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3457 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3458 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3459 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
3460 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
3461 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3462 _(SHOW_VERSION_REPLY, show_version_reply) \
3463 _(SHOW_THREADS_REPLY, show_threads_reply) \
3464 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3465 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3466 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3467 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3468 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3469 _(L2_MACS_EVENT, l2_macs_event) \
3470 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3471 _(IP_ADDRESS_DETAILS, ip_address_details) \
3472 _(IP_DETAILS, ip_details) \
3473 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3474 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3475 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3476 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3477 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3478 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3479 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3480 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3481 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3482 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3483 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3484 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3485 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3486 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3487 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3488 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3489 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3490 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3491 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3492 _(AF_PACKET_DETAILS, af_packet_details) \
3493 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3494 _(POLICER_DETAILS, policer_details) \
3495 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3496 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3497 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3498 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3499 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3500 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3501 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3502 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3503 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3504 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3505 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3506 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3507 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3508 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3509 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3510 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3511 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3512 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3513 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3514 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3515 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3516 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3517 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3518 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3519 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3520 ip_source_and_port_range_check_add_del_reply) \
3521 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3522 ip_source_and_port_range_check_interface_add_del_reply) \
3523 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3524 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3525 _(SET_PUNT_REPLY, set_punt_reply) \
3526 _(IP_TABLE_DETAILS, ip_table_details) \
3527 _(IP_ROUTE_DETAILS, ip_route_details) \
3528 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3529 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3530 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3531 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3532 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3533 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3534 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3535 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3536 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3537 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3538 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3539 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3540 _(SESSION_RULES_DETAILS, session_rules_details) \
3541 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3542 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3543 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3544 _(FLOW_ADD_REPLY, flow_add_reply) \
3546 #define foreach_standalone_reply_msg \
3547 _(SW_INTERFACE_EVENT, sw_interface_event)
3555 #define STR_VTR_OP_CASE(op) \
3556 case L2_VTR_ ## op: \
3560 str_vtr_op (u32 vtr_op)
3564 STR_VTR_OP_CASE (DISABLED);
3565 STR_VTR_OP_CASE (PUSH_1);
3566 STR_VTR_OP_CASE (PUSH_2);
3567 STR_VTR_OP_CASE (POP_1);
3568 STR_VTR_OP_CASE (POP_2);
3569 STR_VTR_OP_CASE (TRANSLATE_1_1);
3570 STR_VTR_OP_CASE (TRANSLATE_1_2);
3571 STR_VTR_OP_CASE (TRANSLATE_2_1);
3572 STR_VTR_OP_CASE (TRANSLATE_2_2);
3579 dump_sub_interface_table (vat_main_t * vam)
3581 const sw_interface_subif_t *sub = NULL;
3583 if (vam->json_output)
3586 ("JSON output supported only for VPE API calls and dump_stats_table");
3591 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3592 "Interface", "sw_if_index",
3593 "sub id", "dot1ad", "tags", "outer id",
3594 "inner id", "exact", "default", "outer any", "inner any");
3596 vec_foreach (sub, vam->sw_if_subif_table)
3599 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3600 sub->interface_name,
3602 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3603 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3604 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3605 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3606 if (sub->vtr_op != L2_VTR_DISABLED)
3609 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3610 "tag1: %d tag2: %d ]",
3611 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3612 sub->vtr_tag1, sub->vtr_tag2);
3620 name_sort_cmp (void *a1, void *a2)
3622 name_sort_t *n1 = a1;
3623 name_sort_t *n2 = a2;
3625 return strcmp ((char *) n1->name, (char *) n2->name);
3629 dump_interface_table (vat_main_t * vam)
3632 name_sort_t *nses = 0, *ns;
3634 if (vam->json_output)
3637 ("JSON output supported only for VPE API calls and dump_stats_table");
3642 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3644 vec_add2 (nses, ns, 1);
3645 ns->name = (u8 *)(p->key);
3646 ns->value = (u32) p->value[0];
3650 vec_sort_with_function (nses, name_sort_cmp);
3652 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3653 vec_foreach (ns, nses)
3655 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3662 dump_ip_table (vat_main_t * vam, int is_ipv6)
3664 const ip_details_t *det = NULL;
3665 const ip_address_details_t *address = NULL;
3668 print (vam->ofp, "%-12s", "sw_if_index");
3670 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3677 print (vam->ofp, "%-12d", i);
3678 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3683 vec_foreach (address, det->addr)
3687 is_ipv6 ? format_ip6_address : format_ip4_address,
3688 address->ip, address->prefix_length);
3696 dump_ipv4_table (vat_main_t * vam)
3698 if (vam->json_output)
3701 ("JSON output supported only for VPE API calls and dump_stats_table");
3705 return dump_ip_table (vam, 0);
3709 dump_ipv6_table (vat_main_t * vam)
3711 if (vam->json_output)
3714 ("JSON output supported only for VPE API calls and dump_stats_table");
3718 return dump_ip_table (vam, 1);
3722 * Pass CLI buffers directly in the CLI_INBAND API message,
3723 * instead of an additional shared memory area.
3726 exec_inband (vat_main_t * vam)
3728 vl_api_cli_inband_t *mp;
3729 unformat_input_t *i = vam->input;
3732 if (vec_len (i->buffer) == 0)
3735 if (vam->exec_mode == 0 && unformat (i, "mode"))
3740 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3747 * In order for the CLI command to work, it
3748 * must be a vector ending in \n, not a C-string ending
3751 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3752 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3756 /* json responses may or may not include a useful reply... */
3757 if (vec_len (vam->cmd_reply))
3758 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3763 exec (vat_main_t * vam)
3765 return exec_inband (vam);
3769 api_create_loopback (vat_main_t * vam)
3771 unformat_input_t *i = vam->input;
3772 vl_api_create_loopback_t *mp;
3773 vl_api_create_loopback_instance_t *mp_lbi;
3776 u8 is_specified = 0;
3777 u32 user_instance = 0;
3780 clib_memset (mac_address, 0, sizeof (mac_address));
3782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3784 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3786 if (unformat (i, "instance %d", &user_instance))
3794 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3795 mp_lbi->is_specified = is_specified;
3797 mp_lbi->user_instance = htonl (user_instance);
3799 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3804 /* Construct the API message */
3805 M (CREATE_LOOPBACK, mp);
3807 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3816 api_delete_loopback (vat_main_t * vam)
3818 unformat_input_t *i = vam->input;
3819 vl_api_delete_loopback_t *mp;
3820 u32 sw_if_index = ~0;
3823 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3825 if (unformat (i, "sw_if_index %d", &sw_if_index))
3831 if (sw_if_index == ~0)
3833 errmsg ("missing sw_if_index");
3837 /* Construct the API message */
3838 M (DELETE_LOOPBACK, mp);
3839 mp->sw_if_index = ntohl (sw_if_index);
3847 api_want_interface_events (vat_main_t * vam)
3849 unformat_input_t *i = vam->input;
3850 vl_api_want_interface_events_t *mp;
3854 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3856 if (unformat (i, "enable"))
3858 else if (unformat (i, "disable"))
3866 errmsg ("missing enable|disable");
3870 M (WANT_INTERFACE_EVENTS, mp);
3871 mp->enable_disable = enable;
3873 vam->interface_event_display = enable;
3881 /* Note: non-static, called once to set up the initial intfc table */
3883 api_sw_interface_dump (vat_main_t * vam)
3885 vl_api_sw_interface_dump_t *mp;
3886 vl_api_control_ping_t *mp_ping;
3888 name_sort_t *nses = 0, *ns;
3889 sw_interface_subif_t *sub = NULL;
3892 /* Toss the old name table */
3894 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3896 vec_add2 (nses, ns, 1);
3897 ns->name = (u8 *)(p->key);
3898 ns->value = (u32) p->value[0];
3902 hash_free (vam->sw_if_index_by_interface_name);
3904 vec_foreach (ns, nses) vec_free (ns->name);
3908 vec_foreach (sub, vam->sw_if_subif_table)
3910 vec_free (sub->interface_name);
3912 vec_free (vam->sw_if_subif_table);
3914 /* recreate the interface name hash table */
3915 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3918 * Ask for all interface names. Otherwise, the epic catalog of
3919 * name filters becomes ridiculously long, and vat ends up needing
3920 * to be taught about new interface types.
3922 M (SW_INTERFACE_DUMP, mp);
3925 /* Use a control ping for synchronization */
3926 MPING (CONTROL_PING, mp_ping);
3934 api_sw_interface_set_flags (vat_main_t * vam)
3936 unformat_input_t *i = vam->input;
3937 vl_api_sw_interface_set_flags_t *mp;
3939 u8 sw_if_index_set = 0;
3943 /* Parse args required to build the message */
3944 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3946 if (unformat (i, "admin-up"))
3948 else if (unformat (i, "admin-down"))
3951 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3952 sw_if_index_set = 1;
3953 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3954 sw_if_index_set = 1;
3959 if (sw_if_index_set == 0)
3961 errmsg ("missing interface name or sw_if_index");
3965 /* Construct the API message */
3966 M (SW_INTERFACE_SET_FLAGS, mp);
3967 mp->sw_if_index = ntohl (sw_if_index);
3968 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3973 /* Wait for a reply, return the good/bad news... */
3979 api_sw_interface_set_rx_mode (vat_main_t * vam)
3981 unformat_input_t *i = vam->input;
3982 vl_api_sw_interface_set_rx_mode_t *mp;
3984 u8 sw_if_index_set = 0;
3986 u8 queue_id_valid = 0;
3988 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3990 /* Parse args required to build the message */
3991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3993 if (unformat (i, "queue %d", &queue_id))
3995 else if (unformat (i, "polling"))
3996 mode = VNET_HW_IF_RX_MODE_POLLING;
3997 else if (unformat (i, "interrupt"))
3998 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3999 else if (unformat (i, "adaptive"))
4000 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
4002 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4003 sw_if_index_set = 1;
4004 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4005 sw_if_index_set = 1;
4010 if (sw_if_index_set == 0)
4012 errmsg ("missing interface name or sw_if_index");
4015 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
4017 errmsg ("missing rx-mode");
4021 /* Construct the API message */
4022 M (SW_INTERFACE_SET_RX_MODE, mp);
4023 mp->sw_if_index = ntohl (sw_if_index);
4024 mp->mode = (vl_api_rx_mode_t) mode;
4025 mp->queue_id_valid = queue_id_valid;
4026 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
4031 /* Wait for a reply, return the good/bad news... */
4037 api_sw_interface_set_rx_placement (vat_main_t * vam)
4039 unformat_input_t *i = vam->input;
4040 vl_api_sw_interface_set_rx_placement_t *mp;
4042 u8 sw_if_index_set = 0;
4045 u32 queue_id, thread_index;
4047 /* Parse args required to build the message */
4048 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4050 if (unformat (i, "queue %d", &queue_id))
4052 else if (unformat (i, "main"))
4054 else if (unformat (i, "worker %d", &thread_index))
4057 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4058 sw_if_index_set = 1;
4059 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4060 sw_if_index_set = 1;
4065 if (sw_if_index_set == 0)
4067 errmsg ("missing interface name or sw_if_index");
4073 /* Construct the API message */
4074 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4075 mp->sw_if_index = ntohl (sw_if_index);
4076 mp->worker_id = ntohl (thread_index);
4077 mp->queue_id = ntohl (queue_id);
4078 mp->is_main = is_main;
4082 /* Wait for a reply, return the good/bad news... */
4087 static void vl_api_sw_interface_rx_placement_details_t_handler
4088 (vl_api_sw_interface_rx_placement_details_t * mp)
4090 vat_main_t *vam = &vat_main;
4091 u32 worker_id = ntohl (mp->worker_id);
4094 "\n%-11d %-11s %-6d %-5d %-9s",
4095 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4096 worker_id, ntohl (mp->queue_id),
4098 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4101 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4102 (vl_api_sw_interface_rx_placement_details_t * mp)
4104 vat_main_t *vam = &vat_main;
4105 vat_json_node_t *node = NULL;
4107 if (VAT_JSON_ARRAY != vam->json_tree.type)
4109 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4110 vat_json_init_array (&vam->json_tree);
4112 node = vat_json_array_add (&vam->json_tree);
4114 vat_json_init_object (node);
4115 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4116 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4117 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4118 vat_json_object_add_uint (node, "mode", mp->mode);
4122 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4124 unformat_input_t *i = vam->input;
4125 vl_api_sw_interface_rx_placement_dump_t *mp;
4126 vl_api_control_ping_t *mp_ping;
4129 u8 sw_if_index_set = 0;
4131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4133 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4135 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4142 "\n%-11s %-11s %-6s %-5s %-4s",
4143 "sw_if_index", "main/worker", "thread", "queue", "mode");
4145 /* Dump Interface rx placement */
4146 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4148 if (sw_if_index_set)
4149 mp->sw_if_index = htonl (sw_if_index);
4151 mp->sw_if_index = ~0;
4155 /* Use a control ping for synchronization */
4156 MPING (CONTROL_PING, mp_ping);
4164 api_sw_interface_clear_stats (vat_main_t * vam)
4166 unformat_input_t *i = vam->input;
4167 vl_api_sw_interface_clear_stats_t *mp;
4169 u8 sw_if_index_set = 0;
4172 /* Parse args required to build the message */
4173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4175 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4176 sw_if_index_set = 1;
4177 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4178 sw_if_index_set = 1;
4183 /* Construct the API message */
4184 M (SW_INTERFACE_CLEAR_STATS, mp);
4186 if (sw_if_index_set == 1)
4187 mp->sw_if_index = ntohl (sw_if_index);
4189 mp->sw_if_index = ~0;
4194 /* Wait for a reply, return the good/bad news... */
4200 api_sw_interface_add_del_address (vat_main_t * vam)
4202 unformat_input_t *i = vam->input;
4203 vl_api_sw_interface_add_del_address_t *mp;
4205 u8 sw_if_index_set = 0;
4206 u8 is_add = 1, del_all = 0;
4207 u32 address_length = 0;
4208 u8 v4_address_set = 0;
4209 u8 v6_address_set = 0;
4210 ip4_address_t v4address;
4211 ip6_address_t v6address;
4214 /* Parse args required to build the message */
4215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4217 if (unformat (i, "del-all"))
4219 else if (unformat (i, "del"))
4222 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4223 sw_if_index_set = 1;
4224 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4225 sw_if_index_set = 1;
4226 else if (unformat (i, "%U/%d",
4227 unformat_ip4_address, &v4address, &address_length))
4229 else if (unformat (i, "%U/%d",
4230 unformat_ip6_address, &v6address, &address_length))
4236 if (sw_if_index_set == 0)
4238 errmsg ("missing interface name or sw_if_index");
4241 if (v4_address_set && v6_address_set)
4243 errmsg ("both v4 and v6 addresses set");
4246 if (!v4_address_set && !v6_address_set && !del_all)
4248 errmsg ("no addresses set");
4252 /* Construct the API message */
4253 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4255 mp->sw_if_index = ntohl (sw_if_index);
4256 mp->is_add = is_add;
4257 mp->del_all = del_all;
4260 mp->prefix.address.af = ADDRESS_IP6;
4261 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4265 mp->prefix.address.af = ADDRESS_IP4;
4266 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4268 mp->prefix.len = address_length;
4273 /* Wait for a reply, return good/bad news */
4279 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4281 unformat_input_t *i = vam->input;
4282 vl_api_sw_interface_set_mpls_enable_t *mp;
4284 u8 sw_if_index_set = 0;
4288 /* Parse args required to build the message */
4289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4291 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4292 sw_if_index_set = 1;
4293 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4294 sw_if_index_set = 1;
4295 else if (unformat (i, "disable"))
4297 else if (unformat (i, "dis"))
4303 if (sw_if_index_set == 0)
4305 errmsg ("missing interface name or sw_if_index");
4309 /* Construct the API message */
4310 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4312 mp->sw_if_index = ntohl (sw_if_index);
4313 mp->enable = enable;
4318 /* Wait for a reply... */
4324 api_sw_interface_set_table (vat_main_t * vam)
4326 unformat_input_t *i = vam->input;
4327 vl_api_sw_interface_set_table_t *mp;
4328 u32 sw_if_index, vrf_id = 0;
4329 u8 sw_if_index_set = 0;
4333 /* Parse args required to build the message */
4334 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4336 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4337 sw_if_index_set = 1;
4338 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4339 sw_if_index_set = 1;
4340 else if (unformat (i, "vrf %d", &vrf_id))
4342 else if (unformat (i, "ipv6"))
4348 if (sw_if_index_set == 0)
4350 errmsg ("missing interface name or sw_if_index");
4354 /* Construct the API message */
4355 M (SW_INTERFACE_SET_TABLE, mp);
4357 mp->sw_if_index = ntohl (sw_if_index);
4358 mp->is_ipv6 = is_ipv6;
4359 mp->vrf_id = ntohl (vrf_id);
4364 /* Wait for a reply... */
4369 static void vl_api_sw_interface_get_table_reply_t_handler
4370 (vl_api_sw_interface_get_table_reply_t * mp)
4372 vat_main_t *vam = &vat_main;
4374 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4376 vam->retval = ntohl (mp->retval);
4377 vam->result_ready = 1;
4381 static void vl_api_sw_interface_get_table_reply_t_handler_json
4382 (vl_api_sw_interface_get_table_reply_t * mp)
4384 vat_main_t *vam = &vat_main;
4385 vat_json_node_t node;
4387 vat_json_init_object (&node);
4388 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4389 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4391 vat_json_print (vam->ofp, &node);
4392 vat_json_free (&node);
4394 vam->retval = ntohl (mp->retval);
4395 vam->result_ready = 1;
4399 api_sw_interface_get_table (vat_main_t * vam)
4401 unformat_input_t *i = vam->input;
4402 vl_api_sw_interface_get_table_t *mp;
4404 u8 sw_if_index_set = 0;
4408 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4410 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4411 sw_if_index_set = 1;
4412 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4413 sw_if_index_set = 1;
4414 else if (unformat (i, "ipv6"))
4420 if (sw_if_index_set == 0)
4422 errmsg ("missing interface name or sw_if_index");
4426 M (SW_INTERFACE_GET_TABLE, mp);
4427 mp->sw_if_index = htonl (sw_if_index);
4428 mp->is_ipv6 = is_ipv6;
4436 api_sw_interface_set_vpath (vat_main_t * vam)
4438 unformat_input_t *i = vam->input;
4439 vl_api_sw_interface_set_vpath_t *mp;
4440 u32 sw_if_index = 0;
4441 u8 sw_if_index_set = 0;
4445 /* Parse args required to build the message */
4446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4448 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4449 sw_if_index_set = 1;
4450 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4451 sw_if_index_set = 1;
4452 else if (unformat (i, "enable"))
4454 else if (unformat (i, "disable"))
4460 if (sw_if_index_set == 0)
4462 errmsg ("missing interface name or sw_if_index");
4466 /* Construct the API message */
4467 M (SW_INTERFACE_SET_VPATH, mp);
4469 mp->sw_if_index = ntohl (sw_if_index);
4470 mp->enable = is_enable;
4475 /* Wait for a reply... */
4481 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4483 unformat_input_t *i = vam->input;
4484 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4485 u32 sw_if_index = 0;
4486 u8 sw_if_index_set = 0;
4491 /* Parse args required to build the message */
4492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4494 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4495 sw_if_index_set = 1;
4496 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4497 sw_if_index_set = 1;
4498 else if (unformat (i, "enable"))
4500 else if (unformat (i, "disable"))
4502 else if (unformat (i, "ip4"))
4504 else if (unformat (i, "ip6"))
4510 if (sw_if_index_set == 0)
4512 errmsg ("missing interface name or sw_if_index");
4516 /* Construct the API message */
4517 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4519 mp->sw_if_index = ntohl (sw_if_index);
4520 mp->enable = is_enable;
4521 mp->is_ipv6 = is_ipv6;
4526 /* Wait for a reply... */
4532 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4534 unformat_input_t *i = vam->input;
4535 vl_api_sw_interface_set_l2_xconnect_t *mp;
4537 u8 rx_sw_if_index_set = 0;
4539 u8 tx_sw_if_index_set = 0;
4543 /* Parse args required to build the message */
4544 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4546 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4547 rx_sw_if_index_set = 1;
4548 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4549 tx_sw_if_index_set = 1;
4550 else if (unformat (i, "rx"))
4552 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4554 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4556 rx_sw_if_index_set = 1;
4561 else if (unformat (i, "tx"))
4563 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4565 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4567 tx_sw_if_index_set = 1;
4572 else if (unformat (i, "enable"))
4574 else if (unformat (i, "disable"))
4580 if (rx_sw_if_index_set == 0)
4582 errmsg ("missing rx interface name or rx_sw_if_index");
4586 if (enable && (tx_sw_if_index_set == 0))
4588 errmsg ("missing tx interface name or tx_sw_if_index");
4592 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4594 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4595 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4596 mp->enable = enable;
4604 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4606 unformat_input_t *i = vam->input;
4607 vl_api_sw_interface_set_l2_bridge_t *mp;
4608 vl_api_l2_port_type_t port_type;
4610 u8 rx_sw_if_index_set = 0;
4617 port_type = L2_API_PORT_TYPE_NORMAL;
4619 /* Parse args required to build the message */
4620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4622 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4623 rx_sw_if_index_set = 1;
4624 else if (unformat (i, "bd_id %d", &bd_id))
4628 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4629 rx_sw_if_index_set = 1;
4630 else if (unformat (i, "shg %d", &shg))
4632 else if (unformat (i, "bvi"))
4633 port_type = L2_API_PORT_TYPE_BVI;
4634 else if (unformat (i, "uu-fwd"))
4635 port_type = L2_API_PORT_TYPE_UU_FWD;
4636 else if (unformat (i, "enable"))
4638 else if (unformat (i, "disable"))
4644 if (rx_sw_if_index_set == 0)
4646 errmsg ("missing rx interface name or sw_if_index");
4650 if (enable && (bd_id_set == 0))
4652 errmsg ("missing bridge domain");
4656 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4658 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4659 mp->bd_id = ntohl (bd_id);
4661 mp->port_type = ntohl (port_type);
4662 mp->enable = enable;
4670 api_bridge_domain_dump (vat_main_t * vam)
4672 unformat_input_t *i = vam->input;
4673 vl_api_bridge_domain_dump_t *mp;
4674 vl_api_control_ping_t *mp_ping;
4678 /* Parse args required to build the message */
4679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4681 if (unformat (i, "bd_id %d", &bd_id))
4687 M (BRIDGE_DOMAIN_DUMP, mp);
4688 mp->bd_id = ntohl (bd_id);
4691 /* Use a control ping for synchronization */
4692 MPING (CONTROL_PING, mp_ping);
4700 api_bridge_domain_add_del (vat_main_t * vam)
4702 unformat_input_t *i = vam->input;
4703 vl_api_bridge_domain_add_del_t *mp;
4706 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4711 /* Parse args required to build the message */
4712 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4714 if (unformat (i, "bd_id %d", &bd_id))
4716 else if (unformat (i, "flood %d", &flood))
4718 else if (unformat (i, "uu-flood %d", &uu_flood))
4720 else if (unformat (i, "forward %d", &forward))
4722 else if (unformat (i, "learn %d", &learn))
4724 else if (unformat (i, "arp-term %d", &arp_term))
4726 else if (unformat (i, "mac-age %d", &mac_age))
4728 else if (unformat (i, "bd-tag %s", &bd_tag))
4730 else if (unformat (i, "del"))
4733 flood = uu_flood = forward = learn = 0;
4741 errmsg ("missing bridge domain");
4748 errmsg ("mac age must be less than 256 ");
4753 if ((bd_tag) && (vec_len (bd_tag) > 63))
4755 errmsg ("bd-tag cannot be longer than 63");
4760 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4762 mp->bd_id = ntohl (bd_id);
4764 mp->uu_flood = uu_flood;
4765 mp->forward = forward;
4767 mp->arp_term = arp_term;
4768 mp->is_add = is_add;
4769 mp->mac_age = (u8) mac_age;
4772 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4773 mp->bd_tag[vec_len (bd_tag)] = 0;
4784 api_l2fib_flush_bd (vat_main_t * vam)
4786 unformat_input_t *i = vam->input;
4787 vl_api_l2fib_flush_bd_t *mp;
4791 /* Parse args required to build the message */
4792 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4794 if (unformat (i, "bd_id %d", &bd_id));
4801 errmsg ("missing bridge domain");
4805 M (L2FIB_FLUSH_BD, mp);
4807 mp->bd_id = htonl (bd_id);
4815 api_l2fib_flush_int (vat_main_t * vam)
4817 unformat_input_t *i = vam->input;
4818 vl_api_l2fib_flush_int_t *mp;
4819 u32 sw_if_index = ~0;
4822 /* Parse args required to build the message */
4823 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4825 if (unformat (i, "sw_if_index %d", &sw_if_index));
4827 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4832 if (sw_if_index == ~0)
4834 errmsg ("missing interface name or sw_if_index");
4838 M (L2FIB_FLUSH_INT, mp);
4840 mp->sw_if_index = ntohl (sw_if_index);
4848 api_l2fib_add_del (vat_main_t * vam)
4850 unformat_input_t *i = vam->input;
4851 vl_api_l2fib_add_del_t *mp;
4857 u32 sw_if_index = 0;
4858 u8 sw_if_index_set = 0;
4867 /* Parse args required to build the message */
4868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4870 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4872 else if (unformat (i, "bd_id %d", &bd_id))
4874 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4875 sw_if_index_set = 1;
4876 else if (unformat (i, "sw_if"))
4878 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4881 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4882 sw_if_index_set = 1;
4887 else if (unformat (i, "static"))
4889 else if (unformat (i, "filter"))
4894 else if (unformat (i, "bvi"))
4899 else if (unformat (i, "del"))
4901 else if (unformat (i, "count %d", &count))
4909 errmsg ("missing mac address");
4915 errmsg ("missing bridge domain");
4919 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4921 errmsg ("missing interface name or sw_if_index");
4927 /* Turn on async mode */
4928 vam->async_mode = 1;
4929 vam->async_errors = 0;
4930 before = vat_time_now (vam);
4933 for (j = 0; j < count; j++)
4935 M (L2FIB_ADD_DEL, mp);
4937 clib_memcpy (mp->mac, mac, 6);
4938 mp->bd_id = ntohl (bd_id);
4939 mp->is_add = is_add;
4940 mp->sw_if_index = ntohl (sw_if_index);
4944 mp->static_mac = static_mac;
4945 mp->filter_mac = filter_mac;
4946 mp->bvi_mac = bvi_mac;
4948 increment_mac_address (mac);
4955 vl_api_control_ping_t *mp_ping;
4958 /* Shut off async mode */
4959 vam->async_mode = 0;
4961 MPING (CONTROL_PING, mp_ping);
4964 timeout = vat_time_now (vam) + 1.0;
4965 while (vat_time_now (vam) < timeout)
4966 if (vam->result_ready == 1)
4971 if (vam->retval == -99)
4974 if (vam->async_errors > 0)
4976 errmsg ("%d asynchronous errors", vam->async_errors);
4979 vam->async_errors = 0;
4980 after = vat_time_now (vam);
4982 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4983 count, after - before, count / (after - before));
4989 /* Wait for a reply... */
4993 /* Return the good/bad news */
4994 return (vam->retval);
4998 api_bridge_domain_set_mac_age (vat_main_t * vam)
5000 unformat_input_t *i = vam->input;
5001 vl_api_bridge_domain_set_mac_age_t *mp;
5006 /* Parse args required to build the message */
5007 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5009 if (unformat (i, "bd_id %d", &bd_id));
5010 else if (unformat (i, "mac-age %d", &mac_age));
5017 errmsg ("missing bridge domain");
5023 errmsg ("mac age must be less than 256 ");
5027 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
5029 mp->bd_id = htonl (bd_id);
5030 mp->mac_age = (u8) mac_age;
5038 api_l2_flags (vat_main_t * vam)
5040 unformat_input_t *i = vam->input;
5041 vl_api_l2_flags_t *mp;
5044 u8 sw_if_index_set = 0;
5048 /* Parse args required to build the message */
5049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5051 if (unformat (i, "sw_if_index %d", &sw_if_index))
5052 sw_if_index_set = 1;
5053 else if (unformat (i, "sw_if"))
5055 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5058 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5059 sw_if_index_set = 1;
5064 else if (unformat (i, "learn"))
5066 else if (unformat (i, "forward"))
5068 else if (unformat (i, "flood"))
5070 else if (unformat (i, "uu-flood"))
5071 flags |= L2_UU_FLOOD;
5072 else if (unformat (i, "arp-term"))
5073 flags |= L2_ARP_TERM;
5074 else if (unformat (i, "off"))
5076 else if (unformat (i, "disable"))
5082 if (sw_if_index_set == 0)
5084 errmsg ("missing interface name or sw_if_index");
5090 mp->sw_if_index = ntohl (sw_if_index);
5091 mp->feature_bitmap = ntohl (flags);
5092 mp->is_set = is_set;
5100 api_bridge_flags (vat_main_t * vam)
5102 unformat_input_t *i = vam->input;
5103 vl_api_bridge_flags_t *mp;
5107 bd_flags_t flags = 0;
5110 /* Parse args required to build the message */
5111 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5113 if (unformat (i, "bd_id %d", &bd_id))
5115 else if (unformat (i, "learn"))
5116 flags |= BRIDGE_API_FLAG_LEARN;
5117 else if (unformat (i, "forward"))
5118 flags |= BRIDGE_API_FLAG_FWD;
5119 else if (unformat (i, "flood"))
5120 flags |= BRIDGE_API_FLAG_FLOOD;
5121 else if (unformat (i, "uu-flood"))
5122 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5123 else if (unformat (i, "arp-term"))
5124 flags |= BRIDGE_API_FLAG_ARP_TERM;
5125 else if (unformat (i, "off"))
5127 else if (unformat (i, "disable"))
5135 errmsg ("missing bridge domain");
5139 M (BRIDGE_FLAGS, mp);
5141 mp->bd_id = ntohl (bd_id);
5142 mp->flags = ntohl (flags);
5143 mp->is_set = is_set;
5151 api_bd_ip_mac_add_del (vat_main_t * vam)
5153 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5154 vl_api_mac_address_t mac = { 0 };
5155 unformat_input_t *i = vam->input;
5156 vl_api_bd_ip_mac_add_del_t *mp;
5165 /* Parse args required to build the message */
5166 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5168 if (unformat (i, "bd_id %d", &bd_id))
5172 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5176 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5180 else if (unformat (i, "del"))
5188 errmsg ("missing bridge domain");
5191 else if (ip_set == 0)
5193 errmsg ("missing IP address");
5196 else if (mac_set == 0)
5198 errmsg ("missing MAC address");
5202 M (BD_IP_MAC_ADD_DEL, mp);
5204 mp->entry.bd_id = ntohl (bd_id);
5205 mp->is_add = is_add;
5207 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5208 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5216 api_bd_ip_mac_flush (vat_main_t * vam)
5218 unformat_input_t *i = vam->input;
5219 vl_api_bd_ip_mac_flush_t *mp;
5224 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5226 if (unformat (i, "bd_id %d", &bd_id))
5236 errmsg ("missing bridge domain");
5240 M (BD_IP_MAC_FLUSH, mp);
5242 mp->bd_id = ntohl (bd_id);
5249 static void vl_api_bd_ip_mac_details_t_handler
5250 (vl_api_bd_ip_mac_details_t * mp)
5252 vat_main_t *vam = &vat_main;
5256 ntohl (mp->entry.bd_id),
5257 format_vl_api_mac_address, mp->entry.mac,
5258 format_vl_api_address, &mp->entry.ip);
5261 static void vl_api_bd_ip_mac_details_t_handler_json
5262 (vl_api_bd_ip_mac_details_t * mp)
5264 vat_main_t *vam = &vat_main;
5265 vat_json_node_t *node = NULL;
5267 if (VAT_JSON_ARRAY != vam->json_tree.type)
5269 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5270 vat_json_init_array (&vam->json_tree);
5272 node = vat_json_array_add (&vam->json_tree);
5274 vat_json_init_object (node);
5275 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5276 vat_json_object_add_string_copy (node, "mac_address",
5277 format (0, "%U", format_vl_api_mac_address,
5281 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5282 vat_json_object_add_string_copy (node, "ip_address", ip);
5287 api_bd_ip_mac_dump (vat_main_t * vam)
5289 unformat_input_t *i = vam->input;
5290 vl_api_bd_ip_mac_dump_t *mp;
5291 vl_api_control_ping_t *mp_ping;
5296 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5298 if (unformat (i, "bd_id %d", &bd_id))
5307 "\n%-5s %-7s %-20s %-30s",
5308 "bd_id", "is_ipv6", "mac_address", "ip_address");
5310 /* Dump Bridge Domain Ip to Mac entries */
5311 M (BD_IP_MAC_DUMP, mp);
5314 mp->bd_id = htonl (bd_id);
5320 /* Use a control ping for synchronization */
5321 MPING (CONTROL_PING, mp_ping);
5329 api_tap_create_v2 (vat_main_t * vam)
5331 unformat_input_t *i = vam->input;
5332 vl_api_tap_create_v2_t *mp;
5336 u32 num_rx_queues = 0;
5337 u8 *host_if_name = 0;
5338 u8 host_if_name_set = 0;
5341 u8 host_mac_addr[6];
5342 u8 host_mac_addr_set = 0;
5343 u8 *host_bridge = 0;
5344 u8 host_bridge_set = 0;
5345 u8 host_ip4_prefix_set = 0;
5346 u8 host_ip6_prefix_set = 0;
5347 ip4_address_t host_ip4_addr;
5348 ip4_address_t host_ip4_gw;
5349 u8 host_ip4_gw_set = 0;
5350 u32 host_ip4_prefix_len = 0;
5351 ip6_address_t host_ip6_addr;
5352 ip6_address_t host_ip6_gw;
5353 u8 host_ip6_gw_set = 0;
5354 u32 host_ip6_prefix_len = 0;
5355 u32 host_mtu_size = 0;
5356 u8 host_mtu_set = 0;
5359 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5361 clib_memset (mac_address, 0, sizeof (mac_address));
5363 /* Parse args required to build the message */
5364 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5366 if (unformat (i, "id %u", &id))
5370 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5372 else if (unformat (i, "host-if-name %s", &host_if_name))
5373 host_if_name_set = 1;
5374 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5376 else if (unformat (i, "host-ns %s", &host_ns))
5378 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5380 host_mac_addr_set = 1;
5381 else if (unformat (i, "host-bridge %s", &host_bridge))
5382 host_bridge_set = 1;
5383 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5384 &host_ip4_addr, &host_ip4_prefix_len))
5385 host_ip4_prefix_set = 1;
5386 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5387 &host_ip6_addr, &host_ip6_prefix_len))
5388 host_ip6_prefix_set = 1;
5389 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5391 host_ip4_gw_set = 1;
5392 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5394 host_ip6_gw_set = 1;
5395 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5397 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5399 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5401 else if (unformat (i, "no-gso"))
5402 tap_flags &= ~TAP_API_FLAG_GSO;
5403 else if (unformat (i, "gso"))
5404 tap_flags |= TAP_API_FLAG_GSO;
5405 else if (unformat (i, "csum-offload"))
5406 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5407 else if (unformat (i, "persist"))
5408 tap_flags |= TAP_API_FLAG_PERSIST;
5409 else if (unformat (i, "attach"))
5410 tap_flags |= TAP_API_FLAG_ATTACH;
5411 else if (unformat (i, "tun"))
5412 tap_flags |= TAP_API_FLAG_TUN;
5413 else if (unformat (i, "gro-coalesce"))
5414 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5415 else if (unformat (i, "packed"))
5416 tap_flags |= TAP_API_FLAG_PACKED;
5417 else if (unformat (i, "in-order"))
5418 tap_flags |= TAP_API_FLAG_IN_ORDER;
5423 if (vec_len (host_if_name) > 63)
5425 errmsg ("tap name too long. ");
5428 if (vec_len (host_ns) > 63)
5430 errmsg ("host name space too long. ");
5433 if (vec_len (host_bridge) > 63)
5435 errmsg ("host bridge name too long. ");
5438 if (host_ip4_prefix_len > 32)
5440 errmsg ("host ip4 prefix length not valid. ");
5443 if (host_ip6_prefix_len > 128)
5445 errmsg ("host ip6 prefix length not valid. ");
5448 if (!is_pow2 (rx_ring_sz))
5450 errmsg ("rx ring size must be power of 2. ");
5453 if (rx_ring_sz > 32768)
5455 errmsg ("rx ring size must be 32768 or lower. ");
5458 if (!is_pow2 (tx_ring_sz))
5460 errmsg ("tx ring size must be power of 2. ");
5463 if (tx_ring_sz > 32768)
5465 errmsg ("tx ring size must be 32768 or lower. ");
5468 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5470 errmsg ("host MTU size must be in between 64 and 65355. ");
5474 /* Construct the API message */
5475 M (TAP_CREATE_V2, mp);
5477 mp->id = ntohl (id);
5478 mp->use_random_mac = random_mac;
5479 mp->num_rx_queues = (u8) num_rx_queues;
5480 mp->tx_ring_sz = ntohs (tx_ring_sz);
5481 mp->rx_ring_sz = ntohs (rx_ring_sz);
5482 mp->host_mtu_set = host_mtu_set;
5483 mp->host_mtu_size = ntohl (host_mtu_size);
5484 mp->host_mac_addr_set = host_mac_addr_set;
5485 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5486 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5487 mp->host_ip4_gw_set = host_ip4_gw_set;
5488 mp->host_ip6_gw_set = host_ip6_gw_set;
5489 mp->tap_flags = ntohl (tap_flags);
5490 mp->host_namespace_set = host_ns_set;
5491 mp->host_if_name_set = host_if_name_set;
5492 mp->host_bridge_set = host_bridge_set;
5494 if (random_mac == 0)
5495 clib_memcpy (mp->mac_address, mac_address, 6);
5496 if (host_mac_addr_set)
5497 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5498 if (host_if_name_set)
5499 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5501 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5502 if (host_bridge_set)
5503 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5504 if (host_ip4_prefix_set)
5506 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5507 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5509 if (host_ip6_prefix_set)
5511 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5512 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5514 if (host_ip4_gw_set)
5515 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5516 if (host_ip6_gw_set)
5517 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5520 vec_free (host_if_name);
5521 vec_free (host_bridge);
5526 /* Wait for a reply... */
5532 api_tap_delete_v2 (vat_main_t * vam)
5534 unformat_input_t *i = vam->input;
5535 vl_api_tap_delete_v2_t *mp;
5536 u32 sw_if_index = ~0;
5537 u8 sw_if_index_set = 0;
5540 /* Parse args required to build the message */
5541 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5543 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5544 sw_if_index_set = 1;
5545 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5546 sw_if_index_set = 1;
5551 if (sw_if_index_set == 0)
5553 errmsg ("missing vpp interface name. ");
5557 /* Construct the API message */
5558 M (TAP_DELETE_V2, mp);
5560 mp->sw_if_index = ntohl (sw_if_index);
5565 /* Wait for a reply... */
5571 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5573 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5576 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5579 addr->domain = x[0];
5582 addr->function = x[3];
5588 api_virtio_pci_create_v2 (vat_main_t * vam)
5590 unformat_input_t *i = vam->input;
5591 vl_api_virtio_pci_create_v2_t *mp;
5595 u64 features = (u64) ~ (0ULL);
5596 u32 virtio_flags = 0;
5599 clib_memset (mac_address, 0, sizeof (mac_address));
5601 /* Parse args required to build the message */
5602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5604 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5608 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5610 else if (unformat (i, "features 0x%llx", &features))
5612 else if (unformat (i, "gso-enabled"))
5613 virtio_flags |= VIRTIO_API_FLAG_GSO;
5614 else if (unformat (i, "csum-offload-enabled"))
5615 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5616 else if (unformat (i, "gro-coalesce"))
5617 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5618 else if (unformat (i, "packed"))
5619 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5620 else if (unformat (i, "in-order"))
5621 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5622 else if (unformat (i, "buffering"))
5623 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5630 errmsg ("pci address must be non zero. ");
5634 /* Construct the API message */
5635 M (VIRTIO_PCI_CREATE_V2, mp);
5637 mp->use_random_mac = random_mac;
5639 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5640 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5641 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5642 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5644 mp->features = clib_host_to_net_u64 (features);
5645 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5647 if (random_mac == 0)
5648 clib_memcpy (mp->mac_address, mac_address, 6);
5653 /* Wait for a reply... */
5659 api_virtio_pci_delete (vat_main_t * vam)
5661 unformat_input_t *i = vam->input;
5662 vl_api_virtio_pci_delete_t *mp;
5663 u32 sw_if_index = ~0;
5664 u8 sw_if_index_set = 0;
5667 /* Parse args required to build the message */
5668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5670 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5671 sw_if_index_set = 1;
5672 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5673 sw_if_index_set = 1;
5678 if (sw_if_index_set == 0)
5680 errmsg ("missing vpp interface name. ");
5684 /* Construct the API message */
5685 M (VIRTIO_PCI_DELETE, mp);
5687 mp->sw_if_index = htonl (sw_if_index);
5692 /* Wait for a reply... */
5698 api_bond_create (vat_main_t * vam)
5700 unformat_input_t *i = vam->input;
5701 vl_api_bond_create_t *mp;
5711 clib_memset (mac_address, 0, sizeof (mac_address));
5714 /* Parse args required to build the message */
5715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5717 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5719 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5720 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5722 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5725 else if (unformat (i, "numa-only"))
5727 else if (unformat (i, "id %u", &id))
5733 if (mode_is_set == 0)
5735 errmsg ("Missing bond mode. ");
5739 /* Construct the API message */
5740 M (BOND_CREATE, mp);
5742 mp->use_custom_mac = custom_mac;
5744 mp->mode = htonl (mode);
5745 mp->lb = htonl (lb);
5746 mp->id = htonl (id);
5747 mp->numa_only = numa_only;
5750 clib_memcpy (mp->mac_address, mac_address, 6);
5755 /* Wait for a reply... */
5761 api_bond_create2 (vat_main_t * vam)
5763 unformat_input_t *i = vam->input;
5764 vl_api_bond_create2_t *mp;
5775 clib_memset (mac_address, 0, sizeof (mac_address));
5778 /* Parse args required to build the message */
5779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5781 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5783 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5784 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5786 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5789 else if (unformat (i, "numa-only"))
5791 else if (unformat (i, "gso"))
5793 else if (unformat (i, "id %u", &id))
5799 if (mode_is_set == 0)
5801 errmsg ("Missing bond mode. ");
5805 /* Construct the API message */
5806 M (BOND_CREATE2, mp);
5808 mp->use_custom_mac = custom_mac;
5810 mp->mode = htonl (mode);
5811 mp->lb = htonl (lb);
5812 mp->id = htonl (id);
5813 mp->numa_only = numa_only;
5814 mp->enable_gso = gso;
5817 clib_memcpy (mp->mac_address, mac_address, 6);
5822 /* Wait for a reply... */
5828 api_bond_delete (vat_main_t * vam)
5830 unformat_input_t *i = vam->input;
5831 vl_api_bond_delete_t *mp;
5832 u32 sw_if_index = ~0;
5833 u8 sw_if_index_set = 0;
5836 /* Parse args required to build the message */
5837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5839 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5840 sw_if_index_set = 1;
5841 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5842 sw_if_index_set = 1;
5847 if (sw_if_index_set == 0)
5849 errmsg ("missing vpp interface name. ");
5853 /* Construct the API message */
5854 M (BOND_DELETE, mp);
5856 mp->sw_if_index = ntohl (sw_if_index);
5861 /* Wait for a reply... */
5867 api_bond_add_member (vat_main_t * vam)
5869 unformat_input_t *i = vam->input;
5870 vl_api_bond_add_member_t *mp;
5871 u32 bond_sw_if_index;
5875 u32 bond_sw_if_index_is_set = 0;
5877 u8 sw_if_index_is_set = 0;
5879 /* Parse args required to build the message */
5880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5882 if (unformat (i, "sw_if_index %d", &sw_if_index))
5883 sw_if_index_is_set = 1;
5884 else if (unformat (i, "bond %u", &bond_sw_if_index))
5885 bond_sw_if_index_is_set = 1;
5886 else if (unformat (i, "passive %d", &is_passive))
5888 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5894 if (bond_sw_if_index_is_set == 0)
5896 errmsg ("Missing bond sw_if_index. ");
5899 if (sw_if_index_is_set == 0)
5901 errmsg ("Missing member sw_if_index. ");
5905 /* Construct the API message */
5906 M (BOND_ADD_MEMBER, mp);
5908 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5909 mp->sw_if_index = ntohl (sw_if_index);
5910 mp->is_long_timeout = is_long_timeout;
5911 mp->is_passive = is_passive;
5916 /* Wait for a reply... */
5922 api_bond_detach_member (vat_main_t * vam)
5924 unformat_input_t *i = vam->input;
5925 vl_api_bond_detach_member_t *mp;
5926 u32 sw_if_index = ~0;
5927 u8 sw_if_index_set = 0;
5930 /* Parse args required to build the message */
5931 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5933 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5934 sw_if_index_set = 1;
5935 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5936 sw_if_index_set = 1;
5941 if (sw_if_index_set == 0)
5943 errmsg ("missing vpp interface name. ");
5947 /* Construct the API message */
5948 M (BOND_DETACH_MEMBER, mp);
5950 mp->sw_if_index = ntohl (sw_if_index);
5955 /* Wait for a reply... */
5961 api_ip_table_add_del (vat_main_t * vam)
5963 unformat_input_t *i = vam->input;
5964 vl_api_ip_table_add_del_t *mp;
5970 /* Parse args required to build the message */
5971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5973 if (unformat (i, "ipv6"))
5975 else if (unformat (i, "del"))
5977 else if (unformat (i, "add"))
5979 else if (unformat (i, "table %d", &table_id))
5983 clib_warning ("parse error '%U'", format_unformat_error, i);
5990 errmsg ("missing table-ID");
5994 /* Construct the API message */
5995 M (IP_TABLE_ADD_DEL, mp);
5997 mp->table.table_id = ntohl (table_id);
5998 mp->table.is_ip6 = is_ipv6;
5999 mp->is_add = is_add;
6004 /* Wait for a reply... */
6011 unformat_fib_path (unformat_input_t * input, va_list * args)
6013 vat_main_t *vam = va_arg (*args, vat_main_t *);
6014 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
6015 u32 weight, preference;
6016 mpls_label_t out_label;
6018 clib_memset (path, 0, sizeof (*path));
6020 path->sw_if_index = ~0;
6024 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6026 if (unformat (input, "%U %U",
6027 unformat_vl_api_ip4_address,
6028 &path->nh.address.ip4,
6029 api_unformat_sw_if_index, vam, &path->sw_if_index))
6031 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6033 else if (unformat (input, "%U %U",
6034 unformat_vl_api_ip6_address,
6035 &path->nh.address.ip6,
6036 api_unformat_sw_if_index, vam, &path->sw_if_index))
6038 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6040 else if (unformat (input, "weight %u", &weight))
6042 path->weight = weight;
6044 else if (unformat (input, "preference %u", &preference))
6046 path->preference = preference;
6048 else if (unformat (input, "%U next-hop-table %d",
6049 unformat_vl_api_ip4_address,
6050 &path->nh.address.ip4, &path->table_id))
6052 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6054 else if (unformat (input, "%U next-hop-table %d",
6055 unformat_vl_api_ip6_address,
6056 &path->nh.address.ip6, &path->table_id))
6058 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6060 else if (unformat (input, "%U",
6061 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6064 * the recursive next-hops are by default in the default table
6067 path->sw_if_index = ~0;
6068 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6070 else if (unformat (input, "%U",
6071 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6074 * the recursive next-hops are by default in the default table
6077 path->sw_if_index = ~0;
6078 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6080 else if (unformat (input, "resolve-via-host"))
6082 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6084 else if (unformat (input, "resolve-via-attached"))
6086 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6088 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6090 path->type = FIB_API_PATH_TYPE_LOCAL;
6091 path->sw_if_index = ~0;
6092 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6094 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6096 path->type = FIB_API_PATH_TYPE_LOCAL;
6097 path->sw_if_index = ~0;
6098 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6100 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6102 else if (unformat (input, "via-label %d", &path->nh.via_label))
6104 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6105 path->sw_if_index = ~0;
6107 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6109 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6110 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6112 else if (unformat (input, "local"))
6114 path->type = FIB_API_PATH_TYPE_LOCAL;
6116 else if (unformat (input, "out-labels"))
6118 while (unformat (input, "%d", &out_label))
6120 path->label_stack[path->n_labels].label = out_label;
6121 path->label_stack[path->n_labels].is_uniform = 0;
6122 path->label_stack[path->n_labels].ttl = 64;
6126 else if (unformat (input, "via"))
6128 /* new path, back up and return */
6129 unformat_put_input (input);
6130 unformat_put_input (input);
6131 unformat_put_input (input);
6132 unformat_put_input (input);
6141 path->proto = ntohl (path->proto);
6142 path->type = ntohl (path->type);
6143 path->flags = ntohl (path->flags);
6144 path->table_id = ntohl (path->table_id);
6145 path->sw_if_index = ntohl (path->sw_if_index);
6151 api_ip_route_add_del (vat_main_t * vam)
6153 unformat_input_t *i = vam->input;
6154 vl_api_ip_route_add_del_t *mp;
6157 u8 is_multipath = 0;
6160 vl_api_prefix_t pfx = { };
6161 vl_api_fib_path_t paths[8];
6165 u32 random_add_del = 0;
6166 u32 *random_vector = 0;
6167 u32 random_seed = 0xdeaddabe;
6169 /* Parse args required to build the message */
6170 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6172 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6174 else if (unformat (i, "del"))
6176 else if (unformat (i, "add"))
6178 else if (unformat (i, "vrf %d", &vrf_id))
6180 else if (unformat (i, "count %d", &count))
6182 else if (unformat (i, "random"))
6184 else if (unformat (i, "multipath"))
6186 else if (unformat (i, "seed %d", &random_seed))
6190 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6193 if (8 == path_count)
6195 errmsg ("max 8 paths");
6201 clib_warning ("parse error '%U'", format_unformat_error, i);
6208 errmsg ("specify a path; via ...");
6211 if (prefix_set == 0)
6213 errmsg ("missing prefix");
6217 /* Generate a pile of unique, random routes */
6220 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6221 u32 this_random_address;
6224 random_hash = hash_create (count, sizeof (uword));
6226 hash_set (random_hash, i->as_u32, 1);
6227 for (j = 0; j <= count; j++)
6231 this_random_address = random_u32 (&random_seed);
6232 this_random_address =
6233 clib_host_to_net_u32 (this_random_address);
6235 while (hash_get (random_hash, this_random_address));
6236 vec_add1 (random_vector, this_random_address);
6237 hash_set (random_hash, this_random_address, 1);
6239 hash_free (random_hash);
6240 set_ip4_address (&pfx.address, random_vector[0]);
6245 /* Turn on async mode */
6246 vam->async_mode = 1;
6247 vam->async_errors = 0;
6248 before = vat_time_now (vam);
6251 for (j = 0; j < count; j++)
6253 /* Construct the API message */
6254 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6256 mp->is_add = is_add;
6257 mp->is_multipath = is_multipath;
6259 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6260 mp->route.table_id = ntohl (vrf_id);
6261 mp->route.n_paths = path_count;
6263 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6266 set_ip4_address (&pfx.address, random_vector[j + 1]);
6268 increment_address (&pfx.address);
6271 /* If we receive SIGTERM, stop now... */
6276 /* When testing multiple add/del ops, use a control-ping to sync */
6279 vl_api_control_ping_t *mp_ping;
6283 /* Shut off async mode */
6284 vam->async_mode = 0;
6286 MPING (CONTROL_PING, mp_ping);
6289 timeout = vat_time_now (vam) + 1.0;
6290 while (vat_time_now (vam) < timeout)
6291 if (vam->result_ready == 1)
6296 if (vam->retval == -99)
6299 if (vam->async_errors > 0)
6301 errmsg ("%d asynchronous errors", vam->async_errors);
6304 vam->async_errors = 0;
6305 after = vat_time_now (vam);
6307 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6311 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6312 count, after - before, count / (after - before));
6318 /* Wait for a reply... */
6323 /* Return the good/bad news */
6324 return (vam->retval);
6328 api_ip_mroute_add_del (vat_main_t * vam)
6330 unformat_input_t *i = vam->input;
6331 u8 path_set = 0, prefix_set = 0, is_add = 1;
6332 vl_api_ip_mroute_add_del_t *mp;
6333 mfib_entry_flags_t eflags = 0;
6334 vl_api_mfib_path_t path;
6335 vl_api_mprefix_t pfx = { };
6339 /* Parse args required to build the message */
6340 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6342 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6345 pfx.grp_address_length = htons (pfx.grp_address_length);
6347 else if (unformat (i, "del"))
6349 else if (unformat (i, "add"))
6351 else if (unformat (i, "vrf %d", &vrf_id))
6353 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6354 path.itf_flags = htonl (path.itf_flags);
6355 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6357 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6361 clib_warning ("parse error '%U'", format_unformat_error, i);
6366 if (prefix_set == 0)
6368 errmsg ("missing addresses\n");
6373 errmsg ("missing path\n");
6377 /* Construct the API message */
6378 M (IP_MROUTE_ADD_DEL, mp);
6380 mp->is_add = is_add;
6381 mp->is_multipath = 1;
6383 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6384 mp->route.table_id = htonl (vrf_id);
6385 mp->route.n_paths = 1;
6386 mp->route.entry_flags = htonl (eflags);
6388 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6392 /* Wait for a reply... */
6398 api_mpls_table_add_del (vat_main_t * vam)
6400 unformat_input_t *i = vam->input;
6401 vl_api_mpls_table_add_del_t *mp;
6406 /* Parse args required to build the message */
6407 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6409 if (unformat (i, "table %d", &table_id))
6411 else if (unformat (i, "del"))
6413 else if (unformat (i, "add"))
6417 clib_warning ("parse error '%U'", format_unformat_error, i);
6424 errmsg ("missing table-ID");
6428 /* Construct the API message */
6429 M (MPLS_TABLE_ADD_DEL, mp);
6431 mp->mt_table.mt_table_id = ntohl (table_id);
6432 mp->mt_is_add = is_add;
6437 /* Wait for a reply... */
6444 api_mpls_route_add_del (vat_main_t * vam)
6446 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6447 mpls_label_t local_label = MPLS_LABEL_INVALID;
6448 unformat_input_t *i = vam->input;
6449 vl_api_mpls_route_add_del_t *mp;
6450 vl_api_fib_path_t paths[8];
6454 /* Parse args required to build the message */
6455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6457 if (unformat (i, "%d", &local_label))
6459 else if (unformat (i, "eos"))
6461 else if (unformat (i, "non-eos"))
6463 else if (unformat (i, "del"))
6465 else if (unformat (i, "add"))
6467 else if (unformat (i, "multipath"))
6469 else if (unformat (i, "count %d", &count))
6473 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6476 if (8 == path_count)
6478 errmsg ("max 8 paths");
6484 clib_warning ("parse error '%U'", format_unformat_error, i);
6491 errmsg ("specify a path; via ...");
6495 if (MPLS_LABEL_INVALID == local_label)
6497 errmsg ("missing label");
6503 /* Turn on async mode */
6504 vam->async_mode = 1;
6505 vam->async_errors = 0;
6506 before = vat_time_now (vam);
6509 for (j = 0; j < count; j++)
6511 /* Construct the API message */
6512 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6514 mp->mr_is_add = is_add;
6515 mp->mr_is_multipath = is_multipath;
6517 mp->mr_route.mr_label = local_label;
6518 mp->mr_route.mr_eos = is_eos;
6519 mp->mr_route.mr_table_id = 0;
6520 mp->mr_route.mr_n_paths = path_count;
6522 clib_memcpy (&mp->mr_route.mr_paths, paths,
6523 sizeof (paths[0]) * path_count);
6529 /* If we receive SIGTERM, stop now... */
6534 /* When testing multiple add/del ops, use a control-ping to sync */
6537 vl_api_control_ping_t *mp_ping;
6541 /* Shut off async mode */
6542 vam->async_mode = 0;
6544 MPING (CONTROL_PING, mp_ping);
6547 timeout = vat_time_now (vam) + 1.0;
6548 while (vat_time_now (vam) < timeout)
6549 if (vam->result_ready == 1)
6554 if (vam->retval == -99)
6557 if (vam->async_errors > 0)
6559 errmsg ("%d asynchronous errors", vam->async_errors);
6562 vam->async_errors = 0;
6563 after = vat_time_now (vam);
6565 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6569 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6570 count, after - before, count / (after - before));
6576 /* Wait for a reply... */
6581 /* Return the good/bad news */
6582 return (vam->retval);
6587 api_mpls_ip_bind_unbind (vat_main_t * vam)
6589 unformat_input_t *i = vam->input;
6590 vl_api_mpls_ip_bind_unbind_t *mp;
6591 u32 ip_table_id = 0;
6593 vl_api_prefix_t pfx;
6595 mpls_label_t local_label = MPLS_LABEL_INVALID;
6598 /* Parse args required to build the message */
6599 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6601 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6603 else if (unformat (i, "%d", &local_label))
6605 else if (unformat (i, "table-id %d", &ip_table_id))
6607 else if (unformat (i, "unbind"))
6609 else if (unformat (i, "bind"))
6613 clib_warning ("parse error '%U'", format_unformat_error, i);
6620 errmsg ("IP prefix not set");
6624 if (MPLS_LABEL_INVALID == local_label)
6626 errmsg ("missing label");
6630 /* Construct the API message */
6631 M (MPLS_IP_BIND_UNBIND, mp);
6633 mp->mb_is_bind = is_bind;
6634 mp->mb_ip_table_id = ntohl (ip_table_id);
6635 mp->mb_mpls_table_id = 0;
6636 mp->mb_label = ntohl (local_label);
6637 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6642 /* Wait for a reply... */
6649 api_sr_mpls_policy_add (vat_main_t * vam)
6651 unformat_input_t *i = vam->input;
6652 vl_api_sr_mpls_policy_add_t *mp;
6658 u32 *segments = NULL;
6661 /* Parse args required to build the message */
6662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6664 if (unformat (i, "bsid %d", &bsid))
6666 else if (unformat (i, "weight %d", &weight))
6668 else if (unformat (i, "spray"))
6670 else if (unformat (i, "next %d", &sid))
6673 vec_add1 (segments, htonl (sid));
6677 clib_warning ("parse error '%U'", format_unformat_error, i);
6684 errmsg ("bsid not set");
6688 if (n_segments == 0)
6690 errmsg ("no sid in segment stack");
6694 /* Construct the API message */
6695 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6697 mp->bsid = htonl (bsid);
6698 mp->weight = htonl (weight);
6699 mp->is_spray = type;
6700 mp->n_segments = n_segments;
6701 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6702 vec_free (segments);
6707 /* Wait for a reply... */
6713 api_sr_mpls_policy_del (vat_main_t * vam)
6715 unformat_input_t *i = vam->input;
6716 vl_api_sr_mpls_policy_del_t *mp;
6720 /* Parse args required to build the message */
6721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6723 if (unformat (i, "bsid %d", &bsid))
6727 clib_warning ("parse error '%U'", format_unformat_error, i);
6734 errmsg ("bsid not set");
6738 /* Construct the API message */
6739 M (SR_MPLS_POLICY_DEL, mp);
6741 mp->bsid = htonl (bsid);
6746 /* Wait for a reply... */
6752 api_bier_table_add_del (vat_main_t * vam)
6754 unformat_input_t *i = vam->input;
6755 vl_api_bier_table_add_del_t *mp;
6757 u32 set = 0, sub_domain = 0, hdr_len = 3;
6758 mpls_label_t local_label = MPLS_LABEL_INVALID;
6761 /* Parse args required to build the message */
6762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6764 if (unformat (i, "sub-domain %d", &sub_domain))
6766 else if (unformat (i, "set %d", &set))
6768 else if (unformat (i, "label %d", &local_label))
6770 else if (unformat (i, "hdr-len %d", &hdr_len))
6772 else if (unformat (i, "add"))
6774 else if (unformat (i, "del"))
6778 clib_warning ("parse error '%U'", format_unformat_error, i);
6783 if (MPLS_LABEL_INVALID == local_label)
6785 errmsg ("missing label\n");
6789 /* Construct the API message */
6790 M (BIER_TABLE_ADD_DEL, mp);
6792 mp->bt_is_add = is_add;
6793 mp->bt_label = ntohl (local_label);
6794 mp->bt_tbl_id.bt_set = set;
6795 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6796 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6801 /* Wait for a reply... */
6808 api_bier_route_add_del (vat_main_t * vam)
6810 unformat_input_t *i = vam->input;
6811 vl_api_bier_route_add_del_t *mp;
6813 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6814 ip4_address_t v4_next_hop_address;
6815 ip6_address_t v6_next_hop_address;
6816 u8 next_hop_set = 0;
6817 u8 next_hop_proto_is_ip4 = 1;
6818 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6821 /* Parse args required to build the message */
6822 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6824 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6826 next_hop_proto_is_ip4 = 1;
6829 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6831 next_hop_proto_is_ip4 = 0;
6834 if (unformat (i, "sub-domain %d", &sub_domain))
6836 else if (unformat (i, "set %d", &set))
6838 else if (unformat (i, "hdr-len %d", &hdr_len))
6840 else if (unformat (i, "bp %d", &bp))
6842 else if (unformat (i, "add"))
6844 else if (unformat (i, "del"))
6846 else if (unformat (i, "out-label %d", &next_hop_out_label))
6850 clib_warning ("parse error '%U'", format_unformat_error, i);
6855 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6857 errmsg ("next hop / label set\n");
6862 errmsg ("bit=position not set\n");
6866 /* Construct the API message */
6867 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6869 mp->br_is_add = is_add;
6870 mp->br_route.br_tbl_id.bt_set = set;
6871 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6872 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6873 mp->br_route.br_bp = ntohs (bp);
6874 mp->br_route.br_n_paths = 1;
6875 mp->br_route.br_paths[0].n_labels = 1;
6876 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6877 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6878 FIB_API_PATH_NH_PROTO_IP4 :
6879 FIB_API_PATH_NH_PROTO_IP6);
6881 if (next_hop_proto_is_ip4)
6883 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6884 &v4_next_hop_address, sizeof (v4_next_hop_address));
6888 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6889 &v6_next_hop_address, sizeof (v6_next_hop_address));
6895 /* Wait for a reply... */
6902 api_mpls_tunnel_add_del (vat_main_t * vam)
6904 unformat_input_t *i = vam->input;
6905 vl_api_mpls_tunnel_add_del_t *mp;
6907 vl_api_fib_path_t paths[8];
6908 u32 sw_if_index = ~0;
6914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6916 if (unformat (i, "add"))
6920 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6922 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6924 else if (unformat (i, "l2-only"))
6928 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6931 if (8 == path_count)
6933 errmsg ("max 8 paths");
6939 clib_warning ("parse error '%U'", format_unformat_error, i);
6944 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6946 mp->mt_is_add = is_add;
6947 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6948 mp->mt_tunnel.mt_l2_only = l2_only;
6949 mp->mt_tunnel.mt_is_multicast = 0;
6950 mp->mt_tunnel.mt_n_paths = path_count;
6952 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6953 sizeof (paths[0]) * path_count);
6961 api_sw_interface_set_unnumbered (vat_main_t * vam)
6963 unformat_input_t *i = vam->input;
6964 vl_api_sw_interface_set_unnumbered_t *mp;
6966 u32 unnum_sw_index = ~0;
6968 u8 sw_if_index_set = 0;
6971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6973 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6974 sw_if_index_set = 1;
6975 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6976 sw_if_index_set = 1;
6977 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6979 else if (unformat (i, "del"))
6983 clib_warning ("parse error '%U'", format_unformat_error, i);
6988 if (sw_if_index_set == 0)
6990 errmsg ("missing interface name or sw_if_index");
6994 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6996 mp->sw_if_index = ntohl (sw_if_index);
6997 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6998 mp->is_add = is_add;
7007 api_create_vlan_subif (vat_main_t * vam)
7009 unformat_input_t *i = vam->input;
7010 vl_api_create_vlan_subif_t *mp;
7012 u8 sw_if_index_set = 0;
7017 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7019 if (unformat (i, "sw_if_index %d", &sw_if_index))
7020 sw_if_index_set = 1;
7022 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7023 sw_if_index_set = 1;
7024 else if (unformat (i, "vlan %d", &vlan_id))
7028 clib_warning ("parse error '%U'", format_unformat_error, i);
7033 if (sw_if_index_set == 0)
7035 errmsg ("missing interface name or sw_if_index");
7039 if (vlan_id_set == 0)
7041 errmsg ("missing vlan_id");
7044 M (CREATE_VLAN_SUBIF, mp);
7046 mp->sw_if_index = ntohl (sw_if_index);
7047 mp->vlan_id = ntohl (vlan_id);
7054 #define foreach_create_subif_bit \
7061 _(outer_vlan_id_any) \
7062 _(inner_vlan_id_any)
7064 #define foreach_create_subif_flag \
7069 _(4, "exact_match") \
7070 _(5, "default_sub") \
7071 _(6, "outer_vlan_id_any") \
7072 _(7, "inner_vlan_id_any")
7075 api_create_subif (vat_main_t * vam)
7077 unformat_input_t *i = vam->input;
7078 vl_api_create_subif_t *mp;
7080 u8 sw_if_index_set = 0;
7083 u32 __attribute__ ((unused)) no_tags = 0;
7084 u32 __attribute__ ((unused)) one_tag = 0;
7085 u32 __attribute__ ((unused)) two_tags = 0;
7086 u32 __attribute__ ((unused)) dot1ad = 0;
7087 u32 __attribute__ ((unused)) exact_match = 0;
7088 u32 __attribute__ ((unused)) default_sub = 0;
7089 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7090 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7092 u16 outer_vlan_id = 0;
7093 u16 inner_vlan_id = 0;
7096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7098 if (unformat (i, "sw_if_index %d", &sw_if_index))
7099 sw_if_index_set = 1;
7101 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7102 sw_if_index_set = 1;
7103 else if (unformat (i, "sub_id %d", &sub_id))
7105 else if (unformat (i, "outer_vlan_id %d", &tmp))
7106 outer_vlan_id = tmp;
7107 else if (unformat (i, "inner_vlan_id %d", &tmp))
7108 inner_vlan_id = tmp;
7110 #define _(a) else if (unformat (i, #a)) a = 1 ;
7111 foreach_create_subif_bit
7115 clib_warning ("parse error '%U'", format_unformat_error, i);
7120 if (sw_if_index_set == 0)
7122 errmsg ("missing interface name or sw_if_index");
7126 if (sub_id_set == 0)
7128 errmsg ("missing sub_id");
7131 M (CREATE_SUBIF, mp);
7133 mp->sw_if_index = ntohl (sw_if_index);
7134 mp->sub_id = ntohl (sub_id);
7136 #define _(a,b) mp->sub_if_flags |= (1 << a);
7137 foreach_create_subif_flag;
7140 mp->outer_vlan_id = ntohs (outer_vlan_id);
7141 mp->inner_vlan_id = ntohs (inner_vlan_id);
7149 api_ip_table_replace_begin (vat_main_t * vam)
7151 unformat_input_t *i = vam->input;
7152 vl_api_ip_table_replace_begin_t *mp;
7157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7159 if (unformat (i, "table %d", &table_id))
7161 else if (unformat (i, "ipv6"))
7165 clib_warning ("parse error '%U'", format_unformat_error, i);
7170 M (IP_TABLE_REPLACE_BEGIN, mp);
7172 mp->table.table_id = ntohl (table_id);
7173 mp->table.is_ip6 = is_ipv6;
7181 api_ip_table_flush (vat_main_t * vam)
7183 unformat_input_t *i = vam->input;
7184 vl_api_ip_table_flush_t *mp;
7189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7191 if (unformat (i, "table %d", &table_id))
7193 else if (unformat (i, "ipv6"))
7197 clib_warning ("parse error '%U'", format_unformat_error, i);
7202 M (IP_TABLE_FLUSH, mp);
7204 mp->table.table_id = ntohl (table_id);
7205 mp->table.is_ip6 = is_ipv6;
7213 api_ip_table_replace_end (vat_main_t * vam)
7215 unformat_input_t *i = vam->input;
7216 vl_api_ip_table_replace_end_t *mp;
7221 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7223 if (unformat (i, "table %d", &table_id))
7225 else if (unformat (i, "ipv6"))
7229 clib_warning ("parse error '%U'", format_unformat_error, i);
7234 M (IP_TABLE_REPLACE_END, mp);
7236 mp->table.table_id = ntohl (table_id);
7237 mp->table.is_ip6 = is_ipv6;
7245 api_set_ip_flow_hash (vat_main_t * vam)
7247 unformat_input_t *i = vam->input;
7248 vl_api_set_ip_flow_hash_t *mp;
7260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7262 if (unformat (i, "vrf %d", &vrf_id))
7264 else if (unformat (i, "ipv6"))
7266 else if (unformat (i, "src"))
7268 else if (unformat (i, "dst"))
7270 else if (unformat (i, "sport"))
7272 else if (unformat (i, "dport"))
7274 else if (unformat (i, "proto"))
7276 else if (unformat (i, "reverse"))
7281 clib_warning ("parse error '%U'", format_unformat_error, i);
7286 if (vrf_id_set == 0)
7288 errmsg ("missing vrf id");
7292 M (SET_IP_FLOW_HASH, mp);
7298 mp->reverse = reverse;
7299 mp->vrf_id = ntohl (vrf_id);
7300 mp->is_ipv6 = is_ipv6;
7308 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7310 unformat_input_t *i = vam->input;
7311 vl_api_sw_interface_ip6_enable_disable_t *mp;
7313 u8 sw_if_index_set = 0;
7317 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7319 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7320 sw_if_index_set = 1;
7321 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7322 sw_if_index_set = 1;
7323 else if (unformat (i, "enable"))
7325 else if (unformat (i, "disable"))
7329 clib_warning ("parse error '%U'", format_unformat_error, i);
7334 if (sw_if_index_set == 0)
7336 errmsg ("missing interface name or sw_if_index");
7340 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7342 mp->sw_if_index = ntohl (sw_if_index);
7343 mp->enable = enable;
7352 api_l2_patch_add_del (vat_main_t * vam)
7354 unformat_input_t *i = vam->input;
7355 vl_api_l2_patch_add_del_t *mp;
7357 u8 rx_sw_if_index_set = 0;
7359 u8 tx_sw_if_index_set = 0;
7363 /* Parse args required to build the message */
7364 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7366 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7367 rx_sw_if_index_set = 1;
7368 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7369 tx_sw_if_index_set = 1;
7370 else if (unformat (i, "rx"))
7372 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7374 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7376 rx_sw_if_index_set = 1;
7381 else if (unformat (i, "tx"))
7383 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7385 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7387 tx_sw_if_index_set = 1;
7392 else if (unformat (i, "del"))
7398 if (rx_sw_if_index_set == 0)
7400 errmsg ("missing rx interface name or rx_sw_if_index");
7404 if (tx_sw_if_index_set == 0)
7406 errmsg ("missing tx interface name or tx_sw_if_index");
7410 M (L2_PATCH_ADD_DEL, mp);
7412 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7413 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7414 mp->is_add = is_add;
7422 u8 localsid_addr[16];
7431 api_sr_localsid_add_del (vat_main_t * vam)
7433 unformat_input_t *i = vam->input;
7434 vl_api_sr_localsid_add_del_t *mp;
7437 ip6_address_t localsid;
7441 u32 fib_table = ~(u32) 0;
7442 ip46_address_t nh_addr;
7443 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7445 bool nexthop_set = 0;
7449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7451 if (unformat (i, "del"))
7453 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7454 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7456 else if (unformat (i, "behavior %u", &behavior));
7457 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7458 else if (unformat (i, "fib-table %u", &fib_table));
7459 else if (unformat (i, "end.psp %u", &behavior));
7464 M (SR_LOCALSID_ADD_DEL, mp);
7466 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7470 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7472 mp->behavior = behavior;
7473 mp->sw_if_index = ntohl (sw_if_index);
7474 mp->fib_table = ntohl (fib_table);
7475 mp->end_psp = end_psp;
7476 mp->is_del = is_del;
7484 api_ioam_enable (vat_main_t * vam)
7486 unformat_input_t *input = vam->input;
7487 vl_api_ioam_enable_t *mp;
7489 int has_trace_option = 0;
7490 int has_pot_option = 0;
7491 int has_seqno_option = 0;
7492 int has_analyse_option = 0;
7495 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7497 if (unformat (input, "trace"))
7498 has_trace_option = 1;
7499 else if (unformat (input, "pot"))
7501 else if (unformat (input, "seqno"))
7502 has_seqno_option = 1;
7503 else if (unformat (input, "analyse"))
7504 has_analyse_option = 1;
7508 M (IOAM_ENABLE, mp);
7509 mp->id = htons (id);
7510 mp->seqno = has_seqno_option;
7511 mp->analyse = has_analyse_option;
7512 mp->pot_enable = has_pot_option;
7513 mp->trace_enable = has_trace_option;
7522 api_ioam_disable (vat_main_t * vam)
7524 vl_api_ioam_disable_t *mp;
7527 M (IOAM_DISABLE, mp);
7533 #define foreach_tcp_proto_field \
7537 #define foreach_udp_proto_field \
7541 #define foreach_ip4_proto_field \
7553 u16 src_port, dst_port;
7556 #if VPP_API_TEST_BUILTIN == 0
7558 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7560 u8 **maskp = va_arg (*args, u8 **);
7562 u8 found_something = 0;
7565 #define _(a) u8 a=0;
7566 foreach_tcp_proto_field;
7569 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7572 #define _(a) else if (unformat (input, #a)) a=1;
7573 foreach_tcp_proto_field
7579 #define _(a) found_something += a;
7580 foreach_tcp_proto_field;
7583 if (found_something == 0)
7586 vec_validate (mask, sizeof (*tcp) - 1);
7588 tcp = (tcp_header_t *) mask;
7590 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7591 foreach_tcp_proto_field;
7599 unformat_udp_mask (unformat_input_t * input, va_list * args)
7601 u8 **maskp = va_arg (*args, u8 **);
7603 u8 found_something = 0;
7606 #define _(a) u8 a=0;
7607 foreach_udp_proto_field;
7610 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7613 #define _(a) else if (unformat (input, #a)) a=1;
7614 foreach_udp_proto_field
7620 #define _(a) found_something += a;
7621 foreach_udp_proto_field;
7624 if (found_something == 0)
7627 vec_validate (mask, sizeof (*udp) - 1);
7629 udp = (udp_header_t *) mask;
7631 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7632 foreach_udp_proto_field;
7640 unformat_l4_mask (unformat_input_t * input, va_list * args)
7642 u8 **maskp = va_arg (*args, u8 **);
7643 u16 src_port = 0, dst_port = 0;
7644 tcpudp_header_t *tcpudp;
7646 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7648 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7650 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7652 else if (unformat (input, "src_port"))
7654 else if (unformat (input, "dst_port"))
7660 if (!src_port && !dst_port)
7664 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7666 tcpudp = (tcpudp_header_t *) mask;
7667 tcpudp->src_port = src_port;
7668 tcpudp->dst_port = dst_port;
7676 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7678 u8 **maskp = va_arg (*args, u8 **);
7680 u8 found_something = 0;
7683 #define _(a) u8 a=0;
7684 foreach_ip4_proto_field;
7690 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7692 if (unformat (input, "version"))
7694 else if (unformat (input, "hdr_length"))
7696 else if (unformat (input, "src"))
7698 else if (unformat (input, "dst"))
7700 else if (unformat (input, "proto"))
7703 #define _(a) else if (unformat (input, #a)) a=1;
7704 foreach_ip4_proto_field
7710 #define _(a) found_something += a;
7711 foreach_ip4_proto_field;
7714 if (found_something == 0)
7717 vec_validate (mask, sizeof (*ip) - 1);
7719 ip = (ip4_header_t *) mask;
7721 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7722 foreach_ip4_proto_field;
7725 ip->ip_version_and_header_length = 0;
7728 ip->ip_version_and_header_length |= 0xF0;
7731 ip->ip_version_and_header_length |= 0x0F;
7737 #define foreach_ip6_proto_field \
7745 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7747 u8 **maskp = va_arg (*args, u8 **);
7749 u8 found_something = 0;
7751 u32 ip_version_traffic_class_and_flow_label;
7753 #define _(a) u8 a=0;
7754 foreach_ip6_proto_field;
7757 u8 traffic_class = 0;
7760 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7762 if (unformat (input, "version"))
7764 else if (unformat (input, "traffic-class"))
7766 else if (unformat (input, "flow-label"))
7768 else if (unformat (input, "src"))
7770 else if (unformat (input, "dst"))
7772 else if (unformat (input, "proto"))
7775 #define _(a) else if (unformat (input, #a)) a=1;
7776 foreach_ip6_proto_field
7782 #define _(a) found_something += a;
7783 foreach_ip6_proto_field;
7786 if (found_something == 0)
7789 vec_validate (mask, sizeof (*ip) - 1);
7791 ip = (ip6_header_t *) mask;
7793 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7794 foreach_ip6_proto_field;
7797 ip_version_traffic_class_and_flow_label = 0;
7800 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7803 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7806 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7808 ip->ip_version_traffic_class_and_flow_label =
7809 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7816 unformat_l3_mask (unformat_input_t * input, va_list * args)
7818 u8 **maskp = va_arg (*args, u8 **);
7820 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7822 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7824 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7833 unformat_l2_mask (unformat_input_t * input, va_list * args)
7835 u8 **maskp = va_arg (*args, u8 **);
7850 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7852 if (unformat (input, "src"))
7854 else if (unformat (input, "dst"))
7856 else if (unformat (input, "proto"))
7858 else if (unformat (input, "tag1"))
7860 else if (unformat (input, "tag2"))
7862 else if (unformat (input, "ignore-tag1"))
7864 else if (unformat (input, "ignore-tag2"))
7866 else if (unformat (input, "cos1"))
7868 else if (unformat (input, "cos2"))
7870 else if (unformat (input, "dot1q"))
7872 else if (unformat (input, "dot1ad"))
7877 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7878 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7881 if (tag1 || ignore_tag1 || cos1 || dot1q)
7883 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7886 vec_validate (mask, len - 1);
7889 clib_memset (mask, 0xff, 6);
7892 clib_memset (mask + 6, 0xff, 6);
7896 /* inner vlan tag */
7905 mask[21] = mask[20] = 0xff;
7926 mask[16] = mask[17] = 0xff;
7936 mask[12] = mask[13] = 0xff;
7943 unformat_classify_mask (unformat_input_t * input, va_list * args)
7945 u8 **maskp = va_arg (*args, u8 **);
7946 u32 *skipp = va_arg (*args, u32 *);
7947 u32 *matchp = va_arg (*args, u32 *);
7955 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7957 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7959 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7961 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7963 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7977 if (mask || l2 || l3 || l4)
7981 /* "With a free Ethernet header in every package" */
7983 vec_validate (l2, 13);
7987 vec_append (mask, l3);
7992 vec_append (mask, l4);
7997 /* Scan forward looking for the first significant mask octet */
7998 for (i = 0; i < vec_len (mask); i++)
8002 /* compute (skip, match) params */
8003 *skipp = i / sizeof (u32x4);
8004 vec_delete (mask, *skipp * sizeof (u32x4), 0);
8006 /* Pad mask to an even multiple of the vector size */
8007 while (vec_len (mask) % sizeof (u32x4))
8010 match = vec_len (mask) / sizeof (u32x4);
8012 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8014 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8015 if (*tmp || *(tmp + 1))
8020 clib_warning ("BUG: match 0");
8022 _vec_len (mask) = match * sizeof (u32x4);
8032 #endif /* VPP_API_TEST_BUILTIN */
8034 #define foreach_l2_next \
8036 _(ethernet, ETHERNET_INPUT) \
8041 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8043 u32 *miss_next_indexp = va_arg (*args, u32 *);
8048 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8052 if (unformat (input, "%d", &tmp))
8061 *miss_next_indexp = next_index;
8065 #define foreach_ip_next \
8071 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8073 u32 *miss_next_indexp = va_arg (*args, u32 *);
8078 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8082 if (unformat (input, "%d", &tmp))
8091 *miss_next_indexp = next_index;
8095 #define foreach_acl_next \
8099 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8101 u32 *miss_next_indexp = va_arg (*args, u32 *);
8106 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8110 if (unformat (input, "permit"))
8115 else if (unformat (input, "%d", &tmp))
8124 *miss_next_indexp = next_index;
8129 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8131 u32 *r = va_arg (*args, u32 *);
8133 if (unformat (input, "conform-color"))
8134 *r = POLICE_CONFORM;
8135 else if (unformat (input, "exceed-color"))
8144 api_classify_add_del_table (vat_main_t * vam)
8146 unformat_input_t *i = vam->input;
8147 vl_api_classify_add_del_table_t *mp;
8154 u32 table_index = ~0;
8155 u32 next_table_index = ~0;
8156 u32 miss_next_index = ~0;
8157 u32 memory_size = 32 << 20;
8159 u32 current_data_flag = 0;
8160 int current_data_offset = 0;
8163 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8165 if (unformat (i, "del"))
8167 else if (unformat (i, "del-chain"))
8172 else if (unformat (i, "buckets %d", &nbuckets))
8174 else if (unformat (i, "memory_size %d", &memory_size))
8176 else if (unformat (i, "skip %d", &skip))
8178 else if (unformat (i, "match %d", &match))
8180 else if (unformat (i, "table %d", &table_index))
8182 else if (unformat (i, "mask %U", unformat_classify_mask,
8183 &mask, &skip, &match))
8185 else if (unformat (i, "next-table %d", &next_table_index))
8187 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8190 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8193 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8196 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8198 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8204 if (is_add && mask == 0)
8206 errmsg ("Mask required");
8210 if (is_add && skip == ~0)
8212 errmsg ("skip count required");
8216 if (is_add && match == ~0)
8218 errmsg ("match count required");
8222 if (!is_add && table_index == ~0)
8224 errmsg ("table index required for delete");
8228 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8230 mp->is_add = is_add;
8231 mp->del_chain = del_chain;
8232 mp->table_index = ntohl (table_index);
8233 mp->nbuckets = ntohl (nbuckets);
8234 mp->memory_size = ntohl (memory_size);
8235 mp->skip_n_vectors = ntohl (skip);
8236 mp->match_n_vectors = ntohl (match);
8237 mp->next_table_index = ntohl (next_table_index);
8238 mp->miss_next_index = ntohl (miss_next_index);
8239 mp->current_data_flag = ntohl (current_data_flag);
8240 mp->current_data_offset = ntohl (current_data_offset);
8241 mp->mask_len = ntohl (vec_len (mask));
8242 clib_memcpy (mp->mask, mask, vec_len (mask));
8251 #if VPP_API_TEST_BUILTIN == 0
8253 unformat_l4_match (unformat_input_t * input, va_list * args)
8255 u8 **matchp = va_arg (*args, u8 **);
8257 u8 *proto_header = 0;
8263 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8265 if (unformat (input, "src_port %d", &src_port))
8267 else if (unformat (input, "dst_port %d", &dst_port))
8273 h.src_port = clib_host_to_net_u16 (src_port);
8274 h.dst_port = clib_host_to_net_u16 (dst_port);
8275 vec_validate (proto_header, sizeof (h) - 1);
8276 memcpy (proto_header, &h, sizeof (h));
8278 *matchp = proto_header;
8284 unformat_ip4_match (unformat_input_t * input, va_list * args)
8286 u8 **matchp = va_arg (*args, u8 **);
8293 int src = 0, dst = 0;
8294 ip4_address_t src_val, dst_val;
8301 int fragment_id = 0;
8302 u32 fragment_id_val;
8308 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8310 if (unformat (input, "version %d", &version_val))
8312 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8314 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8316 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8318 else if (unformat (input, "proto %d", &proto_val))
8320 else if (unformat (input, "tos %d", &tos_val))
8322 else if (unformat (input, "length %d", &length_val))
8324 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8326 else if (unformat (input, "ttl %d", &ttl_val))
8328 else if (unformat (input, "checksum %d", &checksum_val))
8334 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8335 + ttl + checksum == 0)
8339 * Aligned because we use the real comparison functions
8341 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8343 ip = (ip4_header_t *) match;
8345 /* These are realistically matched in practice */
8347 ip->src_address.as_u32 = src_val.as_u32;
8350 ip->dst_address.as_u32 = dst_val.as_u32;
8353 ip->protocol = proto_val;
8356 /* These are not, but they're included for completeness */
8358 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8361 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8367 ip->length = clib_host_to_net_u16 (length_val);
8373 ip->checksum = clib_host_to_net_u16 (checksum_val);
8380 unformat_ip6_match (unformat_input_t * input, va_list * args)
8382 u8 **matchp = va_arg (*args, u8 **);
8387 u8 traffic_class = 0;
8388 u32 traffic_class_val = 0;
8391 int src = 0, dst = 0;
8392 ip6_address_t src_val, dst_val;
8395 int payload_length = 0;
8396 u32 payload_length_val;
8399 u32 ip_version_traffic_class_and_flow_label;
8401 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8403 if (unformat (input, "version %d", &version_val))
8405 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8407 else if (unformat (input, "flow_label %d", &flow_label_val))
8409 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8411 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8413 else if (unformat (input, "proto %d", &proto_val))
8415 else if (unformat (input, "payload_length %d", &payload_length_val))
8417 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8423 if (version + traffic_class + flow_label + src + dst + proto +
8424 payload_length + hop_limit == 0)
8428 * Aligned because we use the real comparison functions
8430 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8432 ip = (ip6_header_t *) match;
8435 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8438 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8441 ip->protocol = proto_val;
8443 ip_version_traffic_class_and_flow_label = 0;
8446 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8449 ip_version_traffic_class_and_flow_label |=
8450 (traffic_class_val & 0xFF) << 20;
8453 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8455 ip->ip_version_traffic_class_and_flow_label =
8456 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8459 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8462 ip->hop_limit = hop_limit_val;
8469 unformat_l3_match (unformat_input_t * input, va_list * args)
8471 u8 **matchp = va_arg (*args, u8 **);
8473 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8475 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8477 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8486 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8488 u8 *tagp = va_arg (*args, u8 *);
8491 if (unformat (input, "%d", &tag))
8493 tagp[0] = (tag >> 8) & 0x0F;
8494 tagp[1] = tag & 0xFF;
8502 unformat_l2_match (unformat_input_t * input, va_list * args)
8504 u8 **matchp = va_arg (*args, u8 **);
8524 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8526 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8529 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8531 else if (unformat (input, "proto %U",
8532 unformat_ethernet_type_host_byte_order, &proto_val))
8534 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8536 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8538 else if (unformat (input, "ignore-tag1"))
8540 else if (unformat (input, "ignore-tag2"))
8542 else if (unformat (input, "cos1 %d", &cos1_val))
8544 else if (unformat (input, "cos2 %d", &cos2_val))
8549 if ((src + dst + proto + tag1 + tag2 +
8550 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8553 if (tag1 || ignore_tag1 || cos1)
8555 if (tag2 || ignore_tag2 || cos2)
8558 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8561 clib_memcpy (match, dst_val, 6);
8564 clib_memcpy (match + 6, src_val, 6);
8568 /* inner vlan tag */
8569 match[19] = tag2_val[1];
8570 match[18] = tag2_val[0];
8572 match[18] |= (cos2_val & 0x7) << 5;
8575 match[21] = proto_val & 0xff;
8576 match[20] = proto_val >> 8;
8580 match[15] = tag1_val[1];
8581 match[14] = tag1_val[0];
8584 match[14] |= (cos1_val & 0x7) << 5;
8590 match[15] = tag1_val[1];
8591 match[14] = tag1_val[0];
8594 match[17] = proto_val & 0xff;
8595 match[16] = proto_val >> 8;
8598 match[14] |= (cos1_val & 0x7) << 5;
8604 match[18] |= (cos2_val & 0x7) << 5;
8606 match[14] |= (cos1_val & 0x7) << 5;
8609 match[13] = proto_val & 0xff;
8610 match[12] = proto_val >> 8;
8618 unformat_qos_source (unformat_input_t * input, va_list * args)
8620 int *qs = va_arg (*args, int *);
8622 if (unformat (input, "ip"))
8623 *qs = QOS_SOURCE_IP;
8624 else if (unformat (input, "mpls"))
8625 *qs = QOS_SOURCE_MPLS;
8626 else if (unformat (input, "ext"))
8627 *qs = QOS_SOURCE_EXT;
8628 else if (unformat (input, "vlan"))
8629 *qs = QOS_SOURCE_VLAN;
8638 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8640 u8 **matchp = va_arg (*args, u8 **);
8641 u32 skip_n_vectors = va_arg (*args, u32);
8642 u32 match_n_vectors = va_arg (*args, u32);
8649 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8651 if (unformat (input, "hex %U", unformat_hex_string, &match))
8653 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8655 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8657 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8671 if (match || l2 || l3 || l4)
8675 /* "Win a free Ethernet header in every packet" */
8677 vec_validate_aligned (l2, 13, sizeof (u32x4));
8681 vec_append_aligned (match, l3, sizeof (u32x4));
8686 vec_append_aligned (match, l4, sizeof (u32x4));
8691 /* Make sure the vector is big enough even if key is all 0's */
8692 vec_validate_aligned
8693 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8696 /* Set size, include skipped vectors */
8697 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8708 api_classify_add_del_session (vat_main_t * vam)
8710 unformat_input_t *i = vam->input;
8711 vl_api_classify_add_del_session_t *mp;
8713 u32 table_index = ~0;
8714 u32 hit_next_index = ~0;
8715 u32 opaque_index = ~0;
8718 u32 skip_n_vectors = 0;
8719 u32 match_n_vectors = 0;
8725 * Warning: you have to supply skip_n and match_n
8726 * because the API client cant simply look at the classify
8730 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8732 if (unformat (i, "del"))
8734 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8737 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8740 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8743 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8745 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8747 else if (unformat (i, "opaque-index %d", &opaque_index))
8749 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8751 else if (unformat (i, "match_n %d", &match_n_vectors))
8753 else if (unformat (i, "match %U", api_unformat_classify_match,
8754 &match, skip_n_vectors, match_n_vectors))
8756 else if (unformat (i, "advance %d", &advance))
8758 else if (unformat (i, "table-index %d", &table_index))
8760 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8762 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8764 else if (unformat (i, "action %d", &action))
8766 else if (unformat (i, "metadata %d", &metadata))
8772 if (table_index == ~0)
8774 errmsg ("Table index required");
8778 if (is_add && match == 0)
8780 errmsg ("Match value required");
8784 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8786 mp->is_add = is_add;
8787 mp->table_index = ntohl (table_index);
8788 mp->hit_next_index = ntohl (hit_next_index);
8789 mp->opaque_index = ntohl (opaque_index);
8790 mp->advance = ntohl (advance);
8791 mp->action = action;
8792 mp->metadata = ntohl (metadata);
8793 mp->match_len = ntohl (vec_len (match));
8794 clib_memcpy (mp->match, match, vec_len (match));
8803 api_classify_set_interface_ip_table (vat_main_t * vam)
8805 unformat_input_t *i = vam->input;
8806 vl_api_classify_set_interface_ip_table_t *mp;
8808 int sw_if_index_set;
8809 u32 table_index = ~0;
8813 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8815 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8816 sw_if_index_set = 1;
8817 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8818 sw_if_index_set = 1;
8819 else if (unformat (i, "table %d", &table_index))
8823 clib_warning ("parse error '%U'", format_unformat_error, i);
8828 if (sw_if_index_set == 0)
8830 errmsg ("missing interface name or sw_if_index");
8835 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8837 mp->sw_if_index = ntohl (sw_if_index);
8838 mp->table_index = ntohl (table_index);
8839 mp->is_ipv6 = is_ipv6;
8847 api_classify_set_interface_l2_tables (vat_main_t * vam)
8849 unformat_input_t *i = vam->input;
8850 vl_api_classify_set_interface_l2_tables_t *mp;
8852 int sw_if_index_set;
8853 u32 ip4_table_index = ~0;
8854 u32 ip6_table_index = ~0;
8855 u32 other_table_index = ~0;
8859 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8861 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8862 sw_if_index_set = 1;
8863 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8864 sw_if_index_set = 1;
8865 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8867 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8869 else if (unformat (i, "other-table %d", &other_table_index))
8871 else if (unformat (i, "is-input %d", &is_input))
8875 clib_warning ("parse error '%U'", format_unformat_error, i);
8880 if (sw_if_index_set == 0)
8882 errmsg ("missing interface name or sw_if_index");
8887 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8889 mp->sw_if_index = ntohl (sw_if_index);
8890 mp->ip4_table_index = ntohl (ip4_table_index);
8891 mp->ip6_table_index = ntohl (ip6_table_index);
8892 mp->other_table_index = ntohl (other_table_index);
8893 mp->is_input = (u8) is_input;
8901 api_set_ipfix_exporter (vat_main_t * vam)
8903 unformat_input_t *i = vam->input;
8904 vl_api_set_ipfix_exporter_t *mp;
8905 ip4_address_t collector_address;
8906 u8 collector_address_set = 0;
8907 u32 collector_port = ~0;
8908 ip4_address_t src_address;
8909 u8 src_address_set = 0;
8912 u32 template_interval = ~0;
8913 u8 udp_checksum = 0;
8916 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8918 if (unformat (i, "collector_address %U", unformat_ip4_address,
8919 &collector_address))
8920 collector_address_set = 1;
8921 else if (unformat (i, "collector_port %d", &collector_port))
8923 else if (unformat (i, "src_address %U", unformat_ip4_address,
8925 src_address_set = 1;
8926 else if (unformat (i, "vrf_id %d", &vrf_id))
8928 else if (unformat (i, "path_mtu %d", &path_mtu))
8930 else if (unformat (i, "template_interval %d", &template_interval))
8932 else if (unformat (i, "udp_checksum"))
8938 if (collector_address_set == 0)
8940 errmsg ("collector_address required");
8944 if (src_address_set == 0)
8946 errmsg ("src_address required");
8950 M (SET_IPFIX_EXPORTER, mp);
8952 memcpy (mp->collector_address.un.ip4, collector_address.data,
8953 sizeof (collector_address.data));
8954 mp->collector_port = htons ((u16) collector_port);
8955 memcpy (mp->src_address.un.ip4, src_address.data,
8956 sizeof (src_address.data));
8957 mp->vrf_id = htonl (vrf_id);
8958 mp->path_mtu = htonl (path_mtu);
8959 mp->template_interval = htonl (template_interval);
8960 mp->udp_checksum = udp_checksum;
8968 api_set_ipfix_classify_stream (vat_main_t * vam)
8970 unformat_input_t *i = vam->input;
8971 vl_api_set_ipfix_classify_stream_t *mp;
8973 u32 src_port = UDP_DST_PORT_ipfix;
8976 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8978 if (unformat (i, "domain %d", &domain_id))
8980 else if (unformat (i, "src_port %d", &src_port))
8984 errmsg ("unknown input `%U'", format_unformat_error, i);
8989 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8991 mp->domain_id = htonl (domain_id);
8992 mp->src_port = htons ((u16) src_port);
9000 api_ipfix_classify_table_add_del (vat_main_t * vam)
9002 unformat_input_t *i = vam->input;
9003 vl_api_ipfix_classify_table_add_del_t *mp;
9005 u32 classify_table_index = ~0;
9007 u8 transport_protocol = 255;
9010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9012 if (unformat (i, "add"))
9014 else if (unformat (i, "del"))
9016 else if (unformat (i, "table %d", &classify_table_index))
9018 else if (unformat (i, "ip4"))
9020 else if (unformat (i, "ip6"))
9022 else if (unformat (i, "tcp"))
9023 transport_protocol = 6;
9024 else if (unformat (i, "udp"))
9025 transport_protocol = 17;
9028 errmsg ("unknown input `%U'", format_unformat_error, i);
9035 errmsg ("expecting: add|del");
9038 if (classify_table_index == ~0)
9040 errmsg ("classifier table not specified");
9043 if (ip_version == 0)
9045 errmsg ("IP version not specified");
9049 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9051 mp->is_add = is_add;
9052 mp->table_id = htonl (classify_table_index);
9053 mp->ip_version = ip_version;
9054 mp->transport_protocol = transport_protocol;
9062 api_get_node_index (vat_main_t * vam)
9064 unformat_input_t *i = vam->input;
9065 vl_api_get_node_index_t *mp;
9069 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9071 if (unformat (i, "node %s", &name))
9078 errmsg ("node name required");
9081 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9083 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9087 M (GET_NODE_INDEX, mp);
9088 clib_memcpy (mp->node_name, name, vec_len (name));
9097 api_get_next_index (vat_main_t * vam)
9099 unformat_input_t *i = vam->input;
9100 vl_api_get_next_index_t *mp;
9101 u8 *node_name = 0, *next_node_name = 0;
9104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9106 if (unformat (i, "node-name %s", &node_name))
9108 else if (unformat (i, "next-node-name %s", &next_node_name))
9114 errmsg ("node name required");
9117 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9119 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9123 if (next_node_name == 0)
9125 errmsg ("next node name required");
9128 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9130 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9134 M (GET_NEXT_INDEX, mp);
9135 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9136 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9137 vec_free (node_name);
9138 vec_free (next_node_name);
9146 api_add_node_next (vat_main_t * vam)
9148 unformat_input_t *i = vam->input;
9149 vl_api_add_node_next_t *mp;
9154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9156 if (unformat (i, "node %s", &name))
9158 else if (unformat (i, "next %s", &next))
9165 errmsg ("node name required");
9168 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9170 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9175 errmsg ("next node required");
9178 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9180 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9184 M (ADD_NODE_NEXT, mp);
9185 clib_memcpy (mp->node_name, name, vec_len (name));
9186 clib_memcpy (mp->next_name, next, vec_len (next));
9195 static void vl_api_sw_interface_tap_v2_details_t_handler
9196 (vl_api_sw_interface_tap_v2_details_t * mp)
9198 vat_main_t *vam = &vat_main;
9201 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9202 mp->host_ip4_prefix.len);
9204 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9205 mp->host_ip6_prefix.len);
9208 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9209 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9210 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9211 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9212 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9218 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9219 (vl_api_sw_interface_tap_v2_details_t * mp)
9221 vat_main_t *vam = &vat_main;
9222 vat_json_node_t *node = NULL;
9224 if (VAT_JSON_ARRAY != vam->json_tree.type)
9226 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9227 vat_json_init_array (&vam->json_tree);
9229 node = vat_json_array_add (&vam->json_tree);
9231 vat_json_init_object (node);
9232 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9233 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9234 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9235 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9236 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9237 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9238 vat_json_object_add_string_copy (node, "host_mac_addr",
9239 format (0, "%U", format_ethernet_address,
9240 &mp->host_mac_addr));
9241 vat_json_object_add_string_copy (node, "host_namespace",
9242 mp->host_namespace);
9243 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9244 vat_json_object_add_string_copy (node, "host_ip4_addr",
9245 format (0, "%U/%d", format_ip4_address,
9246 mp->host_ip4_prefix.address,
9247 mp->host_ip4_prefix.len));
9248 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9249 format (0, "%U/%d", format_ip6_address,
9250 mp->host_ip6_prefix.address,
9251 mp->host_ip6_prefix.len));
9256 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9258 vl_api_sw_interface_tap_v2_dump_t *mp;
9259 vl_api_control_ping_t *mp_ping;
9263 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9264 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9265 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9268 /* Get list of tap interfaces */
9269 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9272 /* Use a control ping for synchronization */
9273 MPING (CONTROL_PING, mp_ping);
9280 static void vl_api_sw_interface_virtio_pci_details_t_handler
9281 (vl_api_sw_interface_virtio_pci_details_t * mp)
9283 vat_main_t *vam = &vat_main;
9298 addr.domain = ntohs (mp->pci_addr.domain);
9299 addr.bus = mp->pci_addr.bus;
9300 addr.slot = mp->pci_addr.slot;
9301 addr.function = mp->pci_addr.function;
9303 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9304 addr.slot, addr.function);
9307 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9308 pci_addr, ntohl (mp->sw_if_index),
9309 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9310 format_ethernet_address, mp->mac_addr,
9311 clib_net_to_host_u64 (mp->features));
9312 vec_free (pci_addr);
9315 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9316 (vl_api_sw_interface_virtio_pci_details_t * mp)
9318 vat_main_t *vam = &vat_main;
9319 vat_json_node_t *node = NULL;
9320 vlib_pci_addr_t pci_addr;
9322 if (VAT_JSON_ARRAY != vam->json_tree.type)
9324 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9325 vat_json_init_array (&vam->json_tree);
9327 node = vat_json_array_add (&vam->json_tree);
9329 pci_addr.domain = ntohs (mp->pci_addr.domain);
9330 pci_addr.bus = mp->pci_addr.bus;
9331 pci_addr.slot = mp->pci_addr.slot;
9332 pci_addr.function = mp->pci_addr.function;
9334 vat_json_init_object (node);
9335 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9336 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9337 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9338 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9339 vat_json_object_add_uint (node, "features",
9340 clib_net_to_host_u64 (mp->features));
9341 vat_json_object_add_string_copy (node, "mac_addr",
9342 format (0, "%U", format_ethernet_address,
9347 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9349 vl_api_sw_interface_virtio_pci_dump_t *mp;
9350 vl_api_control_ping_t *mp_ping;
9354 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9355 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9356 "mac_addr", "features");
9358 /* Get list of tap interfaces */
9359 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9362 /* Use a control ping for synchronization */
9363 MPING (CONTROL_PING, mp_ping);
9371 api_vxlan_offload_rx (vat_main_t * vam)
9373 unformat_input_t *line_input = vam->input;
9374 vl_api_vxlan_offload_rx_t *mp;
9375 u32 hw_if_index = ~0, rx_if_index = ~0;
9379 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9381 if (unformat (line_input, "del"))
9383 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9386 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9388 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9391 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9395 errmsg ("parse error '%U'", format_unformat_error, line_input);
9400 if (hw_if_index == ~0)
9402 errmsg ("no hw interface");
9406 if (rx_if_index == ~0)
9408 errmsg ("no rx tunnel");
9412 M (VXLAN_OFFLOAD_RX, mp);
9414 mp->hw_if_index = ntohl (hw_if_index);
9415 mp->sw_if_index = ntohl (rx_if_index);
9416 mp->enable = is_add;
9423 static uword unformat_vxlan_decap_next
9424 (unformat_input_t * input, va_list * args)
9426 u32 *result = va_arg (*args, u32 *);
9429 if (unformat (input, "l2"))
9430 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9431 else if (unformat (input, "%d", &tmp))
9439 api_vxlan_add_del_tunnel (vat_main_t * vam)
9441 unformat_input_t *line_input = vam->input;
9442 vl_api_vxlan_add_del_tunnel_t *mp;
9443 ip46_address_t src, dst;
9445 u8 ipv4_set = 0, ipv6_set = 0;
9450 u32 mcast_sw_if_index = ~0;
9451 u32 encap_vrf_id = 0;
9452 u32 decap_next_index = ~0;
9456 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9457 clib_memset (&src, 0, sizeof src);
9458 clib_memset (&dst, 0, sizeof dst);
9460 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9462 if (unformat (line_input, "del"))
9464 else if (unformat (line_input, "instance %d", &instance))
9467 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9473 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9479 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9485 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9490 else if (unformat (line_input, "group %U %U",
9491 unformat_ip4_address, &dst.ip4,
9492 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9494 grp_set = dst_set = 1;
9497 else if (unformat (line_input, "group %U",
9498 unformat_ip4_address, &dst.ip4))
9500 grp_set = dst_set = 1;
9503 else if (unformat (line_input, "group %U %U",
9504 unformat_ip6_address, &dst.ip6,
9505 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9507 grp_set = dst_set = 1;
9510 else if (unformat (line_input, "group %U",
9511 unformat_ip6_address, &dst.ip6))
9513 grp_set = dst_set = 1;
9517 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9519 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9521 else if (unformat (line_input, "decap-next %U",
9522 unformat_vxlan_decap_next, &decap_next_index))
9524 else if (unformat (line_input, "vni %d", &vni))
9528 errmsg ("parse error '%U'", format_unformat_error, line_input);
9535 errmsg ("tunnel src address not specified");
9540 errmsg ("tunnel dst address not specified");
9544 if (grp_set && !ip46_address_is_multicast (&dst))
9546 errmsg ("tunnel group address not multicast");
9549 if (grp_set && mcast_sw_if_index == ~0)
9551 errmsg ("tunnel nonexistent multicast device");
9554 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9556 errmsg ("tunnel dst address must be unicast");
9561 if (ipv4_set && ipv6_set)
9563 errmsg ("both IPv4 and IPv6 addresses specified");
9567 if ((vni == 0) || (vni >> 24))
9569 errmsg ("vni not specified or out of range");
9573 M (VXLAN_ADD_DEL_TUNNEL, mp);
9577 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9578 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9582 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9583 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9585 mp->src_address.af = ipv6_set;
9586 mp->dst_address.af = ipv6_set;
9588 mp->instance = htonl (instance);
9589 mp->encap_vrf_id = ntohl (encap_vrf_id);
9590 mp->decap_next_index = ntohl (decap_next_index);
9591 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9592 mp->vni = ntohl (vni);
9593 mp->is_add = is_add;
9600 static void vl_api_vxlan_tunnel_details_t_handler
9601 (vl_api_vxlan_tunnel_details_t * mp)
9603 vat_main_t *vam = &vat_main;
9604 ip46_address_t src =
9605 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9606 ip46_address_t dst =
9607 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9609 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9610 ntohl (mp->sw_if_index),
9611 ntohl (mp->instance),
9612 format_ip46_address, &src, IP46_TYPE_ANY,
9613 format_ip46_address, &dst, IP46_TYPE_ANY,
9614 ntohl (mp->encap_vrf_id),
9615 ntohl (mp->decap_next_index), ntohl (mp->vni),
9616 ntohl (mp->mcast_sw_if_index));
9619 static void vl_api_vxlan_tunnel_details_t_handler_json
9620 (vl_api_vxlan_tunnel_details_t * mp)
9622 vat_main_t *vam = &vat_main;
9623 vat_json_node_t *node = NULL;
9625 if (VAT_JSON_ARRAY != vam->json_tree.type)
9627 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9628 vat_json_init_array (&vam->json_tree);
9630 node = vat_json_array_add (&vam->json_tree);
9632 vat_json_init_object (node);
9633 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9635 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9637 if (mp->src_address.af)
9639 struct in6_addr ip6;
9641 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9642 vat_json_object_add_ip6 (node, "src_address", ip6);
9643 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9644 vat_json_object_add_ip6 (node, "dst_address", ip6);
9650 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9651 vat_json_object_add_ip4 (node, "src_address", ip4);
9652 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9653 vat_json_object_add_ip4 (node, "dst_address", ip4);
9655 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9656 vat_json_object_add_uint (node, "decap_next_index",
9657 ntohl (mp->decap_next_index));
9658 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9659 vat_json_object_add_uint (node, "mcast_sw_if_index",
9660 ntohl (mp->mcast_sw_if_index));
9664 api_vxlan_tunnel_dump (vat_main_t * vam)
9666 unformat_input_t *i = vam->input;
9667 vl_api_vxlan_tunnel_dump_t *mp;
9668 vl_api_control_ping_t *mp_ping;
9670 u8 sw_if_index_set = 0;
9673 /* Parse args required to build the message */
9674 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9676 if (unformat (i, "sw_if_index %d", &sw_if_index))
9677 sw_if_index_set = 1;
9682 if (sw_if_index_set == 0)
9687 if (!vam->json_output)
9689 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9690 "sw_if_index", "instance", "src_address", "dst_address",
9691 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9694 /* Get list of vxlan-tunnel interfaces */
9695 M (VXLAN_TUNNEL_DUMP, mp);
9697 mp->sw_if_index = htonl (sw_if_index);
9701 /* Use a control ping for synchronization */
9702 MPING (CONTROL_PING, mp_ping);
9710 api_l2_fib_clear_table (vat_main_t * vam)
9712 // unformat_input_t * i = vam->input;
9713 vl_api_l2_fib_clear_table_t *mp;
9716 M (L2_FIB_CLEAR_TABLE, mp);
9724 api_l2_interface_efp_filter (vat_main_t * vam)
9726 unformat_input_t *i = vam->input;
9727 vl_api_l2_interface_efp_filter_t *mp;
9730 u8 sw_if_index_set = 0;
9733 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9735 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9736 sw_if_index_set = 1;
9737 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9738 sw_if_index_set = 1;
9739 else if (unformat (i, "enable"))
9741 else if (unformat (i, "disable"))
9745 clib_warning ("parse error '%U'", format_unformat_error, i);
9750 if (sw_if_index_set == 0)
9752 errmsg ("missing sw_if_index");
9756 M (L2_INTERFACE_EFP_FILTER, mp);
9758 mp->sw_if_index = ntohl (sw_if_index);
9759 mp->enable_disable = enable;
9766 #define foreach_vtr_op \
9767 _("disable", L2_VTR_DISABLED) \
9768 _("push-1", L2_VTR_PUSH_1) \
9769 _("push-2", L2_VTR_PUSH_2) \
9770 _("pop-1", L2_VTR_POP_1) \
9771 _("pop-2", L2_VTR_POP_2) \
9772 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9773 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9774 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9775 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9778 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9780 unformat_input_t *i = vam->input;
9781 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9783 u8 sw_if_index_set = 0;
9791 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9793 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9794 sw_if_index_set = 1;
9795 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9796 sw_if_index_set = 1;
9797 else if (unformat (i, "vtr_op %d", &vtr_op))
9799 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9802 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9804 else if (unformat (i, "tag1 %d", &tag1))
9806 else if (unformat (i, "tag2 %d", &tag2))
9810 clib_warning ("parse error '%U'", format_unformat_error, i);
9815 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9817 errmsg ("missing vtr operation or sw_if_index");
9821 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9822 mp->sw_if_index = ntohl (sw_if_index);
9823 mp->vtr_op = ntohl (vtr_op);
9824 mp->push_dot1q = ntohl (push_dot1q);
9825 mp->tag1 = ntohl (tag1);
9826 mp->tag2 = ntohl (tag2);
9834 api_create_vhost_user_if (vat_main_t * vam)
9836 unformat_input_t *i = vam->input;
9837 vl_api_create_vhost_user_if_t *mp;
9840 u8 file_name_set = 0;
9841 u32 custom_dev_instance = ~0;
9843 u8 use_custom_mac = 0;
9844 u8 disable_mrg_rxbuf = 0;
9845 u8 disable_indirect_desc = 0;
9848 u8 enable_packed = 0;
9851 /* Shut up coverity */
9852 clib_memset (hwaddr, 0, sizeof (hwaddr));
9854 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9856 if (unformat (i, "socket %s", &file_name))
9860 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9862 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
9864 else if (unformat (i, "server"))
9866 else if (unformat (i, "disable_mrg_rxbuf"))
9867 disable_mrg_rxbuf = 1;
9868 else if (unformat (i, "disable_indirect_desc"))
9869 disable_indirect_desc = 1;
9870 else if (unformat (i, "gso"))
9872 else if (unformat (i, "packed"))
9874 else if (unformat (i, "tag %s", &tag))
9880 if (file_name_set == 0)
9882 errmsg ("missing socket file name");
9886 if (vec_len (file_name) > 255)
9888 errmsg ("socket file name too long");
9891 vec_add1 (file_name, 0);
9893 M (CREATE_VHOST_USER_IF, mp);
9895 mp->is_server = is_server;
9896 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
9897 mp->disable_indirect_desc = disable_indirect_desc;
9898 mp->enable_gso = enable_gso;
9899 mp->enable_packed = enable_packed;
9900 mp->custom_dev_instance = ntohl (custom_dev_instance);
9901 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9902 vec_free (file_name);
9903 if (custom_dev_instance != ~0)
9906 mp->use_custom_mac = use_custom_mac;
9907 clib_memcpy (mp->mac_address, hwaddr, 6);
9909 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
9918 api_modify_vhost_user_if (vat_main_t * vam)
9920 unformat_input_t *i = vam->input;
9921 vl_api_modify_vhost_user_if_t *mp;
9924 u8 file_name_set = 0;
9925 u32 custom_dev_instance = ~0;
9926 u8 sw_if_index_set = 0;
9927 u32 sw_if_index = (u32) ~ 0;
9929 u8 enable_packed = 0;
9932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9934 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9935 sw_if_index_set = 1;
9936 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9937 sw_if_index_set = 1;
9938 else if (unformat (i, "socket %s", &file_name))
9942 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
9944 else if (unformat (i, "server"))
9946 else if (unformat (i, "gso"))
9948 else if (unformat (i, "packed"))
9954 if (sw_if_index_set == 0)
9956 errmsg ("missing sw_if_index or interface name");
9960 if (file_name_set == 0)
9962 errmsg ("missing socket file name");
9966 if (vec_len (file_name) > 255)
9968 errmsg ("socket file name too long");
9971 vec_add1 (file_name, 0);
9973 M (MODIFY_VHOST_USER_IF, mp);
9975 mp->sw_if_index = ntohl (sw_if_index);
9976 mp->is_server = is_server;
9977 mp->enable_gso = enable_gso;
9978 mp->enable_packed = enable_packed;
9979 mp->custom_dev_instance = ntohl (custom_dev_instance);
9980 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
9981 vec_free (file_name);
9982 if (custom_dev_instance != ~0)
9991 api_create_vhost_user_if_v2 (vat_main_t * vam)
9993 unformat_input_t *i = vam->input;
9994 vl_api_create_vhost_user_if_v2_t *mp;
9997 u8 file_name_set = 0;
9998 u32 custom_dev_instance = ~0;
10000 u8 use_custom_mac = 0;
10001 u8 disable_mrg_rxbuf = 0;
10002 u8 disable_indirect_desc = 0;
10005 u8 enable_packed = 0;
10006 u8 enable_event_idx = 0;
10009 /* Shut up coverity */
10010 clib_memset (hwaddr, 0, sizeof (hwaddr));
10012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10014 if (unformat (i, "socket %s", &file_name))
10018 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10020 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
10021 use_custom_mac = 1;
10022 else if (unformat (i, "server"))
10024 else if (unformat (i, "disable_mrg_rxbuf"))
10025 disable_mrg_rxbuf = 1;
10026 else if (unformat (i, "disable_indirect_desc"))
10027 disable_indirect_desc = 1;
10028 else if (unformat (i, "gso"))
10030 else if (unformat (i, "packed"))
10032 else if (unformat (i, "event-idx"))
10033 enable_event_idx = 1;
10034 else if (unformat (i, "tag %s", &tag))
10040 if (file_name_set == 0)
10042 errmsg ("missing socket file name");
10046 if (vec_len (file_name) > 255)
10048 errmsg ("socket file name too long");
10051 vec_add1 (file_name, 0);
10053 M (CREATE_VHOST_USER_IF_V2, mp);
10055 mp->is_server = is_server;
10056 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
10057 mp->disable_indirect_desc = disable_indirect_desc;
10058 mp->enable_gso = enable_gso;
10059 mp->enable_packed = enable_packed;
10060 mp->enable_event_idx = enable_event_idx;
10061 mp->custom_dev_instance = ntohl (custom_dev_instance);
10062 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10063 vec_free (file_name);
10064 if (custom_dev_instance != ~0)
10067 mp->use_custom_mac = use_custom_mac;
10068 clib_memcpy (mp->mac_address, hwaddr, 6);
10070 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10079 api_modify_vhost_user_if_v2 (vat_main_t * vam)
10081 unformat_input_t *i = vam->input;
10082 vl_api_modify_vhost_user_if_v2_t *mp;
10085 u8 file_name_set = 0;
10086 u32 custom_dev_instance = ~0;
10087 u8 sw_if_index_set = 0;
10088 u32 sw_if_index = (u32) ~ 0;
10090 u8 enable_packed = 0;
10091 u8 enable_event_idx = 0;
10094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10096 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10097 sw_if_index_set = 1;
10098 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10099 sw_if_index_set = 1;
10100 else if (unformat (i, "socket %s", &file_name))
10104 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10106 else if (unformat (i, "server"))
10108 else if (unformat (i, "gso"))
10110 else if (unformat (i, "packed"))
10112 else if (unformat (i, "event-idx"))
10113 enable_event_idx = 1;
10118 if (sw_if_index_set == 0)
10120 errmsg ("missing sw_if_index or interface name");
10124 if (file_name_set == 0)
10126 errmsg ("missing socket file name");
10130 if (vec_len (file_name) > 255)
10132 errmsg ("socket file name too long");
10135 vec_add1 (file_name, 0);
10137 M (MODIFY_VHOST_USER_IF_V2, mp);
10139 mp->sw_if_index = ntohl (sw_if_index);
10140 mp->is_server = is_server;
10141 mp->enable_gso = enable_gso;
10142 mp->enable_packed = enable_packed;
10143 mp->enable_event_idx = enable_event_idx;
10144 mp->custom_dev_instance = ntohl (custom_dev_instance);
10145 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10146 vec_free (file_name);
10147 if (custom_dev_instance != ~0)
10156 api_delete_vhost_user_if (vat_main_t * vam)
10158 unformat_input_t *i = vam->input;
10159 vl_api_delete_vhost_user_if_t *mp;
10160 u32 sw_if_index = ~0;
10161 u8 sw_if_index_set = 0;
10164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10166 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10167 sw_if_index_set = 1;
10168 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10169 sw_if_index_set = 1;
10174 if (sw_if_index_set == 0)
10176 errmsg ("missing sw_if_index or interface name");
10181 M (DELETE_VHOST_USER_IF, mp);
10183 mp->sw_if_index = ntohl (sw_if_index);
10190 static void vl_api_sw_interface_vhost_user_details_t_handler
10191 (vl_api_sw_interface_vhost_user_details_t * mp)
10193 vat_main_t *vam = &vat_main;
10197 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10198 clib_net_to_host_u32
10199 (mp->features_last_32) <<
10202 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
10203 (char *) mp->interface_name, ntohl (mp->sw_if_index),
10204 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
10205 ntohl (mp->num_regions), (char *) mp->sock_filename);
10206 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10209 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10210 (vl_api_sw_interface_vhost_user_details_t * mp)
10212 vat_main_t *vam = &vat_main;
10213 vat_json_node_t *node = NULL;
10215 if (VAT_JSON_ARRAY != vam->json_tree.type)
10217 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10218 vat_json_init_array (&vam->json_tree);
10220 node = vat_json_array_add (&vam->json_tree);
10222 vat_json_init_object (node);
10223 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10224 vat_json_object_add_string_copy (node, "interface_name",
10225 mp->interface_name);
10226 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10227 ntohl (mp->virtio_net_hdr_sz));
10228 vat_json_object_add_uint (node, "features_first_32",
10229 clib_net_to_host_u32 (mp->features_first_32));
10230 vat_json_object_add_uint (node, "features_last_32",
10231 clib_net_to_host_u32 (mp->features_last_32));
10232 vat_json_object_add_uint (node, "is_server", mp->is_server);
10233 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10234 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10235 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10239 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10241 unformat_input_t *i = vam->input;
10242 vl_api_sw_interface_vhost_user_dump_t *mp;
10243 vl_api_control_ping_t *mp_ping;
10245 u32 sw_if_index = ~0;
10247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10249 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10251 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10257 print (vam->ofp, "Interface name idx hdr_sz features "
10258 "server regions filename");
10260 /* Get list of vhost-user interfaces */
10261 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10262 mp->sw_if_index = ntohl (sw_if_index);
10265 /* Use a control ping for synchronization */
10266 MPING (CONTROL_PING, mp_ping);
10274 api_show_version (vat_main_t * vam)
10276 vl_api_show_version_t *mp;
10279 M (SHOW_VERSION, mp);
10288 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10290 unformat_input_t *line_input = vam->input;
10291 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10292 ip46_address_t local, remote;
10297 u32 mcast_sw_if_index = ~0;
10298 u32 encap_vrf_id = 0;
10299 u32 decap_vrf_id = 0;
10305 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10307 if (unformat (line_input, "del"))
10309 else if (unformat (line_input, "local %U",
10310 unformat_ip46_address, &local))
10314 else if (unformat (line_input, "remote %U",
10315 unformat_ip46_address, &remote))
10319 else if (unformat (line_input, "group %U %U",
10320 unformat_ip46_address, &remote,
10321 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10323 grp_set = remote_set = 1;
10325 else if (unformat (line_input, "group %U",
10326 unformat_ip46_address, &remote))
10328 grp_set = remote_set = 1;
10331 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10333 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10335 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10337 else if (unformat (line_input, "vni %d", &vni))
10339 else if (unformat (line_input, "next-ip4"))
10341 else if (unformat (line_input, "next-ip6"))
10343 else if (unformat (line_input, "next-ethernet"))
10345 else if (unformat (line_input, "next-nsh"))
10349 errmsg ("parse error '%U'", format_unformat_error, line_input);
10354 if (local_set == 0)
10356 errmsg ("tunnel local address not specified");
10359 if (remote_set == 0)
10361 errmsg ("tunnel remote address not specified");
10364 if (grp_set && mcast_sw_if_index == ~0)
10366 errmsg ("tunnel nonexistent multicast device");
10369 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10371 errmsg ("both IPv4 and IPv6 addresses specified");
10377 errmsg ("vni not specified");
10381 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10383 ip_address_encode (&local,
10384 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10385 IP46_TYPE_IP6, &mp->local);
10386 ip_address_encode (&remote,
10387 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10388 IP46_TYPE_IP6, &mp->remote);
10390 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10391 mp->encap_vrf_id = ntohl (encap_vrf_id);
10392 mp->decap_vrf_id = ntohl (decap_vrf_id);
10393 mp->protocol = protocol;
10394 mp->vni = ntohl (vni);
10395 mp->is_add = is_add;
10402 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10403 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10405 vat_main_t *vam = &vat_main;
10406 ip46_address_t local, remote;
10408 ip_address_decode (&mp->local, &local);
10409 ip_address_decode (&mp->remote, &remote);
10411 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10412 ntohl (mp->sw_if_index),
10413 format_ip46_address, &local, IP46_TYPE_ANY,
10414 format_ip46_address, &remote, IP46_TYPE_ANY,
10415 ntohl (mp->vni), mp->protocol,
10416 ntohl (mp->mcast_sw_if_index),
10417 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10421 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10422 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10424 vat_main_t *vam = &vat_main;
10425 vat_json_node_t *node = NULL;
10426 struct in_addr ip4;
10427 struct in6_addr ip6;
10428 ip46_address_t local, remote;
10430 ip_address_decode (&mp->local, &local);
10431 ip_address_decode (&mp->remote, &remote);
10433 if (VAT_JSON_ARRAY != vam->json_tree.type)
10435 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10436 vat_json_init_array (&vam->json_tree);
10438 node = vat_json_array_add (&vam->json_tree);
10440 vat_json_init_object (node);
10441 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10442 if (ip46_address_is_ip4 (&local))
10444 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10445 vat_json_object_add_ip4 (node, "local", ip4);
10446 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10447 vat_json_object_add_ip4 (node, "remote", ip4);
10451 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10452 vat_json_object_add_ip6 (node, "local", ip6);
10453 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10454 vat_json_object_add_ip6 (node, "remote", ip6);
10456 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10457 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10458 vat_json_object_add_uint (node, "mcast_sw_if_index",
10459 ntohl (mp->mcast_sw_if_index));
10460 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10461 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10462 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10466 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10468 unformat_input_t *i = vam->input;
10469 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10470 vl_api_control_ping_t *mp_ping;
10472 u8 sw_if_index_set = 0;
10475 /* Parse args required to build the message */
10476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10478 if (unformat (i, "sw_if_index %d", &sw_if_index))
10479 sw_if_index_set = 1;
10484 if (sw_if_index_set == 0)
10489 if (!vam->json_output)
10491 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10492 "sw_if_index", "local", "remote", "vni",
10493 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10496 /* Get list of vxlan-tunnel interfaces */
10497 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10499 mp->sw_if_index = htonl (sw_if_index);
10503 /* Use a control ping for synchronization */
10504 MPING (CONTROL_PING, mp_ping);
10511 static void vl_api_l2_fib_table_details_t_handler
10512 (vl_api_l2_fib_table_details_t * mp)
10514 vat_main_t *vam = &vat_main;
10516 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10518 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10519 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10523 static void vl_api_l2_fib_table_details_t_handler_json
10524 (vl_api_l2_fib_table_details_t * mp)
10526 vat_main_t *vam = &vat_main;
10527 vat_json_node_t *node = NULL;
10529 if (VAT_JSON_ARRAY != vam->json_tree.type)
10531 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10532 vat_json_init_array (&vam->json_tree);
10534 node = vat_json_array_add (&vam->json_tree);
10536 vat_json_init_object (node);
10537 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10538 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10539 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10540 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10541 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10542 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10546 api_l2_fib_table_dump (vat_main_t * vam)
10548 unformat_input_t *i = vam->input;
10549 vl_api_l2_fib_table_dump_t *mp;
10550 vl_api_control_ping_t *mp_ping;
10555 /* Parse args required to build the message */
10556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10558 if (unformat (i, "bd_id %d", &bd_id))
10564 if (bd_id_set == 0)
10566 errmsg ("missing bridge domain");
10570 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10572 /* Get list of l2 fib entries */
10573 M (L2_FIB_TABLE_DUMP, mp);
10575 mp->bd_id = ntohl (bd_id);
10578 /* Use a control ping for synchronization */
10579 MPING (CONTROL_PING, mp_ping);
10588 api_interface_name_renumber (vat_main_t * vam)
10590 unformat_input_t *line_input = vam->input;
10591 vl_api_interface_name_renumber_t *mp;
10592 u32 sw_if_index = ~0;
10593 u32 new_show_dev_instance = ~0;
10596 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10598 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10601 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10603 else if (unformat (line_input, "new_show_dev_instance %d",
10604 &new_show_dev_instance))
10610 if (sw_if_index == ~0)
10612 errmsg ("missing interface name or sw_if_index");
10616 if (new_show_dev_instance == ~0)
10618 errmsg ("missing new_show_dev_instance");
10622 M (INTERFACE_NAME_RENUMBER, mp);
10624 mp->sw_if_index = ntohl (sw_if_index);
10625 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10633 api_want_l2_macs_events (vat_main_t * vam)
10635 unformat_input_t *line_input = vam->input;
10636 vl_api_want_l2_macs_events_t *mp;
10637 u8 enable_disable = 1;
10638 u32 scan_delay = 0;
10639 u32 max_macs_in_event = 0;
10640 u32 learn_limit = 0;
10643 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10645 if (unformat (line_input, "learn-limit %d", &learn_limit))
10647 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10649 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10651 else if (unformat (line_input, "disable"))
10652 enable_disable = 0;
10657 M (WANT_L2_MACS_EVENTS, mp);
10658 mp->enable_disable = enable_disable;
10659 mp->pid = htonl (getpid ());
10660 mp->learn_limit = htonl (learn_limit);
10661 mp->scan_delay = (u8) scan_delay;
10662 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10669 api_input_acl_set_interface (vat_main_t * vam)
10671 unformat_input_t *i = vam->input;
10672 vl_api_input_acl_set_interface_t *mp;
10674 int sw_if_index_set;
10675 u32 ip4_table_index = ~0;
10676 u32 ip6_table_index = ~0;
10677 u32 l2_table_index = ~0;
10681 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10683 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10684 sw_if_index_set = 1;
10685 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10686 sw_if_index_set = 1;
10687 else if (unformat (i, "del"))
10689 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10691 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10693 else if (unformat (i, "l2-table %d", &l2_table_index))
10697 clib_warning ("parse error '%U'", format_unformat_error, i);
10702 if (sw_if_index_set == 0)
10704 errmsg ("missing interface name or sw_if_index");
10708 M (INPUT_ACL_SET_INTERFACE, mp);
10710 mp->sw_if_index = ntohl (sw_if_index);
10711 mp->ip4_table_index = ntohl (ip4_table_index);
10712 mp->ip6_table_index = ntohl (ip6_table_index);
10713 mp->l2_table_index = ntohl (l2_table_index);
10714 mp->is_add = is_add;
10722 api_output_acl_set_interface (vat_main_t * vam)
10724 unformat_input_t *i = vam->input;
10725 vl_api_output_acl_set_interface_t *mp;
10727 int sw_if_index_set;
10728 u32 ip4_table_index = ~0;
10729 u32 ip6_table_index = ~0;
10730 u32 l2_table_index = ~0;
10734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10736 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10737 sw_if_index_set = 1;
10738 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10739 sw_if_index_set = 1;
10740 else if (unformat (i, "del"))
10742 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10744 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10746 else if (unformat (i, "l2-table %d", &l2_table_index))
10750 clib_warning ("parse error '%U'", format_unformat_error, i);
10755 if (sw_if_index_set == 0)
10757 errmsg ("missing interface name or sw_if_index");
10761 M (OUTPUT_ACL_SET_INTERFACE, mp);
10763 mp->sw_if_index = ntohl (sw_if_index);
10764 mp->ip4_table_index = ntohl (ip4_table_index);
10765 mp->ip6_table_index = ntohl (ip6_table_index);
10766 mp->l2_table_index = ntohl (l2_table_index);
10767 mp->is_add = is_add;
10775 api_ip_address_dump (vat_main_t * vam)
10777 unformat_input_t *i = vam->input;
10778 vl_api_ip_address_dump_t *mp;
10779 vl_api_control_ping_t *mp_ping;
10780 u32 sw_if_index = ~0;
10781 u8 sw_if_index_set = 0;
10786 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10788 if (unformat (i, "sw_if_index %d", &sw_if_index))
10789 sw_if_index_set = 1;
10791 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10792 sw_if_index_set = 1;
10793 else if (unformat (i, "ipv4"))
10795 else if (unformat (i, "ipv6"))
10801 if (ipv4_set && ipv6_set)
10803 errmsg ("ipv4 and ipv6 flags cannot be both set");
10807 if ((!ipv4_set) && (!ipv6_set))
10809 errmsg ("no ipv4 nor ipv6 flag set");
10813 if (sw_if_index_set == 0)
10815 errmsg ("missing interface name or sw_if_index");
10819 vam->current_sw_if_index = sw_if_index;
10820 vam->is_ipv6 = ipv6_set;
10822 M (IP_ADDRESS_DUMP, mp);
10823 mp->sw_if_index = ntohl (sw_if_index);
10824 mp->is_ipv6 = ipv6_set;
10827 /* Use a control ping for synchronization */
10828 MPING (CONTROL_PING, mp_ping);
10836 api_ip_dump (vat_main_t * vam)
10838 vl_api_ip_dump_t *mp;
10839 vl_api_control_ping_t *mp_ping;
10840 unformat_input_t *in = vam->input;
10847 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10849 if (unformat (in, "ipv4"))
10851 else if (unformat (in, "ipv6"))
10857 if (ipv4_set && ipv6_set)
10859 errmsg ("ipv4 and ipv6 flags cannot be both set");
10863 if ((!ipv4_set) && (!ipv6_set))
10865 errmsg ("no ipv4 nor ipv6 flag set");
10869 is_ipv6 = ipv6_set;
10870 vam->is_ipv6 = is_ipv6;
10872 /* free old data */
10873 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10875 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10877 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10880 mp->is_ipv6 = ipv6_set;
10883 /* Use a control ping for synchronization */
10884 MPING (CONTROL_PING, mp_ping);
10892 api_ipsec_spd_add_del (vat_main_t * vam)
10894 unformat_input_t *i = vam->input;
10895 vl_api_ipsec_spd_add_del_t *mp;
10900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10902 if (unformat (i, "spd_id %d", &spd_id))
10904 else if (unformat (i, "del"))
10908 clib_warning ("parse error '%U'", format_unformat_error, i);
10914 errmsg ("spd_id must be set");
10918 M (IPSEC_SPD_ADD_DEL, mp);
10920 mp->spd_id = ntohl (spd_id);
10921 mp->is_add = is_add;
10929 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10931 unformat_input_t *i = vam->input;
10932 vl_api_ipsec_interface_add_del_spd_t *mp;
10934 u8 sw_if_index_set = 0;
10935 u32 spd_id = (u32) ~ 0;
10939 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10941 if (unformat (i, "del"))
10943 else if (unformat (i, "spd_id %d", &spd_id))
10946 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10947 sw_if_index_set = 1;
10948 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10949 sw_if_index_set = 1;
10952 clib_warning ("parse error '%U'", format_unformat_error, i);
10958 if (spd_id == (u32) ~ 0)
10960 errmsg ("spd_id must be set");
10964 if (sw_if_index_set == 0)
10966 errmsg ("missing interface name or sw_if_index");
10970 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10972 mp->spd_id = ntohl (spd_id);
10973 mp->sw_if_index = ntohl (sw_if_index);
10974 mp->is_add = is_add;
10982 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10984 unformat_input_t *i = vam->input;
10985 vl_api_ipsec_spd_entry_add_del_t *mp;
10986 u8 is_add = 1, is_outbound = 0;
10987 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10989 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10990 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10991 vl_api_address_t laddr_start = { }, laddr_stop =
11000 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11002 if (unformat (i, "del"))
11004 if (unformat (i, "outbound"))
11006 if (unformat (i, "inbound"))
11008 else if (unformat (i, "spd_id %d", &spd_id))
11010 else if (unformat (i, "sa_id %d", &sa_id))
11012 else if (unformat (i, "priority %d", &priority))
11014 else if (unformat (i, "protocol %d", &protocol))
11016 else if (unformat (i, "lport_start %d", &lport_start))
11018 else if (unformat (i, "lport_stop %d", &lport_stop))
11020 else if (unformat (i, "rport_start %d", &rport_start))
11022 else if (unformat (i, "rport_stop %d", &rport_stop))
11024 else if (unformat (i, "laddr_start %U",
11025 unformat_vl_api_address, &laddr_start))
11027 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
11030 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
11033 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
11037 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11039 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11041 clib_warning ("unsupported action: 'resolve'");
11047 clib_warning ("parse error '%U'", format_unformat_error, i);
11053 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
11055 mp->is_add = is_add;
11057 mp->entry.spd_id = ntohl (spd_id);
11058 mp->entry.priority = ntohl (priority);
11059 mp->entry.is_outbound = is_outbound;
11061 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
11062 sizeof (vl_api_address_t));
11063 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
11064 sizeof (vl_api_address_t));
11065 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
11066 sizeof (vl_api_address_t));
11067 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
11068 sizeof (vl_api_address_t));
11070 mp->entry.protocol = (u8) protocol;
11071 mp->entry.local_port_start = ntohs ((u16) lport_start);
11072 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
11073 mp->entry.remote_port_start = ntohs ((u16) rport_start);
11074 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
11075 mp->entry.policy = (u8) policy;
11076 mp->entry.sa_id = ntohl (sa_id);
11084 api_ipsec_sad_entry_add_del (vat_main_t * vam)
11086 unformat_input_t *i = vam->input;
11087 vl_api_ipsec_sad_entry_add_del_t *mp;
11088 u32 sad_id = 0, spi = 0;
11089 u8 *ck = 0, *ik = 0;
11092 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
11093 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
11094 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
11095 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
11096 vl_api_address_t tun_src, tun_dst;
11099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11101 if (unformat (i, "del"))
11103 else if (unformat (i, "sad_id %d", &sad_id))
11105 else if (unformat (i, "spi %d", &spi))
11107 else if (unformat (i, "esp"))
11108 protocol = IPSEC_API_PROTO_ESP;
11110 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
11112 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11113 if (ADDRESS_IP6 == tun_src.af)
11114 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11117 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
11119 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11120 if (ADDRESS_IP6 == tun_src.af)
11121 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11124 if (unformat (i, "crypto_alg %U",
11125 unformat_ipsec_api_crypto_alg, &crypto_alg))
11127 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11129 else if (unformat (i, "integ_alg %U",
11130 unformat_ipsec_api_integ_alg, &integ_alg))
11132 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11136 clib_warning ("parse error '%U'", format_unformat_error, i);
11142 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
11144 mp->is_add = is_add;
11145 mp->entry.sad_id = ntohl (sad_id);
11146 mp->entry.protocol = protocol;
11147 mp->entry.spi = ntohl (spi);
11148 mp->entry.flags = flags;
11150 mp->entry.crypto_algorithm = crypto_alg;
11151 mp->entry.integrity_algorithm = integ_alg;
11152 mp->entry.crypto_key.length = vec_len (ck);
11153 mp->entry.integrity_key.length = vec_len (ik);
11155 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
11156 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
11158 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
11159 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
11162 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
11164 clib_memcpy (mp->entry.integrity_key.data, ik,
11165 mp->entry.integrity_key.length);
11167 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
11169 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
11170 sizeof (mp->entry.tunnel_src));
11171 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
11172 sizeof (mp->entry.tunnel_dst));
11181 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11183 vat_main_t *vam = &vat_main;
11185 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11186 "crypto_key %U integ_alg %u integ_key %U flags %x "
11187 "tunnel_src_addr %U tunnel_dst_addr %U "
11188 "salt %u seq_outbound %lu last_seq_inbound %lu "
11189 "replay_window %lu stat_index %u\n",
11190 ntohl (mp->entry.sad_id),
11191 ntohl (mp->sw_if_index),
11192 ntohl (mp->entry.spi),
11193 ntohl (mp->entry.protocol),
11194 ntohl (mp->entry.crypto_algorithm),
11195 format_hex_bytes, mp->entry.crypto_key.data,
11196 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11197 format_hex_bytes, mp->entry.integrity_key.data,
11198 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11199 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11200 &mp->entry.tunnel_dst, ntohl (mp->salt),
11201 clib_net_to_host_u64 (mp->seq_outbound),
11202 clib_net_to_host_u64 (mp->last_seq_inbound),
11203 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11206 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11207 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11209 static void vl_api_ipsec_sa_details_t_handler_json
11210 (vl_api_ipsec_sa_details_t * mp)
11212 vat_main_t *vam = &vat_main;
11213 vat_json_node_t *node = NULL;
11214 vl_api_ipsec_sad_flags_t flags;
11216 if (VAT_JSON_ARRAY != vam->json_tree.type)
11218 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11219 vat_json_init_array (&vam->json_tree);
11221 node = vat_json_array_add (&vam->json_tree);
11223 vat_json_init_object (node);
11224 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11225 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11226 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11227 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11228 vat_json_object_add_uint (node, "crypto_alg",
11229 ntohl (mp->entry.crypto_algorithm));
11230 vat_json_object_add_uint (node, "integ_alg",
11231 ntohl (mp->entry.integrity_algorithm));
11232 flags = ntohl (mp->entry.flags);
11233 vat_json_object_add_uint (node, "use_esn",
11234 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11235 vat_json_object_add_uint (node, "use_anti_replay",
11236 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11237 vat_json_object_add_uint (node, "is_tunnel",
11238 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11239 vat_json_object_add_uint (node, "is_tunnel_ip6",
11240 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11241 vat_json_object_add_uint (node, "udp_encap",
11242 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11243 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11244 mp->entry.crypto_key.length);
11245 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11246 mp->entry.integrity_key.length);
11247 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11248 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11249 vat_json_object_add_uint (node, "replay_window",
11250 clib_net_to_host_u64 (mp->replay_window));
11251 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11255 api_ipsec_sa_dump (vat_main_t * vam)
11257 unformat_input_t *i = vam->input;
11258 vl_api_ipsec_sa_dump_t *mp;
11259 vl_api_control_ping_t *mp_ping;
11263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11265 if (unformat (i, "sa_id %d", &sa_id))
11269 clib_warning ("parse error '%U'", format_unformat_error, i);
11274 M (IPSEC_SA_DUMP, mp);
11276 mp->sa_id = ntohl (sa_id);
11280 /* Use a control ping for synchronization */
11281 M (CONTROL_PING, mp_ping);
11289 api_get_first_msg_id (vat_main_t * vam)
11291 vl_api_get_first_msg_id_t *mp;
11292 unformat_input_t *i = vam->input;
11297 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11299 if (unformat (i, "client %s", &name))
11307 errmsg ("missing client name");
11310 vec_add1 (name, 0);
11312 if (vec_len (name) > 63)
11314 errmsg ("client name too long");
11318 M (GET_FIRST_MSG_ID, mp);
11319 clib_memcpy (mp->name, name, vec_len (name));
11326 api_cop_interface_enable_disable (vat_main_t * vam)
11328 unformat_input_t *line_input = vam->input;
11329 vl_api_cop_interface_enable_disable_t *mp;
11330 u32 sw_if_index = ~0;
11331 u8 enable_disable = 1;
11334 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11336 if (unformat (line_input, "disable"))
11337 enable_disable = 0;
11338 if (unformat (line_input, "enable"))
11339 enable_disable = 1;
11340 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11341 vam, &sw_if_index))
11343 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11349 if (sw_if_index == ~0)
11351 errmsg ("missing interface name or sw_if_index");
11355 /* Construct the API message */
11356 M (COP_INTERFACE_ENABLE_DISABLE, mp);
11357 mp->sw_if_index = ntohl (sw_if_index);
11358 mp->enable_disable = enable_disable;
11362 /* Wait for the reply */
11368 api_cop_whitelist_enable_disable (vat_main_t * vam)
11370 unformat_input_t *line_input = vam->input;
11371 vl_api_cop_whitelist_enable_disable_t *mp;
11372 u32 sw_if_index = ~0;
11373 u8 ip4 = 0, ip6 = 0, default_cop = 0;
11377 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11379 if (unformat (line_input, "ip4"))
11381 else if (unformat (line_input, "ip6"))
11383 else if (unformat (line_input, "default"))
11385 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11386 vam, &sw_if_index))
11388 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11390 else if (unformat (line_input, "fib-id %d", &fib_id))
11396 if (sw_if_index == ~0)
11398 errmsg ("missing interface name or sw_if_index");
11402 /* Construct the API message */
11403 M (COP_WHITELIST_ENABLE_DISABLE, mp);
11404 mp->sw_if_index = ntohl (sw_if_index);
11405 mp->fib_id = ntohl (fib_id);
11408 mp->default_cop = default_cop;
11412 /* Wait for the reply */
11418 api_get_node_graph (vat_main_t * vam)
11420 vl_api_get_node_graph_t *mp;
11423 M (GET_NODE_GRAPH, mp);
11427 /* Wait for the reply */
11433 api_af_packet_create (vat_main_t * vam)
11435 unformat_input_t *i = vam->input;
11436 vl_api_af_packet_create_t *mp;
11437 u8 *host_if_name = 0;
11439 u8 random_hw_addr = 1;
11442 clib_memset (hw_addr, 0, sizeof (hw_addr));
11444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11446 if (unformat (i, "name %s", &host_if_name))
11447 vec_add1 (host_if_name, 0);
11448 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11449 random_hw_addr = 0;
11454 if (!vec_len (host_if_name))
11456 errmsg ("host-interface name must be specified");
11460 if (vec_len (host_if_name) > 64)
11462 errmsg ("host-interface name too long");
11466 M (AF_PACKET_CREATE, mp);
11468 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11469 clib_memcpy (mp->hw_addr, hw_addr, 6);
11470 mp->use_random_hw_addr = random_hw_addr;
11471 vec_free (host_if_name);
11479 fprintf (vam->ofp ? vam->ofp : stderr,
11480 " new sw_if_index = %d\n", vam->sw_if_index);
11487 api_af_packet_delete (vat_main_t * vam)
11489 unformat_input_t *i = vam->input;
11490 vl_api_af_packet_delete_t *mp;
11491 u8 *host_if_name = 0;
11494 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11496 if (unformat (i, "name %s", &host_if_name))
11497 vec_add1 (host_if_name, 0);
11502 if (!vec_len (host_if_name))
11504 errmsg ("host-interface name must be specified");
11508 if (vec_len (host_if_name) > 64)
11510 errmsg ("host-interface name too long");
11514 M (AF_PACKET_DELETE, mp);
11516 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11517 vec_free (host_if_name);
11524 static void vl_api_af_packet_details_t_handler
11525 (vl_api_af_packet_details_t * mp)
11527 vat_main_t *vam = &vat_main;
11529 print (vam->ofp, "%-16s %d",
11530 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11533 static void vl_api_af_packet_details_t_handler_json
11534 (vl_api_af_packet_details_t * mp)
11536 vat_main_t *vam = &vat_main;
11537 vat_json_node_t *node = NULL;
11539 if (VAT_JSON_ARRAY != vam->json_tree.type)
11541 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11542 vat_json_init_array (&vam->json_tree);
11544 node = vat_json_array_add (&vam->json_tree);
11546 vat_json_init_object (node);
11547 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11548 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11552 api_af_packet_dump (vat_main_t * vam)
11554 vl_api_af_packet_dump_t *mp;
11555 vl_api_control_ping_t *mp_ping;
11558 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11559 /* Get list of tap interfaces */
11560 M (AF_PACKET_DUMP, mp);
11563 /* Use a control ping for synchronization */
11564 MPING (CONTROL_PING, mp_ping);
11572 api_policer_add_del (vat_main_t * vam)
11574 unformat_input_t *i = vam->input;
11575 vl_api_policer_add_del_t *mp;
11585 u8 color_aware = 0;
11586 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
11589 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
11590 conform_action.dscp = 0;
11591 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
11592 exceed_action.dscp = 0;
11593 violate_action.action_type = SSE2_QOS_ACTION_DROP;
11594 violate_action.dscp = 0;
11596 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11598 if (unformat (i, "del"))
11600 else if (unformat (i, "name %s", &name))
11601 vec_add1 (name, 0);
11602 else if (unformat (i, "cir %u", &cir))
11604 else if (unformat (i, "eir %u", &eir))
11606 else if (unformat (i, "cb %u", &cb))
11608 else if (unformat (i, "eb %u", &eb))
11610 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11613 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11616 else if (unformat (i, "type %U", unformat_policer_type, &type))
11618 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11621 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11624 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11627 else if (unformat (i, "color-aware"))
11633 if (!vec_len (name))
11635 errmsg ("policer name must be specified");
11639 if (vec_len (name) > 64)
11641 errmsg ("policer name too long");
11645 M (POLICER_ADD_DEL, mp);
11647 clib_memcpy (mp->name, name, vec_len (name));
11649 mp->is_add = is_add;
11650 mp->cir = ntohl (cir);
11651 mp->eir = ntohl (eir);
11652 mp->cb = clib_net_to_host_u64 (cb);
11653 mp->eb = clib_net_to_host_u64 (eb);
11654 mp->rate_type = rate_type;
11655 mp->round_type = round_type;
11657 mp->conform_action.type = conform_action.action_type;
11658 mp->conform_action.dscp = conform_action.dscp;
11659 mp->exceed_action.type = exceed_action.action_type;
11660 mp->exceed_action.dscp = exceed_action.dscp;
11661 mp->violate_action.type = violate_action.action_type;
11662 mp->violate_action.dscp = violate_action.dscp;
11663 mp->color_aware = color_aware;
11671 api_policer_dump (vat_main_t * vam)
11673 unformat_input_t *i = vam->input;
11674 vl_api_policer_dump_t *mp;
11675 vl_api_control_ping_t *mp_ping;
11676 u8 *match_name = 0;
11677 u8 match_name_valid = 0;
11680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11682 if (unformat (i, "name %s", &match_name))
11684 vec_add1 (match_name, 0);
11685 match_name_valid = 1;
11691 M (POLICER_DUMP, mp);
11692 mp->match_name_valid = match_name_valid;
11693 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11694 vec_free (match_name);
11698 /* Use a control ping for synchronization */
11699 MPING (CONTROL_PING, mp_ping);
11702 /* Wait for a reply... */
11708 api_policer_classify_set_interface (vat_main_t * vam)
11710 unformat_input_t *i = vam->input;
11711 vl_api_policer_classify_set_interface_t *mp;
11713 int sw_if_index_set;
11714 u32 ip4_table_index = ~0;
11715 u32 ip6_table_index = ~0;
11716 u32 l2_table_index = ~0;
11720 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11722 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11723 sw_if_index_set = 1;
11724 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11725 sw_if_index_set = 1;
11726 else if (unformat (i, "del"))
11728 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11730 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11732 else if (unformat (i, "l2-table %d", &l2_table_index))
11736 clib_warning ("parse error '%U'", format_unformat_error, i);
11741 if (sw_if_index_set == 0)
11743 errmsg ("missing interface name or sw_if_index");
11747 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
11749 mp->sw_if_index = ntohl (sw_if_index);
11750 mp->ip4_table_index = ntohl (ip4_table_index);
11751 mp->ip6_table_index = ntohl (ip6_table_index);
11752 mp->l2_table_index = ntohl (l2_table_index);
11753 mp->is_add = is_add;
11761 api_policer_classify_dump (vat_main_t * vam)
11763 unformat_input_t *i = vam->input;
11764 vl_api_policer_classify_dump_t *mp;
11765 vl_api_control_ping_t *mp_ping;
11766 u8 type = POLICER_CLASSIFY_N_TABLES;
11769 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
11773 errmsg ("classify table type must be specified");
11777 if (!vam->json_output)
11779 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
11782 M (POLICER_CLASSIFY_DUMP, mp);
11787 /* Use a control ping for synchronization */
11788 MPING (CONTROL_PING, mp_ping);
11791 /* Wait for a reply... */
11797 format_fib_api_path_nh_proto (u8 * s, va_list * args)
11799 vl_api_fib_path_nh_proto_t proto =
11800 va_arg (*args, vl_api_fib_path_nh_proto_t);
11804 case FIB_API_PATH_NH_PROTO_IP4:
11805 s = format (s, "ip4");
11807 case FIB_API_PATH_NH_PROTO_IP6:
11808 s = format (s, "ip6");
11810 case FIB_API_PATH_NH_PROTO_MPLS:
11811 s = format (s, "mpls");
11813 case FIB_API_PATH_NH_PROTO_BIER:
11814 s = format (s, "bier");
11816 case FIB_API_PATH_NH_PROTO_ETHERNET:
11817 s = format (s, "ethernet");
11825 format_vl_api_ip_address_union (u8 * s, va_list * args)
11827 vl_api_address_family_t af = va_arg (*args, int);
11828 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
11833 s = format (s, "%U", format_ip4_address, u->ip4);
11836 s = format (s, "%U", format_ip6_address, u->ip6);
11843 format_vl_api_fib_path_type (u8 * s, va_list * args)
11845 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
11849 case FIB_API_PATH_TYPE_NORMAL:
11850 s = format (s, "normal");
11852 case FIB_API_PATH_TYPE_LOCAL:
11853 s = format (s, "local");
11855 case FIB_API_PATH_TYPE_DROP:
11856 s = format (s, "drop");
11858 case FIB_API_PATH_TYPE_UDP_ENCAP:
11859 s = format (s, "udp-encap");
11861 case FIB_API_PATH_TYPE_BIER_IMP:
11862 s = format (s, "bier-imp");
11864 case FIB_API_PATH_TYPE_ICMP_UNREACH:
11865 s = format (s, "unreach");
11867 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
11868 s = format (s, "prohibit");
11870 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
11871 s = format (s, "src-lookup");
11873 case FIB_API_PATH_TYPE_DVR:
11874 s = format (s, "dvr");
11876 case FIB_API_PATH_TYPE_INTERFACE_RX:
11877 s = format (s, "interface-rx");
11879 case FIB_API_PATH_TYPE_CLASSIFY:
11880 s = format (s, "classify");
11888 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
11891 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
11892 ntohl (fp->weight), ntohl (fp->sw_if_index),
11893 format_vl_api_fib_path_type, fp->type,
11894 format_fib_api_path_nh_proto, fp->proto,
11895 format_vl_api_ip_address_union, &fp->nh.address);
11899 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
11900 vl_api_fib_path_t * fp)
11902 struct in_addr ip4;
11903 struct in6_addr ip6;
11905 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
11906 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
11907 vat_json_object_add_uint (node, "type", fp->type);
11908 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
11909 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
11911 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
11912 vat_json_object_add_ip4 (node, "next_hop", ip4);
11914 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
11916 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
11917 vat_json_object_add_ip6 (node, "next_hop", ip6);
11922 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
11924 vat_main_t *vam = &vat_main;
11925 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11926 vl_api_fib_path_t *fp;
11929 print (vam->ofp, "sw_if_index %d via:",
11930 ntohl (mp->mt_tunnel.mt_sw_if_index));
11931 fp = mp->mt_tunnel.mt_paths;
11932 for (i = 0; i < count; i++)
11934 vl_api_fib_path_print (vam, fp);
11938 print (vam->ofp, "");
11941 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
11942 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
11945 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
11947 vat_main_t *vam = &vat_main;
11948 vat_json_node_t *node = NULL;
11949 int count = ntohl (mp->mt_tunnel.mt_n_paths);
11950 vl_api_fib_path_t *fp;
11953 if (VAT_JSON_ARRAY != vam->json_tree.type)
11955 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11956 vat_json_init_array (&vam->json_tree);
11958 node = vat_json_array_add (&vam->json_tree);
11960 vat_json_init_object (node);
11961 vat_json_object_add_uint (node, "sw_if_index",
11962 ntohl (mp->mt_tunnel.mt_sw_if_index));
11964 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
11966 fp = mp->mt_tunnel.mt_paths;
11967 for (i = 0; i < count; i++)
11969 vl_api_mpls_fib_path_json_print (node, fp);
11975 api_mpls_tunnel_dump (vat_main_t * vam)
11977 vl_api_mpls_tunnel_dump_t *mp;
11978 vl_api_control_ping_t *mp_ping;
11981 M (MPLS_TUNNEL_DUMP, mp);
11985 /* Use a control ping for synchronization */
11986 MPING (CONTROL_PING, mp_ping);
11993 #define vl_api_mpls_table_details_t_endian vl_noop_handler
11994 #define vl_api_mpls_table_details_t_print vl_noop_handler
11998 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
12000 vat_main_t *vam = &vat_main;
12002 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
12005 static void vl_api_mpls_table_details_t_handler_json
12006 (vl_api_mpls_table_details_t * mp)
12008 vat_main_t *vam = &vat_main;
12009 vat_json_node_t *node = NULL;
12011 if (VAT_JSON_ARRAY != vam->json_tree.type)
12013 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12014 vat_json_init_array (&vam->json_tree);
12016 node = vat_json_array_add (&vam->json_tree);
12018 vat_json_init_object (node);
12019 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
12023 api_mpls_table_dump (vat_main_t * vam)
12025 vl_api_mpls_table_dump_t *mp;
12026 vl_api_control_ping_t *mp_ping;
12029 M (MPLS_TABLE_DUMP, mp);
12032 /* Use a control ping for synchronization */
12033 MPING (CONTROL_PING, mp_ping);
12040 #define vl_api_mpls_route_details_t_endian vl_noop_handler
12041 #define vl_api_mpls_route_details_t_print vl_noop_handler
12044 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
12046 vat_main_t *vam = &vat_main;
12047 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
12048 vl_api_fib_path_t *fp;
12052 "table-id %d, label %u, ess_bit %u",
12053 ntohl (mp->mr_route.mr_table_id),
12054 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
12055 fp = mp->mr_route.mr_paths;
12056 for (i = 0; i < count; i++)
12058 vl_api_fib_path_print (vam, fp);
12063 static void vl_api_mpls_route_details_t_handler_json
12064 (vl_api_mpls_route_details_t * mp)
12066 vat_main_t *vam = &vat_main;
12067 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
12068 vat_json_node_t *node = NULL;
12069 vl_api_fib_path_t *fp;
12072 if (VAT_JSON_ARRAY != vam->json_tree.type)
12074 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12075 vat_json_init_array (&vam->json_tree);
12077 node = vat_json_array_add (&vam->json_tree);
12079 vat_json_init_object (node);
12080 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
12081 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
12082 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
12083 vat_json_object_add_uint (node, "path_count", count);
12084 fp = mp->mr_route.mr_paths;
12085 for (i = 0; i < count; i++)
12087 vl_api_mpls_fib_path_json_print (node, fp);
12093 api_mpls_route_dump (vat_main_t * vam)
12095 unformat_input_t *input = vam->input;
12096 vl_api_mpls_route_dump_t *mp;
12097 vl_api_control_ping_t *mp_ping;
12101 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12103 if (unformat (input, "table_id %d", &table_id))
12108 if (table_id == ~0)
12110 errmsg ("missing table id");
12114 M (MPLS_ROUTE_DUMP, mp);
12116 mp->table.mt_table_id = ntohl (table_id);
12119 /* Use a control ping for synchronization */
12120 MPING (CONTROL_PING, mp_ping);
12127 #define vl_api_ip_table_details_t_endian vl_noop_handler
12128 #define vl_api_ip_table_details_t_print vl_noop_handler
12131 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12133 vat_main_t *vam = &vat_main;
12136 "%s; table-id %d, prefix %U/%d",
12137 mp->table.name, ntohl (mp->table.table_id));
12141 static void vl_api_ip_table_details_t_handler_json
12142 (vl_api_ip_table_details_t * mp)
12144 vat_main_t *vam = &vat_main;
12145 vat_json_node_t *node = NULL;
12147 if (VAT_JSON_ARRAY != vam->json_tree.type)
12149 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12150 vat_json_init_array (&vam->json_tree);
12152 node = vat_json_array_add (&vam->json_tree);
12154 vat_json_init_object (node);
12155 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12159 api_ip_table_dump (vat_main_t * vam)
12161 vl_api_ip_table_dump_t *mp;
12162 vl_api_control_ping_t *mp_ping;
12165 M (IP_TABLE_DUMP, mp);
12168 /* Use a control ping for synchronization */
12169 MPING (CONTROL_PING, mp_ping);
12177 api_ip_mtable_dump (vat_main_t * vam)
12179 vl_api_ip_mtable_dump_t *mp;
12180 vl_api_control_ping_t *mp_ping;
12183 M (IP_MTABLE_DUMP, mp);
12186 /* Use a control ping for synchronization */
12187 MPING (CONTROL_PING, mp_ping);
12195 api_ip_mroute_dump (vat_main_t * vam)
12197 unformat_input_t *input = vam->input;
12198 vl_api_control_ping_t *mp_ping;
12199 vl_api_ip_mroute_dump_t *mp;
12204 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12206 if (unformat (input, "table_id %d", &table_id))
12208 else if (unformat (input, "ip6"))
12210 else if (unformat (input, "ip4"))
12215 if (table_id == ~0)
12217 errmsg ("missing table id");
12221 M (IP_MROUTE_DUMP, mp);
12222 mp->table.table_id = table_id;
12223 mp->table.is_ip6 = is_ip6;
12226 /* Use a control ping for synchronization */
12227 MPING (CONTROL_PING, mp_ping);
12234 #define vl_api_ip_route_details_t_endian vl_noop_handler
12235 #define vl_api_ip_route_details_t_print vl_noop_handler
12238 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12240 vat_main_t *vam = &vat_main;
12241 u8 count = mp->route.n_paths;
12242 vl_api_fib_path_t *fp;
12246 "table-id %d, prefix %U/%d",
12247 ntohl (mp->route.table_id),
12248 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12249 for (i = 0; i < count; i++)
12251 fp = &mp->route.paths[i];
12253 vl_api_fib_path_print (vam, fp);
12258 static void vl_api_ip_route_details_t_handler_json
12259 (vl_api_ip_route_details_t * mp)
12261 vat_main_t *vam = &vat_main;
12262 u8 count = mp->route.n_paths;
12263 vat_json_node_t *node = NULL;
12264 struct in_addr ip4;
12265 struct in6_addr ip6;
12266 vl_api_fib_path_t *fp;
12269 if (VAT_JSON_ARRAY != vam->json_tree.type)
12271 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12272 vat_json_init_array (&vam->json_tree);
12274 node = vat_json_array_add (&vam->json_tree);
12276 vat_json_init_object (node);
12277 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12278 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12280 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12281 vat_json_object_add_ip6 (node, "prefix", ip6);
12285 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12286 vat_json_object_add_ip4 (node, "prefix", ip4);
12288 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12289 vat_json_object_add_uint (node, "path_count", count);
12290 for (i = 0; i < count; i++)
12292 fp = &mp->route.paths[i];
12293 vl_api_mpls_fib_path_json_print (node, fp);
12298 api_ip_route_dump (vat_main_t * vam)
12300 unformat_input_t *input = vam->input;
12301 vl_api_ip_route_dump_t *mp;
12302 vl_api_control_ping_t *mp_ping;
12308 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12310 if (unformat (input, "table_id %d", &table_id))
12312 else if (unformat (input, "ip6"))
12314 else if (unformat (input, "ip4"))
12319 if (table_id == ~0)
12321 errmsg ("missing table id");
12325 M (IP_ROUTE_DUMP, mp);
12327 mp->table.table_id = table_id;
12328 mp->table.is_ip6 = is_ip6;
12332 /* Use a control ping for synchronization */
12333 MPING (CONTROL_PING, mp_ping);
12341 api_classify_table_ids (vat_main_t * vam)
12343 vl_api_classify_table_ids_t *mp;
12346 /* Construct the API message */
12347 M (CLASSIFY_TABLE_IDS, mp);
12356 api_classify_table_by_interface (vat_main_t * vam)
12358 unformat_input_t *input = vam->input;
12359 vl_api_classify_table_by_interface_t *mp;
12361 u32 sw_if_index = ~0;
12363 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12365 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12367 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12372 if (sw_if_index == ~0)
12374 errmsg ("missing interface name or sw_if_index");
12378 /* Construct the API message */
12379 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12381 mp->sw_if_index = ntohl (sw_if_index);
12389 api_classify_table_info (vat_main_t * vam)
12391 unformat_input_t *input = vam->input;
12392 vl_api_classify_table_info_t *mp;
12396 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12398 if (unformat (input, "table_id %d", &table_id))
12403 if (table_id == ~0)
12405 errmsg ("missing table id");
12409 /* Construct the API message */
12410 M (CLASSIFY_TABLE_INFO, mp);
12412 mp->table_id = ntohl (table_id);
12420 api_classify_session_dump (vat_main_t * vam)
12422 unformat_input_t *input = vam->input;
12423 vl_api_classify_session_dump_t *mp;
12424 vl_api_control_ping_t *mp_ping;
12428 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12430 if (unformat (input, "table_id %d", &table_id))
12435 if (table_id == ~0)
12437 errmsg ("missing table id");
12441 /* Construct the API message */
12442 M (CLASSIFY_SESSION_DUMP, mp);
12444 mp->table_id = ntohl (table_id);
12447 /* Use a control ping for synchronization */
12448 MPING (CONTROL_PING, mp_ping);
12456 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12458 vat_main_t *vam = &vat_main;
12460 print (vam->ofp, "collector_address %U, collector_port %d, "
12461 "src_address %U, vrf_id %d, path_mtu %u, "
12462 "template_interval %u, udp_checksum %d",
12463 format_ip4_address, mp->collector_address,
12464 ntohs (mp->collector_port),
12465 format_ip4_address, mp->src_address,
12466 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12467 ntohl (mp->template_interval), mp->udp_checksum);
12470 vam->result_ready = 1;
12474 vl_api_ipfix_exporter_details_t_handler_json
12475 (vl_api_ipfix_exporter_details_t * mp)
12477 vat_main_t *vam = &vat_main;
12478 vat_json_node_t node;
12479 struct in_addr collector_address;
12480 struct in_addr src_address;
12482 vat_json_init_object (&node);
12483 clib_memcpy (&collector_address, &mp->collector_address,
12484 sizeof (collector_address));
12485 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12486 vat_json_object_add_uint (&node, "collector_port",
12487 ntohs (mp->collector_port));
12488 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12489 vat_json_object_add_ip4 (&node, "src_address", src_address);
12490 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12491 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12492 vat_json_object_add_uint (&node, "template_interval",
12493 ntohl (mp->template_interval));
12494 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12496 vat_json_print (vam->ofp, &node);
12497 vat_json_free (&node);
12499 vam->result_ready = 1;
12503 api_ipfix_exporter_dump (vat_main_t * vam)
12505 vl_api_ipfix_exporter_dump_t *mp;
12508 /* Construct the API message */
12509 M (IPFIX_EXPORTER_DUMP, mp);
12518 api_ipfix_classify_stream_dump (vat_main_t * vam)
12520 vl_api_ipfix_classify_stream_dump_t *mp;
12523 /* Construct the API message */
12524 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12535 vl_api_ipfix_classify_stream_details_t_handler
12536 (vl_api_ipfix_classify_stream_details_t * mp)
12538 vat_main_t *vam = &vat_main;
12539 print (vam->ofp, "domain_id %d, src_port %d",
12540 ntohl (mp->domain_id), ntohs (mp->src_port));
12542 vam->result_ready = 1;
12546 vl_api_ipfix_classify_stream_details_t_handler_json
12547 (vl_api_ipfix_classify_stream_details_t * mp)
12549 vat_main_t *vam = &vat_main;
12550 vat_json_node_t node;
12552 vat_json_init_object (&node);
12553 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12554 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12556 vat_json_print (vam->ofp, &node);
12557 vat_json_free (&node);
12559 vam->result_ready = 1;
12563 api_ipfix_classify_table_dump (vat_main_t * vam)
12565 vl_api_ipfix_classify_table_dump_t *mp;
12566 vl_api_control_ping_t *mp_ping;
12569 if (!vam->json_output)
12571 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12572 "transport_protocol");
12575 /* Construct the API message */
12576 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12581 /* Use a control ping for synchronization */
12582 MPING (CONTROL_PING, mp_ping);
12590 vl_api_ipfix_classify_table_details_t_handler
12591 (vl_api_ipfix_classify_table_details_t * mp)
12593 vat_main_t *vam = &vat_main;
12594 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12595 mp->transport_protocol);
12599 vl_api_ipfix_classify_table_details_t_handler_json
12600 (vl_api_ipfix_classify_table_details_t * mp)
12602 vat_json_node_t *node = NULL;
12603 vat_main_t *vam = &vat_main;
12605 if (VAT_JSON_ARRAY != vam->json_tree.type)
12607 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12608 vat_json_init_array (&vam->json_tree);
12611 node = vat_json_array_add (&vam->json_tree);
12612 vat_json_init_object (node);
12614 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12615 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12616 vat_json_object_add_uint (node, "transport_protocol",
12617 mp->transport_protocol);
12621 api_sw_interface_span_enable_disable (vat_main_t * vam)
12623 unformat_input_t *i = vam->input;
12624 vl_api_sw_interface_span_enable_disable_t *mp;
12625 u32 src_sw_if_index = ~0;
12626 u32 dst_sw_if_index = ~0;
12631 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12634 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12636 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12640 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12642 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12644 else if (unformat (i, "disable"))
12646 else if (unformat (i, "rx"))
12648 else if (unformat (i, "tx"))
12650 else if (unformat (i, "both"))
12652 else if (unformat (i, "l2"))
12658 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12660 mp->sw_if_index_from = htonl (src_sw_if_index);
12661 mp->sw_if_index_to = htonl (dst_sw_if_index);
12671 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12674 vat_main_t *vam = &vat_main;
12675 u8 *sw_if_from_name = 0;
12676 u8 *sw_if_to_name = 0;
12677 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12678 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12679 char *states[] = { "none", "rx", "tx", "both" };
12683 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12685 if ((u32) p->value[0] == sw_if_index_from)
12687 sw_if_from_name = (u8 *)(p->key);
12691 if ((u32) p->value[0] == sw_if_index_to)
12693 sw_if_to_name = (u8 *)(p->key);
12694 if (sw_if_from_name)
12699 print (vam->ofp, "%20s => %20s (%s) %s",
12700 sw_if_from_name, sw_if_to_name, states[mp->state],
12701 mp->is_l2 ? "l2" : "device");
12705 vl_api_sw_interface_span_details_t_handler_json
12706 (vl_api_sw_interface_span_details_t * mp)
12708 vat_main_t *vam = &vat_main;
12709 vat_json_node_t *node = NULL;
12710 u8 *sw_if_from_name = 0;
12711 u8 *sw_if_to_name = 0;
12712 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12713 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12717 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12719 if ((u32) p->value[0] == sw_if_index_from)
12721 sw_if_from_name = (u8 *)(p->key);
12725 if ((u32) p->value[0] == sw_if_index_to)
12727 sw_if_to_name = (u8 *)(p->key);
12728 if (sw_if_from_name)
12734 if (VAT_JSON_ARRAY != vam->json_tree.type)
12736 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12737 vat_json_init_array (&vam->json_tree);
12739 node = vat_json_array_add (&vam->json_tree);
12741 vat_json_init_object (node);
12742 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12743 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12744 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12745 if (0 != sw_if_to_name)
12747 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
12749 vat_json_object_add_uint (node, "state", mp->state);
12750 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
12754 api_sw_interface_span_dump (vat_main_t * vam)
12756 unformat_input_t *input = vam->input;
12757 vl_api_sw_interface_span_dump_t *mp;
12758 vl_api_control_ping_t *mp_ping;
12762 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12764 if (unformat (input, "l2"))
12770 M (SW_INTERFACE_SPAN_DUMP, mp);
12774 /* Use a control ping for synchronization */
12775 MPING (CONTROL_PING, mp_ping);
12783 api_pg_create_interface (vat_main_t * vam)
12785 unformat_input_t *input = vam->input;
12786 vl_api_pg_create_interface_t *mp;
12788 u32 if_id = ~0, gso_size = 0;
12789 u8 gso_enabled = 0;
12791 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12793 if (unformat (input, "if_id %d", &if_id))
12795 else if (unformat (input, "gso-enabled"))
12798 if (unformat (input, "gso-size %u", &gso_size))
12802 errmsg ("missing gso-size");
12811 errmsg ("missing pg interface index");
12815 /* Construct the API message */
12816 M (PG_CREATE_INTERFACE, mp);
12818 mp->interface_id = ntohl (if_id);
12819 mp->gso_enabled = gso_enabled;
12827 api_pg_capture (vat_main_t * vam)
12829 unformat_input_t *input = vam->input;
12830 vl_api_pg_capture_t *mp;
12835 u8 pcap_file_set = 0;
12838 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12840 if (unformat (input, "if_id %d", &if_id))
12842 else if (unformat (input, "pcap %s", &pcap_file))
12844 else if (unformat (input, "count %d", &count))
12846 else if (unformat (input, "disable"))
12853 errmsg ("missing pg interface index");
12856 if (pcap_file_set > 0)
12858 if (vec_len (pcap_file) > 255)
12860 errmsg ("pcap file name is too long");
12865 /* Construct the API message */
12866 M (PG_CAPTURE, mp);
12868 mp->interface_id = ntohl (if_id);
12869 mp->is_enabled = enable;
12870 mp->count = ntohl (count);
12871 if (pcap_file_set != 0)
12873 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
12875 vec_free (pcap_file);
12883 api_pg_enable_disable (vat_main_t * vam)
12885 unformat_input_t *input = vam->input;
12886 vl_api_pg_enable_disable_t *mp;
12889 u8 stream_name_set = 0;
12890 u8 *stream_name = 0;
12892 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12894 if (unformat (input, "stream %s", &stream_name))
12895 stream_name_set = 1;
12896 else if (unformat (input, "disable"))
12902 if (stream_name_set > 0)
12904 if (vec_len (stream_name) > 255)
12906 errmsg ("stream name too long");
12911 /* Construct the API message */
12912 M (PG_ENABLE_DISABLE, mp);
12914 mp->is_enabled = enable;
12915 if (stream_name_set != 0)
12917 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
12919 vec_free (stream_name);
12927 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
12929 unformat_input_t *input = vam->input;
12930 vl_api_pg_interface_enable_disable_coalesce_t *mp;
12932 u32 sw_if_index = ~0;
12935 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12937 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12939 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12941 else if (unformat (input, "disable"))
12947 if (sw_if_index == ~0)
12949 errmsg ("Interface required but not specified");
12953 /* Construct the API message */
12954 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
12956 mp->coalesce_enabled = enable;
12957 mp->sw_if_index = htonl (sw_if_index);
12965 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
12967 unformat_input_t *input = vam->input;
12968 vl_api_ip_source_and_port_range_check_add_del_t *mp;
12970 u16 *low_ports = 0;
12971 u16 *high_ports = 0;
12974 vl_api_prefix_t prefix;
12981 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12983 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
12985 else if (unformat (input, "vrf %d", &vrf_id))
12987 else if (unformat (input, "del"))
12989 else if (unformat (input, "port %d", &tmp))
12991 if (tmp == 0 || tmp > 65535)
12993 errmsg ("port %d out of range", tmp);
12997 this_hi = this_low + 1;
12998 vec_add1 (low_ports, this_low);
12999 vec_add1 (high_ports, this_hi);
13001 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13003 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
13005 errmsg ("incorrect range parameters");
13009 /* Note: in debug CLI +1 is added to high before
13010 passing to real fn that does "the work"
13011 (ip_source_and_port_range_check_add_del).
13012 This fn is a wrapper around the binary API fn a
13013 control plane will call, which expects this increment
13014 to have occurred. Hence letting the binary API control
13015 plane fn do the increment for consistency between VAT
13016 and other control planes.
13019 vec_add1 (low_ports, this_low);
13020 vec_add1 (high_ports, this_hi);
13026 if (prefix_set == 0)
13028 errmsg ("<address>/<mask> not specified");
13034 errmsg ("VRF ID required, not specified");
13041 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13045 if (vec_len (low_ports) == 0)
13047 errmsg ("At least one port or port range required");
13051 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
13053 mp->is_add = is_add;
13055 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
13057 mp->number_of_ranges = vec_len (low_ports);
13059 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
13060 vec_free (low_ports);
13062 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
13063 vec_free (high_ports);
13065 mp->vrf_id = ntohl (vrf_id);
13073 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13075 unformat_input_t *input = vam->input;
13076 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13077 u32 sw_if_index = ~0;
13079 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
13080 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
13084 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13086 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13088 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13090 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
13092 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
13094 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13096 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13098 else if (unformat (input, "del"))
13104 if (sw_if_index == ~0)
13106 errmsg ("Interface required but not specified");
13112 errmsg ("VRF ID required but not specified");
13116 if (tcp_out_vrf_id == 0
13117 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13120 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13124 /* Construct the API message */
13125 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13127 mp->sw_if_index = ntohl (sw_if_index);
13128 mp->is_add = is_add;
13129 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13130 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13131 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13132 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13137 /* Wait for a reply... */
13143 api_set_punt (vat_main_t * vam)
13145 unformat_input_t *i = vam->input;
13146 vl_api_address_family_t af;
13147 vl_api_set_punt_t *mp;
13153 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13155 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13157 else if (unformat (i, "protocol %d", &protocol))
13159 else if (unformat (i, "port %d", &port))
13161 else if (unformat (i, "del"))
13165 clib_warning ("parse error '%U'", format_unformat_error, i);
13172 mp->is_add = (u8) is_add;
13173 mp->punt.type = PUNT_API_TYPE_L4;
13174 mp->punt.punt.l4.af = af;
13175 mp->punt.punt.l4.protocol = (u8) protocol;
13176 mp->punt.punt.l4.port = htons ((u16) port);
13184 api_delete_subif (vat_main_t * vam)
13186 unformat_input_t *i = vam->input;
13187 vl_api_delete_subif_t *mp;
13188 u32 sw_if_index = ~0;
13191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13193 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13195 if (unformat (i, "sw_if_index %d", &sw_if_index))
13201 if (sw_if_index == ~0)
13203 errmsg ("missing sw_if_index");
13207 /* Construct the API message */
13208 M (DELETE_SUBIF, mp);
13209 mp->sw_if_index = ntohl (sw_if_index);
13216 #define foreach_pbb_vtr_op \
13217 _("disable", L2_VTR_DISABLED) \
13218 _("pop", L2_VTR_POP_2) \
13219 _("push", L2_VTR_PUSH_2)
13222 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13224 unformat_input_t *i = vam->input;
13225 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13226 u32 sw_if_index = ~0, vtr_op = ~0;
13227 u16 outer_tag = ~0;
13228 u8 dmac[6], smac[6];
13229 u8 dmac_set = 0, smac_set = 0;
13235 /* Shut up coverity */
13236 clib_memset (dmac, 0, sizeof (dmac));
13237 clib_memset (smac, 0, sizeof (smac));
13239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13241 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13243 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13245 else if (unformat (i, "vtr_op %d", &vtr_op))
13247 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13250 else if (unformat (i, "translate_pbb_stag"))
13252 if (unformat (i, "%d", &tmp))
13254 vtr_op = L2_VTR_TRANSLATE_2_1;
13260 ("translate_pbb_stag operation requires outer tag definition");
13264 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13266 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13268 else if (unformat (i, "sid %d", &sid))
13270 else if (unformat (i, "vlanid %d", &tmp))
13274 clib_warning ("parse error '%U'", format_unformat_error, i);
13279 if ((sw_if_index == ~0) || (vtr_op == ~0))
13281 errmsg ("missing sw_if_index or vtr operation");
13284 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13285 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13288 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13292 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13293 mp->sw_if_index = ntohl (sw_if_index);
13294 mp->vtr_op = ntohl (vtr_op);
13295 mp->outer_tag = ntohs (outer_tag);
13296 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13297 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13298 mp->b_vlanid = ntohs (vlanid);
13299 mp->i_sid = ntohl (sid);
13307 api_flow_classify_set_interface (vat_main_t * vam)
13309 unformat_input_t *i = vam->input;
13310 vl_api_flow_classify_set_interface_t *mp;
13312 int sw_if_index_set;
13313 u32 ip4_table_index = ~0;
13314 u32 ip6_table_index = ~0;
13318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13320 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13321 sw_if_index_set = 1;
13322 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13323 sw_if_index_set = 1;
13324 else if (unformat (i, "del"))
13326 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13328 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13332 clib_warning ("parse error '%U'", format_unformat_error, i);
13337 if (sw_if_index_set == 0)
13339 errmsg ("missing interface name or sw_if_index");
13343 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13345 mp->sw_if_index = ntohl (sw_if_index);
13346 mp->ip4_table_index = ntohl (ip4_table_index);
13347 mp->ip6_table_index = ntohl (ip6_table_index);
13348 mp->is_add = is_add;
13356 api_flow_classify_dump (vat_main_t * vam)
13358 unformat_input_t *i = vam->input;
13359 vl_api_flow_classify_dump_t *mp;
13360 vl_api_control_ping_t *mp_ping;
13361 u8 type = FLOW_CLASSIFY_N_TABLES;
13364 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13368 errmsg ("classify table type must be specified");
13372 if (!vam->json_output)
13374 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13377 M (FLOW_CLASSIFY_DUMP, mp);
13382 /* Use a control ping for synchronization */
13383 MPING (CONTROL_PING, mp_ping);
13386 /* Wait for a reply... */
13392 api_feature_enable_disable (vat_main_t * vam)
13394 unformat_input_t *i = vam->input;
13395 vl_api_feature_enable_disable_t *mp;
13397 u8 *feature_name = 0;
13398 u32 sw_if_index = ~0;
13402 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13404 if (unformat (i, "arc_name %s", &arc_name))
13406 else if (unformat (i, "feature_name %s", &feature_name))
13409 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13411 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13413 else if (unformat (i, "disable"))
13421 errmsg ("missing arc name");
13424 if (vec_len (arc_name) > 63)
13426 errmsg ("arc name too long");
13429 if (feature_name == 0)
13431 errmsg ("missing feature name");
13434 if (vec_len (feature_name) > 63)
13436 errmsg ("feature name too long");
13439 if (sw_if_index == ~0)
13441 errmsg ("missing interface name or sw_if_index");
13445 /* Construct the API message */
13446 M (FEATURE_ENABLE_DISABLE, mp);
13447 mp->sw_if_index = ntohl (sw_if_index);
13448 mp->enable = enable;
13449 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13450 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13451 vec_free (arc_name);
13452 vec_free (feature_name);
13460 api_feature_gso_enable_disable (vat_main_t * vam)
13462 unformat_input_t *i = vam->input;
13463 vl_api_feature_gso_enable_disable_t *mp;
13464 u32 sw_if_index = ~0;
13468 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13470 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13472 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13474 else if (unformat (i, "enable"))
13476 else if (unformat (i, "disable"))
13482 if (sw_if_index == ~0)
13484 errmsg ("missing interface name or sw_if_index");
13488 /* Construct the API message */
13489 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13490 mp->sw_if_index = ntohl (sw_if_index);
13491 mp->enable_disable = enable;
13499 api_sw_interface_tag_add_del (vat_main_t * vam)
13501 unformat_input_t *i = vam->input;
13502 vl_api_sw_interface_tag_add_del_t *mp;
13503 u32 sw_if_index = ~0;
13508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13510 if (unformat (i, "tag %s", &tag))
13512 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13514 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13516 else if (unformat (i, "del"))
13522 if (sw_if_index == ~0)
13524 errmsg ("missing interface name or sw_if_index");
13528 if (enable && (tag == 0))
13530 errmsg ("no tag specified");
13534 /* Construct the API message */
13535 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13536 mp->sw_if_index = ntohl (sw_if_index);
13537 mp->is_add = enable;
13539 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13548 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13550 unformat_input_t *i = vam->input;
13551 vl_api_mac_address_t mac = { 0 };
13552 vl_api_sw_interface_add_del_mac_address_t *mp;
13553 u32 sw_if_index = ~0;
13558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13560 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13562 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13564 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13566 else if (unformat (i, "del"))
13572 if (sw_if_index == ~0)
13574 errmsg ("missing interface name or sw_if_index");
13580 errmsg ("missing MAC address");
13584 /* Construct the API message */
13585 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13586 mp->sw_if_index = ntohl (sw_if_index);
13587 mp->is_add = is_add;
13588 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13595 static void vl_api_l2_xconnect_details_t_handler
13596 (vl_api_l2_xconnect_details_t * mp)
13598 vat_main_t *vam = &vat_main;
13600 print (vam->ofp, "%15d%15d",
13601 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13604 static void vl_api_l2_xconnect_details_t_handler_json
13605 (vl_api_l2_xconnect_details_t * mp)
13607 vat_main_t *vam = &vat_main;
13608 vat_json_node_t *node = NULL;
13610 if (VAT_JSON_ARRAY != vam->json_tree.type)
13612 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13613 vat_json_init_array (&vam->json_tree);
13615 node = vat_json_array_add (&vam->json_tree);
13617 vat_json_init_object (node);
13618 vat_json_object_add_uint (node, "rx_sw_if_index",
13619 ntohl (mp->rx_sw_if_index));
13620 vat_json_object_add_uint (node, "tx_sw_if_index",
13621 ntohl (mp->tx_sw_if_index));
13625 api_l2_xconnect_dump (vat_main_t * vam)
13627 vl_api_l2_xconnect_dump_t *mp;
13628 vl_api_control_ping_t *mp_ping;
13631 if (!vam->json_output)
13633 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13636 M (L2_XCONNECT_DUMP, mp);
13640 /* Use a control ping for synchronization */
13641 MPING (CONTROL_PING, mp_ping);
13649 api_hw_interface_set_mtu (vat_main_t * vam)
13651 unformat_input_t *i = vam->input;
13652 vl_api_hw_interface_set_mtu_t *mp;
13653 u32 sw_if_index = ~0;
13657 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13659 if (unformat (i, "mtu %d", &mtu))
13661 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13663 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13669 if (sw_if_index == ~0)
13671 errmsg ("missing interface name or sw_if_index");
13677 errmsg ("no mtu specified");
13681 /* Construct the API message */
13682 M (HW_INTERFACE_SET_MTU, mp);
13683 mp->sw_if_index = ntohl (sw_if_index);
13684 mp->mtu = ntohs ((u16) mtu);
13692 api_p2p_ethernet_add (vat_main_t * vam)
13694 unformat_input_t *i = vam->input;
13695 vl_api_p2p_ethernet_add_t *mp;
13696 u32 parent_if_index = ~0;
13702 clib_memset (remote_mac, 0, sizeof (remote_mac));
13703 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13705 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13707 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13711 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13713 else if (unformat (i, "sub_id %d", &sub_id))
13717 clib_warning ("parse error '%U'", format_unformat_error, i);
13722 if (parent_if_index == ~0)
13724 errmsg ("missing interface name or sw_if_index");
13729 errmsg ("missing remote mac address");
13734 errmsg ("missing sub-interface id");
13738 M (P2P_ETHERNET_ADD, mp);
13739 mp->parent_if_index = ntohl (parent_if_index);
13740 mp->subif_id = ntohl (sub_id);
13741 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13749 api_p2p_ethernet_del (vat_main_t * vam)
13751 unformat_input_t *i = vam->input;
13752 vl_api_p2p_ethernet_del_t *mp;
13753 u32 parent_if_index = ~0;
13758 clib_memset (remote_mac, 0, sizeof (remote_mac));
13759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13761 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13763 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13767 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13771 clib_warning ("parse error '%U'", format_unformat_error, i);
13776 if (parent_if_index == ~0)
13778 errmsg ("missing interface name or sw_if_index");
13783 errmsg ("missing remote mac address");
13787 M (P2P_ETHERNET_DEL, mp);
13788 mp->parent_if_index = ntohl (parent_if_index);
13789 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
13797 api_tcp_configure_src_addresses (vat_main_t * vam)
13799 vl_api_tcp_configure_src_addresses_t *mp;
13800 unformat_input_t *i = vam->input;
13801 vl_api_address_t first, last;
13806 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13808 if (unformat (i, "%U - %U",
13809 unformat_vl_api_address, &first,
13810 unformat_vl_api_address, &last))
13814 errmsg ("one range per message (range already set)");
13819 else if (unformat (i, "vrf %d", &vrf_id))
13825 if (range_set == 0)
13827 errmsg ("address range not set");
13831 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
13833 mp->vrf_id = ntohl (vrf_id);
13834 clib_memcpy (&mp->first_address, &first, sizeof (first));
13835 clib_memcpy (&mp->last_address, &last, sizeof (last));
13842 static void vl_api_app_namespace_add_del_reply_t_handler
13843 (vl_api_app_namespace_add_del_reply_t * mp)
13845 vat_main_t *vam = &vat_main;
13846 i32 retval = ntohl (mp->retval);
13847 if (vam->async_mode)
13849 vam->async_errors += (retval < 0);
13853 vam->retval = retval;
13855 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
13856 vam->result_ready = 1;
13860 static void vl_api_app_namespace_add_del_reply_t_handler_json
13861 (vl_api_app_namespace_add_del_reply_t * mp)
13863 vat_main_t *vam = &vat_main;
13864 vat_json_node_t node;
13866 vat_json_init_object (&node);
13867 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
13868 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
13870 vat_json_print (vam->ofp, &node);
13871 vat_json_free (&node);
13873 vam->retval = ntohl (mp->retval);
13874 vam->result_ready = 1;
13878 api_app_namespace_add_del (vat_main_t * vam)
13880 vl_api_app_namespace_add_del_t *mp;
13881 unformat_input_t *i = vam->input;
13882 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
13883 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
13887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13889 if (unformat (i, "id %_%v%_", &ns_id))
13891 else if (unformat (i, "secret %lu", &secret))
13893 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13894 sw_if_index_set = 1;
13895 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
13897 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
13902 if (!ns_id || !secret_set || !sw_if_index_set)
13904 errmsg ("namespace id, secret and sw_if_index must be set");
13907 if (vec_len (ns_id) > 64)
13909 errmsg ("namespace id too long");
13912 M (APP_NAMESPACE_ADD_DEL, mp);
13914 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
13915 mp->secret = clib_host_to_net_u64 (secret);
13916 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
13917 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
13918 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
13926 api_sock_init_shm (vat_main_t * vam)
13928 #if VPP_API_TEST_BUILTIN == 0
13929 unformat_input_t *i = vam->input;
13930 vl_api_shm_elem_config_t *config = 0;
13931 u64 size = 64 << 20;
13934 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13936 if (unformat (i, "size %U", unformat_memory_size, &size))
13943 * Canned custom ring allocator config.
13944 * Should probably parse all of this
13946 vec_validate (config, 6);
13947 config[0].type = VL_API_VLIB_RING;
13948 config[0].size = 256;
13949 config[0].count = 32;
13951 config[1].type = VL_API_VLIB_RING;
13952 config[1].size = 1024;
13953 config[1].count = 16;
13955 config[2].type = VL_API_VLIB_RING;
13956 config[2].size = 4096;
13957 config[2].count = 2;
13959 config[3].type = VL_API_CLIENT_RING;
13960 config[3].size = 256;
13961 config[3].count = 32;
13963 config[4].type = VL_API_CLIENT_RING;
13964 config[4].size = 1024;
13965 config[4].count = 16;
13967 config[5].type = VL_API_CLIENT_RING;
13968 config[5].size = 4096;
13969 config[5].count = 2;
13971 config[6].type = VL_API_QUEUE;
13972 config[6].count = 128;
13973 config[6].size = sizeof (uword);
13975 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
13977 vam->client_index_invalid = 1;
13985 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
13987 vat_main_t *vam = &vat_main;
13988 fib_prefix_t lcl, rmt;
13990 ip_prefix_decode (&mp->lcl, &lcl);
13991 ip_prefix_decode (&mp->rmt, &rmt);
13993 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
13996 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
13997 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
13998 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
13999 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
14000 &rmt.fp_addr.ip4, rmt.fp_len,
14001 clib_net_to_host_u16 (mp->rmt_port),
14002 clib_net_to_host_u32 (mp->action_index), mp->tag);
14007 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14008 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14009 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
14010 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
14011 &rmt.fp_addr.ip6, rmt.fp_len,
14012 clib_net_to_host_u16 (mp->rmt_port),
14013 clib_net_to_host_u32 (mp->action_index), mp->tag);
14018 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
14021 vat_main_t *vam = &vat_main;
14022 vat_json_node_t *node = NULL;
14023 struct in6_addr ip6;
14024 struct in_addr ip4;
14026 fib_prefix_t lcl, rmt;
14028 ip_prefix_decode (&mp->lcl, &lcl);
14029 ip_prefix_decode (&mp->rmt, &rmt);
14031 if (VAT_JSON_ARRAY != vam->json_tree.type)
14033 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14034 vat_json_init_array (&vam->json_tree);
14036 node = vat_json_array_add (&vam->json_tree);
14037 vat_json_init_object (node);
14039 vat_json_object_add_uint (node, "appns_index",
14040 clib_net_to_host_u32 (mp->appns_index));
14041 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
14042 vat_json_object_add_uint (node, "scope", mp->scope);
14043 vat_json_object_add_uint (node, "action_index",
14044 clib_net_to_host_u32 (mp->action_index));
14045 vat_json_object_add_uint (node, "lcl_port",
14046 clib_net_to_host_u16 (mp->lcl_port));
14047 vat_json_object_add_uint (node, "rmt_port",
14048 clib_net_to_host_u16 (mp->rmt_port));
14049 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
14050 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
14051 vat_json_object_add_string_copy (node, "tag", mp->tag);
14052 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14054 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
14055 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
14056 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
14057 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
14061 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
14062 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
14063 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
14064 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
14069 api_session_rule_add_del (vat_main_t * vam)
14071 vl_api_session_rule_add_del_t *mp;
14072 unformat_input_t *i = vam->input;
14073 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
14074 u32 appns_index = 0, scope = 0;
14075 ip4_address_t lcl_ip4, rmt_ip4;
14076 ip6_address_t lcl_ip6, rmt_ip6;
14077 u8 is_ip4 = 1, conn_set = 0;
14078 u8 is_add = 1, *tag = 0;
14080 fib_prefix_t lcl, rmt;
14082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14084 if (unformat (i, "del"))
14086 else if (unformat (i, "add"))
14088 else if (unformat (i, "proto tcp"))
14090 else if (unformat (i, "proto udp"))
14092 else if (unformat (i, "appns %d", &appns_index))
14094 else if (unformat (i, "scope %d", &scope))
14096 else if (unformat (i, "tag %_%v%_", &tag))
14100 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14101 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14109 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14110 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14116 else if (unformat (i, "action %d", &action))
14121 if (proto == ~0 || !conn_set || action == ~0)
14123 errmsg ("transport proto, connection and action must be set");
14129 errmsg ("scope should be 0-3");
14133 M (SESSION_RULE_ADD_DEL, mp);
14135 clib_memset (&lcl, 0, sizeof (lcl));
14136 clib_memset (&rmt, 0, sizeof (rmt));
14139 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14140 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14141 lcl.fp_len = lcl_plen;
14142 rmt.fp_len = rmt_plen;
14146 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14147 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14148 lcl.fp_len = lcl_plen;
14149 rmt.fp_len = rmt_plen;
14153 ip_prefix_encode (&lcl, &mp->lcl);
14154 ip_prefix_encode (&rmt, &mp->rmt);
14155 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14156 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14157 mp->transport_proto =
14158 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14159 mp->action_index = clib_host_to_net_u32 (action);
14160 mp->appns_index = clib_host_to_net_u32 (appns_index);
14162 mp->is_add = is_add;
14165 clib_memcpy (mp->tag, tag, vec_len (tag));
14175 api_session_rules_dump (vat_main_t * vam)
14177 vl_api_session_rules_dump_t *mp;
14178 vl_api_control_ping_t *mp_ping;
14181 if (!vam->json_output)
14183 print (vam->ofp, "%=20s", "Session Rules");
14186 M (SESSION_RULES_DUMP, mp);
14190 /* Use a control ping for synchronization */
14191 MPING (CONTROL_PING, mp_ping);
14194 /* Wait for a reply... */
14200 api_ip_container_proxy_add_del (vat_main_t * vam)
14202 vl_api_ip_container_proxy_add_del_t *mp;
14203 unformat_input_t *i = vam->input;
14204 u32 sw_if_index = ~0;
14205 vl_api_prefix_t pfx = { };
14209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14211 if (unformat (i, "del"))
14213 else if (unformat (i, "add"))
14215 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14217 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14222 if (sw_if_index == ~0 || pfx.len == 0)
14224 errmsg ("address and sw_if_index must be set");
14228 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14230 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14231 mp->is_add = is_add;
14232 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14240 api_qos_record_enable_disable (vat_main_t * vam)
14242 unformat_input_t *i = vam->input;
14243 vl_api_qos_record_enable_disable_t *mp;
14244 u32 sw_if_index, qs = 0xff;
14245 u8 sw_if_index_set = 0;
14249 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14251 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14252 sw_if_index_set = 1;
14253 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14254 sw_if_index_set = 1;
14255 else if (unformat (i, "%U", unformat_qos_source, &qs))
14257 else if (unformat (i, "disable"))
14261 clib_warning ("parse error '%U'", format_unformat_error, i);
14266 if (sw_if_index_set == 0)
14268 errmsg ("missing interface name or sw_if_index");
14273 errmsg ("input location must be specified");
14277 M (QOS_RECORD_ENABLE_DISABLE, mp);
14279 mp->record.sw_if_index = ntohl (sw_if_index);
14280 mp->record.input_source = qs;
14281 mp->enable = enable;
14290 q_or_quit (vat_main_t * vam)
14292 #if VPP_API_TEST_BUILTIN == 0
14293 longjmp (vam->jump_buf, 1);
14295 return 0; /* not so much */
14299 q (vat_main_t * vam)
14301 return q_or_quit (vam);
14305 quit (vat_main_t * vam)
14307 return q_or_quit (vam);
14311 comment (vat_main_t * vam)
14317 elog_save (vat_main_t * vam)
14319 #if VPP_API_TEST_BUILTIN == 0
14320 elog_main_t *em = &vam->elog_main;
14321 unformat_input_t *i = vam->input;
14322 char *file, *chroot_file;
14323 clib_error_t *error;
14325 if (!unformat (i, "%s", &file))
14327 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14331 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14332 if (strstr (file, "..") || index (file, '/'))
14334 errmsg ("illegal characters in filename '%s'", file);
14338 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14342 errmsg ("Saving %wd of %wd events to %s",
14343 elog_n_events_in_buffer (em),
14344 elog_buffer_capacity (em), chroot_file);
14346 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14347 vec_free (chroot_file);
14350 clib_error_report (error);
14352 errmsg ("Use the vpp event loger...");
14359 elog_setup (vat_main_t * vam)
14361 #if VPP_API_TEST_BUILTIN == 0
14362 elog_main_t *em = &vam->elog_main;
14363 unformat_input_t *i = vam->input;
14364 u32 nevents = 128 << 10;
14366 (void) unformat (i, "nevents %d", &nevents);
14368 elog_init (em, nevents);
14369 vl_api_set_elog_main (em);
14370 vl_api_set_elog_trace_api_messages (1);
14371 errmsg ("Event logger initialized with %u events", nevents);
14373 errmsg ("Use the vpp event loger...");
14379 elog_enable (vat_main_t * vam)
14381 #if VPP_API_TEST_BUILTIN == 0
14382 elog_main_t *em = &vam->elog_main;
14384 elog_enable_disable (em, 1 /* enable */ );
14385 vl_api_set_elog_trace_api_messages (1);
14386 errmsg ("Event logger enabled...");
14388 errmsg ("Use the vpp event loger...");
14394 elog_disable (vat_main_t * vam)
14396 #if VPP_API_TEST_BUILTIN == 0
14397 elog_main_t *em = &vam->elog_main;
14399 elog_enable_disable (em, 0 /* enable */ );
14400 vl_api_set_elog_trace_api_messages (1);
14401 errmsg ("Event logger disabled...");
14403 errmsg ("Use the vpp event loger...");
14409 statseg (vat_main_t * vam)
14411 ssvm_private_t *ssvmp = &vam->stat_segment;
14412 ssvm_shared_header_t *shared_header = ssvmp->sh;
14413 vlib_counter_t **counters;
14414 u64 thread0_index1_packets;
14415 u64 thread0_index1_bytes;
14416 f64 vector_rate, input_rate;
14419 uword *counter_vector_by_name;
14420 if (vam->stat_segment_lockp == 0)
14422 errmsg ("Stat segment not mapped...");
14426 /* look up "/if/rx for sw_if_index 1 as a test */
14428 clib_spinlock_lock (vam->stat_segment_lockp);
14430 counter_vector_by_name = (uword *) shared_header->opaque[1];
14432 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14435 clib_spinlock_unlock (vam->stat_segment_lockp);
14436 errmsg ("/if/tx not found?");
14440 /* Fish per-thread vector of combined counters from shared memory */
14441 counters = (vlib_counter_t **) p[0];
14443 if (vec_len (counters[0]) < 2)
14445 clib_spinlock_unlock (vam->stat_segment_lockp);
14446 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14450 /* Read thread 0 sw_if_index 1 counter */
14451 thread0_index1_packets = counters[0][1].packets;
14452 thread0_index1_bytes = counters[0][1].bytes;
14454 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14457 clib_spinlock_unlock (vam->stat_segment_lockp);
14458 errmsg ("vector_rate not found?");
14462 vector_rate = *(f64 *) (p[0]);
14463 p = hash_get_mem (counter_vector_by_name, "input_rate");
14466 clib_spinlock_unlock (vam->stat_segment_lockp);
14467 errmsg ("input_rate not found?");
14470 input_rate = *(f64 *) (p[0]);
14472 clib_spinlock_unlock (vam->stat_segment_lockp);
14474 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14475 vector_rate, input_rate);
14476 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14477 thread0_index1_packets, thread0_index1_bytes);
14483 cmd_cmp (void *a1, void *a2)
14488 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14492 help (vat_main_t * vam)
14497 unformat_input_t *i = vam->input;
14500 if (unformat (i, "%s", &name))
14504 vec_add1 (name, 0);
14506 hs = hash_get_mem (vam->help_by_name, name);
14508 print (vam->ofp, "usage: %s %s", name, hs[0]);
14510 print (vam->ofp, "No such msg / command '%s'", name);
14515 print (vam->ofp, "Help is available for the following:");
14518 hash_foreach_pair (p, vam->function_by_name,
14520 vec_add1 (cmds, (u8 *)(p->key));
14524 vec_sort_with_function (cmds, cmd_cmp);
14526 for (j = 0; j < vec_len (cmds); j++)
14527 print (vam->ofp, "%s", cmds[j]);
14534 set (vat_main_t * vam)
14536 u8 *name = 0, *value = 0;
14537 unformat_input_t *i = vam->input;
14539 if (unformat (i, "%s", &name))
14541 /* The input buffer is a vector, not a string. */
14542 value = vec_dup (i->buffer);
14543 vec_delete (value, i->index, 0);
14544 /* Almost certainly has a trailing newline */
14545 if (value[vec_len (value) - 1] == '\n')
14546 value[vec_len (value) - 1] = 0;
14547 /* Make sure it's a proper string, one way or the other */
14548 vec_add1 (value, 0);
14549 (void) clib_macro_set_value (&vam->macro_main,
14550 (char *) name, (char *) value);
14553 errmsg ("usage: set <name> <value>");
14561 unset (vat_main_t * vam)
14565 if (unformat (vam->input, "%s", &name))
14566 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14567 errmsg ("unset: %s wasn't set", name);
14580 macro_sort_cmp (void *a1, void *a2)
14582 macro_sort_t *s1 = a1;
14583 macro_sort_t *s2 = a2;
14585 return strcmp ((char *) (s1->name), (char *) (s2->name));
14589 dump_macro_table (vat_main_t * vam)
14591 macro_sort_t *sort_me = 0, *sm;
14596 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14598 vec_add2 (sort_me, sm, 1);
14599 sm->name = (u8 *)(p->key);
14600 sm->value = (u8 *) (p->value[0]);
14604 vec_sort_with_function (sort_me, macro_sort_cmp);
14606 if (vec_len (sort_me))
14607 print (vam->ofp, "%-15s%s", "Name", "Value");
14609 print (vam->ofp, "The macro table is empty...");
14611 for (i = 0; i < vec_len (sort_me); i++)
14612 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14617 dump_node_table (vat_main_t * vam)
14620 vlib_node_t *node, *next_node;
14622 if (vec_len (vam->graph_nodes) == 0)
14624 print (vam->ofp, "Node table empty, issue get_node_graph...");
14628 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14630 node = vam->graph_nodes[0][i];
14631 print (vam->ofp, "[%d] %s", i, node->name);
14632 for (j = 0; j < vec_len (node->next_nodes); j++)
14634 if (node->next_nodes[j] != ~0)
14636 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14637 print (vam->ofp, " [%d] %s", j, next_node->name);
14645 value_sort_cmp (void *a1, void *a2)
14647 name_sort_t *n1 = a1;
14648 name_sort_t *n2 = a2;
14650 if (n1->value < n2->value)
14652 if (n1->value > n2->value)
14659 dump_msg_api_table (vat_main_t * vam)
14661 api_main_t *am = vlibapi_get_main ();
14662 name_sort_t *nses = 0, *ns;
14667 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14669 vec_add2 (nses, ns, 1);
14670 ns->name = (u8 *)(hp->key);
14671 ns->value = (u32) hp->value[0];
14675 vec_sort_with_function (nses, value_sort_cmp);
14677 for (i = 0; i < vec_len (nses); i++)
14678 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14684 get_msg_id (vat_main_t * vam)
14689 if (unformat (vam->input, "%s", &name_and_crc))
14691 message_index = vl_msg_api_get_msg_index (name_and_crc);
14692 if (message_index == ~0)
14694 print (vam->ofp, " '%s' not found", name_and_crc);
14697 print (vam->ofp, " '%s' has message index %d",
14698 name_and_crc, message_index);
14701 errmsg ("name_and_crc required...");
14706 search_node_table (vat_main_t * vam)
14708 unformat_input_t *line_input = vam->input;
14711 vlib_node_t *node, *next_node;
14714 if (vam->graph_node_index_by_name == 0)
14716 print (vam->ofp, "Node table empty, issue get_node_graph...");
14720 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14722 if (unformat (line_input, "%s", &node_to_find))
14724 vec_add1 (node_to_find, 0);
14725 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14728 print (vam->ofp, "%s not found...", node_to_find);
14731 node = vam->graph_nodes[0][p[0]];
14732 print (vam->ofp, "[%d] %s", p[0], node->name);
14733 for (j = 0; j < vec_len (node->next_nodes); j++)
14735 if (node->next_nodes[j] != ~0)
14737 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14738 print (vam->ofp, " [%d] %s", j, next_node->name);
14745 clib_warning ("parse error '%U'", format_unformat_error,
14751 vec_free (node_to_find);
14760 script (vat_main_t * vam)
14762 #if (VPP_API_TEST_BUILTIN==0)
14764 char *save_current_file;
14765 unformat_input_t save_input;
14766 jmp_buf save_jump_buf;
14767 u32 save_line_number;
14769 FILE *new_fp, *save_ifp;
14771 if (unformat (vam->input, "%s", &s))
14773 new_fp = fopen ((char *) s, "r");
14776 errmsg ("Couldn't open script file %s", s);
14783 errmsg ("Missing script name");
14787 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
14788 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
14789 save_ifp = vam->ifp;
14790 save_line_number = vam->input_line_number;
14791 save_current_file = (char *) vam->current_file;
14793 vam->input_line_number = 0;
14795 vam->current_file = s;
14798 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
14799 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
14800 vam->ifp = save_ifp;
14801 vam->input_line_number = save_line_number;
14802 vam->current_file = (u8 *) save_current_file;
14807 clib_warning ("use the exec command...");
14813 echo (vat_main_t * vam)
14815 print (vam->ofp, "%v", vam->input->buffer);
14819 /* List of API message constructors, CLI names map to api_xxx */
14820 #define foreach_vpe_api_msg \
14821 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
14822 _(sw_interface_dump,"") \
14823 _(sw_interface_set_flags, \
14824 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
14825 _(sw_interface_add_del_address, \
14826 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
14827 _(sw_interface_set_rx_mode, \
14828 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
14829 _(sw_interface_set_rx_placement, \
14830 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
14831 _(sw_interface_rx_placement_dump, \
14832 "[<intfc> | sw_if_index <id>]") \
14833 _(sw_interface_set_table, \
14834 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
14835 _(sw_interface_set_mpls_enable, \
14836 "<intfc> | sw_if_index [disable | dis]") \
14837 _(sw_interface_set_vpath, \
14838 "<intfc> | sw_if_index <id> enable | disable") \
14839 _(sw_interface_set_vxlan_bypass, \
14840 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
14841 _(sw_interface_set_l2_xconnect, \
14842 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14843 "enable | disable") \
14844 _(sw_interface_set_l2_bridge, \
14845 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
14846 "[shg <split-horizon-group>] [bvi]\n" \
14847 "enable | disable") \
14848 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
14849 _(bridge_domain_add_del, \
14850 "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") \
14851 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
14853 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
14854 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
14855 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
14857 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14859 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
14861 "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]") \
14863 "<vpp-if-name> | sw_if_index <id>") \
14864 _(sw_interface_tap_v2_dump, "") \
14865 _(virtio_pci_create_v2, \
14866 "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]") \
14867 _(virtio_pci_delete, \
14868 "<vpp-if-name> | sw_if_index <id>") \
14869 _(sw_interface_virtio_pci_dump, "") \
14871 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
14872 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14875 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
14876 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
14877 "[id <if-id>] [gso]") \
14879 "<vpp-if-name> | sw_if_index <id>") \
14880 _(bond_add_member, \
14881 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
14882 _(bond_detach_member, \
14883 "sw_if_index <n>") \
14884 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
14885 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
14886 _(sw_member_interface_dump, \
14887 "<vpp-if-name> | sw_if_index <id>") \
14888 _(ip_table_add_del, \
14889 "table <n> [ipv6] [add | del]\n") \
14890 _(ip_route_add_del, \
14891 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
14892 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
14893 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
14894 "[multipath] [count <n>] [del]") \
14895 _(ip_mroute_add_del, \
14896 "<src> <grp>/<mask> [table-id <n>]\n" \
14897 "[<intfc> | sw_if_index <id>] [local] [del]") \
14898 _(mpls_table_add_del, \
14899 "table <n> [add | del]\n") \
14900 _(mpls_route_add_del, \
14901 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
14902 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
14903 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
14904 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
14905 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
14906 "[count <n>] [del]") \
14907 _(mpls_ip_bind_unbind, \
14908 "<label> <addr/len>") \
14909 _(mpls_tunnel_add_del, \
14910 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
14911 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
14912 "[l2-only] [out-label <n>]") \
14913 _(sr_mpls_policy_add, \
14914 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
14915 _(sr_mpls_policy_del, \
14917 _(bier_table_add_del, \
14918 "<label> <sub-domain> <set> <bsl> [del]") \
14919 _(bier_route_add_del, \
14920 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
14921 "[<intfc> | sw_if_index <id>]" \
14922 "[weight <n>] [del] [multipath]") \
14923 _(sw_interface_set_unnumbered, \
14924 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
14925 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
14926 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
14927 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
14928 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
14929 "[outer_vlan_id_any][inner_vlan_id_any]") \
14930 _(ip_table_replace_begin, "table <n> [ipv6]") \
14931 _(ip_table_flush, "table <n> [ipv6]") \
14932 _(ip_table_replace_end, "table <n> [ipv6]") \
14933 _(set_ip_flow_hash, \
14934 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
14935 _(sw_interface_ip6_enable_disable, \
14936 "<intfc> | sw_if_index <id> enable | disable") \
14937 _(l2_patch_add_del, \
14938 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
14939 "enable | disable") \
14940 _(sr_localsid_add_del, \
14941 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
14942 "fib-table <num> (end.psp) sw_if_index <num>") \
14943 _(classify_add_del_table, \
14944 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
14945 " [del] [del-chain] mask <mask-value>\n" \
14946 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
14947 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
14948 _(classify_add_del_session, \
14949 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
14950 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
14951 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
14952 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
14953 _(classify_set_interface_ip_table, \
14954 "<intfc> | sw_if_index <nn> table <nn>") \
14955 _(classify_set_interface_l2_tables, \
14956 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14957 " [other-table <nn>]") \
14958 _(get_node_index, "node <node-name") \
14959 _(add_node_next, "node <node-name> next <next-node-name>") \
14960 _(vxlan_offload_rx, \
14961 "hw { <interface name> | hw_if_index <nn>} " \
14962 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
14963 _(vxlan_add_del_tunnel, \
14964 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
14965 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
14966 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
14967 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14968 _(l2_fib_clear_table, "") \
14969 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
14970 _(l2_interface_vlan_tag_rewrite, \
14971 "<intfc> | sw_if_index <nn> \n" \
14972 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
14973 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
14974 _(create_vhost_user_if, \
14975 "socket <filename> [server] [renumber <dev_instance>] " \
14976 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14977 "[mac <mac_address>] [packed]") \
14978 _(modify_vhost_user_if, \
14979 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14980 "[server] [renumber <dev_instance>] [gso] [packed]") \
14981 _(create_vhost_user_if_v2, \
14982 "socket <filename> [server] [renumber <dev_instance>] " \
14983 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
14984 "[mac <mac_address>] [packed] [event-idx]") \
14985 _(modify_vhost_user_if_v2, \
14986 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14987 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
14988 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
14989 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
14990 _(show_version, "") \
14991 _(show_threads, "") \
14992 _(vxlan_gpe_add_del_tunnel, \
14993 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
14994 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
14995 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
14996 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
14997 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14998 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
14999 _(interface_name_renumber, \
15000 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15001 _(input_acl_set_interface, \
15002 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15003 " [l2-table <nn>] [del]") \
15004 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
15005 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15006 _(ip_dump, "ipv4 | ipv6") \
15007 _(ipsec_spd_add_del, "spd_id <n> [del]") \
15008 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15010 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15011 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15012 " integ_alg <alg> integ_key <hex>") \
15013 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
15014 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15015 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15016 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
15017 _(ipsec_sa_dump, "[sa_id <n>]") \
15018 _(delete_loopback,"sw_if_index <nn>") \
15019 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15020 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
15021 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
15022 _(want_interface_events, "enable|disable") \
15023 _(get_first_msg_id, "client <name>") \
15024 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15025 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
15026 "fib-id <nn> [ip4][ip6][default]") \
15027 _(get_node_graph, " ") \
15028 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
15029 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15030 _(ioam_disable, "") \
15031 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
15032 _(af_packet_delete, "name <host interface name>") \
15033 _(af_packet_dump, "") \
15034 _(policer_add_del, "name <policer name> <params> [del]") \
15035 _(policer_dump, "[name <policer name>]") \
15036 _(policer_classify_set_interface, \
15037 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15038 " [l2-table <nn>] [del]") \
15039 _(policer_classify_dump, "type [ip4|ip6|l2]") \
15040 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
15041 _(mpls_table_dump, "") \
15042 _(mpls_route_dump, "table-id <ID>") \
15043 _(classify_table_ids, "") \
15044 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15045 _(classify_table_info, "table_id <nn>") \
15046 _(classify_session_dump, "table_id <nn>") \
15047 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15048 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15049 "[template_interval <nn>] [udp_checksum]") \
15050 _(ipfix_exporter_dump, "") \
15051 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15052 _(ipfix_classify_stream_dump, "") \
15053 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
15054 _(ipfix_classify_table_dump, "") \
15055 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
15056 _(sw_interface_span_dump, "[l2]") \
15057 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15058 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
15059 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
15060 _(pg_enable_disable, "[stream <id>] disable") \
15061 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
15062 _(ip_source_and_port_range_check_add_del, \
15063 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15064 _(ip_source_and_port_range_check_interface_add_del, \
15065 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
15066 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15067 _(delete_subif,"<intfc> | sw_if_index <nn>") \
15068 _(l2_interface_pbb_tag_rewrite, \
15069 "<intfc> | sw_if_index <nn> \n" \
15070 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15071 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15072 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
15073 _(flow_classify_set_interface, \
15074 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
15075 _(flow_classify_dump, "type [ip4|ip6]") \
15076 _(ip_table_dump, "") \
15077 _(ip_route_dump, "table-id [ip4|ip6]") \
15078 _(ip_mtable_dump, "") \
15079 _(ip_mroute_dump, "table-id [ip4|ip6]") \
15080 _(feature_enable_disable, "arc_name <arc_name> " \
15081 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
15082 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
15083 "[enable | disable] ") \
15084 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
15086 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
15087 "mac <mac-address> [del]") \
15088 _(l2_xconnect_dump, "") \
15089 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
15090 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
15091 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
15092 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
15093 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
15094 _(sock_init_shm, "size <nnn>") \
15095 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
15096 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
15097 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15098 _(session_rules_dump, "") \
15099 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15100 _(output_acl_set_interface, \
15101 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15102 " [l2-table <nn>] [del]") \
15103 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15105 /* List of command functions, CLI names map directly to functions */
15106 #define foreach_cli_function \
15107 _(comment, "usage: comment <ignore-rest-of-line>") \
15108 _(dump_interface_table, "usage: dump_interface_table") \
15109 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15110 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15111 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15112 _(dump_macro_table, "usage: dump_macro_table ") \
15113 _(dump_node_table, "usage: dump_node_table") \
15114 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15115 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15116 _(elog_disable, "usage: elog_disable") \
15117 _(elog_enable, "usage: elog_enable") \
15118 _(elog_save, "usage: elog_save <filename>") \
15119 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15120 _(echo, "usage: echo <message>") \
15121 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15122 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15123 _(help, "usage: help") \
15124 _(q, "usage: quit") \
15125 _(quit, "usage: quit") \
15126 _(search_node_table, "usage: search_node_table <name>...") \
15127 _(set, "usage: set <variable-name> <value>") \
15128 _(script, "usage: script <file-name>") \
15129 _(statseg, "usage: statseg") \
15130 _(unset, "usage: unset <variable-name>")
15133 static void vl_api_##n##_t_handler_uni \
15134 (vl_api_##n##_t * mp) \
15136 vat_main_t * vam = &vat_main; \
15137 if (vam->json_output) { \
15138 vl_api_##n##_t_handler_json(mp); \
15140 vl_api_##n##_t_handler(mp); \
15143 foreach_vpe_api_reply_msg;
15144 #if VPP_API_TEST_BUILTIN == 0
15145 foreach_standalone_reply_msg;
15150 vat_api_hookup (vat_main_t * vam)
15153 vl_msg_api_set_handlers(VL_API_##N, #n, \
15154 vl_api_##n##_t_handler_uni, \
15156 vl_api_##n##_t_endian, \
15157 vl_api_##n##_t_print, \
15158 sizeof(vl_api_##n##_t), 1);
15159 foreach_vpe_api_reply_msg;
15160 #if VPP_API_TEST_BUILTIN == 0
15161 foreach_standalone_reply_msg;
15165 #if (VPP_API_TEST_BUILTIN==0)
15166 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15168 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15170 vam->function_by_name = hash_create_string (0, sizeof (uword));
15172 vam->help_by_name = hash_create_string (0, sizeof (uword));
15175 /* API messages we can send */
15176 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15177 foreach_vpe_api_msg;
15181 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15182 foreach_vpe_api_msg;
15185 /* CLI functions */
15186 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15187 foreach_cli_function;
15191 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15192 foreach_cli_function;
15196 #if VPP_API_TEST_BUILTIN
15197 static clib_error_t *
15198 vat_api_hookup_shim (vlib_main_t * vm)
15200 vat_api_hookup (&vat_main);
15204 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15208 * fd.io coding-style-patch-verification: ON
15211 * eval: (c-set-style "gnu")