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/gre/gre.h>
32 #include <vnet/vxlan-gpe/vxlan_gpe.h>
33 #include <vnet/udp/udp_local.h>
35 #include <vpp/api/vpe_msg_enum.h>
36 #include <vnet/l2/l2_classify.h>
37 #include <vnet/l2/l2_vtr.h>
38 #include <vnet/classify/in_out_acl.h>
39 #include <vnet/classify/policer_classify.h>
40 #include <vnet/classify/flow_classify.h>
41 #include <vnet/mpls/mpls.h>
42 #include <vnet/ipsec/ipsec.h>
44 #include <vnet/ip/ip6_hop_by_hop.h>
45 #include <vnet/ip/ip_source_and_port_range_check.h>
46 #include <vnet/policer/xlate.h>
47 #include <vnet/span/span.h>
48 #include <vnet/policer/policer.h>
49 #include <vnet/policer/police.h>
50 #include <vnet/mfib/mfib_types.h>
51 #include <vnet/bonding/node.h>
52 #include <vnet/qos/qos_types.h>
53 #include <vnet/ethernet/ethernet_types_api.h>
54 #include <vnet/ip/ip_types_api.h>
55 #include "vat/json_format.h"
56 #include <vnet/ip/ip_types_api.h>
57 #include <vnet/ethernet/ethernet_types_api.h>
62 #define vl_typedefs /* define message structures */
63 #include <vpp/api/vpe_all_api_h.h>
66 /* declare message handlers for each api */
68 #define vl_endianfun /* define message structures */
69 #include <vpp/api/vpe_all_api_h.h>
72 /* instantiate all the print functions we know about */
73 #if VPP_API_TEST_BUILTIN == 0
74 #define vl_print(handle, ...)
76 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
79 #include <vpp/api/vpe_all_api_h.h>
82 #define __plugin_msg_base 0
83 #include <vlibapi/vat_helper_macros.h>
85 #include <vnet/format_fns.h>
87 void vl_api_set_elog_main (elog_main_t * m);
88 int vl_api_set_elog_trace_api_messages (int enable);
90 #if VPP_API_TEST_BUILTIN == 0
100 vat_socket_connect (vat_main_t * vam)
103 api_main_t *am = vlibapi_get_main ();
104 vam->socket_client_main = &socket_client_main;
105 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
107 0 /* default socket rx, tx buffer */ )))
110 /* vpp expects the client index in network order */
111 vam->my_client_index = htonl (socket_client_main.client_index);
112 am->my_client_index = vam->my_client_index;
115 #else /* vpp built-in case, we don't do sockets... */
117 vat_socket_connect (vat_main_t * vam)
123 vl_socket_client_read (int wait)
129 vl_socket_client_write ()
135 vl_socket_client_msg_alloc (int nbytes)
143 vat_time_now (vat_main_t * vam)
145 #if VPP_API_TEST_BUILTIN
146 return vlib_time_now (vam->vlib_main);
148 return clib_time_now (&vam->clib_time);
153 errmsg (char *fmt, ...)
155 vat_main_t *vam = &vat_main;
160 s = va_format (0, fmt, &va);
165 #if VPP_API_TEST_BUILTIN
166 vlib_cli_output (vam->vlib_main, (char *) s);
169 if (vam->ifp != stdin)
170 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
171 vam->input_line_number);
173 fformat (vam->ofp, "%s\n", (char *) s);
181 #if VPP_API_TEST_BUILTIN == 0
183 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
185 vat_main_t *vam = va_arg (*args, vat_main_t *);
186 u32 *result = va_arg (*args, u32 *);
190 if (!unformat (input, "%s", &if_name))
193 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
201 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
206 /* Parse an IP4 address %d.%d.%d.%d. */
208 unformat_ip4_address (unformat_input_t * input, va_list * args)
210 u8 *result = va_arg (*args, u8 *);
213 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
216 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
228 unformat_ethernet_address (unformat_input_t * input, va_list * args)
230 u8 *result = va_arg (*args, u8 *);
233 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
234 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
238 for (i = 0; i < 6; i++)
239 if (a[i] >= (1 << 8))
242 for (i = 0; i < 6; i++)
248 /* Returns ethernet type as an int in host byte order. */
250 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
253 u16 *result = va_arg (*args, u16 *);
257 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
259 if (type >= (1 << 16))
267 /* Parse an IP46 address. */
269 unformat_ip46_address (unformat_input_t * input, va_list * args)
271 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
272 ip46_type_t type = va_arg (*args, ip46_type_t);
273 if ((type != IP46_TYPE_IP6) &&
274 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
276 ip46_address_mask_ip4 (ip46);
279 else if ((type != IP46_TYPE_IP4) &&
280 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
287 /* Parse an IP6 address. */
289 unformat_ip6_address (unformat_input_t * input, va_list * args)
291 ip6_address_t *result = va_arg (*args, ip6_address_t *);
293 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
294 uword c, n_colon, double_colon_index;
296 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
297 double_colon_index = ARRAY_LEN (hex_quads);
298 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
301 if (c >= '0' && c <= '9')
303 else if (c >= 'a' && c <= 'f')
304 hex_digit = c + 10 - 'a';
305 else if (c >= 'A' && c <= 'F')
306 hex_digit = c + 10 - 'A';
307 else if (c == ':' && n_colon < 2)
311 unformat_put_input (input);
315 /* Too many hex quads. */
316 if (n_hex_quads >= ARRAY_LEN (hex_quads))
321 hex_quad = (hex_quad << 4) | hex_digit;
323 /* Hex quad must fit in 16 bits. */
324 if (n_hex_digits >= 4)
331 /* Save position of :: */
334 /* More than one :: ? */
335 if (double_colon_index < ARRAY_LEN (hex_quads))
337 double_colon_index = n_hex_quads;
340 if (n_colon > 0 && n_hex_digits > 0)
342 hex_quads[n_hex_quads++] = hex_quad;
348 if (n_hex_digits > 0)
349 hex_quads[n_hex_quads++] = hex_quad;
354 /* Expand :: to appropriate number of zero hex quads. */
355 if (double_colon_index < ARRAY_LEN (hex_quads))
357 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
359 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
360 hex_quads[n_zero + i] = hex_quads[i];
362 for (i = 0; i < n_zero; i++)
363 hex_quads[double_colon_index + i] = 0;
365 n_hex_quads = ARRAY_LEN (hex_quads);
368 /* Too few hex quads given. */
369 if (n_hex_quads < ARRAY_LEN (hex_quads))
372 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
373 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
380 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
382 u32 *r = va_arg (*args, u32 *);
385 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
386 foreach_ipsec_policy_action
394 format_ipsec_crypto_alg (u8 * s, va_list * args)
396 u32 i = va_arg (*args, u32);
401 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
402 foreach_ipsec_crypto_alg
405 return format (s, "unknown");
407 return format (s, "%s", t);
411 format_ipsec_integ_alg (u8 * s, va_list * args)
413 u32 i = va_arg (*args, u32);
418 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
419 foreach_ipsec_integ_alg
422 return format (s, "unknown");
424 return format (s, "%s", t);
427 #else /* VPP_API_TEST_BUILTIN == 1 */
429 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
431 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
432 vnet_main_t *vnm = vnet_get_main ();
433 u32 *result = va_arg (*args, u32 *);
435 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
439 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
441 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
442 vnet_main_t *vnm = vnet_get_main ();
443 u32 *result = va_arg (*args, u32 *);
445 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
448 #endif /* VPP_API_TEST_BUILTIN */
451 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
453 u32 *r = va_arg (*args, u32 *);
456 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
457 foreach_ipsec_crypto_alg
465 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
467 u32 *r = va_arg (*args, u32 *);
470 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
471 foreach_ipsec_integ_alg
479 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
481 u8 *r = va_arg (*args, u8 *);
483 if (unformat (input, "kbps"))
484 *r = SSE2_QOS_RATE_KBPS;
485 else if (unformat (input, "pps"))
486 *r = SSE2_QOS_RATE_PPS;
493 unformat_policer_round_type (unformat_input_t * input, va_list * args)
495 u8 *r = va_arg (*args, u8 *);
497 if (unformat (input, "closest"))
498 *r = SSE2_QOS_ROUND_TO_CLOSEST;
499 else if (unformat (input, "up"))
500 *r = SSE2_QOS_ROUND_TO_UP;
501 else if (unformat (input, "down"))
502 *r = SSE2_QOS_ROUND_TO_DOWN;
509 unformat_policer_type (unformat_input_t * input, va_list * args)
511 u8 *r = va_arg (*args, u8 *);
513 if (unformat (input, "1r2c"))
514 *r = SSE2_QOS_POLICER_TYPE_1R2C;
515 else if (unformat (input, "1r3c"))
516 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
517 else if (unformat (input, "2r3c-2698"))
518 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
519 else if (unformat (input, "2r3c-4115"))
520 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
521 else if (unformat (input, "2r3c-mef5cf1"))
522 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
529 unformat_dscp (unformat_input_t * input, va_list * va)
531 u8 *r = va_arg (*va, u8 *);
534 #define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
543 unformat_policer_action_type (unformat_input_t * input, va_list * va)
545 sse2_qos_pol_action_params_st *a
546 = va_arg (*va, sse2_qos_pol_action_params_st *);
548 if (unformat (input, "drop"))
549 a->action_type = SSE2_QOS_ACTION_DROP;
550 else if (unformat (input, "transmit"))
551 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
552 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
553 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
560 unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
562 u32 *r = va_arg (*va, u32 *);
565 if (unformat (input, "ip4"))
566 tid = POLICER_CLASSIFY_TABLE_IP4;
567 else if (unformat (input, "ip6"))
568 tid = POLICER_CLASSIFY_TABLE_IP6;
569 else if (unformat (input, "l2"))
570 tid = POLICER_CLASSIFY_TABLE_L2;
579 unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
581 u32 *r = va_arg (*va, u32 *);
584 if (unformat (input, "ip4"))
585 tid = FLOW_CLASSIFY_TABLE_IP4;
586 else if (unformat (input, "ip6"))
587 tid = FLOW_CLASSIFY_TABLE_IP6;
595 #if (VPP_API_TEST_BUILTIN==0)
597 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
598 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
599 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
600 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
603 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
605 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
606 mfib_itf_attribute_t attr;
609 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
611 if (unformat (input, mfib_itf_flag_long_names[attr]))
612 *iflags |= (1 << attr);
614 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
616 if (unformat (input, mfib_itf_flag_names[attr]))
617 *iflags |= (1 << attr);
620 return (old == *iflags ? 0 : 1);
624 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
626 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
627 mfib_entry_attribute_t attr;
630 FOR_EACH_MFIB_ATTRIBUTE (attr)
632 if (unformat (input, mfib_flag_long_names[attr]))
633 *eflags |= (1 << attr);
635 FOR_EACH_MFIB_ATTRIBUTE (attr)
637 if (unformat (input, mfib_flag_names[attr]))
638 *eflags |= (1 << attr);
641 return (old == *eflags ? 0 : 1);
645 format_ip4_address (u8 * s, va_list * args)
647 u8 *a = va_arg (*args, u8 *);
648 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
652 format_ip6_address (u8 * s, va_list * args)
654 ip6_address_t *a = va_arg (*args, ip6_address_t *);
655 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
657 i_max_n_zero = ARRAY_LEN (a->as_u16);
659 i_first_zero = i_max_n_zero;
661 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
663 u32 is_zero = a->as_u16[i] == 0;
664 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
670 if ((!is_zero && n_zeros > max_n_zeros)
671 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
673 i_max_n_zero = i_first_zero;
674 max_n_zeros = n_zeros;
675 i_first_zero = ARRAY_LEN (a->as_u16);
680 last_double_colon = 0;
681 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
683 if (i == i_max_n_zero && max_n_zeros > 1)
685 s = format (s, "::");
686 i += max_n_zeros - 1;
687 last_double_colon = 1;
691 s = format (s, "%s%x",
692 (last_double_colon || i == 0) ? "" : ":",
693 clib_net_to_host_u16 (a->as_u16[i]));
694 last_double_colon = 0;
701 /* Format an IP46 address. */
703 format_ip46_address (u8 * s, va_list * args)
705 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
706 ip46_type_t type = va_arg (*args, ip46_type_t);
712 is_ip4 = ip46_address_is_ip4 (ip46);
723 format (s, "%U", format_ip4_address, &ip46->ip4) :
724 format (s, "%U", format_ip6_address, &ip46->ip6);
728 format_ethernet_address (u8 * s, va_list * args)
730 u8 *a = va_arg (*args, u8 *);
732 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
733 a[0], a[1], a[2], a[3], a[4], a[5]);
738 increment_v4_address (vl_api_ip4_address_t * i)
740 ip4_address_t *a = (ip4_address_t *) i;
743 v = ntohl (a->as_u32) + 1;
744 a->as_u32 = ntohl (v);
748 increment_v6_address (vl_api_ip6_address_t * i)
750 ip6_address_t *a = (ip6_address_t *) i;
753 v0 = clib_net_to_host_u64 (a->as_u64[0]);
754 v1 = clib_net_to_host_u64 (a->as_u64[1]);
759 a->as_u64[0] = clib_net_to_host_u64 (v0);
760 a->as_u64[1] = clib_net_to_host_u64 (v1);
764 increment_address (vl_api_address_t * a)
766 if (a->af == ADDRESS_IP4)
767 increment_v4_address (&a->un.ip4);
768 else if (a->af == ADDRESS_IP6)
769 increment_v6_address (&a->un.ip6);
773 set_ip4_address (vl_api_address_t * a, u32 v)
775 if (a->af == ADDRESS_IP4)
777 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
783 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
786 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
788 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
789 sizeof (ip6_address_t));
793 increment_mac_address (u8 * mac)
795 u64 tmp = *((u64 *) mac);
796 tmp = clib_net_to_host_u64 (tmp);
797 tmp += 1 << 16; /* skip unused (least significant) octets */
798 tmp = clib_host_to_net_u64 (tmp);
800 clib_memcpy (mac, &tmp, 6);
804 vat_json_object_add_address (vat_json_node_t * node,
805 const char *str, const vl_api_address_t * addr)
807 if (ADDRESS_IP6 == addr->af)
811 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
812 vat_json_object_add_ip6 (node, str, ip6);
818 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
819 vat_json_object_add_ip4 (node, str, ip4);
824 vat_json_object_add_prefix (vat_json_node_t * node,
825 const vl_api_prefix_t * prefix)
827 vat_json_object_add_uint (node, "len", prefix->len);
828 vat_json_object_add_address (node, "address", &prefix->address);
831 static void vl_api_create_loopback_reply_t_handler
832 (vl_api_create_loopback_reply_t * mp)
834 vat_main_t *vam = &vat_main;
835 i32 retval = ntohl (mp->retval);
837 vam->retval = retval;
838 vam->regenerate_interface_table = 1;
839 vam->sw_if_index = ntohl (mp->sw_if_index);
840 vam->result_ready = 1;
843 static void vl_api_create_loopback_reply_t_handler_json
844 (vl_api_create_loopback_reply_t * mp)
846 vat_main_t *vam = &vat_main;
847 vat_json_node_t node;
849 vat_json_init_object (&node);
850 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
851 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
853 vat_json_print (vam->ofp, &node);
854 vat_json_free (&node);
855 vam->retval = ntohl (mp->retval);
856 vam->result_ready = 1;
859 static void vl_api_create_loopback_instance_reply_t_handler
860 (vl_api_create_loopback_instance_reply_t * mp)
862 vat_main_t *vam = &vat_main;
863 i32 retval = ntohl (mp->retval);
865 vam->retval = retval;
866 vam->regenerate_interface_table = 1;
867 vam->sw_if_index = ntohl (mp->sw_if_index);
868 vam->result_ready = 1;
871 static void vl_api_create_loopback_instance_reply_t_handler_json
872 (vl_api_create_loopback_instance_reply_t * mp)
874 vat_main_t *vam = &vat_main;
875 vat_json_node_t node;
877 vat_json_init_object (&node);
878 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
879 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
881 vat_json_print (vam->ofp, &node);
882 vat_json_free (&node);
883 vam->retval = ntohl (mp->retval);
884 vam->result_ready = 1;
887 static void vl_api_af_packet_create_reply_t_handler
888 (vl_api_af_packet_create_reply_t * mp)
890 vat_main_t *vam = &vat_main;
891 i32 retval = ntohl (mp->retval);
893 vam->retval = retval;
894 vam->regenerate_interface_table = 1;
895 vam->sw_if_index = ntohl (mp->sw_if_index);
896 vam->result_ready = 1;
899 static void vl_api_af_packet_create_reply_t_handler_json
900 (vl_api_af_packet_create_reply_t * mp)
902 vat_main_t *vam = &vat_main;
903 vat_json_node_t node;
905 vat_json_init_object (&node);
906 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
907 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
909 vat_json_print (vam->ofp, &node);
910 vat_json_free (&node);
912 vam->retval = ntohl (mp->retval);
913 vam->result_ready = 1;
916 static void vl_api_create_vlan_subif_reply_t_handler
917 (vl_api_create_vlan_subif_reply_t * mp)
919 vat_main_t *vam = &vat_main;
920 i32 retval = ntohl (mp->retval);
922 vam->retval = retval;
923 vam->regenerate_interface_table = 1;
924 vam->sw_if_index = ntohl (mp->sw_if_index);
925 vam->result_ready = 1;
928 static void vl_api_create_vlan_subif_reply_t_handler_json
929 (vl_api_create_vlan_subif_reply_t * mp)
931 vat_main_t *vam = &vat_main;
932 vat_json_node_t node;
934 vat_json_init_object (&node);
935 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
936 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
938 vat_json_print (vam->ofp, &node);
939 vat_json_free (&node);
941 vam->retval = ntohl (mp->retval);
942 vam->result_ready = 1;
945 static void vl_api_create_subif_reply_t_handler
946 (vl_api_create_subif_reply_t * mp)
948 vat_main_t *vam = &vat_main;
949 i32 retval = ntohl (mp->retval);
951 vam->retval = retval;
952 vam->regenerate_interface_table = 1;
953 vam->sw_if_index = ntohl (mp->sw_if_index);
954 vam->result_ready = 1;
957 static void vl_api_create_subif_reply_t_handler_json
958 (vl_api_create_subif_reply_t * mp)
960 vat_main_t *vam = &vat_main;
961 vat_json_node_t node;
963 vat_json_init_object (&node);
964 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
965 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
967 vat_json_print (vam->ofp, &node);
968 vat_json_free (&node);
970 vam->retval = ntohl (mp->retval);
971 vam->result_ready = 1;
974 static void vl_api_interface_name_renumber_reply_t_handler
975 (vl_api_interface_name_renumber_reply_t * mp)
977 vat_main_t *vam = &vat_main;
978 i32 retval = ntohl (mp->retval);
980 vam->retval = retval;
981 vam->regenerate_interface_table = 1;
982 vam->result_ready = 1;
985 static void vl_api_interface_name_renumber_reply_t_handler_json
986 (vl_api_interface_name_renumber_reply_t * mp)
988 vat_main_t *vam = &vat_main;
989 vat_json_node_t node;
991 vat_json_init_object (&node);
992 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
994 vat_json_print (vam->ofp, &node);
995 vat_json_free (&node);
997 vam->retval = ntohl (mp->retval);
998 vam->result_ready = 1;
1002 * Special-case: build the interface table, maintain
1003 * the next loopback sw_if_index vbl.
1005 static void vl_api_sw_interface_details_t_handler
1006 (vl_api_sw_interface_details_t * mp)
1008 vat_main_t *vam = &vat_main;
1009 u8 *s = format (0, "%s%c", mp->interface_name, 0);
1011 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1012 ntohl (mp->sw_if_index));
1014 /* In sub interface case, fill the sub interface table entry */
1015 if (mp->sw_if_index != mp->sup_sw_if_index)
1017 sw_interface_subif_t *sub = NULL;
1019 vec_add2 (vam->sw_if_subif_table, sub, 1);
1021 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1022 strncpy ((char *) sub->interface_name, (char *) s,
1023 vec_len (sub->interface_name));
1024 sub->sw_if_index = ntohl (mp->sw_if_index);
1025 sub->sub_id = ntohl (mp->sub_id);
1027 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1029 sub->sub_number_of_tags = mp->sub_number_of_tags;
1030 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1031 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
1033 /* vlan tag rewrite */
1034 sub->vtr_op = ntohl (mp->vtr_op);
1035 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1036 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1037 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1041 static void vl_api_sw_interface_details_t_handler_json
1042 (vl_api_sw_interface_details_t * mp)
1044 vat_main_t *vam = &vat_main;
1045 vat_json_node_t *node = NULL;
1047 if (VAT_JSON_ARRAY != vam->json_tree.type)
1049 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1050 vat_json_init_array (&vam->json_tree);
1052 node = vat_json_array_add (&vam->json_tree);
1054 vat_json_init_object (node);
1055 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1056 vat_json_object_add_uint (node, "sup_sw_if_index",
1057 ntohl (mp->sup_sw_if_index));
1058 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1059 sizeof (mp->l2_address));
1060 vat_json_object_add_string_copy (node, "interface_name",
1061 mp->interface_name);
1062 vat_json_object_add_string_copy (node, "interface_dev_type",
1063 mp->interface_dev_type);
1064 vat_json_object_add_uint (node, "flags", mp->flags);
1065 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1066 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1067 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1068 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1069 vat_json_object_add_uint (node, "sub_number_of_tags",
1070 mp->sub_number_of_tags);
1071 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1072 ntohs (mp->sub_outer_vlan_id));
1073 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1074 ntohs (mp->sub_inner_vlan_id));
1075 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1076 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1077 vat_json_object_add_uint (node, "vtr_push_dot1q",
1078 ntohl (mp->vtr_push_dot1q));
1079 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1080 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1081 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1083 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1085 format_ethernet_address,
1087 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1089 format_ethernet_address,
1091 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1092 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1096 #if VPP_API_TEST_BUILTIN == 0
1097 static void vl_api_sw_interface_event_t_handler
1098 (vl_api_sw_interface_event_t * mp)
1100 vat_main_t *vam = &vat_main;
1101 if (vam->interface_event_display)
1102 errmsg ("interface flags: sw_if_index %d %s %s",
1103 ntohl (mp->sw_if_index),
1104 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1105 "admin-up" : "admin-down",
1106 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1107 "link-up" : "link-down");
1111 __clib_unused static void
1112 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1114 /* JSON output not supported */
1118 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1120 vat_main_t *vam = &vat_main;
1121 i32 retval = ntohl (mp->retval);
1123 vam->retval = retval;
1124 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1125 vam->result_ready = 1;
1129 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1131 vat_main_t *vam = &vat_main;
1132 vat_json_node_t node;
1136 vat_json_init_object (&node);
1137 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1138 vat_json_object_add_uint (&node, "reply_in_shmem",
1139 ntohl (mp->reply_in_shmem));
1140 /* Toss the shared-memory original... */
1141 oldheap = vl_msg_push_heap ();
1143 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1146 vl_msg_pop_heap (oldheap);
1148 vat_json_print (vam->ofp, &node);
1149 vat_json_free (&node);
1151 vam->retval = ntohl (mp->retval);
1152 vam->result_ready = 1;
1156 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1158 vat_main_t *vam = &vat_main;
1159 i32 retval = ntohl (mp->retval);
1161 vec_reset_length (vam->cmd_reply);
1163 vam->retval = retval;
1165 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1166 vam->result_ready = 1;
1170 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1172 vat_main_t *vam = &vat_main;
1173 vat_json_node_t node;
1174 u8 *reply = 0; /* reply vector */
1176 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1177 vec_reset_length (vam->cmd_reply);
1179 vat_json_init_object (&node);
1180 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1181 vat_json_object_add_string_copy (&node, "reply", reply);
1183 vat_json_print (vam->ofp, &node);
1184 vat_json_free (&node);
1187 vam->retval = ntohl (mp->retval);
1188 vam->result_ready = 1;
1191 static void vl_api_classify_add_del_table_reply_t_handler
1192 (vl_api_classify_add_del_table_reply_t * mp)
1194 vat_main_t *vam = &vat_main;
1195 i32 retval = ntohl (mp->retval);
1196 if (vam->async_mode)
1198 vam->async_errors += (retval < 0);
1202 vam->retval = retval;
1204 ((mp->new_table_index != 0xFFFFFFFF) ||
1205 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1206 (mp->match_n_vectors != 0xFFFFFFFF)))
1208 * Note: this is just barely thread-safe, depends on
1209 * the main thread spinning waiting for an answer...
1211 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1212 ntohl (mp->new_table_index),
1213 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1214 vam->result_ready = 1;
1218 static void vl_api_classify_add_del_table_reply_t_handler_json
1219 (vl_api_classify_add_del_table_reply_t * mp)
1221 vat_main_t *vam = &vat_main;
1222 vat_json_node_t node;
1224 vat_json_init_object (&node);
1225 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1226 vat_json_object_add_uint (&node, "new_table_index",
1227 ntohl (mp->new_table_index));
1228 vat_json_object_add_uint (&node, "skip_n_vectors",
1229 ntohl (mp->skip_n_vectors));
1230 vat_json_object_add_uint (&node, "match_n_vectors",
1231 ntohl (mp->match_n_vectors));
1233 vat_json_print (vam->ofp, &node);
1234 vat_json_free (&node);
1236 vam->retval = ntohl (mp->retval);
1237 vam->result_ready = 1;
1240 static void vl_api_get_node_index_reply_t_handler
1241 (vl_api_get_node_index_reply_t * mp)
1243 vat_main_t *vam = &vat_main;
1244 i32 retval = ntohl (mp->retval);
1245 if (vam->async_mode)
1247 vam->async_errors += (retval < 0);
1251 vam->retval = retval;
1253 errmsg ("node index %d", ntohl (mp->node_index));
1254 vam->result_ready = 1;
1258 static void vl_api_get_node_index_reply_t_handler_json
1259 (vl_api_get_node_index_reply_t * mp)
1261 vat_main_t *vam = &vat_main;
1262 vat_json_node_t node;
1264 vat_json_init_object (&node);
1265 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1266 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1268 vat_json_print (vam->ofp, &node);
1269 vat_json_free (&node);
1271 vam->retval = ntohl (mp->retval);
1272 vam->result_ready = 1;
1275 static void vl_api_get_next_index_reply_t_handler
1276 (vl_api_get_next_index_reply_t * mp)
1278 vat_main_t *vam = &vat_main;
1279 i32 retval = ntohl (mp->retval);
1280 if (vam->async_mode)
1282 vam->async_errors += (retval < 0);
1286 vam->retval = retval;
1288 errmsg ("next node index %d", ntohl (mp->next_index));
1289 vam->result_ready = 1;
1293 static void vl_api_get_next_index_reply_t_handler_json
1294 (vl_api_get_next_index_reply_t * mp)
1296 vat_main_t *vam = &vat_main;
1297 vat_json_node_t node;
1299 vat_json_init_object (&node);
1300 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1301 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1303 vat_json_print (vam->ofp, &node);
1304 vat_json_free (&node);
1306 vam->retval = ntohl (mp->retval);
1307 vam->result_ready = 1;
1310 static void vl_api_add_node_next_reply_t_handler
1311 (vl_api_add_node_next_reply_t * mp)
1313 vat_main_t *vam = &vat_main;
1314 i32 retval = ntohl (mp->retval);
1315 if (vam->async_mode)
1317 vam->async_errors += (retval < 0);
1321 vam->retval = retval;
1323 errmsg ("next index %d", ntohl (mp->next_index));
1324 vam->result_ready = 1;
1328 static void vl_api_add_node_next_reply_t_handler_json
1329 (vl_api_add_node_next_reply_t * mp)
1331 vat_main_t *vam = &vat_main;
1332 vat_json_node_t node;
1334 vat_json_init_object (&node);
1335 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1336 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1338 vat_json_print (vam->ofp, &node);
1339 vat_json_free (&node);
1341 vam->retval = ntohl (mp->retval);
1342 vam->result_ready = 1;
1345 static void vl_api_show_version_reply_t_handler
1346 (vl_api_show_version_reply_t * mp)
1348 vat_main_t *vam = &vat_main;
1349 i32 retval = ntohl (mp->retval);
1353 errmsg (" program: %s", mp->program);
1354 errmsg (" version: %s", mp->version);
1355 errmsg (" build date: %s", mp->build_date);
1356 errmsg ("build directory: %s", mp->build_directory);
1358 vam->retval = retval;
1359 vam->result_ready = 1;
1362 static void vl_api_show_version_reply_t_handler_json
1363 (vl_api_show_version_reply_t * mp)
1365 vat_main_t *vam = &vat_main;
1366 vat_json_node_t node;
1368 vat_json_init_object (&node);
1369 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1370 vat_json_object_add_string_copy (&node, "program", mp->program);
1371 vat_json_object_add_string_copy (&node, "version", mp->version);
1372 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1373 vat_json_object_add_string_copy (&node, "build_directory",
1374 mp->build_directory);
1376 vat_json_print (vam->ofp, &node);
1377 vat_json_free (&node);
1379 vam->retval = ntohl (mp->retval);
1380 vam->result_ready = 1;
1383 static void vl_api_show_threads_reply_t_handler
1384 (vl_api_show_threads_reply_t * mp)
1386 vat_main_t *vam = &vat_main;
1387 i32 retval = ntohl (mp->retval);
1391 count = ntohl (mp->count);
1393 for (i = 0; i < count; i++)
1395 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1396 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1397 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1398 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1399 ntohl (mp->thread_data[i].cpu_socket));
1401 vam->retval = retval;
1402 vam->result_ready = 1;
1405 static void vl_api_show_threads_reply_t_handler_json
1406 (vl_api_show_threads_reply_t * mp)
1408 vat_main_t *vam = &vat_main;
1409 vat_json_node_t node;
1410 vl_api_thread_data_t *td;
1411 i32 retval = ntohl (mp->retval);
1415 count = ntohl (mp->count);
1417 vat_json_init_object (&node);
1418 vat_json_object_add_int (&node, "retval", retval);
1419 vat_json_object_add_uint (&node, "count", count);
1421 for (i = 0; i < count; i++)
1423 td = &mp->thread_data[i];
1424 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1425 vat_json_object_add_string_copy (&node, "name", td->name);
1426 vat_json_object_add_string_copy (&node, "type", td->type);
1427 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1428 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1429 vat_json_object_add_int (&node, "core", ntohl (td->id));
1430 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1433 vat_json_print (vam->ofp, &node);
1434 vat_json_free (&node);
1436 vam->retval = retval;
1437 vam->result_ready = 1;
1441 api_show_threads (vat_main_t * vam)
1443 vl_api_show_threads_t *mp;
1447 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1448 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1450 M (SHOW_THREADS, mp);
1458 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1460 u32 n_macs = ntohl (mp->n_macs);
1461 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1462 ntohl (mp->pid), mp->client_index, n_macs);
1464 for (i = 0; i < n_macs; i++)
1466 vl_api_mac_entry_t *mac = &mp->mac[i];
1467 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1468 i + 1, ntohl (mac->sw_if_index),
1469 format_ethernet_address, mac->mac_addr, mac->action);
1476 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1478 /* JSON output not supported */
1481 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1482 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1485 * Special-case: build the bridge domain table, maintain
1486 * the next bd id vbl.
1488 static void vl_api_bridge_domain_details_t_handler
1489 (vl_api_bridge_domain_details_t * mp)
1491 vat_main_t *vam = &vat_main;
1492 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1495 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1496 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1498 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1499 ntohl (mp->bd_id), mp->learn, mp->forward,
1500 mp->flood, ntohl (mp->bvi_sw_if_index),
1501 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1505 vl_api_bridge_domain_sw_if_t *sw_ifs;
1506 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1509 sw_ifs = mp->sw_if_details;
1510 for (i = 0; i < n_sw_ifs; i++)
1516 sw_if_index = ntohl (sw_ifs->sw_if_index);
1519 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1521 if ((u32) p->value[0] == sw_if_index)
1523 sw_if_name = (u8 *)(p->key);
1528 print (vam->ofp, "%7d %3d %s", sw_if_index,
1529 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1530 "sw_if_index not found!");
1537 static void vl_api_bridge_domain_details_t_handler_json
1538 (vl_api_bridge_domain_details_t * mp)
1540 vat_main_t *vam = &vat_main;
1541 vat_json_node_t *node, *array = NULL;
1542 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1544 if (VAT_JSON_ARRAY != vam->json_tree.type)
1546 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1547 vat_json_init_array (&vam->json_tree);
1549 node = vat_json_array_add (&vam->json_tree);
1551 vat_json_init_object (node);
1552 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1553 vat_json_object_add_uint (node, "flood", mp->flood);
1554 vat_json_object_add_uint (node, "forward", mp->forward);
1555 vat_json_object_add_uint (node, "learn", mp->learn);
1556 vat_json_object_add_uint (node, "bvi_sw_if_index",
1557 ntohl (mp->bvi_sw_if_index));
1558 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1559 array = vat_json_object_add (node, "sw_if");
1560 vat_json_init_array (array);
1566 vl_api_bridge_domain_sw_if_t *sw_ifs;
1569 sw_ifs = mp->sw_if_details;
1570 for (i = 0; i < n_sw_ifs; i++)
1572 node = vat_json_array_add (array);
1573 vat_json_init_object (node);
1574 vat_json_object_add_uint (node, "sw_if_index",
1575 ntohl (sw_ifs->sw_if_index));
1576 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1582 static void vl_api_control_ping_reply_t_handler
1583 (vl_api_control_ping_reply_t * mp)
1585 vat_main_t *vam = &vat_main;
1586 i32 retval = ntohl (mp->retval);
1587 if (vam->async_mode)
1589 vam->async_errors += (retval < 0);
1593 vam->retval = retval;
1594 vam->result_ready = 1;
1596 if (vam->socket_client_main)
1597 vam->socket_client_main->control_pings_outstanding--;
1600 static void vl_api_control_ping_reply_t_handler_json
1601 (vl_api_control_ping_reply_t * mp)
1603 vat_main_t *vam = &vat_main;
1604 i32 retval = ntohl (mp->retval);
1606 if (VAT_JSON_NONE != vam->json_tree.type)
1608 vat_json_print (vam->ofp, &vam->json_tree);
1609 vat_json_free (&vam->json_tree);
1610 vam->json_tree.type = VAT_JSON_NONE;
1615 vat_json_init_array (&vam->json_tree);
1616 vat_json_print (vam->ofp, &vam->json_tree);
1617 vam->json_tree.type = VAT_JSON_NONE;
1620 vam->retval = retval;
1621 vam->result_ready = 1;
1625 vl_api_bridge_domain_set_mac_age_reply_t_handler
1626 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1628 vat_main_t *vam = &vat_main;
1629 i32 retval = ntohl (mp->retval);
1630 if (vam->async_mode)
1632 vam->async_errors += (retval < 0);
1636 vam->retval = retval;
1637 vam->result_ready = 1;
1641 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1642 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1644 vat_main_t *vam = &vat_main;
1645 vat_json_node_t node;
1647 vat_json_init_object (&node);
1648 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1650 vat_json_print (vam->ofp, &node);
1651 vat_json_free (&node);
1653 vam->retval = ntohl (mp->retval);
1654 vam->result_ready = 1;
1658 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1660 vat_main_t *vam = &vat_main;
1661 i32 retval = ntohl (mp->retval);
1662 if (vam->async_mode)
1664 vam->async_errors += (retval < 0);
1668 vam->retval = retval;
1669 vam->result_ready = 1;
1673 static void vl_api_l2_flags_reply_t_handler_json
1674 (vl_api_l2_flags_reply_t * mp)
1676 vat_main_t *vam = &vat_main;
1677 vat_json_node_t node;
1679 vat_json_init_object (&node);
1680 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1681 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1682 ntohl (mp->resulting_feature_bitmap));
1684 vat_json_print (vam->ofp, &node);
1685 vat_json_free (&node);
1687 vam->retval = ntohl (mp->retval);
1688 vam->result_ready = 1;
1691 static void vl_api_bridge_flags_reply_t_handler
1692 (vl_api_bridge_flags_reply_t * mp)
1694 vat_main_t *vam = &vat_main;
1695 i32 retval = ntohl (mp->retval);
1696 if (vam->async_mode)
1698 vam->async_errors += (retval < 0);
1702 vam->retval = retval;
1703 vam->result_ready = 1;
1707 static void vl_api_bridge_flags_reply_t_handler_json
1708 (vl_api_bridge_flags_reply_t * mp)
1710 vat_main_t *vam = &vat_main;
1711 vat_json_node_t node;
1713 vat_json_init_object (&node);
1714 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1715 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1716 ntohl (mp->resulting_feature_bitmap));
1718 vat_json_print (vam->ofp, &node);
1719 vat_json_free (&node);
1721 vam->retval = ntohl (mp->retval);
1722 vam->result_ready = 1;
1726 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1728 vat_main_t *vam = &vat_main;
1729 i32 retval = ntohl (mp->retval);
1730 if (vam->async_mode)
1732 vam->async_errors += (retval < 0);
1736 vam->retval = retval;
1737 vam->sw_if_index = ntohl (mp->sw_if_index);
1738 vam->result_ready = 1;
1743 static void vl_api_tap_create_v2_reply_t_handler_json
1744 (vl_api_tap_create_v2_reply_t * mp)
1746 vat_main_t *vam = &vat_main;
1747 vat_json_node_t node;
1749 vat_json_init_object (&node);
1750 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1751 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1753 vat_json_print (vam->ofp, &node);
1754 vat_json_free (&node);
1756 vam->retval = ntohl (mp->retval);
1757 vam->result_ready = 1;
1762 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1764 vat_main_t *vam = &vat_main;
1765 i32 retval = ntohl (mp->retval);
1766 if (vam->async_mode)
1768 vam->async_errors += (retval < 0);
1772 vam->retval = retval;
1773 vam->result_ready = 1;
1777 static void vl_api_tap_delete_v2_reply_t_handler_json
1778 (vl_api_tap_delete_v2_reply_t * mp)
1780 vat_main_t *vam = &vat_main;
1781 vat_json_node_t node;
1783 vat_json_init_object (&node);
1784 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1786 vat_json_print (vam->ofp, &node);
1787 vat_json_free (&node);
1789 vam->retval = ntohl (mp->retval);
1790 vam->result_ready = 1;
1794 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1797 vat_main_t *vam = &vat_main;
1798 i32 retval = ntohl (mp->retval);
1799 if (vam->async_mode)
1801 vam->async_errors += (retval < 0);
1805 vam->retval = retval;
1806 vam->sw_if_index = ntohl (mp->sw_if_index);
1807 vam->result_ready = 1;
1811 static void vl_api_virtio_pci_create_reply_t_handler_json
1812 (vl_api_virtio_pci_create_reply_t * mp)
1814 vat_main_t *vam = &vat_main;
1815 vat_json_node_t node;
1817 vat_json_init_object (&node);
1818 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1819 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1821 vat_json_print (vam->ofp, &node);
1822 vat_json_free (&node);
1824 vam->retval = ntohl (mp->retval);
1825 vam->result_ready = 1;
1830 vl_api_virtio_pci_create_v2_reply_t_handler
1831 (vl_api_virtio_pci_create_v2_reply_t * mp)
1833 vat_main_t *vam = &vat_main;
1834 i32 retval = ntohl (mp->retval);
1835 if (vam->async_mode)
1837 vam->async_errors += (retval < 0);
1841 vam->retval = retval;
1842 vam->sw_if_index = ntohl (mp->sw_if_index);
1843 vam->result_ready = 1;
1847 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1848 (vl_api_virtio_pci_create_v2_reply_t * mp)
1850 vat_main_t *vam = &vat_main;
1851 vat_json_node_t node;
1853 vat_json_init_object (&node);
1854 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1855 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1857 vat_json_print (vam->ofp, &node);
1858 vat_json_free (&node);
1860 vam->retval = ntohl (mp->retval);
1861 vam->result_ready = 1;
1865 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1868 vat_main_t *vam = &vat_main;
1869 i32 retval = ntohl (mp->retval);
1870 if (vam->async_mode)
1872 vam->async_errors += (retval < 0);
1876 vam->retval = retval;
1877 vam->result_ready = 1;
1881 static void vl_api_virtio_pci_delete_reply_t_handler_json
1882 (vl_api_virtio_pci_delete_reply_t * mp)
1884 vat_main_t *vam = &vat_main;
1885 vat_json_node_t node;
1887 vat_json_init_object (&node);
1888 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1890 vat_json_print (vam->ofp, &node);
1891 vat_json_free (&node);
1893 vam->retval = ntohl (mp->retval);
1894 vam->result_ready = 1;
1898 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1900 vat_main_t *vam = &vat_main;
1901 i32 retval = ntohl (mp->retval);
1903 if (vam->async_mode)
1905 vam->async_errors += (retval < 0);
1909 vam->retval = retval;
1910 vam->sw_if_index = ntohl (mp->sw_if_index);
1911 vam->result_ready = 1;
1915 static void vl_api_bond_create_reply_t_handler_json
1916 (vl_api_bond_create_reply_t * mp)
1918 vat_main_t *vam = &vat_main;
1919 vat_json_node_t node;
1921 vat_json_init_object (&node);
1922 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1923 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1925 vat_json_print (vam->ofp, &node);
1926 vat_json_free (&node);
1928 vam->retval = ntohl (mp->retval);
1929 vam->result_ready = 1;
1933 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1935 vat_main_t *vam = &vat_main;
1936 i32 retval = ntohl (mp->retval);
1938 if (vam->async_mode)
1940 vam->async_errors += (retval < 0);
1944 vam->retval = retval;
1945 vam->sw_if_index = ntohl (mp->sw_if_index);
1946 vam->result_ready = 1;
1950 static void vl_api_bond_create2_reply_t_handler_json
1951 (vl_api_bond_create2_reply_t * mp)
1953 vat_main_t *vam = &vat_main;
1954 vat_json_node_t node;
1956 vat_json_init_object (&node);
1957 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1958 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1960 vat_json_print (vam->ofp, &node);
1961 vat_json_free (&node);
1963 vam->retval = ntohl (mp->retval);
1964 vam->result_ready = 1;
1968 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1970 vat_main_t *vam = &vat_main;
1971 i32 retval = ntohl (mp->retval);
1973 if (vam->async_mode)
1975 vam->async_errors += (retval < 0);
1979 vam->retval = retval;
1980 vam->result_ready = 1;
1984 static void vl_api_bond_delete_reply_t_handler_json
1985 (vl_api_bond_delete_reply_t * mp)
1987 vat_main_t *vam = &vat_main;
1988 vat_json_node_t node;
1990 vat_json_init_object (&node);
1991 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1993 vat_json_print (vam->ofp, &node);
1994 vat_json_free (&node);
1996 vam->retval = ntohl (mp->retval);
1997 vam->result_ready = 1;
2001 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
2003 vat_main_t *vam = &vat_main;
2004 i32 retval = ntohl (mp->retval);
2006 if (vam->async_mode)
2008 vam->async_errors += (retval < 0);
2012 vam->retval = retval;
2013 vam->result_ready = 1;
2017 static void vl_api_bond_add_member_reply_t_handler_json
2018 (vl_api_bond_add_member_reply_t * mp)
2020 vat_main_t *vam = &vat_main;
2021 vat_json_node_t node;
2023 vat_json_init_object (&node);
2024 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2026 vat_json_print (vam->ofp, &node);
2027 vat_json_free (&node);
2029 vam->retval = ntohl (mp->retval);
2030 vam->result_ready = 1;
2034 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
2037 vat_main_t *vam = &vat_main;
2038 i32 retval = ntohl (mp->retval);
2040 if (vam->async_mode)
2042 vam->async_errors += (retval < 0);
2046 vam->retval = retval;
2047 vam->result_ready = 1;
2051 static void vl_api_bond_detach_member_reply_t_handler_json
2052 (vl_api_bond_detach_member_reply_t * mp)
2054 vat_main_t *vam = &vat_main;
2055 vat_json_node_t node;
2057 vat_json_init_object (&node);
2058 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2060 vat_json_print (vam->ofp, &node);
2061 vat_json_free (&node);
2063 vam->retval = ntohl (mp->retval);
2064 vam->result_ready = 1;
2068 api_sw_interface_set_bond_weight (vat_main_t * vam)
2070 unformat_input_t *i = vam->input;
2071 vl_api_sw_interface_set_bond_weight_t *mp;
2072 u32 sw_if_index = ~0;
2074 u8 weight_enter = 0;
2077 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2079 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2081 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2083 else if (unformat (i, "weight %u", &weight))
2089 if (sw_if_index == ~0)
2091 errmsg ("missing interface name or sw_if_index");
2094 if (weight_enter == 0)
2096 errmsg ("missing valid weight");
2100 /* Construct the API message */
2101 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2102 mp->sw_if_index = ntohl (sw_if_index);
2103 mp->weight = ntohl (weight);
2110 static void vl_api_sw_bond_interface_details_t_handler
2111 (vl_api_sw_bond_interface_details_t * mp)
2113 vat_main_t *vam = &vat_main;
2116 "%-16s %-12d %-12U %-13U %-14u %-14u",
2117 mp->interface_name, ntohl (mp->sw_if_index),
2118 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2119 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2122 static void vl_api_sw_bond_interface_details_t_handler_json
2123 (vl_api_sw_bond_interface_details_t * mp)
2125 vat_main_t *vam = &vat_main;
2126 vat_json_node_t *node = NULL;
2128 if (VAT_JSON_ARRAY != vam->json_tree.type)
2130 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2131 vat_json_init_array (&vam->json_tree);
2133 node = vat_json_array_add (&vam->json_tree);
2135 vat_json_init_object (node);
2136 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2137 vat_json_object_add_string_copy (node, "interface_name",
2138 mp->interface_name);
2139 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2140 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2141 vat_json_object_add_uint (node, "active_members",
2142 ntohl (mp->active_members));
2143 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2147 api_sw_bond_interface_dump (vat_main_t * vam)
2149 unformat_input_t *i = vam->input;
2150 vl_api_sw_bond_interface_dump_t *mp;
2151 vl_api_control_ping_t *mp_ping;
2153 u32 sw_if_index = ~0;
2155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2157 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2159 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2166 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2167 "interface name", "sw_if_index", "mode", "load balance",
2168 "active members", "members");
2170 /* Get list of bond interfaces */
2171 M (SW_BOND_INTERFACE_DUMP, mp);
2172 mp->sw_if_index = ntohl (sw_if_index);
2175 /* Use a control ping for synchronization */
2176 MPING (CONTROL_PING, mp_ping);
2183 static void vl_api_sw_member_interface_details_t_handler
2184 (vl_api_sw_member_interface_details_t * mp)
2186 vat_main_t *vam = &vat_main;
2189 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2190 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2191 ntohl (mp->weight), mp->is_local_numa);
2194 static void vl_api_sw_member_interface_details_t_handler_json
2195 (vl_api_sw_member_interface_details_t * mp)
2197 vat_main_t *vam = &vat_main;
2198 vat_json_node_t *node = NULL;
2200 if (VAT_JSON_ARRAY != vam->json_tree.type)
2202 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2203 vat_json_init_array (&vam->json_tree);
2205 node = vat_json_array_add (&vam->json_tree);
2207 vat_json_init_object (node);
2208 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2209 vat_json_object_add_string_copy (node, "interface_name",
2210 mp->interface_name);
2211 vat_json_object_add_uint (node, "passive", mp->is_passive);
2212 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2213 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2214 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2218 api_sw_member_interface_dump (vat_main_t * vam)
2220 unformat_input_t *i = vam->input;
2221 vl_api_sw_member_interface_dump_t *mp;
2222 vl_api_control_ping_t *mp_ping;
2223 u32 sw_if_index = ~0;
2224 u8 sw_if_index_set = 0;
2227 /* Parse args required to build the message */
2228 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2230 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2231 sw_if_index_set = 1;
2232 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2233 sw_if_index_set = 1;
2238 if (sw_if_index_set == 0)
2240 errmsg ("missing vpp interface name. ");
2245 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2246 "member interface name", "sw_if_index", "passive", "long_timeout",
2247 "weight", "local numa");
2249 /* Get list of bond interfaces */
2250 M (SW_MEMBER_INTERFACE_DUMP, mp);
2251 mp->sw_if_index = ntohl (sw_if_index);
2254 /* Use a control ping for synchronization */
2255 MPING (CONTROL_PING, mp_ping);
2262 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2263 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2265 vat_main_t *vam = &vat_main;
2266 i32 retval = ntohl (mp->retval);
2267 if (vam->async_mode)
2269 vam->async_errors += (retval < 0);
2273 vam->retval = retval;
2274 vam->sw_if_index = ntohl (mp->sw_if_index);
2275 vam->result_ready = 1;
2277 vam->regenerate_interface_table = 1;
2280 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2281 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2283 vat_main_t *vam = &vat_main;
2284 vat_json_node_t node;
2286 vat_json_init_object (&node);
2287 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2288 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2289 ntohl (mp->sw_if_index));
2291 vat_json_print (vam->ofp, &node);
2292 vat_json_free (&node);
2294 vam->retval = ntohl (mp->retval);
2295 vam->result_ready = 1;
2298 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2299 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2301 vat_main_t *vam = &vat_main;
2302 i32 retval = ntohl (mp->retval);
2303 if (vam->async_mode)
2305 vam->async_errors += (retval < 0);
2309 vam->retval = retval;
2310 vam->sw_if_index = ntohl (mp->sw_if_index);
2311 vam->result_ready = 1;
2313 vam->regenerate_interface_table = 1;
2316 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2317 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2319 vat_main_t *vam = &vat_main;
2320 vat_json_node_t node;
2322 vat_json_init_object (&node);
2323 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2324 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2326 vat_json_print (vam->ofp, &node);
2327 vat_json_free (&node);
2329 vam->retval = ntohl (mp->retval);
2330 vam->result_ready = 1;
2333 static void vl_api_vxlan_offload_rx_reply_t_handler
2334 (vl_api_vxlan_offload_rx_reply_t * mp)
2336 vat_main_t *vam = &vat_main;
2337 i32 retval = ntohl (mp->retval);
2338 if (vam->async_mode)
2340 vam->async_errors += (retval < 0);
2344 vam->retval = retval;
2345 vam->result_ready = 1;
2349 static void vl_api_vxlan_offload_rx_reply_t_handler_json
2350 (vl_api_vxlan_offload_rx_reply_t * mp)
2352 vat_main_t *vam = &vat_main;
2353 vat_json_node_t node;
2355 vat_json_init_object (&node);
2356 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2358 vat_json_print (vam->ofp, &node);
2359 vat_json_free (&node);
2361 vam->retval = ntohl (mp->retval);
2362 vam->result_ready = 1;
2365 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2366 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2368 vat_main_t *vam = &vat_main;
2369 i32 retval = ntohl (mp->retval);
2370 if (vam->async_mode)
2372 vam->async_errors += (retval < 0);
2376 vam->retval = retval;
2377 vam->sw_if_index = ntohl (mp->sw_if_index);
2378 vam->result_ready = 1;
2380 vam->regenerate_interface_table = 1;
2383 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2384 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2386 vat_main_t *vam = &vat_main;
2387 vat_json_node_t node;
2389 vat_json_init_object (&node);
2390 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2391 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2393 vat_json_print (vam->ofp, &node);
2394 vat_json_free (&node);
2396 vam->retval = ntohl (mp->retval);
2397 vam->result_ready = 1;
2400 static void vl_api_gre_tunnel_add_del_reply_t_handler
2401 (vl_api_gre_tunnel_add_del_reply_t * mp)
2403 vat_main_t *vam = &vat_main;
2404 i32 retval = ntohl (mp->retval);
2405 if (vam->async_mode)
2407 vam->async_errors += (retval < 0);
2411 vam->retval = retval;
2412 vam->sw_if_index = ntohl (mp->sw_if_index);
2413 vam->result_ready = 1;
2417 static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2418 (vl_api_gre_tunnel_add_del_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_reply_t_handler
2435 (vl_api_create_vhost_user_if_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_reply_t_handler_json
2453 (vl_api_create_vhost_user_if_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 _(delete_vhost_user_if_reply) \
3288 _(want_l2_macs_events_reply) \
3289 _(input_acl_set_interface_reply) \
3290 _(ipsec_spd_add_del_reply) \
3291 _(ipsec_interface_add_del_spd_reply) \
3292 _(ipsec_spd_entry_add_del_reply) \
3293 _(ipsec_sad_entry_add_del_reply) \
3294 _(ipsec_tunnel_if_add_del_reply) \
3295 _(ipsec_tunnel_if_set_sa_reply) \
3296 _(delete_loopback_reply) \
3297 _(bd_ip_mac_add_del_reply) \
3298 _(bd_ip_mac_flush_reply) \
3299 _(want_interface_events_reply) \
3300 _(cop_interface_enable_disable_reply) \
3301 _(cop_whitelist_enable_disable_reply) \
3302 _(sw_interface_clear_stats_reply) \
3303 _(ioam_enable_reply) \
3304 _(ioam_disable_reply) \
3305 _(af_packet_delete_reply) \
3306 _(policer_classify_set_interface_reply) \
3307 _(set_ipfix_exporter_reply) \
3308 _(set_ipfix_classify_stream_reply) \
3309 _(ipfix_classify_table_add_del_reply) \
3310 _(flow_classify_set_interface_reply) \
3311 _(sw_interface_span_enable_disable_reply) \
3312 _(pg_capture_reply) \
3313 _(pg_enable_disable_reply) \
3314 _(pg_interface_enable_disable_coalesce_reply) \
3315 _(ip_source_and_port_range_check_add_del_reply) \
3316 _(ip_source_and_port_range_check_interface_add_del_reply)\
3317 _(delete_subif_reply) \
3318 _(l2_interface_pbb_tag_rewrite_reply) \
3320 _(feature_enable_disable_reply) \
3321 _(feature_gso_enable_disable_reply) \
3322 _(sw_interface_tag_add_del_reply) \
3323 _(sw_interface_add_del_mac_address_reply) \
3324 _(hw_interface_set_mtu_reply) \
3325 _(p2p_ethernet_add_reply) \
3326 _(p2p_ethernet_del_reply) \
3327 _(tcp_configure_src_addresses_reply) \
3328 _(session_rule_add_del_reply) \
3329 _(ip_container_proxy_add_del_reply) \
3330 _(output_acl_set_interface_reply) \
3331 _(qos_record_enable_disable_reply) \
3335 static void vl_api_##n##_t_handler \
3336 (vl_api_##n##_t * mp) \
3338 vat_main_t * vam = &vat_main; \
3339 i32 retval = ntohl(mp->retval); \
3340 if (vam->async_mode) { \
3341 vam->async_errors += (retval < 0); \
3343 vam->retval = retval; \
3344 vam->result_ready = 1; \
3347 foreach_standard_reply_retval_handler;
3351 static void vl_api_##n##_t_handler_json \
3352 (vl_api_##n##_t * mp) \
3354 vat_main_t * vam = &vat_main; \
3355 vat_json_node_t node; \
3356 vat_json_init_object(&node); \
3357 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3358 vat_json_print(vam->ofp, &node); \
3359 vam->retval = ntohl(mp->retval); \
3360 vam->result_ready = 1; \
3362 foreach_standard_reply_retval_handler;
3366 * Table of message reply handlers, must include boilerplate handlers
3370 #define foreach_vpe_api_reply_msg \
3371 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3372 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3373 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3374 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3375 _(CONTROL_PING_REPLY, control_ping_reply) \
3376 _(CLI_REPLY, cli_reply) \
3377 _(CLI_INBAND_REPLY, cli_inband_reply) \
3378 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3379 sw_interface_add_del_address_reply) \
3380 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3381 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3382 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3383 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3384 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3385 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3386 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3387 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3388 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3389 sw_interface_set_l2_xconnect_reply) \
3390 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3391 sw_interface_set_l2_bridge_reply) \
3392 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3393 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3394 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3395 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3396 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3397 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3398 _(L2_FLAGS_REPLY, l2_flags_reply) \
3399 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3400 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3401 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3402 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3403 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3404 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3405 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3406 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3407 _(BOND_CREATE_REPLY, bond_create_reply) \
3408 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3409 _(BOND_DELETE_REPLY, bond_delete_reply) \
3410 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3411 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3412 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3413 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3414 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3415 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3416 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3417 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3418 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3419 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3420 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3421 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3422 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3423 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3424 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3425 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3426 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3427 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3428 sw_interface_set_unnumbered_reply) \
3429 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3430 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3431 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3432 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3433 sw_interface_ip6_enable_disable_reply) \
3434 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3435 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3436 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3437 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3438 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3439 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3440 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3441 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3442 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3443 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3444 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3445 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3446 classify_set_interface_ip_table_reply) \
3447 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3448 classify_set_interface_l2_tables_reply) \
3449 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3450 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3451 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3452 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3453 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3454 _(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
3455 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
3456 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3457 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3458 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3459 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3460 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3461 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3462 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3463 _(SHOW_VERSION_REPLY, show_version_reply) \
3464 _(SHOW_THREADS_REPLY, show_threads_reply) \
3465 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3466 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3467 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3468 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3469 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3470 _(L2_MACS_EVENT, l2_macs_event) \
3471 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3472 _(IP_ADDRESS_DETAILS, ip_address_details) \
3473 _(IP_DETAILS, ip_details) \
3474 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3475 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3476 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3477 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3478 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3479 _(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
3480 _(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
3481 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3482 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3483 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3484 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3485 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3486 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3487 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3488 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3489 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3490 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3491 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3492 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3493 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3494 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3495 _(AF_PACKET_DETAILS, af_packet_details) \
3496 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3497 _(POLICER_DETAILS, policer_details) \
3498 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3499 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3500 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3501 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3502 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3503 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3504 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3505 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3506 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3507 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3508 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3509 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3510 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3511 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3512 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3513 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3514 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3515 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3516 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3517 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3518 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3519 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3520 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3521 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3522 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3523 ip_source_and_port_range_check_add_del_reply) \
3524 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3525 ip_source_and_port_range_check_interface_add_del_reply) \
3526 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3527 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3528 _(SET_PUNT_REPLY, set_punt_reply) \
3529 _(IP_TABLE_DETAILS, ip_table_details) \
3530 _(IP_ROUTE_DETAILS, ip_route_details) \
3531 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3532 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3533 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3534 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3535 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3536 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3537 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3538 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3539 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3540 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3541 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3542 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3543 _(SESSION_RULES_DETAILS, session_rules_details) \
3544 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3545 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3546 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3547 _(FLOW_ADD_REPLY, flow_add_reply) \
3549 #define foreach_standalone_reply_msg \
3550 _(SW_INTERFACE_EVENT, sw_interface_event)
3558 #define STR_VTR_OP_CASE(op) \
3559 case L2_VTR_ ## op: \
3563 str_vtr_op (u32 vtr_op)
3567 STR_VTR_OP_CASE (DISABLED);
3568 STR_VTR_OP_CASE (PUSH_1);
3569 STR_VTR_OP_CASE (PUSH_2);
3570 STR_VTR_OP_CASE (POP_1);
3571 STR_VTR_OP_CASE (POP_2);
3572 STR_VTR_OP_CASE (TRANSLATE_1_1);
3573 STR_VTR_OP_CASE (TRANSLATE_1_2);
3574 STR_VTR_OP_CASE (TRANSLATE_2_1);
3575 STR_VTR_OP_CASE (TRANSLATE_2_2);
3582 dump_sub_interface_table (vat_main_t * vam)
3584 const sw_interface_subif_t *sub = NULL;
3586 if (vam->json_output)
3589 ("JSON output supported only for VPE API calls and dump_stats_table");
3594 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3595 "Interface", "sw_if_index",
3596 "sub id", "dot1ad", "tags", "outer id",
3597 "inner id", "exact", "default", "outer any", "inner any");
3599 vec_foreach (sub, vam->sw_if_subif_table)
3602 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3603 sub->interface_name,
3605 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3606 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3607 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3608 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3609 if (sub->vtr_op != L2_VTR_DISABLED)
3612 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3613 "tag1: %d tag2: %d ]",
3614 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3615 sub->vtr_tag1, sub->vtr_tag2);
3623 name_sort_cmp (void *a1, void *a2)
3625 name_sort_t *n1 = a1;
3626 name_sort_t *n2 = a2;
3628 return strcmp ((char *) n1->name, (char *) n2->name);
3632 dump_interface_table (vat_main_t * vam)
3635 name_sort_t *nses = 0, *ns;
3637 if (vam->json_output)
3640 ("JSON output supported only for VPE API calls and dump_stats_table");
3645 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3647 vec_add2 (nses, ns, 1);
3648 ns->name = (u8 *)(p->key);
3649 ns->value = (u32) p->value[0];
3653 vec_sort_with_function (nses, name_sort_cmp);
3655 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3656 vec_foreach (ns, nses)
3658 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3665 dump_ip_table (vat_main_t * vam, int is_ipv6)
3667 const ip_details_t *det = NULL;
3668 const ip_address_details_t *address = NULL;
3671 print (vam->ofp, "%-12s", "sw_if_index");
3673 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3680 print (vam->ofp, "%-12d", i);
3681 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3686 vec_foreach (address, det->addr)
3690 is_ipv6 ? format_ip6_address : format_ip4_address,
3691 address->ip, address->prefix_length);
3699 dump_ipv4_table (vat_main_t * vam)
3701 if (vam->json_output)
3704 ("JSON output supported only for VPE API calls and dump_stats_table");
3708 return dump_ip_table (vam, 0);
3712 dump_ipv6_table (vat_main_t * vam)
3714 if (vam->json_output)
3717 ("JSON output supported only for VPE API calls and dump_stats_table");
3721 return dump_ip_table (vam, 1);
3725 * Pass CLI buffers directly in the CLI_INBAND API message,
3726 * instead of an additional shared memory area.
3729 exec_inband (vat_main_t * vam)
3731 vl_api_cli_inband_t *mp;
3732 unformat_input_t *i = vam->input;
3735 if (vec_len (i->buffer) == 0)
3738 if (vam->exec_mode == 0 && unformat (i, "mode"))
3743 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3750 * In order for the CLI command to work, it
3751 * must be a vector ending in \n, not a C-string ending
3754 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3755 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3759 /* json responses may or may not include a useful reply... */
3760 if (vec_len (vam->cmd_reply))
3761 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3766 exec (vat_main_t * vam)
3768 return exec_inband (vam);
3772 api_create_loopback (vat_main_t * vam)
3774 unformat_input_t *i = vam->input;
3775 vl_api_create_loopback_t *mp;
3776 vl_api_create_loopback_instance_t *mp_lbi;
3779 u8 is_specified = 0;
3780 u32 user_instance = 0;
3783 clib_memset (mac_address, 0, sizeof (mac_address));
3785 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3787 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3789 if (unformat (i, "instance %d", &user_instance))
3797 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3798 mp_lbi->is_specified = is_specified;
3800 mp_lbi->user_instance = htonl (user_instance);
3802 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3807 /* Construct the API message */
3808 M (CREATE_LOOPBACK, mp);
3810 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3819 api_delete_loopback (vat_main_t * vam)
3821 unformat_input_t *i = vam->input;
3822 vl_api_delete_loopback_t *mp;
3823 u32 sw_if_index = ~0;
3826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3828 if (unformat (i, "sw_if_index %d", &sw_if_index))
3834 if (sw_if_index == ~0)
3836 errmsg ("missing sw_if_index");
3840 /* Construct the API message */
3841 M (DELETE_LOOPBACK, mp);
3842 mp->sw_if_index = ntohl (sw_if_index);
3850 api_want_interface_events (vat_main_t * vam)
3852 unformat_input_t *i = vam->input;
3853 vl_api_want_interface_events_t *mp;
3857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3859 if (unformat (i, "enable"))
3861 else if (unformat (i, "disable"))
3869 errmsg ("missing enable|disable");
3873 M (WANT_INTERFACE_EVENTS, mp);
3874 mp->enable_disable = enable;
3876 vam->interface_event_display = enable;
3884 /* Note: non-static, called once to set up the initial intfc table */
3886 api_sw_interface_dump (vat_main_t * vam)
3888 vl_api_sw_interface_dump_t *mp;
3889 vl_api_control_ping_t *mp_ping;
3891 name_sort_t *nses = 0, *ns;
3892 sw_interface_subif_t *sub = NULL;
3895 /* Toss the old name table */
3897 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3899 vec_add2 (nses, ns, 1);
3900 ns->name = (u8 *)(p->key);
3901 ns->value = (u32) p->value[0];
3905 hash_free (vam->sw_if_index_by_interface_name);
3907 vec_foreach (ns, nses) vec_free (ns->name);
3911 vec_foreach (sub, vam->sw_if_subif_table)
3913 vec_free (sub->interface_name);
3915 vec_free (vam->sw_if_subif_table);
3917 /* recreate the interface name hash table */
3918 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3921 * Ask for all interface names. Otherwise, the epic catalog of
3922 * name filters becomes ridiculously long, and vat ends up needing
3923 * to be taught about new interface types.
3925 M (SW_INTERFACE_DUMP, mp);
3928 /* Use a control ping for synchronization */
3929 MPING (CONTROL_PING, mp_ping);
3937 api_sw_interface_set_flags (vat_main_t * vam)
3939 unformat_input_t *i = vam->input;
3940 vl_api_sw_interface_set_flags_t *mp;
3942 u8 sw_if_index_set = 0;
3946 /* Parse args required to build the message */
3947 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3949 if (unformat (i, "admin-up"))
3951 else if (unformat (i, "admin-down"))
3954 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3955 sw_if_index_set = 1;
3956 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3957 sw_if_index_set = 1;
3962 if (sw_if_index_set == 0)
3964 errmsg ("missing interface name or sw_if_index");
3968 /* Construct the API message */
3969 M (SW_INTERFACE_SET_FLAGS, mp);
3970 mp->sw_if_index = ntohl (sw_if_index);
3971 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3976 /* Wait for a reply, return the good/bad news... */
3982 api_sw_interface_set_rx_mode (vat_main_t * vam)
3984 unformat_input_t *i = vam->input;
3985 vl_api_sw_interface_set_rx_mode_t *mp;
3987 u8 sw_if_index_set = 0;
3989 u8 queue_id_valid = 0;
3991 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3993 /* Parse args required to build the message */
3994 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3996 if (unformat (i, "queue %d", &queue_id))
3998 else if (unformat (i, "polling"))
3999 mode = VNET_HW_IF_RX_MODE_POLLING;
4000 else if (unformat (i, "interrupt"))
4001 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
4002 else if (unformat (i, "adaptive"))
4003 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
4005 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4006 sw_if_index_set = 1;
4007 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4008 sw_if_index_set = 1;
4013 if (sw_if_index_set == 0)
4015 errmsg ("missing interface name or sw_if_index");
4018 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
4020 errmsg ("missing rx-mode");
4024 /* Construct the API message */
4025 M (SW_INTERFACE_SET_RX_MODE, mp);
4026 mp->sw_if_index = ntohl (sw_if_index);
4027 mp->mode = (vl_api_rx_mode_t) mode;
4028 mp->queue_id_valid = queue_id_valid;
4029 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
4034 /* Wait for a reply, return the good/bad news... */
4040 api_sw_interface_set_rx_placement (vat_main_t * vam)
4042 unformat_input_t *i = vam->input;
4043 vl_api_sw_interface_set_rx_placement_t *mp;
4045 u8 sw_if_index_set = 0;
4048 u32 queue_id, thread_index;
4050 /* Parse args required to build the message */
4051 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4053 if (unformat (i, "queue %d", &queue_id))
4055 else if (unformat (i, "main"))
4057 else if (unformat (i, "worker %d", &thread_index))
4060 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4061 sw_if_index_set = 1;
4062 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4063 sw_if_index_set = 1;
4068 if (sw_if_index_set == 0)
4070 errmsg ("missing interface name or sw_if_index");
4076 /* Construct the API message */
4077 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4078 mp->sw_if_index = ntohl (sw_if_index);
4079 mp->worker_id = ntohl (thread_index);
4080 mp->queue_id = ntohl (queue_id);
4081 mp->is_main = is_main;
4085 /* Wait for a reply, return the good/bad news... */
4090 static void vl_api_sw_interface_rx_placement_details_t_handler
4091 (vl_api_sw_interface_rx_placement_details_t * mp)
4093 vat_main_t *vam = &vat_main;
4094 u32 worker_id = ntohl (mp->worker_id);
4097 "\n%-11d %-11s %-6d %-5d %-9s",
4098 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4099 worker_id, ntohl (mp->queue_id),
4101 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4104 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4105 (vl_api_sw_interface_rx_placement_details_t * mp)
4107 vat_main_t *vam = &vat_main;
4108 vat_json_node_t *node = NULL;
4110 if (VAT_JSON_ARRAY != vam->json_tree.type)
4112 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4113 vat_json_init_array (&vam->json_tree);
4115 node = vat_json_array_add (&vam->json_tree);
4117 vat_json_init_object (node);
4118 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4119 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4120 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4121 vat_json_object_add_uint (node, "mode", mp->mode);
4125 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4127 unformat_input_t *i = vam->input;
4128 vl_api_sw_interface_rx_placement_dump_t *mp;
4129 vl_api_control_ping_t *mp_ping;
4132 u8 sw_if_index_set = 0;
4134 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4136 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4138 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4145 "\n%-11s %-11s %-6s %-5s %-4s",
4146 "sw_if_index", "main/worker", "thread", "queue", "mode");
4148 /* Dump Interface rx placement */
4149 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4151 if (sw_if_index_set)
4152 mp->sw_if_index = htonl (sw_if_index);
4154 mp->sw_if_index = ~0;
4158 /* Use a control ping for synchronization */
4159 MPING (CONTROL_PING, mp_ping);
4167 api_sw_interface_clear_stats (vat_main_t * vam)
4169 unformat_input_t *i = vam->input;
4170 vl_api_sw_interface_clear_stats_t *mp;
4172 u8 sw_if_index_set = 0;
4175 /* Parse args required to build the message */
4176 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4178 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4179 sw_if_index_set = 1;
4180 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4181 sw_if_index_set = 1;
4186 /* Construct the API message */
4187 M (SW_INTERFACE_CLEAR_STATS, mp);
4189 if (sw_if_index_set == 1)
4190 mp->sw_if_index = ntohl (sw_if_index);
4192 mp->sw_if_index = ~0;
4197 /* Wait for a reply, return the good/bad news... */
4203 api_sw_interface_add_del_address (vat_main_t * vam)
4205 unformat_input_t *i = vam->input;
4206 vl_api_sw_interface_add_del_address_t *mp;
4208 u8 sw_if_index_set = 0;
4209 u8 is_add = 1, del_all = 0;
4210 u32 address_length = 0;
4211 u8 v4_address_set = 0;
4212 u8 v6_address_set = 0;
4213 ip4_address_t v4address;
4214 ip6_address_t v6address;
4217 /* Parse args required to build the message */
4218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4220 if (unformat (i, "del-all"))
4222 else if (unformat (i, "del"))
4225 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4226 sw_if_index_set = 1;
4227 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4228 sw_if_index_set = 1;
4229 else if (unformat (i, "%U/%d",
4230 unformat_ip4_address, &v4address, &address_length))
4232 else if (unformat (i, "%U/%d",
4233 unformat_ip6_address, &v6address, &address_length))
4239 if (sw_if_index_set == 0)
4241 errmsg ("missing interface name or sw_if_index");
4244 if (v4_address_set && v6_address_set)
4246 errmsg ("both v4 and v6 addresses set");
4249 if (!v4_address_set && !v6_address_set && !del_all)
4251 errmsg ("no addresses set");
4255 /* Construct the API message */
4256 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4258 mp->sw_if_index = ntohl (sw_if_index);
4259 mp->is_add = is_add;
4260 mp->del_all = del_all;
4263 mp->prefix.address.af = ADDRESS_IP6;
4264 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4268 mp->prefix.address.af = ADDRESS_IP4;
4269 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4271 mp->prefix.len = address_length;
4276 /* Wait for a reply, return good/bad news */
4282 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4284 unformat_input_t *i = vam->input;
4285 vl_api_sw_interface_set_mpls_enable_t *mp;
4287 u8 sw_if_index_set = 0;
4291 /* Parse args required to build the message */
4292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4294 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4295 sw_if_index_set = 1;
4296 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4297 sw_if_index_set = 1;
4298 else if (unformat (i, "disable"))
4300 else if (unformat (i, "dis"))
4306 if (sw_if_index_set == 0)
4308 errmsg ("missing interface name or sw_if_index");
4312 /* Construct the API message */
4313 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4315 mp->sw_if_index = ntohl (sw_if_index);
4316 mp->enable = enable;
4321 /* Wait for a reply... */
4327 api_sw_interface_set_table (vat_main_t * vam)
4329 unformat_input_t *i = vam->input;
4330 vl_api_sw_interface_set_table_t *mp;
4331 u32 sw_if_index, vrf_id = 0;
4332 u8 sw_if_index_set = 0;
4336 /* Parse args required to build the message */
4337 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4339 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4340 sw_if_index_set = 1;
4341 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4342 sw_if_index_set = 1;
4343 else if (unformat (i, "vrf %d", &vrf_id))
4345 else if (unformat (i, "ipv6"))
4351 if (sw_if_index_set == 0)
4353 errmsg ("missing interface name or sw_if_index");
4357 /* Construct the API message */
4358 M (SW_INTERFACE_SET_TABLE, mp);
4360 mp->sw_if_index = ntohl (sw_if_index);
4361 mp->is_ipv6 = is_ipv6;
4362 mp->vrf_id = ntohl (vrf_id);
4367 /* Wait for a reply... */
4372 static void vl_api_sw_interface_get_table_reply_t_handler
4373 (vl_api_sw_interface_get_table_reply_t * mp)
4375 vat_main_t *vam = &vat_main;
4377 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4379 vam->retval = ntohl (mp->retval);
4380 vam->result_ready = 1;
4384 static void vl_api_sw_interface_get_table_reply_t_handler_json
4385 (vl_api_sw_interface_get_table_reply_t * mp)
4387 vat_main_t *vam = &vat_main;
4388 vat_json_node_t node;
4390 vat_json_init_object (&node);
4391 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4392 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4394 vat_json_print (vam->ofp, &node);
4395 vat_json_free (&node);
4397 vam->retval = ntohl (mp->retval);
4398 vam->result_ready = 1;
4402 api_sw_interface_get_table (vat_main_t * vam)
4404 unformat_input_t *i = vam->input;
4405 vl_api_sw_interface_get_table_t *mp;
4407 u8 sw_if_index_set = 0;
4411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4413 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4414 sw_if_index_set = 1;
4415 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4416 sw_if_index_set = 1;
4417 else if (unformat (i, "ipv6"))
4423 if (sw_if_index_set == 0)
4425 errmsg ("missing interface name or sw_if_index");
4429 M (SW_INTERFACE_GET_TABLE, mp);
4430 mp->sw_if_index = htonl (sw_if_index);
4431 mp->is_ipv6 = is_ipv6;
4439 api_sw_interface_set_vpath (vat_main_t * vam)
4441 unformat_input_t *i = vam->input;
4442 vl_api_sw_interface_set_vpath_t *mp;
4443 u32 sw_if_index = 0;
4444 u8 sw_if_index_set = 0;
4448 /* Parse args required to build the message */
4449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4451 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4452 sw_if_index_set = 1;
4453 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4454 sw_if_index_set = 1;
4455 else if (unformat (i, "enable"))
4457 else if (unformat (i, "disable"))
4463 if (sw_if_index_set == 0)
4465 errmsg ("missing interface name or sw_if_index");
4469 /* Construct the API message */
4470 M (SW_INTERFACE_SET_VPATH, mp);
4472 mp->sw_if_index = ntohl (sw_if_index);
4473 mp->enable = is_enable;
4478 /* Wait for a reply... */
4484 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4486 unformat_input_t *i = vam->input;
4487 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4488 u32 sw_if_index = 0;
4489 u8 sw_if_index_set = 0;
4494 /* Parse args required to build the message */
4495 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4497 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4498 sw_if_index_set = 1;
4499 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4500 sw_if_index_set = 1;
4501 else if (unformat (i, "enable"))
4503 else if (unformat (i, "disable"))
4505 else if (unformat (i, "ip4"))
4507 else if (unformat (i, "ip6"))
4513 if (sw_if_index_set == 0)
4515 errmsg ("missing interface name or sw_if_index");
4519 /* Construct the API message */
4520 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4522 mp->sw_if_index = ntohl (sw_if_index);
4523 mp->enable = is_enable;
4524 mp->is_ipv6 = is_ipv6;
4529 /* Wait for a reply... */
4535 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4537 unformat_input_t *i = vam->input;
4538 vl_api_sw_interface_set_l2_xconnect_t *mp;
4540 u8 rx_sw_if_index_set = 0;
4542 u8 tx_sw_if_index_set = 0;
4546 /* Parse args required to build the message */
4547 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4549 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4550 rx_sw_if_index_set = 1;
4551 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4552 tx_sw_if_index_set = 1;
4553 else if (unformat (i, "rx"))
4555 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4557 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4559 rx_sw_if_index_set = 1;
4564 else if (unformat (i, "tx"))
4566 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4568 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4570 tx_sw_if_index_set = 1;
4575 else if (unformat (i, "enable"))
4577 else if (unformat (i, "disable"))
4583 if (rx_sw_if_index_set == 0)
4585 errmsg ("missing rx interface name or rx_sw_if_index");
4589 if (enable && (tx_sw_if_index_set == 0))
4591 errmsg ("missing tx interface name or tx_sw_if_index");
4595 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4597 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4598 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4599 mp->enable = enable;
4607 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4609 unformat_input_t *i = vam->input;
4610 vl_api_sw_interface_set_l2_bridge_t *mp;
4611 vl_api_l2_port_type_t port_type;
4613 u8 rx_sw_if_index_set = 0;
4620 port_type = L2_API_PORT_TYPE_NORMAL;
4622 /* Parse args required to build the message */
4623 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4625 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4626 rx_sw_if_index_set = 1;
4627 else if (unformat (i, "bd_id %d", &bd_id))
4631 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4632 rx_sw_if_index_set = 1;
4633 else if (unformat (i, "shg %d", &shg))
4635 else if (unformat (i, "bvi"))
4636 port_type = L2_API_PORT_TYPE_BVI;
4637 else if (unformat (i, "uu-fwd"))
4638 port_type = L2_API_PORT_TYPE_UU_FWD;
4639 else if (unformat (i, "enable"))
4641 else if (unformat (i, "disable"))
4647 if (rx_sw_if_index_set == 0)
4649 errmsg ("missing rx interface name or sw_if_index");
4653 if (enable && (bd_id_set == 0))
4655 errmsg ("missing bridge domain");
4659 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4661 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4662 mp->bd_id = ntohl (bd_id);
4664 mp->port_type = ntohl (port_type);
4665 mp->enable = enable;
4673 api_bridge_domain_dump (vat_main_t * vam)
4675 unformat_input_t *i = vam->input;
4676 vl_api_bridge_domain_dump_t *mp;
4677 vl_api_control_ping_t *mp_ping;
4681 /* Parse args required to build the message */
4682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4684 if (unformat (i, "bd_id %d", &bd_id))
4690 M (BRIDGE_DOMAIN_DUMP, mp);
4691 mp->bd_id = ntohl (bd_id);
4694 /* Use a control ping for synchronization */
4695 MPING (CONTROL_PING, mp_ping);
4703 api_bridge_domain_add_del (vat_main_t * vam)
4705 unformat_input_t *i = vam->input;
4706 vl_api_bridge_domain_add_del_t *mp;
4709 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4714 /* Parse args required to build the message */
4715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4717 if (unformat (i, "bd_id %d", &bd_id))
4719 else if (unformat (i, "flood %d", &flood))
4721 else if (unformat (i, "uu-flood %d", &uu_flood))
4723 else if (unformat (i, "forward %d", &forward))
4725 else if (unformat (i, "learn %d", &learn))
4727 else if (unformat (i, "arp-term %d", &arp_term))
4729 else if (unformat (i, "mac-age %d", &mac_age))
4731 else if (unformat (i, "bd-tag %s", &bd_tag))
4733 else if (unformat (i, "del"))
4736 flood = uu_flood = forward = learn = 0;
4744 errmsg ("missing bridge domain");
4751 errmsg ("mac age must be less than 256 ");
4756 if ((bd_tag) && (vec_len (bd_tag) > 63))
4758 errmsg ("bd-tag cannot be longer than 63");
4763 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4765 mp->bd_id = ntohl (bd_id);
4767 mp->uu_flood = uu_flood;
4768 mp->forward = forward;
4770 mp->arp_term = arp_term;
4771 mp->is_add = is_add;
4772 mp->mac_age = (u8) mac_age;
4775 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4776 mp->bd_tag[vec_len (bd_tag)] = 0;
4787 api_l2fib_flush_bd (vat_main_t * vam)
4789 unformat_input_t *i = vam->input;
4790 vl_api_l2fib_flush_bd_t *mp;
4794 /* Parse args required to build the message */
4795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4797 if (unformat (i, "bd_id %d", &bd_id));
4804 errmsg ("missing bridge domain");
4808 M (L2FIB_FLUSH_BD, mp);
4810 mp->bd_id = htonl (bd_id);
4818 api_l2fib_flush_int (vat_main_t * vam)
4820 unformat_input_t *i = vam->input;
4821 vl_api_l2fib_flush_int_t *mp;
4822 u32 sw_if_index = ~0;
4825 /* Parse args required to build the message */
4826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4828 if (unformat (i, "sw_if_index %d", &sw_if_index));
4830 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4835 if (sw_if_index == ~0)
4837 errmsg ("missing interface name or sw_if_index");
4841 M (L2FIB_FLUSH_INT, mp);
4843 mp->sw_if_index = ntohl (sw_if_index);
4851 api_l2fib_add_del (vat_main_t * vam)
4853 unformat_input_t *i = vam->input;
4854 vl_api_l2fib_add_del_t *mp;
4860 u32 sw_if_index = 0;
4861 u8 sw_if_index_set = 0;
4870 /* Parse args required to build the message */
4871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4873 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4875 else if (unformat (i, "bd_id %d", &bd_id))
4877 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4878 sw_if_index_set = 1;
4879 else if (unformat (i, "sw_if"))
4881 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4884 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4885 sw_if_index_set = 1;
4890 else if (unformat (i, "static"))
4892 else if (unformat (i, "filter"))
4897 else if (unformat (i, "bvi"))
4902 else if (unformat (i, "del"))
4904 else if (unformat (i, "count %d", &count))
4912 errmsg ("missing mac address");
4918 errmsg ("missing bridge domain");
4922 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4924 errmsg ("missing interface name or sw_if_index");
4930 /* Turn on async mode */
4931 vam->async_mode = 1;
4932 vam->async_errors = 0;
4933 before = vat_time_now (vam);
4936 for (j = 0; j < count; j++)
4938 M (L2FIB_ADD_DEL, mp);
4940 clib_memcpy (mp->mac, mac, 6);
4941 mp->bd_id = ntohl (bd_id);
4942 mp->is_add = is_add;
4943 mp->sw_if_index = ntohl (sw_if_index);
4947 mp->static_mac = static_mac;
4948 mp->filter_mac = filter_mac;
4949 mp->bvi_mac = bvi_mac;
4951 increment_mac_address (mac);
4958 vl_api_control_ping_t *mp_ping;
4961 /* Shut off async mode */
4962 vam->async_mode = 0;
4964 MPING (CONTROL_PING, mp_ping);
4967 timeout = vat_time_now (vam) + 1.0;
4968 while (vat_time_now (vam) < timeout)
4969 if (vam->result_ready == 1)
4974 if (vam->retval == -99)
4977 if (vam->async_errors > 0)
4979 errmsg ("%d asynchronous errors", vam->async_errors);
4982 vam->async_errors = 0;
4983 after = vat_time_now (vam);
4985 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4986 count, after - before, count / (after - before));
4992 /* Wait for a reply... */
4996 /* Return the good/bad news */
4997 return (vam->retval);
5001 api_bridge_domain_set_mac_age (vat_main_t * vam)
5003 unformat_input_t *i = vam->input;
5004 vl_api_bridge_domain_set_mac_age_t *mp;
5009 /* Parse args required to build the message */
5010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5012 if (unformat (i, "bd_id %d", &bd_id));
5013 else if (unformat (i, "mac-age %d", &mac_age));
5020 errmsg ("missing bridge domain");
5026 errmsg ("mac age must be less than 256 ");
5030 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
5032 mp->bd_id = htonl (bd_id);
5033 mp->mac_age = (u8) mac_age;
5041 api_l2_flags (vat_main_t * vam)
5043 unformat_input_t *i = vam->input;
5044 vl_api_l2_flags_t *mp;
5047 u8 sw_if_index_set = 0;
5051 /* Parse args required to build the message */
5052 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5054 if (unformat (i, "sw_if_index %d", &sw_if_index))
5055 sw_if_index_set = 1;
5056 else if (unformat (i, "sw_if"))
5058 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5061 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5062 sw_if_index_set = 1;
5067 else if (unformat (i, "learn"))
5069 else if (unformat (i, "forward"))
5071 else if (unformat (i, "flood"))
5073 else if (unformat (i, "uu-flood"))
5074 flags |= L2_UU_FLOOD;
5075 else if (unformat (i, "arp-term"))
5076 flags |= L2_ARP_TERM;
5077 else if (unformat (i, "off"))
5079 else if (unformat (i, "disable"))
5085 if (sw_if_index_set == 0)
5087 errmsg ("missing interface name or sw_if_index");
5093 mp->sw_if_index = ntohl (sw_if_index);
5094 mp->feature_bitmap = ntohl (flags);
5095 mp->is_set = is_set;
5103 api_bridge_flags (vat_main_t * vam)
5105 unformat_input_t *i = vam->input;
5106 vl_api_bridge_flags_t *mp;
5110 bd_flags_t flags = 0;
5113 /* Parse args required to build the message */
5114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5116 if (unformat (i, "bd_id %d", &bd_id))
5118 else if (unformat (i, "learn"))
5119 flags |= BRIDGE_API_FLAG_LEARN;
5120 else if (unformat (i, "forward"))
5121 flags |= BRIDGE_API_FLAG_FWD;
5122 else if (unformat (i, "flood"))
5123 flags |= BRIDGE_API_FLAG_FLOOD;
5124 else if (unformat (i, "uu-flood"))
5125 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5126 else if (unformat (i, "arp-term"))
5127 flags |= BRIDGE_API_FLAG_ARP_TERM;
5128 else if (unformat (i, "off"))
5130 else if (unformat (i, "disable"))
5138 errmsg ("missing bridge domain");
5142 M (BRIDGE_FLAGS, mp);
5144 mp->bd_id = ntohl (bd_id);
5145 mp->flags = ntohl (flags);
5146 mp->is_set = is_set;
5154 api_bd_ip_mac_add_del (vat_main_t * vam)
5156 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5157 vl_api_mac_address_t mac = { 0 };
5158 unformat_input_t *i = vam->input;
5159 vl_api_bd_ip_mac_add_del_t *mp;
5168 /* Parse args required to build the message */
5169 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5171 if (unformat (i, "bd_id %d", &bd_id))
5175 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5179 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5183 else if (unformat (i, "del"))
5191 errmsg ("missing bridge domain");
5194 else if (ip_set == 0)
5196 errmsg ("missing IP address");
5199 else if (mac_set == 0)
5201 errmsg ("missing MAC address");
5205 M (BD_IP_MAC_ADD_DEL, mp);
5207 mp->entry.bd_id = ntohl (bd_id);
5208 mp->is_add = is_add;
5210 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5211 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5219 api_bd_ip_mac_flush (vat_main_t * vam)
5221 unformat_input_t *i = vam->input;
5222 vl_api_bd_ip_mac_flush_t *mp;
5227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5229 if (unformat (i, "bd_id %d", &bd_id))
5239 errmsg ("missing bridge domain");
5243 M (BD_IP_MAC_FLUSH, mp);
5245 mp->bd_id = ntohl (bd_id);
5252 static void vl_api_bd_ip_mac_details_t_handler
5253 (vl_api_bd_ip_mac_details_t * mp)
5255 vat_main_t *vam = &vat_main;
5259 ntohl (mp->entry.bd_id),
5260 format_vl_api_mac_address, mp->entry.mac,
5261 format_vl_api_address, &mp->entry.ip);
5264 static void vl_api_bd_ip_mac_details_t_handler_json
5265 (vl_api_bd_ip_mac_details_t * mp)
5267 vat_main_t *vam = &vat_main;
5268 vat_json_node_t *node = NULL;
5270 if (VAT_JSON_ARRAY != vam->json_tree.type)
5272 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5273 vat_json_init_array (&vam->json_tree);
5275 node = vat_json_array_add (&vam->json_tree);
5277 vat_json_init_object (node);
5278 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5279 vat_json_object_add_string_copy (node, "mac_address",
5280 format (0, "%U", format_vl_api_mac_address,
5284 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5285 vat_json_object_add_string_copy (node, "ip_address", ip);
5290 api_bd_ip_mac_dump (vat_main_t * vam)
5292 unformat_input_t *i = vam->input;
5293 vl_api_bd_ip_mac_dump_t *mp;
5294 vl_api_control_ping_t *mp_ping;
5299 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5301 if (unformat (i, "bd_id %d", &bd_id))
5310 "\n%-5s %-7s %-20s %-30s",
5311 "bd_id", "is_ipv6", "mac_address", "ip_address");
5313 /* Dump Bridge Domain Ip to Mac entries */
5314 M (BD_IP_MAC_DUMP, mp);
5317 mp->bd_id = htonl (bd_id);
5323 /* Use a control ping for synchronization */
5324 MPING (CONTROL_PING, mp_ping);
5332 api_tap_create_v2 (vat_main_t * vam)
5334 unformat_input_t *i = vam->input;
5335 vl_api_tap_create_v2_t *mp;
5339 u32 num_rx_queues = 0;
5340 u8 *host_if_name = 0;
5341 u8 host_if_name_set = 0;
5344 u8 host_mac_addr[6];
5345 u8 host_mac_addr_set = 0;
5346 u8 *host_bridge = 0;
5347 u8 host_bridge_set = 0;
5348 u8 host_ip4_prefix_set = 0;
5349 u8 host_ip6_prefix_set = 0;
5350 ip4_address_t host_ip4_addr;
5351 ip4_address_t host_ip4_gw;
5352 u8 host_ip4_gw_set = 0;
5353 u32 host_ip4_prefix_len = 0;
5354 ip6_address_t host_ip6_addr;
5355 ip6_address_t host_ip6_gw;
5356 u8 host_ip6_gw_set = 0;
5357 u32 host_ip6_prefix_len = 0;
5358 u32 host_mtu_size = 0;
5359 u8 host_mtu_set = 0;
5362 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5364 clib_memset (mac_address, 0, sizeof (mac_address));
5366 /* Parse args required to build the message */
5367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5369 if (unformat (i, "id %u", &id))
5373 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5375 else if (unformat (i, "host-if-name %s", &host_if_name))
5376 host_if_name_set = 1;
5377 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5379 else if (unformat (i, "host-ns %s", &host_ns))
5381 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5383 host_mac_addr_set = 1;
5384 else if (unformat (i, "host-bridge %s", &host_bridge))
5385 host_bridge_set = 1;
5386 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5387 &host_ip4_addr, &host_ip4_prefix_len))
5388 host_ip4_prefix_set = 1;
5389 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5390 &host_ip6_addr, &host_ip6_prefix_len))
5391 host_ip6_prefix_set = 1;
5392 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5394 host_ip4_gw_set = 1;
5395 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5397 host_ip6_gw_set = 1;
5398 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5400 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5402 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5404 else if (unformat (i, "no-gso"))
5405 tap_flags &= ~TAP_API_FLAG_GSO;
5406 else if (unformat (i, "gso"))
5407 tap_flags |= TAP_API_FLAG_GSO;
5408 else if (unformat (i, "csum-offload"))
5409 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5410 else if (unformat (i, "persist"))
5411 tap_flags |= TAP_API_FLAG_PERSIST;
5412 else if (unformat (i, "attach"))
5413 tap_flags |= TAP_API_FLAG_ATTACH;
5414 else if (unformat (i, "tun"))
5415 tap_flags |= TAP_API_FLAG_TUN;
5416 else if (unformat (i, "gro-coalesce"))
5417 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5418 else if (unformat (i, "packed"))
5419 tap_flags |= TAP_API_FLAG_PACKED;
5420 else if (unformat (i, "in-order"))
5421 tap_flags |= TAP_API_FLAG_IN_ORDER;
5426 if (vec_len (host_if_name) > 63)
5428 errmsg ("tap name too long. ");
5431 if (vec_len (host_ns) > 63)
5433 errmsg ("host name space too long. ");
5436 if (vec_len (host_bridge) > 63)
5438 errmsg ("host bridge name too long. ");
5441 if (host_ip4_prefix_len > 32)
5443 errmsg ("host ip4 prefix length not valid. ");
5446 if (host_ip6_prefix_len > 128)
5448 errmsg ("host ip6 prefix length not valid. ");
5451 if (!is_pow2 (rx_ring_sz))
5453 errmsg ("rx ring size must be power of 2. ");
5456 if (rx_ring_sz > 32768)
5458 errmsg ("rx ring size must be 32768 or lower. ");
5461 if (!is_pow2 (tx_ring_sz))
5463 errmsg ("tx ring size must be power of 2. ");
5466 if (tx_ring_sz > 32768)
5468 errmsg ("tx ring size must be 32768 or lower. ");
5471 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5473 errmsg ("host MTU size must be in between 64 and 65355. ");
5477 /* Construct the API message */
5478 M (TAP_CREATE_V2, mp);
5480 mp->id = ntohl (id);
5481 mp->use_random_mac = random_mac;
5482 mp->num_rx_queues = (u8) num_rx_queues;
5483 mp->tx_ring_sz = ntohs (tx_ring_sz);
5484 mp->rx_ring_sz = ntohs (rx_ring_sz);
5485 mp->host_mtu_set = host_mtu_set;
5486 mp->host_mtu_size = ntohl (host_mtu_size);
5487 mp->host_mac_addr_set = host_mac_addr_set;
5488 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5489 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5490 mp->host_ip4_gw_set = host_ip4_gw_set;
5491 mp->host_ip6_gw_set = host_ip6_gw_set;
5492 mp->tap_flags = ntohl (tap_flags);
5493 mp->host_namespace_set = host_ns_set;
5494 mp->host_if_name_set = host_if_name_set;
5495 mp->host_bridge_set = host_bridge_set;
5497 if (random_mac == 0)
5498 clib_memcpy (mp->mac_address, mac_address, 6);
5499 if (host_mac_addr_set)
5500 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5501 if (host_if_name_set)
5502 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5504 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5505 if (host_bridge_set)
5506 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5507 if (host_ip4_prefix_set)
5509 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5510 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5512 if (host_ip6_prefix_set)
5514 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5515 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5517 if (host_ip4_gw_set)
5518 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5519 if (host_ip6_gw_set)
5520 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5523 vec_free (host_if_name);
5524 vec_free (host_bridge);
5529 /* Wait for a reply... */
5535 api_tap_delete_v2 (vat_main_t * vam)
5537 unformat_input_t *i = vam->input;
5538 vl_api_tap_delete_v2_t *mp;
5539 u32 sw_if_index = ~0;
5540 u8 sw_if_index_set = 0;
5543 /* Parse args required to build the message */
5544 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5546 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5547 sw_if_index_set = 1;
5548 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5549 sw_if_index_set = 1;
5554 if (sw_if_index_set == 0)
5556 errmsg ("missing vpp interface name. ");
5560 /* Construct the API message */
5561 M (TAP_DELETE_V2, mp);
5563 mp->sw_if_index = ntohl (sw_if_index);
5568 /* Wait for a reply... */
5574 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5576 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5579 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5582 addr->domain = x[0];
5585 addr->function = x[3];
5591 api_virtio_pci_create_v2 (vat_main_t * vam)
5593 unformat_input_t *i = vam->input;
5594 vl_api_virtio_pci_create_v2_t *mp;
5598 u64 features = (u64) ~ (0ULL);
5599 u32 virtio_flags = 0;
5602 clib_memset (mac_address, 0, sizeof (mac_address));
5604 /* Parse args required to build the message */
5605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5607 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5611 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5613 else if (unformat (i, "features 0x%llx", &features))
5615 else if (unformat (i, "gso-enabled"))
5616 virtio_flags |= VIRTIO_API_FLAG_GSO;
5617 else if (unformat (i, "csum-offload-enabled"))
5618 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5619 else if (unformat (i, "gro-coalesce"))
5620 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5621 else if (unformat (i, "packed"))
5622 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5623 else if (unformat (i, "in-order"))
5624 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5625 else if (unformat (i, "buffering"))
5626 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5633 errmsg ("pci address must be non zero. ");
5637 /* Construct the API message */
5638 M (VIRTIO_PCI_CREATE_V2, mp);
5640 mp->use_random_mac = random_mac;
5642 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5643 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5644 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5645 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5647 mp->features = clib_host_to_net_u64 (features);
5648 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5650 if (random_mac == 0)
5651 clib_memcpy (mp->mac_address, mac_address, 6);
5656 /* Wait for a reply... */
5662 api_virtio_pci_delete (vat_main_t * vam)
5664 unformat_input_t *i = vam->input;
5665 vl_api_virtio_pci_delete_t *mp;
5666 u32 sw_if_index = ~0;
5667 u8 sw_if_index_set = 0;
5670 /* Parse args required to build the message */
5671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5673 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5674 sw_if_index_set = 1;
5675 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5676 sw_if_index_set = 1;
5681 if (sw_if_index_set == 0)
5683 errmsg ("missing vpp interface name. ");
5687 /* Construct the API message */
5688 M (VIRTIO_PCI_DELETE, mp);
5690 mp->sw_if_index = htonl (sw_if_index);
5695 /* Wait for a reply... */
5701 api_bond_create (vat_main_t * vam)
5703 unformat_input_t *i = vam->input;
5704 vl_api_bond_create_t *mp;
5714 clib_memset (mac_address, 0, sizeof (mac_address));
5717 /* Parse args required to build the message */
5718 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5720 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5722 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5723 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5725 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5728 else if (unformat (i, "numa-only"))
5730 else if (unformat (i, "id %u", &id))
5736 if (mode_is_set == 0)
5738 errmsg ("Missing bond mode. ");
5742 /* Construct the API message */
5743 M (BOND_CREATE, mp);
5745 mp->use_custom_mac = custom_mac;
5747 mp->mode = htonl (mode);
5748 mp->lb = htonl (lb);
5749 mp->id = htonl (id);
5750 mp->numa_only = numa_only;
5753 clib_memcpy (mp->mac_address, mac_address, 6);
5758 /* Wait for a reply... */
5764 api_bond_create2 (vat_main_t * vam)
5766 unformat_input_t *i = vam->input;
5767 vl_api_bond_create2_t *mp;
5778 clib_memset (mac_address, 0, sizeof (mac_address));
5781 /* Parse args required to build the message */
5782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5784 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5786 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5787 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5789 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5792 else if (unformat (i, "numa-only"))
5794 else if (unformat (i, "gso"))
5796 else if (unformat (i, "id %u", &id))
5802 if (mode_is_set == 0)
5804 errmsg ("Missing bond mode. ");
5808 /* Construct the API message */
5809 M (BOND_CREATE2, mp);
5811 mp->use_custom_mac = custom_mac;
5813 mp->mode = htonl (mode);
5814 mp->lb = htonl (lb);
5815 mp->id = htonl (id);
5816 mp->numa_only = numa_only;
5817 mp->enable_gso = gso;
5820 clib_memcpy (mp->mac_address, mac_address, 6);
5825 /* Wait for a reply... */
5831 api_bond_delete (vat_main_t * vam)
5833 unformat_input_t *i = vam->input;
5834 vl_api_bond_delete_t *mp;
5835 u32 sw_if_index = ~0;
5836 u8 sw_if_index_set = 0;
5839 /* Parse args required to build the message */
5840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5842 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5843 sw_if_index_set = 1;
5844 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5845 sw_if_index_set = 1;
5850 if (sw_if_index_set == 0)
5852 errmsg ("missing vpp interface name. ");
5856 /* Construct the API message */
5857 M (BOND_DELETE, mp);
5859 mp->sw_if_index = ntohl (sw_if_index);
5864 /* Wait for a reply... */
5870 api_bond_add_member (vat_main_t * vam)
5872 unformat_input_t *i = vam->input;
5873 vl_api_bond_add_member_t *mp;
5874 u32 bond_sw_if_index;
5878 u32 bond_sw_if_index_is_set = 0;
5880 u8 sw_if_index_is_set = 0;
5882 /* Parse args required to build the message */
5883 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5885 if (unformat (i, "sw_if_index %d", &sw_if_index))
5886 sw_if_index_is_set = 1;
5887 else if (unformat (i, "bond %u", &bond_sw_if_index))
5888 bond_sw_if_index_is_set = 1;
5889 else if (unformat (i, "passive %d", &is_passive))
5891 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5897 if (bond_sw_if_index_is_set == 0)
5899 errmsg ("Missing bond sw_if_index. ");
5902 if (sw_if_index_is_set == 0)
5904 errmsg ("Missing member sw_if_index. ");
5908 /* Construct the API message */
5909 M (BOND_ADD_MEMBER, mp);
5911 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5912 mp->sw_if_index = ntohl (sw_if_index);
5913 mp->is_long_timeout = is_long_timeout;
5914 mp->is_passive = is_passive;
5919 /* Wait for a reply... */
5925 api_bond_detach_member (vat_main_t * vam)
5927 unformat_input_t *i = vam->input;
5928 vl_api_bond_detach_member_t *mp;
5929 u32 sw_if_index = ~0;
5930 u8 sw_if_index_set = 0;
5933 /* Parse args required to build the message */
5934 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5936 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5937 sw_if_index_set = 1;
5938 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5939 sw_if_index_set = 1;
5944 if (sw_if_index_set == 0)
5946 errmsg ("missing vpp interface name. ");
5950 /* Construct the API message */
5951 M (BOND_DETACH_MEMBER, mp);
5953 mp->sw_if_index = ntohl (sw_if_index);
5958 /* Wait for a reply... */
5964 api_ip_table_add_del (vat_main_t * vam)
5966 unformat_input_t *i = vam->input;
5967 vl_api_ip_table_add_del_t *mp;
5973 /* Parse args required to build the message */
5974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5976 if (unformat (i, "ipv6"))
5978 else if (unformat (i, "del"))
5980 else if (unformat (i, "add"))
5982 else if (unformat (i, "table %d", &table_id))
5986 clib_warning ("parse error '%U'", format_unformat_error, i);
5993 errmsg ("missing table-ID");
5997 /* Construct the API message */
5998 M (IP_TABLE_ADD_DEL, mp);
6000 mp->table.table_id = ntohl (table_id);
6001 mp->table.is_ip6 = is_ipv6;
6002 mp->is_add = is_add;
6007 /* Wait for a reply... */
6014 unformat_fib_path (unformat_input_t * input, va_list * args)
6016 vat_main_t *vam = va_arg (*args, vat_main_t *);
6017 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
6018 u32 weight, preference;
6019 mpls_label_t out_label;
6021 clib_memset (path, 0, sizeof (*path));
6023 path->sw_if_index = ~0;
6027 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6029 if (unformat (input, "%U %U",
6030 unformat_vl_api_ip4_address,
6031 &path->nh.address.ip4,
6032 api_unformat_sw_if_index, vam, &path->sw_if_index))
6034 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6036 else if (unformat (input, "%U %U",
6037 unformat_vl_api_ip6_address,
6038 &path->nh.address.ip6,
6039 api_unformat_sw_if_index, vam, &path->sw_if_index))
6041 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6043 else if (unformat (input, "weight %u", &weight))
6045 path->weight = weight;
6047 else if (unformat (input, "preference %u", &preference))
6049 path->preference = preference;
6051 else if (unformat (input, "%U next-hop-table %d",
6052 unformat_vl_api_ip4_address,
6053 &path->nh.address.ip4, &path->table_id))
6055 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6057 else if (unformat (input, "%U next-hop-table %d",
6058 unformat_vl_api_ip6_address,
6059 &path->nh.address.ip6, &path->table_id))
6061 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6063 else if (unformat (input, "%U",
6064 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6067 * the recursive next-hops are by default in the default table
6070 path->sw_if_index = ~0;
6071 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6073 else if (unformat (input, "%U",
6074 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6077 * the recursive next-hops are by default in the default table
6080 path->sw_if_index = ~0;
6081 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6083 else if (unformat (input, "resolve-via-host"))
6085 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6087 else if (unformat (input, "resolve-via-attached"))
6089 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6091 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6093 path->type = FIB_API_PATH_TYPE_LOCAL;
6094 path->sw_if_index = ~0;
6095 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6097 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6099 path->type = FIB_API_PATH_TYPE_LOCAL;
6100 path->sw_if_index = ~0;
6101 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6103 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6105 else if (unformat (input, "via-label %d", &path->nh.via_label))
6107 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6108 path->sw_if_index = ~0;
6110 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6112 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6113 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6115 else if (unformat (input, "local"))
6117 path->type = FIB_API_PATH_TYPE_LOCAL;
6119 else if (unformat (input, "out-labels"))
6121 while (unformat (input, "%d", &out_label))
6123 path->label_stack[path->n_labels].label = out_label;
6124 path->label_stack[path->n_labels].is_uniform = 0;
6125 path->label_stack[path->n_labels].ttl = 64;
6129 else if (unformat (input, "via"))
6131 /* new path, back up and return */
6132 unformat_put_input (input);
6133 unformat_put_input (input);
6134 unformat_put_input (input);
6135 unformat_put_input (input);
6144 path->proto = ntohl (path->proto);
6145 path->type = ntohl (path->type);
6146 path->flags = ntohl (path->flags);
6147 path->table_id = ntohl (path->table_id);
6148 path->sw_if_index = ntohl (path->sw_if_index);
6154 api_ip_route_add_del (vat_main_t * vam)
6156 unformat_input_t *i = vam->input;
6157 vl_api_ip_route_add_del_t *mp;
6160 u8 is_multipath = 0;
6163 vl_api_prefix_t pfx = { };
6164 vl_api_fib_path_t paths[8];
6168 u32 random_add_del = 0;
6169 u32 *random_vector = 0;
6170 u32 random_seed = 0xdeaddabe;
6172 /* Parse args required to build the message */
6173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6175 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6177 else if (unformat (i, "del"))
6179 else if (unformat (i, "add"))
6181 else if (unformat (i, "vrf %d", &vrf_id))
6183 else if (unformat (i, "count %d", &count))
6185 else if (unformat (i, "random"))
6187 else if (unformat (i, "multipath"))
6189 else if (unformat (i, "seed %d", &random_seed))
6193 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6196 if (8 == path_count)
6198 errmsg ("max 8 paths");
6204 clib_warning ("parse error '%U'", format_unformat_error, i);
6211 errmsg ("specify a path; via ...");
6214 if (prefix_set == 0)
6216 errmsg ("missing prefix");
6220 /* Generate a pile of unique, random routes */
6223 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6224 u32 this_random_address;
6227 random_hash = hash_create (count, sizeof (uword));
6229 hash_set (random_hash, i->as_u32, 1);
6230 for (j = 0; j <= count; j++)
6234 this_random_address = random_u32 (&random_seed);
6235 this_random_address =
6236 clib_host_to_net_u32 (this_random_address);
6238 while (hash_get (random_hash, this_random_address));
6239 vec_add1 (random_vector, this_random_address);
6240 hash_set (random_hash, this_random_address, 1);
6242 hash_free (random_hash);
6243 set_ip4_address (&pfx.address, random_vector[0]);
6248 /* Turn on async mode */
6249 vam->async_mode = 1;
6250 vam->async_errors = 0;
6251 before = vat_time_now (vam);
6254 for (j = 0; j < count; j++)
6256 /* Construct the API message */
6257 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6259 mp->is_add = is_add;
6260 mp->is_multipath = is_multipath;
6262 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6263 mp->route.table_id = ntohl (vrf_id);
6264 mp->route.n_paths = path_count;
6266 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6269 set_ip4_address (&pfx.address, random_vector[j + 1]);
6271 increment_address (&pfx.address);
6274 /* If we receive SIGTERM, stop now... */
6279 /* When testing multiple add/del ops, use a control-ping to sync */
6282 vl_api_control_ping_t *mp_ping;
6286 /* Shut off async mode */
6287 vam->async_mode = 0;
6289 MPING (CONTROL_PING, mp_ping);
6292 timeout = vat_time_now (vam) + 1.0;
6293 while (vat_time_now (vam) < timeout)
6294 if (vam->result_ready == 1)
6299 if (vam->retval == -99)
6302 if (vam->async_errors > 0)
6304 errmsg ("%d asynchronous errors", vam->async_errors);
6307 vam->async_errors = 0;
6308 after = vat_time_now (vam);
6310 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6314 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6315 count, after - before, count / (after - before));
6321 /* Wait for a reply... */
6326 /* Return the good/bad news */
6327 return (vam->retval);
6331 api_ip_mroute_add_del (vat_main_t * vam)
6333 unformat_input_t *i = vam->input;
6334 u8 path_set = 0, prefix_set = 0, is_add = 1;
6335 vl_api_ip_mroute_add_del_t *mp;
6336 mfib_entry_flags_t eflags = 0;
6337 vl_api_mfib_path_t path;
6338 vl_api_mprefix_t pfx = { };
6342 /* Parse args required to build the message */
6343 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6345 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6348 pfx.grp_address_length = htons (pfx.grp_address_length);
6350 else if (unformat (i, "del"))
6352 else if (unformat (i, "add"))
6354 else if (unformat (i, "vrf %d", &vrf_id))
6356 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6357 path.itf_flags = htonl (path.itf_flags);
6358 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6360 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6364 clib_warning ("parse error '%U'", format_unformat_error, i);
6369 if (prefix_set == 0)
6371 errmsg ("missing addresses\n");
6376 errmsg ("missing path\n");
6380 /* Construct the API message */
6381 M (IP_MROUTE_ADD_DEL, mp);
6383 mp->is_add = is_add;
6384 mp->is_multipath = 1;
6386 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6387 mp->route.table_id = htonl (vrf_id);
6388 mp->route.n_paths = 1;
6389 mp->route.entry_flags = htonl (eflags);
6391 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6395 /* Wait for a reply... */
6401 api_mpls_table_add_del (vat_main_t * vam)
6403 unformat_input_t *i = vam->input;
6404 vl_api_mpls_table_add_del_t *mp;
6409 /* Parse args required to build the message */
6410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6412 if (unformat (i, "table %d", &table_id))
6414 else if (unformat (i, "del"))
6416 else if (unformat (i, "add"))
6420 clib_warning ("parse error '%U'", format_unformat_error, i);
6427 errmsg ("missing table-ID");
6431 /* Construct the API message */
6432 M (MPLS_TABLE_ADD_DEL, mp);
6434 mp->mt_table.mt_table_id = ntohl (table_id);
6435 mp->mt_is_add = is_add;
6440 /* Wait for a reply... */
6447 api_mpls_route_add_del (vat_main_t * vam)
6449 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6450 mpls_label_t local_label = MPLS_LABEL_INVALID;
6451 unformat_input_t *i = vam->input;
6452 vl_api_mpls_route_add_del_t *mp;
6453 vl_api_fib_path_t paths[8];
6457 /* Parse args required to build the message */
6458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6460 if (unformat (i, "%d", &local_label))
6462 else if (unformat (i, "eos"))
6464 else if (unformat (i, "non-eos"))
6466 else if (unformat (i, "del"))
6468 else if (unformat (i, "add"))
6470 else if (unformat (i, "multipath"))
6472 else if (unformat (i, "count %d", &count))
6476 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6479 if (8 == path_count)
6481 errmsg ("max 8 paths");
6487 clib_warning ("parse error '%U'", format_unformat_error, i);
6494 errmsg ("specify a path; via ...");
6498 if (MPLS_LABEL_INVALID == local_label)
6500 errmsg ("missing label");
6506 /* Turn on async mode */
6507 vam->async_mode = 1;
6508 vam->async_errors = 0;
6509 before = vat_time_now (vam);
6512 for (j = 0; j < count; j++)
6514 /* Construct the API message */
6515 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6517 mp->mr_is_add = is_add;
6518 mp->mr_is_multipath = is_multipath;
6520 mp->mr_route.mr_label = local_label;
6521 mp->mr_route.mr_eos = is_eos;
6522 mp->mr_route.mr_table_id = 0;
6523 mp->mr_route.mr_n_paths = path_count;
6525 clib_memcpy (&mp->mr_route.mr_paths, paths,
6526 sizeof (paths[0]) * path_count);
6532 /* If we receive SIGTERM, stop now... */
6537 /* When testing multiple add/del ops, use a control-ping to sync */
6540 vl_api_control_ping_t *mp_ping;
6544 /* Shut off async mode */
6545 vam->async_mode = 0;
6547 MPING (CONTROL_PING, mp_ping);
6550 timeout = vat_time_now (vam) + 1.0;
6551 while (vat_time_now (vam) < timeout)
6552 if (vam->result_ready == 1)
6557 if (vam->retval == -99)
6560 if (vam->async_errors > 0)
6562 errmsg ("%d asynchronous errors", vam->async_errors);
6565 vam->async_errors = 0;
6566 after = vat_time_now (vam);
6568 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6572 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6573 count, after - before, count / (after - before));
6579 /* Wait for a reply... */
6584 /* Return the good/bad news */
6585 return (vam->retval);
6590 api_mpls_ip_bind_unbind (vat_main_t * vam)
6592 unformat_input_t *i = vam->input;
6593 vl_api_mpls_ip_bind_unbind_t *mp;
6594 u32 ip_table_id = 0;
6596 vl_api_prefix_t pfx;
6598 mpls_label_t local_label = MPLS_LABEL_INVALID;
6601 /* Parse args required to build the message */
6602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6604 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6606 else if (unformat (i, "%d", &local_label))
6608 else if (unformat (i, "table-id %d", &ip_table_id))
6610 else if (unformat (i, "unbind"))
6612 else if (unformat (i, "bind"))
6616 clib_warning ("parse error '%U'", format_unformat_error, i);
6623 errmsg ("IP prefix not set");
6627 if (MPLS_LABEL_INVALID == local_label)
6629 errmsg ("missing label");
6633 /* Construct the API message */
6634 M (MPLS_IP_BIND_UNBIND, mp);
6636 mp->mb_is_bind = is_bind;
6637 mp->mb_ip_table_id = ntohl (ip_table_id);
6638 mp->mb_mpls_table_id = 0;
6639 mp->mb_label = ntohl (local_label);
6640 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6645 /* Wait for a reply... */
6652 api_sr_mpls_policy_add (vat_main_t * vam)
6654 unformat_input_t *i = vam->input;
6655 vl_api_sr_mpls_policy_add_t *mp;
6661 u32 *segments = NULL;
6664 /* Parse args required to build the message */
6665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6667 if (unformat (i, "bsid %d", &bsid))
6669 else if (unformat (i, "weight %d", &weight))
6671 else if (unformat (i, "spray"))
6673 else if (unformat (i, "next %d", &sid))
6676 vec_add1 (segments, htonl (sid));
6680 clib_warning ("parse error '%U'", format_unformat_error, i);
6687 errmsg ("bsid not set");
6691 if (n_segments == 0)
6693 errmsg ("no sid in segment stack");
6697 /* Construct the API message */
6698 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6700 mp->bsid = htonl (bsid);
6701 mp->weight = htonl (weight);
6702 mp->is_spray = type;
6703 mp->n_segments = n_segments;
6704 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6705 vec_free (segments);
6710 /* Wait for a reply... */
6716 api_sr_mpls_policy_del (vat_main_t * vam)
6718 unformat_input_t *i = vam->input;
6719 vl_api_sr_mpls_policy_del_t *mp;
6723 /* Parse args required to build the message */
6724 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6726 if (unformat (i, "bsid %d", &bsid))
6730 clib_warning ("parse error '%U'", format_unformat_error, i);
6737 errmsg ("bsid not set");
6741 /* Construct the API message */
6742 M (SR_MPLS_POLICY_DEL, mp);
6744 mp->bsid = htonl (bsid);
6749 /* Wait for a reply... */
6755 api_bier_table_add_del (vat_main_t * vam)
6757 unformat_input_t *i = vam->input;
6758 vl_api_bier_table_add_del_t *mp;
6760 u32 set = 0, sub_domain = 0, hdr_len = 3;
6761 mpls_label_t local_label = MPLS_LABEL_INVALID;
6764 /* Parse args required to build the message */
6765 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6767 if (unformat (i, "sub-domain %d", &sub_domain))
6769 else if (unformat (i, "set %d", &set))
6771 else if (unformat (i, "label %d", &local_label))
6773 else if (unformat (i, "hdr-len %d", &hdr_len))
6775 else if (unformat (i, "add"))
6777 else if (unformat (i, "del"))
6781 clib_warning ("parse error '%U'", format_unformat_error, i);
6786 if (MPLS_LABEL_INVALID == local_label)
6788 errmsg ("missing label\n");
6792 /* Construct the API message */
6793 M (BIER_TABLE_ADD_DEL, mp);
6795 mp->bt_is_add = is_add;
6796 mp->bt_label = ntohl (local_label);
6797 mp->bt_tbl_id.bt_set = set;
6798 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6799 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6804 /* Wait for a reply... */
6811 api_bier_route_add_del (vat_main_t * vam)
6813 unformat_input_t *i = vam->input;
6814 vl_api_bier_route_add_del_t *mp;
6816 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6817 ip4_address_t v4_next_hop_address;
6818 ip6_address_t v6_next_hop_address;
6819 u8 next_hop_set = 0;
6820 u8 next_hop_proto_is_ip4 = 1;
6821 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6824 /* Parse args required to build the message */
6825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6827 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6829 next_hop_proto_is_ip4 = 1;
6832 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6834 next_hop_proto_is_ip4 = 0;
6837 if (unformat (i, "sub-domain %d", &sub_domain))
6839 else if (unformat (i, "set %d", &set))
6841 else if (unformat (i, "hdr-len %d", &hdr_len))
6843 else if (unformat (i, "bp %d", &bp))
6845 else if (unformat (i, "add"))
6847 else if (unformat (i, "del"))
6849 else if (unformat (i, "out-label %d", &next_hop_out_label))
6853 clib_warning ("parse error '%U'", format_unformat_error, i);
6858 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6860 errmsg ("next hop / label set\n");
6865 errmsg ("bit=position not set\n");
6869 /* Construct the API message */
6870 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6872 mp->br_is_add = is_add;
6873 mp->br_route.br_tbl_id.bt_set = set;
6874 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6875 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6876 mp->br_route.br_bp = ntohs (bp);
6877 mp->br_route.br_n_paths = 1;
6878 mp->br_route.br_paths[0].n_labels = 1;
6879 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6880 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6881 FIB_API_PATH_NH_PROTO_IP4 :
6882 FIB_API_PATH_NH_PROTO_IP6);
6884 if (next_hop_proto_is_ip4)
6886 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6887 &v4_next_hop_address, sizeof (v4_next_hop_address));
6891 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6892 &v6_next_hop_address, sizeof (v6_next_hop_address));
6898 /* Wait for a reply... */
6905 api_mpls_tunnel_add_del (vat_main_t * vam)
6907 unformat_input_t *i = vam->input;
6908 vl_api_mpls_tunnel_add_del_t *mp;
6910 vl_api_fib_path_t paths[8];
6911 u32 sw_if_index = ~0;
6917 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6919 if (unformat (i, "add"))
6923 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6925 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6927 else if (unformat (i, "l2-only"))
6931 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6934 if (8 == path_count)
6936 errmsg ("max 8 paths");
6942 clib_warning ("parse error '%U'", format_unformat_error, i);
6947 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6949 mp->mt_is_add = is_add;
6950 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6951 mp->mt_tunnel.mt_l2_only = l2_only;
6952 mp->mt_tunnel.mt_is_multicast = 0;
6953 mp->mt_tunnel.mt_n_paths = path_count;
6955 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6956 sizeof (paths[0]) * path_count);
6964 api_sw_interface_set_unnumbered (vat_main_t * vam)
6966 unformat_input_t *i = vam->input;
6967 vl_api_sw_interface_set_unnumbered_t *mp;
6969 u32 unnum_sw_index = ~0;
6971 u8 sw_if_index_set = 0;
6974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6976 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6977 sw_if_index_set = 1;
6978 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6979 sw_if_index_set = 1;
6980 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6982 else if (unformat (i, "del"))
6986 clib_warning ("parse error '%U'", format_unformat_error, i);
6991 if (sw_if_index_set == 0)
6993 errmsg ("missing interface name or sw_if_index");
6997 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6999 mp->sw_if_index = ntohl (sw_if_index);
7000 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
7001 mp->is_add = is_add;
7010 api_create_vlan_subif (vat_main_t * vam)
7012 unformat_input_t *i = vam->input;
7013 vl_api_create_vlan_subif_t *mp;
7015 u8 sw_if_index_set = 0;
7020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7022 if (unformat (i, "sw_if_index %d", &sw_if_index))
7023 sw_if_index_set = 1;
7025 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7026 sw_if_index_set = 1;
7027 else if (unformat (i, "vlan %d", &vlan_id))
7031 clib_warning ("parse error '%U'", format_unformat_error, i);
7036 if (sw_if_index_set == 0)
7038 errmsg ("missing interface name or sw_if_index");
7042 if (vlan_id_set == 0)
7044 errmsg ("missing vlan_id");
7047 M (CREATE_VLAN_SUBIF, mp);
7049 mp->sw_if_index = ntohl (sw_if_index);
7050 mp->vlan_id = ntohl (vlan_id);
7057 #define foreach_create_subif_bit \
7064 _(outer_vlan_id_any) \
7065 _(inner_vlan_id_any)
7067 #define foreach_create_subif_flag \
7072 _(4, "exact_match") \
7073 _(5, "default_sub") \
7074 _(6, "outer_vlan_id_any") \
7075 _(7, "inner_vlan_id_any")
7078 api_create_subif (vat_main_t * vam)
7080 unformat_input_t *i = vam->input;
7081 vl_api_create_subif_t *mp;
7083 u8 sw_if_index_set = 0;
7086 u32 __attribute__ ((unused)) no_tags = 0;
7087 u32 __attribute__ ((unused)) one_tag = 0;
7088 u32 __attribute__ ((unused)) two_tags = 0;
7089 u32 __attribute__ ((unused)) dot1ad = 0;
7090 u32 __attribute__ ((unused)) exact_match = 0;
7091 u32 __attribute__ ((unused)) default_sub = 0;
7092 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7093 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7095 u16 outer_vlan_id = 0;
7096 u16 inner_vlan_id = 0;
7099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7101 if (unformat (i, "sw_if_index %d", &sw_if_index))
7102 sw_if_index_set = 1;
7104 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7105 sw_if_index_set = 1;
7106 else if (unformat (i, "sub_id %d", &sub_id))
7108 else if (unformat (i, "outer_vlan_id %d", &tmp))
7109 outer_vlan_id = tmp;
7110 else if (unformat (i, "inner_vlan_id %d", &tmp))
7111 inner_vlan_id = tmp;
7113 #define _(a) else if (unformat (i, #a)) a = 1 ;
7114 foreach_create_subif_bit
7118 clib_warning ("parse error '%U'", format_unformat_error, i);
7123 if (sw_if_index_set == 0)
7125 errmsg ("missing interface name or sw_if_index");
7129 if (sub_id_set == 0)
7131 errmsg ("missing sub_id");
7134 M (CREATE_SUBIF, mp);
7136 mp->sw_if_index = ntohl (sw_if_index);
7137 mp->sub_id = ntohl (sub_id);
7139 #define _(a,b) mp->sub_if_flags |= (1 << a);
7140 foreach_create_subif_flag;
7143 mp->outer_vlan_id = ntohs (outer_vlan_id);
7144 mp->inner_vlan_id = ntohs (inner_vlan_id);
7152 api_ip_table_replace_begin (vat_main_t * vam)
7154 unformat_input_t *i = vam->input;
7155 vl_api_ip_table_replace_begin_t *mp;
7160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7162 if (unformat (i, "table %d", &table_id))
7164 else if (unformat (i, "ipv6"))
7168 clib_warning ("parse error '%U'", format_unformat_error, i);
7173 M (IP_TABLE_REPLACE_BEGIN, mp);
7175 mp->table.table_id = ntohl (table_id);
7176 mp->table.is_ip6 = is_ipv6;
7184 api_ip_table_flush (vat_main_t * vam)
7186 unformat_input_t *i = vam->input;
7187 vl_api_ip_table_flush_t *mp;
7192 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7194 if (unformat (i, "table %d", &table_id))
7196 else if (unformat (i, "ipv6"))
7200 clib_warning ("parse error '%U'", format_unformat_error, i);
7205 M (IP_TABLE_FLUSH, mp);
7207 mp->table.table_id = ntohl (table_id);
7208 mp->table.is_ip6 = is_ipv6;
7216 api_ip_table_replace_end (vat_main_t * vam)
7218 unformat_input_t *i = vam->input;
7219 vl_api_ip_table_replace_end_t *mp;
7224 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7226 if (unformat (i, "table %d", &table_id))
7228 else if (unformat (i, "ipv6"))
7232 clib_warning ("parse error '%U'", format_unformat_error, i);
7237 M (IP_TABLE_REPLACE_END, mp);
7239 mp->table.table_id = ntohl (table_id);
7240 mp->table.is_ip6 = is_ipv6;
7248 api_set_ip_flow_hash (vat_main_t * vam)
7250 unformat_input_t *i = vam->input;
7251 vl_api_set_ip_flow_hash_t *mp;
7263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7265 if (unformat (i, "vrf %d", &vrf_id))
7267 else if (unformat (i, "ipv6"))
7269 else if (unformat (i, "src"))
7271 else if (unformat (i, "dst"))
7273 else if (unformat (i, "sport"))
7275 else if (unformat (i, "dport"))
7277 else if (unformat (i, "proto"))
7279 else if (unformat (i, "reverse"))
7284 clib_warning ("parse error '%U'", format_unformat_error, i);
7289 if (vrf_id_set == 0)
7291 errmsg ("missing vrf id");
7295 M (SET_IP_FLOW_HASH, mp);
7301 mp->reverse = reverse;
7302 mp->vrf_id = ntohl (vrf_id);
7303 mp->is_ipv6 = is_ipv6;
7311 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7313 unformat_input_t *i = vam->input;
7314 vl_api_sw_interface_ip6_enable_disable_t *mp;
7316 u8 sw_if_index_set = 0;
7320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7322 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7323 sw_if_index_set = 1;
7324 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7325 sw_if_index_set = 1;
7326 else if (unformat (i, "enable"))
7328 else if (unformat (i, "disable"))
7332 clib_warning ("parse error '%U'", format_unformat_error, i);
7337 if (sw_if_index_set == 0)
7339 errmsg ("missing interface name or sw_if_index");
7343 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7345 mp->sw_if_index = ntohl (sw_if_index);
7346 mp->enable = enable;
7355 api_l2_patch_add_del (vat_main_t * vam)
7357 unformat_input_t *i = vam->input;
7358 vl_api_l2_patch_add_del_t *mp;
7360 u8 rx_sw_if_index_set = 0;
7362 u8 tx_sw_if_index_set = 0;
7366 /* Parse args required to build the message */
7367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7369 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7370 rx_sw_if_index_set = 1;
7371 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7372 tx_sw_if_index_set = 1;
7373 else if (unformat (i, "rx"))
7375 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7377 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7379 rx_sw_if_index_set = 1;
7384 else if (unformat (i, "tx"))
7386 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7388 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7390 tx_sw_if_index_set = 1;
7395 else if (unformat (i, "del"))
7401 if (rx_sw_if_index_set == 0)
7403 errmsg ("missing rx interface name or rx_sw_if_index");
7407 if (tx_sw_if_index_set == 0)
7409 errmsg ("missing tx interface name or tx_sw_if_index");
7413 M (L2_PATCH_ADD_DEL, mp);
7415 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7416 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7417 mp->is_add = is_add;
7425 u8 localsid_addr[16];
7434 api_sr_localsid_add_del (vat_main_t * vam)
7436 unformat_input_t *i = vam->input;
7437 vl_api_sr_localsid_add_del_t *mp;
7440 ip6_address_t localsid;
7444 u32 fib_table = ~(u32) 0;
7445 ip46_address_t nh_addr;
7446 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7448 bool nexthop_set = 0;
7452 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7454 if (unformat (i, "del"))
7456 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7457 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7459 else if (unformat (i, "behavior %u", &behavior));
7460 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7461 else if (unformat (i, "fib-table %u", &fib_table));
7462 else if (unformat (i, "end.psp %u", &behavior));
7467 M (SR_LOCALSID_ADD_DEL, mp);
7469 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7473 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7475 mp->behavior = behavior;
7476 mp->sw_if_index = ntohl (sw_if_index);
7477 mp->fib_table = ntohl (fib_table);
7478 mp->end_psp = end_psp;
7479 mp->is_del = is_del;
7487 api_ioam_enable (vat_main_t * vam)
7489 unformat_input_t *input = vam->input;
7490 vl_api_ioam_enable_t *mp;
7492 int has_trace_option = 0;
7493 int has_pot_option = 0;
7494 int has_seqno_option = 0;
7495 int has_analyse_option = 0;
7498 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7500 if (unformat (input, "trace"))
7501 has_trace_option = 1;
7502 else if (unformat (input, "pot"))
7504 else if (unformat (input, "seqno"))
7505 has_seqno_option = 1;
7506 else if (unformat (input, "analyse"))
7507 has_analyse_option = 1;
7511 M (IOAM_ENABLE, mp);
7512 mp->id = htons (id);
7513 mp->seqno = has_seqno_option;
7514 mp->analyse = has_analyse_option;
7515 mp->pot_enable = has_pot_option;
7516 mp->trace_enable = has_trace_option;
7525 api_ioam_disable (vat_main_t * vam)
7527 vl_api_ioam_disable_t *mp;
7530 M (IOAM_DISABLE, mp);
7536 #define foreach_tcp_proto_field \
7540 #define foreach_udp_proto_field \
7544 #define foreach_ip4_proto_field \
7556 u16 src_port, dst_port;
7559 #if VPP_API_TEST_BUILTIN == 0
7561 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7563 u8 **maskp = va_arg (*args, u8 **);
7565 u8 found_something = 0;
7568 #define _(a) u8 a=0;
7569 foreach_tcp_proto_field;
7572 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7575 #define _(a) else if (unformat (input, #a)) a=1;
7576 foreach_tcp_proto_field
7582 #define _(a) found_something += a;
7583 foreach_tcp_proto_field;
7586 if (found_something == 0)
7589 vec_validate (mask, sizeof (*tcp) - 1);
7591 tcp = (tcp_header_t *) mask;
7593 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7594 foreach_tcp_proto_field;
7602 unformat_udp_mask (unformat_input_t * input, va_list * args)
7604 u8 **maskp = va_arg (*args, u8 **);
7606 u8 found_something = 0;
7609 #define _(a) u8 a=0;
7610 foreach_udp_proto_field;
7613 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7616 #define _(a) else if (unformat (input, #a)) a=1;
7617 foreach_udp_proto_field
7623 #define _(a) found_something += a;
7624 foreach_udp_proto_field;
7627 if (found_something == 0)
7630 vec_validate (mask, sizeof (*udp) - 1);
7632 udp = (udp_header_t *) mask;
7634 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7635 foreach_udp_proto_field;
7643 unformat_l4_mask (unformat_input_t * input, va_list * args)
7645 u8 **maskp = va_arg (*args, u8 **);
7646 u16 src_port = 0, dst_port = 0;
7647 tcpudp_header_t *tcpudp;
7649 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7651 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7653 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7655 else if (unformat (input, "src_port"))
7657 else if (unformat (input, "dst_port"))
7663 if (!src_port && !dst_port)
7667 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7669 tcpudp = (tcpudp_header_t *) mask;
7670 tcpudp->src_port = src_port;
7671 tcpudp->dst_port = dst_port;
7679 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7681 u8 **maskp = va_arg (*args, u8 **);
7683 u8 found_something = 0;
7686 #define _(a) u8 a=0;
7687 foreach_ip4_proto_field;
7693 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7695 if (unformat (input, "version"))
7697 else if (unformat (input, "hdr_length"))
7699 else if (unformat (input, "src"))
7701 else if (unformat (input, "dst"))
7703 else if (unformat (input, "proto"))
7706 #define _(a) else if (unformat (input, #a)) a=1;
7707 foreach_ip4_proto_field
7713 #define _(a) found_something += a;
7714 foreach_ip4_proto_field;
7717 if (found_something == 0)
7720 vec_validate (mask, sizeof (*ip) - 1);
7722 ip = (ip4_header_t *) mask;
7724 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7725 foreach_ip4_proto_field;
7728 ip->ip_version_and_header_length = 0;
7731 ip->ip_version_and_header_length |= 0xF0;
7734 ip->ip_version_and_header_length |= 0x0F;
7740 #define foreach_ip6_proto_field \
7748 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7750 u8 **maskp = va_arg (*args, u8 **);
7752 u8 found_something = 0;
7754 u32 ip_version_traffic_class_and_flow_label;
7756 #define _(a) u8 a=0;
7757 foreach_ip6_proto_field;
7760 u8 traffic_class = 0;
7763 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7765 if (unformat (input, "version"))
7767 else if (unformat (input, "traffic-class"))
7769 else if (unformat (input, "flow-label"))
7771 else if (unformat (input, "src"))
7773 else if (unformat (input, "dst"))
7775 else if (unformat (input, "proto"))
7778 #define _(a) else if (unformat (input, #a)) a=1;
7779 foreach_ip6_proto_field
7785 #define _(a) found_something += a;
7786 foreach_ip6_proto_field;
7789 if (found_something == 0)
7792 vec_validate (mask, sizeof (*ip) - 1);
7794 ip = (ip6_header_t *) mask;
7796 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7797 foreach_ip6_proto_field;
7800 ip_version_traffic_class_and_flow_label = 0;
7803 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7806 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7809 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7811 ip->ip_version_traffic_class_and_flow_label =
7812 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7819 unformat_l3_mask (unformat_input_t * input, va_list * args)
7821 u8 **maskp = va_arg (*args, u8 **);
7823 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7825 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7827 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7836 unformat_l2_mask (unformat_input_t * input, va_list * args)
7838 u8 **maskp = va_arg (*args, u8 **);
7853 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7855 if (unformat (input, "src"))
7857 else if (unformat (input, "dst"))
7859 else if (unformat (input, "proto"))
7861 else if (unformat (input, "tag1"))
7863 else if (unformat (input, "tag2"))
7865 else if (unformat (input, "ignore-tag1"))
7867 else if (unformat (input, "ignore-tag2"))
7869 else if (unformat (input, "cos1"))
7871 else if (unformat (input, "cos2"))
7873 else if (unformat (input, "dot1q"))
7875 else if (unformat (input, "dot1ad"))
7880 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7881 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7884 if (tag1 || ignore_tag1 || cos1 || dot1q)
7886 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7889 vec_validate (mask, len - 1);
7892 clib_memset (mask, 0xff, 6);
7895 clib_memset (mask + 6, 0xff, 6);
7899 /* inner vlan tag */
7908 mask[21] = mask[20] = 0xff;
7929 mask[16] = mask[17] = 0xff;
7939 mask[12] = mask[13] = 0xff;
7946 unformat_classify_mask (unformat_input_t * input, va_list * args)
7948 u8 **maskp = va_arg (*args, u8 **);
7949 u32 *skipp = va_arg (*args, u32 *);
7950 u32 *matchp = va_arg (*args, u32 *);
7958 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7960 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7962 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7964 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7966 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7980 if (mask || l2 || l3 || l4)
7984 /* "With a free Ethernet header in every package" */
7986 vec_validate (l2, 13);
7990 vec_append (mask, l3);
7995 vec_append (mask, l4);
8000 /* Scan forward looking for the first significant mask octet */
8001 for (i = 0; i < vec_len (mask); i++)
8005 /* compute (skip, match) params */
8006 *skipp = i / sizeof (u32x4);
8007 vec_delete (mask, *skipp * sizeof (u32x4), 0);
8009 /* Pad mask to an even multiple of the vector size */
8010 while (vec_len (mask) % sizeof (u32x4))
8013 match = vec_len (mask) / sizeof (u32x4);
8015 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8017 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8018 if (*tmp || *(tmp + 1))
8023 clib_warning ("BUG: match 0");
8025 _vec_len (mask) = match * sizeof (u32x4);
8035 #endif /* VPP_API_TEST_BUILTIN */
8037 #define foreach_l2_next \
8039 _(ethernet, ETHERNET_INPUT) \
8044 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8046 u32 *miss_next_indexp = va_arg (*args, u32 *);
8051 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8055 if (unformat (input, "%d", &tmp))
8064 *miss_next_indexp = next_index;
8068 #define foreach_ip_next \
8074 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8076 u32 *miss_next_indexp = va_arg (*args, u32 *);
8081 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8085 if (unformat (input, "%d", &tmp))
8094 *miss_next_indexp = next_index;
8098 #define foreach_acl_next \
8102 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8104 u32 *miss_next_indexp = va_arg (*args, u32 *);
8109 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8113 if (unformat (input, "permit"))
8118 else if (unformat (input, "%d", &tmp))
8127 *miss_next_indexp = next_index;
8132 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8134 u32 *r = va_arg (*args, u32 *);
8136 if (unformat (input, "conform-color"))
8137 *r = POLICE_CONFORM;
8138 else if (unformat (input, "exceed-color"))
8147 api_classify_add_del_table (vat_main_t * vam)
8149 unformat_input_t *i = vam->input;
8150 vl_api_classify_add_del_table_t *mp;
8157 u32 table_index = ~0;
8158 u32 next_table_index = ~0;
8159 u32 miss_next_index = ~0;
8160 u32 memory_size = 32 << 20;
8162 u32 current_data_flag = 0;
8163 int current_data_offset = 0;
8166 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8168 if (unformat (i, "del"))
8170 else if (unformat (i, "del-chain"))
8175 else if (unformat (i, "buckets %d", &nbuckets))
8177 else if (unformat (i, "memory_size %d", &memory_size))
8179 else if (unformat (i, "skip %d", &skip))
8181 else if (unformat (i, "match %d", &match))
8183 else if (unformat (i, "table %d", &table_index))
8185 else if (unformat (i, "mask %U", unformat_classify_mask,
8186 &mask, &skip, &match))
8188 else if (unformat (i, "next-table %d", &next_table_index))
8190 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8193 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8196 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8199 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8201 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8207 if (is_add && mask == 0)
8209 errmsg ("Mask required");
8213 if (is_add && skip == ~0)
8215 errmsg ("skip count required");
8219 if (is_add && match == ~0)
8221 errmsg ("match count required");
8225 if (!is_add && table_index == ~0)
8227 errmsg ("table index required for delete");
8231 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8233 mp->is_add = is_add;
8234 mp->del_chain = del_chain;
8235 mp->table_index = ntohl (table_index);
8236 mp->nbuckets = ntohl (nbuckets);
8237 mp->memory_size = ntohl (memory_size);
8238 mp->skip_n_vectors = ntohl (skip);
8239 mp->match_n_vectors = ntohl (match);
8240 mp->next_table_index = ntohl (next_table_index);
8241 mp->miss_next_index = ntohl (miss_next_index);
8242 mp->current_data_flag = ntohl (current_data_flag);
8243 mp->current_data_offset = ntohl (current_data_offset);
8244 mp->mask_len = ntohl (vec_len (mask));
8245 clib_memcpy (mp->mask, mask, vec_len (mask));
8254 #if VPP_API_TEST_BUILTIN == 0
8256 unformat_l4_match (unformat_input_t * input, va_list * args)
8258 u8 **matchp = va_arg (*args, u8 **);
8260 u8 *proto_header = 0;
8266 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8268 if (unformat (input, "src_port %d", &src_port))
8270 else if (unformat (input, "dst_port %d", &dst_port))
8276 h.src_port = clib_host_to_net_u16 (src_port);
8277 h.dst_port = clib_host_to_net_u16 (dst_port);
8278 vec_validate (proto_header, sizeof (h) - 1);
8279 memcpy (proto_header, &h, sizeof (h));
8281 *matchp = proto_header;
8287 unformat_ip4_match (unformat_input_t * input, va_list * args)
8289 u8 **matchp = va_arg (*args, u8 **);
8296 int src = 0, dst = 0;
8297 ip4_address_t src_val, dst_val;
8304 int fragment_id = 0;
8305 u32 fragment_id_val;
8311 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8313 if (unformat (input, "version %d", &version_val))
8315 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8317 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8319 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8321 else if (unformat (input, "proto %d", &proto_val))
8323 else if (unformat (input, "tos %d", &tos_val))
8325 else if (unformat (input, "length %d", &length_val))
8327 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8329 else if (unformat (input, "ttl %d", &ttl_val))
8331 else if (unformat (input, "checksum %d", &checksum_val))
8337 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8338 + ttl + checksum == 0)
8342 * Aligned because we use the real comparison functions
8344 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8346 ip = (ip4_header_t *) match;
8348 /* These are realistically matched in practice */
8350 ip->src_address.as_u32 = src_val.as_u32;
8353 ip->dst_address.as_u32 = dst_val.as_u32;
8356 ip->protocol = proto_val;
8359 /* These are not, but they're included for completeness */
8361 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8364 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8370 ip->length = clib_host_to_net_u16 (length_val);
8376 ip->checksum = clib_host_to_net_u16 (checksum_val);
8383 unformat_ip6_match (unformat_input_t * input, va_list * args)
8385 u8 **matchp = va_arg (*args, u8 **);
8390 u8 traffic_class = 0;
8391 u32 traffic_class_val = 0;
8394 int src = 0, dst = 0;
8395 ip6_address_t src_val, dst_val;
8398 int payload_length = 0;
8399 u32 payload_length_val;
8402 u32 ip_version_traffic_class_and_flow_label;
8404 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8406 if (unformat (input, "version %d", &version_val))
8408 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8410 else if (unformat (input, "flow_label %d", &flow_label_val))
8412 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8414 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8416 else if (unformat (input, "proto %d", &proto_val))
8418 else if (unformat (input, "payload_length %d", &payload_length_val))
8420 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8426 if (version + traffic_class + flow_label + src + dst + proto +
8427 payload_length + hop_limit == 0)
8431 * Aligned because we use the real comparison functions
8433 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8435 ip = (ip6_header_t *) match;
8438 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8441 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8444 ip->protocol = proto_val;
8446 ip_version_traffic_class_and_flow_label = 0;
8449 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8452 ip_version_traffic_class_and_flow_label |=
8453 (traffic_class_val & 0xFF) << 20;
8456 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8458 ip->ip_version_traffic_class_and_flow_label =
8459 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8462 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8465 ip->hop_limit = hop_limit_val;
8472 unformat_l3_match (unformat_input_t * input, va_list * args)
8474 u8 **matchp = va_arg (*args, u8 **);
8476 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8478 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8480 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8489 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8491 u8 *tagp = va_arg (*args, u8 *);
8494 if (unformat (input, "%d", &tag))
8496 tagp[0] = (tag >> 8) & 0x0F;
8497 tagp[1] = tag & 0xFF;
8505 unformat_l2_match (unformat_input_t * input, va_list * args)
8507 u8 **matchp = va_arg (*args, u8 **);
8527 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8529 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8532 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8534 else if (unformat (input, "proto %U",
8535 unformat_ethernet_type_host_byte_order, &proto_val))
8537 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8539 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8541 else if (unformat (input, "ignore-tag1"))
8543 else if (unformat (input, "ignore-tag2"))
8545 else if (unformat (input, "cos1 %d", &cos1_val))
8547 else if (unformat (input, "cos2 %d", &cos2_val))
8552 if ((src + dst + proto + tag1 + tag2 +
8553 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8556 if (tag1 || ignore_tag1 || cos1)
8558 if (tag2 || ignore_tag2 || cos2)
8561 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8564 clib_memcpy (match, dst_val, 6);
8567 clib_memcpy (match + 6, src_val, 6);
8571 /* inner vlan tag */
8572 match[19] = tag2_val[1];
8573 match[18] = tag2_val[0];
8575 match[18] |= (cos2_val & 0x7) << 5;
8578 match[21] = proto_val & 0xff;
8579 match[20] = proto_val >> 8;
8583 match[15] = tag1_val[1];
8584 match[14] = tag1_val[0];
8587 match[14] |= (cos1_val & 0x7) << 5;
8593 match[15] = tag1_val[1];
8594 match[14] = tag1_val[0];
8597 match[17] = proto_val & 0xff;
8598 match[16] = proto_val >> 8;
8601 match[14] |= (cos1_val & 0x7) << 5;
8607 match[18] |= (cos2_val & 0x7) << 5;
8609 match[14] |= (cos1_val & 0x7) << 5;
8612 match[13] = proto_val & 0xff;
8613 match[12] = proto_val >> 8;
8621 unformat_qos_source (unformat_input_t * input, va_list * args)
8623 int *qs = va_arg (*args, int *);
8625 if (unformat (input, "ip"))
8626 *qs = QOS_SOURCE_IP;
8627 else if (unformat (input, "mpls"))
8628 *qs = QOS_SOURCE_MPLS;
8629 else if (unformat (input, "ext"))
8630 *qs = QOS_SOURCE_EXT;
8631 else if (unformat (input, "vlan"))
8632 *qs = QOS_SOURCE_VLAN;
8641 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8643 u8 **matchp = va_arg (*args, u8 **);
8644 u32 skip_n_vectors = va_arg (*args, u32);
8645 u32 match_n_vectors = va_arg (*args, u32);
8652 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8654 if (unformat (input, "hex %U", unformat_hex_string, &match))
8656 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8658 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8660 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8674 if (match || l2 || l3 || l4)
8678 /* "Win a free Ethernet header in every packet" */
8680 vec_validate_aligned (l2, 13, sizeof (u32x4));
8684 vec_append_aligned (match, l3, sizeof (u32x4));
8689 vec_append_aligned (match, l4, sizeof (u32x4));
8694 /* Make sure the vector is big enough even if key is all 0's */
8695 vec_validate_aligned
8696 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8699 /* Set size, include skipped vectors */
8700 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8711 api_classify_add_del_session (vat_main_t * vam)
8713 unformat_input_t *i = vam->input;
8714 vl_api_classify_add_del_session_t *mp;
8716 u32 table_index = ~0;
8717 u32 hit_next_index = ~0;
8718 u32 opaque_index = ~0;
8721 u32 skip_n_vectors = 0;
8722 u32 match_n_vectors = 0;
8728 * Warning: you have to supply skip_n and match_n
8729 * because the API client cant simply look at the classify
8733 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8735 if (unformat (i, "del"))
8737 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8740 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8743 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8746 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8748 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8750 else if (unformat (i, "opaque-index %d", &opaque_index))
8752 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8754 else if (unformat (i, "match_n %d", &match_n_vectors))
8756 else if (unformat (i, "match %U", api_unformat_classify_match,
8757 &match, skip_n_vectors, match_n_vectors))
8759 else if (unformat (i, "advance %d", &advance))
8761 else if (unformat (i, "table-index %d", &table_index))
8763 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8765 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8767 else if (unformat (i, "action %d", &action))
8769 else if (unformat (i, "metadata %d", &metadata))
8775 if (table_index == ~0)
8777 errmsg ("Table index required");
8781 if (is_add && match == 0)
8783 errmsg ("Match value required");
8787 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8789 mp->is_add = is_add;
8790 mp->table_index = ntohl (table_index);
8791 mp->hit_next_index = ntohl (hit_next_index);
8792 mp->opaque_index = ntohl (opaque_index);
8793 mp->advance = ntohl (advance);
8794 mp->action = action;
8795 mp->metadata = ntohl (metadata);
8796 mp->match_len = ntohl (vec_len (match));
8797 clib_memcpy (mp->match, match, vec_len (match));
8806 api_classify_set_interface_ip_table (vat_main_t * vam)
8808 unformat_input_t *i = vam->input;
8809 vl_api_classify_set_interface_ip_table_t *mp;
8811 int sw_if_index_set;
8812 u32 table_index = ~0;
8816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8818 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8819 sw_if_index_set = 1;
8820 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8821 sw_if_index_set = 1;
8822 else if (unformat (i, "table %d", &table_index))
8826 clib_warning ("parse error '%U'", format_unformat_error, i);
8831 if (sw_if_index_set == 0)
8833 errmsg ("missing interface name or sw_if_index");
8838 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8840 mp->sw_if_index = ntohl (sw_if_index);
8841 mp->table_index = ntohl (table_index);
8842 mp->is_ipv6 = is_ipv6;
8850 api_classify_set_interface_l2_tables (vat_main_t * vam)
8852 unformat_input_t *i = vam->input;
8853 vl_api_classify_set_interface_l2_tables_t *mp;
8855 int sw_if_index_set;
8856 u32 ip4_table_index = ~0;
8857 u32 ip6_table_index = ~0;
8858 u32 other_table_index = ~0;
8862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8864 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8865 sw_if_index_set = 1;
8866 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8867 sw_if_index_set = 1;
8868 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8870 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8872 else if (unformat (i, "other-table %d", &other_table_index))
8874 else if (unformat (i, "is-input %d", &is_input))
8878 clib_warning ("parse error '%U'", format_unformat_error, i);
8883 if (sw_if_index_set == 0)
8885 errmsg ("missing interface name or sw_if_index");
8890 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8892 mp->sw_if_index = ntohl (sw_if_index);
8893 mp->ip4_table_index = ntohl (ip4_table_index);
8894 mp->ip6_table_index = ntohl (ip6_table_index);
8895 mp->other_table_index = ntohl (other_table_index);
8896 mp->is_input = (u8) is_input;
8904 api_set_ipfix_exporter (vat_main_t * vam)
8906 unformat_input_t *i = vam->input;
8907 vl_api_set_ipfix_exporter_t *mp;
8908 ip4_address_t collector_address;
8909 u8 collector_address_set = 0;
8910 u32 collector_port = ~0;
8911 ip4_address_t src_address;
8912 u8 src_address_set = 0;
8915 u32 template_interval = ~0;
8916 u8 udp_checksum = 0;
8919 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8921 if (unformat (i, "collector_address %U", unformat_ip4_address,
8922 &collector_address))
8923 collector_address_set = 1;
8924 else if (unformat (i, "collector_port %d", &collector_port))
8926 else if (unformat (i, "src_address %U", unformat_ip4_address,
8928 src_address_set = 1;
8929 else if (unformat (i, "vrf_id %d", &vrf_id))
8931 else if (unformat (i, "path_mtu %d", &path_mtu))
8933 else if (unformat (i, "template_interval %d", &template_interval))
8935 else if (unformat (i, "udp_checksum"))
8941 if (collector_address_set == 0)
8943 errmsg ("collector_address required");
8947 if (src_address_set == 0)
8949 errmsg ("src_address required");
8953 M (SET_IPFIX_EXPORTER, mp);
8955 memcpy (mp->collector_address.un.ip4, collector_address.data,
8956 sizeof (collector_address.data));
8957 mp->collector_port = htons ((u16) collector_port);
8958 memcpy (mp->src_address.un.ip4, src_address.data,
8959 sizeof (src_address.data));
8960 mp->vrf_id = htonl (vrf_id);
8961 mp->path_mtu = htonl (path_mtu);
8962 mp->template_interval = htonl (template_interval);
8963 mp->udp_checksum = udp_checksum;
8971 api_set_ipfix_classify_stream (vat_main_t * vam)
8973 unformat_input_t *i = vam->input;
8974 vl_api_set_ipfix_classify_stream_t *mp;
8976 u32 src_port = UDP_DST_PORT_ipfix;
8979 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8981 if (unformat (i, "domain %d", &domain_id))
8983 else if (unformat (i, "src_port %d", &src_port))
8987 errmsg ("unknown input `%U'", format_unformat_error, i);
8992 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8994 mp->domain_id = htonl (domain_id);
8995 mp->src_port = htons ((u16) src_port);
9003 api_ipfix_classify_table_add_del (vat_main_t * vam)
9005 unformat_input_t *i = vam->input;
9006 vl_api_ipfix_classify_table_add_del_t *mp;
9008 u32 classify_table_index = ~0;
9010 u8 transport_protocol = 255;
9013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9015 if (unformat (i, "add"))
9017 else if (unformat (i, "del"))
9019 else if (unformat (i, "table %d", &classify_table_index))
9021 else if (unformat (i, "ip4"))
9023 else if (unformat (i, "ip6"))
9025 else if (unformat (i, "tcp"))
9026 transport_protocol = 6;
9027 else if (unformat (i, "udp"))
9028 transport_protocol = 17;
9031 errmsg ("unknown input `%U'", format_unformat_error, i);
9038 errmsg ("expecting: add|del");
9041 if (classify_table_index == ~0)
9043 errmsg ("classifier table not specified");
9046 if (ip_version == 0)
9048 errmsg ("IP version not specified");
9052 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9054 mp->is_add = is_add;
9055 mp->table_id = htonl (classify_table_index);
9056 mp->ip_version = ip_version;
9057 mp->transport_protocol = transport_protocol;
9065 api_get_node_index (vat_main_t * vam)
9067 unformat_input_t *i = vam->input;
9068 vl_api_get_node_index_t *mp;
9072 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9074 if (unformat (i, "node %s", &name))
9081 errmsg ("node name required");
9084 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9086 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9090 M (GET_NODE_INDEX, mp);
9091 clib_memcpy (mp->node_name, name, vec_len (name));
9100 api_get_next_index (vat_main_t * vam)
9102 unformat_input_t *i = vam->input;
9103 vl_api_get_next_index_t *mp;
9104 u8 *node_name = 0, *next_node_name = 0;
9107 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9109 if (unformat (i, "node-name %s", &node_name))
9111 else if (unformat (i, "next-node-name %s", &next_node_name))
9117 errmsg ("node name required");
9120 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9122 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9126 if (next_node_name == 0)
9128 errmsg ("next node name required");
9131 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9133 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9137 M (GET_NEXT_INDEX, mp);
9138 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9139 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9140 vec_free (node_name);
9141 vec_free (next_node_name);
9149 api_add_node_next (vat_main_t * vam)
9151 unformat_input_t *i = vam->input;
9152 vl_api_add_node_next_t *mp;
9157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9159 if (unformat (i, "node %s", &name))
9161 else if (unformat (i, "next %s", &next))
9168 errmsg ("node name required");
9171 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9173 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9178 errmsg ("next node required");
9181 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9183 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9187 M (ADD_NODE_NEXT, mp);
9188 clib_memcpy (mp->node_name, name, vec_len (name));
9189 clib_memcpy (mp->next_name, next, vec_len (next));
9198 static void vl_api_sw_interface_tap_v2_details_t_handler
9199 (vl_api_sw_interface_tap_v2_details_t * mp)
9201 vat_main_t *vam = &vat_main;
9204 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9205 mp->host_ip4_prefix.len);
9207 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9208 mp->host_ip6_prefix.len);
9211 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9212 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9213 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9214 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9215 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9221 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9222 (vl_api_sw_interface_tap_v2_details_t * mp)
9224 vat_main_t *vam = &vat_main;
9225 vat_json_node_t *node = NULL;
9227 if (VAT_JSON_ARRAY != vam->json_tree.type)
9229 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9230 vat_json_init_array (&vam->json_tree);
9232 node = vat_json_array_add (&vam->json_tree);
9234 vat_json_init_object (node);
9235 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9236 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9237 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9238 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9239 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9240 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9241 vat_json_object_add_string_copy (node, "host_mac_addr",
9242 format (0, "%U", format_ethernet_address,
9243 &mp->host_mac_addr));
9244 vat_json_object_add_string_copy (node, "host_namespace",
9245 mp->host_namespace);
9246 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9247 vat_json_object_add_string_copy (node, "host_ip4_addr",
9248 format (0, "%U/%d", format_ip4_address,
9249 mp->host_ip4_prefix.address,
9250 mp->host_ip4_prefix.len));
9251 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9252 format (0, "%U/%d", format_ip6_address,
9253 mp->host_ip6_prefix.address,
9254 mp->host_ip6_prefix.len));
9259 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9261 vl_api_sw_interface_tap_v2_dump_t *mp;
9262 vl_api_control_ping_t *mp_ping;
9266 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9267 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9268 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9271 /* Get list of tap interfaces */
9272 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9275 /* Use a control ping for synchronization */
9276 MPING (CONTROL_PING, mp_ping);
9283 static void vl_api_sw_interface_virtio_pci_details_t_handler
9284 (vl_api_sw_interface_virtio_pci_details_t * mp)
9286 vat_main_t *vam = &vat_main;
9301 addr.domain = ntohs (mp->pci_addr.domain);
9302 addr.bus = mp->pci_addr.bus;
9303 addr.slot = mp->pci_addr.slot;
9304 addr.function = mp->pci_addr.function;
9306 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9307 addr.slot, addr.function);
9310 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9311 pci_addr, ntohl (mp->sw_if_index),
9312 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9313 format_ethernet_address, mp->mac_addr,
9314 clib_net_to_host_u64 (mp->features));
9315 vec_free (pci_addr);
9318 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9319 (vl_api_sw_interface_virtio_pci_details_t * mp)
9321 vat_main_t *vam = &vat_main;
9322 vat_json_node_t *node = NULL;
9323 vlib_pci_addr_t pci_addr;
9325 if (VAT_JSON_ARRAY != vam->json_tree.type)
9327 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9328 vat_json_init_array (&vam->json_tree);
9330 node = vat_json_array_add (&vam->json_tree);
9332 pci_addr.domain = ntohs (mp->pci_addr.domain);
9333 pci_addr.bus = mp->pci_addr.bus;
9334 pci_addr.slot = mp->pci_addr.slot;
9335 pci_addr.function = mp->pci_addr.function;
9337 vat_json_init_object (node);
9338 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9339 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9340 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9341 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9342 vat_json_object_add_uint (node, "features",
9343 clib_net_to_host_u64 (mp->features));
9344 vat_json_object_add_string_copy (node, "mac_addr",
9345 format (0, "%U", format_ethernet_address,
9350 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9352 vl_api_sw_interface_virtio_pci_dump_t *mp;
9353 vl_api_control_ping_t *mp_ping;
9357 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9358 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9359 "mac_addr", "features");
9361 /* Get list of tap interfaces */
9362 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9365 /* Use a control ping for synchronization */
9366 MPING (CONTROL_PING, mp_ping);
9374 api_vxlan_offload_rx (vat_main_t * vam)
9376 unformat_input_t *line_input = vam->input;
9377 vl_api_vxlan_offload_rx_t *mp;
9378 u32 hw_if_index = ~0, rx_if_index = ~0;
9382 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9384 if (unformat (line_input, "del"))
9386 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9389 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9391 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9394 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9398 errmsg ("parse error '%U'", format_unformat_error, line_input);
9403 if (hw_if_index == ~0)
9405 errmsg ("no hw interface");
9409 if (rx_if_index == ~0)
9411 errmsg ("no rx tunnel");
9415 M (VXLAN_OFFLOAD_RX, mp);
9417 mp->hw_if_index = ntohl (hw_if_index);
9418 mp->sw_if_index = ntohl (rx_if_index);
9419 mp->enable = is_add;
9426 static uword unformat_vxlan_decap_next
9427 (unformat_input_t * input, va_list * args)
9429 u32 *result = va_arg (*args, u32 *);
9432 if (unformat (input, "l2"))
9433 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9434 else if (unformat (input, "%d", &tmp))
9442 api_vxlan_add_del_tunnel (vat_main_t * vam)
9444 unformat_input_t *line_input = vam->input;
9445 vl_api_vxlan_add_del_tunnel_t *mp;
9446 ip46_address_t src, dst;
9448 u8 ipv4_set = 0, ipv6_set = 0;
9453 u32 mcast_sw_if_index = ~0;
9454 u32 encap_vrf_id = 0;
9455 u32 decap_next_index = ~0;
9459 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9460 clib_memset (&src, 0, sizeof src);
9461 clib_memset (&dst, 0, sizeof dst);
9463 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9465 if (unformat (line_input, "del"))
9467 else if (unformat (line_input, "instance %d", &instance))
9470 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9476 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9482 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9488 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9493 else if (unformat (line_input, "group %U %U",
9494 unformat_ip4_address, &dst.ip4,
9495 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9497 grp_set = dst_set = 1;
9500 else if (unformat (line_input, "group %U",
9501 unformat_ip4_address, &dst.ip4))
9503 grp_set = dst_set = 1;
9506 else if (unformat (line_input, "group %U %U",
9507 unformat_ip6_address, &dst.ip6,
9508 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9510 grp_set = dst_set = 1;
9513 else if (unformat (line_input, "group %U",
9514 unformat_ip6_address, &dst.ip6))
9516 grp_set = dst_set = 1;
9520 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9522 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9524 else if (unformat (line_input, "decap-next %U",
9525 unformat_vxlan_decap_next, &decap_next_index))
9527 else if (unformat (line_input, "vni %d", &vni))
9531 errmsg ("parse error '%U'", format_unformat_error, line_input);
9538 errmsg ("tunnel src address not specified");
9543 errmsg ("tunnel dst address not specified");
9547 if (grp_set && !ip46_address_is_multicast (&dst))
9549 errmsg ("tunnel group address not multicast");
9552 if (grp_set && mcast_sw_if_index == ~0)
9554 errmsg ("tunnel nonexistent multicast device");
9557 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9559 errmsg ("tunnel dst address must be unicast");
9564 if (ipv4_set && ipv6_set)
9566 errmsg ("both IPv4 and IPv6 addresses specified");
9570 if ((vni == 0) || (vni >> 24))
9572 errmsg ("vni not specified or out of range");
9576 M (VXLAN_ADD_DEL_TUNNEL, mp);
9580 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9581 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9585 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9586 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9588 mp->src_address.af = ipv6_set;
9589 mp->dst_address.af = ipv6_set;
9591 mp->instance = htonl (instance);
9592 mp->encap_vrf_id = ntohl (encap_vrf_id);
9593 mp->decap_next_index = ntohl (decap_next_index);
9594 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9595 mp->vni = ntohl (vni);
9596 mp->is_add = is_add;
9603 static void vl_api_vxlan_tunnel_details_t_handler
9604 (vl_api_vxlan_tunnel_details_t * mp)
9606 vat_main_t *vam = &vat_main;
9607 ip46_address_t src =
9608 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9609 ip46_address_t dst =
9610 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9612 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9613 ntohl (mp->sw_if_index),
9614 ntohl (mp->instance),
9615 format_ip46_address, &src, IP46_TYPE_ANY,
9616 format_ip46_address, &dst, IP46_TYPE_ANY,
9617 ntohl (mp->encap_vrf_id),
9618 ntohl (mp->decap_next_index), ntohl (mp->vni),
9619 ntohl (mp->mcast_sw_if_index));
9622 static void vl_api_vxlan_tunnel_details_t_handler_json
9623 (vl_api_vxlan_tunnel_details_t * mp)
9625 vat_main_t *vam = &vat_main;
9626 vat_json_node_t *node = NULL;
9628 if (VAT_JSON_ARRAY != vam->json_tree.type)
9630 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9631 vat_json_init_array (&vam->json_tree);
9633 node = vat_json_array_add (&vam->json_tree);
9635 vat_json_init_object (node);
9636 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9638 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9640 if (mp->src_address.af)
9642 struct in6_addr ip6;
9644 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9645 vat_json_object_add_ip6 (node, "src_address", ip6);
9646 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9647 vat_json_object_add_ip6 (node, "dst_address", ip6);
9653 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9654 vat_json_object_add_ip4 (node, "src_address", ip4);
9655 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9656 vat_json_object_add_ip4 (node, "dst_address", ip4);
9658 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9659 vat_json_object_add_uint (node, "decap_next_index",
9660 ntohl (mp->decap_next_index));
9661 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9662 vat_json_object_add_uint (node, "mcast_sw_if_index",
9663 ntohl (mp->mcast_sw_if_index));
9667 api_vxlan_tunnel_dump (vat_main_t * vam)
9669 unformat_input_t *i = vam->input;
9670 vl_api_vxlan_tunnel_dump_t *mp;
9671 vl_api_control_ping_t *mp_ping;
9673 u8 sw_if_index_set = 0;
9676 /* Parse args required to build the message */
9677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9679 if (unformat (i, "sw_if_index %d", &sw_if_index))
9680 sw_if_index_set = 1;
9685 if (sw_if_index_set == 0)
9690 if (!vam->json_output)
9692 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9693 "sw_if_index", "instance", "src_address", "dst_address",
9694 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9697 /* Get list of vxlan-tunnel interfaces */
9698 M (VXLAN_TUNNEL_DUMP, mp);
9700 mp->sw_if_index = htonl (sw_if_index);
9704 /* Use a control ping for synchronization */
9705 MPING (CONTROL_PING, mp_ping);
9713 api_gre_tunnel_add_del (vat_main_t * vam)
9715 unformat_input_t *line_input = vam->input;
9716 vl_api_address_t src = { }, dst =
9719 vl_api_gre_tunnel_add_del_t *mp;
9720 vl_api_gre_tunnel_type_t t_type;
9724 u32 outer_table_id = 0;
9729 t_type = GRE_API_TUNNEL_TYPE_L3;
9731 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9733 if (unformat (line_input, "del"))
9735 else if (unformat (line_input, "instance %d", &instance))
9737 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
9741 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
9745 else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
9747 else if (unformat (line_input, "teb"))
9748 t_type = GRE_API_TUNNEL_TYPE_TEB;
9749 else if (unformat (line_input, "erspan %d", &session_id))
9750 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
9753 errmsg ("parse error '%U'", format_unformat_error, line_input);
9760 errmsg ("tunnel src address not specified");
9765 errmsg ("tunnel dst address not specified");
9769 M (GRE_TUNNEL_ADD_DEL, mp);
9771 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
9772 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
9774 mp->tunnel.instance = htonl (instance);
9775 mp->tunnel.outer_table_id = htonl (outer_table_id);
9776 mp->is_add = is_add;
9777 mp->tunnel.session_id = htons ((u16) session_id);
9778 mp->tunnel.type = htonl (t_type);
9785 static void vl_api_gre_tunnel_details_t_handler
9786 (vl_api_gre_tunnel_details_t * mp)
9788 vat_main_t *vam = &vat_main;
9790 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
9791 ntohl (mp->tunnel.sw_if_index),
9792 ntohl (mp->tunnel.instance),
9793 format_vl_api_address, &mp->tunnel.src,
9794 format_vl_api_address, &mp->tunnel.dst,
9795 mp->tunnel.type, ntohl (mp->tunnel.outer_table_id),
9796 ntohl (mp->tunnel.session_id));
9799 static void vl_api_gre_tunnel_details_t_handler_json
9800 (vl_api_gre_tunnel_details_t * mp)
9802 vat_main_t *vam = &vat_main;
9803 vat_json_node_t *node = NULL;
9805 if (VAT_JSON_ARRAY != vam->json_tree.type)
9807 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9808 vat_json_init_array (&vam->json_tree);
9810 node = vat_json_array_add (&vam->json_tree);
9812 vat_json_init_object (node);
9813 vat_json_object_add_uint (node, "sw_if_index",
9814 ntohl (mp->tunnel.sw_if_index));
9815 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
9817 vat_json_object_add_address (node, "src", &mp->tunnel.src);
9818 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
9819 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
9820 vat_json_object_add_uint (node, "outer_table_id",
9821 ntohl (mp->tunnel.outer_table_id));
9822 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
9826 api_gre_tunnel_dump (vat_main_t * vam)
9828 unformat_input_t *i = vam->input;
9829 vl_api_gre_tunnel_dump_t *mp;
9830 vl_api_control_ping_t *mp_ping;
9832 u8 sw_if_index_set = 0;
9835 /* Parse args required to build the message */
9836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9838 if (unformat (i, "sw_if_index %d", &sw_if_index))
9839 sw_if_index_set = 1;
9844 if (sw_if_index_set == 0)
9849 if (!vam->json_output)
9851 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
9852 "sw_if_index", "instance", "src_address", "dst_address",
9853 "tunnel_type", "outer_fib_id", "session_id");
9856 /* Get list of gre-tunnel interfaces */
9857 M (GRE_TUNNEL_DUMP, mp);
9859 mp->sw_if_index = htonl (sw_if_index);
9863 /* Use a control ping for synchronization */
9864 MPING (CONTROL_PING, mp_ping);
9872 api_l2_fib_clear_table (vat_main_t * vam)
9874 // unformat_input_t * i = vam->input;
9875 vl_api_l2_fib_clear_table_t *mp;
9878 M (L2_FIB_CLEAR_TABLE, mp);
9886 api_l2_interface_efp_filter (vat_main_t * vam)
9888 unformat_input_t *i = vam->input;
9889 vl_api_l2_interface_efp_filter_t *mp;
9892 u8 sw_if_index_set = 0;
9895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9897 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9898 sw_if_index_set = 1;
9899 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9900 sw_if_index_set = 1;
9901 else if (unformat (i, "enable"))
9903 else if (unformat (i, "disable"))
9907 clib_warning ("parse error '%U'", format_unformat_error, i);
9912 if (sw_if_index_set == 0)
9914 errmsg ("missing sw_if_index");
9918 M (L2_INTERFACE_EFP_FILTER, mp);
9920 mp->sw_if_index = ntohl (sw_if_index);
9921 mp->enable_disable = enable;
9928 #define foreach_vtr_op \
9929 _("disable", L2_VTR_DISABLED) \
9930 _("push-1", L2_VTR_PUSH_1) \
9931 _("push-2", L2_VTR_PUSH_2) \
9932 _("pop-1", L2_VTR_POP_1) \
9933 _("pop-2", L2_VTR_POP_2) \
9934 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9935 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9936 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9937 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9940 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9942 unformat_input_t *i = vam->input;
9943 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9945 u8 sw_if_index_set = 0;
9953 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9955 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9956 sw_if_index_set = 1;
9957 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9958 sw_if_index_set = 1;
9959 else if (unformat (i, "vtr_op %d", &vtr_op))
9961 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9964 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9966 else if (unformat (i, "tag1 %d", &tag1))
9968 else if (unformat (i, "tag2 %d", &tag2))
9972 clib_warning ("parse error '%U'", format_unformat_error, i);
9977 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9979 errmsg ("missing vtr operation or sw_if_index");
9983 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9984 mp->sw_if_index = ntohl (sw_if_index);
9985 mp->vtr_op = ntohl (vtr_op);
9986 mp->push_dot1q = ntohl (push_dot1q);
9987 mp->tag1 = ntohl (tag1);
9988 mp->tag2 = ntohl (tag2);
9996 api_create_vhost_user_if (vat_main_t * vam)
9998 unformat_input_t *i = vam->input;
9999 vl_api_create_vhost_user_if_t *mp;
10002 u8 file_name_set = 0;
10003 u32 custom_dev_instance = ~0;
10005 u8 use_custom_mac = 0;
10006 u8 disable_mrg_rxbuf = 0;
10007 u8 disable_indirect_desc = 0;
10010 u8 enable_packed = 0;
10013 /* Shut up coverity */
10014 clib_memset (hwaddr, 0, sizeof (hwaddr));
10016 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10018 if (unformat (i, "socket %s", &file_name))
10022 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10024 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
10025 use_custom_mac = 1;
10026 else if (unformat (i, "server"))
10028 else if (unformat (i, "disable_mrg_rxbuf"))
10029 disable_mrg_rxbuf = 1;
10030 else if (unformat (i, "disable_indirect_desc"))
10031 disable_indirect_desc = 1;
10032 else if (unformat (i, "gso"))
10034 else if (unformat (i, "packed"))
10036 else if (unformat (i, "tag %s", &tag))
10042 if (file_name_set == 0)
10044 errmsg ("missing socket file name");
10048 if (vec_len (file_name) > 255)
10050 errmsg ("socket file name too long");
10053 vec_add1 (file_name, 0);
10055 M (CREATE_VHOST_USER_IF, mp);
10057 mp->is_server = is_server;
10058 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
10059 mp->disable_indirect_desc = disable_indirect_desc;
10060 mp->enable_gso = enable_gso;
10061 mp->enable_packed = enable_packed;
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->custom_dev_instance = ntohl (custom_dev_instance);
10070 mp->use_custom_mac = use_custom_mac;
10071 clib_memcpy (mp->mac_address, hwaddr, 6);
10073 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10082 api_modify_vhost_user_if (vat_main_t * vam)
10084 unformat_input_t *i = vam->input;
10085 vl_api_modify_vhost_user_if_t *mp;
10088 u8 file_name_set = 0;
10089 u32 custom_dev_instance = ~0;
10090 u8 sw_if_index_set = 0;
10091 u32 sw_if_index = (u32) ~ 0;
10093 u8 enable_packed = 0;
10096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10098 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10099 sw_if_index_set = 1;
10100 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10101 sw_if_index_set = 1;
10102 else if (unformat (i, "socket %s", &file_name))
10106 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10108 else if (unformat (i, "server"))
10110 else if (unformat (i, "gso"))
10112 else if (unformat (i, "packed"))
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, 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 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10144 vec_free (file_name);
10145 if (custom_dev_instance != ~0)
10148 mp->custom_dev_instance = ntohl (custom_dev_instance);
10157 api_delete_vhost_user_if (vat_main_t * vam)
10159 unformat_input_t *i = vam->input;
10160 vl_api_delete_vhost_user_if_t *mp;
10161 u32 sw_if_index = ~0;
10162 u8 sw_if_index_set = 0;
10165 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10167 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10168 sw_if_index_set = 1;
10169 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10170 sw_if_index_set = 1;
10175 if (sw_if_index_set == 0)
10177 errmsg ("missing sw_if_index or interface name");
10182 M (DELETE_VHOST_USER_IF, mp);
10184 mp->sw_if_index = ntohl (sw_if_index);
10191 static void vl_api_sw_interface_vhost_user_details_t_handler
10192 (vl_api_sw_interface_vhost_user_details_t * mp)
10194 vat_main_t *vam = &vat_main;
10198 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10199 clib_net_to_host_u32
10200 (mp->features_last_32) <<
10203 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
10204 (char *) mp->interface_name,
10205 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10206 features, mp->is_server,
10207 ntohl (mp->num_regions), (char *) mp->sock_filename);
10208 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10211 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10212 (vl_api_sw_interface_vhost_user_details_t * mp)
10214 vat_main_t *vam = &vat_main;
10215 vat_json_node_t *node = NULL;
10217 if (VAT_JSON_ARRAY != vam->json_tree.type)
10219 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10220 vat_json_init_array (&vam->json_tree);
10222 node = vat_json_array_add (&vam->json_tree);
10224 vat_json_init_object (node);
10225 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10226 vat_json_object_add_string_copy (node, "interface_name",
10227 mp->interface_name);
10228 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10229 ntohl (mp->virtio_net_hdr_sz));
10230 vat_json_object_add_uint (node, "features_first_32",
10231 clib_net_to_host_u32 (mp->features_first_32));
10232 vat_json_object_add_uint (node, "features_last_32",
10233 clib_net_to_host_u32 (mp->features_last_32));
10234 vat_json_object_add_uint (node, "is_server", mp->is_server);
10235 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10236 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10237 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10241 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10243 unformat_input_t *i = vam->input;
10244 vl_api_sw_interface_vhost_user_dump_t *mp;
10245 vl_api_control_ping_t *mp_ping;
10247 u32 sw_if_index = ~0;
10249 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10251 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10253 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10260 "Interface name idx hdr_sz features server regions filename");
10262 /* Get list of vhost-user interfaces */
10263 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10264 mp->sw_if_index = ntohl (sw_if_index);
10267 /* Use a control ping for synchronization */
10268 MPING (CONTROL_PING, mp_ping);
10276 api_show_version (vat_main_t * vam)
10278 vl_api_show_version_t *mp;
10281 M (SHOW_VERSION, mp);
10290 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10292 unformat_input_t *line_input = vam->input;
10293 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10294 ip46_address_t local, remote;
10299 u32 mcast_sw_if_index = ~0;
10300 u32 encap_vrf_id = 0;
10301 u32 decap_vrf_id = 0;
10307 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10309 if (unformat (line_input, "del"))
10311 else if (unformat (line_input, "local %U",
10312 unformat_ip46_address, &local))
10316 else if (unformat (line_input, "remote %U",
10317 unformat_ip46_address, &remote))
10321 else if (unformat (line_input, "group %U %U",
10322 unformat_ip46_address, &remote,
10323 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10325 grp_set = remote_set = 1;
10327 else if (unformat (line_input, "group %U",
10328 unformat_ip46_address, &remote))
10330 grp_set = remote_set = 1;
10333 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10335 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10337 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10339 else if (unformat (line_input, "vni %d", &vni))
10341 else if (unformat (line_input, "next-ip4"))
10343 else if (unformat (line_input, "next-ip6"))
10345 else if (unformat (line_input, "next-ethernet"))
10347 else if (unformat (line_input, "next-nsh"))
10351 errmsg ("parse error '%U'", format_unformat_error, line_input);
10356 if (local_set == 0)
10358 errmsg ("tunnel local address not specified");
10361 if (remote_set == 0)
10363 errmsg ("tunnel remote address not specified");
10366 if (grp_set && mcast_sw_if_index == ~0)
10368 errmsg ("tunnel nonexistent multicast device");
10371 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10373 errmsg ("both IPv4 and IPv6 addresses specified");
10379 errmsg ("vni not specified");
10383 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10385 ip_address_encode (&local,
10386 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10387 IP46_TYPE_IP6, &mp->local);
10388 ip_address_encode (&remote,
10389 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10390 IP46_TYPE_IP6, &mp->remote);
10392 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10393 mp->encap_vrf_id = ntohl (encap_vrf_id);
10394 mp->decap_vrf_id = ntohl (decap_vrf_id);
10395 mp->protocol = protocol;
10396 mp->vni = ntohl (vni);
10397 mp->is_add = is_add;
10404 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10405 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10407 vat_main_t *vam = &vat_main;
10408 ip46_address_t local, remote;
10410 ip_address_decode (&mp->local, &local);
10411 ip_address_decode (&mp->remote, &remote);
10413 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10414 ntohl (mp->sw_if_index),
10415 format_ip46_address, &local, IP46_TYPE_ANY,
10416 format_ip46_address, &remote, IP46_TYPE_ANY,
10417 ntohl (mp->vni), mp->protocol,
10418 ntohl (mp->mcast_sw_if_index),
10419 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10423 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10424 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10426 vat_main_t *vam = &vat_main;
10427 vat_json_node_t *node = NULL;
10428 struct in_addr ip4;
10429 struct in6_addr ip6;
10430 ip46_address_t local, remote;
10432 ip_address_decode (&mp->local, &local);
10433 ip_address_decode (&mp->remote, &remote);
10435 if (VAT_JSON_ARRAY != vam->json_tree.type)
10437 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10438 vat_json_init_array (&vam->json_tree);
10440 node = vat_json_array_add (&vam->json_tree);
10442 vat_json_init_object (node);
10443 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10444 if (ip46_address_is_ip4 (&local))
10446 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10447 vat_json_object_add_ip4 (node, "local", ip4);
10448 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10449 vat_json_object_add_ip4 (node, "remote", ip4);
10453 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10454 vat_json_object_add_ip6 (node, "local", ip6);
10455 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10456 vat_json_object_add_ip6 (node, "remote", ip6);
10458 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10459 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10460 vat_json_object_add_uint (node, "mcast_sw_if_index",
10461 ntohl (mp->mcast_sw_if_index));
10462 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10463 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10464 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10468 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10470 unformat_input_t *i = vam->input;
10471 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10472 vl_api_control_ping_t *mp_ping;
10474 u8 sw_if_index_set = 0;
10477 /* Parse args required to build the message */
10478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10480 if (unformat (i, "sw_if_index %d", &sw_if_index))
10481 sw_if_index_set = 1;
10486 if (sw_if_index_set == 0)
10491 if (!vam->json_output)
10493 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10494 "sw_if_index", "local", "remote", "vni",
10495 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10498 /* Get list of vxlan-tunnel interfaces */
10499 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10501 mp->sw_if_index = htonl (sw_if_index);
10505 /* Use a control ping for synchronization */
10506 MPING (CONTROL_PING, mp_ping);
10513 static void vl_api_l2_fib_table_details_t_handler
10514 (vl_api_l2_fib_table_details_t * mp)
10516 vat_main_t *vam = &vat_main;
10518 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10520 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10521 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10525 static void vl_api_l2_fib_table_details_t_handler_json
10526 (vl_api_l2_fib_table_details_t * mp)
10528 vat_main_t *vam = &vat_main;
10529 vat_json_node_t *node = NULL;
10531 if (VAT_JSON_ARRAY != vam->json_tree.type)
10533 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10534 vat_json_init_array (&vam->json_tree);
10536 node = vat_json_array_add (&vam->json_tree);
10538 vat_json_init_object (node);
10539 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10540 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10541 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10542 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10543 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10544 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10548 api_l2_fib_table_dump (vat_main_t * vam)
10550 unformat_input_t *i = vam->input;
10551 vl_api_l2_fib_table_dump_t *mp;
10552 vl_api_control_ping_t *mp_ping;
10557 /* Parse args required to build the message */
10558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10560 if (unformat (i, "bd_id %d", &bd_id))
10566 if (bd_id_set == 0)
10568 errmsg ("missing bridge domain");
10572 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10574 /* Get list of l2 fib entries */
10575 M (L2_FIB_TABLE_DUMP, mp);
10577 mp->bd_id = ntohl (bd_id);
10580 /* Use a control ping for synchronization */
10581 MPING (CONTROL_PING, mp_ping);
10590 api_interface_name_renumber (vat_main_t * vam)
10592 unformat_input_t *line_input = vam->input;
10593 vl_api_interface_name_renumber_t *mp;
10594 u32 sw_if_index = ~0;
10595 u32 new_show_dev_instance = ~0;
10598 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10600 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10603 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10605 else if (unformat (line_input, "new_show_dev_instance %d",
10606 &new_show_dev_instance))
10612 if (sw_if_index == ~0)
10614 errmsg ("missing interface name or sw_if_index");
10618 if (new_show_dev_instance == ~0)
10620 errmsg ("missing new_show_dev_instance");
10624 M (INTERFACE_NAME_RENUMBER, mp);
10626 mp->sw_if_index = ntohl (sw_if_index);
10627 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10635 api_want_l2_macs_events (vat_main_t * vam)
10637 unformat_input_t *line_input = vam->input;
10638 vl_api_want_l2_macs_events_t *mp;
10639 u8 enable_disable = 1;
10640 u32 scan_delay = 0;
10641 u32 max_macs_in_event = 0;
10642 u32 learn_limit = 0;
10645 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10647 if (unformat (line_input, "learn-limit %d", &learn_limit))
10649 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10651 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10653 else if (unformat (line_input, "disable"))
10654 enable_disable = 0;
10659 M (WANT_L2_MACS_EVENTS, mp);
10660 mp->enable_disable = enable_disable;
10661 mp->pid = htonl (getpid ());
10662 mp->learn_limit = htonl (learn_limit);
10663 mp->scan_delay = (u8) scan_delay;
10664 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10671 api_input_acl_set_interface (vat_main_t * vam)
10673 unformat_input_t *i = vam->input;
10674 vl_api_input_acl_set_interface_t *mp;
10676 int sw_if_index_set;
10677 u32 ip4_table_index = ~0;
10678 u32 ip6_table_index = ~0;
10679 u32 l2_table_index = ~0;
10683 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10685 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10686 sw_if_index_set = 1;
10687 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10688 sw_if_index_set = 1;
10689 else if (unformat (i, "del"))
10691 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10693 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10695 else if (unformat (i, "l2-table %d", &l2_table_index))
10699 clib_warning ("parse error '%U'", format_unformat_error, i);
10704 if (sw_if_index_set == 0)
10706 errmsg ("missing interface name or sw_if_index");
10710 M (INPUT_ACL_SET_INTERFACE, mp);
10712 mp->sw_if_index = ntohl (sw_if_index);
10713 mp->ip4_table_index = ntohl (ip4_table_index);
10714 mp->ip6_table_index = ntohl (ip6_table_index);
10715 mp->l2_table_index = ntohl (l2_table_index);
10716 mp->is_add = is_add;
10724 api_output_acl_set_interface (vat_main_t * vam)
10726 unformat_input_t *i = vam->input;
10727 vl_api_output_acl_set_interface_t *mp;
10729 int sw_if_index_set;
10730 u32 ip4_table_index = ~0;
10731 u32 ip6_table_index = ~0;
10732 u32 l2_table_index = ~0;
10736 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10738 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10739 sw_if_index_set = 1;
10740 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10741 sw_if_index_set = 1;
10742 else if (unformat (i, "del"))
10744 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10746 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10748 else if (unformat (i, "l2-table %d", &l2_table_index))
10752 clib_warning ("parse error '%U'", format_unformat_error, i);
10757 if (sw_if_index_set == 0)
10759 errmsg ("missing interface name or sw_if_index");
10763 M (OUTPUT_ACL_SET_INTERFACE, mp);
10765 mp->sw_if_index = ntohl (sw_if_index);
10766 mp->ip4_table_index = ntohl (ip4_table_index);
10767 mp->ip6_table_index = ntohl (ip6_table_index);
10768 mp->l2_table_index = ntohl (l2_table_index);
10769 mp->is_add = is_add;
10777 api_ip_address_dump (vat_main_t * vam)
10779 unformat_input_t *i = vam->input;
10780 vl_api_ip_address_dump_t *mp;
10781 vl_api_control_ping_t *mp_ping;
10782 u32 sw_if_index = ~0;
10783 u8 sw_if_index_set = 0;
10788 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10790 if (unformat (i, "sw_if_index %d", &sw_if_index))
10791 sw_if_index_set = 1;
10793 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10794 sw_if_index_set = 1;
10795 else if (unformat (i, "ipv4"))
10797 else if (unformat (i, "ipv6"))
10803 if (ipv4_set && ipv6_set)
10805 errmsg ("ipv4 and ipv6 flags cannot be both set");
10809 if ((!ipv4_set) && (!ipv6_set))
10811 errmsg ("no ipv4 nor ipv6 flag set");
10815 if (sw_if_index_set == 0)
10817 errmsg ("missing interface name or sw_if_index");
10821 vam->current_sw_if_index = sw_if_index;
10822 vam->is_ipv6 = ipv6_set;
10824 M (IP_ADDRESS_DUMP, mp);
10825 mp->sw_if_index = ntohl (sw_if_index);
10826 mp->is_ipv6 = ipv6_set;
10829 /* Use a control ping for synchronization */
10830 MPING (CONTROL_PING, mp_ping);
10838 api_ip_dump (vat_main_t * vam)
10840 vl_api_ip_dump_t *mp;
10841 vl_api_control_ping_t *mp_ping;
10842 unformat_input_t *in = vam->input;
10849 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10851 if (unformat (in, "ipv4"))
10853 else if (unformat (in, "ipv6"))
10859 if (ipv4_set && ipv6_set)
10861 errmsg ("ipv4 and ipv6 flags cannot be both set");
10865 if ((!ipv4_set) && (!ipv6_set))
10867 errmsg ("no ipv4 nor ipv6 flag set");
10871 is_ipv6 = ipv6_set;
10872 vam->is_ipv6 = is_ipv6;
10874 /* free old data */
10875 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10877 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10879 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10882 mp->is_ipv6 = ipv6_set;
10885 /* Use a control ping for synchronization */
10886 MPING (CONTROL_PING, mp_ping);
10894 api_ipsec_spd_add_del (vat_main_t * vam)
10896 unformat_input_t *i = vam->input;
10897 vl_api_ipsec_spd_add_del_t *mp;
10902 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10904 if (unformat (i, "spd_id %d", &spd_id))
10906 else if (unformat (i, "del"))
10910 clib_warning ("parse error '%U'", format_unformat_error, i);
10916 errmsg ("spd_id must be set");
10920 M (IPSEC_SPD_ADD_DEL, mp);
10922 mp->spd_id = ntohl (spd_id);
10923 mp->is_add = is_add;
10931 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10933 unformat_input_t *i = vam->input;
10934 vl_api_ipsec_interface_add_del_spd_t *mp;
10936 u8 sw_if_index_set = 0;
10937 u32 spd_id = (u32) ~ 0;
10941 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10943 if (unformat (i, "del"))
10945 else if (unformat (i, "spd_id %d", &spd_id))
10948 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10949 sw_if_index_set = 1;
10950 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10951 sw_if_index_set = 1;
10954 clib_warning ("parse error '%U'", format_unformat_error, i);
10960 if (spd_id == (u32) ~ 0)
10962 errmsg ("spd_id must be set");
10966 if (sw_if_index_set == 0)
10968 errmsg ("missing interface name or sw_if_index");
10972 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10974 mp->spd_id = ntohl (spd_id);
10975 mp->sw_if_index = ntohl (sw_if_index);
10976 mp->is_add = is_add;
10984 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10986 unformat_input_t *i = vam->input;
10987 vl_api_ipsec_spd_entry_add_del_t *mp;
10988 u8 is_add = 1, is_outbound = 0;
10989 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10991 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10992 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10993 vl_api_address_t laddr_start = { }, laddr_stop =
11002 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11004 if (unformat (i, "del"))
11006 if (unformat (i, "outbound"))
11008 if (unformat (i, "inbound"))
11010 else if (unformat (i, "spd_id %d", &spd_id))
11012 else if (unformat (i, "sa_id %d", &sa_id))
11014 else if (unformat (i, "priority %d", &priority))
11016 else if (unformat (i, "protocol %d", &protocol))
11018 else if (unformat (i, "lport_start %d", &lport_start))
11020 else if (unformat (i, "lport_stop %d", &lport_stop))
11022 else if (unformat (i, "rport_start %d", &rport_start))
11024 else if (unformat (i, "rport_stop %d", &rport_stop))
11026 else if (unformat (i, "laddr_start %U",
11027 unformat_vl_api_address, &laddr_start))
11029 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
11032 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
11035 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
11039 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11041 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11043 clib_warning ("unsupported action: 'resolve'");
11049 clib_warning ("parse error '%U'", format_unformat_error, i);
11055 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
11057 mp->is_add = is_add;
11059 mp->entry.spd_id = ntohl (spd_id);
11060 mp->entry.priority = ntohl (priority);
11061 mp->entry.is_outbound = is_outbound;
11063 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
11064 sizeof (vl_api_address_t));
11065 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
11066 sizeof (vl_api_address_t));
11067 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
11068 sizeof (vl_api_address_t));
11069 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
11070 sizeof (vl_api_address_t));
11072 mp->entry.protocol = (u8) protocol;
11073 mp->entry.local_port_start = ntohs ((u16) lport_start);
11074 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
11075 mp->entry.remote_port_start = ntohs ((u16) rport_start);
11076 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
11077 mp->entry.policy = (u8) policy;
11078 mp->entry.sa_id = ntohl (sa_id);
11086 api_ipsec_sad_entry_add_del (vat_main_t * vam)
11088 unformat_input_t *i = vam->input;
11089 vl_api_ipsec_sad_entry_add_del_t *mp;
11090 u32 sad_id = 0, spi = 0;
11091 u8 *ck = 0, *ik = 0;
11094 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
11095 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
11096 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
11097 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
11098 vl_api_address_t tun_src, tun_dst;
11101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11103 if (unformat (i, "del"))
11105 else if (unformat (i, "sad_id %d", &sad_id))
11107 else if (unformat (i, "spi %d", &spi))
11109 else if (unformat (i, "esp"))
11110 protocol = IPSEC_API_PROTO_ESP;
11112 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
11114 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11115 if (ADDRESS_IP6 == tun_src.af)
11116 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11119 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
11121 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11122 if (ADDRESS_IP6 == tun_src.af)
11123 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11126 if (unformat (i, "crypto_alg %U",
11127 unformat_ipsec_api_crypto_alg, &crypto_alg))
11129 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11131 else if (unformat (i, "integ_alg %U",
11132 unformat_ipsec_api_integ_alg, &integ_alg))
11134 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11138 clib_warning ("parse error '%U'", format_unformat_error, i);
11144 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
11146 mp->is_add = is_add;
11147 mp->entry.sad_id = ntohl (sad_id);
11148 mp->entry.protocol = protocol;
11149 mp->entry.spi = ntohl (spi);
11150 mp->entry.flags = flags;
11152 mp->entry.crypto_algorithm = crypto_alg;
11153 mp->entry.integrity_algorithm = integ_alg;
11154 mp->entry.crypto_key.length = vec_len (ck);
11155 mp->entry.integrity_key.length = vec_len (ik);
11157 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
11158 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
11160 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
11161 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
11164 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
11166 clib_memcpy (mp->entry.integrity_key.data, ik,
11167 mp->entry.integrity_key.length);
11169 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
11171 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
11172 sizeof (mp->entry.tunnel_src));
11173 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
11174 sizeof (mp->entry.tunnel_dst));
11183 api_ipsec_tunnel_if_add_del (vat_main_t * vam)
11185 unformat_input_t *i = vam->input;
11186 vl_api_ipsec_tunnel_if_add_del_t *mp;
11187 u32 local_spi = 0, remote_spi = 0;
11188 u32 crypto_alg = 0, integ_alg = 0;
11189 u8 *lck = NULL, *rck = NULL;
11190 u8 *lik = NULL, *rik = NULL;
11191 vl_api_address_t local_ip = { 0 };
11192 vl_api_address_t remote_ip = { 0 };
11196 u8 anti_replay = 0;
11202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11204 if (unformat (i, "del"))
11206 else if (unformat (i, "esn"))
11208 else if (unformat (i, "anti-replay"))
11210 else if (unformat (i, "count %d", &count))
11212 else if (unformat (i, "local_spi %d", &local_spi))
11214 else if (unformat (i, "remote_spi %d", &remote_spi))
11217 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
11220 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
11222 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
11225 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
11227 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
11229 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
11233 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
11235 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
11237 errmsg ("unsupported crypto-alg: '%U'\n",
11238 format_ipsec_crypto_alg, crypto_alg);
11244 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
11246 if (integ_alg >= IPSEC_INTEG_N_ALG)
11248 errmsg ("unsupported integ-alg: '%U'\n",
11249 format_ipsec_integ_alg, integ_alg);
11253 else if (unformat (i, "instance %u", &instance))
11257 errmsg ("parse error '%U'\n", format_unformat_error, i);
11264 /* Turn on async mode */
11265 vam->async_mode = 1;
11266 vam->async_errors = 0;
11267 before = vat_time_now (vam);
11270 for (jj = 0; jj < count; jj++)
11272 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
11274 mp->is_add = is_add;
11276 mp->anti_replay = anti_replay;
11279 increment_address (&remote_ip);
11281 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
11282 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
11284 mp->local_spi = htonl (local_spi + jj);
11285 mp->remote_spi = htonl (remote_spi + jj);
11286 mp->crypto_alg = (u8) crypto_alg;
11288 mp->local_crypto_key_len = 0;
11291 mp->local_crypto_key_len = vec_len (lck);
11292 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
11293 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
11294 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
11297 mp->remote_crypto_key_len = 0;
11300 mp->remote_crypto_key_len = vec_len (rck);
11301 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
11302 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
11303 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
11306 mp->integ_alg = (u8) integ_alg;
11308 mp->local_integ_key_len = 0;
11311 mp->local_integ_key_len = vec_len (lik);
11312 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
11313 mp->local_integ_key_len = sizeof (mp->local_integ_key);
11314 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
11317 mp->remote_integ_key_len = 0;
11320 mp->remote_integ_key_len = vec_len (rik);
11321 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
11322 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
11323 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
11328 mp->renumber = renumber;
11329 mp->show_instance = ntohl (instance);
11334 /* When testing multiple add/del ops, use a control-ping to sync */
11337 vl_api_control_ping_t *mp_ping;
11341 /* Shut off async mode */
11342 vam->async_mode = 0;
11344 MPING (CONTROL_PING, mp_ping);
11347 timeout = vat_time_now (vam) + 1.0;
11348 while (vat_time_now (vam) < timeout)
11349 if (vam->result_ready == 1)
11354 if (vam->retval == -99)
11355 errmsg ("timeout");
11357 if (vam->async_errors > 0)
11359 errmsg ("%d asynchronous errors", vam->async_errors);
11362 vam->async_errors = 0;
11363 after = vat_time_now (vam);
11365 /* slim chance, but we might have eaten SIGTERM on the first iteration */
11369 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
11370 count, after - before, count / (after - before));
11374 /* Wait for a reply... */
11383 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11385 vat_main_t *vam = &vat_main;
11387 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11388 "crypto_key %U integ_alg %u integ_key %U flags %x "
11389 "tunnel_src_addr %U tunnel_dst_addr %U "
11390 "salt %u seq_outbound %lu last_seq_inbound %lu "
11391 "replay_window %lu stat_index %u\n",
11392 ntohl (mp->entry.sad_id),
11393 ntohl (mp->sw_if_index),
11394 ntohl (mp->entry.spi),
11395 ntohl (mp->entry.protocol),
11396 ntohl (mp->entry.crypto_algorithm),
11397 format_hex_bytes, mp->entry.crypto_key.data,
11398 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11399 format_hex_bytes, mp->entry.integrity_key.data,
11400 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11401 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11402 &mp->entry.tunnel_dst, ntohl (mp->salt),
11403 clib_net_to_host_u64 (mp->seq_outbound),
11404 clib_net_to_host_u64 (mp->last_seq_inbound),
11405 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11408 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11409 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11411 static void vl_api_ipsec_sa_details_t_handler_json
11412 (vl_api_ipsec_sa_details_t * mp)
11414 vat_main_t *vam = &vat_main;
11415 vat_json_node_t *node = NULL;
11416 vl_api_ipsec_sad_flags_t flags;
11418 if (VAT_JSON_ARRAY != vam->json_tree.type)
11420 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11421 vat_json_init_array (&vam->json_tree);
11423 node = vat_json_array_add (&vam->json_tree);
11425 vat_json_init_object (node);
11426 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11427 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11428 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11429 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11430 vat_json_object_add_uint (node, "crypto_alg",
11431 ntohl (mp->entry.crypto_algorithm));
11432 vat_json_object_add_uint (node, "integ_alg",
11433 ntohl (mp->entry.integrity_algorithm));
11434 flags = ntohl (mp->entry.flags);
11435 vat_json_object_add_uint (node, "use_esn",
11436 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11437 vat_json_object_add_uint (node, "use_anti_replay",
11438 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11439 vat_json_object_add_uint (node, "is_tunnel",
11440 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11441 vat_json_object_add_uint (node, "is_tunnel_ip6",
11442 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11443 vat_json_object_add_uint (node, "udp_encap",
11444 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11445 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11446 mp->entry.crypto_key.length);
11447 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11448 mp->entry.integrity_key.length);
11449 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11450 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11451 vat_json_object_add_uint (node, "replay_window",
11452 clib_net_to_host_u64 (mp->replay_window));
11453 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11457 api_ipsec_sa_dump (vat_main_t * vam)
11459 unformat_input_t *i = vam->input;
11460 vl_api_ipsec_sa_dump_t *mp;
11461 vl_api_control_ping_t *mp_ping;
11465 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11467 if (unformat (i, "sa_id %d", &sa_id))
11471 clib_warning ("parse error '%U'", format_unformat_error, i);
11476 M (IPSEC_SA_DUMP, mp);
11478 mp->sa_id = ntohl (sa_id);
11482 /* Use a control ping for synchronization */
11483 M (CONTROL_PING, mp_ping);
11491 api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
11493 unformat_input_t *i = vam->input;
11494 vl_api_ipsec_tunnel_if_set_sa_t *mp;
11495 u32 sw_if_index = ~0;
11497 u8 is_outbound = (u8) ~ 0;
11500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11502 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11504 else if (unformat (i, "sa_id %d", &sa_id))
11506 else if (unformat (i, "outbound"))
11508 else if (unformat (i, "inbound"))
11512 clib_warning ("parse error '%U'", format_unformat_error, i);
11517 if (sw_if_index == ~0)
11519 errmsg ("interface must be specified");
11525 errmsg ("SA ID must be specified");
11529 M (IPSEC_TUNNEL_IF_SET_SA, mp);
11531 mp->sw_if_index = htonl (sw_if_index);
11532 mp->sa_id = htonl (sa_id);
11533 mp->is_outbound = is_outbound;
11542 api_get_first_msg_id (vat_main_t * vam)
11544 vl_api_get_first_msg_id_t *mp;
11545 unformat_input_t *i = vam->input;
11550 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11552 if (unformat (i, "client %s", &name))
11560 errmsg ("missing client name");
11563 vec_add1 (name, 0);
11565 if (vec_len (name) > 63)
11567 errmsg ("client name too long");
11571 M (GET_FIRST_MSG_ID, mp);
11572 clib_memcpy (mp->name, name, vec_len (name));
11579 api_cop_interface_enable_disable (vat_main_t * vam)
11581 unformat_input_t *line_input = vam->input;
11582 vl_api_cop_interface_enable_disable_t *mp;
11583 u32 sw_if_index = ~0;
11584 u8 enable_disable = 1;
11587 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11589 if (unformat (line_input, "disable"))
11590 enable_disable = 0;
11591 if (unformat (line_input, "enable"))
11592 enable_disable = 1;
11593 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11594 vam, &sw_if_index))
11596 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11602 if (sw_if_index == ~0)
11604 errmsg ("missing interface name or sw_if_index");
11608 /* Construct the API message */
11609 M (COP_INTERFACE_ENABLE_DISABLE, mp);
11610 mp->sw_if_index = ntohl (sw_if_index);
11611 mp->enable_disable = enable_disable;
11615 /* Wait for the reply */
11621 api_cop_whitelist_enable_disable (vat_main_t * vam)
11623 unformat_input_t *line_input = vam->input;
11624 vl_api_cop_whitelist_enable_disable_t *mp;
11625 u32 sw_if_index = ~0;
11626 u8 ip4 = 0, ip6 = 0, default_cop = 0;
11630 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11632 if (unformat (line_input, "ip4"))
11634 else if (unformat (line_input, "ip6"))
11636 else if (unformat (line_input, "default"))
11638 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11639 vam, &sw_if_index))
11641 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11643 else if (unformat (line_input, "fib-id %d", &fib_id))
11649 if (sw_if_index == ~0)
11651 errmsg ("missing interface name or sw_if_index");
11655 /* Construct the API message */
11656 M (COP_WHITELIST_ENABLE_DISABLE, mp);
11657 mp->sw_if_index = ntohl (sw_if_index);
11658 mp->fib_id = ntohl (fib_id);
11661 mp->default_cop = default_cop;
11665 /* Wait for the reply */
11671 api_get_node_graph (vat_main_t * vam)
11673 vl_api_get_node_graph_t *mp;
11676 M (GET_NODE_GRAPH, mp);
11680 /* Wait for the reply */
11686 api_af_packet_create (vat_main_t * vam)
11688 unformat_input_t *i = vam->input;
11689 vl_api_af_packet_create_t *mp;
11690 u8 *host_if_name = 0;
11692 u8 random_hw_addr = 1;
11695 clib_memset (hw_addr, 0, sizeof (hw_addr));
11697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11699 if (unformat (i, "name %s", &host_if_name))
11700 vec_add1 (host_if_name, 0);
11701 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11702 random_hw_addr = 0;
11707 if (!vec_len (host_if_name))
11709 errmsg ("host-interface name must be specified");
11713 if (vec_len (host_if_name) > 64)
11715 errmsg ("host-interface name too long");
11719 M (AF_PACKET_CREATE, mp);
11721 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11722 clib_memcpy (mp->hw_addr, hw_addr, 6);
11723 mp->use_random_hw_addr = random_hw_addr;
11724 vec_free (host_if_name);
11732 fprintf (vam->ofp ? vam->ofp : stderr,
11733 " new sw_if_index = %d\n", vam->sw_if_index);
11740 api_af_packet_delete (vat_main_t * vam)
11742 unformat_input_t *i = vam->input;
11743 vl_api_af_packet_delete_t *mp;
11744 u8 *host_if_name = 0;
11747 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11749 if (unformat (i, "name %s", &host_if_name))
11750 vec_add1 (host_if_name, 0);
11755 if (!vec_len (host_if_name))
11757 errmsg ("host-interface name must be specified");
11761 if (vec_len (host_if_name) > 64)
11763 errmsg ("host-interface name too long");
11767 M (AF_PACKET_DELETE, mp);
11769 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11770 vec_free (host_if_name);
11777 static void vl_api_af_packet_details_t_handler
11778 (vl_api_af_packet_details_t * mp)
11780 vat_main_t *vam = &vat_main;
11782 print (vam->ofp, "%-16s %d",
11783 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11786 static void vl_api_af_packet_details_t_handler_json
11787 (vl_api_af_packet_details_t * mp)
11789 vat_main_t *vam = &vat_main;
11790 vat_json_node_t *node = NULL;
11792 if (VAT_JSON_ARRAY != vam->json_tree.type)
11794 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11795 vat_json_init_array (&vam->json_tree);
11797 node = vat_json_array_add (&vam->json_tree);
11799 vat_json_init_object (node);
11800 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11801 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11805 api_af_packet_dump (vat_main_t * vam)
11807 vl_api_af_packet_dump_t *mp;
11808 vl_api_control_ping_t *mp_ping;
11811 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11812 /* Get list of tap interfaces */
11813 M (AF_PACKET_DUMP, mp);
11816 /* Use a control ping for synchronization */
11817 MPING (CONTROL_PING, mp_ping);
11825 api_policer_add_del (vat_main_t * vam)
11827 unformat_input_t *i = vam->input;
11828 vl_api_policer_add_del_t *mp;
11838 u8 color_aware = 0;
11839 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
11842 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
11843 conform_action.dscp = 0;
11844 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
11845 exceed_action.dscp = 0;
11846 violate_action.action_type = SSE2_QOS_ACTION_DROP;
11847 violate_action.dscp = 0;
11849 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11851 if (unformat (i, "del"))
11853 else if (unformat (i, "name %s", &name))
11854 vec_add1 (name, 0);
11855 else if (unformat (i, "cir %u", &cir))
11857 else if (unformat (i, "eir %u", &eir))
11859 else if (unformat (i, "cb %u", &cb))
11861 else if (unformat (i, "eb %u", &eb))
11863 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11866 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11869 else if (unformat (i, "type %U", unformat_policer_type, &type))
11871 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11874 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11877 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11880 else if (unformat (i, "color-aware"))
11886 if (!vec_len (name))
11888 errmsg ("policer name must be specified");
11892 if (vec_len (name) > 64)
11894 errmsg ("policer name too long");
11898 M (POLICER_ADD_DEL, mp);
11900 clib_memcpy (mp->name, name, vec_len (name));
11902 mp->is_add = is_add;
11903 mp->cir = ntohl (cir);
11904 mp->eir = ntohl (eir);
11905 mp->cb = clib_net_to_host_u64 (cb);
11906 mp->eb = clib_net_to_host_u64 (eb);
11907 mp->rate_type = rate_type;
11908 mp->round_type = round_type;
11910 mp->conform_action.type = conform_action.action_type;
11911 mp->conform_action.dscp = conform_action.dscp;
11912 mp->exceed_action.type = exceed_action.action_type;
11913 mp->exceed_action.dscp = exceed_action.dscp;
11914 mp->violate_action.type = violate_action.action_type;
11915 mp->violate_action.dscp = violate_action.dscp;
11916 mp->color_aware = color_aware;
11924 api_policer_dump (vat_main_t * vam)
11926 unformat_input_t *i = vam->input;
11927 vl_api_policer_dump_t *mp;
11928 vl_api_control_ping_t *mp_ping;
11929 u8 *match_name = 0;
11930 u8 match_name_valid = 0;
11933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11935 if (unformat (i, "name %s", &match_name))
11937 vec_add1 (match_name, 0);
11938 match_name_valid = 1;
11944 M (POLICER_DUMP, mp);
11945 mp->match_name_valid = match_name_valid;
11946 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11947 vec_free (match_name);
11951 /* Use a control ping for synchronization */
11952 MPING (CONTROL_PING, mp_ping);
11955 /* Wait for a reply... */
11961 api_policer_classify_set_interface (vat_main_t * vam)
11963 unformat_input_t *i = vam->input;
11964 vl_api_policer_classify_set_interface_t *mp;
11966 int sw_if_index_set;
11967 u32 ip4_table_index = ~0;
11968 u32 ip6_table_index = ~0;
11969 u32 l2_table_index = ~0;
11973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11975 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11976 sw_if_index_set = 1;
11977 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11978 sw_if_index_set = 1;
11979 else if (unformat (i, "del"))
11981 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11983 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11985 else if (unformat (i, "l2-table %d", &l2_table_index))
11989 clib_warning ("parse error '%U'", format_unformat_error, i);
11994 if (sw_if_index_set == 0)
11996 errmsg ("missing interface name or sw_if_index");
12000 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
12002 mp->sw_if_index = ntohl (sw_if_index);
12003 mp->ip4_table_index = ntohl (ip4_table_index);
12004 mp->ip6_table_index = ntohl (ip6_table_index);
12005 mp->l2_table_index = ntohl (l2_table_index);
12006 mp->is_add = is_add;
12014 api_policer_classify_dump (vat_main_t * vam)
12016 unformat_input_t *i = vam->input;
12017 vl_api_policer_classify_dump_t *mp;
12018 vl_api_control_ping_t *mp_ping;
12019 u8 type = POLICER_CLASSIFY_N_TABLES;
12022 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
12026 errmsg ("classify table type must be specified");
12030 if (!vam->json_output)
12032 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
12035 M (POLICER_CLASSIFY_DUMP, mp);
12040 /* Use a control ping for synchronization */
12041 MPING (CONTROL_PING, mp_ping);
12044 /* Wait for a reply... */
12050 format_fib_api_path_nh_proto (u8 * s, va_list * args)
12052 vl_api_fib_path_nh_proto_t proto =
12053 va_arg (*args, vl_api_fib_path_nh_proto_t);
12057 case FIB_API_PATH_NH_PROTO_IP4:
12058 s = format (s, "ip4");
12060 case FIB_API_PATH_NH_PROTO_IP6:
12061 s = format (s, "ip6");
12063 case FIB_API_PATH_NH_PROTO_MPLS:
12064 s = format (s, "mpls");
12066 case FIB_API_PATH_NH_PROTO_BIER:
12067 s = format (s, "bier");
12069 case FIB_API_PATH_NH_PROTO_ETHERNET:
12070 s = format (s, "ethernet");
12078 format_vl_api_ip_address_union (u8 * s, va_list * args)
12080 vl_api_address_family_t af = va_arg (*args, int);
12081 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
12086 s = format (s, "%U", format_ip4_address, u->ip4);
12089 s = format (s, "%U", format_ip6_address, u->ip6);
12096 format_vl_api_fib_path_type (u8 * s, va_list * args)
12098 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
12102 case FIB_API_PATH_TYPE_NORMAL:
12103 s = format (s, "normal");
12105 case FIB_API_PATH_TYPE_LOCAL:
12106 s = format (s, "local");
12108 case FIB_API_PATH_TYPE_DROP:
12109 s = format (s, "drop");
12111 case FIB_API_PATH_TYPE_UDP_ENCAP:
12112 s = format (s, "udp-encap");
12114 case FIB_API_PATH_TYPE_BIER_IMP:
12115 s = format (s, "bier-imp");
12117 case FIB_API_PATH_TYPE_ICMP_UNREACH:
12118 s = format (s, "unreach");
12120 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
12121 s = format (s, "prohibit");
12123 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
12124 s = format (s, "src-lookup");
12126 case FIB_API_PATH_TYPE_DVR:
12127 s = format (s, "dvr");
12129 case FIB_API_PATH_TYPE_INTERFACE_RX:
12130 s = format (s, "interface-rx");
12132 case FIB_API_PATH_TYPE_CLASSIFY:
12133 s = format (s, "classify");
12141 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
12144 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
12145 ntohl (fp->weight), ntohl (fp->sw_if_index),
12146 format_vl_api_fib_path_type, fp->type,
12147 format_fib_api_path_nh_proto, fp->proto,
12148 format_vl_api_ip_address_union, &fp->nh.address);
12152 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
12153 vl_api_fib_path_t * fp)
12155 struct in_addr ip4;
12156 struct in6_addr ip6;
12158 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
12159 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
12160 vat_json_object_add_uint (node, "type", fp->type);
12161 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
12162 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
12164 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
12165 vat_json_object_add_ip4 (node, "next_hop", ip4);
12167 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
12169 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
12170 vat_json_object_add_ip6 (node, "next_hop", ip6);
12175 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
12177 vat_main_t *vam = &vat_main;
12178 int count = ntohl (mp->mt_tunnel.mt_n_paths);
12179 vl_api_fib_path_t *fp;
12182 print (vam->ofp, "sw_if_index %d via:",
12183 ntohl (mp->mt_tunnel.mt_sw_if_index));
12184 fp = mp->mt_tunnel.mt_paths;
12185 for (i = 0; i < count; i++)
12187 vl_api_fib_path_print (vam, fp);
12191 print (vam->ofp, "");
12194 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
12195 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
12198 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
12200 vat_main_t *vam = &vat_main;
12201 vat_json_node_t *node = NULL;
12202 int count = ntohl (mp->mt_tunnel.mt_n_paths);
12203 vl_api_fib_path_t *fp;
12206 if (VAT_JSON_ARRAY != vam->json_tree.type)
12208 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12209 vat_json_init_array (&vam->json_tree);
12211 node = vat_json_array_add (&vam->json_tree);
12213 vat_json_init_object (node);
12214 vat_json_object_add_uint (node, "sw_if_index",
12215 ntohl (mp->mt_tunnel.mt_sw_if_index));
12217 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
12219 fp = mp->mt_tunnel.mt_paths;
12220 for (i = 0; i < count; i++)
12222 vl_api_mpls_fib_path_json_print (node, fp);
12228 api_mpls_tunnel_dump (vat_main_t * vam)
12230 vl_api_mpls_tunnel_dump_t *mp;
12231 vl_api_control_ping_t *mp_ping;
12234 M (MPLS_TUNNEL_DUMP, mp);
12238 /* Use a control ping for synchronization */
12239 MPING (CONTROL_PING, mp_ping);
12246 #define vl_api_mpls_table_details_t_endian vl_noop_handler
12247 #define vl_api_mpls_table_details_t_print vl_noop_handler
12251 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
12253 vat_main_t *vam = &vat_main;
12255 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
12258 static void vl_api_mpls_table_details_t_handler_json
12259 (vl_api_mpls_table_details_t * mp)
12261 vat_main_t *vam = &vat_main;
12262 vat_json_node_t *node = NULL;
12264 if (VAT_JSON_ARRAY != vam->json_tree.type)
12266 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12267 vat_json_init_array (&vam->json_tree);
12269 node = vat_json_array_add (&vam->json_tree);
12271 vat_json_init_object (node);
12272 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
12276 api_mpls_table_dump (vat_main_t * vam)
12278 vl_api_mpls_table_dump_t *mp;
12279 vl_api_control_ping_t *mp_ping;
12282 M (MPLS_TABLE_DUMP, mp);
12285 /* Use a control ping for synchronization */
12286 MPING (CONTROL_PING, mp_ping);
12293 #define vl_api_mpls_route_details_t_endian vl_noop_handler
12294 #define vl_api_mpls_route_details_t_print vl_noop_handler
12297 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
12299 vat_main_t *vam = &vat_main;
12300 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
12301 vl_api_fib_path_t *fp;
12305 "table-id %d, label %u, ess_bit %u",
12306 ntohl (mp->mr_route.mr_table_id),
12307 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
12308 fp = mp->mr_route.mr_paths;
12309 for (i = 0; i < count; i++)
12311 vl_api_fib_path_print (vam, fp);
12316 static void vl_api_mpls_route_details_t_handler_json
12317 (vl_api_mpls_route_details_t * mp)
12319 vat_main_t *vam = &vat_main;
12320 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
12321 vat_json_node_t *node = NULL;
12322 vl_api_fib_path_t *fp;
12325 if (VAT_JSON_ARRAY != vam->json_tree.type)
12327 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12328 vat_json_init_array (&vam->json_tree);
12330 node = vat_json_array_add (&vam->json_tree);
12332 vat_json_init_object (node);
12333 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
12334 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
12335 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
12336 vat_json_object_add_uint (node, "path_count", count);
12337 fp = mp->mr_route.mr_paths;
12338 for (i = 0; i < count; i++)
12340 vl_api_mpls_fib_path_json_print (node, fp);
12346 api_mpls_route_dump (vat_main_t * vam)
12348 unformat_input_t *input = vam->input;
12349 vl_api_mpls_route_dump_t *mp;
12350 vl_api_control_ping_t *mp_ping;
12354 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12356 if (unformat (input, "table_id %d", &table_id))
12361 if (table_id == ~0)
12363 errmsg ("missing table id");
12367 M (MPLS_ROUTE_DUMP, mp);
12369 mp->table.mt_table_id = ntohl (table_id);
12372 /* Use a control ping for synchronization */
12373 MPING (CONTROL_PING, mp_ping);
12380 #define vl_api_ip_table_details_t_endian vl_noop_handler
12381 #define vl_api_ip_table_details_t_print vl_noop_handler
12384 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12386 vat_main_t *vam = &vat_main;
12389 "%s; table-id %d, prefix %U/%d",
12390 mp->table.name, ntohl (mp->table.table_id));
12394 static void vl_api_ip_table_details_t_handler_json
12395 (vl_api_ip_table_details_t * mp)
12397 vat_main_t *vam = &vat_main;
12398 vat_json_node_t *node = NULL;
12400 if (VAT_JSON_ARRAY != vam->json_tree.type)
12402 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12403 vat_json_init_array (&vam->json_tree);
12405 node = vat_json_array_add (&vam->json_tree);
12407 vat_json_init_object (node);
12408 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12412 api_ip_table_dump (vat_main_t * vam)
12414 vl_api_ip_table_dump_t *mp;
12415 vl_api_control_ping_t *mp_ping;
12418 M (IP_TABLE_DUMP, mp);
12421 /* Use a control ping for synchronization */
12422 MPING (CONTROL_PING, mp_ping);
12430 api_ip_mtable_dump (vat_main_t * vam)
12432 vl_api_ip_mtable_dump_t *mp;
12433 vl_api_control_ping_t *mp_ping;
12436 M (IP_MTABLE_DUMP, mp);
12439 /* Use a control ping for synchronization */
12440 MPING (CONTROL_PING, mp_ping);
12448 api_ip_mroute_dump (vat_main_t * vam)
12450 unformat_input_t *input = vam->input;
12451 vl_api_control_ping_t *mp_ping;
12452 vl_api_ip_mroute_dump_t *mp;
12457 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12459 if (unformat (input, "table_id %d", &table_id))
12461 else if (unformat (input, "ip6"))
12463 else if (unformat (input, "ip4"))
12468 if (table_id == ~0)
12470 errmsg ("missing table id");
12474 M (IP_MROUTE_DUMP, mp);
12475 mp->table.table_id = table_id;
12476 mp->table.is_ip6 = is_ip6;
12479 /* Use a control ping for synchronization */
12480 MPING (CONTROL_PING, mp_ping);
12487 #define vl_api_ip_route_details_t_endian vl_noop_handler
12488 #define vl_api_ip_route_details_t_print vl_noop_handler
12491 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12493 vat_main_t *vam = &vat_main;
12494 u8 count = mp->route.n_paths;
12495 vl_api_fib_path_t *fp;
12499 "table-id %d, prefix %U/%d",
12500 ntohl (mp->route.table_id),
12501 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12502 for (i = 0; i < count; i++)
12504 fp = &mp->route.paths[i];
12506 vl_api_fib_path_print (vam, fp);
12511 static void vl_api_ip_route_details_t_handler_json
12512 (vl_api_ip_route_details_t * mp)
12514 vat_main_t *vam = &vat_main;
12515 u8 count = mp->route.n_paths;
12516 vat_json_node_t *node = NULL;
12517 struct in_addr ip4;
12518 struct in6_addr ip6;
12519 vl_api_fib_path_t *fp;
12522 if (VAT_JSON_ARRAY != vam->json_tree.type)
12524 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12525 vat_json_init_array (&vam->json_tree);
12527 node = vat_json_array_add (&vam->json_tree);
12529 vat_json_init_object (node);
12530 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12531 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12533 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12534 vat_json_object_add_ip6 (node, "prefix", ip6);
12538 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12539 vat_json_object_add_ip4 (node, "prefix", ip4);
12541 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12542 vat_json_object_add_uint (node, "path_count", count);
12543 for (i = 0; i < count; i++)
12545 fp = &mp->route.paths[i];
12546 vl_api_mpls_fib_path_json_print (node, fp);
12551 api_ip_route_dump (vat_main_t * vam)
12553 unformat_input_t *input = vam->input;
12554 vl_api_ip_route_dump_t *mp;
12555 vl_api_control_ping_t *mp_ping;
12561 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12563 if (unformat (input, "table_id %d", &table_id))
12565 else if (unformat (input, "ip6"))
12567 else if (unformat (input, "ip4"))
12572 if (table_id == ~0)
12574 errmsg ("missing table id");
12578 M (IP_ROUTE_DUMP, mp);
12580 mp->table.table_id = table_id;
12581 mp->table.is_ip6 = is_ip6;
12585 /* Use a control ping for synchronization */
12586 MPING (CONTROL_PING, mp_ping);
12594 api_classify_table_ids (vat_main_t * vam)
12596 vl_api_classify_table_ids_t *mp;
12599 /* Construct the API message */
12600 M (CLASSIFY_TABLE_IDS, mp);
12609 api_classify_table_by_interface (vat_main_t * vam)
12611 unformat_input_t *input = vam->input;
12612 vl_api_classify_table_by_interface_t *mp;
12614 u32 sw_if_index = ~0;
12616 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12618 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12620 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12625 if (sw_if_index == ~0)
12627 errmsg ("missing interface name or sw_if_index");
12631 /* Construct the API message */
12632 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12634 mp->sw_if_index = ntohl (sw_if_index);
12642 api_classify_table_info (vat_main_t * vam)
12644 unformat_input_t *input = vam->input;
12645 vl_api_classify_table_info_t *mp;
12649 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12651 if (unformat (input, "table_id %d", &table_id))
12656 if (table_id == ~0)
12658 errmsg ("missing table id");
12662 /* Construct the API message */
12663 M (CLASSIFY_TABLE_INFO, mp);
12665 mp->table_id = ntohl (table_id);
12673 api_classify_session_dump (vat_main_t * vam)
12675 unformat_input_t *input = vam->input;
12676 vl_api_classify_session_dump_t *mp;
12677 vl_api_control_ping_t *mp_ping;
12681 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12683 if (unformat (input, "table_id %d", &table_id))
12688 if (table_id == ~0)
12690 errmsg ("missing table id");
12694 /* Construct the API message */
12695 M (CLASSIFY_SESSION_DUMP, mp);
12697 mp->table_id = ntohl (table_id);
12700 /* Use a control ping for synchronization */
12701 MPING (CONTROL_PING, mp_ping);
12709 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12711 vat_main_t *vam = &vat_main;
12713 print (vam->ofp, "collector_address %U, collector_port %d, "
12714 "src_address %U, vrf_id %d, path_mtu %u, "
12715 "template_interval %u, udp_checksum %d",
12716 format_ip4_address, mp->collector_address,
12717 ntohs (mp->collector_port),
12718 format_ip4_address, mp->src_address,
12719 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12720 ntohl (mp->template_interval), mp->udp_checksum);
12723 vam->result_ready = 1;
12727 vl_api_ipfix_exporter_details_t_handler_json
12728 (vl_api_ipfix_exporter_details_t * mp)
12730 vat_main_t *vam = &vat_main;
12731 vat_json_node_t node;
12732 struct in_addr collector_address;
12733 struct in_addr src_address;
12735 vat_json_init_object (&node);
12736 clib_memcpy (&collector_address, &mp->collector_address,
12737 sizeof (collector_address));
12738 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12739 vat_json_object_add_uint (&node, "collector_port",
12740 ntohs (mp->collector_port));
12741 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12742 vat_json_object_add_ip4 (&node, "src_address", src_address);
12743 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12744 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12745 vat_json_object_add_uint (&node, "template_interval",
12746 ntohl (mp->template_interval));
12747 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12749 vat_json_print (vam->ofp, &node);
12750 vat_json_free (&node);
12752 vam->result_ready = 1;
12756 api_ipfix_exporter_dump (vat_main_t * vam)
12758 vl_api_ipfix_exporter_dump_t *mp;
12761 /* Construct the API message */
12762 M (IPFIX_EXPORTER_DUMP, mp);
12771 api_ipfix_classify_stream_dump (vat_main_t * vam)
12773 vl_api_ipfix_classify_stream_dump_t *mp;
12776 /* Construct the API message */
12777 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12788 vl_api_ipfix_classify_stream_details_t_handler
12789 (vl_api_ipfix_classify_stream_details_t * mp)
12791 vat_main_t *vam = &vat_main;
12792 print (vam->ofp, "domain_id %d, src_port %d",
12793 ntohl (mp->domain_id), ntohs (mp->src_port));
12795 vam->result_ready = 1;
12799 vl_api_ipfix_classify_stream_details_t_handler_json
12800 (vl_api_ipfix_classify_stream_details_t * mp)
12802 vat_main_t *vam = &vat_main;
12803 vat_json_node_t node;
12805 vat_json_init_object (&node);
12806 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12807 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12809 vat_json_print (vam->ofp, &node);
12810 vat_json_free (&node);
12812 vam->result_ready = 1;
12816 api_ipfix_classify_table_dump (vat_main_t * vam)
12818 vl_api_ipfix_classify_table_dump_t *mp;
12819 vl_api_control_ping_t *mp_ping;
12822 if (!vam->json_output)
12824 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12825 "transport_protocol");
12828 /* Construct the API message */
12829 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12834 /* Use a control ping for synchronization */
12835 MPING (CONTROL_PING, mp_ping);
12843 vl_api_ipfix_classify_table_details_t_handler
12844 (vl_api_ipfix_classify_table_details_t * mp)
12846 vat_main_t *vam = &vat_main;
12847 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12848 mp->transport_protocol);
12852 vl_api_ipfix_classify_table_details_t_handler_json
12853 (vl_api_ipfix_classify_table_details_t * mp)
12855 vat_json_node_t *node = NULL;
12856 vat_main_t *vam = &vat_main;
12858 if (VAT_JSON_ARRAY != vam->json_tree.type)
12860 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12861 vat_json_init_array (&vam->json_tree);
12864 node = vat_json_array_add (&vam->json_tree);
12865 vat_json_init_object (node);
12867 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12868 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12869 vat_json_object_add_uint (node, "transport_protocol",
12870 mp->transport_protocol);
12874 api_sw_interface_span_enable_disable (vat_main_t * vam)
12876 unformat_input_t *i = vam->input;
12877 vl_api_sw_interface_span_enable_disable_t *mp;
12878 u32 src_sw_if_index = ~0;
12879 u32 dst_sw_if_index = ~0;
12884 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12887 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12889 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12893 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12895 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12897 else if (unformat (i, "disable"))
12899 else if (unformat (i, "rx"))
12901 else if (unformat (i, "tx"))
12903 else if (unformat (i, "both"))
12905 else if (unformat (i, "l2"))
12911 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12913 mp->sw_if_index_from = htonl (src_sw_if_index);
12914 mp->sw_if_index_to = htonl (dst_sw_if_index);
12924 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12927 vat_main_t *vam = &vat_main;
12928 u8 *sw_if_from_name = 0;
12929 u8 *sw_if_to_name = 0;
12930 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12931 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12932 char *states[] = { "none", "rx", "tx", "both" };
12936 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12938 if ((u32) p->value[0] == sw_if_index_from)
12940 sw_if_from_name = (u8 *)(p->key);
12944 if ((u32) p->value[0] == sw_if_index_to)
12946 sw_if_to_name = (u8 *)(p->key);
12947 if (sw_if_from_name)
12952 print (vam->ofp, "%20s => %20s (%s) %s",
12953 sw_if_from_name, sw_if_to_name, states[mp->state],
12954 mp->is_l2 ? "l2" : "device");
12958 vl_api_sw_interface_span_details_t_handler_json
12959 (vl_api_sw_interface_span_details_t * mp)
12961 vat_main_t *vam = &vat_main;
12962 vat_json_node_t *node = NULL;
12963 u8 *sw_if_from_name = 0;
12964 u8 *sw_if_to_name = 0;
12965 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12966 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12970 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12972 if ((u32) p->value[0] == sw_if_index_from)
12974 sw_if_from_name = (u8 *)(p->key);
12978 if ((u32) p->value[0] == sw_if_index_to)
12980 sw_if_to_name = (u8 *)(p->key);
12981 if (sw_if_from_name)
12987 if (VAT_JSON_ARRAY != vam->json_tree.type)
12989 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12990 vat_json_init_array (&vam->json_tree);
12992 node = vat_json_array_add (&vam->json_tree);
12994 vat_json_init_object (node);
12995 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12996 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12997 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12998 if (0 != sw_if_to_name)
13000 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
13002 vat_json_object_add_uint (node, "state", mp->state);
13003 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
13007 api_sw_interface_span_dump (vat_main_t * vam)
13009 unformat_input_t *input = vam->input;
13010 vl_api_sw_interface_span_dump_t *mp;
13011 vl_api_control_ping_t *mp_ping;
13015 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13017 if (unformat (input, "l2"))
13023 M (SW_INTERFACE_SPAN_DUMP, mp);
13027 /* Use a control ping for synchronization */
13028 MPING (CONTROL_PING, mp_ping);
13036 api_pg_create_interface (vat_main_t * vam)
13038 unformat_input_t *input = vam->input;
13039 vl_api_pg_create_interface_t *mp;
13041 u32 if_id = ~0, gso_size = 0;
13042 u8 gso_enabled = 0;
13044 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13046 if (unformat (input, "if_id %d", &if_id))
13048 else if (unformat (input, "gso-enabled"))
13051 if (unformat (input, "gso-size %u", &gso_size))
13055 errmsg ("missing gso-size");
13064 errmsg ("missing pg interface index");
13068 /* Construct the API message */
13069 M (PG_CREATE_INTERFACE, mp);
13071 mp->interface_id = ntohl (if_id);
13072 mp->gso_enabled = gso_enabled;
13080 api_pg_capture (vat_main_t * vam)
13082 unformat_input_t *input = vam->input;
13083 vl_api_pg_capture_t *mp;
13088 u8 pcap_file_set = 0;
13091 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13093 if (unformat (input, "if_id %d", &if_id))
13095 else if (unformat (input, "pcap %s", &pcap_file))
13097 else if (unformat (input, "count %d", &count))
13099 else if (unformat (input, "disable"))
13106 errmsg ("missing pg interface index");
13109 if (pcap_file_set > 0)
13111 if (vec_len (pcap_file) > 255)
13113 errmsg ("pcap file name is too long");
13118 /* Construct the API message */
13119 M (PG_CAPTURE, mp);
13121 mp->interface_id = ntohl (if_id);
13122 mp->is_enabled = enable;
13123 mp->count = ntohl (count);
13124 if (pcap_file_set != 0)
13126 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
13128 vec_free (pcap_file);
13136 api_pg_enable_disable (vat_main_t * vam)
13138 unformat_input_t *input = vam->input;
13139 vl_api_pg_enable_disable_t *mp;
13142 u8 stream_name_set = 0;
13143 u8 *stream_name = 0;
13145 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13147 if (unformat (input, "stream %s", &stream_name))
13148 stream_name_set = 1;
13149 else if (unformat (input, "disable"))
13155 if (stream_name_set > 0)
13157 if (vec_len (stream_name) > 255)
13159 errmsg ("stream name too long");
13164 /* Construct the API message */
13165 M (PG_ENABLE_DISABLE, mp);
13167 mp->is_enabled = enable;
13168 if (stream_name_set != 0)
13170 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
13172 vec_free (stream_name);
13180 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
13182 unformat_input_t *input = vam->input;
13183 vl_api_pg_interface_enable_disable_coalesce_t *mp;
13185 u32 sw_if_index = ~0;
13188 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13190 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13192 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13194 else if (unformat (input, "disable"))
13200 if (sw_if_index == ~0)
13202 errmsg ("Interface required but not specified");
13206 /* Construct the API message */
13207 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
13209 mp->coalesce_enabled = enable;
13210 mp->sw_if_index = htonl (sw_if_index);
13218 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
13220 unformat_input_t *input = vam->input;
13221 vl_api_ip_source_and_port_range_check_add_del_t *mp;
13223 u16 *low_ports = 0;
13224 u16 *high_ports = 0;
13227 vl_api_prefix_t prefix;
13234 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13236 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
13238 else if (unformat (input, "vrf %d", &vrf_id))
13240 else if (unformat (input, "del"))
13242 else if (unformat (input, "port %d", &tmp))
13244 if (tmp == 0 || tmp > 65535)
13246 errmsg ("port %d out of range", tmp);
13250 this_hi = this_low + 1;
13251 vec_add1 (low_ports, this_low);
13252 vec_add1 (high_ports, this_hi);
13254 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13256 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
13258 errmsg ("incorrect range parameters");
13262 /* Note: in debug CLI +1 is added to high before
13263 passing to real fn that does "the work"
13264 (ip_source_and_port_range_check_add_del).
13265 This fn is a wrapper around the binary API fn a
13266 control plane will call, which expects this increment
13267 to have occurred. Hence letting the binary API control
13268 plane fn do the increment for consistency between VAT
13269 and other control planes.
13272 vec_add1 (low_ports, this_low);
13273 vec_add1 (high_ports, this_hi);
13279 if (prefix_set == 0)
13281 errmsg ("<address>/<mask> not specified");
13287 errmsg ("VRF ID required, not specified");
13294 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13298 if (vec_len (low_ports) == 0)
13300 errmsg ("At least one port or port range required");
13304 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
13306 mp->is_add = is_add;
13308 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
13310 mp->number_of_ranges = vec_len (low_ports);
13312 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
13313 vec_free (low_ports);
13315 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
13316 vec_free (high_ports);
13318 mp->vrf_id = ntohl (vrf_id);
13326 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13328 unformat_input_t *input = vam->input;
13329 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13330 u32 sw_if_index = ~0;
13332 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
13333 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
13337 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13339 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13341 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13343 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
13345 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
13347 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13349 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13351 else if (unformat (input, "del"))
13357 if (sw_if_index == ~0)
13359 errmsg ("Interface required but not specified");
13365 errmsg ("VRF ID required but not specified");
13369 if (tcp_out_vrf_id == 0
13370 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13373 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13377 /* Construct the API message */
13378 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13380 mp->sw_if_index = ntohl (sw_if_index);
13381 mp->is_add = is_add;
13382 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13383 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13384 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13385 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13390 /* Wait for a reply... */
13396 api_set_punt (vat_main_t * vam)
13398 unformat_input_t *i = vam->input;
13399 vl_api_address_family_t af;
13400 vl_api_set_punt_t *mp;
13406 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13408 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13410 else if (unformat (i, "protocol %d", &protocol))
13412 else if (unformat (i, "port %d", &port))
13414 else if (unformat (i, "del"))
13418 clib_warning ("parse error '%U'", format_unformat_error, i);
13425 mp->is_add = (u8) is_add;
13426 mp->punt.type = PUNT_API_TYPE_L4;
13427 mp->punt.punt.l4.af = af;
13428 mp->punt.punt.l4.protocol = (u8) protocol;
13429 mp->punt.punt.l4.port = htons ((u16) port);
13437 api_delete_subif (vat_main_t * vam)
13439 unformat_input_t *i = vam->input;
13440 vl_api_delete_subif_t *mp;
13441 u32 sw_if_index = ~0;
13444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13446 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13448 if (unformat (i, "sw_if_index %d", &sw_if_index))
13454 if (sw_if_index == ~0)
13456 errmsg ("missing sw_if_index");
13460 /* Construct the API message */
13461 M (DELETE_SUBIF, mp);
13462 mp->sw_if_index = ntohl (sw_if_index);
13469 #define foreach_pbb_vtr_op \
13470 _("disable", L2_VTR_DISABLED) \
13471 _("pop", L2_VTR_POP_2) \
13472 _("push", L2_VTR_PUSH_2)
13475 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13477 unformat_input_t *i = vam->input;
13478 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13479 u32 sw_if_index = ~0, vtr_op = ~0;
13480 u16 outer_tag = ~0;
13481 u8 dmac[6], smac[6];
13482 u8 dmac_set = 0, smac_set = 0;
13488 /* Shut up coverity */
13489 clib_memset (dmac, 0, sizeof (dmac));
13490 clib_memset (smac, 0, sizeof (smac));
13492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13494 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13496 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13498 else if (unformat (i, "vtr_op %d", &vtr_op))
13500 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13503 else if (unformat (i, "translate_pbb_stag"))
13505 if (unformat (i, "%d", &tmp))
13507 vtr_op = L2_VTR_TRANSLATE_2_1;
13513 ("translate_pbb_stag operation requires outer tag definition");
13517 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13519 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13521 else if (unformat (i, "sid %d", &sid))
13523 else if (unformat (i, "vlanid %d", &tmp))
13527 clib_warning ("parse error '%U'", format_unformat_error, i);
13532 if ((sw_if_index == ~0) || (vtr_op == ~0))
13534 errmsg ("missing sw_if_index or vtr operation");
13537 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13538 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13541 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13545 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13546 mp->sw_if_index = ntohl (sw_if_index);
13547 mp->vtr_op = ntohl (vtr_op);
13548 mp->outer_tag = ntohs (outer_tag);
13549 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13550 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13551 mp->b_vlanid = ntohs (vlanid);
13552 mp->i_sid = ntohl (sid);
13560 api_flow_classify_set_interface (vat_main_t * vam)
13562 unformat_input_t *i = vam->input;
13563 vl_api_flow_classify_set_interface_t *mp;
13565 int sw_if_index_set;
13566 u32 ip4_table_index = ~0;
13567 u32 ip6_table_index = ~0;
13571 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13573 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13574 sw_if_index_set = 1;
13575 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13576 sw_if_index_set = 1;
13577 else if (unformat (i, "del"))
13579 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13581 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13585 clib_warning ("parse error '%U'", format_unformat_error, i);
13590 if (sw_if_index_set == 0)
13592 errmsg ("missing interface name or sw_if_index");
13596 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13598 mp->sw_if_index = ntohl (sw_if_index);
13599 mp->ip4_table_index = ntohl (ip4_table_index);
13600 mp->ip6_table_index = ntohl (ip6_table_index);
13601 mp->is_add = is_add;
13609 api_flow_classify_dump (vat_main_t * vam)
13611 unformat_input_t *i = vam->input;
13612 vl_api_flow_classify_dump_t *mp;
13613 vl_api_control_ping_t *mp_ping;
13614 u8 type = FLOW_CLASSIFY_N_TABLES;
13617 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13621 errmsg ("classify table type must be specified");
13625 if (!vam->json_output)
13627 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13630 M (FLOW_CLASSIFY_DUMP, mp);
13635 /* Use a control ping for synchronization */
13636 MPING (CONTROL_PING, mp_ping);
13639 /* Wait for a reply... */
13645 api_feature_enable_disable (vat_main_t * vam)
13647 unformat_input_t *i = vam->input;
13648 vl_api_feature_enable_disable_t *mp;
13650 u8 *feature_name = 0;
13651 u32 sw_if_index = ~0;
13655 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13657 if (unformat (i, "arc_name %s", &arc_name))
13659 else if (unformat (i, "feature_name %s", &feature_name))
13662 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13664 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13666 else if (unformat (i, "disable"))
13674 errmsg ("missing arc name");
13677 if (vec_len (arc_name) > 63)
13679 errmsg ("arc name too long");
13682 if (feature_name == 0)
13684 errmsg ("missing feature name");
13687 if (vec_len (feature_name) > 63)
13689 errmsg ("feature name too long");
13692 if (sw_if_index == ~0)
13694 errmsg ("missing interface name or sw_if_index");
13698 /* Construct the API message */
13699 M (FEATURE_ENABLE_DISABLE, mp);
13700 mp->sw_if_index = ntohl (sw_if_index);
13701 mp->enable = enable;
13702 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13703 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13704 vec_free (arc_name);
13705 vec_free (feature_name);
13713 api_feature_gso_enable_disable (vat_main_t * vam)
13715 unformat_input_t *i = vam->input;
13716 vl_api_feature_gso_enable_disable_t *mp;
13717 u32 sw_if_index = ~0;
13721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13723 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13725 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13727 else if (unformat (i, "enable"))
13729 else if (unformat (i, "disable"))
13735 if (sw_if_index == ~0)
13737 errmsg ("missing interface name or sw_if_index");
13741 /* Construct the API message */
13742 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13743 mp->sw_if_index = ntohl (sw_if_index);
13744 mp->enable_disable = enable;
13752 api_sw_interface_tag_add_del (vat_main_t * vam)
13754 unformat_input_t *i = vam->input;
13755 vl_api_sw_interface_tag_add_del_t *mp;
13756 u32 sw_if_index = ~0;
13761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13763 if (unformat (i, "tag %s", &tag))
13765 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13767 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13769 else if (unformat (i, "del"))
13775 if (sw_if_index == ~0)
13777 errmsg ("missing interface name or sw_if_index");
13781 if (enable && (tag == 0))
13783 errmsg ("no tag specified");
13787 /* Construct the API message */
13788 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13789 mp->sw_if_index = ntohl (sw_if_index);
13790 mp->is_add = enable;
13792 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13801 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13803 unformat_input_t *i = vam->input;
13804 vl_api_mac_address_t mac = { 0 };
13805 vl_api_sw_interface_add_del_mac_address_t *mp;
13806 u32 sw_if_index = ~0;
13811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13813 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13815 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13817 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13819 else if (unformat (i, "del"))
13825 if (sw_if_index == ~0)
13827 errmsg ("missing interface name or sw_if_index");
13833 errmsg ("missing MAC address");
13837 /* Construct the API message */
13838 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13839 mp->sw_if_index = ntohl (sw_if_index);
13840 mp->is_add = is_add;
13841 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13848 static void vl_api_l2_xconnect_details_t_handler
13849 (vl_api_l2_xconnect_details_t * mp)
13851 vat_main_t *vam = &vat_main;
13853 print (vam->ofp, "%15d%15d",
13854 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13857 static void vl_api_l2_xconnect_details_t_handler_json
13858 (vl_api_l2_xconnect_details_t * mp)
13860 vat_main_t *vam = &vat_main;
13861 vat_json_node_t *node = NULL;
13863 if (VAT_JSON_ARRAY != vam->json_tree.type)
13865 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13866 vat_json_init_array (&vam->json_tree);
13868 node = vat_json_array_add (&vam->json_tree);
13870 vat_json_init_object (node);
13871 vat_json_object_add_uint (node, "rx_sw_if_index",
13872 ntohl (mp->rx_sw_if_index));
13873 vat_json_object_add_uint (node, "tx_sw_if_index",
13874 ntohl (mp->tx_sw_if_index));
13878 api_l2_xconnect_dump (vat_main_t * vam)
13880 vl_api_l2_xconnect_dump_t *mp;
13881 vl_api_control_ping_t *mp_ping;
13884 if (!vam->json_output)
13886 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13889 M (L2_XCONNECT_DUMP, mp);
13893 /* Use a control ping for synchronization */
13894 MPING (CONTROL_PING, mp_ping);
13902 api_hw_interface_set_mtu (vat_main_t * vam)
13904 unformat_input_t *i = vam->input;
13905 vl_api_hw_interface_set_mtu_t *mp;
13906 u32 sw_if_index = ~0;
13910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13912 if (unformat (i, "mtu %d", &mtu))
13914 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13916 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13922 if (sw_if_index == ~0)
13924 errmsg ("missing interface name or sw_if_index");
13930 errmsg ("no mtu specified");
13934 /* Construct the API message */
13935 M (HW_INTERFACE_SET_MTU, mp);
13936 mp->sw_if_index = ntohl (sw_if_index);
13937 mp->mtu = ntohs ((u16) mtu);
13945 api_p2p_ethernet_add (vat_main_t * vam)
13947 unformat_input_t *i = vam->input;
13948 vl_api_p2p_ethernet_add_t *mp;
13949 u32 parent_if_index = ~0;
13955 clib_memset (remote_mac, 0, sizeof (remote_mac));
13956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13958 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13960 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13964 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13966 else if (unformat (i, "sub_id %d", &sub_id))
13970 clib_warning ("parse error '%U'", format_unformat_error, i);
13975 if (parent_if_index == ~0)
13977 errmsg ("missing interface name or sw_if_index");
13982 errmsg ("missing remote mac address");
13987 errmsg ("missing sub-interface id");
13991 M (P2P_ETHERNET_ADD, mp);
13992 mp->parent_if_index = ntohl (parent_if_index);
13993 mp->subif_id = ntohl (sub_id);
13994 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
14002 api_p2p_ethernet_del (vat_main_t * vam)
14004 unformat_input_t *i = vam->input;
14005 vl_api_p2p_ethernet_del_t *mp;
14006 u32 parent_if_index = ~0;
14011 clib_memset (remote_mac, 0, sizeof (remote_mac));
14012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14014 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
14016 else if (unformat (i, "sw_if_index %d", &parent_if_index))
14020 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
14024 clib_warning ("parse error '%U'", format_unformat_error, i);
14029 if (parent_if_index == ~0)
14031 errmsg ("missing interface name or sw_if_index");
14036 errmsg ("missing remote mac address");
14040 M (P2P_ETHERNET_DEL, mp);
14041 mp->parent_if_index = ntohl (parent_if_index);
14042 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
14050 api_tcp_configure_src_addresses (vat_main_t * vam)
14052 vl_api_tcp_configure_src_addresses_t *mp;
14053 unformat_input_t *i = vam->input;
14054 vl_api_address_t first, last;
14059 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14061 if (unformat (i, "%U - %U",
14062 unformat_vl_api_address, &first,
14063 unformat_vl_api_address, &last))
14067 errmsg ("one range per message (range already set)");
14072 else if (unformat (i, "vrf %d", &vrf_id))
14078 if (range_set == 0)
14080 errmsg ("address range not set");
14084 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
14086 mp->vrf_id = ntohl (vrf_id);
14087 clib_memcpy (&mp->first_address, &first, sizeof (first));
14088 clib_memcpy (&mp->last_address, &last, sizeof (last));
14095 static void vl_api_app_namespace_add_del_reply_t_handler
14096 (vl_api_app_namespace_add_del_reply_t * mp)
14098 vat_main_t *vam = &vat_main;
14099 i32 retval = ntohl (mp->retval);
14100 if (vam->async_mode)
14102 vam->async_errors += (retval < 0);
14106 vam->retval = retval;
14108 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
14109 vam->result_ready = 1;
14113 static void vl_api_app_namespace_add_del_reply_t_handler_json
14114 (vl_api_app_namespace_add_del_reply_t * mp)
14116 vat_main_t *vam = &vat_main;
14117 vat_json_node_t node;
14119 vat_json_init_object (&node);
14120 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
14121 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
14123 vat_json_print (vam->ofp, &node);
14124 vat_json_free (&node);
14126 vam->retval = ntohl (mp->retval);
14127 vam->result_ready = 1;
14131 api_app_namespace_add_del (vat_main_t * vam)
14133 vl_api_app_namespace_add_del_t *mp;
14134 unformat_input_t *i = vam->input;
14135 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
14136 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
14140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14142 if (unformat (i, "id %_%v%_", &ns_id))
14144 else if (unformat (i, "secret %lu", &secret))
14146 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14147 sw_if_index_set = 1;
14148 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
14150 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
14155 if (!ns_id || !secret_set || !sw_if_index_set)
14157 errmsg ("namespace id, secret and sw_if_index must be set");
14160 if (vec_len (ns_id) > 64)
14162 errmsg ("namespace id too long");
14165 M (APP_NAMESPACE_ADD_DEL, mp);
14167 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
14168 mp->secret = clib_host_to_net_u64 (secret);
14169 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14170 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
14171 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
14179 api_sock_init_shm (vat_main_t * vam)
14181 #if VPP_API_TEST_BUILTIN == 0
14182 unformat_input_t *i = vam->input;
14183 vl_api_shm_elem_config_t *config = 0;
14184 u64 size = 64 << 20;
14187 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14189 if (unformat (i, "size %U", unformat_memory_size, &size))
14196 * Canned custom ring allocator config.
14197 * Should probably parse all of this
14199 vec_validate (config, 6);
14200 config[0].type = VL_API_VLIB_RING;
14201 config[0].size = 256;
14202 config[0].count = 32;
14204 config[1].type = VL_API_VLIB_RING;
14205 config[1].size = 1024;
14206 config[1].count = 16;
14208 config[2].type = VL_API_VLIB_RING;
14209 config[2].size = 4096;
14210 config[2].count = 2;
14212 config[3].type = VL_API_CLIENT_RING;
14213 config[3].size = 256;
14214 config[3].count = 32;
14216 config[4].type = VL_API_CLIENT_RING;
14217 config[4].size = 1024;
14218 config[4].count = 16;
14220 config[5].type = VL_API_CLIENT_RING;
14221 config[5].size = 4096;
14222 config[5].count = 2;
14224 config[6].type = VL_API_QUEUE;
14225 config[6].count = 128;
14226 config[6].size = sizeof (uword);
14228 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
14230 vam->client_index_invalid = 1;
14238 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
14240 vat_main_t *vam = &vat_main;
14241 fib_prefix_t lcl, rmt;
14243 ip_prefix_decode (&mp->lcl, &lcl);
14244 ip_prefix_decode (&mp->rmt, &rmt);
14246 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14249 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14250 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14251 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
14252 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
14253 &rmt.fp_addr.ip4, rmt.fp_len,
14254 clib_net_to_host_u16 (mp->rmt_port),
14255 clib_net_to_host_u32 (mp->action_index), mp->tag);
14260 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14261 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14262 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
14263 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
14264 &rmt.fp_addr.ip6, rmt.fp_len,
14265 clib_net_to_host_u16 (mp->rmt_port),
14266 clib_net_to_host_u32 (mp->action_index), mp->tag);
14271 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
14274 vat_main_t *vam = &vat_main;
14275 vat_json_node_t *node = NULL;
14276 struct in6_addr ip6;
14277 struct in_addr ip4;
14279 fib_prefix_t lcl, rmt;
14281 ip_prefix_decode (&mp->lcl, &lcl);
14282 ip_prefix_decode (&mp->rmt, &rmt);
14284 if (VAT_JSON_ARRAY != vam->json_tree.type)
14286 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14287 vat_json_init_array (&vam->json_tree);
14289 node = vat_json_array_add (&vam->json_tree);
14290 vat_json_init_object (node);
14292 vat_json_object_add_uint (node, "appns_index",
14293 clib_net_to_host_u32 (mp->appns_index));
14294 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
14295 vat_json_object_add_uint (node, "scope", mp->scope);
14296 vat_json_object_add_uint (node, "action_index",
14297 clib_net_to_host_u32 (mp->action_index));
14298 vat_json_object_add_uint (node, "lcl_port",
14299 clib_net_to_host_u16 (mp->lcl_port));
14300 vat_json_object_add_uint (node, "rmt_port",
14301 clib_net_to_host_u16 (mp->rmt_port));
14302 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
14303 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
14304 vat_json_object_add_string_copy (node, "tag", mp->tag);
14305 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14307 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
14308 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
14309 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
14310 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
14314 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
14315 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
14316 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
14317 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
14322 api_session_rule_add_del (vat_main_t * vam)
14324 vl_api_session_rule_add_del_t *mp;
14325 unformat_input_t *i = vam->input;
14326 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
14327 u32 appns_index = 0, scope = 0;
14328 ip4_address_t lcl_ip4, rmt_ip4;
14329 ip6_address_t lcl_ip6, rmt_ip6;
14330 u8 is_ip4 = 1, conn_set = 0;
14331 u8 is_add = 1, *tag = 0;
14333 fib_prefix_t lcl, rmt;
14335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14337 if (unformat (i, "del"))
14339 else if (unformat (i, "add"))
14341 else if (unformat (i, "proto tcp"))
14343 else if (unformat (i, "proto udp"))
14345 else if (unformat (i, "appns %d", &appns_index))
14347 else if (unformat (i, "scope %d", &scope))
14349 else if (unformat (i, "tag %_%v%_", &tag))
14353 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14354 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14362 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14363 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14369 else if (unformat (i, "action %d", &action))
14374 if (proto == ~0 || !conn_set || action == ~0)
14376 errmsg ("transport proto, connection and action must be set");
14382 errmsg ("scope should be 0-3");
14386 M (SESSION_RULE_ADD_DEL, mp);
14388 clib_memset (&lcl, 0, sizeof (lcl));
14389 clib_memset (&rmt, 0, sizeof (rmt));
14392 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14393 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14394 lcl.fp_len = lcl_plen;
14395 rmt.fp_len = rmt_plen;
14399 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14400 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14401 lcl.fp_len = lcl_plen;
14402 rmt.fp_len = rmt_plen;
14406 ip_prefix_encode (&lcl, &mp->lcl);
14407 ip_prefix_encode (&rmt, &mp->rmt);
14408 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14409 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14410 mp->transport_proto =
14411 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14412 mp->action_index = clib_host_to_net_u32 (action);
14413 mp->appns_index = clib_host_to_net_u32 (appns_index);
14415 mp->is_add = is_add;
14418 clib_memcpy (mp->tag, tag, vec_len (tag));
14428 api_session_rules_dump (vat_main_t * vam)
14430 vl_api_session_rules_dump_t *mp;
14431 vl_api_control_ping_t *mp_ping;
14434 if (!vam->json_output)
14436 print (vam->ofp, "%=20s", "Session Rules");
14439 M (SESSION_RULES_DUMP, mp);
14443 /* Use a control ping for synchronization */
14444 MPING (CONTROL_PING, mp_ping);
14447 /* Wait for a reply... */
14453 api_ip_container_proxy_add_del (vat_main_t * vam)
14455 vl_api_ip_container_proxy_add_del_t *mp;
14456 unformat_input_t *i = vam->input;
14457 u32 sw_if_index = ~0;
14458 vl_api_prefix_t pfx = { };
14462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14464 if (unformat (i, "del"))
14466 else if (unformat (i, "add"))
14468 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14470 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14475 if (sw_if_index == ~0 || pfx.len == 0)
14477 errmsg ("address and sw_if_index must be set");
14481 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14483 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14484 mp->is_add = is_add;
14485 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14493 api_qos_record_enable_disable (vat_main_t * vam)
14495 unformat_input_t *i = vam->input;
14496 vl_api_qos_record_enable_disable_t *mp;
14497 u32 sw_if_index, qs = 0xff;
14498 u8 sw_if_index_set = 0;
14502 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14504 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14505 sw_if_index_set = 1;
14506 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14507 sw_if_index_set = 1;
14508 else if (unformat (i, "%U", unformat_qos_source, &qs))
14510 else if (unformat (i, "disable"))
14514 clib_warning ("parse error '%U'", format_unformat_error, i);
14519 if (sw_if_index_set == 0)
14521 errmsg ("missing interface name or sw_if_index");
14526 errmsg ("input location must be specified");
14530 M (QOS_RECORD_ENABLE_DISABLE, mp);
14532 mp->record.sw_if_index = ntohl (sw_if_index);
14533 mp->record.input_source = qs;
14534 mp->enable = enable;
14543 q_or_quit (vat_main_t * vam)
14545 #if VPP_API_TEST_BUILTIN == 0
14546 longjmp (vam->jump_buf, 1);
14548 return 0; /* not so much */
14552 q (vat_main_t * vam)
14554 return q_or_quit (vam);
14558 quit (vat_main_t * vam)
14560 return q_or_quit (vam);
14564 comment (vat_main_t * vam)
14570 elog_save (vat_main_t * vam)
14572 #if VPP_API_TEST_BUILTIN == 0
14573 elog_main_t *em = &vam->elog_main;
14574 unformat_input_t *i = vam->input;
14575 char *file, *chroot_file;
14576 clib_error_t *error;
14578 if (!unformat (i, "%s", &file))
14580 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14584 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14585 if (strstr (file, "..") || index (file, '/'))
14587 errmsg ("illegal characters in filename '%s'", file);
14591 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14595 errmsg ("Saving %wd of %wd events to %s",
14596 elog_n_events_in_buffer (em),
14597 elog_buffer_capacity (em), chroot_file);
14599 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14600 vec_free (chroot_file);
14603 clib_error_report (error);
14605 errmsg ("Use the vpp event loger...");
14612 elog_setup (vat_main_t * vam)
14614 #if VPP_API_TEST_BUILTIN == 0
14615 elog_main_t *em = &vam->elog_main;
14616 unformat_input_t *i = vam->input;
14617 u32 nevents = 128 << 10;
14619 (void) unformat (i, "nevents %d", &nevents);
14621 elog_init (em, nevents);
14622 vl_api_set_elog_main (em);
14623 vl_api_set_elog_trace_api_messages (1);
14624 errmsg ("Event logger initialized with %u events", nevents);
14626 errmsg ("Use the vpp event loger...");
14632 elog_enable (vat_main_t * vam)
14634 #if VPP_API_TEST_BUILTIN == 0
14635 elog_main_t *em = &vam->elog_main;
14637 elog_enable_disable (em, 1 /* enable */ );
14638 vl_api_set_elog_trace_api_messages (1);
14639 errmsg ("Event logger enabled...");
14641 errmsg ("Use the vpp event loger...");
14647 elog_disable (vat_main_t * vam)
14649 #if VPP_API_TEST_BUILTIN == 0
14650 elog_main_t *em = &vam->elog_main;
14652 elog_enable_disable (em, 0 /* enable */ );
14653 vl_api_set_elog_trace_api_messages (1);
14654 errmsg ("Event logger disabled...");
14656 errmsg ("Use the vpp event loger...");
14662 statseg (vat_main_t * vam)
14664 ssvm_private_t *ssvmp = &vam->stat_segment;
14665 ssvm_shared_header_t *shared_header = ssvmp->sh;
14666 vlib_counter_t **counters;
14667 u64 thread0_index1_packets;
14668 u64 thread0_index1_bytes;
14669 f64 vector_rate, input_rate;
14672 uword *counter_vector_by_name;
14673 if (vam->stat_segment_lockp == 0)
14675 errmsg ("Stat segment not mapped...");
14679 /* look up "/if/rx for sw_if_index 1 as a test */
14681 clib_spinlock_lock (vam->stat_segment_lockp);
14683 counter_vector_by_name = (uword *) shared_header->opaque[1];
14685 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14688 clib_spinlock_unlock (vam->stat_segment_lockp);
14689 errmsg ("/if/tx not found?");
14693 /* Fish per-thread vector of combined counters from shared memory */
14694 counters = (vlib_counter_t **) p[0];
14696 if (vec_len (counters[0]) < 2)
14698 clib_spinlock_unlock (vam->stat_segment_lockp);
14699 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14703 /* Read thread 0 sw_if_index 1 counter */
14704 thread0_index1_packets = counters[0][1].packets;
14705 thread0_index1_bytes = counters[0][1].bytes;
14707 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14710 clib_spinlock_unlock (vam->stat_segment_lockp);
14711 errmsg ("vector_rate not found?");
14715 vector_rate = *(f64 *) (p[0]);
14716 p = hash_get_mem (counter_vector_by_name, "input_rate");
14719 clib_spinlock_unlock (vam->stat_segment_lockp);
14720 errmsg ("input_rate not found?");
14723 input_rate = *(f64 *) (p[0]);
14725 clib_spinlock_unlock (vam->stat_segment_lockp);
14727 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14728 vector_rate, input_rate);
14729 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14730 thread0_index1_packets, thread0_index1_bytes);
14736 cmd_cmp (void *a1, void *a2)
14741 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14745 help (vat_main_t * vam)
14750 unformat_input_t *i = vam->input;
14753 if (unformat (i, "%s", &name))
14757 vec_add1 (name, 0);
14759 hs = hash_get_mem (vam->help_by_name, name);
14761 print (vam->ofp, "usage: %s %s", name, hs[0]);
14763 print (vam->ofp, "No such msg / command '%s'", name);
14768 print (vam->ofp, "Help is available for the following:");
14771 hash_foreach_pair (p, vam->function_by_name,
14773 vec_add1 (cmds, (u8 *)(p->key));
14777 vec_sort_with_function (cmds, cmd_cmp);
14779 for (j = 0; j < vec_len (cmds); j++)
14780 print (vam->ofp, "%s", cmds[j]);
14787 set (vat_main_t * vam)
14789 u8 *name = 0, *value = 0;
14790 unformat_input_t *i = vam->input;
14792 if (unformat (i, "%s", &name))
14794 /* The input buffer is a vector, not a string. */
14795 value = vec_dup (i->buffer);
14796 vec_delete (value, i->index, 0);
14797 /* Almost certainly has a trailing newline */
14798 if (value[vec_len (value) - 1] == '\n')
14799 value[vec_len (value) - 1] = 0;
14800 /* Make sure it's a proper string, one way or the other */
14801 vec_add1 (value, 0);
14802 (void) clib_macro_set_value (&vam->macro_main,
14803 (char *) name, (char *) value);
14806 errmsg ("usage: set <name> <value>");
14814 unset (vat_main_t * vam)
14818 if (unformat (vam->input, "%s", &name))
14819 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14820 errmsg ("unset: %s wasn't set", name);
14833 macro_sort_cmp (void *a1, void *a2)
14835 macro_sort_t *s1 = a1;
14836 macro_sort_t *s2 = a2;
14838 return strcmp ((char *) (s1->name), (char *) (s2->name));
14842 dump_macro_table (vat_main_t * vam)
14844 macro_sort_t *sort_me = 0, *sm;
14849 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14851 vec_add2 (sort_me, sm, 1);
14852 sm->name = (u8 *)(p->key);
14853 sm->value = (u8 *) (p->value[0]);
14857 vec_sort_with_function (sort_me, macro_sort_cmp);
14859 if (vec_len (sort_me))
14860 print (vam->ofp, "%-15s%s", "Name", "Value");
14862 print (vam->ofp, "The macro table is empty...");
14864 for (i = 0; i < vec_len (sort_me); i++)
14865 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14870 dump_node_table (vat_main_t * vam)
14873 vlib_node_t *node, *next_node;
14875 if (vec_len (vam->graph_nodes) == 0)
14877 print (vam->ofp, "Node table empty, issue get_node_graph...");
14881 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14883 node = vam->graph_nodes[0][i];
14884 print (vam->ofp, "[%d] %s", i, node->name);
14885 for (j = 0; j < vec_len (node->next_nodes); j++)
14887 if (node->next_nodes[j] != ~0)
14889 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14890 print (vam->ofp, " [%d] %s", j, next_node->name);
14898 value_sort_cmp (void *a1, void *a2)
14900 name_sort_t *n1 = a1;
14901 name_sort_t *n2 = a2;
14903 if (n1->value < n2->value)
14905 if (n1->value > n2->value)
14912 dump_msg_api_table (vat_main_t * vam)
14914 api_main_t *am = vlibapi_get_main ();
14915 name_sort_t *nses = 0, *ns;
14920 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14922 vec_add2 (nses, ns, 1);
14923 ns->name = (u8 *)(hp->key);
14924 ns->value = (u32) hp->value[0];
14928 vec_sort_with_function (nses, value_sort_cmp);
14930 for (i = 0; i < vec_len (nses); i++)
14931 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14937 get_msg_id (vat_main_t * vam)
14942 if (unformat (vam->input, "%s", &name_and_crc))
14944 message_index = vl_msg_api_get_msg_index (name_and_crc);
14945 if (message_index == ~0)
14947 print (vam->ofp, " '%s' not found", name_and_crc);
14950 print (vam->ofp, " '%s' has message index %d",
14951 name_and_crc, message_index);
14954 errmsg ("name_and_crc required...");
14959 search_node_table (vat_main_t * vam)
14961 unformat_input_t *line_input = vam->input;
14964 vlib_node_t *node, *next_node;
14967 if (vam->graph_node_index_by_name == 0)
14969 print (vam->ofp, "Node table empty, issue get_node_graph...");
14973 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14975 if (unformat (line_input, "%s", &node_to_find))
14977 vec_add1 (node_to_find, 0);
14978 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14981 print (vam->ofp, "%s not found...", node_to_find);
14984 node = vam->graph_nodes[0][p[0]];
14985 print (vam->ofp, "[%d] %s", p[0], node->name);
14986 for (j = 0; j < vec_len (node->next_nodes); j++)
14988 if (node->next_nodes[j] != ~0)
14990 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14991 print (vam->ofp, " [%d] %s", j, next_node->name);
14998 clib_warning ("parse error '%U'", format_unformat_error,
15004 vec_free (node_to_find);
15013 script (vat_main_t * vam)
15015 #if (VPP_API_TEST_BUILTIN==0)
15017 char *save_current_file;
15018 unformat_input_t save_input;
15019 jmp_buf save_jump_buf;
15020 u32 save_line_number;
15022 FILE *new_fp, *save_ifp;
15024 if (unformat (vam->input, "%s", &s))
15026 new_fp = fopen ((char *) s, "r");
15029 errmsg ("Couldn't open script file %s", s);
15036 errmsg ("Missing script name");
15040 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
15041 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
15042 save_ifp = vam->ifp;
15043 save_line_number = vam->input_line_number;
15044 save_current_file = (char *) vam->current_file;
15046 vam->input_line_number = 0;
15048 vam->current_file = s;
15051 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
15052 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
15053 vam->ifp = save_ifp;
15054 vam->input_line_number = save_line_number;
15055 vam->current_file = (u8 *) save_current_file;
15060 clib_warning ("use the exec command...");
15066 echo (vat_main_t * vam)
15068 print (vam->ofp, "%v", vam->input->buffer);
15072 /* List of API message constructors, CLI names map to api_xxx */
15073 #define foreach_vpe_api_msg \
15074 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
15075 _(sw_interface_dump,"") \
15076 _(sw_interface_set_flags, \
15077 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
15078 _(sw_interface_add_del_address, \
15079 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
15080 _(sw_interface_set_rx_mode, \
15081 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
15082 _(sw_interface_set_rx_placement, \
15083 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
15084 _(sw_interface_rx_placement_dump, \
15085 "[<intfc> | sw_if_index <id>]") \
15086 _(sw_interface_set_table, \
15087 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
15088 _(sw_interface_set_mpls_enable, \
15089 "<intfc> | sw_if_index [disable | dis]") \
15090 _(sw_interface_set_vpath, \
15091 "<intfc> | sw_if_index <id> enable | disable") \
15092 _(sw_interface_set_vxlan_bypass, \
15093 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
15094 _(sw_interface_set_l2_xconnect, \
15095 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15096 "enable | disable") \
15097 _(sw_interface_set_l2_bridge, \
15098 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
15099 "[shg <split-horizon-group>] [bvi]\n" \
15100 "enable | disable") \
15101 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
15102 _(bridge_domain_add_del, \
15103 "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") \
15104 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
15106 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
15107 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
15108 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
15110 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15112 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15114 "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]") \
15116 "<vpp-if-name> | sw_if_index <id>") \
15117 _(sw_interface_tap_v2_dump, "") \
15118 _(virtio_pci_create_v2, \
15119 "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]") \
15120 _(virtio_pci_delete, \
15121 "<vpp-if-name> | sw_if_index <id>") \
15122 _(sw_interface_virtio_pci_dump, "") \
15124 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
15125 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
15128 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
15129 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
15130 "[id <if-id>] [gso]") \
15132 "<vpp-if-name> | sw_if_index <id>") \
15133 _(bond_add_member, \
15134 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
15135 _(bond_detach_member, \
15136 "sw_if_index <n>") \
15137 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
15138 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
15139 _(sw_member_interface_dump, \
15140 "<vpp-if-name> | sw_if_index <id>") \
15141 _(ip_table_add_del, \
15142 "table <n> [ipv6] [add | del]\n") \
15143 _(ip_route_add_del, \
15144 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
15145 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
15146 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
15147 "[multipath] [count <n>] [del]") \
15148 _(ip_mroute_add_del, \
15149 "<src> <grp>/<mask> [table-id <n>]\n" \
15150 "[<intfc> | sw_if_index <id>] [local] [del]") \
15151 _(mpls_table_add_del, \
15152 "table <n> [add | del]\n") \
15153 _(mpls_route_add_del, \
15154 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
15155 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
15156 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
15157 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
15158 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
15159 "[count <n>] [del]") \
15160 _(mpls_ip_bind_unbind, \
15161 "<label> <addr/len>") \
15162 _(mpls_tunnel_add_del, \
15163 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
15164 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
15165 "[l2-only] [out-label <n>]") \
15166 _(sr_mpls_policy_add, \
15167 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
15168 _(sr_mpls_policy_del, \
15170 _(bier_table_add_del, \
15171 "<label> <sub-domain> <set> <bsl> [del]") \
15172 _(bier_route_add_del, \
15173 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
15174 "[<intfc> | sw_if_index <id>]" \
15175 "[weight <n>] [del] [multipath]") \
15176 _(sw_interface_set_unnumbered, \
15177 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
15178 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
15179 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
15180 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
15181 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
15182 "[outer_vlan_id_any][inner_vlan_id_any]") \
15183 _(ip_table_replace_begin, "table <n> [ipv6]") \
15184 _(ip_table_flush, "table <n> [ipv6]") \
15185 _(ip_table_replace_end, "table <n> [ipv6]") \
15186 _(set_ip_flow_hash, \
15187 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
15188 _(sw_interface_ip6_enable_disable, \
15189 "<intfc> | sw_if_index <id> enable | disable") \
15190 _(l2_patch_add_del, \
15191 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15192 "enable | disable") \
15193 _(sr_localsid_add_del, \
15194 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
15195 "fib-table <num> (end.psp) sw_if_index <num>") \
15196 _(classify_add_del_table, \
15197 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15198 " [del] [del-chain] mask <mask-value>\n" \
15199 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
15200 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
15201 _(classify_add_del_session, \
15202 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15203 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15204 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
15205 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
15206 _(classify_set_interface_ip_table, \
15207 "<intfc> | sw_if_index <nn> table <nn>") \
15208 _(classify_set_interface_l2_tables, \
15209 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15210 " [other-table <nn>]") \
15211 _(get_node_index, "node <node-name") \
15212 _(add_node_next, "node <node-name> next <next-node-name>") \
15213 _(vxlan_offload_rx, \
15214 "hw { <interface name> | hw_if_index <nn>} " \
15215 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
15216 _(vxlan_add_del_tunnel, \
15217 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
15218 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
15219 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
15220 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15221 _(gre_tunnel_add_del, \
15222 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
15223 "[teb | erspan <session-id>] [del]") \
15224 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15225 _(l2_fib_clear_table, "") \
15226 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15227 _(l2_interface_vlan_tag_rewrite, \
15228 "<intfc> | sw_if_index <nn> \n" \
15229 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15230 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15231 _(create_vhost_user_if, \
15232 "socket <filename> [server] [renumber <dev_instance>] " \
15233 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
15234 "[mac <mac_address>] [packed]") \
15235 _(modify_vhost_user_if, \
15236 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15237 "[server] [renumber <dev_instance>] [gso] [packed]") \
15238 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15239 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
15240 _(show_version, "") \
15241 _(show_threads, "") \
15242 _(vxlan_gpe_add_del_tunnel, \
15243 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
15244 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
15245 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
15246 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
15247 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15248 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
15249 _(interface_name_renumber, \
15250 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15251 _(input_acl_set_interface, \
15252 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15253 " [l2-table <nn>] [del]") \
15254 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
15255 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15256 _(ip_dump, "ipv4 | ipv6") \
15257 _(ipsec_spd_add_del, "spd_id <n> [del]") \
15258 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15260 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15261 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15262 " integ_alg <alg> integ_key <hex>") \
15263 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
15264 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15265 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15266 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
15267 _(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
15268 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
15269 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
15270 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
15271 " [instance <n>]") \
15272 _(ipsec_sa_dump, "[sa_id <n>]") \
15273 _(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
15274 _(delete_loopback,"sw_if_index <nn>") \
15275 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15276 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
15277 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
15278 _(want_interface_events, "enable|disable") \
15279 _(get_first_msg_id, "client <name>") \
15280 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15281 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
15282 "fib-id <nn> [ip4][ip6][default]") \
15283 _(get_node_graph, " ") \
15284 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
15285 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15286 _(ioam_disable, "") \
15287 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
15288 _(af_packet_delete, "name <host interface name>") \
15289 _(af_packet_dump, "") \
15290 _(policer_add_del, "name <policer name> <params> [del]") \
15291 _(policer_dump, "[name <policer name>]") \
15292 _(policer_classify_set_interface, \
15293 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15294 " [l2-table <nn>] [del]") \
15295 _(policer_classify_dump, "type [ip4|ip6|l2]") \
15296 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
15297 _(mpls_table_dump, "") \
15298 _(mpls_route_dump, "table-id <ID>") \
15299 _(classify_table_ids, "") \
15300 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15301 _(classify_table_info, "table_id <nn>") \
15302 _(classify_session_dump, "table_id <nn>") \
15303 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15304 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15305 "[template_interval <nn>] [udp_checksum]") \
15306 _(ipfix_exporter_dump, "") \
15307 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15308 _(ipfix_classify_stream_dump, "") \
15309 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
15310 _(ipfix_classify_table_dump, "") \
15311 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
15312 _(sw_interface_span_dump, "[l2]") \
15313 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15314 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
15315 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
15316 _(pg_enable_disable, "[stream <id>] disable") \
15317 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
15318 _(ip_source_and_port_range_check_add_del, \
15319 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15320 _(ip_source_and_port_range_check_interface_add_del, \
15321 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
15322 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15323 _(delete_subif,"<intfc> | sw_if_index <nn>") \
15324 _(l2_interface_pbb_tag_rewrite, \
15325 "<intfc> | sw_if_index <nn> \n" \
15326 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15327 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15328 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
15329 _(flow_classify_set_interface, \
15330 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
15331 _(flow_classify_dump, "type [ip4|ip6]") \
15332 _(ip_table_dump, "") \
15333 _(ip_route_dump, "table-id [ip4|ip6]") \
15334 _(ip_mtable_dump, "") \
15335 _(ip_mroute_dump, "table-id [ip4|ip6]") \
15336 _(feature_enable_disable, "arc_name <arc_name> " \
15337 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
15338 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
15339 "[enable | disable] ") \
15340 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
15342 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
15343 "mac <mac-address> [del]") \
15344 _(l2_xconnect_dump, "") \
15345 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
15346 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
15347 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
15348 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
15349 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
15350 _(sock_init_shm, "size <nnn>") \
15351 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
15352 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
15353 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15354 _(session_rules_dump, "") \
15355 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15356 _(output_acl_set_interface, \
15357 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15358 " [l2-table <nn>] [del]") \
15359 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15361 /* List of command functions, CLI names map directly to functions */
15362 #define foreach_cli_function \
15363 _(comment, "usage: comment <ignore-rest-of-line>") \
15364 _(dump_interface_table, "usage: dump_interface_table") \
15365 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15366 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15367 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15368 _(dump_macro_table, "usage: dump_macro_table ") \
15369 _(dump_node_table, "usage: dump_node_table") \
15370 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15371 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15372 _(elog_disable, "usage: elog_disable") \
15373 _(elog_enable, "usage: elog_enable") \
15374 _(elog_save, "usage: elog_save <filename>") \
15375 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15376 _(echo, "usage: echo <message>") \
15377 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15378 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15379 _(help, "usage: help") \
15380 _(q, "usage: quit") \
15381 _(quit, "usage: quit") \
15382 _(search_node_table, "usage: search_node_table <name>...") \
15383 _(set, "usage: set <variable-name> <value>") \
15384 _(script, "usage: script <file-name>") \
15385 _(statseg, "usage: statseg") \
15386 _(unset, "usage: unset <variable-name>")
15389 static void vl_api_##n##_t_handler_uni \
15390 (vl_api_##n##_t * mp) \
15392 vat_main_t * vam = &vat_main; \
15393 if (vam->json_output) { \
15394 vl_api_##n##_t_handler_json(mp); \
15396 vl_api_##n##_t_handler(mp); \
15399 foreach_vpe_api_reply_msg;
15400 #if VPP_API_TEST_BUILTIN == 0
15401 foreach_standalone_reply_msg;
15406 vat_api_hookup (vat_main_t * vam)
15409 vl_msg_api_set_handlers(VL_API_##N, #n, \
15410 vl_api_##n##_t_handler_uni, \
15412 vl_api_##n##_t_endian, \
15413 vl_api_##n##_t_print, \
15414 sizeof(vl_api_##n##_t), 1);
15415 foreach_vpe_api_reply_msg;
15416 #if VPP_API_TEST_BUILTIN == 0
15417 foreach_standalone_reply_msg;
15421 #if (VPP_API_TEST_BUILTIN==0)
15422 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15424 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15426 vam->function_by_name = hash_create_string (0, sizeof (uword));
15428 vam->help_by_name = hash_create_string (0, sizeof (uword));
15431 /* API messages we can send */
15432 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15433 foreach_vpe_api_msg;
15437 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15438 foreach_vpe_api_msg;
15441 /* CLI functions */
15442 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15443 foreach_cli_function;
15447 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15448 foreach_cli_function;
15452 #if VPP_API_TEST_BUILTIN
15453 static clib_error_t *
15454 vat_api_hookup_shim (vlib_main_t * vm)
15456 vat_api_hookup (&vat_main);
15460 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15464 * fd.io coding-style-patch-verification: ON
15467 * eval: (c-set-style "gnu")