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>
34 #include <vpp/api/vpe_msg_enum.h>
35 #include <vnet/l2/l2_classify.h>
36 #include <vnet/l2/l2_vtr.h>
37 #include <vnet/classify/in_out_acl.h>
38 #include <vnet/classify/policer_classify.h>
39 #include <vnet/classify/flow_classify.h>
40 #include <vnet/mpls/mpls.h>
41 #include <vnet/ipsec/ipsec.h>
43 #include <vnet/ip/ip6_hop_by_hop.h>
44 #include <vnet/ip/ip_source_and_port_range_check.h>
45 #include <vnet/policer/xlate.h>
46 #include <vnet/span/span.h>
47 #include <vnet/policer/policer.h>
48 #include <vnet/policer/police.h>
49 #include <vnet/mfib/mfib_types.h>
50 #include <vnet/bonding/node.h>
51 #include <vnet/qos/qos_types.h>
52 #include <vnet/ethernet/ethernet_types_api.h>
53 #include <vnet/ip/ip_types_api.h>
54 #include "vat/json_format.h"
55 #include <vnet/ip/ip_types_api.h>
56 #include <vnet/ethernet/ethernet_types_api.h>
61 #define vl_typedefs /* define message structures */
62 #include <vpp/api/vpe_all_api_h.h>
65 /* declare message handlers for each api */
67 #define vl_endianfun /* define message structures */
68 #include <vpp/api/vpe_all_api_h.h>
71 /* instantiate all the print functions we know about */
72 #if VPP_API_TEST_BUILTIN == 0
73 #define vl_print(handle, ...)
75 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
78 #include <vpp/api/vpe_all_api_h.h>
81 #define __plugin_msg_base 0
82 #include <vlibapi/vat_helper_macros.h>
84 #include <vnet/format_fns.h>
86 void vl_api_set_elog_main (elog_main_t * m);
87 int vl_api_set_elog_trace_api_messages (int enable);
89 #if VPP_API_TEST_BUILTIN == 0
99 vat_socket_connect (vat_main_t * vam)
102 api_main_t *am = vlibapi_get_main ();
103 vam->socket_client_main = &socket_client_main;
104 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
106 0 /* default socket rx, tx buffer */ )))
109 /* vpp expects the client index in network order */
110 vam->my_client_index = htonl (socket_client_main.client_index);
111 am->my_client_index = vam->my_client_index;
114 #else /* vpp built-in case, we don't do sockets... */
116 vat_socket_connect (vat_main_t * vam)
122 vl_socket_client_read (int wait)
128 vl_socket_client_write ()
134 vl_socket_client_msg_alloc (int nbytes)
142 vat_time_now (vat_main_t * vam)
144 #if VPP_API_TEST_BUILTIN
145 return vlib_time_now (vam->vlib_main);
147 return clib_time_now (&vam->clib_time);
152 errmsg (char *fmt, ...)
154 vat_main_t *vam = &vat_main;
159 s = va_format (0, fmt, &va);
164 #if VPP_API_TEST_BUILTIN
165 vlib_cli_output (vam->vlib_main, (char *) s);
168 if (vam->ifp != stdin)
169 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
170 vam->input_line_number);
172 fformat (vam->ofp, "%s\n", (char *) s);
180 #if VPP_API_TEST_BUILTIN == 0
182 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
184 vat_main_t *vam = va_arg (*args, vat_main_t *);
185 u32 *result = va_arg (*args, u32 *);
189 if (!unformat (input, "%s", &if_name))
192 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
200 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
205 /* Parse an IP4 address %d.%d.%d.%d. */
207 unformat_ip4_address (unformat_input_t * input, va_list * args)
209 u8 *result = va_arg (*args, u8 *);
212 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
215 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
227 unformat_ethernet_address (unformat_input_t * input, va_list * args)
229 u8 *result = va_arg (*args, u8 *);
232 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
233 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
237 for (i = 0; i < 6; i++)
238 if (a[i] >= (1 << 8))
241 for (i = 0; i < 6; i++)
247 /* Returns ethernet type as an int in host byte order. */
249 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
252 u16 *result = va_arg (*args, u16 *);
256 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
258 if (type >= (1 << 16))
266 /* Parse an IP46 address. */
268 unformat_ip46_address (unformat_input_t * input, va_list * args)
270 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
271 ip46_type_t type = va_arg (*args, ip46_type_t);
272 if ((type != IP46_TYPE_IP6) &&
273 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
275 ip46_address_mask_ip4 (ip46);
278 else if ((type != IP46_TYPE_IP4) &&
279 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
286 /* Parse an IP6 address. */
288 unformat_ip6_address (unformat_input_t * input, va_list * args)
290 ip6_address_t *result = va_arg (*args, ip6_address_t *);
292 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
293 uword c, n_colon, double_colon_index;
295 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
296 double_colon_index = ARRAY_LEN (hex_quads);
297 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
300 if (c >= '0' && c <= '9')
302 else if (c >= 'a' && c <= 'f')
303 hex_digit = c + 10 - 'a';
304 else if (c >= 'A' && c <= 'F')
305 hex_digit = c + 10 - 'A';
306 else if (c == ':' && n_colon < 2)
310 unformat_put_input (input);
314 /* Too many hex quads. */
315 if (n_hex_quads >= ARRAY_LEN (hex_quads))
320 hex_quad = (hex_quad << 4) | hex_digit;
322 /* Hex quad must fit in 16 bits. */
323 if (n_hex_digits >= 4)
330 /* Save position of :: */
333 /* More than one :: ? */
334 if (double_colon_index < ARRAY_LEN (hex_quads))
336 double_colon_index = n_hex_quads;
339 if (n_colon > 0 && n_hex_digits > 0)
341 hex_quads[n_hex_quads++] = hex_quad;
347 if (n_hex_digits > 0)
348 hex_quads[n_hex_quads++] = hex_quad;
353 /* Expand :: to appropriate number of zero hex quads. */
354 if (double_colon_index < ARRAY_LEN (hex_quads))
356 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
358 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
359 hex_quads[n_zero + i] = hex_quads[i];
361 for (i = 0; i < n_zero; i++)
362 hex_quads[double_colon_index + i] = 0;
364 n_hex_quads = ARRAY_LEN (hex_quads);
367 /* Too few hex quads given. */
368 if (n_hex_quads < ARRAY_LEN (hex_quads))
371 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
372 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
379 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
381 u32 *r = va_arg (*args, u32 *);
384 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
385 foreach_ipsec_policy_action
393 format_ipsec_crypto_alg (u8 * s, va_list * args)
395 u32 i = va_arg (*args, u32);
400 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
401 foreach_ipsec_crypto_alg
404 return format (s, "unknown");
406 return format (s, "%s", t);
410 format_ipsec_integ_alg (u8 * s, va_list * args)
412 u32 i = va_arg (*args, u32);
417 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
418 foreach_ipsec_integ_alg
421 return format (s, "unknown");
423 return format (s, "%s", t);
426 #else /* VPP_API_TEST_BUILTIN == 1 */
428 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
430 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
431 vnet_main_t *vnm = vnet_get_main ();
432 u32 *result = va_arg (*args, u32 *);
434 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
438 api_unformat_hw_if_index (unformat_input_t * input, va_list * args)
440 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
441 vnet_main_t *vnm = vnet_get_main ();
442 u32 *result = va_arg (*args, u32 *);
444 return unformat (input, "%U", unformat_vnet_hw_interface, vnm, result);
447 #endif /* VPP_API_TEST_BUILTIN */
450 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
452 u32 *r = va_arg (*args, u32 *);
455 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
456 foreach_ipsec_crypto_alg
464 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
466 u32 *r = va_arg (*args, u32 *);
469 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
470 foreach_ipsec_integ_alg
478 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
480 u8 *r = va_arg (*args, u8 *);
482 if (unformat (input, "kbps"))
483 *r = SSE2_QOS_RATE_KBPS;
484 else if (unformat (input, "pps"))
485 *r = SSE2_QOS_RATE_PPS;
492 unformat_policer_round_type (unformat_input_t * input, va_list * args)
494 u8 *r = va_arg (*args, u8 *);
496 if (unformat (input, "closest"))
497 *r = SSE2_QOS_ROUND_TO_CLOSEST;
498 else if (unformat (input, "up"))
499 *r = SSE2_QOS_ROUND_TO_UP;
500 else if (unformat (input, "down"))
501 *r = SSE2_QOS_ROUND_TO_DOWN;
508 unformat_policer_type (unformat_input_t * input, va_list * args)
510 u8 *r = va_arg (*args, u8 *);
512 if (unformat (input, "1r2c"))
513 *r = SSE2_QOS_POLICER_TYPE_1R2C;
514 else if (unformat (input, "1r3c"))
515 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
516 else if (unformat (input, "2r3c-2698"))
517 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
518 else if (unformat (input, "2r3c-4115"))
519 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
520 else if (unformat (input, "2r3c-mef5cf1"))
521 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
528 unformat_dscp (unformat_input_t * input, va_list * va)
530 u8 *r = va_arg (*va, u8 *);
533 #define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
542 unformat_policer_action_type (unformat_input_t * input, va_list * va)
544 sse2_qos_pol_action_params_st *a
545 = va_arg (*va, sse2_qos_pol_action_params_st *);
547 if (unformat (input, "drop"))
548 a->action_type = SSE2_QOS_ACTION_DROP;
549 else if (unformat (input, "transmit"))
550 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
551 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
552 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
559 unformat_policer_classify_table_type (unformat_input_t * input, va_list * va)
561 u32 *r = va_arg (*va, u32 *);
564 if (unformat (input, "ip4"))
565 tid = POLICER_CLASSIFY_TABLE_IP4;
566 else if (unformat (input, "ip6"))
567 tid = POLICER_CLASSIFY_TABLE_IP6;
568 else if (unformat (input, "l2"))
569 tid = POLICER_CLASSIFY_TABLE_L2;
578 unformat_flow_classify_table_type (unformat_input_t * input, va_list * va)
580 u32 *r = va_arg (*va, u32 *);
583 if (unformat (input, "ip4"))
584 tid = FLOW_CLASSIFY_TABLE_IP4;
585 else if (unformat (input, "ip6"))
586 tid = FLOW_CLASSIFY_TABLE_IP6;
594 #if (VPP_API_TEST_BUILTIN==0)
596 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
597 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
598 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
599 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
602 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
604 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
605 mfib_itf_attribute_t attr;
608 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
610 if (unformat (input, mfib_itf_flag_long_names[attr]))
611 *iflags |= (1 << attr);
613 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
615 if (unformat (input, mfib_itf_flag_names[attr]))
616 *iflags |= (1 << attr);
619 return (old == *iflags ? 0 : 1);
623 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
625 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
626 mfib_entry_attribute_t attr;
629 FOR_EACH_MFIB_ATTRIBUTE (attr)
631 if (unformat (input, mfib_flag_long_names[attr]))
632 *eflags |= (1 << attr);
634 FOR_EACH_MFIB_ATTRIBUTE (attr)
636 if (unformat (input, mfib_flag_names[attr]))
637 *eflags |= (1 << attr);
640 return (old == *eflags ? 0 : 1);
644 format_ip4_address (u8 * s, va_list * args)
646 u8 *a = va_arg (*args, u8 *);
647 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
651 format_ip6_address (u8 * s, va_list * args)
653 ip6_address_t *a = va_arg (*args, ip6_address_t *);
654 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
656 i_max_n_zero = ARRAY_LEN (a->as_u16);
658 i_first_zero = i_max_n_zero;
660 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
662 u32 is_zero = a->as_u16[i] == 0;
663 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
669 if ((!is_zero && n_zeros > max_n_zeros)
670 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
672 i_max_n_zero = i_first_zero;
673 max_n_zeros = n_zeros;
674 i_first_zero = ARRAY_LEN (a->as_u16);
679 last_double_colon = 0;
680 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
682 if (i == i_max_n_zero && max_n_zeros > 1)
684 s = format (s, "::");
685 i += max_n_zeros - 1;
686 last_double_colon = 1;
690 s = format (s, "%s%x",
691 (last_double_colon || i == 0) ? "" : ":",
692 clib_net_to_host_u16 (a->as_u16[i]));
693 last_double_colon = 0;
700 /* Format an IP46 address. */
702 format_ip46_address (u8 * s, va_list * args)
704 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
705 ip46_type_t type = va_arg (*args, ip46_type_t);
711 is_ip4 = ip46_address_is_ip4 (ip46);
722 format (s, "%U", format_ip4_address, &ip46->ip4) :
723 format (s, "%U", format_ip6_address, &ip46->ip6);
727 format_ethernet_address (u8 * s, va_list * args)
729 u8 *a = va_arg (*args, u8 *);
731 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
732 a[0], a[1], a[2], a[3], a[4], a[5]);
737 increment_v4_address (vl_api_ip4_address_t * i)
739 ip4_address_t *a = (ip4_address_t *) i;
742 v = ntohl (a->as_u32) + 1;
743 a->as_u32 = ntohl (v);
747 increment_v6_address (vl_api_ip6_address_t * i)
749 ip6_address_t *a = (ip6_address_t *) i;
752 v0 = clib_net_to_host_u64 (a->as_u64[0]);
753 v1 = clib_net_to_host_u64 (a->as_u64[1]);
758 a->as_u64[0] = clib_net_to_host_u64 (v0);
759 a->as_u64[1] = clib_net_to_host_u64 (v1);
763 increment_address (vl_api_address_t * a)
765 if (a->af == ADDRESS_IP4)
766 increment_v4_address (&a->un.ip4);
767 else if (a->af == ADDRESS_IP6)
768 increment_v6_address (&a->un.ip6);
772 set_ip4_address (vl_api_address_t * a, u32 v)
774 if (a->af == ADDRESS_IP4)
776 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
782 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
785 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
787 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
788 sizeof (ip6_address_t));
792 increment_mac_address (u8 * mac)
794 u64 tmp = *((u64 *) mac);
795 tmp = clib_net_to_host_u64 (tmp);
796 tmp += 1 << 16; /* skip unused (least significant) octets */
797 tmp = clib_host_to_net_u64 (tmp);
799 clib_memcpy (mac, &tmp, 6);
803 vat_json_object_add_address (vat_json_node_t * node,
804 const char *str, const vl_api_address_t * addr)
806 if (ADDRESS_IP6 == addr->af)
810 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
811 vat_json_object_add_ip6 (node, str, ip6);
817 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
818 vat_json_object_add_ip4 (node, str, ip4);
823 vat_json_object_add_prefix (vat_json_node_t * node,
824 const vl_api_prefix_t * prefix)
826 vat_json_object_add_uint (node, "len", prefix->len);
827 vat_json_object_add_address (node, "address", &prefix->address);
830 static void vl_api_create_loopback_reply_t_handler
831 (vl_api_create_loopback_reply_t * mp)
833 vat_main_t *vam = &vat_main;
834 i32 retval = ntohl (mp->retval);
836 vam->retval = retval;
837 vam->regenerate_interface_table = 1;
838 vam->sw_if_index = ntohl (mp->sw_if_index);
839 vam->result_ready = 1;
842 static void vl_api_create_loopback_reply_t_handler_json
843 (vl_api_create_loopback_reply_t * mp)
845 vat_main_t *vam = &vat_main;
846 vat_json_node_t node;
848 vat_json_init_object (&node);
849 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
850 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
852 vat_json_print (vam->ofp, &node);
853 vat_json_free (&node);
854 vam->retval = ntohl (mp->retval);
855 vam->result_ready = 1;
858 static void vl_api_create_loopback_instance_reply_t_handler
859 (vl_api_create_loopback_instance_reply_t * mp)
861 vat_main_t *vam = &vat_main;
862 i32 retval = ntohl (mp->retval);
864 vam->retval = retval;
865 vam->regenerate_interface_table = 1;
866 vam->sw_if_index = ntohl (mp->sw_if_index);
867 vam->result_ready = 1;
870 static void vl_api_create_loopback_instance_reply_t_handler_json
871 (vl_api_create_loopback_instance_reply_t * mp)
873 vat_main_t *vam = &vat_main;
874 vat_json_node_t node;
876 vat_json_init_object (&node);
877 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
878 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
880 vat_json_print (vam->ofp, &node);
881 vat_json_free (&node);
882 vam->retval = ntohl (mp->retval);
883 vam->result_ready = 1;
886 static void vl_api_af_packet_create_reply_t_handler
887 (vl_api_af_packet_create_reply_t * mp)
889 vat_main_t *vam = &vat_main;
890 i32 retval = ntohl (mp->retval);
892 vam->retval = retval;
893 vam->regenerate_interface_table = 1;
894 vam->sw_if_index = ntohl (mp->sw_if_index);
895 vam->result_ready = 1;
898 static void vl_api_af_packet_create_reply_t_handler_json
899 (vl_api_af_packet_create_reply_t * mp)
901 vat_main_t *vam = &vat_main;
902 vat_json_node_t node;
904 vat_json_init_object (&node);
905 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
906 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
908 vat_json_print (vam->ofp, &node);
909 vat_json_free (&node);
911 vam->retval = ntohl (mp->retval);
912 vam->result_ready = 1;
915 static void vl_api_create_vlan_subif_reply_t_handler
916 (vl_api_create_vlan_subif_reply_t * mp)
918 vat_main_t *vam = &vat_main;
919 i32 retval = ntohl (mp->retval);
921 vam->retval = retval;
922 vam->regenerate_interface_table = 1;
923 vam->sw_if_index = ntohl (mp->sw_if_index);
924 vam->result_ready = 1;
927 static void vl_api_create_vlan_subif_reply_t_handler_json
928 (vl_api_create_vlan_subif_reply_t * mp)
930 vat_main_t *vam = &vat_main;
931 vat_json_node_t node;
933 vat_json_init_object (&node);
934 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
935 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
937 vat_json_print (vam->ofp, &node);
938 vat_json_free (&node);
940 vam->retval = ntohl (mp->retval);
941 vam->result_ready = 1;
944 static void vl_api_create_subif_reply_t_handler
945 (vl_api_create_subif_reply_t * mp)
947 vat_main_t *vam = &vat_main;
948 i32 retval = ntohl (mp->retval);
950 vam->retval = retval;
951 vam->regenerate_interface_table = 1;
952 vam->sw_if_index = ntohl (mp->sw_if_index);
953 vam->result_ready = 1;
956 static void vl_api_create_subif_reply_t_handler_json
957 (vl_api_create_subif_reply_t * mp)
959 vat_main_t *vam = &vat_main;
960 vat_json_node_t node;
962 vat_json_init_object (&node);
963 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
964 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
966 vat_json_print (vam->ofp, &node);
967 vat_json_free (&node);
969 vam->retval = ntohl (mp->retval);
970 vam->result_ready = 1;
973 static void vl_api_interface_name_renumber_reply_t_handler
974 (vl_api_interface_name_renumber_reply_t * mp)
976 vat_main_t *vam = &vat_main;
977 i32 retval = ntohl (mp->retval);
979 vam->retval = retval;
980 vam->regenerate_interface_table = 1;
981 vam->result_ready = 1;
984 static void vl_api_interface_name_renumber_reply_t_handler_json
985 (vl_api_interface_name_renumber_reply_t * mp)
987 vat_main_t *vam = &vat_main;
988 vat_json_node_t node;
990 vat_json_init_object (&node);
991 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
993 vat_json_print (vam->ofp, &node);
994 vat_json_free (&node);
996 vam->retval = ntohl (mp->retval);
997 vam->result_ready = 1;
1001 * Special-case: build the interface table, maintain
1002 * the next loopback sw_if_index vbl.
1004 static void vl_api_sw_interface_details_t_handler
1005 (vl_api_sw_interface_details_t * mp)
1007 vat_main_t *vam = &vat_main;
1008 u8 *s = format (0, "%s%c", mp->interface_name, 0);
1010 hash_set_mem (vam->sw_if_index_by_interface_name, s,
1011 ntohl (mp->sw_if_index));
1013 /* In sub interface case, fill the sub interface table entry */
1014 if (mp->sw_if_index != mp->sup_sw_if_index)
1016 sw_interface_subif_t *sub = NULL;
1018 vec_add2 (vam->sw_if_subif_table, sub, 1);
1020 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
1021 strncpy ((char *) sub->interface_name, (char *) s,
1022 vec_len (sub->interface_name));
1023 sub->sw_if_index = ntohl (mp->sw_if_index);
1024 sub->sub_id = ntohl (mp->sub_id);
1026 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
1028 sub->sub_number_of_tags = mp->sub_number_of_tags;
1029 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
1030 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
1032 /* vlan tag rewrite */
1033 sub->vtr_op = ntohl (mp->vtr_op);
1034 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
1035 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
1036 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
1040 static void vl_api_sw_interface_details_t_handler_json
1041 (vl_api_sw_interface_details_t * mp)
1043 vat_main_t *vam = &vat_main;
1044 vat_json_node_t *node = NULL;
1046 if (VAT_JSON_ARRAY != vam->json_tree.type)
1048 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1049 vat_json_init_array (&vam->json_tree);
1051 node = vat_json_array_add (&vam->json_tree);
1053 vat_json_init_object (node);
1054 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1055 vat_json_object_add_uint (node, "sup_sw_if_index",
1056 ntohl (mp->sup_sw_if_index));
1057 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1058 sizeof (mp->l2_address));
1059 vat_json_object_add_string_copy (node, "interface_name",
1060 mp->interface_name);
1061 vat_json_object_add_string_copy (node, "interface_dev_type",
1062 mp->interface_dev_type);
1063 vat_json_object_add_uint (node, "flags", mp->flags);
1064 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1065 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1066 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1067 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1068 vat_json_object_add_uint (node, "sub_number_of_tags",
1069 mp->sub_number_of_tags);
1070 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1071 ntohs (mp->sub_outer_vlan_id));
1072 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1073 ntohs (mp->sub_inner_vlan_id));
1074 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1075 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1076 vat_json_object_add_uint (node, "vtr_push_dot1q",
1077 ntohl (mp->vtr_push_dot1q));
1078 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1079 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1080 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1082 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1084 format_ethernet_address,
1086 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1088 format_ethernet_address,
1090 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1091 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1095 #if VPP_API_TEST_BUILTIN == 0
1096 static void vl_api_sw_interface_event_t_handler
1097 (vl_api_sw_interface_event_t * mp)
1099 vat_main_t *vam = &vat_main;
1100 if (vam->interface_event_display)
1101 errmsg ("interface flags: sw_if_index %d %s %s",
1102 ntohl (mp->sw_if_index),
1103 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1104 "admin-up" : "admin-down",
1105 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1106 "link-up" : "link-down");
1110 __clib_unused static void
1111 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1113 /* JSON output not supported */
1117 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1119 vat_main_t *vam = &vat_main;
1120 i32 retval = ntohl (mp->retval);
1122 vam->retval = retval;
1123 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1124 vam->result_ready = 1;
1128 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1130 vat_main_t *vam = &vat_main;
1131 vat_json_node_t node;
1135 vat_json_init_object (&node);
1136 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1137 vat_json_object_add_uint (&node, "reply_in_shmem",
1138 ntohl (mp->reply_in_shmem));
1139 /* Toss the shared-memory original... */
1140 oldheap = vl_msg_push_heap ();
1142 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1145 vl_msg_pop_heap (oldheap);
1147 vat_json_print (vam->ofp, &node);
1148 vat_json_free (&node);
1150 vam->retval = ntohl (mp->retval);
1151 vam->result_ready = 1;
1155 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1157 vat_main_t *vam = &vat_main;
1158 i32 retval = ntohl (mp->retval);
1160 vec_reset_length (vam->cmd_reply);
1162 vam->retval = retval;
1164 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1165 vam->result_ready = 1;
1169 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1171 vat_main_t *vam = &vat_main;
1172 vat_json_node_t node;
1173 u8 *reply = 0; /* reply vector */
1175 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1176 vec_reset_length (vam->cmd_reply);
1178 vat_json_init_object (&node);
1179 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1180 vat_json_object_add_string_copy (&node, "reply", reply);
1182 vat_json_print (vam->ofp, &node);
1183 vat_json_free (&node);
1186 vam->retval = ntohl (mp->retval);
1187 vam->result_ready = 1;
1190 static void vl_api_classify_add_del_table_reply_t_handler
1191 (vl_api_classify_add_del_table_reply_t * mp)
1193 vat_main_t *vam = &vat_main;
1194 i32 retval = ntohl (mp->retval);
1195 if (vam->async_mode)
1197 vam->async_errors += (retval < 0);
1201 vam->retval = retval;
1203 ((mp->new_table_index != 0xFFFFFFFF) ||
1204 (mp->skip_n_vectors != 0xFFFFFFFF) ||
1205 (mp->match_n_vectors != 0xFFFFFFFF)))
1207 * Note: this is just barely thread-safe, depends on
1208 * the main thread spinning waiting for an answer...
1210 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d",
1211 ntohl (mp->new_table_index),
1212 ntohl (mp->skip_n_vectors), ntohl (mp->match_n_vectors));
1213 vam->result_ready = 1;
1217 static void vl_api_classify_add_del_table_reply_t_handler_json
1218 (vl_api_classify_add_del_table_reply_t * mp)
1220 vat_main_t *vam = &vat_main;
1221 vat_json_node_t node;
1223 vat_json_init_object (&node);
1224 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1225 vat_json_object_add_uint (&node, "new_table_index",
1226 ntohl (mp->new_table_index));
1227 vat_json_object_add_uint (&node, "skip_n_vectors",
1228 ntohl (mp->skip_n_vectors));
1229 vat_json_object_add_uint (&node, "match_n_vectors",
1230 ntohl (mp->match_n_vectors));
1232 vat_json_print (vam->ofp, &node);
1233 vat_json_free (&node);
1235 vam->retval = ntohl (mp->retval);
1236 vam->result_ready = 1;
1239 static void vl_api_get_node_index_reply_t_handler
1240 (vl_api_get_node_index_reply_t * mp)
1242 vat_main_t *vam = &vat_main;
1243 i32 retval = ntohl (mp->retval);
1244 if (vam->async_mode)
1246 vam->async_errors += (retval < 0);
1250 vam->retval = retval;
1252 errmsg ("node index %d", ntohl (mp->node_index));
1253 vam->result_ready = 1;
1257 static void vl_api_get_node_index_reply_t_handler_json
1258 (vl_api_get_node_index_reply_t * mp)
1260 vat_main_t *vam = &vat_main;
1261 vat_json_node_t node;
1263 vat_json_init_object (&node);
1264 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1265 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1267 vat_json_print (vam->ofp, &node);
1268 vat_json_free (&node);
1270 vam->retval = ntohl (mp->retval);
1271 vam->result_ready = 1;
1274 static void vl_api_get_next_index_reply_t_handler
1275 (vl_api_get_next_index_reply_t * mp)
1277 vat_main_t *vam = &vat_main;
1278 i32 retval = ntohl (mp->retval);
1279 if (vam->async_mode)
1281 vam->async_errors += (retval < 0);
1285 vam->retval = retval;
1287 errmsg ("next node index %d", ntohl (mp->next_index));
1288 vam->result_ready = 1;
1292 static void vl_api_get_next_index_reply_t_handler_json
1293 (vl_api_get_next_index_reply_t * mp)
1295 vat_main_t *vam = &vat_main;
1296 vat_json_node_t node;
1298 vat_json_init_object (&node);
1299 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1300 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1302 vat_json_print (vam->ofp, &node);
1303 vat_json_free (&node);
1305 vam->retval = ntohl (mp->retval);
1306 vam->result_ready = 1;
1309 static void vl_api_add_node_next_reply_t_handler
1310 (vl_api_add_node_next_reply_t * mp)
1312 vat_main_t *vam = &vat_main;
1313 i32 retval = ntohl (mp->retval);
1314 if (vam->async_mode)
1316 vam->async_errors += (retval < 0);
1320 vam->retval = retval;
1322 errmsg ("next index %d", ntohl (mp->next_index));
1323 vam->result_ready = 1;
1327 static void vl_api_add_node_next_reply_t_handler_json
1328 (vl_api_add_node_next_reply_t * mp)
1330 vat_main_t *vam = &vat_main;
1331 vat_json_node_t node;
1333 vat_json_init_object (&node);
1334 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1335 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1337 vat_json_print (vam->ofp, &node);
1338 vat_json_free (&node);
1340 vam->retval = ntohl (mp->retval);
1341 vam->result_ready = 1;
1344 static void vl_api_show_version_reply_t_handler
1345 (vl_api_show_version_reply_t * mp)
1347 vat_main_t *vam = &vat_main;
1348 i32 retval = ntohl (mp->retval);
1352 errmsg (" program: %s", mp->program);
1353 errmsg (" version: %s", mp->version);
1354 errmsg (" build date: %s", mp->build_date);
1355 errmsg ("build directory: %s", mp->build_directory);
1357 vam->retval = retval;
1358 vam->result_ready = 1;
1361 static void vl_api_show_version_reply_t_handler_json
1362 (vl_api_show_version_reply_t * mp)
1364 vat_main_t *vam = &vat_main;
1365 vat_json_node_t node;
1367 vat_json_init_object (&node);
1368 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1369 vat_json_object_add_string_copy (&node, "program", mp->program);
1370 vat_json_object_add_string_copy (&node, "version", mp->version);
1371 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1372 vat_json_object_add_string_copy (&node, "build_directory",
1373 mp->build_directory);
1375 vat_json_print (vam->ofp, &node);
1376 vat_json_free (&node);
1378 vam->retval = ntohl (mp->retval);
1379 vam->result_ready = 1;
1382 static void vl_api_show_threads_reply_t_handler
1383 (vl_api_show_threads_reply_t * mp)
1385 vat_main_t *vam = &vat_main;
1386 i32 retval = ntohl (mp->retval);
1390 count = ntohl (mp->count);
1392 for (i = 0; i < count; i++)
1394 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1395 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1396 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1397 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1398 ntohl (mp->thread_data[i].cpu_socket));
1400 vam->retval = retval;
1401 vam->result_ready = 1;
1404 static void vl_api_show_threads_reply_t_handler_json
1405 (vl_api_show_threads_reply_t * mp)
1407 vat_main_t *vam = &vat_main;
1408 vat_json_node_t node;
1409 vl_api_thread_data_t *td;
1410 i32 retval = ntohl (mp->retval);
1414 count = ntohl (mp->count);
1416 vat_json_init_object (&node);
1417 vat_json_object_add_int (&node, "retval", retval);
1418 vat_json_object_add_uint (&node, "count", count);
1420 for (i = 0; i < count; i++)
1422 td = &mp->thread_data[i];
1423 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1424 vat_json_object_add_string_copy (&node, "name", td->name);
1425 vat_json_object_add_string_copy (&node, "type", td->type);
1426 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1427 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1428 vat_json_object_add_int (&node, "core", ntohl (td->id));
1429 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1432 vat_json_print (vam->ofp, &node);
1433 vat_json_free (&node);
1435 vam->retval = retval;
1436 vam->result_ready = 1;
1440 api_show_threads (vat_main_t * vam)
1442 vl_api_show_threads_t *mp;
1446 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1447 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1449 M (SHOW_THREADS, mp);
1457 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1459 u32 n_macs = ntohl (mp->n_macs);
1460 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1461 ntohl (mp->pid), mp->client_index, n_macs);
1463 for (i = 0; i < n_macs; i++)
1465 vl_api_mac_entry_t *mac = &mp->mac[i];
1466 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1467 i + 1, ntohl (mac->sw_if_index),
1468 format_ethernet_address, mac->mac_addr, mac->action);
1475 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1477 /* JSON output not supported */
1480 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1481 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1484 * Special-case: build the bridge domain table, maintain
1485 * the next bd id vbl.
1487 static void vl_api_bridge_domain_details_t_handler
1488 (vl_api_bridge_domain_details_t * mp)
1490 vat_main_t *vam = &vat_main;
1491 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1494 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1495 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1497 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1498 ntohl (mp->bd_id), mp->learn, mp->forward,
1499 mp->flood, ntohl (mp->bvi_sw_if_index),
1500 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1504 vl_api_bridge_domain_sw_if_t *sw_ifs;
1505 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1508 sw_ifs = mp->sw_if_details;
1509 for (i = 0; i < n_sw_ifs; i++)
1515 sw_if_index = ntohl (sw_ifs->sw_if_index);
1518 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1520 if ((u32) p->value[0] == sw_if_index)
1522 sw_if_name = (u8 *)(p->key);
1527 print (vam->ofp, "%7d %3d %s", sw_if_index,
1528 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1529 "sw_if_index not found!");
1536 static void vl_api_bridge_domain_details_t_handler_json
1537 (vl_api_bridge_domain_details_t * mp)
1539 vat_main_t *vam = &vat_main;
1540 vat_json_node_t *node, *array = NULL;
1541 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1543 if (VAT_JSON_ARRAY != vam->json_tree.type)
1545 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1546 vat_json_init_array (&vam->json_tree);
1548 node = vat_json_array_add (&vam->json_tree);
1550 vat_json_init_object (node);
1551 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1552 vat_json_object_add_uint (node, "flood", mp->flood);
1553 vat_json_object_add_uint (node, "forward", mp->forward);
1554 vat_json_object_add_uint (node, "learn", mp->learn);
1555 vat_json_object_add_uint (node, "bvi_sw_if_index",
1556 ntohl (mp->bvi_sw_if_index));
1557 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1558 array = vat_json_object_add (node, "sw_if");
1559 vat_json_init_array (array);
1565 vl_api_bridge_domain_sw_if_t *sw_ifs;
1568 sw_ifs = mp->sw_if_details;
1569 for (i = 0; i < n_sw_ifs; i++)
1571 node = vat_json_array_add (array);
1572 vat_json_init_object (node);
1573 vat_json_object_add_uint (node, "sw_if_index",
1574 ntohl (sw_ifs->sw_if_index));
1575 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1581 static void vl_api_control_ping_reply_t_handler
1582 (vl_api_control_ping_reply_t * mp)
1584 vat_main_t *vam = &vat_main;
1585 i32 retval = ntohl (mp->retval);
1586 if (vam->async_mode)
1588 vam->async_errors += (retval < 0);
1592 vam->retval = retval;
1593 vam->result_ready = 1;
1595 if (vam->socket_client_main)
1596 vam->socket_client_main->control_pings_outstanding--;
1599 static void vl_api_control_ping_reply_t_handler_json
1600 (vl_api_control_ping_reply_t * mp)
1602 vat_main_t *vam = &vat_main;
1603 i32 retval = ntohl (mp->retval);
1605 if (VAT_JSON_NONE != vam->json_tree.type)
1607 vat_json_print (vam->ofp, &vam->json_tree);
1608 vat_json_free (&vam->json_tree);
1609 vam->json_tree.type = VAT_JSON_NONE;
1614 vat_json_init_array (&vam->json_tree);
1615 vat_json_print (vam->ofp, &vam->json_tree);
1616 vam->json_tree.type = VAT_JSON_NONE;
1619 vam->retval = retval;
1620 vam->result_ready = 1;
1624 vl_api_bridge_domain_set_mac_age_reply_t_handler
1625 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1627 vat_main_t *vam = &vat_main;
1628 i32 retval = ntohl (mp->retval);
1629 if (vam->async_mode)
1631 vam->async_errors += (retval < 0);
1635 vam->retval = retval;
1636 vam->result_ready = 1;
1640 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1641 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1643 vat_main_t *vam = &vat_main;
1644 vat_json_node_t node;
1646 vat_json_init_object (&node);
1647 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1649 vat_json_print (vam->ofp, &node);
1650 vat_json_free (&node);
1652 vam->retval = ntohl (mp->retval);
1653 vam->result_ready = 1;
1657 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1659 vat_main_t *vam = &vat_main;
1660 i32 retval = ntohl (mp->retval);
1661 if (vam->async_mode)
1663 vam->async_errors += (retval < 0);
1667 vam->retval = retval;
1668 vam->result_ready = 1;
1672 static void vl_api_l2_flags_reply_t_handler_json
1673 (vl_api_l2_flags_reply_t * mp)
1675 vat_main_t *vam = &vat_main;
1676 vat_json_node_t node;
1678 vat_json_init_object (&node);
1679 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1680 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1681 ntohl (mp->resulting_feature_bitmap));
1683 vat_json_print (vam->ofp, &node);
1684 vat_json_free (&node);
1686 vam->retval = ntohl (mp->retval);
1687 vam->result_ready = 1;
1690 static void vl_api_bridge_flags_reply_t_handler
1691 (vl_api_bridge_flags_reply_t * mp)
1693 vat_main_t *vam = &vat_main;
1694 i32 retval = ntohl (mp->retval);
1695 if (vam->async_mode)
1697 vam->async_errors += (retval < 0);
1701 vam->retval = retval;
1702 vam->result_ready = 1;
1706 static void vl_api_bridge_flags_reply_t_handler_json
1707 (vl_api_bridge_flags_reply_t * mp)
1709 vat_main_t *vam = &vat_main;
1710 vat_json_node_t node;
1712 vat_json_init_object (&node);
1713 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1714 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1715 ntohl (mp->resulting_feature_bitmap));
1717 vat_json_print (vam->ofp, &node);
1718 vat_json_free (&node);
1720 vam->retval = ntohl (mp->retval);
1721 vam->result_ready = 1;
1725 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1727 vat_main_t *vam = &vat_main;
1728 i32 retval = ntohl (mp->retval);
1729 if (vam->async_mode)
1731 vam->async_errors += (retval < 0);
1735 vam->retval = retval;
1736 vam->sw_if_index = ntohl (mp->sw_if_index);
1737 vam->result_ready = 1;
1742 static void vl_api_tap_create_v2_reply_t_handler_json
1743 (vl_api_tap_create_v2_reply_t * mp)
1745 vat_main_t *vam = &vat_main;
1746 vat_json_node_t node;
1748 vat_json_init_object (&node);
1749 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1750 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1752 vat_json_print (vam->ofp, &node);
1753 vat_json_free (&node);
1755 vam->retval = ntohl (mp->retval);
1756 vam->result_ready = 1;
1761 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1763 vat_main_t *vam = &vat_main;
1764 i32 retval = ntohl (mp->retval);
1765 if (vam->async_mode)
1767 vam->async_errors += (retval < 0);
1771 vam->retval = retval;
1772 vam->result_ready = 1;
1776 static void vl_api_tap_delete_v2_reply_t_handler_json
1777 (vl_api_tap_delete_v2_reply_t * mp)
1779 vat_main_t *vam = &vat_main;
1780 vat_json_node_t node;
1782 vat_json_init_object (&node);
1783 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1785 vat_json_print (vam->ofp, &node);
1786 vat_json_free (&node);
1788 vam->retval = ntohl (mp->retval);
1789 vam->result_ready = 1;
1793 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1796 vat_main_t *vam = &vat_main;
1797 i32 retval = ntohl (mp->retval);
1798 if (vam->async_mode)
1800 vam->async_errors += (retval < 0);
1804 vam->retval = retval;
1805 vam->sw_if_index = ntohl (mp->sw_if_index);
1806 vam->result_ready = 1;
1810 static void vl_api_virtio_pci_create_reply_t_handler_json
1811 (vl_api_virtio_pci_create_reply_t * mp)
1813 vat_main_t *vam = &vat_main;
1814 vat_json_node_t node;
1816 vat_json_init_object (&node);
1817 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1818 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1820 vat_json_print (vam->ofp, &node);
1821 vat_json_free (&node);
1823 vam->retval = ntohl (mp->retval);
1824 vam->result_ready = 1;
1829 vl_api_virtio_pci_create_v2_reply_t_handler
1830 (vl_api_virtio_pci_create_v2_reply_t * mp)
1832 vat_main_t *vam = &vat_main;
1833 i32 retval = ntohl (mp->retval);
1834 if (vam->async_mode)
1836 vam->async_errors += (retval < 0);
1840 vam->retval = retval;
1841 vam->sw_if_index = ntohl (mp->sw_if_index);
1842 vam->result_ready = 1;
1846 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1847 (vl_api_virtio_pci_create_v2_reply_t * mp)
1849 vat_main_t *vam = &vat_main;
1850 vat_json_node_t node;
1852 vat_json_init_object (&node);
1853 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1854 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1856 vat_json_print (vam->ofp, &node);
1857 vat_json_free (&node);
1859 vam->retval = ntohl (mp->retval);
1860 vam->result_ready = 1;
1864 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1867 vat_main_t *vam = &vat_main;
1868 i32 retval = ntohl (mp->retval);
1869 if (vam->async_mode)
1871 vam->async_errors += (retval < 0);
1875 vam->retval = retval;
1876 vam->result_ready = 1;
1880 static void vl_api_virtio_pci_delete_reply_t_handler_json
1881 (vl_api_virtio_pci_delete_reply_t * mp)
1883 vat_main_t *vam = &vat_main;
1884 vat_json_node_t node;
1886 vat_json_init_object (&node);
1887 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1889 vat_json_print (vam->ofp, &node);
1890 vat_json_free (&node);
1892 vam->retval = ntohl (mp->retval);
1893 vam->result_ready = 1;
1897 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1899 vat_main_t *vam = &vat_main;
1900 i32 retval = ntohl (mp->retval);
1902 if (vam->async_mode)
1904 vam->async_errors += (retval < 0);
1908 vam->retval = retval;
1909 vam->sw_if_index = ntohl (mp->sw_if_index);
1910 vam->result_ready = 1;
1914 static void vl_api_bond_create_reply_t_handler_json
1915 (vl_api_bond_create_reply_t * mp)
1917 vat_main_t *vam = &vat_main;
1918 vat_json_node_t node;
1920 vat_json_init_object (&node);
1921 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1922 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1924 vat_json_print (vam->ofp, &node);
1925 vat_json_free (&node);
1927 vam->retval = ntohl (mp->retval);
1928 vam->result_ready = 1;
1932 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1934 vat_main_t *vam = &vat_main;
1935 i32 retval = ntohl (mp->retval);
1937 if (vam->async_mode)
1939 vam->async_errors += (retval < 0);
1943 vam->retval = retval;
1944 vam->sw_if_index = ntohl (mp->sw_if_index);
1945 vam->result_ready = 1;
1949 static void vl_api_bond_create2_reply_t_handler_json
1950 (vl_api_bond_create2_reply_t * mp)
1952 vat_main_t *vam = &vat_main;
1953 vat_json_node_t node;
1955 vat_json_init_object (&node);
1956 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1957 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1959 vat_json_print (vam->ofp, &node);
1960 vat_json_free (&node);
1962 vam->retval = ntohl (mp->retval);
1963 vam->result_ready = 1;
1967 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1969 vat_main_t *vam = &vat_main;
1970 i32 retval = ntohl (mp->retval);
1972 if (vam->async_mode)
1974 vam->async_errors += (retval < 0);
1978 vam->retval = retval;
1979 vam->result_ready = 1;
1983 static void vl_api_bond_delete_reply_t_handler_json
1984 (vl_api_bond_delete_reply_t * mp)
1986 vat_main_t *vam = &vat_main;
1987 vat_json_node_t node;
1989 vat_json_init_object (&node);
1990 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1992 vat_json_print (vam->ofp, &node);
1993 vat_json_free (&node);
1995 vam->retval = ntohl (mp->retval);
1996 vam->result_ready = 1;
2000 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
2002 vat_main_t *vam = &vat_main;
2003 i32 retval = ntohl (mp->retval);
2005 if (vam->async_mode)
2007 vam->async_errors += (retval < 0);
2011 vam->retval = retval;
2012 vam->result_ready = 1;
2016 static void vl_api_bond_add_member_reply_t_handler_json
2017 (vl_api_bond_add_member_reply_t * mp)
2019 vat_main_t *vam = &vat_main;
2020 vat_json_node_t node;
2022 vat_json_init_object (&node);
2023 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2025 vat_json_print (vam->ofp, &node);
2026 vat_json_free (&node);
2028 vam->retval = ntohl (mp->retval);
2029 vam->result_ready = 1;
2033 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
2036 vat_main_t *vam = &vat_main;
2037 i32 retval = ntohl (mp->retval);
2039 if (vam->async_mode)
2041 vam->async_errors += (retval < 0);
2045 vam->retval = retval;
2046 vam->result_ready = 1;
2050 static void vl_api_bond_detach_member_reply_t_handler_json
2051 (vl_api_bond_detach_member_reply_t * mp)
2053 vat_main_t *vam = &vat_main;
2054 vat_json_node_t node;
2056 vat_json_init_object (&node);
2057 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2059 vat_json_print (vam->ofp, &node);
2060 vat_json_free (&node);
2062 vam->retval = ntohl (mp->retval);
2063 vam->result_ready = 1;
2067 api_sw_interface_set_bond_weight (vat_main_t * vam)
2069 unformat_input_t *i = vam->input;
2070 vl_api_sw_interface_set_bond_weight_t *mp;
2071 u32 sw_if_index = ~0;
2073 u8 weight_enter = 0;
2076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2078 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2080 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2082 else if (unformat (i, "weight %u", &weight))
2088 if (sw_if_index == ~0)
2090 errmsg ("missing interface name or sw_if_index");
2093 if (weight_enter == 0)
2095 errmsg ("missing valid weight");
2099 /* Construct the API message */
2100 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
2101 mp->sw_if_index = ntohl (sw_if_index);
2102 mp->weight = ntohl (weight);
2109 static void vl_api_sw_bond_interface_details_t_handler
2110 (vl_api_sw_bond_interface_details_t * mp)
2112 vat_main_t *vam = &vat_main;
2115 "%-16s %-12d %-12U %-13U %-14u %-14u",
2116 mp->interface_name, ntohl (mp->sw_if_index),
2117 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2118 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2121 static void vl_api_sw_bond_interface_details_t_handler_json
2122 (vl_api_sw_bond_interface_details_t * mp)
2124 vat_main_t *vam = &vat_main;
2125 vat_json_node_t *node = NULL;
2127 if (VAT_JSON_ARRAY != vam->json_tree.type)
2129 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2130 vat_json_init_array (&vam->json_tree);
2132 node = vat_json_array_add (&vam->json_tree);
2134 vat_json_init_object (node);
2135 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2136 vat_json_object_add_string_copy (node, "interface_name",
2137 mp->interface_name);
2138 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2139 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2140 vat_json_object_add_uint (node, "active_members",
2141 ntohl (mp->active_members));
2142 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2146 api_sw_bond_interface_dump (vat_main_t * vam)
2148 unformat_input_t *i = vam->input;
2149 vl_api_sw_bond_interface_dump_t *mp;
2150 vl_api_control_ping_t *mp_ping;
2152 u32 sw_if_index = ~0;
2154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2156 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2158 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2165 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2166 "interface name", "sw_if_index", "mode", "load balance",
2167 "active members", "members");
2169 /* Get list of bond interfaces */
2170 M (SW_BOND_INTERFACE_DUMP, mp);
2171 mp->sw_if_index = ntohl (sw_if_index);
2174 /* Use a control ping for synchronization */
2175 MPING (CONTROL_PING, mp_ping);
2182 static void vl_api_sw_member_interface_details_t_handler
2183 (vl_api_sw_member_interface_details_t * mp)
2185 vat_main_t *vam = &vat_main;
2188 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2189 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2190 ntohl (mp->weight), mp->is_local_numa);
2193 static void vl_api_sw_member_interface_details_t_handler_json
2194 (vl_api_sw_member_interface_details_t * mp)
2196 vat_main_t *vam = &vat_main;
2197 vat_json_node_t *node = NULL;
2199 if (VAT_JSON_ARRAY != vam->json_tree.type)
2201 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2202 vat_json_init_array (&vam->json_tree);
2204 node = vat_json_array_add (&vam->json_tree);
2206 vat_json_init_object (node);
2207 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2208 vat_json_object_add_string_copy (node, "interface_name",
2209 mp->interface_name);
2210 vat_json_object_add_uint (node, "passive", mp->is_passive);
2211 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2212 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2213 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2217 api_sw_member_interface_dump (vat_main_t * vam)
2219 unformat_input_t *i = vam->input;
2220 vl_api_sw_member_interface_dump_t *mp;
2221 vl_api_control_ping_t *mp_ping;
2222 u32 sw_if_index = ~0;
2223 u8 sw_if_index_set = 0;
2226 /* Parse args required to build the message */
2227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2229 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2230 sw_if_index_set = 1;
2231 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2232 sw_if_index_set = 1;
2237 if (sw_if_index_set == 0)
2239 errmsg ("missing vpp interface name. ");
2244 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2245 "member interface name", "sw_if_index", "passive", "long_timeout",
2246 "weight", "local numa");
2248 /* Get list of bond interfaces */
2249 M (SW_MEMBER_INTERFACE_DUMP, mp);
2250 mp->sw_if_index = ntohl (sw_if_index);
2253 /* Use a control ping for synchronization */
2254 MPING (CONTROL_PING, mp_ping);
2261 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2262 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2264 vat_main_t *vam = &vat_main;
2265 i32 retval = ntohl (mp->retval);
2266 if (vam->async_mode)
2268 vam->async_errors += (retval < 0);
2272 vam->retval = retval;
2273 vam->sw_if_index = ntohl (mp->sw_if_index);
2274 vam->result_ready = 1;
2276 vam->regenerate_interface_table = 1;
2279 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2280 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2282 vat_main_t *vam = &vat_main;
2283 vat_json_node_t node;
2285 vat_json_init_object (&node);
2286 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2287 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2288 ntohl (mp->sw_if_index));
2290 vat_json_print (vam->ofp, &node);
2291 vat_json_free (&node);
2293 vam->retval = ntohl (mp->retval);
2294 vam->result_ready = 1;
2297 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
2298 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2300 vat_main_t *vam = &vat_main;
2301 i32 retval = ntohl (mp->retval);
2302 if (vam->async_mode)
2304 vam->async_errors += (retval < 0);
2308 vam->retval = retval;
2309 vam->sw_if_index = ntohl (mp->sw_if_index);
2310 vam->result_ready = 1;
2312 vam->regenerate_interface_table = 1;
2315 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
2316 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
2318 vat_main_t *vam = &vat_main;
2319 vat_json_node_t node;
2321 vat_json_init_object (&node);
2322 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2323 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2325 vat_json_print (vam->ofp, &node);
2326 vat_json_free (&node);
2328 vam->retval = ntohl (mp->retval);
2329 vam->result_ready = 1;
2332 static void vl_api_vxlan_offload_rx_reply_t_handler
2333 (vl_api_vxlan_offload_rx_reply_t * mp)
2335 vat_main_t *vam = &vat_main;
2336 i32 retval = ntohl (mp->retval);
2337 if (vam->async_mode)
2339 vam->async_errors += (retval < 0);
2343 vam->retval = retval;
2344 vam->result_ready = 1;
2348 static void vl_api_vxlan_offload_rx_reply_t_handler_json
2349 (vl_api_vxlan_offload_rx_reply_t * mp)
2351 vat_main_t *vam = &vat_main;
2352 vat_json_node_t node;
2354 vat_json_init_object (&node);
2355 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2357 vat_json_print (vam->ofp, &node);
2358 vat_json_free (&node);
2360 vam->retval = ntohl (mp->retval);
2361 vam->result_ready = 1;
2364 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler
2365 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2367 vat_main_t *vam = &vat_main;
2368 i32 retval = ntohl (mp->retval);
2369 if (vam->async_mode)
2371 vam->async_errors += (retval < 0);
2375 vam->retval = retval;
2376 vam->sw_if_index = ntohl (mp->sw_if_index);
2377 vam->result_ready = 1;
2379 vam->regenerate_interface_table = 1;
2382 static void vl_api_vxlan_gpe_add_del_tunnel_reply_t_handler_json
2383 (vl_api_vxlan_gpe_add_del_tunnel_reply_t * mp)
2385 vat_main_t *vam = &vat_main;
2386 vat_json_node_t node;
2388 vat_json_init_object (&node);
2389 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2390 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2392 vat_json_print (vam->ofp, &node);
2393 vat_json_free (&node);
2395 vam->retval = ntohl (mp->retval);
2396 vam->result_ready = 1;
2399 static void vl_api_gre_tunnel_add_del_reply_t_handler
2400 (vl_api_gre_tunnel_add_del_reply_t * mp)
2402 vat_main_t *vam = &vat_main;
2403 i32 retval = ntohl (mp->retval);
2404 if (vam->async_mode)
2406 vam->async_errors += (retval < 0);
2410 vam->retval = retval;
2411 vam->sw_if_index = ntohl (mp->sw_if_index);
2412 vam->result_ready = 1;
2416 static void vl_api_gre_tunnel_add_del_reply_t_handler_json
2417 (vl_api_gre_tunnel_add_del_reply_t * mp)
2419 vat_main_t *vam = &vat_main;
2420 vat_json_node_t node;
2422 vat_json_init_object (&node);
2423 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2424 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2426 vat_json_print (vam->ofp, &node);
2427 vat_json_free (&node);
2429 vam->retval = ntohl (mp->retval);
2430 vam->result_ready = 1;
2433 static void vl_api_create_vhost_user_if_reply_t_handler
2434 (vl_api_create_vhost_user_if_reply_t * mp)
2436 vat_main_t *vam = &vat_main;
2437 i32 retval = ntohl (mp->retval);
2438 if (vam->async_mode)
2440 vam->async_errors += (retval < 0);
2444 vam->retval = retval;
2445 vam->sw_if_index = ntohl (mp->sw_if_index);
2446 vam->result_ready = 1;
2448 vam->regenerate_interface_table = 1;
2451 static void vl_api_create_vhost_user_if_reply_t_handler_json
2452 (vl_api_create_vhost_user_if_reply_t * mp)
2454 vat_main_t *vam = &vat_main;
2455 vat_json_node_t node;
2457 vat_json_init_object (&node);
2458 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2459 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2461 vat_json_print (vam->ofp, &node);
2462 vat_json_free (&node);
2464 vam->retval = ntohl (mp->retval);
2465 vam->result_ready = 1;
2468 static void vl_api_ip_address_details_t_handler
2469 (vl_api_ip_address_details_t * mp)
2471 vat_main_t *vam = &vat_main;
2472 static ip_address_details_t empty_ip_address_details = { {0} };
2473 ip_address_details_t *address = NULL;
2474 ip_details_t *current_ip_details = NULL;
2475 ip_details_t *details = NULL;
2477 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2479 if (!details || vam->current_sw_if_index >= vec_len (details)
2480 || !details[vam->current_sw_if_index].present)
2482 errmsg ("ip address details arrived but not stored");
2483 errmsg ("ip_dump should be called first");
2487 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2489 #define addresses (current_ip_details->addr)
2491 vec_validate_init_empty (addresses, vec_len (addresses),
2492 empty_ip_address_details);
2494 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2496 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2497 address->prefix_length = mp->prefix.len;
2501 static void vl_api_ip_address_details_t_handler_json
2502 (vl_api_ip_address_details_t * mp)
2504 vat_main_t *vam = &vat_main;
2505 vat_json_node_t *node = NULL;
2507 if (VAT_JSON_ARRAY != vam->json_tree.type)
2509 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2510 vat_json_init_array (&vam->json_tree);
2512 node = vat_json_array_add (&vam->json_tree);
2514 vat_json_init_object (node);
2515 vat_json_object_add_prefix (node, &mp->prefix);
2519 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2521 vat_main_t *vam = &vat_main;
2522 static ip_details_t empty_ip_details = { 0 };
2523 ip_details_t *ip = NULL;
2524 u32 sw_if_index = ~0;
2526 sw_if_index = ntohl (mp->sw_if_index);
2528 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2529 sw_if_index, empty_ip_details);
2531 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2538 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2540 vat_main_t *vam = &vat_main;
2542 if (VAT_JSON_ARRAY != vam->json_tree.type)
2544 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2545 vat_json_init_array (&vam->json_tree);
2547 vat_json_array_add_uint (&vam->json_tree,
2548 clib_net_to_host_u32 (mp->sw_if_index));
2551 static void vl_api_get_first_msg_id_reply_t_handler
2552 (vl_api_get_first_msg_id_reply_t * mp)
2554 vat_main_t *vam = &vat_main;
2555 i32 retval = ntohl (mp->retval);
2557 if (vam->async_mode)
2559 vam->async_errors += (retval < 0);
2563 vam->retval = retval;
2564 vam->result_ready = 1;
2568 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2572 static void vl_api_get_first_msg_id_reply_t_handler_json
2573 (vl_api_get_first_msg_id_reply_t * mp)
2575 vat_main_t *vam = &vat_main;
2576 vat_json_node_t node;
2578 vat_json_init_object (&node);
2579 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2580 vat_json_object_add_uint (&node, "first_msg_id",
2581 (uint) ntohs (mp->first_msg_id));
2583 vat_json_print (vam->ofp, &node);
2584 vat_json_free (&node);
2586 vam->retval = ntohl (mp->retval);
2587 vam->result_ready = 1;
2590 static void vl_api_get_node_graph_reply_t_handler
2591 (vl_api_get_node_graph_reply_t * mp)
2593 vat_main_t *vam = &vat_main;
2594 i32 retval = ntohl (mp->retval);
2595 u8 *pvt_copy, *reply;
2600 if (vam->async_mode)
2602 vam->async_errors += (retval < 0);
2606 vam->retval = retval;
2607 vam->result_ready = 1;
2610 /* "Should never happen..." */
2614 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2615 pvt_copy = vec_dup (reply);
2617 /* Toss the shared-memory original... */
2618 oldheap = vl_msg_push_heap ();
2622 vl_msg_pop_heap (oldheap);
2624 if (vam->graph_nodes)
2626 hash_free (vam->graph_node_index_by_name);
2628 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2630 node = vam->graph_nodes[0][i];
2631 vec_free (node->name);
2632 vec_free (node->next_nodes);
2635 vec_free (vam->graph_nodes[0]);
2636 vec_free (vam->graph_nodes);
2639 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2640 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2641 vec_free (pvt_copy);
2643 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2645 node = vam->graph_nodes[0][i];
2646 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2650 static void vl_api_get_node_graph_reply_t_handler_json
2651 (vl_api_get_node_graph_reply_t * mp)
2653 vat_main_t *vam = &vat_main;
2655 vat_json_node_t node;
2658 /* $$$$ make this real? */
2659 vat_json_init_object (&node);
2660 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2661 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2663 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2665 /* Toss the shared-memory original... */
2666 oldheap = vl_msg_push_heap ();
2670 vl_msg_pop_heap (oldheap);
2672 vat_json_print (vam->ofp, &node);
2673 vat_json_free (&node);
2675 vam->retval = ntohl (mp->retval);
2676 vam->result_ready = 1;
2680 format_policer_type (u8 * s, va_list * va)
2682 u32 i = va_arg (*va, u32);
2684 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2685 s = format (s, "1r2c");
2686 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2687 s = format (s, "1r3c");
2688 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2689 s = format (s, "2r3c-2698");
2690 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2691 s = format (s, "2r3c-4115");
2692 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2693 s = format (s, "2r3c-mef5cf1");
2695 s = format (s, "ILLEGAL");
2700 format_policer_rate_type (u8 * s, va_list * va)
2702 u32 i = va_arg (*va, u32);
2704 if (i == SSE2_QOS_RATE_KBPS)
2705 s = format (s, "kbps");
2706 else if (i == SSE2_QOS_RATE_PPS)
2707 s = format (s, "pps");
2709 s = format (s, "ILLEGAL");
2714 format_policer_round_type (u8 * s, va_list * va)
2716 u32 i = va_arg (*va, u32);
2718 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2719 s = format (s, "closest");
2720 else if (i == SSE2_QOS_ROUND_TO_UP)
2721 s = format (s, "up");
2722 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2723 s = format (s, "down");
2725 s = format (s, "ILLEGAL");
2730 format_policer_action_type (u8 * s, va_list * va)
2732 u32 i = va_arg (*va, u32);
2734 if (i == SSE2_QOS_ACTION_DROP)
2735 s = format (s, "drop");
2736 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2737 s = format (s, "transmit");
2738 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2739 s = format (s, "mark-and-transmit");
2741 s = format (s, "ILLEGAL");
2746 format_dscp (u8 * s, va_list * va)
2748 u32 i = va_arg (*va, u32);
2753 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2757 return format (s, "ILLEGAL");
2759 s = format (s, "%s", t);
2764 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2766 vat_main_t *vam = &vat_main;
2767 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2769 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2770 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2772 conform_dscp_str = format (0, "");
2774 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2775 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2777 exceed_dscp_str = format (0, "");
2779 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2780 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2782 violate_dscp_str = format (0, "");
2784 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2785 "rate type %U, round type %U, %s rate, %s color-aware, "
2786 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2787 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2788 "conform action %U%s, exceed action %U%s, violate action %U%s",
2790 format_policer_type, mp->type,
2793 clib_net_to_host_u64 (mp->cb),
2794 clib_net_to_host_u64 (mp->eb),
2795 format_policer_rate_type, mp->rate_type,
2796 format_policer_round_type, mp->round_type,
2797 mp->single_rate ? "single" : "dual",
2798 mp->color_aware ? "is" : "not",
2799 ntohl (mp->cir_tokens_per_period),
2800 ntohl (mp->pir_tokens_per_period),
2802 ntohl (mp->current_limit),
2803 ntohl (mp->current_bucket),
2804 ntohl (mp->extended_limit),
2805 ntohl (mp->extended_bucket),
2806 clib_net_to_host_u64 (mp->last_update_time),
2807 format_policer_action_type, mp->conform_action.type,
2809 format_policer_action_type, mp->exceed_action.type,
2811 format_policer_action_type, mp->violate_action.type,
2814 vec_free (conform_dscp_str);
2815 vec_free (exceed_dscp_str);
2816 vec_free (violate_dscp_str);
2819 static void vl_api_policer_details_t_handler_json
2820 (vl_api_policer_details_t * mp)
2822 vat_main_t *vam = &vat_main;
2823 vat_json_node_t *node;
2824 u8 *rate_type_str, *round_type_str, *type_str;
2825 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2827 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2829 format (0, "%U", format_policer_round_type, mp->round_type);
2830 type_str = format (0, "%U", format_policer_type, mp->type);
2831 conform_action_str = format (0, "%U", format_policer_action_type,
2832 mp->conform_action.type);
2833 exceed_action_str = format (0, "%U", format_policer_action_type,
2834 mp->exceed_action.type);
2835 violate_action_str = format (0, "%U", format_policer_action_type,
2836 mp->violate_action.type);
2838 if (VAT_JSON_ARRAY != vam->json_tree.type)
2840 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2841 vat_json_init_array (&vam->json_tree);
2843 node = vat_json_array_add (&vam->json_tree);
2845 vat_json_init_object (node);
2846 vat_json_object_add_string_copy (node, "name", mp->name);
2847 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2848 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2849 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2850 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2851 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2852 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2853 vat_json_object_add_string_copy (node, "type", type_str);
2854 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2855 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2856 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2857 vat_json_object_add_uint (node, "cir_tokens_per_period",
2858 ntohl (mp->cir_tokens_per_period));
2859 vat_json_object_add_uint (node, "eir_tokens_per_period",
2860 ntohl (mp->pir_tokens_per_period));
2861 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2862 vat_json_object_add_uint (node, "current_bucket",
2863 ntohl (mp->current_bucket));
2864 vat_json_object_add_uint (node, "extended_limit",
2865 ntohl (mp->extended_limit));
2866 vat_json_object_add_uint (node, "extended_bucket",
2867 ntohl (mp->extended_bucket));
2868 vat_json_object_add_uint (node, "last_update_time",
2869 ntohl (mp->last_update_time));
2870 vat_json_object_add_string_copy (node, "conform_action",
2871 conform_action_str);
2872 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2874 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2875 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2876 vec_free (dscp_str);
2878 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2879 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2881 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2882 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2883 vec_free (dscp_str);
2885 vat_json_object_add_string_copy (node, "violate_action",
2886 violate_action_str);
2887 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2889 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2890 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2891 vec_free (dscp_str);
2894 vec_free (rate_type_str);
2895 vec_free (round_type_str);
2896 vec_free (type_str);
2897 vec_free (conform_action_str);
2898 vec_free (exceed_action_str);
2899 vec_free (violate_action_str);
2903 vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t *
2906 vat_main_t *vam = &vat_main;
2907 int i, count = ntohl (mp->count);
2910 print (vam->ofp, "classify table ids (%d) : ", count);
2911 for (i = 0; i < count; i++)
2913 print (vam->ofp, "%d", ntohl (mp->ids[i]));
2914 print (vam->ofp, (i < count - 1) ? "," : "");
2916 vam->retval = ntohl (mp->retval);
2917 vam->result_ready = 1;
2921 vl_api_classify_table_ids_reply_t_handler_json
2922 (vl_api_classify_table_ids_reply_t * mp)
2924 vat_main_t *vam = &vat_main;
2925 int i, count = ntohl (mp->count);
2929 vat_json_node_t node;
2931 vat_json_init_object (&node);
2932 for (i = 0; i < count; i++)
2934 vat_json_object_add_uint (&node, "table_id", ntohl (mp->ids[i]));
2936 vat_json_print (vam->ofp, &node);
2937 vat_json_free (&node);
2939 vam->retval = ntohl (mp->retval);
2940 vam->result_ready = 1;
2944 vl_api_classify_table_by_interface_reply_t_handler
2945 (vl_api_classify_table_by_interface_reply_t * mp)
2947 vat_main_t *vam = &vat_main;
2950 table_id = ntohl (mp->l2_table_id);
2952 print (vam->ofp, "l2 table id : %d", table_id);
2954 print (vam->ofp, "l2 table id : No input ACL tables configured");
2955 table_id = ntohl (mp->ip4_table_id);
2957 print (vam->ofp, "ip4 table id : %d", table_id);
2959 print (vam->ofp, "ip4 table id : No input ACL tables configured");
2960 table_id = ntohl (mp->ip6_table_id);
2962 print (vam->ofp, "ip6 table id : %d", table_id);
2964 print (vam->ofp, "ip6 table id : No input ACL tables configured");
2965 vam->retval = ntohl (mp->retval);
2966 vam->result_ready = 1;
2970 vl_api_classify_table_by_interface_reply_t_handler_json
2971 (vl_api_classify_table_by_interface_reply_t * mp)
2973 vat_main_t *vam = &vat_main;
2974 vat_json_node_t node;
2976 vat_json_init_object (&node);
2978 vat_json_object_add_int (&node, "l2_table_id", ntohl (mp->l2_table_id));
2979 vat_json_object_add_int (&node, "ip4_table_id", ntohl (mp->ip4_table_id));
2980 vat_json_object_add_int (&node, "ip6_table_id", ntohl (mp->ip6_table_id));
2982 vat_json_print (vam->ofp, &node);
2983 vat_json_free (&node);
2985 vam->retval = ntohl (mp->retval);
2986 vam->result_ready = 1;
2989 static void vl_api_policer_add_del_reply_t_handler
2990 (vl_api_policer_add_del_reply_t * mp)
2992 vat_main_t *vam = &vat_main;
2993 i32 retval = ntohl (mp->retval);
2994 if (vam->async_mode)
2996 vam->async_errors += (retval < 0);
3000 vam->retval = retval;
3001 vam->result_ready = 1;
3002 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
3004 * Note: this is just barely thread-safe, depends on
3005 * the main thread spinning waiting for an answer...
3007 errmsg ("policer index %d", ntohl (mp->policer_index));
3011 static void vl_api_policer_add_del_reply_t_handler_json
3012 (vl_api_policer_add_del_reply_t * mp)
3014 vat_main_t *vam = &vat_main;
3015 vat_json_node_t node;
3017 vat_json_init_object (&node);
3018 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3019 vat_json_object_add_uint (&node, "policer_index",
3020 ntohl (mp->policer_index));
3022 vat_json_print (vam->ofp, &node);
3023 vat_json_free (&node);
3025 vam->retval = ntohl (mp->retval);
3026 vam->result_ready = 1;
3029 /* Format hex dump. */
3031 format_hex_bytes (u8 * s, va_list * va)
3033 u8 *bytes = va_arg (*va, u8 *);
3034 int n_bytes = va_arg (*va, int);
3037 /* Print short or long form depending on byte count. */
3038 uword short_form = n_bytes <= 32;
3039 u32 indent = format_get_indent (s);
3044 for (i = 0; i < n_bytes; i++)
3046 if (!short_form && (i % 32) == 0)
3047 s = format (s, "%08x: ", i);
3048 s = format (s, "%02x", bytes[i]);
3049 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
3050 s = format (s, "\n%U", format_white_space, indent);
3057 vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t
3060 vat_main_t *vam = &vat_main;
3061 i32 retval = ntohl (mp->retval);
3064 print (vam->ofp, "classify table info :");
3065 print (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d",
3066 ntohl (mp->active_sessions), ntohl (mp->next_table_index),
3067 ntohl (mp->miss_next_index));
3068 print (vam->ofp, "nbuckets: %d skip: %d match: %d",
3069 ntohl (mp->nbuckets), ntohl (mp->skip_n_vectors),
3070 ntohl (mp->match_n_vectors));
3071 print (vam->ofp, "mask: %U", format_hex_bytes, mp->mask,
3072 ntohl (mp->mask_length));
3074 vam->retval = retval;
3075 vam->result_ready = 1;
3079 vl_api_classify_table_info_reply_t_handler_json
3080 (vl_api_classify_table_info_reply_t * mp)
3082 vat_main_t *vam = &vat_main;
3083 vat_json_node_t node;
3085 i32 retval = ntohl (mp->retval);
3088 vat_json_init_object (&node);
3090 vat_json_object_add_int (&node, "sessions",
3091 ntohl (mp->active_sessions));
3092 vat_json_object_add_int (&node, "nexttbl",
3093 ntohl (mp->next_table_index));
3094 vat_json_object_add_int (&node, "nextnode",
3095 ntohl (mp->miss_next_index));
3096 vat_json_object_add_int (&node, "nbuckets", ntohl (mp->nbuckets));
3097 vat_json_object_add_int (&node, "skip", ntohl (mp->skip_n_vectors));
3098 vat_json_object_add_int (&node, "match", ntohl (mp->match_n_vectors));
3099 u8 *s = format (0, "%U%c", format_hex_bytes, mp->mask,
3100 ntohl (mp->mask_length), 0);
3101 vat_json_object_add_string_copy (&node, "mask", s);
3103 vat_json_print (vam->ofp, &node);
3104 vat_json_free (&node);
3106 vam->retval = ntohl (mp->retval);
3107 vam->result_ready = 1;
3111 vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t *
3114 vat_main_t *vam = &vat_main;
3116 print (vam->ofp, "next_index: %d advance: %d opaque: %d ",
3117 ntohl (mp->hit_next_index), ntohl (mp->advance),
3118 ntohl (mp->opaque_index));
3119 print (vam->ofp, "mask: %U", format_hex_bytes, mp->match,
3120 ntohl (mp->match_length));
3124 vl_api_classify_session_details_t_handler_json
3125 (vl_api_classify_session_details_t * mp)
3127 vat_main_t *vam = &vat_main;
3128 vat_json_node_t *node = NULL;
3130 if (VAT_JSON_ARRAY != vam->json_tree.type)
3132 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3133 vat_json_init_array (&vam->json_tree);
3135 node = vat_json_array_add (&vam->json_tree);
3137 vat_json_init_object (node);
3138 vat_json_object_add_int (node, "next_index", ntohl (mp->hit_next_index));
3139 vat_json_object_add_int (node, "advance", ntohl (mp->advance));
3140 vat_json_object_add_int (node, "opaque", ntohl (mp->opaque_index));
3142 format (0, "%U%c", format_hex_bytes, mp->match, ntohl (mp->match_length),
3144 vat_json_object_add_string_copy (node, "match", s);
3147 static void vl_api_pg_create_interface_reply_t_handler
3148 (vl_api_pg_create_interface_reply_t * mp)
3150 vat_main_t *vam = &vat_main;
3152 vam->retval = ntohl (mp->retval);
3153 vam->result_ready = 1;
3156 static void vl_api_pg_create_interface_reply_t_handler_json
3157 (vl_api_pg_create_interface_reply_t * mp)
3159 vat_main_t *vam = &vat_main;
3160 vat_json_node_t node;
3162 i32 retval = ntohl (mp->retval);
3165 vat_json_init_object (&node);
3167 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
3169 vat_json_print (vam->ofp, &node);
3170 vat_json_free (&node);
3172 vam->retval = ntohl (mp->retval);
3173 vam->result_ready = 1;
3176 static void vl_api_policer_classify_details_t_handler
3177 (vl_api_policer_classify_details_t * mp)
3179 vat_main_t *vam = &vat_main;
3181 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3182 ntohl (mp->table_index));
3185 static void vl_api_policer_classify_details_t_handler_json
3186 (vl_api_policer_classify_details_t * mp)
3188 vat_main_t *vam = &vat_main;
3189 vat_json_node_t *node;
3191 if (VAT_JSON_ARRAY != vam->json_tree.type)
3193 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3194 vat_json_init_array (&vam->json_tree);
3196 node = vat_json_array_add (&vam->json_tree);
3198 vat_json_init_object (node);
3199 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3200 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3203 static void vl_api_flow_classify_details_t_handler
3204 (vl_api_flow_classify_details_t * mp)
3206 vat_main_t *vam = &vat_main;
3208 print (vam->ofp, "%10d%20d", ntohl (mp->sw_if_index),
3209 ntohl (mp->table_index));
3212 static void vl_api_flow_classify_details_t_handler_json
3213 (vl_api_flow_classify_details_t * mp)
3215 vat_main_t *vam = &vat_main;
3216 vat_json_node_t *node;
3218 if (VAT_JSON_ARRAY != vam->json_tree.type)
3220 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3221 vat_json_init_array (&vam->json_tree);
3223 node = vat_json_array_add (&vam->json_tree);
3225 vat_json_init_object (node);
3226 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3227 vat_json_object_add_uint (node, "table_index", ntohl (mp->table_index));
3231 * Generate boilerplate reply handlers, which
3232 * dig the return value out of the xxx_reply_t API message,
3233 * stick it into vam->retval, and set vam->result_ready
3235 * Could also do this by pointing N message decode slots at
3236 * a single function, but that could break in subtle ways.
3239 #define foreach_standard_reply_retval_handler \
3240 _(sw_interface_set_flags_reply) \
3241 _(sw_interface_add_del_address_reply) \
3242 _(sw_interface_set_rx_mode_reply) \
3243 _(sw_interface_set_rx_placement_reply) \
3244 _(sw_interface_set_table_reply) \
3245 _(sw_interface_set_mpls_enable_reply) \
3246 _(sw_interface_set_vpath_reply) \
3247 _(sw_interface_set_vxlan_bypass_reply) \
3248 _(sw_interface_set_vxlan_gpe_bypass_reply) \
3249 _(sw_interface_set_l2_bridge_reply) \
3250 _(sw_interface_set_bond_weight_reply) \
3251 _(bridge_domain_add_del_reply) \
3252 _(sw_interface_set_l2_xconnect_reply) \
3253 _(l2fib_add_del_reply) \
3254 _(l2fib_flush_int_reply) \
3255 _(l2fib_flush_bd_reply) \
3256 _(ip_route_add_del_reply) \
3257 _(ip_table_add_del_reply) \
3258 _(ip_table_replace_begin_reply) \
3259 _(ip_table_flush_reply) \
3260 _(ip_table_replace_end_reply) \
3261 _(ip_mroute_add_del_reply) \
3262 _(mpls_route_add_del_reply) \
3263 _(mpls_table_add_del_reply) \
3264 _(mpls_ip_bind_unbind_reply) \
3265 _(bier_route_add_del_reply) \
3266 _(bier_table_add_del_reply) \
3267 _(sw_interface_set_unnumbered_reply) \
3268 _(set_ip_flow_hash_reply) \
3269 _(sw_interface_ip6_enable_disable_reply) \
3270 _(l2_patch_add_del_reply) \
3271 _(sr_mpls_policy_add_reply) \
3272 _(sr_mpls_policy_mod_reply) \
3273 _(sr_mpls_policy_del_reply) \
3274 _(sr_policy_add_reply) \
3275 _(sr_policy_mod_reply) \
3276 _(sr_policy_del_reply) \
3277 _(sr_localsid_add_del_reply) \
3278 _(sr_steering_add_del_reply) \
3279 _(classify_add_del_session_reply) \
3280 _(classify_set_interface_ip_table_reply) \
3281 _(classify_set_interface_l2_tables_reply) \
3282 _(l2_fib_clear_table_reply) \
3283 _(l2_interface_efp_filter_reply) \
3284 _(l2_interface_vlan_tag_rewrite_reply) \
3285 _(modify_vhost_user_if_reply) \
3286 _(delete_vhost_user_if_reply) \
3287 _(want_l2_macs_events_reply) \
3288 _(input_acl_set_interface_reply) \
3289 _(ipsec_spd_add_del_reply) \
3290 _(ipsec_interface_add_del_spd_reply) \
3291 _(ipsec_spd_entry_add_del_reply) \
3292 _(ipsec_sad_entry_add_del_reply) \
3293 _(ipsec_tunnel_if_add_del_reply) \
3294 _(ipsec_tunnel_if_set_sa_reply) \
3295 _(delete_loopback_reply) \
3296 _(bd_ip_mac_add_del_reply) \
3297 _(bd_ip_mac_flush_reply) \
3298 _(want_interface_events_reply) \
3299 _(cop_interface_enable_disable_reply) \
3300 _(cop_whitelist_enable_disable_reply) \
3301 _(sw_interface_clear_stats_reply) \
3302 _(ioam_enable_reply) \
3303 _(ioam_disable_reply) \
3304 _(af_packet_delete_reply) \
3305 _(policer_classify_set_interface_reply) \
3306 _(set_ipfix_exporter_reply) \
3307 _(set_ipfix_classify_stream_reply) \
3308 _(ipfix_classify_table_add_del_reply) \
3309 _(flow_classify_set_interface_reply) \
3310 _(sw_interface_span_enable_disable_reply) \
3311 _(pg_capture_reply) \
3312 _(pg_enable_disable_reply) \
3313 _(pg_interface_enable_disable_coalesce_reply) \
3314 _(ip_source_and_port_range_check_add_del_reply) \
3315 _(ip_source_and_port_range_check_interface_add_del_reply)\
3316 _(delete_subif_reply) \
3317 _(l2_interface_pbb_tag_rewrite_reply) \
3319 _(feature_enable_disable_reply) \
3320 _(feature_gso_enable_disable_reply) \
3321 _(sw_interface_tag_add_del_reply) \
3322 _(sw_interface_add_del_mac_address_reply) \
3323 _(hw_interface_set_mtu_reply) \
3324 _(p2p_ethernet_add_reply) \
3325 _(p2p_ethernet_del_reply) \
3326 _(tcp_configure_src_addresses_reply) \
3327 _(session_rule_add_del_reply) \
3328 _(ip_container_proxy_add_del_reply) \
3329 _(output_acl_set_interface_reply) \
3330 _(qos_record_enable_disable_reply) \
3334 static void vl_api_##n##_t_handler \
3335 (vl_api_##n##_t * mp) \
3337 vat_main_t * vam = &vat_main; \
3338 i32 retval = ntohl(mp->retval); \
3339 if (vam->async_mode) { \
3340 vam->async_errors += (retval < 0); \
3342 vam->retval = retval; \
3343 vam->result_ready = 1; \
3346 foreach_standard_reply_retval_handler;
3350 static void vl_api_##n##_t_handler_json \
3351 (vl_api_##n##_t * mp) \
3353 vat_main_t * vam = &vat_main; \
3354 vat_json_node_t node; \
3355 vat_json_init_object(&node); \
3356 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3357 vat_json_print(vam->ofp, &node); \
3358 vam->retval = ntohl(mp->retval); \
3359 vam->result_ready = 1; \
3361 foreach_standard_reply_retval_handler;
3365 * Table of message reply handlers, must include boilerplate handlers
3369 #define foreach_vpe_api_reply_msg \
3370 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3371 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
3372 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3373 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3374 _(CONTROL_PING_REPLY, control_ping_reply) \
3375 _(CLI_REPLY, cli_reply) \
3376 _(CLI_INBAND_REPLY, cli_inband_reply) \
3377 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3378 sw_interface_add_del_address_reply) \
3379 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
3380 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
3381 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
3382 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3383 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
3384 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3385 _(SW_INTERFACE_SET_VXLAN_BYPASS_REPLY, sw_interface_set_vxlan_bypass_reply) \
3386 _(SW_INTERFACE_SET_VXLAN_GPE_BYPASS_REPLY, sw_interface_set_vxlan_gpe_bypass_reply) \
3387 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3388 sw_interface_set_l2_xconnect_reply) \
3389 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3390 sw_interface_set_l2_bridge_reply) \
3391 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3392 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3393 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
3394 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3395 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
3396 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
3397 _(L2_FLAGS_REPLY, l2_flags_reply) \
3398 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3399 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
3400 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
3401 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
3402 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
3403 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
3404 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
3405 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
3406 _(BOND_CREATE_REPLY, bond_create_reply) \
3407 _(BOND_CREATE2_REPLY, bond_create2_reply) \
3408 _(BOND_DELETE_REPLY, bond_delete_reply) \
3409 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
3410 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
3411 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
3412 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
3413 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
3414 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
3415 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
3416 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
3417 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
3418 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
3419 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
3420 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
3421 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
3422 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
3423 _(BIER_ROUTE_ADD_DEL_REPLY, bier_route_add_del_reply) \
3424 _(BIER_TABLE_ADD_DEL_REPLY, bier_table_add_del_reply) \
3425 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
3426 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3427 sw_interface_set_unnumbered_reply) \
3428 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3429 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3430 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3431 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3432 sw_interface_ip6_enable_disable_reply) \
3433 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3434 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
3435 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
3436 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
3437 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
3438 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
3439 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
3440 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
3441 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
3442 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3443 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3444 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3445 classify_set_interface_ip_table_reply) \
3446 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3447 classify_set_interface_l2_tables_reply) \
3448 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3449 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3450 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3451 _(VXLAN_OFFLOAD_RX_REPLY, vxlan_offload_rx_reply) \
3452 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3453 _(GRE_TUNNEL_ADD_DEL_REPLY, gre_tunnel_add_del_reply) \
3454 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
3455 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3456 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3457 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3458 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3459 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3460 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3461 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3462 _(SHOW_VERSION_REPLY, show_version_reply) \
3463 _(SHOW_THREADS_REPLY, show_threads_reply) \
3464 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
3465 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3466 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3467 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3468 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3469 _(L2_MACS_EVENT, l2_macs_event) \
3470 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3471 _(IP_ADDRESS_DETAILS, ip_address_details) \
3472 _(IP_DETAILS, ip_details) \
3473 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3474 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3475 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3476 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3477 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3478 _(IPSEC_TUNNEL_IF_ADD_DEL_REPLY, ipsec_tunnel_if_add_del_reply) \
3479 _(IPSEC_TUNNEL_IF_SET_SA_REPLY, ipsec_tunnel_if_set_sa_reply) \
3480 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3481 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3482 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3483 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3484 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3485 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3486 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3487 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3488 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3489 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3490 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3491 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3492 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3493 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3494 _(AF_PACKET_DETAILS, af_packet_details) \
3495 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3496 _(POLICER_DETAILS, policer_details) \
3497 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3498 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3499 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3500 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3501 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3502 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3503 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3504 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3505 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3506 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3507 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3508 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3509 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3510 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3511 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3512 _(FLOW_CLASSIFY_SET_INTERFACE_REPLY, flow_classify_set_interface_reply) \
3513 _(FLOW_CLASSIFY_DETAILS, flow_classify_details) \
3514 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3515 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3516 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3517 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3518 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3519 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3520 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3521 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3522 ip_source_and_port_range_check_add_del_reply) \
3523 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3524 ip_source_and_port_range_check_interface_add_del_reply) \
3525 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3526 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3527 _(SET_PUNT_REPLY, set_punt_reply) \
3528 _(IP_TABLE_DETAILS, ip_table_details) \
3529 _(IP_ROUTE_DETAILS, ip_route_details) \
3530 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3531 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3532 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3533 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3534 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3535 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3536 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3537 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3538 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3539 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3540 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3541 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3542 _(SESSION_RULES_DETAILS, session_rules_details) \
3543 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3544 _(OUTPUT_ACL_SET_INTERFACE_REPLY, output_acl_set_interface_reply) \
3545 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3546 _(FLOW_ADD_REPLY, flow_add_reply) \
3548 #define foreach_standalone_reply_msg \
3549 _(SW_INTERFACE_EVENT, sw_interface_event)
3557 #define STR_VTR_OP_CASE(op) \
3558 case L2_VTR_ ## op: \
3562 str_vtr_op (u32 vtr_op)
3566 STR_VTR_OP_CASE (DISABLED);
3567 STR_VTR_OP_CASE (PUSH_1);
3568 STR_VTR_OP_CASE (PUSH_2);
3569 STR_VTR_OP_CASE (POP_1);
3570 STR_VTR_OP_CASE (POP_2);
3571 STR_VTR_OP_CASE (TRANSLATE_1_1);
3572 STR_VTR_OP_CASE (TRANSLATE_1_2);
3573 STR_VTR_OP_CASE (TRANSLATE_2_1);
3574 STR_VTR_OP_CASE (TRANSLATE_2_2);
3581 dump_sub_interface_table (vat_main_t * vam)
3583 const sw_interface_subif_t *sub = NULL;
3585 if (vam->json_output)
3588 ("JSON output supported only for VPE API calls and dump_stats_table");
3593 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3594 "Interface", "sw_if_index",
3595 "sub id", "dot1ad", "tags", "outer id",
3596 "inner id", "exact", "default", "outer any", "inner any");
3598 vec_foreach (sub, vam->sw_if_subif_table)
3601 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3602 sub->interface_name,
3604 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3605 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3606 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3607 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3608 if (sub->vtr_op != L2_VTR_DISABLED)
3611 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3612 "tag1: %d tag2: %d ]",
3613 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3614 sub->vtr_tag1, sub->vtr_tag2);
3622 name_sort_cmp (void *a1, void *a2)
3624 name_sort_t *n1 = a1;
3625 name_sort_t *n2 = a2;
3627 return strcmp ((char *) n1->name, (char *) n2->name);
3631 dump_interface_table (vat_main_t * vam)
3634 name_sort_t *nses = 0, *ns;
3636 if (vam->json_output)
3639 ("JSON output supported only for VPE API calls and dump_stats_table");
3644 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3646 vec_add2 (nses, ns, 1);
3647 ns->name = (u8 *)(p->key);
3648 ns->value = (u32) p->value[0];
3652 vec_sort_with_function (nses, name_sort_cmp);
3654 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3655 vec_foreach (ns, nses)
3657 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3664 dump_ip_table (vat_main_t * vam, int is_ipv6)
3666 const ip_details_t *det = NULL;
3667 const ip_address_details_t *address = NULL;
3670 print (vam->ofp, "%-12s", "sw_if_index");
3672 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3679 print (vam->ofp, "%-12d", i);
3680 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3685 vec_foreach (address, det->addr)
3689 is_ipv6 ? format_ip6_address : format_ip4_address,
3690 address->ip, address->prefix_length);
3698 dump_ipv4_table (vat_main_t * vam)
3700 if (vam->json_output)
3703 ("JSON output supported only for VPE API calls and dump_stats_table");
3707 return dump_ip_table (vam, 0);
3711 dump_ipv6_table (vat_main_t * vam)
3713 if (vam->json_output)
3716 ("JSON output supported only for VPE API calls and dump_stats_table");
3720 return dump_ip_table (vam, 1);
3724 * Pass CLI buffers directly in the CLI_INBAND API message,
3725 * instead of an additional shared memory area.
3728 exec_inband (vat_main_t * vam)
3730 vl_api_cli_inband_t *mp;
3731 unformat_input_t *i = vam->input;
3734 if (vec_len (i->buffer) == 0)
3737 if (vam->exec_mode == 0 && unformat (i, "mode"))
3742 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3749 * In order for the CLI command to work, it
3750 * must be a vector ending in \n, not a C-string ending
3753 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3754 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3758 /* json responses may or may not include a useful reply... */
3759 if (vec_len (vam->cmd_reply))
3760 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3765 exec (vat_main_t * vam)
3767 return exec_inband (vam);
3771 api_create_loopback (vat_main_t * vam)
3773 unformat_input_t *i = vam->input;
3774 vl_api_create_loopback_t *mp;
3775 vl_api_create_loopback_instance_t *mp_lbi;
3778 u8 is_specified = 0;
3779 u32 user_instance = 0;
3782 clib_memset (mac_address, 0, sizeof (mac_address));
3784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3786 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3788 if (unformat (i, "instance %d", &user_instance))
3796 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3797 mp_lbi->is_specified = is_specified;
3799 mp_lbi->user_instance = htonl (user_instance);
3801 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3806 /* Construct the API message */
3807 M (CREATE_LOOPBACK, mp);
3809 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3818 api_delete_loopback (vat_main_t * vam)
3820 unformat_input_t *i = vam->input;
3821 vl_api_delete_loopback_t *mp;
3822 u32 sw_if_index = ~0;
3825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3827 if (unformat (i, "sw_if_index %d", &sw_if_index))
3833 if (sw_if_index == ~0)
3835 errmsg ("missing sw_if_index");
3839 /* Construct the API message */
3840 M (DELETE_LOOPBACK, mp);
3841 mp->sw_if_index = ntohl (sw_if_index);
3849 api_want_interface_events (vat_main_t * vam)
3851 unformat_input_t *i = vam->input;
3852 vl_api_want_interface_events_t *mp;
3856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3858 if (unformat (i, "enable"))
3860 else if (unformat (i, "disable"))
3868 errmsg ("missing enable|disable");
3872 M (WANT_INTERFACE_EVENTS, mp);
3873 mp->enable_disable = enable;
3875 vam->interface_event_display = enable;
3883 /* Note: non-static, called once to set up the initial intfc table */
3885 api_sw_interface_dump (vat_main_t * vam)
3887 vl_api_sw_interface_dump_t *mp;
3888 vl_api_control_ping_t *mp_ping;
3890 name_sort_t *nses = 0, *ns;
3891 sw_interface_subif_t *sub = NULL;
3894 /* Toss the old name table */
3896 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3898 vec_add2 (nses, ns, 1);
3899 ns->name = (u8 *)(p->key);
3900 ns->value = (u32) p->value[0];
3904 hash_free (vam->sw_if_index_by_interface_name);
3906 vec_foreach (ns, nses) vec_free (ns->name);
3910 vec_foreach (sub, vam->sw_if_subif_table)
3912 vec_free (sub->interface_name);
3914 vec_free (vam->sw_if_subif_table);
3916 /* recreate the interface name hash table */
3917 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3920 * Ask for all interface names. Otherwise, the epic catalog of
3921 * name filters becomes ridiculously long, and vat ends up needing
3922 * to be taught about new interface types.
3924 M (SW_INTERFACE_DUMP, mp);
3927 /* Use a control ping for synchronization */
3928 MPING (CONTROL_PING, mp_ping);
3936 api_sw_interface_set_flags (vat_main_t * vam)
3938 unformat_input_t *i = vam->input;
3939 vl_api_sw_interface_set_flags_t *mp;
3941 u8 sw_if_index_set = 0;
3945 /* Parse args required to build the message */
3946 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3948 if (unformat (i, "admin-up"))
3950 else if (unformat (i, "admin-down"))
3953 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3954 sw_if_index_set = 1;
3955 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3956 sw_if_index_set = 1;
3961 if (sw_if_index_set == 0)
3963 errmsg ("missing interface name or sw_if_index");
3967 /* Construct the API message */
3968 M (SW_INTERFACE_SET_FLAGS, mp);
3969 mp->sw_if_index = ntohl (sw_if_index);
3970 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3975 /* Wait for a reply, return the good/bad news... */
3981 api_sw_interface_set_rx_mode (vat_main_t * vam)
3983 unformat_input_t *i = vam->input;
3984 vl_api_sw_interface_set_rx_mode_t *mp;
3986 u8 sw_if_index_set = 0;
3988 u8 queue_id_valid = 0;
3990 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3992 /* Parse args required to build the message */
3993 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3995 if (unformat (i, "queue %d", &queue_id))
3997 else if (unformat (i, "polling"))
3998 mode = VNET_HW_IF_RX_MODE_POLLING;
3999 else if (unformat (i, "interrupt"))
4000 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
4001 else if (unformat (i, "adaptive"))
4002 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
4004 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4005 sw_if_index_set = 1;
4006 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4007 sw_if_index_set = 1;
4012 if (sw_if_index_set == 0)
4014 errmsg ("missing interface name or sw_if_index");
4017 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
4019 errmsg ("missing rx-mode");
4023 /* Construct the API message */
4024 M (SW_INTERFACE_SET_RX_MODE, mp);
4025 mp->sw_if_index = ntohl (sw_if_index);
4026 mp->mode = (vl_api_rx_mode_t) mode;
4027 mp->queue_id_valid = queue_id_valid;
4028 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
4033 /* Wait for a reply, return the good/bad news... */
4039 api_sw_interface_set_rx_placement (vat_main_t * vam)
4041 unformat_input_t *i = vam->input;
4042 vl_api_sw_interface_set_rx_placement_t *mp;
4044 u8 sw_if_index_set = 0;
4047 u32 queue_id, thread_index;
4049 /* Parse args required to build the message */
4050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4052 if (unformat (i, "queue %d", &queue_id))
4054 else if (unformat (i, "main"))
4056 else if (unformat (i, "worker %d", &thread_index))
4059 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4060 sw_if_index_set = 1;
4061 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4062 sw_if_index_set = 1;
4067 if (sw_if_index_set == 0)
4069 errmsg ("missing interface name or sw_if_index");
4075 /* Construct the API message */
4076 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
4077 mp->sw_if_index = ntohl (sw_if_index);
4078 mp->worker_id = ntohl (thread_index);
4079 mp->queue_id = ntohl (queue_id);
4080 mp->is_main = is_main;
4084 /* Wait for a reply, return the good/bad news... */
4089 static void vl_api_sw_interface_rx_placement_details_t_handler
4090 (vl_api_sw_interface_rx_placement_details_t * mp)
4092 vat_main_t *vam = &vat_main;
4093 u32 worker_id = ntohl (mp->worker_id);
4096 "\n%-11d %-11s %-6d %-5d %-9s",
4097 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
4098 worker_id, ntohl (mp->queue_id),
4100 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
4103 static void vl_api_sw_interface_rx_placement_details_t_handler_json
4104 (vl_api_sw_interface_rx_placement_details_t * mp)
4106 vat_main_t *vam = &vat_main;
4107 vat_json_node_t *node = NULL;
4109 if (VAT_JSON_ARRAY != vam->json_tree.type)
4111 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4112 vat_json_init_array (&vam->json_tree);
4114 node = vat_json_array_add (&vam->json_tree);
4116 vat_json_init_object (node);
4117 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
4118 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
4119 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
4120 vat_json_object_add_uint (node, "mode", mp->mode);
4124 api_sw_interface_rx_placement_dump (vat_main_t * vam)
4126 unformat_input_t *i = vam->input;
4127 vl_api_sw_interface_rx_placement_dump_t *mp;
4128 vl_api_control_ping_t *mp_ping;
4131 u8 sw_if_index_set = 0;
4133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4135 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4137 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4144 "\n%-11s %-11s %-6s %-5s %-4s",
4145 "sw_if_index", "main/worker", "thread", "queue", "mode");
4147 /* Dump Interface rx placement */
4148 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
4150 if (sw_if_index_set)
4151 mp->sw_if_index = htonl (sw_if_index);
4153 mp->sw_if_index = ~0;
4157 /* Use a control ping for synchronization */
4158 MPING (CONTROL_PING, mp_ping);
4166 api_sw_interface_clear_stats (vat_main_t * vam)
4168 unformat_input_t *i = vam->input;
4169 vl_api_sw_interface_clear_stats_t *mp;
4171 u8 sw_if_index_set = 0;
4174 /* Parse args required to build the message */
4175 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4177 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4178 sw_if_index_set = 1;
4179 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4180 sw_if_index_set = 1;
4185 /* Construct the API message */
4186 M (SW_INTERFACE_CLEAR_STATS, mp);
4188 if (sw_if_index_set == 1)
4189 mp->sw_if_index = ntohl (sw_if_index);
4191 mp->sw_if_index = ~0;
4196 /* Wait for a reply, return the good/bad news... */
4202 api_sw_interface_add_del_address (vat_main_t * vam)
4204 unformat_input_t *i = vam->input;
4205 vl_api_sw_interface_add_del_address_t *mp;
4207 u8 sw_if_index_set = 0;
4208 u8 is_add = 1, del_all = 0;
4209 u32 address_length = 0;
4210 u8 v4_address_set = 0;
4211 u8 v6_address_set = 0;
4212 ip4_address_t v4address;
4213 ip6_address_t v6address;
4216 /* Parse args required to build the message */
4217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4219 if (unformat (i, "del-all"))
4221 else if (unformat (i, "del"))
4224 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4225 sw_if_index_set = 1;
4226 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4227 sw_if_index_set = 1;
4228 else if (unformat (i, "%U/%d",
4229 unformat_ip4_address, &v4address, &address_length))
4231 else if (unformat (i, "%U/%d",
4232 unformat_ip6_address, &v6address, &address_length))
4238 if (sw_if_index_set == 0)
4240 errmsg ("missing interface name or sw_if_index");
4243 if (v4_address_set && v6_address_set)
4245 errmsg ("both v4 and v6 addresses set");
4248 if (!v4_address_set && !v6_address_set && !del_all)
4250 errmsg ("no addresses set");
4254 /* Construct the API message */
4255 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
4257 mp->sw_if_index = ntohl (sw_if_index);
4258 mp->is_add = is_add;
4259 mp->del_all = del_all;
4262 mp->prefix.address.af = ADDRESS_IP6;
4263 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
4267 mp->prefix.address.af = ADDRESS_IP4;
4268 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
4270 mp->prefix.len = address_length;
4275 /* Wait for a reply, return good/bad news */
4281 api_sw_interface_set_mpls_enable (vat_main_t * vam)
4283 unformat_input_t *i = vam->input;
4284 vl_api_sw_interface_set_mpls_enable_t *mp;
4286 u8 sw_if_index_set = 0;
4290 /* Parse args required to build the message */
4291 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4293 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4294 sw_if_index_set = 1;
4295 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4296 sw_if_index_set = 1;
4297 else if (unformat (i, "disable"))
4299 else if (unformat (i, "dis"))
4305 if (sw_if_index_set == 0)
4307 errmsg ("missing interface name or sw_if_index");
4311 /* Construct the API message */
4312 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
4314 mp->sw_if_index = ntohl (sw_if_index);
4315 mp->enable = enable;
4320 /* Wait for a reply... */
4326 api_sw_interface_set_table (vat_main_t * vam)
4328 unformat_input_t *i = vam->input;
4329 vl_api_sw_interface_set_table_t *mp;
4330 u32 sw_if_index, vrf_id = 0;
4331 u8 sw_if_index_set = 0;
4335 /* Parse args required to build the message */
4336 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4338 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4339 sw_if_index_set = 1;
4340 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4341 sw_if_index_set = 1;
4342 else if (unformat (i, "vrf %d", &vrf_id))
4344 else if (unformat (i, "ipv6"))
4350 if (sw_if_index_set == 0)
4352 errmsg ("missing interface name or sw_if_index");
4356 /* Construct the API message */
4357 M (SW_INTERFACE_SET_TABLE, mp);
4359 mp->sw_if_index = ntohl (sw_if_index);
4360 mp->is_ipv6 = is_ipv6;
4361 mp->vrf_id = ntohl (vrf_id);
4366 /* Wait for a reply... */
4371 static void vl_api_sw_interface_get_table_reply_t_handler
4372 (vl_api_sw_interface_get_table_reply_t * mp)
4374 vat_main_t *vam = &vat_main;
4376 print (vam->ofp, "%d", ntohl (mp->vrf_id));
4378 vam->retval = ntohl (mp->retval);
4379 vam->result_ready = 1;
4383 static void vl_api_sw_interface_get_table_reply_t_handler_json
4384 (vl_api_sw_interface_get_table_reply_t * mp)
4386 vat_main_t *vam = &vat_main;
4387 vat_json_node_t node;
4389 vat_json_init_object (&node);
4390 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4391 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
4393 vat_json_print (vam->ofp, &node);
4394 vat_json_free (&node);
4396 vam->retval = ntohl (mp->retval);
4397 vam->result_ready = 1;
4401 api_sw_interface_get_table (vat_main_t * vam)
4403 unformat_input_t *i = vam->input;
4404 vl_api_sw_interface_get_table_t *mp;
4406 u8 sw_if_index_set = 0;
4410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4412 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4413 sw_if_index_set = 1;
4414 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4415 sw_if_index_set = 1;
4416 else if (unformat (i, "ipv6"))
4422 if (sw_if_index_set == 0)
4424 errmsg ("missing interface name or sw_if_index");
4428 M (SW_INTERFACE_GET_TABLE, mp);
4429 mp->sw_if_index = htonl (sw_if_index);
4430 mp->is_ipv6 = is_ipv6;
4438 api_sw_interface_set_vpath (vat_main_t * vam)
4440 unformat_input_t *i = vam->input;
4441 vl_api_sw_interface_set_vpath_t *mp;
4442 u32 sw_if_index = 0;
4443 u8 sw_if_index_set = 0;
4447 /* Parse args required to build the message */
4448 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4450 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4451 sw_if_index_set = 1;
4452 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4453 sw_if_index_set = 1;
4454 else if (unformat (i, "enable"))
4456 else if (unformat (i, "disable"))
4462 if (sw_if_index_set == 0)
4464 errmsg ("missing interface name or sw_if_index");
4468 /* Construct the API message */
4469 M (SW_INTERFACE_SET_VPATH, mp);
4471 mp->sw_if_index = ntohl (sw_if_index);
4472 mp->enable = is_enable;
4477 /* Wait for a reply... */
4483 api_sw_interface_set_vxlan_bypass (vat_main_t * vam)
4485 unformat_input_t *i = vam->input;
4486 vl_api_sw_interface_set_vxlan_bypass_t *mp;
4487 u32 sw_if_index = 0;
4488 u8 sw_if_index_set = 0;
4493 /* Parse args required to build the message */
4494 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4496 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4497 sw_if_index_set = 1;
4498 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4499 sw_if_index_set = 1;
4500 else if (unformat (i, "enable"))
4502 else if (unformat (i, "disable"))
4504 else if (unformat (i, "ip4"))
4506 else if (unformat (i, "ip6"))
4512 if (sw_if_index_set == 0)
4514 errmsg ("missing interface name or sw_if_index");
4518 /* Construct the API message */
4519 M (SW_INTERFACE_SET_VXLAN_BYPASS, mp);
4521 mp->sw_if_index = ntohl (sw_if_index);
4522 mp->enable = is_enable;
4523 mp->is_ipv6 = is_ipv6;
4528 /* Wait for a reply... */
4534 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4536 unformat_input_t *i = vam->input;
4537 vl_api_sw_interface_set_l2_xconnect_t *mp;
4539 u8 rx_sw_if_index_set = 0;
4541 u8 tx_sw_if_index_set = 0;
4545 /* Parse args required to build the message */
4546 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4548 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4549 rx_sw_if_index_set = 1;
4550 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4551 tx_sw_if_index_set = 1;
4552 else if (unformat (i, "rx"))
4554 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4556 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4558 rx_sw_if_index_set = 1;
4563 else if (unformat (i, "tx"))
4565 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4567 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4569 tx_sw_if_index_set = 1;
4574 else if (unformat (i, "enable"))
4576 else if (unformat (i, "disable"))
4582 if (rx_sw_if_index_set == 0)
4584 errmsg ("missing rx interface name or rx_sw_if_index");
4588 if (enable && (tx_sw_if_index_set == 0))
4590 errmsg ("missing tx interface name or tx_sw_if_index");
4594 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4596 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4597 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4598 mp->enable = enable;
4606 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4608 unformat_input_t *i = vam->input;
4609 vl_api_sw_interface_set_l2_bridge_t *mp;
4610 vl_api_l2_port_type_t port_type;
4612 u8 rx_sw_if_index_set = 0;
4619 port_type = L2_API_PORT_TYPE_NORMAL;
4621 /* Parse args required to build the message */
4622 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4624 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4625 rx_sw_if_index_set = 1;
4626 else if (unformat (i, "bd_id %d", &bd_id))
4630 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4631 rx_sw_if_index_set = 1;
4632 else if (unformat (i, "shg %d", &shg))
4634 else if (unformat (i, "bvi"))
4635 port_type = L2_API_PORT_TYPE_BVI;
4636 else if (unformat (i, "uu-fwd"))
4637 port_type = L2_API_PORT_TYPE_UU_FWD;
4638 else if (unformat (i, "enable"))
4640 else if (unformat (i, "disable"))
4646 if (rx_sw_if_index_set == 0)
4648 errmsg ("missing rx interface name or sw_if_index");
4652 if (enable && (bd_id_set == 0))
4654 errmsg ("missing bridge domain");
4658 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4660 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4661 mp->bd_id = ntohl (bd_id);
4663 mp->port_type = ntohl (port_type);
4664 mp->enable = enable;
4672 api_bridge_domain_dump (vat_main_t * vam)
4674 unformat_input_t *i = vam->input;
4675 vl_api_bridge_domain_dump_t *mp;
4676 vl_api_control_ping_t *mp_ping;
4680 /* Parse args required to build the message */
4681 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4683 if (unformat (i, "bd_id %d", &bd_id))
4689 M (BRIDGE_DOMAIN_DUMP, mp);
4690 mp->bd_id = ntohl (bd_id);
4693 /* Use a control ping for synchronization */
4694 MPING (CONTROL_PING, mp_ping);
4702 api_bridge_domain_add_del (vat_main_t * vam)
4704 unformat_input_t *i = vam->input;
4705 vl_api_bridge_domain_add_del_t *mp;
4708 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4713 /* Parse args required to build the message */
4714 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4716 if (unformat (i, "bd_id %d", &bd_id))
4718 else if (unformat (i, "flood %d", &flood))
4720 else if (unformat (i, "uu-flood %d", &uu_flood))
4722 else if (unformat (i, "forward %d", &forward))
4724 else if (unformat (i, "learn %d", &learn))
4726 else if (unformat (i, "arp-term %d", &arp_term))
4728 else if (unformat (i, "mac-age %d", &mac_age))
4730 else if (unformat (i, "bd-tag %s", &bd_tag))
4732 else if (unformat (i, "del"))
4735 flood = uu_flood = forward = learn = 0;
4743 errmsg ("missing bridge domain");
4750 errmsg ("mac age must be less than 256 ");
4755 if ((bd_tag) && (vec_len (bd_tag) > 63))
4757 errmsg ("bd-tag cannot be longer than 63");
4762 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4764 mp->bd_id = ntohl (bd_id);
4766 mp->uu_flood = uu_flood;
4767 mp->forward = forward;
4769 mp->arp_term = arp_term;
4770 mp->is_add = is_add;
4771 mp->mac_age = (u8) mac_age;
4774 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4775 mp->bd_tag[vec_len (bd_tag)] = 0;
4786 api_l2fib_flush_bd (vat_main_t * vam)
4788 unformat_input_t *i = vam->input;
4789 vl_api_l2fib_flush_bd_t *mp;
4793 /* Parse args required to build the message */
4794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4796 if (unformat (i, "bd_id %d", &bd_id));
4803 errmsg ("missing bridge domain");
4807 M (L2FIB_FLUSH_BD, mp);
4809 mp->bd_id = htonl (bd_id);
4817 api_l2fib_flush_int (vat_main_t * vam)
4819 unformat_input_t *i = vam->input;
4820 vl_api_l2fib_flush_int_t *mp;
4821 u32 sw_if_index = ~0;
4824 /* Parse args required to build the message */
4825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4827 if (unformat (i, "sw_if_index %d", &sw_if_index));
4829 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4834 if (sw_if_index == ~0)
4836 errmsg ("missing interface name or sw_if_index");
4840 M (L2FIB_FLUSH_INT, mp);
4842 mp->sw_if_index = ntohl (sw_if_index);
4850 api_l2fib_add_del (vat_main_t * vam)
4852 unformat_input_t *i = vam->input;
4853 vl_api_l2fib_add_del_t *mp;
4859 u32 sw_if_index = 0;
4860 u8 sw_if_index_set = 0;
4869 /* Parse args required to build the message */
4870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4872 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4874 else if (unformat (i, "bd_id %d", &bd_id))
4876 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4877 sw_if_index_set = 1;
4878 else if (unformat (i, "sw_if"))
4880 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4883 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4884 sw_if_index_set = 1;
4889 else if (unformat (i, "static"))
4891 else if (unformat (i, "filter"))
4896 else if (unformat (i, "bvi"))
4901 else if (unformat (i, "del"))
4903 else if (unformat (i, "count %d", &count))
4911 errmsg ("missing mac address");
4917 errmsg ("missing bridge domain");
4921 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4923 errmsg ("missing interface name or sw_if_index");
4929 /* Turn on async mode */
4930 vam->async_mode = 1;
4931 vam->async_errors = 0;
4932 before = vat_time_now (vam);
4935 for (j = 0; j < count; j++)
4937 M (L2FIB_ADD_DEL, mp);
4939 clib_memcpy (mp->mac, mac, 6);
4940 mp->bd_id = ntohl (bd_id);
4941 mp->is_add = is_add;
4942 mp->sw_if_index = ntohl (sw_if_index);
4946 mp->static_mac = static_mac;
4947 mp->filter_mac = filter_mac;
4948 mp->bvi_mac = bvi_mac;
4950 increment_mac_address (mac);
4957 vl_api_control_ping_t *mp_ping;
4960 /* Shut off async mode */
4961 vam->async_mode = 0;
4963 MPING (CONTROL_PING, mp_ping);
4966 timeout = vat_time_now (vam) + 1.0;
4967 while (vat_time_now (vam) < timeout)
4968 if (vam->result_ready == 1)
4973 if (vam->retval == -99)
4976 if (vam->async_errors > 0)
4978 errmsg ("%d asynchronous errors", vam->async_errors);
4981 vam->async_errors = 0;
4982 after = vat_time_now (vam);
4984 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4985 count, after - before, count / (after - before));
4991 /* Wait for a reply... */
4995 /* Return the good/bad news */
4996 return (vam->retval);
5000 api_bridge_domain_set_mac_age (vat_main_t * vam)
5002 unformat_input_t *i = vam->input;
5003 vl_api_bridge_domain_set_mac_age_t *mp;
5008 /* Parse args required to build the message */
5009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5011 if (unformat (i, "bd_id %d", &bd_id));
5012 else if (unformat (i, "mac-age %d", &mac_age));
5019 errmsg ("missing bridge domain");
5025 errmsg ("mac age must be less than 256 ");
5029 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
5031 mp->bd_id = htonl (bd_id);
5032 mp->mac_age = (u8) mac_age;
5040 api_l2_flags (vat_main_t * vam)
5042 unformat_input_t *i = vam->input;
5043 vl_api_l2_flags_t *mp;
5046 u8 sw_if_index_set = 0;
5050 /* Parse args required to build the message */
5051 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5053 if (unformat (i, "sw_if_index %d", &sw_if_index))
5054 sw_if_index_set = 1;
5055 else if (unformat (i, "sw_if"))
5057 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5060 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5061 sw_if_index_set = 1;
5066 else if (unformat (i, "learn"))
5068 else if (unformat (i, "forward"))
5070 else if (unformat (i, "flood"))
5072 else if (unformat (i, "uu-flood"))
5073 flags |= L2_UU_FLOOD;
5074 else if (unformat (i, "arp-term"))
5075 flags |= L2_ARP_TERM;
5076 else if (unformat (i, "off"))
5078 else if (unformat (i, "disable"))
5084 if (sw_if_index_set == 0)
5086 errmsg ("missing interface name or sw_if_index");
5092 mp->sw_if_index = ntohl (sw_if_index);
5093 mp->feature_bitmap = ntohl (flags);
5094 mp->is_set = is_set;
5102 api_bridge_flags (vat_main_t * vam)
5104 unformat_input_t *i = vam->input;
5105 vl_api_bridge_flags_t *mp;
5109 bd_flags_t flags = 0;
5112 /* Parse args required to build the message */
5113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5115 if (unformat (i, "bd_id %d", &bd_id))
5117 else if (unformat (i, "learn"))
5118 flags |= BRIDGE_API_FLAG_LEARN;
5119 else if (unformat (i, "forward"))
5120 flags |= BRIDGE_API_FLAG_FWD;
5121 else if (unformat (i, "flood"))
5122 flags |= BRIDGE_API_FLAG_FLOOD;
5123 else if (unformat (i, "uu-flood"))
5124 flags |= BRIDGE_API_FLAG_UU_FLOOD;
5125 else if (unformat (i, "arp-term"))
5126 flags |= BRIDGE_API_FLAG_ARP_TERM;
5127 else if (unformat (i, "off"))
5129 else if (unformat (i, "disable"))
5137 errmsg ("missing bridge domain");
5141 M (BRIDGE_FLAGS, mp);
5143 mp->bd_id = ntohl (bd_id);
5144 mp->flags = ntohl (flags);
5145 mp->is_set = is_set;
5153 api_bd_ip_mac_add_del (vat_main_t * vam)
5155 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
5156 vl_api_mac_address_t mac = { 0 };
5157 unformat_input_t *i = vam->input;
5158 vl_api_bd_ip_mac_add_del_t *mp;
5167 /* Parse args required to build the message */
5168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5170 if (unformat (i, "bd_id %d", &bd_id))
5174 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
5178 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
5182 else if (unformat (i, "del"))
5190 errmsg ("missing bridge domain");
5193 else if (ip_set == 0)
5195 errmsg ("missing IP address");
5198 else if (mac_set == 0)
5200 errmsg ("missing MAC address");
5204 M (BD_IP_MAC_ADD_DEL, mp);
5206 mp->entry.bd_id = ntohl (bd_id);
5207 mp->is_add = is_add;
5209 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
5210 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
5218 api_bd_ip_mac_flush (vat_main_t * vam)
5220 unformat_input_t *i = vam->input;
5221 vl_api_bd_ip_mac_flush_t *mp;
5226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5228 if (unformat (i, "bd_id %d", &bd_id))
5238 errmsg ("missing bridge domain");
5242 M (BD_IP_MAC_FLUSH, mp);
5244 mp->bd_id = ntohl (bd_id);
5251 static void vl_api_bd_ip_mac_details_t_handler
5252 (vl_api_bd_ip_mac_details_t * mp)
5254 vat_main_t *vam = &vat_main;
5258 ntohl (mp->entry.bd_id),
5259 format_vl_api_mac_address, mp->entry.mac,
5260 format_vl_api_address, &mp->entry.ip);
5263 static void vl_api_bd_ip_mac_details_t_handler_json
5264 (vl_api_bd_ip_mac_details_t * mp)
5266 vat_main_t *vam = &vat_main;
5267 vat_json_node_t *node = NULL;
5269 if (VAT_JSON_ARRAY != vam->json_tree.type)
5271 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
5272 vat_json_init_array (&vam->json_tree);
5274 node = vat_json_array_add (&vam->json_tree);
5276 vat_json_init_object (node);
5277 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
5278 vat_json_object_add_string_copy (node, "mac_address",
5279 format (0, "%U", format_vl_api_mac_address,
5283 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
5284 vat_json_object_add_string_copy (node, "ip_address", ip);
5289 api_bd_ip_mac_dump (vat_main_t * vam)
5291 unformat_input_t *i = vam->input;
5292 vl_api_bd_ip_mac_dump_t *mp;
5293 vl_api_control_ping_t *mp_ping;
5298 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5300 if (unformat (i, "bd_id %d", &bd_id))
5309 "\n%-5s %-7s %-20s %-30s",
5310 "bd_id", "is_ipv6", "mac_address", "ip_address");
5312 /* Dump Bridge Domain Ip to Mac entries */
5313 M (BD_IP_MAC_DUMP, mp);
5316 mp->bd_id = htonl (bd_id);
5322 /* Use a control ping for synchronization */
5323 MPING (CONTROL_PING, mp_ping);
5331 api_tap_create_v2 (vat_main_t * vam)
5333 unformat_input_t *i = vam->input;
5334 vl_api_tap_create_v2_t *mp;
5338 u32 num_rx_queues = 0;
5339 u8 *host_if_name = 0;
5340 u8 host_if_name_set = 0;
5343 u8 host_mac_addr[6];
5344 u8 host_mac_addr_set = 0;
5345 u8 *host_bridge = 0;
5346 u8 host_bridge_set = 0;
5347 u8 host_ip4_prefix_set = 0;
5348 u8 host_ip6_prefix_set = 0;
5349 ip4_address_t host_ip4_addr;
5350 ip4_address_t host_ip4_gw;
5351 u8 host_ip4_gw_set = 0;
5352 u32 host_ip4_prefix_len = 0;
5353 ip6_address_t host_ip6_addr;
5354 ip6_address_t host_ip6_gw;
5355 u8 host_ip6_gw_set = 0;
5356 u32 host_ip6_prefix_len = 0;
5357 u32 host_mtu_size = 0;
5358 u8 host_mtu_set = 0;
5361 u32 rx_ring_sz = 0, tx_ring_sz = 0;
5363 clib_memset (mac_address, 0, sizeof (mac_address));
5365 /* Parse args required to build the message */
5366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5368 if (unformat (i, "id %u", &id))
5372 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5374 else if (unformat (i, "host-if-name %s", &host_if_name))
5375 host_if_name_set = 1;
5376 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
5378 else if (unformat (i, "host-ns %s", &host_ns))
5380 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
5382 host_mac_addr_set = 1;
5383 else if (unformat (i, "host-bridge %s", &host_bridge))
5384 host_bridge_set = 1;
5385 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
5386 &host_ip4_addr, &host_ip4_prefix_len))
5387 host_ip4_prefix_set = 1;
5388 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
5389 &host_ip6_addr, &host_ip6_prefix_len))
5390 host_ip6_prefix_set = 1;
5391 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
5393 host_ip4_gw_set = 1;
5394 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
5396 host_ip6_gw_set = 1;
5397 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
5399 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
5401 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
5403 else if (unformat (i, "no-gso"))
5404 tap_flags &= ~TAP_API_FLAG_GSO;
5405 else if (unformat (i, "gso"))
5406 tap_flags |= TAP_API_FLAG_GSO;
5407 else if (unformat (i, "csum-offload"))
5408 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
5409 else if (unformat (i, "persist"))
5410 tap_flags |= TAP_API_FLAG_PERSIST;
5411 else if (unformat (i, "attach"))
5412 tap_flags |= TAP_API_FLAG_ATTACH;
5413 else if (unformat (i, "tun"))
5414 tap_flags |= TAP_API_FLAG_TUN;
5415 else if (unformat (i, "gro-coalesce"))
5416 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
5417 else if (unformat (i, "packed"))
5418 tap_flags |= TAP_API_FLAG_PACKED;
5419 else if (unformat (i, "in-order"))
5420 tap_flags |= TAP_API_FLAG_IN_ORDER;
5425 if (vec_len (host_if_name) > 63)
5427 errmsg ("tap name too long. ");
5430 if (vec_len (host_ns) > 63)
5432 errmsg ("host name space too long. ");
5435 if (vec_len (host_bridge) > 63)
5437 errmsg ("host bridge name too long. ");
5440 if (host_ip4_prefix_len > 32)
5442 errmsg ("host ip4 prefix length not valid. ");
5445 if (host_ip6_prefix_len > 128)
5447 errmsg ("host ip6 prefix length not valid. ");
5450 if (!is_pow2 (rx_ring_sz))
5452 errmsg ("rx ring size must be power of 2. ");
5455 if (rx_ring_sz > 32768)
5457 errmsg ("rx ring size must be 32768 or lower. ");
5460 if (!is_pow2 (tx_ring_sz))
5462 errmsg ("tx ring size must be power of 2. ");
5465 if (tx_ring_sz > 32768)
5467 errmsg ("tx ring size must be 32768 or lower. ");
5470 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
5472 errmsg ("host MTU size must be in between 64 and 65355. ");
5476 /* Construct the API message */
5477 M (TAP_CREATE_V2, mp);
5479 mp->id = ntohl (id);
5480 mp->use_random_mac = random_mac;
5481 mp->num_rx_queues = (u8) num_rx_queues;
5482 mp->tx_ring_sz = ntohs (tx_ring_sz);
5483 mp->rx_ring_sz = ntohs (rx_ring_sz);
5484 mp->host_mtu_set = host_mtu_set;
5485 mp->host_mtu_size = ntohl (host_mtu_size);
5486 mp->host_mac_addr_set = host_mac_addr_set;
5487 mp->host_ip4_prefix_set = host_ip4_prefix_set;
5488 mp->host_ip6_prefix_set = host_ip6_prefix_set;
5489 mp->host_ip4_gw_set = host_ip4_gw_set;
5490 mp->host_ip6_gw_set = host_ip6_gw_set;
5491 mp->tap_flags = ntohl (tap_flags);
5492 mp->host_namespace_set = host_ns_set;
5493 mp->host_if_name_set = host_if_name_set;
5494 mp->host_bridge_set = host_bridge_set;
5496 if (random_mac == 0)
5497 clib_memcpy (mp->mac_address, mac_address, 6);
5498 if (host_mac_addr_set)
5499 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
5500 if (host_if_name_set)
5501 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
5503 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
5504 if (host_bridge_set)
5505 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
5506 if (host_ip4_prefix_set)
5508 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
5509 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
5511 if (host_ip6_prefix_set)
5513 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
5514 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
5516 if (host_ip4_gw_set)
5517 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
5518 if (host_ip6_gw_set)
5519 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
5522 vec_free (host_if_name);
5523 vec_free (host_bridge);
5528 /* Wait for a reply... */
5534 api_tap_delete_v2 (vat_main_t * vam)
5536 unformat_input_t *i = vam->input;
5537 vl_api_tap_delete_v2_t *mp;
5538 u32 sw_if_index = ~0;
5539 u8 sw_if_index_set = 0;
5542 /* Parse args required to build the message */
5543 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5545 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5546 sw_if_index_set = 1;
5547 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5548 sw_if_index_set = 1;
5553 if (sw_if_index_set == 0)
5555 errmsg ("missing vpp interface name. ");
5559 /* Construct the API message */
5560 M (TAP_DELETE_V2, mp);
5562 mp->sw_if_index = ntohl (sw_if_index);
5567 /* Wait for a reply... */
5573 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5575 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5578 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5581 addr->domain = x[0];
5584 addr->function = x[3];
5590 api_virtio_pci_create_v2 (vat_main_t * vam)
5592 unformat_input_t *i = vam->input;
5593 vl_api_virtio_pci_create_v2_t *mp;
5597 u64 features = (u64) ~ (0ULL);
5598 u32 virtio_flags = 0;
5601 clib_memset (mac_address, 0, sizeof (mac_address));
5603 /* Parse args required to build the message */
5604 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5606 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5610 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5612 else if (unformat (i, "features 0x%llx", &features))
5614 else if (unformat (i, "gso-enabled"))
5615 virtio_flags |= VIRTIO_API_FLAG_GSO;
5616 else if (unformat (i, "csum-offload-enabled"))
5617 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5618 else if (unformat (i, "gro-coalesce"))
5619 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5620 else if (unformat (i, "packed"))
5621 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5622 else if (unformat (i, "in-order"))
5623 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5624 else if (unformat (i, "buffering"))
5625 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5632 errmsg ("pci address must be non zero. ");
5636 /* Construct the API message */
5637 M (VIRTIO_PCI_CREATE_V2, mp);
5639 mp->use_random_mac = random_mac;
5641 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5642 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5643 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5644 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5646 mp->features = clib_host_to_net_u64 (features);
5647 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5649 if (random_mac == 0)
5650 clib_memcpy (mp->mac_address, mac_address, 6);
5655 /* Wait for a reply... */
5661 api_virtio_pci_delete (vat_main_t * vam)
5663 unformat_input_t *i = vam->input;
5664 vl_api_virtio_pci_delete_t *mp;
5665 u32 sw_if_index = ~0;
5666 u8 sw_if_index_set = 0;
5669 /* Parse args required to build the message */
5670 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5672 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5673 sw_if_index_set = 1;
5674 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5675 sw_if_index_set = 1;
5680 if (sw_if_index_set == 0)
5682 errmsg ("missing vpp interface name. ");
5686 /* Construct the API message */
5687 M (VIRTIO_PCI_DELETE, mp);
5689 mp->sw_if_index = htonl (sw_if_index);
5694 /* Wait for a reply... */
5700 api_bond_create (vat_main_t * vam)
5702 unformat_input_t *i = vam->input;
5703 vl_api_bond_create_t *mp;
5713 clib_memset (mac_address, 0, sizeof (mac_address));
5716 /* Parse args required to build the message */
5717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5719 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5721 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5722 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5724 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5727 else if (unformat (i, "numa-only"))
5729 else if (unformat (i, "id %u", &id))
5735 if (mode_is_set == 0)
5737 errmsg ("Missing bond mode. ");
5741 /* Construct the API message */
5742 M (BOND_CREATE, mp);
5744 mp->use_custom_mac = custom_mac;
5746 mp->mode = htonl (mode);
5747 mp->lb = htonl (lb);
5748 mp->id = htonl (id);
5749 mp->numa_only = numa_only;
5752 clib_memcpy (mp->mac_address, mac_address, 6);
5757 /* Wait for a reply... */
5763 api_bond_create2 (vat_main_t * vam)
5765 unformat_input_t *i = vam->input;
5766 vl_api_bond_create2_t *mp;
5777 clib_memset (mac_address, 0, sizeof (mac_address));
5780 /* Parse args required to build the message */
5781 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5783 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5785 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5786 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5788 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5791 else if (unformat (i, "numa-only"))
5793 else if (unformat (i, "gso"))
5795 else if (unformat (i, "id %u", &id))
5801 if (mode_is_set == 0)
5803 errmsg ("Missing bond mode. ");
5807 /* Construct the API message */
5808 M (BOND_CREATE2, mp);
5810 mp->use_custom_mac = custom_mac;
5812 mp->mode = htonl (mode);
5813 mp->lb = htonl (lb);
5814 mp->id = htonl (id);
5815 mp->numa_only = numa_only;
5816 mp->enable_gso = gso;
5819 clib_memcpy (mp->mac_address, mac_address, 6);
5824 /* Wait for a reply... */
5830 api_bond_delete (vat_main_t * vam)
5832 unformat_input_t *i = vam->input;
5833 vl_api_bond_delete_t *mp;
5834 u32 sw_if_index = ~0;
5835 u8 sw_if_index_set = 0;
5838 /* Parse args required to build the message */
5839 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5841 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5842 sw_if_index_set = 1;
5843 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5844 sw_if_index_set = 1;
5849 if (sw_if_index_set == 0)
5851 errmsg ("missing vpp interface name. ");
5855 /* Construct the API message */
5856 M (BOND_DELETE, mp);
5858 mp->sw_if_index = ntohl (sw_if_index);
5863 /* Wait for a reply... */
5869 api_bond_add_member (vat_main_t * vam)
5871 unformat_input_t *i = vam->input;
5872 vl_api_bond_add_member_t *mp;
5873 u32 bond_sw_if_index;
5877 u32 bond_sw_if_index_is_set = 0;
5879 u8 sw_if_index_is_set = 0;
5881 /* Parse args required to build the message */
5882 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5884 if (unformat (i, "sw_if_index %d", &sw_if_index))
5885 sw_if_index_is_set = 1;
5886 else if (unformat (i, "bond %u", &bond_sw_if_index))
5887 bond_sw_if_index_is_set = 1;
5888 else if (unformat (i, "passive %d", &is_passive))
5890 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5896 if (bond_sw_if_index_is_set == 0)
5898 errmsg ("Missing bond sw_if_index. ");
5901 if (sw_if_index_is_set == 0)
5903 errmsg ("Missing member sw_if_index. ");
5907 /* Construct the API message */
5908 M (BOND_ADD_MEMBER, mp);
5910 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5911 mp->sw_if_index = ntohl (sw_if_index);
5912 mp->is_long_timeout = is_long_timeout;
5913 mp->is_passive = is_passive;
5918 /* Wait for a reply... */
5924 api_bond_detach_member (vat_main_t * vam)
5926 unformat_input_t *i = vam->input;
5927 vl_api_bond_detach_member_t *mp;
5928 u32 sw_if_index = ~0;
5929 u8 sw_if_index_set = 0;
5932 /* Parse args required to build the message */
5933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5935 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5936 sw_if_index_set = 1;
5937 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5938 sw_if_index_set = 1;
5943 if (sw_if_index_set == 0)
5945 errmsg ("missing vpp interface name. ");
5949 /* Construct the API message */
5950 M (BOND_DETACH_MEMBER, mp);
5952 mp->sw_if_index = ntohl (sw_if_index);
5957 /* Wait for a reply... */
5963 api_ip_table_add_del (vat_main_t * vam)
5965 unformat_input_t *i = vam->input;
5966 vl_api_ip_table_add_del_t *mp;
5972 /* Parse args required to build the message */
5973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5975 if (unformat (i, "ipv6"))
5977 else if (unformat (i, "del"))
5979 else if (unformat (i, "add"))
5981 else if (unformat (i, "table %d", &table_id))
5985 clib_warning ("parse error '%U'", format_unformat_error, i);
5992 errmsg ("missing table-ID");
5996 /* Construct the API message */
5997 M (IP_TABLE_ADD_DEL, mp);
5999 mp->table.table_id = ntohl (table_id);
6000 mp->table.is_ip6 = is_ipv6;
6001 mp->is_add = is_add;
6006 /* Wait for a reply... */
6013 unformat_fib_path (unformat_input_t * input, va_list * args)
6015 vat_main_t *vam = va_arg (*args, vat_main_t *);
6016 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
6017 u32 weight, preference;
6018 mpls_label_t out_label;
6020 clib_memset (path, 0, sizeof (*path));
6022 path->sw_if_index = ~0;
6026 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6028 if (unformat (input, "%U %U",
6029 unformat_vl_api_ip4_address,
6030 &path->nh.address.ip4,
6031 api_unformat_sw_if_index, vam, &path->sw_if_index))
6033 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6035 else if (unformat (input, "%U %U",
6036 unformat_vl_api_ip6_address,
6037 &path->nh.address.ip6,
6038 api_unformat_sw_if_index, vam, &path->sw_if_index))
6040 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6042 else if (unformat (input, "weight %u", &weight))
6044 path->weight = weight;
6046 else if (unformat (input, "preference %u", &preference))
6048 path->preference = preference;
6050 else if (unformat (input, "%U next-hop-table %d",
6051 unformat_vl_api_ip4_address,
6052 &path->nh.address.ip4, &path->table_id))
6054 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6056 else if (unformat (input, "%U next-hop-table %d",
6057 unformat_vl_api_ip6_address,
6058 &path->nh.address.ip6, &path->table_id))
6060 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6062 else if (unformat (input, "%U",
6063 unformat_vl_api_ip4_address, &path->nh.address.ip4))
6066 * the recursive next-hops are by default in the default table
6069 path->sw_if_index = ~0;
6070 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6072 else if (unformat (input, "%U",
6073 unformat_vl_api_ip6_address, &path->nh.address.ip6))
6076 * the recursive next-hops are by default in the default table
6079 path->sw_if_index = ~0;
6080 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6082 else if (unformat (input, "resolve-via-host"))
6084 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
6086 else if (unformat (input, "resolve-via-attached"))
6088 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
6090 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
6092 path->type = FIB_API_PATH_TYPE_LOCAL;
6093 path->sw_if_index = ~0;
6094 path->proto = FIB_API_PATH_NH_PROTO_IP4;
6096 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
6098 path->type = FIB_API_PATH_TYPE_LOCAL;
6099 path->sw_if_index = ~0;
6100 path->proto = FIB_API_PATH_NH_PROTO_IP6;
6102 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
6104 else if (unformat (input, "via-label %d", &path->nh.via_label))
6106 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
6107 path->sw_if_index = ~0;
6109 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
6111 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
6112 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
6114 else if (unformat (input, "local"))
6116 path->type = FIB_API_PATH_TYPE_LOCAL;
6118 else if (unformat (input, "out-labels"))
6120 while (unformat (input, "%d", &out_label))
6122 path->label_stack[path->n_labels].label = out_label;
6123 path->label_stack[path->n_labels].is_uniform = 0;
6124 path->label_stack[path->n_labels].ttl = 64;
6128 else if (unformat (input, "via"))
6130 /* new path, back up and return */
6131 unformat_put_input (input);
6132 unformat_put_input (input);
6133 unformat_put_input (input);
6134 unformat_put_input (input);
6143 path->proto = ntohl (path->proto);
6144 path->type = ntohl (path->type);
6145 path->flags = ntohl (path->flags);
6146 path->table_id = ntohl (path->table_id);
6147 path->sw_if_index = ntohl (path->sw_if_index);
6153 api_ip_route_add_del (vat_main_t * vam)
6155 unformat_input_t *i = vam->input;
6156 vl_api_ip_route_add_del_t *mp;
6159 u8 is_multipath = 0;
6162 vl_api_prefix_t pfx = { };
6163 vl_api_fib_path_t paths[8];
6167 u32 random_add_del = 0;
6168 u32 *random_vector = 0;
6169 u32 random_seed = 0xdeaddabe;
6171 /* Parse args required to build the message */
6172 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6174 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6176 else if (unformat (i, "del"))
6178 else if (unformat (i, "add"))
6180 else if (unformat (i, "vrf %d", &vrf_id))
6182 else if (unformat (i, "count %d", &count))
6184 else if (unformat (i, "random"))
6186 else if (unformat (i, "multipath"))
6188 else if (unformat (i, "seed %d", &random_seed))
6192 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6195 if (8 == path_count)
6197 errmsg ("max 8 paths");
6203 clib_warning ("parse error '%U'", format_unformat_error, i);
6210 errmsg ("specify a path; via ...");
6213 if (prefix_set == 0)
6215 errmsg ("missing prefix");
6219 /* Generate a pile of unique, random routes */
6222 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
6223 u32 this_random_address;
6226 random_hash = hash_create (count, sizeof (uword));
6228 hash_set (random_hash, i->as_u32, 1);
6229 for (j = 0; j <= count; j++)
6233 this_random_address = random_u32 (&random_seed);
6234 this_random_address =
6235 clib_host_to_net_u32 (this_random_address);
6237 while (hash_get (random_hash, this_random_address));
6238 vec_add1 (random_vector, this_random_address);
6239 hash_set (random_hash, this_random_address, 1);
6241 hash_free (random_hash);
6242 set_ip4_address (&pfx.address, random_vector[0]);
6247 /* Turn on async mode */
6248 vam->async_mode = 1;
6249 vam->async_errors = 0;
6250 before = vat_time_now (vam);
6253 for (j = 0; j < count; j++)
6255 /* Construct the API message */
6256 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6258 mp->is_add = is_add;
6259 mp->is_multipath = is_multipath;
6261 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6262 mp->route.table_id = ntohl (vrf_id);
6263 mp->route.n_paths = path_count;
6265 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
6268 set_ip4_address (&pfx.address, random_vector[j + 1]);
6270 increment_address (&pfx.address);
6273 /* If we receive SIGTERM, stop now... */
6278 /* When testing multiple add/del ops, use a control-ping to sync */
6281 vl_api_control_ping_t *mp_ping;
6285 /* Shut off async mode */
6286 vam->async_mode = 0;
6288 MPING (CONTROL_PING, mp_ping);
6291 timeout = vat_time_now (vam) + 1.0;
6292 while (vat_time_now (vam) < timeout)
6293 if (vam->result_ready == 1)
6298 if (vam->retval == -99)
6301 if (vam->async_errors > 0)
6303 errmsg ("%d asynchronous errors", vam->async_errors);
6306 vam->async_errors = 0;
6307 after = vat_time_now (vam);
6309 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6313 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6314 count, after - before, count / (after - before));
6320 /* Wait for a reply... */
6325 /* Return the good/bad news */
6326 return (vam->retval);
6330 api_ip_mroute_add_del (vat_main_t * vam)
6332 unformat_input_t *i = vam->input;
6333 u8 path_set = 0, prefix_set = 0, is_add = 1;
6334 vl_api_ip_mroute_add_del_t *mp;
6335 mfib_entry_flags_t eflags = 0;
6336 vl_api_mfib_path_t path;
6337 vl_api_mprefix_t pfx = { };
6341 /* Parse args required to build the message */
6342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6344 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
6347 pfx.grp_address_length = htons (pfx.grp_address_length);
6349 else if (unformat (i, "del"))
6351 else if (unformat (i, "add"))
6353 else if (unformat (i, "vrf %d", &vrf_id))
6355 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
6356 path.itf_flags = htonl (path.itf_flags);
6357 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
6359 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
6363 clib_warning ("parse error '%U'", format_unformat_error, i);
6368 if (prefix_set == 0)
6370 errmsg ("missing addresses\n");
6375 errmsg ("missing path\n");
6379 /* Construct the API message */
6380 M (IP_MROUTE_ADD_DEL, mp);
6382 mp->is_add = is_add;
6383 mp->is_multipath = 1;
6385 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
6386 mp->route.table_id = htonl (vrf_id);
6387 mp->route.n_paths = 1;
6388 mp->route.entry_flags = htonl (eflags);
6390 clib_memcpy (&mp->route.paths, &path, sizeof (path));
6394 /* Wait for a reply... */
6400 api_mpls_table_add_del (vat_main_t * vam)
6402 unformat_input_t *i = vam->input;
6403 vl_api_mpls_table_add_del_t *mp;
6408 /* Parse args required to build the message */
6409 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6411 if (unformat (i, "table %d", &table_id))
6413 else if (unformat (i, "del"))
6415 else if (unformat (i, "add"))
6419 clib_warning ("parse error '%U'", format_unformat_error, i);
6426 errmsg ("missing table-ID");
6430 /* Construct the API message */
6431 M (MPLS_TABLE_ADD_DEL, mp);
6433 mp->mt_table.mt_table_id = ntohl (table_id);
6434 mp->mt_is_add = is_add;
6439 /* Wait for a reply... */
6446 api_mpls_route_add_del (vat_main_t * vam)
6448 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
6449 mpls_label_t local_label = MPLS_LABEL_INVALID;
6450 unformat_input_t *i = vam->input;
6451 vl_api_mpls_route_add_del_t *mp;
6452 vl_api_fib_path_t paths[8];
6456 /* Parse args required to build the message */
6457 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6459 if (unformat (i, "%d", &local_label))
6461 else if (unformat (i, "eos"))
6463 else if (unformat (i, "non-eos"))
6465 else if (unformat (i, "del"))
6467 else if (unformat (i, "add"))
6469 else if (unformat (i, "multipath"))
6471 else if (unformat (i, "count %d", &count))
6475 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6478 if (8 == path_count)
6480 errmsg ("max 8 paths");
6486 clib_warning ("parse error '%U'", format_unformat_error, i);
6493 errmsg ("specify a path; via ...");
6497 if (MPLS_LABEL_INVALID == local_label)
6499 errmsg ("missing label");
6505 /* Turn on async mode */
6506 vam->async_mode = 1;
6507 vam->async_errors = 0;
6508 before = vat_time_now (vam);
6511 for (j = 0; j < count; j++)
6513 /* Construct the API message */
6514 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6516 mp->mr_is_add = is_add;
6517 mp->mr_is_multipath = is_multipath;
6519 mp->mr_route.mr_label = local_label;
6520 mp->mr_route.mr_eos = is_eos;
6521 mp->mr_route.mr_table_id = 0;
6522 mp->mr_route.mr_n_paths = path_count;
6524 clib_memcpy (&mp->mr_route.mr_paths, paths,
6525 sizeof (paths[0]) * path_count);
6531 /* If we receive SIGTERM, stop now... */
6536 /* When testing multiple add/del ops, use a control-ping to sync */
6539 vl_api_control_ping_t *mp_ping;
6543 /* Shut off async mode */
6544 vam->async_mode = 0;
6546 MPING (CONTROL_PING, mp_ping);
6549 timeout = vat_time_now (vam) + 1.0;
6550 while (vat_time_now (vam) < timeout)
6551 if (vam->result_ready == 1)
6556 if (vam->retval == -99)
6559 if (vam->async_errors > 0)
6561 errmsg ("%d asynchronous errors", vam->async_errors);
6564 vam->async_errors = 0;
6565 after = vat_time_now (vam);
6567 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6571 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6572 count, after - before, count / (after - before));
6578 /* Wait for a reply... */
6583 /* Return the good/bad news */
6584 return (vam->retval);
6589 api_mpls_ip_bind_unbind (vat_main_t * vam)
6591 unformat_input_t *i = vam->input;
6592 vl_api_mpls_ip_bind_unbind_t *mp;
6593 u32 ip_table_id = 0;
6595 vl_api_prefix_t pfx;
6597 mpls_label_t local_label = MPLS_LABEL_INVALID;
6600 /* Parse args required to build the message */
6601 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6603 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6605 else if (unformat (i, "%d", &local_label))
6607 else if (unformat (i, "table-id %d", &ip_table_id))
6609 else if (unformat (i, "unbind"))
6611 else if (unformat (i, "bind"))
6615 clib_warning ("parse error '%U'", format_unformat_error, i);
6622 errmsg ("IP prefix not set");
6626 if (MPLS_LABEL_INVALID == local_label)
6628 errmsg ("missing label");
6632 /* Construct the API message */
6633 M (MPLS_IP_BIND_UNBIND, mp);
6635 mp->mb_is_bind = is_bind;
6636 mp->mb_ip_table_id = ntohl (ip_table_id);
6637 mp->mb_mpls_table_id = 0;
6638 mp->mb_label = ntohl (local_label);
6639 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6644 /* Wait for a reply... */
6651 api_sr_mpls_policy_add (vat_main_t * vam)
6653 unformat_input_t *i = vam->input;
6654 vl_api_sr_mpls_policy_add_t *mp;
6660 u32 *segments = NULL;
6663 /* Parse args required to build the message */
6664 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6666 if (unformat (i, "bsid %d", &bsid))
6668 else if (unformat (i, "weight %d", &weight))
6670 else if (unformat (i, "spray"))
6672 else if (unformat (i, "next %d", &sid))
6675 vec_add1 (segments, htonl (sid));
6679 clib_warning ("parse error '%U'", format_unformat_error, i);
6686 errmsg ("bsid not set");
6690 if (n_segments == 0)
6692 errmsg ("no sid in segment stack");
6696 /* Construct the API message */
6697 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6699 mp->bsid = htonl (bsid);
6700 mp->weight = htonl (weight);
6701 mp->is_spray = type;
6702 mp->n_segments = n_segments;
6703 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6704 vec_free (segments);
6709 /* Wait for a reply... */
6715 api_sr_mpls_policy_del (vat_main_t * vam)
6717 unformat_input_t *i = vam->input;
6718 vl_api_sr_mpls_policy_del_t *mp;
6722 /* Parse args required to build the message */
6723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6725 if (unformat (i, "bsid %d", &bsid))
6729 clib_warning ("parse error '%U'", format_unformat_error, i);
6736 errmsg ("bsid not set");
6740 /* Construct the API message */
6741 M (SR_MPLS_POLICY_DEL, mp);
6743 mp->bsid = htonl (bsid);
6748 /* Wait for a reply... */
6754 api_bier_table_add_del (vat_main_t * vam)
6756 unformat_input_t *i = vam->input;
6757 vl_api_bier_table_add_del_t *mp;
6759 u32 set = 0, sub_domain = 0, hdr_len = 3;
6760 mpls_label_t local_label = MPLS_LABEL_INVALID;
6763 /* Parse args required to build the message */
6764 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6766 if (unformat (i, "sub-domain %d", &sub_domain))
6768 else if (unformat (i, "set %d", &set))
6770 else if (unformat (i, "label %d", &local_label))
6772 else if (unformat (i, "hdr-len %d", &hdr_len))
6774 else if (unformat (i, "add"))
6776 else if (unformat (i, "del"))
6780 clib_warning ("parse error '%U'", format_unformat_error, i);
6785 if (MPLS_LABEL_INVALID == local_label)
6787 errmsg ("missing label\n");
6791 /* Construct the API message */
6792 M (BIER_TABLE_ADD_DEL, mp);
6794 mp->bt_is_add = is_add;
6795 mp->bt_label = ntohl (local_label);
6796 mp->bt_tbl_id.bt_set = set;
6797 mp->bt_tbl_id.bt_sub_domain = sub_domain;
6798 mp->bt_tbl_id.bt_hdr_len_id = hdr_len;
6803 /* Wait for a reply... */
6810 api_bier_route_add_del (vat_main_t * vam)
6812 unformat_input_t *i = vam->input;
6813 vl_api_bier_route_add_del_t *mp;
6815 u32 set = 0, sub_domain = 0, hdr_len = 3, bp = 0;
6816 ip4_address_t v4_next_hop_address;
6817 ip6_address_t v6_next_hop_address;
6818 u8 next_hop_set = 0;
6819 u8 next_hop_proto_is_ip4 = 1;
6820 mpls_label_t next_hop_out_label = MPLS_LABEL_INVALID;
6823 /* Parse args required to build the message */
6824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6826 if (unformat (i, "%U", unformat_ip4_address, &v4_next_hop_address))
6828 next_hop_proto_is_ip4 = 1;
6831 else if (unformat (i, "%U", unformat_ip6_address, &v6_next_hop_address))
6833 next_hop_proto_is_ip4 = 0;
6836 if (unformat (i, "sub-domain %d", &sub_domain))
6838 else if (unformat (i, "set %d", &set))
6840 else if (unformat (i, "hdr-len %d", &hdr_len))
6842 else if (unformat (i, "bp %d", &bp))
6844 else if (unformat (i, "add"))
6846 else if (unformat (i, "del"))
6848 else if (unformat (i, "out-label %d", &next_hop_out_label))
6852 clib_warning ("parse error '%U'", format_unformat_error, i);
6857 if (!next_hop_set || (MPLS_LABEL_INVALID == next_hop_out_label))
6859 errmsg ("next hop / label set\n");
6864 errmsg ("bit=position not set\n");
6868 /* Construct the API message */
6869 M2 (BIER_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t));
6871 mp->br_is_add = is_add;
6872 mp->br_route.br_tbl_id.bt_set = set;
6873 mp->br_route.br_tbl_id.bt_sub_domain = sub_domain;
6874 mp->br_route.br_tbl_id.bt_hdr_len_id = hdr_len;
6875 mp->br_route.br_bp = ntohs (bp);
6876 mp->br_route.br_n_paths = 1;
6877 mp->br_route.br_paths[0].n_labels = 1;
6878 mp->br_route.br_paths[0].label_stack[0].label = ntohl (next_hop_out_label);
6879 mp->br_route.br_paths[0].proto = (next_hop_proto_is_ip4 ?
6880 FIB_API_PATH_NH_PROTO_IP4 :
6881 FIB_API_PATH_NH_PROTO_IP6);
6883 if (next_hop_proto_is_ip4)
6885 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip4,
6886 &v4_next_hop_address, sizeof (v4_next_hop_address));
6890 clib_memcpy (&mp->br_route.br_paths[0].nh.address.ip6,
6891 &v6_next_hop_address, sizeof (v6_next_hop_address));
6897 /* Wait for a reply... */
6904 api_mpls_tunnel_add_del (vat_main_t * vam)
6906 unformat_input_t *i = vam->input;
6907 vl_api_mpls_tunnel_add_del_t *mp;
6909 vl_api_fib_path_t paths[8];
6910 u32 sw_if_index = ~0;
6916 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6918 if (unformat (i, "add"))
6922 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6924 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6926 else if (unformat (i, "l2-only"))
6930 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6933 if (8 == path_count)
6935 errmsg ("max 8 paths");
6941 clib_warning ("parse error '%U'", format_unformat_error, i);
6946 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6948 mp->mt_is_add = is_add;
6949 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6950 mp->mt_tunnel.mt_l2_only = l2_only;
6951 mp->mt_tunnel.mt_is_multicast = 0;
6952 mp->mt_tunnel.mt_n_paths = path_count;
6954 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6955 sizeof (paths[0]) * path_count);
6963 api_sw_interface_set_unnumbered (vat_main_t * vam)
6965 unformat_input_t *i = vam->input;
6966 vl_api_sw_interface_set_unnumbered_t *mp;
6968 u32 unnum_sw_index = ~0;
6970 u8 sw_if_index_set = 0;
6973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6975 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6976 sw_if_index_set = 1;
6977 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6978 sw_if_index_set = 1;
6979 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6981 else if (unformat (i, "del"))
6985 clib_warning ("parse error '%U'", format_unformat_error, i);
6990 if (sw_if_index_set == 0)
6992 errmsg ("missing interface name or sw_if_index");
6996 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6998 mp->sw_if_index = ntohl (sw_if_index);
6999 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
7000 mp->is_add = is_add;
7009 api_create_vlan_subif (vat_main_t * vam)
7011 unformat_input_t *i = vam->input;
7012 vl_api_create_vlan_subif_t *mp;
7014 u8 sw_if_index_set = 0;
7019 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7021 if (unformat (i, "sw_if_index %d", &sw_if_index))
7022 sw_if_index_set = 1;
7024 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7025 sw_if_index_set = 1;
7026 else if (unformat (i, "vlan %d", &vlan_id))
7030 clib_warning ("parse error '%U'", format_unformat_error, i);
7035 if (sw_if_index_set == 0)
7037 errmsg ("missing interface name or sw_if_index");
7041 if (vlan_id_set == 0)
7043 errmsg ("missing vlan_id");
7046 M (CREATE_VLAN_SUBIF, mp);
7048 mp->sw_if_index = ntohl (sw_if_index);
7049 mp->vlan_id = ntohl (vlan_id);
7056 #define foreach_create_subif_bit \
7063 _(outer_vlan_id_any) \
7064 _(inner_vlan_id_any)
7066 #define foreach_create_subif_flag \
7071 _(4, "exact_match") \
7072 _(5, "default_sub") \
7073 _(6, "outer_vlan_id_any") \
7074 _(7, "inner_vlan_id_any")
7077 api_create_subif (vat_main_t * vam)
7079 unformat_input_t *i = vam->input;
7080 vl_api_create_subif_t *mp;
7082 u8 sw_if_index_set = 0;
7085 u32 __attribute__ ((unused)) no_tags = 0;
7086 u32 __attribute__ ((unused)) one_tag = 0;
7087 u32 __attribute__ ((unused)) two_tags = 0;
7088 u32 __attribute__ ((unused)) dot1ad = 0;
7089 u32 __attribute__ ((unused)) exact_match = 0;
7090 u32 __attribute__ ((unused)) default_sub = 0;
7091 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
7092 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
7094 u16 outer_vlan_id = 0;
7095 u16 inner_vlan_id = 0;
7098 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7100 if (unformat (i, "sw_if_index %d", &sw_if_index))
7101 sw_if_index_set = 1;
7103 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7104 sw_if_index_set = 1;
7105 else if (unformat (i, "sub_id %d", &sub_id))
7107 else if (unformat (i, "outer_vlan_id %d", &tmp))
7108 outer_vlan_id = tmp;
7109 else if (unformat (i, "inner_vlan_id %d", &tmp))
7110 inner_vlan_id = tmp;
7112 #define _(a) else if (unformat (i, #a)) a = 1 ;
7113 foreach_create_subif_bit
7117 clib_warning ("parse error '%U'", format_unformat_error, i);
7122 if (sw_if_index_set == 0)
7124 errmsg ("missing interface name or sw_if_index");
7128 if (sub_id_set == 0)
7130 errmsg ("missing sub_id");
7133 M (CREATE_SUBIF, mp);
7135 mp->sw_if_index = ntohl (sw_if_index);
7136 mp->sub_id = ntohl (sub_id);
7138 #define _(a,b) mp->sub_if_flags |= (1 << a);
7139 foreach_create_subif_flag;
7142 mp->outer_vlan_id = ntohs (outer_vlan_id);
7143 mp->inner_vlan_id = ntohs (inner_vlan_id);
7151 api_ip_table_replace_begin (vat_main_t * vam)
7153 unformat_input_t *i = vam->input;
7154 vl_api_ip_table_replace_begin_t *mp;
7159 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7161 if (unformat (i, "table %d", &table_id))
7163 else if (unformat (i, "ipv6"))
7167 clib_warning ("parse error '%U'", format_unformat_error, i);
7172 M (IP_TABLE_REPLACE_BEGIN, mp);
7174 mp->table.table_id = ntohl (table_id);
7175 mp->table.is_ip6 = is_ipv6;
7183 api_ip_table_flush (vat_main_t * vam)
7185 unformat_input_t *i = vam->input;
7186 vl_api_ip_table_flush_t *mp;
7191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7193 if (unformat (i, "table %d", &table_id))
7195 else if (unformat (i, "ipv6"))
7199 clib_warning ("parse error '%U'", format_unformat_error, i);
7204 M (IP_TABLE_FLUSH, mp);
7206 mp->table.table_id = ntohl (table_id);
7207 mp->table.is_ip6 = is_ipv6;
7215 api_ip_table_replace_end (vat_main_t * vam)
7217 unformat_input_t *i = vam->input;
7218 vl_api_ip_table_replace_end_t *mp;
7223 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7225 if (unformat (i, "table %d", &table_id))
7227 else if (unformat (i, "ipv6"))
7231 clib_warning ("parse error '%U'", format_unformat_error, i);
7236 M (IP_TABLE_REPLACE_END, mp);
7238 mp->table.table_id = ntohl (table_id);
7239 mp->table.is_ip6 = is_ipv6;
7247 api_set_ip_flow_hash (vat_main_t * vam)
7249 unformat_input_t *i = vam->input;
7250 vl_api_set_ip_flow_hash_t *mp;
7262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7264 if (unformat (i, "vrf %d", &vrf_id))
7266 else if (unformat (i, "ipv6"))
7268 else if (unformat (i, "src"))
7270 else if (unformat (i, "dst"))
7272 else if (unformat (i, "sport"))
7274 else if (unformat (i, "dport"))
7276 else if (unformat (i, "proto"))
7278 else if (unformat (i, "reverse"))
7283 clib_warning ("parse error '%U'", format_unformat_error, i);
7288 if (vrf_id_set == 0)
7290 errmsg ("missing vrf id");
7294 M (SET_IP_FLOW_HASH, mp);
7300 mp->reverse = reverse;
7301 mp->vrf_id = ntohl (vrf_id);
7302 mp->is_ipv6 = is_ipv6;
7310 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
7312 unformat_input_t *i = vam->input;
7313 vl_api_sw_interface_ip6_enable_disable_t *mp;
7315 u8 sw_if_index_set = 0;
7319 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7321 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7322 sw_if_index_set = 1;
7323 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7324 sw_if_index_set = 1;
7325 else if (unformat (i, "enable"))
7327 else if (unformat (i, "disable"))
7331 clib_warning ("parse error '%U'", format_unformat_error, i);
7336 if (sw_if_index_set == 0)
7338 errmsg ("missing interface name or sw_if_index");
7342 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
7344 mp->sw_if_index = ntohl (sw_if_index);
7345 mp->enable = enable;
7354 api_l2_patch_add_del (vat_main_t * vam)
7356 unformat_input_t *i = vam->input;
7357 vl_api_l2_patch_add_del_t *mp;
7359 u8 rx_sw_if_index_set = 0;
7361 u8 tx_sw_if_index_set = 0;
7365 /* Parse args required to build the message */
7366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7368 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
7369 rx_sw_if_index_set = 1;
7370 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
7371 tx_sw_if_index_set = 1;
7372 else if (unformat (i, "rx"))
7374 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7376 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7378 rx_sw_if_index_set = 1;
7383 else if (unformat (i, "tx"))
7385 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7387 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
7389 tx_sw_if_index_set = 1;
7394 else if (unformat (i, "del"))
7400 if (rx_sw_if_index_set == 0)
7402 errmsg ("missing rx interface name or rx_sw_if_index");
7406 if (tx_sw_if_index_set == 0)
7408 errmsg ("missing tx interface name or tx_sw_if_index");
7412 M (L2_PATCH_ADD_DEL, mp);
7414 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
7415 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
7416 mp->is_add = is_add;
7424 u8 localsid_addr[16];
7433 api_sr_localsid_add_del (vat_main_t * vam)
7435 unformat_input_t *i = vam->input;
7436 vl_api_sr_localsid_add_del_t *mp;
7439 ip6_address_t localsid;
7443 u32 fib_table = ~(u32) 0;
7444 ip46_address_t nh_addr;
7445 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
7447 bool nexthop_set = 0;
7451 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7453 if (unformat (i, "del"))
7455 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
7456 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
7458 else if (unformat (i, "behavior %u", &behavior));
7459 else if (unformat (i, "sw_if_index %u", &sw_if_index));
7460 else if (unformat (i, "fib-table %u", &fib_table));
7461 else if (unformat (i, "end.psp %u", &behavior));
7466 M (SR_LOCALSID_ADD_DEL, mp);
7468 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
7472 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
7474 mp->behavior = behavior;
7475 mp->sw_if_index = ntohl (sw_if_index);
7476 mp->fib_table = ntohl (fib_table);
7477 mp->end_psp = end_psp;
7478 mp->is_del = is_del;
7486 api_ioam_enable (vat_main_t * vam)
7488 unformat_input_t *input = vam->input;
7489 vl_api_ioam_enable_t *mp;
7491 int has_trace_option = 0;
7492 int has_pot_option = 0;
7493 int has_seqno_option = 0;
7494 int has_analyse_option = 0;
7497 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7499 if (unformat (input, "trace"))
7500 has_trace_option = 1;
7501 else if (unformat (input, "pot"))
7503 else if (unformat (input, "seqno"))
7504 has_seqno_option = 1;
7505 else if (unformat (input, "analyse"))
7506 has_analyse_option = 1;
7510 M (IOAM_ENABLE, mp);
7511 mp->id = htons (id);
7512 mp->seqno = has_seqno_option;
7513 mp->analyse = has_analyse_option;
7514 mp->pot_enable = has_pot_option;
7515 mp->trace_enable = has_trace_option;
7524 api_ioam_disable (vat_main_t * vam)
7526 vl_api_ioam_disable_t *mp;
7529 M (IOAM_DISABLE, mp);
7535 #define foreach_tcp_proto_field \
7539 #define foreach_udp_proto_field \
7543 #define foreach_ip4_proto_field \
7555 u16 src_port, dst_port;
7558 #if VPP_API_TEST_BUILTIN == 0
7560 unformat_tcp_mask (unformat_input_t * input, va_list * args)
7562 u8 **maskp = va_arg (*args, u8 **);
7564 u8 found_something = 0;
7567 #define _(a) u8 a=0;
7568 foreach_tcp_proto_field;
7571 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7574 #define _(a) else if (unformat (input, #a)) a=1;
7575 foreach_tcp_proto_field
7581 #define _(a) found_something += a;
7582 foreach_tcp_proto_field;
7585 if (found_something == 0)
7588 vec_validate (mask, sizeof (*tcp) - 1);
7590 tcp = (tcp_header_t *) mask;
7592 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
7593 foreach_tcp_proto_field;
7601 unformat_udp_mask (unformat_input_t * input, va_list * args)
7603 u8 **maskp = va_arg (*args, u8 **);
7605 u8 found_something = 0;
7608 #define _(a) u8 a=0;
7609 foreach_udp_proto_field;
7612 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7615 #define _(a) else if (unformat (input, #a)) a=1;
7616 foreach_udp_proto_field
7622 #define _(a) found_something += a;
7623 foreach_udp_proto_field;
7626 if (found_something == 0)
7629 vec_validate (mask, sizeof (*udp) - 1);
7631 udp = (udp_header_t *) mask;
7633 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
7634 foreach_udp_proto_field;
7642 unformat_l4_mask (unformat_input_t * input, va_list * args)
7644 u8 **maskp = va_arg (*args, u8 **);
7645 u16 src_port = 0, dst_port = 0;
7646 tcpudp_header_t *tcpudp;
7648 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7650 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
7652 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
7654 else if (unformat (input, "src_port"))
7656 else if (unformat (input, "dst_port"))
7662 if (!src_port && !dst_port)
7666 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
7668 tcpudp = (tcpudp_header_t *) mask;
7669 tcpudp->src_port = src_port;
7670 tcpudp->dst_port = dst_port;
7678 unformat_ip4_mask (unformat_input_t * input, va_list * args)
7680 u8 **maskp = va_arg (*args, u8 **);
7682 u8 found_something = 0;
7685 #define _(a) u8 a=0;
7686 foreach_ip4_proto_field;
7692 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7694 if (unformat (input, "version"))
7696 else if (unformat (input, "hdr_length"))
7698 else if (unformat (input, "src"))
7700 else if (unformat (input, "dst"))
7702 else if (unformat (input, "proto"))
7705 #define _(a) else if (unformat (input, #a)) a=1;
7706 foreach_ip4_proto_field
7712 #define _(a) found_something += a;
7713 foreach_ip4_proto_field;
7716 if (found_something == 0)
7719 vec_validate (mask, sizeof (*ip) - 1);
7721 ip = (ip4_header_t *) mask;
7723 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7724 foreach_ip4_proto_field;
7727 ip->ip_version_and_header_length = 0;
7730 ip->ip_version_and_header_length |= 0xF0;
7733 ip->ip_version_and_header_length |= 0x0F;
7739 #define foreach_ip6_proto_field \
7747 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7749 u8 **maskp = va_arg (*args, u8 **);
7751 u8 found_something = 0;
7753 u32 ip_version_traffic_class_and_flow_label;
7755 #define _(a) u8 a=0;
7756 foreach_ip6_proto_field;
7759 u8 traffic_class = 0;
7762 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7764 if (unformat (input, "version"))
7766 else if (unformat (input, "traffic-class"))
7768 else if (unformat (input, "flow-label"))
7770 else if (unformat (input, "src"))
7772 else if (unformat (input, "dst"))
7774 else if (unformat (input, "proto"))
7777 #define _(a) else if (unformat (input, #a)) a=1;
7778 foreach_ip6_proto_field
7784 #define _(a) found_something += a;
7785 foreach_ip6_proto_field;
7788 if (found_something == 0)
7791 vec_validate (mask, sizeof (*ip) - 1);
7793 ip = (ip6_header_t *) mask;
7795 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7796 foreach_ip6_proto_field;
7799 ip_version_traffic_class_and_flow_label = 0;
7802 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7805 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7808 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7810 ip->ip_version_traffic_class_and_flow_label =
7811 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7818 unformat_l3_mask (unformat_input_t * input, va_list * args)
7820 u8 **maskp = va_arg (*args, u8 **);
7822 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7824 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7826 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7835 unformat_l2_mask (unformat_input_t * input, va_list * args)
7837 u8 **maskp = va_arg (*args, u8 **);
7852 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7854 if (unformat (input, "src"))
7856 else if (unformat (input, "dst"))
7858 else if (unformat (input, "proto"))
7860 else if (unformat (input, "tag1"))
7862 else if (unformat (input, "tag2"))
7864 else if (unformat (input, "ignore-tag1"))
7866 else if (unformat (input, "ignore-tag2"))
7868 else if (unformat (input, "cos1"))
7870 else if (unformat (input, "cos2"))
7872 else if (unformat (input, "dot1q"))
7874 else if (unformat (input, "dot1ad"))
7879 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7880 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7883 if (tag1 || ignore_tag1 || cos1 || dot1q)
7885 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7888 vec_validate (mask, len - 1);
7891 clib_memset (mask, 0xff, 6);
7894 clib_memset (mask + 6, 0xff, 6);
7898 /* inner vlan tag */
7907 mask[21] = mask[20] = 0xff;
7928 mask[16] = mask[17] = 0xff;
7938 mask[12] = mask[13] = 0xff;
7945 unformat_classify_mask (unformat_input_t * input, va_list * args)
7947 u8 **maskp = va_arg (*args, u8 **);
7948 u32 *skipp = va_arg (*args, u32 *);
7949 u32 *matchp = va_arg (*args, u32 *);
7957 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7959 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7961 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7963 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7965 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7979 if (mask || l2 || l3 || l4)
7983 /* "With a free Ethernet header in every package" */
7985 vec_validate (l2, 13);
7989 vec_append (mask, l3);
7994 vec_append (mask, l4);
7999 /* Scan forward looking for the first significant mask octet */
8000 for (i = 0; i < vec_len (mask); i++)
8004 /* compute (skip, match) params */
8005 *skipp = i / sizeof (u32x4);
8006 vec_delete (mask, *skipp * sizeof (u32x4), 0);
8008 /* Pad mask to an even multiple of the vector size */
8009 while (vec_len (mask) % sizeof (u32x4))
8012 match = vec_len (mask) / sizeof (u32x4);
8014 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
8016 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
8017 if (*tmp || *(tmp + 1))
8022 clib_warning ("BUG: match 0");
8024 _vec_len (mask) = match * sizeof (u32x4);
8034 #endif /* VPP_API_TEST_BUILTIN */
8036 #define foreach_l2_next \
8038 _(ethernet, ETHERNET_INPUT) \
8043 unformat_l2_next_index (unformat_input_t * input, va_list * args)
8045 u32 *miss_next_indexp = va_arg (*args, u32 *);
8050 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
8054 if (unformat (input, "%d", &tmp))
8063 *miss_next_indexp = next_index;
8067 #define foreach_ip_next \
8073 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
8075 u32 *miss_next_indexp = va_arg (*args, u32 *);
8080 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
8084 if (unformat (input, "%d", &tmp))
8093 *miss_next_indexp = next_index;
8097 #define foreach_acl_next \
8101 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
8103 u32 *miss_next_indexp = va_arg (*args, u32 *);
8108 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
8112 if (unformat (input, "permit"))
8117 else if (unformat (input, "%d", &tmp))
8126 *miss_next_indexp = next_index;
8131 unformat_policer_precolor (unformat_input_t * input, va_list * args)
8133 u32 *r = va_arg (*args, u32 *);
8135 if (unformat (input, "conform-color"))
8136 *r = POLICE_CONFORM;
8137 else if (unformat (input, "exceed-color"))
8146 api_classify_add_del_table (vat_main_t * vam)
8148 unformat_input_t *i = vam->input;
8149 vl_api_classify_add_del_table_t *mp;
8156 u32 table_index = ~0;
8157 u32 next_table_index = ~0;
8158 u32 miss_next_index = ~0;
8159 u32 memory_size = 32 << 20;
8161 u32 current_data_flag = 0;
8162 int current_data_offset = 0;
8165 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8167 if (unformat (i, "del"))
8169 else if (unformat (i, "del-chain"))
8174 else if (unformat (i, "buckets %d", &nbuckets))
8176 else if (unformat (i, "memory_size %d", &memory_size))
8178 else if (unformat (i, "skip %d", &skip))
8180 else if (unformat (i, "match %d", &match))
8182 else if (unformat (i, "table %d", &table_index))
8184 else if (unformat (i, "mask %U", unformat_classify_mask,
8185 &mask, &skip, &match))
8187 else if (unformat (i, "next-table %d", &next_table_index))
8189 else if (unformat (i, "miss-next %U", api_unformat_ip_next_index,
8192 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
8195 else if (unformat (i, "acl-miss-next %U", api_unformat_acl_next_index,
8198 else if (unformat (i, "current-data-flag %d", ¤t_data_flag))
8200 else if (unformat (i, "current-data-offset %d", ¤t_data_offset))
8206 if (is_add && mask == 0)
8208 errmsg ("Mask required");
8212 if (is_add && skip == ~0)
8214 errmsg ("skip count required");
8218 if (is_add && match == ~0)
8220 errmsg ("match count required");
8224 if (!is_add && table_index == ~0)
8226 errmsg ("table index required for delete");
8230 M2 (CLASSIFY_ADD_DEL_TABLE, mp, vec_len (mask));
8232 mp->is_add = is_add;
8233 mp->del_chain = del_chain;
8234 mp->table_index = ntohl (table_index);
8235 mp->nbuckets = ntohl (nbuckets);
8236 mp->memory_size = ntohl (memory_size);
8237 mp->skip_n_vectors = ntohl (skip);
8238 mp->match_n_vectors = ntohl (match);
8239 mp->next_table_index = ntohl (next_table_index);
8240 mp->miss_next_index = ntohl (miss_next_index);
8241 mp->current_data_flag = ntohl (current_data_flag);
8242 mp->current_data_offset = ntohl (current_data_offset);
8243 mp->mask_len = ntohl (vec_len (mask));
8244 clib_memcpy (mp->mask, mask, vec_len (mask));
8253 #if VPP_API_TEST_BUILTIN == 0
8255 unformat_l4_match (unformat_input_t * input, va_list * args)
8257 u8 **matchp = va_arg (*args, u8 **);
8259 u8 *proto_header = 0;
8265 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8267 if (unformat (input, "src_port %d", &src_port))
8269 else if (unformat (input, "dst_port %d", &dst_port))
8275 h.src_port = clib_host_to_net_u16 (src_port);
8276 h.dst_port = clib_host_to_net_u16 (dst_port);
8277 vec_validate (proto_header, sizeof (h) - 1);
8278 memcpy (proto_header, &h, sizeof (h));
8280 *matchp = proto_header;
8286 unformat_ip4_match (unformat_input_t * input, va_list * args)
8288 u8 **matchp = va_arg (*args, u8 **);
8295 int src = 0, dst = 0;
8296 ip4_address_t src_val, dst_val;
8303 int fragment_id = 0;
8304 u32 fragment_id_val;
8310 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8312 if (unformat (input, "version %d", &version_val))
8314 else if (unformat (input, "hdr_length %d", &hdr_length_val))
8316 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
8318 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
8320 else if (unformat (input, "proto %d", &proto_val))
8322 else if (unformat (input, "tos %d", &tos_val))
8324 else if (unformat (input, "length %d", &length_val))
8326 else if (unformat (input, "fragment_id %d", &fragment_id_val))
8328 else if (unformat (input, "ttl %d", &ttl_val))
8330 else if (unformat (input, "checksum %d", &checksum_val))
8336 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
8337 + ttl + checksum == 0)
8341 * Aligned because we use the real comparison functions
8343 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8345 ip = (ip4_header_t *) match;
8347 /* These are realistically matched in practice */
8349 ip->src_address.as_u32 = src_val.as_u32;
8352 ip->dst_address.as_u32 = dst_val.as_u32;
8355 ip->protocol = proto_val;
8358 /* These are not, but they're included for completeness */
8360 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
8363 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
8369 ip->length = clib_host_to_net_u16 (length_val);
8375 ip->checksum = clib_host_to_net_u16 (checksum_val);
8382 unformat_ip6_match (unformat_input_t * input, va_list * args)
8384 u8 **matchp = va_arg (*args, u8 **);
8389 u8 traffic_class = 0;
8390 u32 traffic_class_val = 0;
8393 int src = 0, dst = 0;
8394 ip6_address_t src_val, dst_val;
8397 int payload_length = 0;
8398 u32 payload_length_val;
8401 u32 ip_version_traffic_class_and_flow_label;
8403 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8405 if (unformat (input, "version %d", &version_val))
8407 else if (unformat (input, "traffic_class %d", &traffic_class_val))
8409 else if (unformat (input, "flow_label %d", &flow_label_val))
8411 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
8413 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
8415 else if (unformat (input, "proto %d", &proto_val))
8417 else if (unformat (input, "payload_length %d", &payload_length_val))
8419 else if (unformat (input, "hop_limit %d", &hop_limit_val))
8425 if (version + traffic_class + flow_label + src + dst + proto +
8426 payload_length + hop_limit == 0)
8430 * Aligned because we use the real comparison functions
8432 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
8434 ip = (ip6_header_t *) match;
8437 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
8440 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
8443 ip->protocol = proto_val;
8445 ip_version_traffic_class_and_flow_label = 0;
8448 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
8451 ip_version_traffic_class_and_flow_label |=
8452 (traffic_class_val & 0xFF) << 20;
8455 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
8457 ip->ip_version_traffic_class_and_flow_label =
8458 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
8461 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
8464 ip->hop_limit = hop_limit_val;
8471 unformat_l3_match (unformat_input_t * input, va_list * args)
8473 u8 **matchp = va_arg (*args, u8 **);
8475 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8477 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
8479 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
8488 unformat_vlan_tag (unformat_input_t * input, va_list * args)
8490 u8 *tagp = va_arg (*args, u8 *);
8493 if (unformat (input, "%d", &tag))
8495 tagp[0] = (tag >> 8) & 0x0F;
8496 tagp[1] = tag & 0xFF;
8504 unformat_l2_match (unformat_input_t * input, va_list * args)
8506 u8 **matchp = va_arg (*args, u8 **);
8526 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8528 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
8531 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
8533 else if (unformat (input, "proto %U",
8534 unformat_ethernet_type_host_byte_order, &proto_val))
8536 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
8538 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
8540 else if (unformat (input, "ignore-tag1"))
8542 else if (unformat (input, "ignore-tag2"))
8544 else if (unformat (input, "cos1 %d", &cos1_val))
8546 else if (unformat (input, "cos2 %d", &cos2_val))
8551 if ((src + dst + proto + tag1 + tag2 +
8552 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
8555 if (tag1 || ignore_tag1 || cos1)
8557 if (tag2 || ignore_tag2 || cos2)
8560 vec_validate_aligned (match, len - 1, sizeof (u32x4));
8563 clib_memcpy (match, dst_val, 6);
8566 clib_memcpy (match + 6, src_val, 6);
8570 /* inner vlan tag */
8571 match[19] = tag2_val[1];
8572 match[18] = tag2_val[0];
8574 match[18] |= (cos2_val & 0x7) << 5;
8577 match[21] = proto_val & 0xff;
8578 match[20] = proto_val >> 8;
8582 match[15] = tag1_val[1];
8583 match[14] = tag1_val[0];
8586 match[14] |= (cos1_val & 0x7) << 5;
8592 match[15] = tag1_val[1];
8593 match[14] = tag1_val[0];
8596 match[17] = proto_val & 0xff;
8597 match[16] = proto_val >> 8;
8600 match[14] |= (cos1_val & 0x7) << 5;
8606 match[18] |= (cos2_val & 0x7) << 5;
8608 match[14] |= (cos1_val & 0x7) << 5;
8611 match[13] = proto_val & 0xff;
8612 match[12] = proto_val >> 8;
8620 unformat_qos_source (unformat_input_t * input, va_list * args)
8622 int *qs = va_arg (*args, int *);
8624 if (unformat (input, "ip"))
8625 *qs = QOS_SOURCE_IP;
8626 else if (unformat (input, "mpls"))
8627 *qs = QOS_SOURCE_MPLS;
8628 else if (unformat (input, "ext"))
8629 *qs = QOS_SOURCE_EXT;
8630 else if (unformat (input, "vlan"))
8631 *qs = QOS_SOURCE_VLAN;
8640 api_unformat_classify_match (unformat_input_t * input, va_list * args)
8642 u8 **matchp = va_arg (*args, u8 **);
8643 u32 skip_n_vectors = va_arg (*args, u32);
8644 u32 match_n_vectors = va_arg (*args, u32);
8651 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8653 if (unformat (input, "hex %U", unformat_hex_string, &match))
8655 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
8657 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
8659 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
8673 if (match || l2 || l3 || l4)
8677 /* "Win a free Ethernet header in every packet" */
8679 vec_validate_aligned (l2, 13, sizeof (u32x4));
8683 vec_append_aligned (match, l3, sizeof (u32x4));
8688 vec_append_aligned (match, l4, sizeof (u32x4));
8693 /* Make sure the vector is big enough even if key is all 0's */
8694 vec_validate_aligned
8695 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
8698 /* Set size, include skipped vectors */
8699 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
8710 api_classify_add_del_session (vat_main_t * vam)
8712 unformat_input_t *i = vam->input;
8713 vl_api_classify_add_del_session_t *mp;
8715 u32 table_index = ~0;
8716 u32 hit_next_index = ~0;
8717 u32 opaque_index = ~0;
8720 u32 skip_n_vectors = 0;
8721 u32 match_n_vectors = 0;
8727 * Warning: you have to supply skip_n and match_n
8728 * because the API client cant simply look at the classify
8732 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8734 if (unformat (i, "del"))
8736 else if (unformat (i, "hit-next %U", api_unformat_ip_next_index,
8739 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
8742 else if (unformat (i, "acl-hit-next %U", api_unformat_acl_next_index,
8745 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
8747 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
8749 else if (unformat (i, "opaque-index %d", &opaque_index))
8751 else if (unformat (i, "skip_n %d", &skip_n_vectors))
8753 else if (unformat (i, "match_n %d", &match_n_vectors))
8755 else if (unformat (i, "match %U", api_unformat_classify_match,
8756 &match, skip_n_vectors, match_n_vectors))
8758 else if (unformat (i, "advance %d", &advance))
8760 else if (unformat (i, "table-index %d", &table_index))
8762 else if (unformat (i, "action set-ip4-fib-id %d", &metadata))
8764 else if (unformat (i, "action set-ip6-fib-id %d", &metadata))
8766 else if (unformat (i, "action %d", &action))
8768 else if (unformat (i, "metadata %d", &metadata))
8774 if (table_index == ~0)
8776 errmsg ("Table index required");
8780 if (is_add && match == 0)
8782 errmsg ("Match value required");
8786 M2 (CLASSIFY_ADD_DEL_SESSION, mp, vec_len (match));
8788 mp->is_add = is_add;
8789 mp->table_index = ntohl (table_index);
8790 mp->hit_next_index = ntohl (hit_next_index);
8791 mp->opaque_index = ntohl (opaque_index);
8792 mp->advance = ntohl (advance);
8793 mp->action = action;
8794 mp->metadata = ntohl (metadata);
8795 mp->match_len = ntohl (vec_len (match));
8796 clib_memcpy (mp->match, match, vec_len (match));
8805 api_classify_set_interface_ip_table (vat_main_t * vam)
8807 unformat_input_t *i = vam->input;
8808 vl_api_classify_set_interface_ip_table_t *mp;
8810 int sw_if_index_set;
8811 u32 table_index = ~0;
8815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8817 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8818 sw_if_index_set = 1;
8819 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8820 sw_if_index_set = 1;
8821 else if (unformat (i, "table %d", &table_index))
8825 clib_warning ("parse error '%U'", format_unformat_error, i);
8830 if (sw_if_index_set == 0)
8832 errmsg ("missing interface name or sw_if_index");
8837 M (CLASSIFY_SET_INTERFACE_IP_TABLE, mp);
8839 mp->sw_if_index = ntohl (sw_if_index);
8840 mp->table_index = ntohl (table_index);
8841 mp->is_ipv6 = is_ipv6;
8849 api_classify_set_interface_l2_tables (vat_main_t * vam)
8851 unformat_input_t *i = vam->input;
8852 vl_api_classify_set_interface_l2_tables_t *mp;
8854 int sw_if_index_set;
8855 u32 ip4_table_index = ~0;
8856 u32 ip6_table_index = ~0;
8857 u32 other_table_index = ~0;
8861 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8863 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8864 sw_if_index_set = 1;
8865 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8866 sw_if_index_set = 1;
8867 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8869 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8871 else if (unformat (i, "other-table %d", &other_table_index))
8873 else if (unformat (i, "is-input %d", &is_input))
8877 clib_warning ("parse error '%U'", format_unformat_error, i);
8882 if (sw_if_index_set == 0)
8884 errmsg ("missing interface name or sw_if_index");
8889 M (CLASSIFY_SET_INTERFACE_L2_TABLES, mp);
8891 mp->sw_if_index = ntohl (sw_if_index);
8892 mp->ip4_table_index = ntohl (ip4_table_index);
8893 mp->ip6_table_index = ntohl (ip6_table_index);
8894 mp->other_table_index = ntohl (other_table_index);
8895 mp->is_input = (u8) is_input;
8903 api_set_ipfix_exporter (vat_main_t * vam)
8905 unformat_input_t *i = vam->input;
8906 vl_api_set_ipfix_exporter_t *mp;
8907 ip4_address_t collector_address;
8908 u8 collector_address_set = 0;
8909 u32 collector_port = ~0;
8910 ip4_address_t src_address;
8911 u8 src_address_set = 0;
8914 u32 template_interval = ~0;
8915 u8 udp_checksum = 0;
8918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8920 if (unformat (i, "collector_address %U", unformat_ip4_address,
8921 &collector_address))
8922 collector_address_set = 1;
8923 else if (unformat (i, "collector_port %d", &collector_port))
8925 else if (unformat (i, "src_address %U", unformat_ip4_address,
8927 src_address_set = 1;
8928 else if (unformat (i, "vrf_id %d", &vrf_id))
8930 else if (unformat (i, "path_mtu %d", &path_mtu))
8932 else if (unformat (i, "template_interval %d", &template_interval))
8934 else if (unformat (i, "udp_checksum"))
8940 if (collector_address_set == 0)
8942 errmsg ("collector_address required");
8946 if (src_address_set == 0)
8948 errmsg ("src_address required");
8952 M (SET_IPFIX_EXPORTER, mp);
8954 memcpy (mp->collector_address.un.ip4, collector_address.data,
8955 sizeof (collector_address.data));
8956 mp->collector_port = htons ((u16) collector_port);
8957 memcpy (mp->src_address.un.ip4, src_address.data,
8958 sizeof (src_address.data));
8959 mp->vrf_id = htonl (vrf_id);
8960 mp->path_mtu = htonl (path_mtu);
8961 mp->template_interval = htonl (template_interval);
8962 mp->udp_checksum = udp_checksum;
8970 api_set_ipfix_classify_stream (vat_main_t * vam)
8972 unformat_input_t *i = vam->input;
8973 vl_api_set_ipfix_classify_stream_t *mp;
8975 u32 src_port = UDP_DST_PORT_ipfix;
8978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8980 if (unformat (i, "domain %d", &domain_id))
8982 else if (unformat (i, "src_port %d", &src_port))
8986 errmsg ("unknown input `%U'", format_unformat_error, i);
8991 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8993 mp->domain_id = htonl (domain_id);
8994 mp->src_port = htons ((u16) src_port);
9002 api_ipfix_classify_table_add_del (vat_main_t * vam)
9004 unformat_input_t *i = vam->input;
9005 vl_api_ipfix_classify_table_add_del_t *mp;
9007 u32 classify_table_index = ~0;
9009 u8 transport_protocol = 255;
9012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9014 if (unformat (i, "add"))
9016 else if (unformat (i, "del"))
9018 else if (unformat (i, "table %d", &classify_table_index))
9020 else if (unformat (i, "ip4"))
9022 else if (unformat (i, "ip6"))
9024 else if (unformat (i, "tcp"))
9025 transport_protocol = 6;
9026 else if (unformat (i, "udp"))
9027 transport_protocol = 17;
9030 errmsg ("unknown input `%U'", format_unformat_error, i);
9037 errmsg ("expecting: add|del");
9040 if (classify_table_index == ~0)
9042 errmsg ("classifier table not specified");
9045 if (ip_version == 0)
9047 errmsg ("IP version not specified");
9051 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
9053 mp->is_add = is_add;
9054 mp->table_id = htonl (classify_table_index);
9055 mp->ip_version = ip_version;
9056 mp->transport_protocol = transport_protocol;
9064 api_get_node_index (vat_main_t * vam)
9066 unformat_input_t *i = vam->input;
9067 vl_api_get_node_index_t *mp;
9071 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9073 if (unformat (i, "node %s", &name))
9080 errmsg ("node name required");
9083 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9085 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9089 M (GET_NODE_INDEX, mp);
9090 clib_memcpy (mp->node_name, name, vec_len (name));
9099 api_get_next_index (vat_main_t * vam)
9101 unformat_input_t *i = vam->input;
9102 vl_api_get_next_index_t *mp;
9103 u8 *node_name = 0, *next_node_name = 0;
9106 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9108 if (unformat (i, "node-name %s", &node_name))
9110 else if (unformat (i, "next-node-name %s", &next_node_name))
9116 errmsg ("node name required");
9119 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
9121 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9125 if (next_node_name == 0)
9127 errmsg ("next node name required");
9130 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
9132 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
9136 M (GET_NEXT_INDEX, mp);
9137 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
9138 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
9139 vec_free (node_name);
9140 vec_free (next_node_name);
9148 api_add_node_next (vat_main_t * vam)
9150 unformat_input_t *i = vam->input;
9151 vl_api_add_node_next_t *mp;
9156 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9158 if (unformat (i, "node %s", &name))
9160 else if (unformat (i, "next %s", &next))
9167 errmsg ("node name required");
9170 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
9172 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
9177 errmsg ("next node required");
9180 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
9182 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
9186 M (ADD_NODE_NEXT, mp);
9187 clib_memcpy (mp->node_name, name, vec_len (name));
9188 clib_memcpy (mp->next_name, next, vec_len (next));
9197 static void vl_api_sw_interface_tap_v2_details_t_handler
9198 (vl_api_sw_interface_tap_v2_details_t * mp)
9200 vat_main_t *vam = &vat_main;
9203 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
9204 mp->host_ip4_prefix.len);
9206 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
9207 mp->host_ip6_prefix.len);
9210 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
9211 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
9212 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9213 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
9214 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
9220 static void vl_api_sw_interface_tap_v2_details_t_handler_json
9221 (vl_api_sw_interface_tap_v2_details_t * mp)
9223 vat_main_t *vam = &vat_main;
9224 vat_json_node_t *node = NULL;
9226 if (VAT_JSON_ARRAY != vam->json_tree.type)
9228 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9229 vat_json_init_array (&vam->json_tree);
9231 node = vat_json_array_add (&vam->json_tree);
9233 vat_json_init_object (node);
9234 vat_json_object_add_uint (node, "id", ntohl (mp->id));
9235 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9236 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
9237 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
9238 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9239 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9240 vat_json_object_add_string_copy (node, "host_mac_addr",
9241 format (0, "%U", format_ethernet_address,
9242 &mp->host_mac_addr));
9243 vat_json_object_add_string_copy (node, "host_namespace",
9244 mp->host_namespace);
9245 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
9246 vat_json_object_add_string_copy (node, "host_ip4_addr",
9247 format (0, "%U/%d", format_ip4_address,
9248 mp->host_ip4_prefix.address,
9249 mp->host_ip4_prefix.len));
9250 vat_json_object_add_string_copy (node, "host_ip6_prefix",
9251 format (0, "%U/%d", format_ip6_address,
9252 mp->host_ip6_prefix.address,
9253 mp->host_ip6_prefix.len));
9258 api_sw_interface_tap_v2_dump (vat_main_t * vam)
9260 vl_api_sw_interface_tap_v2_dump_t *mp;
9261 vl_api_control_ping_t *mp_ping;
9265 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
9266 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
9267 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
9270 /* Get list of tap interfaces */
9271 M (SW_INTERFACE_TAP_V2_DUMP, mp);
9274 /* Use a control ping for synchronization */
9275 MPING (CONTROL_PING, mp_ping);
9282 static void vl_api_sw_interface_virtio_pci_details_t_handler
9283 (vl_api_sw_interface_virtio_pci_details_t * mp)
9285 vat_main_t *vam = &vat_main;
9300 addr.domain = ntohs (mp->pci_addr.domain);
9301 addr.bus = mp->pci_addr.bus;
9302 addr.slot = mp->pci_addr.slot;
9303 addr.function = mp->pci_addr.function;
9305 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
9306 addr.slot, addr.function);
9309 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
9310 pci_addr, ntohl (mp->sw_if_index),
9311 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
9312 format_ethernet_address, mp->mac_addr,
9313 clib_net_to_host_u64 (mp->features));
9314 vec_free (pci_addr);
9317 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
9318 (vl_api_sw_interface_virtio_pci_details_t * mp)
9320 vat_main_t *vam = &vat_main;
9321 vat_json_node_t *node = NULL;
9322 vlib_pci_addr_t pci_addr;
9324 if (VAT_JSON_ARRAY != vam->json_tree.type)
9326 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9327 vat_json_init_array (&vam->json_tree);
9329 node = vat_json_array_add (&vam->json_tree);
9331 pci_addr.domain = ntohs (mp->pci_addr.domain);
9332 pci_addr.bus = mp->pci_addr.bus;
9333 pci_addr.slot = mp->pci_addr.slot;
9334 pci_addr.function = mp->pci_addr.function;
9336 vat_json_init_object (node);
9337 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
9338 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9339 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
9340 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
9341 vat_json_object_add_uint (node, "features",
9342 clib_net_to_host_u64 (mp->features));
9343 vat_json_object_add_string_copy (node, "mac_addr",
9344 format (0, "%U", format_ethernet_address,
9349 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
9351 vl_api_sw_interface_virtio_pci_dump_t *mp;
9352 vl_api_control_ping_t *mp_ping;
9356 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
9357 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
9358 "mac_addr", "features");
9360 /* Get list of tap interfaces */
9361 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
9364 /* Use a control ping for synchronization */
9365 MPING (CONTROL_PING, mp_ping);
9373 api_vxlan_offload_rx (vat_main_t * vam)
9375 unformat_input_t *line_input = vam->input;
9376 vl_api_vxlan_offload_rx_t *mp;
9377 u32 hw_if_index = ~0, rx_if_index = ~0;
9381 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9383 if (unformat (line_input, "del"))
9385 else if (unformat (line_input, "hw %U", api_unformat_hw_if_index, vam,
9388 else if (unformat (line_input, "hw hw_if_index %u", &hw_if_index))
9390 else if (unformat (line_input, "rx %U", api_unformat_sw_if_index, vam,
9393 else if (unformat (line_input, "rx sw_if_index %u", &rx_if_index))
9397 errmsg ("parse error '%U'", format_unformat_error, line_input);
9402 if (hw_if_index == ~0)
9404 errmsg ("no hw interface");
9408 if (rx_if_index == ~0)
9410 errmsg ("no rx tunnel");
9414 M (VXLAN_OFFLOAD_RX, mp);
9416 mp->hw_if_index = ntohl (hw_if_index);
9417 mp->sw_if_index = ntohl (rx_if_index);
9418 mp->enable = is_add;
9425 static uword unformat_vxlan_decap_next
9426 (unformat_input_t * input, va_list * args)
9428 u32 *result = va_arg (*args, u32 *);
9431 if (unformat (input, "l2"))
9432 *result = VXLAN_INPUT_NEXT_L2_INPUT;
9433 else if (unformat (input, "%d", &tmp))
9441 api_vxlan_add_del_tunnel (vat_main_t * vam)
9443 unformat_input_t *line_input = vam->input;
9444 vl_api_vxlan_add_del_tunnel_t *mp;
9445 ip46_address_t src, dst;
9447 u8 ipv4_set = 0, ipv6_set = 0;
9452 u32 mcast_sw_if_index = ~0;
9453 u32 encap_vrf_id = 0;
9454 u32 decap_next_index = ~0;
9458 /* Can't "universally zero init" (={0}) due to GCC bug 53119 */
9459 clib_memset (&src, 0, sizeof src);
9460 clib_memset (&dst, 0, sizeof dst);
9462 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9464 if (unformat (line_input, "del"))
9466 else if (unformat (line_input, "instance %d", &instance))
9469 if (unformat (line_input, "src %U", unformat_ip4_address, &src.ip4))
9475 if (unformat (line_input, "dst %U", unformat_ip4_address, &dst.ip4))
9481 if (unformat (line_input, "src %U", unformat_ip6_address, &src.ip6))
9487 if (unformat (line_input, "dst %U", unformat_ip6_address, &dst.ip6))
9492 else if (unformat (line_input, "group %U %U",
9493 unformat_ip4_address, &dst.ip4,
9494 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9496 grp_set = dst_set = 1;
9499 else if (unformat (line_input, "group %U",
9500 unformat_ip4_address, &dst.ip4))
9502 grp_set = dst_set = 1;
9505 else if (unformat (line_input, "group %U %U",
9506 unformat_ip6_address, &dst.ip6,
9507 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
9509 grp_set = dst_set = 1;
9512 else if (unformat (line_input, "group %U",
9513 unformat_ip6_address, &dst.ip6))
9515 grp_set = dst_set = 1;
9519 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
9521 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9523 else if (unformat (line_input, "decap-next %U",
9524 unformat_vxlan_decap_next, &decap_next_index))
9526 else if (unformat (line_input, "vni %d", &vni))
9530 errmsg ("parse error '%U'", format_unformat_error, line_input);
9537 errmsg ("tunnel src address not specified");
9542 errmsg ("tunnel dst address not specified");
9546 if (grp_set && !ip46_address_is_multicast (&dst))
9548 errmsg ("tunnel group address not multicast");
9551 if (grp_set && mcast_sw_if_index == ~0)
9553 errmsg ("tunnel nonexistent multicast device");
9556 if (grp_set == 0 && ip46_address_is_multicast (&dst))
9558 errmsg ("tunnel dst address must be unicast");
9563 if (ipv4_set && ipv6_set)
9565 errmsg ("both IPv4 and IPv6 addresses specified");
9569 if ((vni == 0) || (vni >> 24))
9571 errmsg ("vni not specified or out of range");
9575 M (VXLAN_ADD_DEL_TUNNEL, mp);
9579 clib_memcpy (mp->src_address.un.ip6, &src.ip6, sizeof (src.ip6));
9580 clib_memcpy (mp->dst_address.un.ip6, &dst.ip6, sizeof (dst.ip6));
9584 clib_memcpy (mp->src_address.un.ip4, &src.ip4, sizeof (src.ip4));
9585 clib_memcpy (mp->dst_address.un.ip4, &dst.ip4, sizeof (dst.ip4));
9587 mp->src_address.af = ipv6_set;
9588 mp->dst_address.af = ipv6_set;
9590 mp->instance = htonl (instance);
9591 mp->encap_vrf_id = ntohl (encap_vrf_id);
9592 mp->decap_next_index = ntohl (decap_next_index);
9593 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
9594 mp->vni = ntohl (vni);
9595 mp->is_add = is_add;
9602 static void vl_api_vxlan_tunnel_details_t_handler
9603 (vl_api_vxlan_tunnel_details_t * mp)
9605 vat_main_t *vam = &vat_main;
9606 ip46_address_t src =
9607 to_ip46 (mp->dst_address.af, (u8 *) & mp->dst_address.un);
9608 ip46_address_t dst =
9609 to_ip46 (mp->dst_address.af, (u8 *) & mp->src_address.un);
9611 print (vam->ofp, "%11d%11d%24U%24U%14d%18d%13d%19d",
9612 ntohl (mp->sw_if_index),
9613 ntohl (mp->instance),
9614 format_ip46_address, &src, IP46_TYPE_ANY,
9615 format_ip46_address, &dst, IP46_TYPE_ANY,
9616 ntohl (mp->encap_vrf_id),
9617 ntohl (mp->decap_next_index), ntohl (mp->vni),
9618 ntohl (mp->mcast_sw_if_index));
9621 static void vl_api_vxlan_tunnel_details_t_handler_json
9622 (vl_api_vxlan_tunnel_details_t * mp)
9624 vat_main_t *vam = &vat_main;
9625 vat_json_node_t *node = NULL;
9627 if (VAT_JSON_ARRAY != vam->json_tree.type)
9629 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9630 vat_json_init_array (&vam->json_tree);
9632 node = vat_json_array_add (&vam->json_tree);
9634 vat_json_init_object (node);
9635 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9637 vat_json_object_add_uint (node, "instance", ntohl (mp->instance));
9639 if (mp->src_address.af)
9641 struct in6_addr ip6;
9643 clib_memcpy (&ip6, mp->src_address.un.ip6, sizeof (ip6));
9644 vat_json_object_add_ip6 (node, "src_address", ip6);
9645 clib_memcpy (&ip6, mp->dst_address.un.ip6, sizeof (ip6));
9646 vat_json_object_add_ip6 (node, "dst_address", ip6);
9652 clib_memcpy (&ip4, mp->src_address.un.ip4, sizeof (ip4));
9653 vat_json_object_add_ip4 (node, "src_address", ip4);
9654 clib_memcpy (&ip4, mp->dst_address.un.ip4, sizeof (ip4));
9655 vat_json_object_add_ip4 (node, "dst_address", ip4);
9657 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
9658 vat_json_object_add_uint (node, "decap_next_index",
9659 ntohl (mp->decap_next_index));
9660 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
9661 vat_json_object_add_uint (node, "mcast_sw_if_index",
9662 ntohl (mp->mcast_sw_if_index));
9666 api_vxlan_tunnel_dump (vat_main_t * vam)
9668 unformat_input_t *i = vam->input;
9669 vl_api_vxlan_tunnel_dump_t *mp;
9670 vl_api_control_ping_t *mp_ping;
9672 u8 sw_if_index_set = 0;
9675 /* Parse args required to build the message */
9676 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9678 if (unformat (i, "sw_if_index %d", &sw_if_index))
9679 sw_if_index_set = 1;
9684 if (sw_if_index_set == 0)
9689 if (!vam->json_output)
9691 print (vam->ofp, "%11s%11s%24s%24s%14s%18s%13s%19s",
9692 "sw_if_index", "instance", "src_address", "dst_address",
9693 "encap_vrf_id", "decap_next_index", "vni", "mcast_sw_if_index");
9696 /* Get list of vxlan-tunnel interfaces */
9697 M (VXLAN_TUNNEL_DUMP, mp);
9699 mp->sw_if_index = htonl (sw_if_index);
9703 /* Use a control ping for synchronization */
9704 MPING (CONTROL_PING, mp_ping);
9712 api_gre_tunnel_add_del (vat_main_t * vam)
9714 unformat_input_t *line_input = vam->input;
9715 vl_api_address_t src = { }, dst =
9718 vl_api_gre_tunnel_add_del_t *mp;
9719 vl_api_gre_tunnel_type_t t_type;
9723 u32 outer_table_id = 0;
9728 t_type = GRE_API_TUNNEL_TYPE_L3;
9730 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9732 if (unformat (line_input, "del"))
9734 else if (unformat (line_input, "instance %d", &instance))
9736 else if (unformat (line_input, "src %U", unformat_vl_api_address, &src))
9740 else if (unformat (line_input, "dst %U", unformat_vl_api_address, &dst))
9744 else if (unformat (line_input, "outer-table-id %d", &outer_table_id))
9746 else if (unformat (line_input, "teb"))
9747 t_type = GRE_API_TUNNEL_TYPE_TEB;
9748 else if (unformat (line_input, "erspan %d", &session_id))
9749 t_type = GRE_API_TUNNEL_TYPE_ERSPAN;
9752 errmsg ("parse error '%U'", format_unformat_error, line_input);
9759 errmsg ("tunnel src address not specified");
9764 errmsg ("tunnel dst address not specified");
9768 M (GRE_TUNNEL_ADD_DEL, mp);
9770 clib_memcpy (&mp->tunnel.src, &src, sizeof (mp->tunnel.src));
9771 clib_memcpy (&mp->tunnel.dst, &dst, sizeof (mp->tunnel.dst));
9773 mp->tunnel.instance = htonl (instance);
9774 mp->tunnel.outer_table_id = htonl (outer_table_id);
9775 mp->is_add = is_add;
9776 mp->tunnel.session_id = htons ((u16) session_id);
9777 mp->tunnel.type = htonl (t_type);
9784 static void vl_api_gre_tunnel_details_t_handler
9785 (vl_api_gre_tunnel_details_t * mp)
9787 vat_main_t *vam = &vat_main;
9789 print (vam->ofp, "%11d%11d%24U%24U%13d%14d%12d",
9790 ntohl (mp->tunnel.sw_if_index),
9791 ntohl (mp->tunnel.instance),
9792 format_vl_api_address, &mp->tunnel.src,
9793 format_vl_api_address, &mp->tunnel.dst,
9794 mp->tunnel.type, ntohl (mp->tunnel.outer_table_id),
9795 ntohl (mp->tunnel.session_id));
9798 static void vl_api_gre_tunnel_details_t_handler_json
9799 (vl_api_gre_tunnel_details_t * mp)
9801 vat_main_t *vam = &vat_main;
9802 vat_json_node_t *node = NULL;
9804 if (VAT_JSON_ARRAY != vam->json_tree.type)
9806 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9807 vat_json_init_array (&vam->json_tree);
9809 node = vat_json_array_add (&vam->json_tree);
9811 vat_json_init_object (node);
9812 vat_json_object_add_uint (node, "sw_if_index",
9813 ntohl (mp->tunnel.sw_if_index));
9814 vat_json_object_add_uint (node, "instance", ntohl (mp->tunnel.instance));
9816 vat_json_object_add_address (node, "src", &mp->tunnel.src);
9817 vat_json_object_add_address (node, "dst", &mp->tunnel.dst);
9818 vat_json_object_add_uint (node, "tunnel_type", mp->tunnel.type);
9819 vat_json_object_add_uint (node, "outer_table_id",
9820 ntohl (mp->tunnel.outer_table_id));
9821 vat_json_object_add_uint (node, "session_id", mp->tunnel.session_id);
9825 api_gre_tunnel_dump (vat_main_t * vam)
9827 unformat_input_t *i = vam->input;
9828 vl_api_gre_tunnel_dump_t *mp;
9829 vl_api_control_ping_t *mp_ping;
9831 u8 sw_if_index_set = 0;
9834 /* Parse args required to build the message */
9835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9837 if (unformat (i, "sw_if_index %d", &sw_if_index))
9838 sw_if_index_set = 1;
9843 if (sw_if_index_set == 0)
9848 if (!vam->json_output)
9850 print (vam->ofp, "%11s%11s%24s%24s%13s%14s%12s",
9851 "sw_if_index", "instance", "src_address", "dst_address",
9852 "tunnel_type", "outer_fib_id", "session_id");
9855 /* Get list of gre-tunnel interfaces */
9856 M (GRE_TUNNEL_DUMP, mp);
9858 mp->sw_if_index = htonl (sw_if_index);
9862 /* Use a control ping for synchronization */
9863 MPING (CONTROL_PING, mp_ping);
9871 api_l2_fib_clear_table (vat_main_t * vam)
9873 // unformat_input_t * i = vam->input;
9874 vl_api_l2_fib_clear_table_t *mp;
9877 M (L2_FIB_CLEAR_TABLE, mp);
9885 api_l2_interface_efp_filter (vat_main_t * vam)
9887 unformat_input_t *i = vam->input;
9888 vl_api_l2_interface_efp_filter_t *mp;
9891 u8 sw_if_index_set = 0;
9894 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9896 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9897 sw_if_index_set = 1;
9898 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9899 sw_if_index_set = 1;
9900 else if (unformat (i, "enable"))
9902 else if (unformat (i, "disable"))
9906 clib_warning ("parse error '%U'", format_unformat_error, i);
9911 if (sw_if_index_set == 0)
9913 errmsg ("missing sw_if_index");
9917 M (L2_INTERFACE_EFP_FILTER, mp);
9919 mp->sw_if_index = ntohl (sw_if_index);
9920 mp->enable_disable = enable;
9927 #define foreach_vtr_op \
9928 _("disable", L2_VTR_DISABLED) \
9929 _("push-1", L2_VTR_PUSH_1) \
9930 _("push-2", L2_VTR_PUSH_2) \
9931 _("pop-1", L2_VTR_POP_1) \
9932 _("pop-2", L2_VTR_POP_2) \
9933 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
9934 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
9935 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
9936 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
9939 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
9941 unformat_input_t *i = vam->input;
9942 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
9944 u8 sw_if_index_set = 0;
9952 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9954 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9955 sw_if_index_set = 1;
9956 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9957 sw_if_index_set = 1;
9958 else if (unformat (i, "vtr_op %d", &vtr_op))
9960 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
9963 else if (unformat (i, "push_dot1q %d", &push_dot1q))
9965 else if (unformat (i, "tag1 %d", &tag1))
9967 else if (unformat (i, "tag2 %d", &tag2))
9971 clib_warning ("parse error '%U'", format_unformat_error, i);
9976 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
9978 errmsg ("missing vtr operation or sw_if_index");
9982 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
9983 mp->sw_if_index = ntohl (sw_if_index);
9984 mp->vtr_op = ntohl (vtr_op);
9985 mp->push_dot1q = ntohl (push_dot1q);
9986 mp->tag1 = ntohl (tag1);
9987 mp->tag2 = ntohl (tag2);
9995 api_create_vhost_user_if (vat_main_t * vam)
9997 unformat_input_t *i = vam->input;
9998 vl_api_create_vhost_user_if_t *mp;
10001 u8 file_name_set = 0;
10002 u32 custom_dev_instance = ~0;
10004 u8 use_custom_mac = 0;
10005 u8 disable_mrg_rxbuf = 0;
10006 u8 disable_indirect_desc = 0;
10009 u8 enable_packed = 0;
10012 /* Shut up coverity */
10013 clib_memset (hwaddr, 0, sizeof (hwaddr));
10015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10017 if (unformat (i, "socket %s", &file_name))
10021 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10023 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
10024 use_custom_mac = 1;
10025 else if (unformat (i, "server"))
10027 else if (unformat (i, "disable_mrg_rxbuf"))
10028 disable_mrg_rxbuf = 1;
10029 else if (unformat (i, "disable_indirect_desc"))
10030 disable_indirect_desc = 1;
10031 else if (unformat (i, "gso"))
10033 else if (unformat (i, "packed"))
10035 else if (unformat (i, "tag %s", &tag))
10041 if (file_name_set == 0)
10043 errmsg ("missing socket file name");
10047 if (vec_len (file_name) > 255)
10049 errmsg ("socket file name too long");
10052 vec_add1 (file_name, 0);
10054 M (CREATE_VHOST_USER_IF, mp);
10056 mp->is_server = is_server;
10057 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
10058 mp->disable_indirect_desc = disable_indirect_desc;
10059 mp->enable_gso = enable_gso;
10060 mp->enable_packed = enable_packed;
10061 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10062 vec_free (file_name);
10063 if (custom_dev_instance != ~0)
10066 mp->custom_dev_instance = ntohl (custom_dev_instance);
10069 mp->use_custom_mac = use_custom_mac;
10070 clib_memcpy (mp->mac_address, hwaddr, 6);
10072 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10081 api_modify_vhost_user_if (vat_main_t * vam)
10083 unformat_input_t *i = vam->input;
10084 vl_api_modify_vhost_user_if_t *mp;
10087 u8 file_name_set = 0;
10088 u32 custom_dev_instance = ~0;
10089 u8 sw_if_index_set = 0;
10090 u32 sw_if_index = (u32) ~ 0;
10092 u8 enable_packed = 0;
10095 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10097 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10098 sw_if_index_set = 1;
10099 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10100 sw_if_index_set = 1;
10101 else if (unformat (i, "socket %s", &file_name))
10105 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
10107 else if (unformat (i, "server"))
10109 else if (unformat (i, "gso"))
10111 else if (unformat (i, "packed"))
10117 if (sw_if_index_set == 0)
10119 errmsg ("missing sw_if_index or interface name");
10123 if (file_name_set == 0)
10125 errmsg ("missing socket file name");
10129 if (vec_len (file_name) > 255)
10131 errmsg ("socket file name too long");
10134 vec_add1 (file_name, 0);
10136 M (MODIFY_VHOST_USER_IF, mp);
10138 mp->sw_if_index = ntohl (sw_if_index);
10139 mp->is_server = is_server;
10140 mp->enable_gso = enable_gso;
10141 mp->enable_packed = enable_packed;
10142 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
10143 vec_free (file_name);
10144 if (custom_dev_instance != ~0)
10147 mp->custom_dev_instance = ntohl (custom_dev_instance);
10156 api_delete_vhost_user_if (vat_main_t * vam)
10158 unformat_input_t *i = vam->input;
10159 vl_api_delete_vhost_user_if_t *mp;
10160 u32 sw_if_index = ~0;
10161 u8 sw_if_index_set = 0;
10164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10166 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10167 sw_if_index_set = 1;
10168 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10169 sw_if_index_set = 1;
10174 if (sw_if_index_set == 0)
10176 errmsg ("missing sw_if_index or interface name");
10181 M (DELETE_VHOST_USER_IF, mp);
10183 mp->sw_if_index = ntohl (sw_if_index);
10190 static void vl_api_sw_interface_vhost_user_details_t_handler
10191 (vl_api_sw_interface_vhost_user_details_t * mp)
10193 vat_main_t *vam = &vat_main;
10197 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
10198 clib_net_to_host_u32
10199 (mp->features_last_32) <<
10202 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s",
10203 (char *) mp->interface_name,
10204 ntohl (mp->sw_if_index), ntohl (mp->virtio_net_hdr_sz),
10205 features, mp->is_server,
10206 ntohl (mp->num_regions), (char *) mp->sock_filename);
10207 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
10210 static void vl_api_sw_interface_vhost_user_details_t_handler_json
10211 (vl_api_sw_interface_vhost_user_details_t * mp)
10213 vat_main_t *vam = &vat_main;
10214 vat_json_node_t *node = NULL;
10216 if (VAT_JSON_ARRAY != vam->json_tree.type)
10218 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10219 vat_json_init_array (&vam->json_tree);
10221 node = vat_json_array_add (&vam->json_tree);
10223 vat_json_init_object (node);
10224 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10225 vat_json_object_add_string_copy (node, "interface_name",
10226 mp->interface_name);
10227 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
10228 ntohl (mp->virtio_net_hdr_sz));
10229 vat_json_object_add_uint (node, "features_first_32",
10230 clib_net_to_host_u32 (mp->features_first_32));
10231 vat_json_object_add_uint (node, "features_last_32",
10232 clib_net_to_host_u32 (mp->features_last_32));
10233 vat_json_object_add_uint (node, "is_server", mp->is_server);
10234 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
10235 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
10236 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
10240 api_sw_interface_vhost_user_dump (vat_main_t * vam)
10242 unformat_input_t *i = vam->input;
10243 vl_api_sw_interface_vhost_user_dump_t *mp;
10244 vl_api_control_ping_t *mp_ping;
10246 u32 sw_if_index = ~0;
10248 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10250 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10252 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10259 "Interface name idx hdr_sz features server regions filename");
10261 /* Get list of vhost-user interfaces */
10262 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
10263 mp->sw_if_index = ntohl (sw_if_index);
10266 /* Use a control ping for synchronization */
10267 MPING (CONTROL_PING, mp_ping);
10275 api_show_version (vat_main_t * vam)
10277 vl_api_show_version_t *mp;
10280 M (SHOW_VERSION, mp);
10289 api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
10291 unformat_input_t *line_input = vam->input;
10292 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
10293 ip46_address_t local, remote;
10298 u32 mcast_sw_if_index = ~0;
10299 u32 encap_vrf_id = 0;
10300 u32 decap_vrf_id = 0;
10306 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10308 if (unformat (line_input, "del"))
10310 else if (unformat (line_input, "local %U",
10311 unformat_ip46_address, &local))
10315 else if (unformat (line_input, "remote %U",
10316 unformat_ip46_address, &remote))
10320 else if (unformat (line_input, "group %U %U",
10321 unformat_ip46_address, &remote,
10322 api_unformat_sw_if_index, vam, &mcast_sw_if_index))
10324 grp_set = remote_set = 1;
10326 else if (unformat (line_input, "group %U",
10327 unformat_ip46_address, &remote))
10329 grp_set = remote_set = 1;
10332 if (unformat (line_input, "mcast_sw_if_index %u", &mcast_sw_if_index))
10334 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
10336 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
10338 else if (unformat (line_input, "vni %d", &vni))
10340 else if (unformat (line_input, "next-ip4"))
10342 else if (unformat (line_input, "next-ip6"))
10344 else if (unformat (line_input, "next-ethernet"))
10346 else if (unformat (line_input, "next-nsh"))
10350 errmsg ("parse error '%U'", format_unformat_error, line_input);
10355 if (local_set == 0)
10357 errmsg ("tunnel local address not specified");
10360 if (remote_set == 0)
10362 errmsg ("tunnel remote address not specified");
10365 if (grp_set && mcast_sw_if_index == ~0)
10367 errmsg ("tunnel nonexistent multicast device");
10370 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
10372 errmsg ("both IPv4 and IPv6 addresses specified");
10378 errmsg ("vni not specified");
10382 M (VXLAN_GPE_ADD_DEL_TUNNEL, mp);
10384 ip_address_encode (&local,
10385 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
10386 IP46_TYPE_IP6, &mp->local);
10387 ip_address_encode (&remote,
10388 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
10389 IP46_TYPE_IP6, &mp->remote);
10391 mp->mcast_sw_if_index = ntohl (mcast_sw_if_index);
10392 mp->encap_vrf_id = ntohl (encap_vrf_id);
10393 mp->decap_vrf_id = ntohl (decap_vrf_id);
10394 mp->protocol = protocol;
10395 mp->vni = ntohl (vni);
10396 mp->is_add = is_add;
10403 static void vl_api_vxlan_gpe_tunnel_details_t_handler
10404 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10406 vat_main_t *vam = &vat_main;
10407 ip46_address_t local, remote;
10409 ip_address_decode (&mp->local, &local);
10410 ip_address_decode (&mp->remote, &remote);
10412 print (vam->ofp, "%11d%24U%24U%13d%12d%19d%14d%14d",
10413 ntohl (mp->sw_if_index),
10414 format_ip46_address, &local, IP46_TYPE_ANY,
10415 format_ip46_address, &remote, IP46_TYPE_ANY,
10416 ntohl (mp->vni), mp->protocol,
10417 ntohl (mp->mcast_sw_if_index),
10418 ntohl (mp->encap_vrf_id), ntohl (mp->decap_vrf_id));
10422 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
10423 (vl_api_vxlan_gpe_tunnel_details_t * mp)
10425 vat_main_t *vam = &vat_main;
10426 vat_json_node_t *node = NULL;
10427 struct in_addr ip4;
10428 struct in6_addr ip6;
10429 ip46_address_t local, remote;
10431 ip_address_decode (&mp->local, &local);
10432 ip_address_decode (&mp->remote, &remote);
10434 if (VAT_JSON_ARRAY != vam->json_tree.type)
10436 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10437 vat_json_init_array (&vam->json_tree);
10439 node = vat_json_array_add (&vam->json_tree);
10441 vat_json_init_object (node);
10442 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10443 if (ip46_address_is_ip4 (&local))
10445 clib_memcpy (&ip4, &local.ip4, sizeof (ip4));
10446 vat_json_object_add_ip4 (node, "local", ip4);
10447 clib_memcpy (&ip4, &remote.ip4, sizeof (ip4));
10448 vat_json_object_add_ip4 (node, "remote", ip4);
10452 clib_memcpy (&ip6, &local.ip6, sizeof (ip6));
10453 vat_json_object_add_ip6 (node, "local", ip6);
10454 clib_memcpy (&ip6, &remote.ip6, sizeof (ip6));
10455 vat_json_object_add_ip6 (node, "remote", ip6);
10457 vat_json_object_add_uint (node, "vni", ntohl (mp->vni));
10458 vat_json_object_add_uint (node, "protocol", ntohl (mp->protocol));
10459 vat_json_object_add_uint (node, "mcast_sw_if_index",
10460 ntohl (mp->mcast_sw_if_index));
10461 vat_json_object_add_uint (node, "encap_vrf_id", ntohl (mp->encap_vrf_id));
10462 vat_json_object_add_uint (node, "decap_vrf_id", ntohl (mp->decap_vrf_id));
10463 vat_json_object_add_uint (node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
10467 api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
10469 unformat_input_t *i = vam->input;
10470 vl_api_vxlan_gpe_tunnel_dump_t *mp;
10471 vl_api_control_ping_t *mp_ping;
10473 u8 sw_if_index_set = 0;
10476 /* Parse args required to build the message */
10477 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10479 if (unformat (i, "sw_if_index %d", &sw_if_index))
10480 sw_if_index_set = 1;
10485 if (sw_if_index_set == 0)
10490 if (!vam->json_output)
10492 print (vam->ofp, "%11s%24s%24s%13s%15s%19s%14s%14s",
10493 "sw_if_index", "local", "remote", "vni",
10494 "protocol", "mcast_sw_if_index", "encap_vrf_id", "decap_vrf_id");
10497 /* Get list of vxlan-tunnel interfaces */
10498 M (VXLAN_GPE_TUNNEL_DUMP, mp);
10500 mp->sw_if_index = htonl (sw_if_index);
10504 /* Use a control ping for synchronization */
10505 MPING (CONTROL_PING, mp_ping);
10512 static void vl_api_l2_fib_table_details_t_handler
10513 (vl_api_l2_fib_table_details_t * mp)
10515 vat_main_t *vam = &vat_main;
10517 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
10519 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
10520 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
10524 static void vl_api_l2_fib_table_details_t_handler_json
10525 (vl_api_l2_fib_table_details_t * mp)
10527 vat_main_t *vam = &vat_main;
10528 vat_json_node_t *node = NULL;
10530 if (VAT_JSON_ARRAY != vam->json_tree.type)
10532 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10533 vat_json_init_array (&vam->json_tree);
10535 node = vat_json_array_add (&vam->json_tree);
10537 vat_json_init_object (node);
10538 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
10539 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
10540 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
10541 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
10542 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
10543 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
10547 api_l2_fib_table_dump (vat_main_t * vam)
10549 unformat_input_t *i = vam->input;
10550 vl_api_l2_fib_table_dump_t *mp;
10551 vl_api_control_ping_t *mp_ping;
10556 /* Parse args required to build the message */
10557 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10559 if (unformat (i, "bd_id %d", &bd_id))
10565 if (bd_id_set == 0)
10567 errmsg ("missing bridge domain");
10571 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
10573 /* Get list of l2 fib entries */
10574 M (L2_FIB_TABLE_DUMP, mp);
10576 mp->bd_id = ntohl (bd_id);
10579 /* Use a control ping for synchronization */
10580 MPING (CONTROL_PING, mp_ping);
10589 api_interface_name_renumber (vat_main_t * vam)
10591 unformat_input_t *line_input = vam->input;
10592 vl_api_interface_name_renumber_t *mp;
10593 u32 sw_if_index = ~0;
10594 u32 new_show_dev_instance = ~0;
10597 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10599 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
10602 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10604 else if (unformat (line_input, "new_show_dev_instance %d",
10605 &new_show_dev_instance))
10611 if (sw_if_index == ~0)
10613 errmsg ("missing interface name or sw_if_index");
10617 if (new_show_dev_instance == ~0)
10619 errmsg ("missing new_show_dev_instance");
10623 M (INTERFACE_NAME_RENUMBER, mp);
10625 mp->sw_if_index = ntohl (sw_if_index);
10626 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
10634 api_want_l2_macs_events (vat_main_t * vam)
10636 unformat_input_t *line_input = vam->input;
10637 vl_api_want_l2_macs_events_t *mp;
10638 u8 enable_disable = 1;
10639 u32 scan_delay = 0;
10640 u32 max_macs_in_event = 0;
10641 u32 learn_limit = 0;
10644 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
10646 if (unformat (line_input, "learn-limit %d", &learn_limit))
10648 else if (unformat (line_input, "scan-delay %d", &scan_delay))
10650 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
10652 else if (unformat (line_input, "disable"))
10653 enable_disable = 0;
10658 M (WANT_L2_MACS_EVENTS, mp);
10659 mp->enable_disable = enable_disable;
10660 mp->pid = htonl (getpid ());
10661 mp->learn_limit = htonl (learn_limit);
10662 mp->scan_delay = (u8) scan_delay;
10663 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
10670 api_input_acl_set_interface (vat_main_t * vam)
10672 unformat_input_t *i = vam->input;
10673 vl_api_input_acl_set_interface_t *mp;
10675 int sw_if_index_set;
10676 u32 ip4_table_index = ~0;
10677 u32 ip6_table_index = ~0;
10678 u32 l2_table_index = ~0;
10682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10684 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10685 sw_if_index_set = 1;
10686 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10687 sw_if_index_set = 1;
10688 else if (unformat (i, "del"))
10690 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10692 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10694 else if (unformat (i, "l2-table %d", &l2_table_index))
10698 clib_warning ("parse error '%U'", format_unformat_error, i);
10703 if (sw_if_index_set == 0)
10705 errmsg ("missing interface name or sw_if_index");
10709 M (INPUT_ACL_SET_INTERFACE, mp);
10711 mp->sw_if_index = ntohl (sw_if_index);
10712 mp->ip4_table_index = ntohl (ip4_table_index);
10713 mp->ip6_table_index = ntohl (ip6_table_index);
10714 mp->l2_table_index = ntohl (l2_table_index);
10715 mp->is_add = is_add;
10723 api_output_acl_set_interface (vat_main_t * vam)
10725 unformat_input_t *i = vam->input;
10726 vl_api_output_acl_set_interface_t *mp;
10728 int sw_if_index_set;
10729 u32 ip4_table_index = ~0;
10730 u32 ip6_table_index = ~0;
10731 u32 l2_table_index = ~0;
10735 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10737 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10738 sw_if_index_set = 1;
10739 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10740 sw_if_index_set = 1;
10741 else if (unformat (i, "del"))
10743 else if (unformat (i, "ip4-table %d", &ip4_table_index))
10745 else if (unformat (i, "ip6-table %d", &ip6_table_index))
10747 else if (unformat (i, "l2-table %d", &l2_table_index))
10751 clib_warning ("parse error '%U'", format_unformat_error, i);
10756 if (sw_if_index_set == 0)
10758 errmsg ("missing interface name or sw_if_index");
10762 M (OUTPUT_ACL_SET_INTERFACE, mp);
10764 mp->sw_if_index = ntohl (sw_if_index);
10765 mp->ip4_table_index = ntohl (ip4_table_index);
10766 mp->ip6_table_index = ntohl (ip6_table_index);
10767 mp->l2_table_index = ntohl (l2_table_index);
10768 mp->is_add = is_add;
10776 api_ip_address_dump (vat_main_t * vam)
10778 unformat_input_t *i = vam->input;
10779 vl_api_ip_address_dump_t *mp;
10780 vl_api_control_ping_t *mp_ping;
10781 u32 sw_if_index = ~0;
10782 u8 sw_if_index_set = 0;
10787 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10789 if (unformat (i, "sw_if_index %d", &sw_if_index))
10790 sw_if_index_set = 1;
10792 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10793 sw_if_index_set = 1;
10794 else if (unformat (i, "ipv4"))
10796 else if (unformat (i, "ipv6"))
10802 if (ipv4_set && ipv6_set)
10804 errmsg ("ipv4 and ipv6 flags cannot be both set");
10808 if ((!ipv4_set) && (!ipv6_set))
10810 errmsg ("no ipv4 nor ipv6 flag set");
10814 if (sw_if_index_set == 0)
10816 errmsg ("missing interface name or sw_if_index");
10820 vam->current_sw_if_index = sw_if_index;
10821 vam->is_ipv6 = ipv6_set;
10823 M (IP_ADDRESS_DUMP, mp);
10824 mp->sw_if_index = ntohl (sw_if_index);
10825 mp->is_ipv6 = ipv6_set;
10828 /* Use a control ping for synchronization */
10829 MPING (CONTROL_PING, mp_ping);
10837 api_ip_dump (vat_main_t * vam)
10839 vl_api_ip_dump_t *mp;
10840 vl_api_control_ping_t *mp_ping;
10841 unformat_input_t *in = vam->input;
10848 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
10850 if (unformat (in, "ipv4"))
10852 else if (unformat (in, "ipv6"))
10858 if (ipv4_set && ipv6_set)
10860 errmsg ("ipv4 and ipv6 flags cannot be both set");
10864 if ((!ipv4_set) && (!ipv6_set))
10866 errmsg ("no ipv4 nor ipv6 flag set");
10870 is_ipv6 = ipv6_set;
10871 vam->is_ipv6 = is_ipv6;
10873 /* free old data */
10874 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
10876 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
10878 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
10881 mp->is_ipv6 = ipv6_set;
10884 /* Use a control ping for synchronization */
10885 MPING (CONTROL_PING, mp_ping);
10893 api_ipsec_spd_add_del (vat_main_t * vam)
10895 unformat_input_t *i = vam->input;
10896 vl_api_ipsec_spd_add_del_t *mp;
10901 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10903 if (unformat (i, "spd_id %d", &spd_id))
10905 else if (unformat (i, "del"))
10909 clib_warning ("parse error '%U'", format_unformat_error, i);
10915 errmsg ("spd_id must be set");
10919 M (IPSEC_SPD_ADD_DEL, mp);
10921 mp->spd_id = ntohl (spd_id);
10922 mp->is_add = is_add;
10930 api_ipsec_interface_add_del_spd (vat_main_t * vam)
10932 unformat_input_t *i = vam->input;
10933 vl_api_ipsec_interface_add_del_spd_t *mp;
10935 u8 sw_if_index_set = 0;
10936 u32 spd_id = (u32) ~ 0;
10940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10942 if (unformat (i, "del"))
10944 else if (unformat (i, "spd_id %d", &spd_id))
10947 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10948 sw_if_index_set = 1;
10949 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10950 sw_if_index_set = 1;
10953 clib_warning ("parse error '%U'", format_unformat_error, i);
10959 if (spd_id == (u32) ~ 0)
10961 errmsg ("spd_id must be set");
10965 if (sw_if_index_set == 0)
10967 errmsg ("missing interface name or sw_if_index");
10971 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
10973 mp->spd_id = ntohl (spd_id);
10974 mp->sw_if_index = ntohl (sw_if_index);
10975 mp->is_add = is_add;
10983 api_ipsec_spd_entry_add_del (vat_main_t * vam)
10985 unformat_input_t *i = vam->input;
10986 vl_api_ipsec_spd_entry_add_del_t *mp;
10987 u8 is_add = 1, is_outbound = 0;
10988 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
10990 u32 rport_start = 0, rport_stop = (u32) ~ 0;
10991 u32 lport_start = 0, lport_stop = (u32) ~ 0;
10992 vl_api_address_t laddr_start = { }, laddr_stop =
11001 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11003 if (unformat (i, "del"))
11005 if (unformat (i, "outbound"))
11007 if (unformat (i, "inbound"))
11009 else if (unformat (i, "spd_id %d", &spd_id))
11011 else if (unformat (i, "sa_id %d", &sa_id))
11013 else if (unformat (i, "priority %d", &priority))
11015 else if (unformat (i, "protocol %d", &protocol))
11017 else if (unformat (i, "lport_start %d", &lport_start))
11019 else if (unformat (i, "lport_stop %d", &lport_stop))
11021 else if (unformat (i, "rport_start %d", &rport_start))
11023 else if (unformat (i, "rport_stop %d", &rport_stop))
11025 else if (unformat (i, "laddr_start %U",
11026 unformat_vl_api_address, &laddr_start))
11028 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
11031 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
11034 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
11038 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
11040 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
11042 clib_warning ("unsupported action: 'resolve'");
11048 clib_warning ("parse error '%U'", format_unformat_error, i);
11054 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
11056 mp->is_add = is_add;
11058 mp->entry.spd_id = ntohl (spd_id);
11059 mp->entry.priority = ntohl (priority);
11060 mp->entry.is_outbound = is_outbound;
11062 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
11063 sizeof (vl_api_address_t));
11064 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
11065 sizeof (vl_api_address_t));
11066 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
11067 sizeof (vl_api_address_t));
11068 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
11069 sizeof (vl_api_address_t));
11071 mp->entry.protocol = (u8) protocol;
11072 mp->entry.local_port_start = ntohs ((u16) lport_start);
11073 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
11074 mp->entry.remote_port_start = ntohs ((u16) rport_start);
11075 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
11076 mp->entry.policy = (u8) policy;
11077 mp->entry.sa_id = ntohl (sa_id);
11085 api_ipsec_sad_entry_add_del (vat_main_t * vam)
11087 unformat_input_t *i = vam->input;
11088 vl_api_ipsec_sad_entry_add_del_t *mp;
11089 u32 sad_id = 0, spi = 0;
11090 u8 *ck = 0, *ik = 0;
11093 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
11094 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
11095 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
11096 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
11097 vl_api_address_t tun_src, tun_dst;
11100 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11102 if (unformat (i, "del"))
11104 else if (unformat (i, "sad_id %d", &sad_id))
11106 else if (unformat (i, "spi %d", &spi))
11108 else if (unformat (i, "esp"))
11109 protocol = IPSEC_API_PROTO_ESP;
11111 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
11113 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11114 if (ADDRESS_IP6 == tun_src.af)
11115 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11118 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
11120 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
11121 if (ADDRESS_IP6 == tun_src.af)
11122 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
11125 if (unformat (i, "crypto_alg %U",
11126 unformat_ipsec_api_crypto_alg, &crypto_alg))
11128 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
11130 else if (unformat (i, "integ_alg %U",
11131 unformat_ipsec_api_integ_alg, &integ_alg))
11133 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
11137 clib_warning ("parse error '%U'", format_unformat_error, i);
11143 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
11145 mp->is_add = is_add;
11146 mp->entry.sad_id = ntohl (sad_id);
11147 mp->entry.protocol = protocol;
11148 mp->entry.spi = ntohl (spi);
11149 mp->entry.flags = flags;
11151 mp->entry.crypto_algorithm = crypto_alg;
11152 mp->entry.integrity_algorithm = integ_alg;
11153 mp->entry.crypto_key.length = vec_len (ck);
11154 mp->entry.integrity_key.length = vec_len (ik);
11156 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
11157 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
11159 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
11160 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
11163 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
11165 clib_memcpy (mp->entry.integrity_key.data, ik,
11166 mp->entry.integrity_key.length);
11168 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
11170 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
11171 sizeof (mp->entry.tunnel_src));
11172 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
11173 sizeof (mp->entry.tunnel_dst));
11182 api_ipsec_tunnel_if_add_del (vat_main_t * vam)
11184 unformat_input_t *i = vam->input;
11185 vl_api_ipsec_tunnel_if_add_del_t *mp;
11186 u32 local_spi = 0, remote_spi = 0;
11187 u32 crypto_alg = 0, integ_alg = 0;
11188 u8 *lck = NULL, *rck = NULL;
11189 u8 *lik = NULL, *rik = NULL;
11190 vl_api_address_t local_ip = { 0 };
11191 vl_api_address_t remote_ip = { 0 };
11195 u8 anti_replay = 0;
11201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11203 if (unformat (i, "del"))
11205 else if (unformat (i, "esn"))
11207 else if (unformat (i, "anti-replay"))
11209 else if (unformat (i, "count %d", &count))
11211 else if (unformat (i, "local_spi %d", &local_spi))
11213 else if (unformat (i, "remote_spi %d", &remote_spi))
11216 if (unformat (i, "local_ip %U", unformat_vl_api_address, &local_ip))
11219 if (unformat (i, "remote_ip %U", unformat_vl_api_address, &remote_ip))
11221 else if (unformat (i, "local_crypto_key %U", unformat_hex_string, &lck))
11224 if (unformat (i, "remote_crypto_key %U", unformat_hex_string, &rck))
11226 else if (unformat (i, "local_integ_key %U", unformat_hex_string, &lik))
11228 else if (unformat (i, "remote_integ_key %U", unformat_hex_string, &rik))
11232 (i, "crypto_alg %U", unformat_ipsec_api_crypto_alg, &crypto_alg))
11234 if (crypto_alg >= IPSEC_CRYPTO_N_ALG)
11236 errmsg ("unsupported crypto-alg: '%U'\n",
11237 format_ipsec_crypto_alg, crypto_alg);
11243 (i, "integ_alg %U", unformat_ipsec_api_integ_alg, &integ_alg))
11245 if (integ_alg >= IPSEC_INTEG_N_ALG)
11247 errmsg ("unsupported integ-alg: '%U'\n",
11248 format_ipsec_integ_alg, integ_alg);
11252 else if (unformat (i, "instance %u", &instance))
11256 errmsg ("parse error '%U'\n", format_unformat_error, i);
11263 /* Turn on async mode */
11264 vam->async_mode = 1;
11265 vam->async_errors = 0;
11266 before = vat_time_now (vam);
11269 for (jj = 0; jj < count; jj++)
11271 M (IPSEC_TUNNEL_IF_ADD_DEL, mp);
11273 mp->is_add = is_add;
11275 mp->anti_replay = anti_replay;
11278 increment_address (&remote_ip);
11280 clib_memcpy (&mp->local_ip, &local_ip, sizeof (local_ip));
11281 clib_memcpy (&mp->remote_ip, &remote_ip, sizeof (remote_ip));
11283 mp->local_spi = htonl (local_spi + jj);
11284 mp->remote_spi = htonl (remote_spi + jj);
11285 mp->crypto_alg = (u8) crypto_alg;
11287 mp->local_crypto_key_len = 0;
11290 mp->local_crypto_key_len = vec_len (lck);
11291 if (mp->local_crypto_key_len > sizeof (mp->local_crypto_key))
11292 mp->local_crypto_key_len = sizeof (mp->local_crypto_key);
11293 clib_memcpy (mp->local_crypto_key, lck, mp->local_crypto_key_len);
11296 mp->remote_crypto_key_len = 0;
11299 mp->remote_crypto_key_len = vec_len (rck);
11300 if (mp->remote_crypto_key_len > sizeof (mp->remote_crypto_key))
11301 mp->remote_crypto_key_len = sizeof (mp->remote_crypto_key);
11302 clib_memcpy (mp->remote_crypto_key, rck, mp->remote_crypto_key_len);
11305 mp->integ_alg = (u8) integ_alg;
11307 mp->local_integ_key_len = 0;
11310 mp->local_integ_key_len = vec_len (lik);
11311 if (mp->local_integ_key_len > sizeof (mp->local_integ_key))
11312 mp->local_integ_key_len = sizeof (mp->local_integ_key);
11313 clib_memcpy (mp->local_integ_key, lik, mp->local_integ_key_len);
11316 mp->remote_integ_key_len = 0;
11319 mp->remote_integ_key_len = vec_len (rik);
11320 if (mp->remote_integ_key_len > sizeof (mp->remote_integ_key))
11321 mp->remote_integ_key_len = sizeof (mp->remote_integ_key);
11322 clib_memcpy (mp->remote_integ_key, rik, mp->remote_integ_key_len);
11327 mp->renumber = renumber;
11328 mp->show_instance = ntohl (instance);
11333 /* When testing multiple add/del ops, use a control-ping to sync */
11336 vl_api_control_ping_t *mp_ping;
11340 /* Shut off async mode */
11341 vam->async_mode = 0;
11343 MPING (CONTROL_PING, mp_ping);
11346 timeout = vat_time_now (vam) + 1.0;
11347 while (vat_time_now (vam) < timeout)
11348 if (vam->result_ready == 1)
11353 if (vam->retval == -99)
11354 errmsg ("timeout");
11356 if (vam->async_errors > 0)
11358 errmsg ("%d asynchronous errors", vam->async_errors);
11361 vam->async_errors = 0;
11362 after = vat_time_now (vam);
11364 /* slim chance, but we might have eaten SIGTERM on the first iteration */
11368 print (vam->ofp, "%d tunnels in %.6f secs, %.2f tunnels/sec",
11369 count, after - before, count / (after - before));
11373 /* Wait for a reply... */
11382 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
11384 vat_main_t *vam = &vat_main;
11386 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
11387 "crypto_key %U integ_alg %u integ_key %U flags %x "
11388 "tunnel_src_addr %U tunnel_dst_addr %U "
11389 "salt %u seq_outbound %lu last_seq_inbound %lu "
11390 "replay_window %lu stat_index %u\n",
11391 ntohl (mp->entry.sad_id),
11392 ntohl (mp->sw_if_index),
11393 ntohl (mp->entry.spi),
11394 ntohl (mp->entry.protocol),
11395 ntohl (mp->entry.crypto_algorithm),
11396 format_hex_bytes, mp->entry.crypto_key.data,
11397 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
11398 format_hex_bytes, mp->entry.integrity_key.data,
11399 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
11400 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
11401 &mp->entry.tunnel_dst, ntohl (mp->salt),
11402 clib_net_to_host_u64 (mp->seq_outbound),
11403 clib_net_to_host_u64 (mp->last_seq_inbound),
11404 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
11407 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
11408 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
11410 static void vl_api_ipsec_sa_details_t_handler_json
11411 (vl_api_ipsec_sa_details_t * mp)
11413 vat_main_t *vam = &vat_main;
11414 vat_json_node_t *node = NULL;
11415 vl_api_ipsec_sad_flags_t flags;
11417 if (VAT_JSON_ARRAY != vam->json_tree.type)
11419 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11420 vat_json_init_array (&vam->json_tree);
11422 node = vat_json_array_add (&vam->json_tree);
11424 vat_json_init_object (node);
11425 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
11426 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11427 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
11428 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
11429 vat_json_object_add_uint (node, "crypto_alg",
11430 ntohl (mp->entry.crypto_algorithm));
11431 vat_json_object_add_uint (node, "integ_alg",
11432 ntohl (mp->entry.integrity_algorithm));
11433 flags = ntohl (mp->entry.flags);
11434 vat_json_object_add_uint (node, "use_esn",
11435 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
11436 vat_json_object_add_uint (node, "use_anti_replay",
11437 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
11438 vat_json_object_add_uint (node, "is_tunnel",
11439 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
11440 vat_json_object_add_uint (node, "is_tunnel_ip6",
11441 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
11442 vat_json_object_add_uint (node, "udp_encap",
11443 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
11444 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
11445 mp->entry.crypto_key.length);
11446 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
11447 mp->entry.integrity_key.length);
11448 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
11449 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
11450 vat_json_object_add_uint (node, "replay_window",
11451 clib_net_to_host_u64 (mp->replay_window));
11452 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
11456 api_ipsec_sa_dump (vat_main_t * vam)
11458 unformat_input_t *i = vam->input;
11459 vl_api_ipsec_sa_dump_t *mp;
11460 vl_api_control_ping_t *mp_ping;
11464 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11466 if (unformat (i, "sa_id %d", &sa_id))
11470 clib_warning ("parse error '%U'", format_unformat_error, i);
11475 M (IPSEC_SA_DUMP, mp);
11477 mp->sa_id = ntohl (sa_id);
11481 /* Use a control ping for synchronization */
11482 M (CONTROL_PING, mp_ping);
11490 api_ipsec_tunnel_if_set_sa (vat_main_t * vam)
11492 unformat_input_t *i = vam->input;
11493 vl_api_ipsec_tunnel_if_set_sa_t *mp;
11494 u32 sw_if_index = ~0;
11496 u8 is_outbound = (u8) ~ 0;
11499 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11501 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11503 else if (unformat (i, "sa_id %d", &sa_id))
11505 else if (unformat (i, "outbound"))
11507 else if (unformat (i, "inbound"))
11511 clib_warning ("parse error '%U'", format_unformat_error, i);
11516 if (sw_if_index == ~0)
11518 errmsg ("interface must be specified");
11524 errmsg ("SA ID must be specified");
11528 M (IPSEC_TUNNEL_IF_SET_SA, mp);
11530 mp->sw_if_index = htonl (sw_if_index);
11531 mp->sa_id = htonl (sa_id);
11532 mp->is_outbound = is_outbound;
11541 api_get_first_msg_id (vat_main_t * vam)
11543 vl_api_get_first_msg_id_t *mp;
11544 unformat_input_t *i = vam->input;
11549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11551 if (unformat (i, "client %s", &name))
11559 errmsg ("missing client name");
11562 vec_add1 (name, 0);
11564 if (vec_len (name) > 63)
11566 errmsg ("client name too long");
11570 M (GET_FIRST_MSG_ID, mp);
11571 clib_memcpy (mp->name, name, vec_len (name));
11578 api_cop_interface_enable_disable (vat_main_t * vam)
11580 unformat_input_t *line_input = vam->input;
11581 vl_api_cop_interface_enable_disable_t *mp;
11582 u32 sw_if_index = ~0;
11583 u8 enable_disable = 1;
11586 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11588 if (unformat (line_input, "disable"))
11589 enable_disable = 0;
11590 if (unformat (line_input, "enable"))
11591 enable_disable = 1;
11592 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11593 vam, &sw_if_index))
11595 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11601 if (sw_if_index == ~0)
11603 errmsg ("missing interface name or sw_if_index");
11607 /* Construct the API message */
11608 M (COP_INTERFACE_ENABLE_DISABLE, mp);
11609 mp->sw_if_index = ntohl (sw_if_index);
11610 mp->enable_disable = enable_disable;
11614 /* Wait for the reply */
11620 api_cop_whitelist_enable_disable (vat_main_t * vam)
11622 unformat_input_t *line_input = vam->input;
11623 vl_api_cop_whitelist_enable_disable_t *mp;
11624 u32 sw_if_index = ~0;
11625 u8 ip4 = 0, ip6 = 0, default_cop = 0;
11629 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11631 if (unformat (line_input, "ip4"))
11633 else if (unformat (line_input, "ip6"))
11635 else if (unformat (line_input, "default"))
11637 else if (unformat (line_input, "%U", api_unformat_sw_if_index,
11638 vam, &sw_if_index))
11640 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
11642 else if (unformat (line_input, "fib-id %d", &fib_id))
11648 if (sw_if_index == ~0)
11650 errmsg ("missing interface name or sw_if_index");
11654 /* Construct the API message */
11655 M (COP_WHITELIST_ENABLE_DISABLE, mp);
11656 mp->sw_if_index = ntohl (sw_if_index);
11657 mp->fib_id = ntohl (fib_id);
11660 mp->default_cop = default_cop;
11664 /* Wait for the reply */
11670 api_get_node_graph (vat_main_t * vam)
11672 vl_api_get_node_graph_t *mp;
11675 M (GET_NODE_GRAPH, mp);
11679 /* Wait for the reply */
11685 api_af_packet_create (vat_main_t * vam)
11687 unformat_input_t *i = vam->input;
11688 vl_api_af_packet_create_t *mp;
11689 u8 *host_if_name = 0;
11691 u8 random_hw_addr = 1;
11694 clib_memset (hw_addr, 0, sizeof (hw_addr));
11696 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11698 if (unformat (i, "name %s", &host_if_name))
11699 vec_add1 (host_if_name, 0);
11700 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11701 random_hw_addr = 0;
11706 if (!vec_len (host_if_name))
11708 errmsg ("host-interface name must be specified");
11712 if (vec_len (host_if_name) > 64)
11714 errmsg ("host-interface name too long");
11718 M (AF_PACKET_CREATE, mp);
11720 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11721 clib_memcpy (mp->hw_addr, hw_addr, 6);
11722 mp->use_random_hw_addr = random_hw_addr;
11723 vec_free (host_if_name);
11731 fprintf (vam->ofp ? vam->ofp : stderr,
11732 " new sw_if_index = %d\n", vam->sw_if_index);
11739 api_af_packet_delete (vat_main_t * vam)
11741 unformat_input_t *i = vam->input;
11742 vl_api_af_packet_delete_t *mp;
11743 u8 *host_if_name = 0;
11746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11748 if (unformat (i, "name %s", &host_if_name))
11749 vec_add1 (host_if_name, 0);
11754 if (!vec_len (host_if_name))
11756 errmsg ("host-interface name must be specified");
11760 if (vec_len (host_if_name) > 64)
11762 errmsg ("host-interface name too long");
11766 M (AF_PACKET_DELETE, mp);
11768 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11769 vec_free (host_if_name);
11776 static void vl_api_af_packet_details_t_handler
11777 (vl_api_af_packet_details_t * mp)
11779 vat_main_t *vam = &vat_main;
11781 print (vam->ofp, "%-16s %d",
11782 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
11785 static void vl_api_af_packet_details_t_handler_json
11786 (vl_api_af_packet_details_t * mp)
11788 vat_main_t *vam = &vat_main;
11789 vat_json_node_t *node = NULL;
11791 if (VAT_JSON_ARRAY != vam->json_tree.type)
11793 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11794 vat_json_init_array (&vam->json_tree);
11796 node = vat_json_array_add (&vam->json_tree);
11798 vat_json_init_object (node);
11799 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
11800 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
11804 api_af_packet_dump (vat_main_t * vam)
11806 vl_api_af_packet_dump_t *mp;
11807 vl_api_control_ping_t *mp_ping;
11810 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
11811 /* Get list of tap interfaces */
11812 M (AF_PACKET_DUMP, mp);
11815 /* Use a control ping for synchronization */
11816 MPING (CONTROL_PING, mp_ping);
11824 api_policer_add_del (vat_main_t * vam)
11826 unformat_input_t *i = vam->input;
11827 vl_api_policer_add_del_t *mp;
11837 u8 color_aware = 0;
11838 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
11841 conform_action.action_type = SSE2_QOS_ACTION_TRANSMIT;
11842 conform_action.dscp = 0;
11843 exceed_action.action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
11844 exceed_action.dscp = 0;
11845 violate_action.action_type = SSE2_QOS_ACTION_DROP;
11846 violate_action.dscp = 0;
11848 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11850 if (unformat (i, "del"))
11852 else if (unformat (i, "name %s", &name))
11853 vec_add1 (name, 0);
11854 else if (unformat (i, "cir %u", &cir))
11856 else if (unformat (i, "eir %u", &eir))
11858 else if (unformat (i, "cb %u", &cb))
11860 else if (unformat (i, "eb %u", &eb))
11862 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11865 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11868 else if (unformat (i, "type %U", unformat_policer_type, &type))
11870 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11873 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11876 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11879 else if (unformat (i, "color-aware"))
11885 if (!vec_len (name))
11887 errmsg ("policer name must be specified");
11891 if (vec_len (name) > 64)
11893 errmsg ("policer name too long");
11897 M (POLICER_ADD_DEL, mp);
11899 clib_memcpy (mp->name, name, vec_len (name));
11901 mp->is_add = is_add;
11902 mp->cir = ntohl (cir);
11903 mp->eir = ntohl (eir);
11904 mp->cb = clib_net_to_host_u64 (cb);
11905 mp->eb = clib_net_to_host_u64 (eb);
11906 mp->rate_type = rate_type;
11907 mp->round_type = round_type;
11909 mp->conform_action.type = conform_action.action_type;
11910 mp->conform_action.dscp = conform_action.dscp;
11911 mp->exceed_action.type = exceed_action.action_type;
11912 mp->exceed_action.dscp = exceed_action.dscp;
11913 mp->violate_action.type = violate_action.action_type;
11914 mp->violate_action.dscp = violate_action.dscp;
11915 mp->color_aware = color_aware;
11923 api_policer_dump (vat_main_t * vam)
11925 unformat_input_t *i = vam->input;
11926 vl_api_policer_dump_t *mp;
11927 vl_api_control_ping_t *mp_ping;
11928 u8 *match_name = 0;
11929 u8 match_name_valid = 0;
11932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11934 if (unformat (i, "name %s", &match_name))
11936 vec_add1 (match_name, 0);
11937 match_name_valid = 1;
11943 M (POLICER_DUMP, mp);
11944 mp->match_name_valid = match_name_valid;
11945 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11946 vec_free (match_name);
11950 /* Use a control ping for synchronization */
11951 MPING (CONTROL_PING, mp_ping);
11954 /* Wait for a reply... */
11960 api_policer_classify_set_interface (vat_main_t * vam)
11962 unformat_input_t *i = vam->input;
11963 vl_api_policer_classify_set_interface_t *mp;
11965 int sw_if_index_set;
11966 u32 ip4_table_index = ~0;
11967 u32 ip6_table_index = ~0;
11968 u32 l2_table_index = ~0;
11972 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11974 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11975 sw_if_index_set = 1;
11976 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11977 sw_if_index_set = 1;
11978 else if (unformat (i, "del"))
11980 else if (unformat (i, "ip4-table %d", &ip4_table_index))
11982 else if (unformat (i, "ip6-table %d", &ip6_table_index))
11984 else if (unformat (i, "l2-table %d", &l2_table_index))
11988 clib_warning ("parse error '%U'", format_unformat_error, i);
11993 if (sw_if_index_set == 0)
11995 errmsg ("missing interface name or sw_if_index");
11999 M (POLICER_CLASSIFY_SET_INTERFACE, mp);
12001 mp->sw_if_index = ntohl (sw_if_index);
12002 mp->ip4_table_index = ntohl (ip4_table_index);
12003 mp->ip6_table_index = ntohl (ip6_table_index);
12004 mp->l2_table_index = ntohl (l2_table_index);
12005 mp->is_add = is_add;
12013 api_policer_classify_dump (vat_main_t * vam)
12015 unformat_input_t *i = vam->input;
12016 vl_api_policer_classify_dump_t *mp;
12017 vl_api_control_ping_t *mp_ping;
12018 u8 type = POLICER_CLASSIFY_N_TABLES;
12021 if (unformat (i, "type %U", unformat_policer_classify_table_type, &type))
12025 errmsg ("classify table type must be specified");
12029 if (!vam->json_output)
12031 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
12034 M (POLICER_CLASSIFY_DUMP, mp);
12039 /* Use a control ping for synchronization */
12040 MPING (CONTROL_PING, mp_ping);
12043 /* Wait for a reply... */
12049 format_fib_api_path_nh_proto (u8 * s, va_list * args)
12051 vl_api_fib_path_nh_proto_t proto =
12052 va_arg (*args, vl_api_fib_path_nh_proto_t);
12056 case FIB_API_PATH_NH_PROTO_IP4:
12057 s = format (s, "ip4");
12059 case FIB_API_PATH_NH_PROTO_IP6:
12060 s = format (s, "ip6");
12062 case FIB_API_PATH_NH_PROTO_MPLS:
12063 s = format (s, "mpls");
12065 case FIB_API_PATH_NH_PROTO_BIER:
12066 s = format (s, "bier");
12068 case FIB_API_PATH_NH_PROTO_ETHERNET:
12069 s = format (s, "ethernet");
12077 format_vl_api_ip_address_union (u8 * s, va_list * args)
12079 vl_api_address_family_t af = va_arg (*args, int);
12080 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
12085 s = format (s, "%U", format_ip4_address, u->ip4);
12088 s = format (s, "%U", format_ip6_address, u->ip6);
12095 format_vl_api_fib_path_type (u8 * s, va_list * args)
12097 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
12101 case FIB_API_PATH_TYPE_NORMAL:
12102 s = format (s, "normal");
12104 case FIB_API_PATH_TYPE_LOCAL:
12105 s = format (s, "local");
12107 case FIB_API_PATH_TYPE_DROP:
12108 s = format (s, "drop");
12110 case FIB_API_PATH_TYPE_UDP_ENCAP:
12111 s = format (s, "udp-encap");
12113 case FIB_API_PATH_TYPE_BIER_IMP:
12114 s = format (s, "bier-imp");
12116 case FIB_API_PATH_TYPE_ICMP_UNREACH:
12117 s = format (s, "unreach");
12119 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
12120 s = format (s, "prohibit");
12122 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
12123 s = format (s, "src-lookup");
12125 case FIB_API_PATH_TYPE_DVR:
12126 s = format (s, "dvr");
12128 case FIB_API_PATH_TYPE_INTERFACE_RX:
12129 s = format (s, "interface-rx");
12131 case FIB_API_PATH_TYPE_CLASSIFY:
12132 s = format (s, "classify");
12140 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
12143 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
12144 ntohl (fp->weight), ntohl (fp->sw_if_index),
12145 format_vl_api_fib_path_type, fp->type,
12146 format_fib_api_path_nh_proto, fp->proto,
12147 format_vl_api_ip_address_union, &fp->nh.address);
12151 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
12152 vl_api_fib_path_t * fp)
12154 struct in_addr ip4;
12155 struct in6_addr ip6;
12157 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
12158 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
12159 vat_json_object_add_uint (node, "type", fp->type);
12160 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
12161 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
12163 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
12164 vat_json_object_add_ip4 (node, "next_hop", ip4);
12166 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
12168 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
12169 vat_json_object_add_ip6 (node, "next_hop", ip6);
12174 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
12176 vat_main_t *vam = &vat_main;
12177 int count = ntohl (mp->mt_tunnel.mt_n_paths);
12178 vl_api_fib_path_t *fp;
12181 print (vam->ofp, "sw_if_index %d via:",
12182 ntohl (mp->mt_tunnel.mt_sw_if_index));
12183 fp = mp->mt_tunnel.mt_paths;
12184 for (i = 0; i < count; i++)
12186 vl_api_fib_path_print (vam, fp);
12190 print (vam->ofp, "");
12193 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
12194 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
12197 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
12199 vat_main_t *vam = &vat_main;
12200 vat_json_node_t *node = NULL;
12201 int count = ntohl (mp->mt_tunnel.mt_n_paths);
12202 vl_api_fib_path_t *fp;
12205 if (VAT_JSON_ARRAY != vam->json_tree.type)
12207 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12208 vat_json_init_array (&vam->json_tree);
12210 node = vat_json_array_add (&vam->json_tree);
12212 vat_json_init_object (node);
12213 vat_json_object_add_uint (node, "sw_if_index",
12214 ntohl (mp->mt_tunnel.mt_sw_if_index));
12216 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
12218 fp = mp->mt_tunnel.mt_paths;
12219 for (i = 0; i < count; i++)
12221 vl_api_mpls_fib_path_json_print (node, fp);
12227 api_mpls_tunnel_dump (vat_main_t * vam)
12229 vl_api_mpls_tunnel_dump_t *mp;
12230 vl_api_control_ping_t *mp_ping;
12233 M (MPLS_TUNNEL_DUMP, mp);
12237 /* Use a control ping for synchronization */
12238 MPING (CONTROL_PING, mp_ping);
12245 #define vl_api_mpls_table_details_t_endian vl_noop_handler
12246 #define vl_api_mpls_table_details_t_print vl_noop_handler
12250 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
12252 vat_main_t *vam = &vat_main;
12254 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
12257 static void vl_api_mpls_table_details_t_handler_json
12258 (vl_api_mpls_table_details_t * mp)
12260 vat_main_t *vam = &vat_main;
12261 vat_json_node_t *node = NULL;
12263 if (VAT_JSON_ARRAY != vam->json_tree.type)
12265 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12266 vat_json_init_array (&vam->json_tree);
12268 node = vat_json_array_add (&vam->json_tree);
12270 vat_json_init_object (node);
12271 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
12275 api_mpls_table_dump (vat_main_t * vam)
12277 vl_api_mpls_table_dump_t *mp;
12278 vl_api_control_ping_t *mp_ping;
12281 M (MPLS_TABLE_DUMP, mp);
12284 /* Use a control ping for synchronization */
12285 MPING (CONTROL_PING, mp_ping);
12292 #define vl_api_mpls_route_details_t_endian vl_noop_handler
12293 #define vl_api_mpls_route_details_t_print vl_noop_handler
12296 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
12298 vat_main_t *vam = &vat_main;
12299 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
12300 vl_api_fib_path_t *fp;
12304 "table-id %d, label %u, ess_bit %u",
12305 ntohl (mp->mr_route.mr_table_id),
12306 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
12307 fp = mp->mr_route.mr_paths;
12308 for (i = 0; i < count; i++)
12310 vl_api_fib_path_print (vam, fp);
12315 static void vl_api_mpls_route_details_t_handler_json
12316 (vl_api_mpls_route_details_t * mp)
12318 vat_main_t *vam = &vat_main;
12319 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
12320 vat_json_node_t *node = NULL;
12321 vl_api_fib_path_t *fp;
12324 if (VAT_JSON_ARRAY != vam->json_tree.type)
12326 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12327 vat_json_init_array (&vam->json_tree);
12329 node = vat_json_array_add (&vam->json_tree);
12331 vat_json_init_object (node);
12332 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
12333 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
12334 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
12335 vat_json_object_add_uint (node, "path_count", count);
12336 fp = mp->mr_route.mr_paths;
12337 for (i = 0; i < count; i++)
12339 vl_api_mpls_fib_path_json_print (node, fp);
12345 api_mpls_route_dump (vat_main_t * vam)
12347 unformat_input_t *input = vam->input;
12348 vl_api_mpls_route_dump_t *mp;
12349 vl_api_control_ping_t *mp_ping;
12353 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12355 if (unformat (input, "table_id %d", &table_id))
12360 if (table_id == ~0)
12362 errmsg ("missing table id");
12366 M (MPLS_ROUTE_DUMP, mp);
12368 mp->table.mt_table_id = ntohl (table_id);
12371 /* Use a control ping for synchronization */
12372 MPING (CONTROL_PING, mp_ping);
12379 #define vl_api_ip_table_details_t_endian vl_noop_handler
12380 #define vl_api_ip_table_details_t_print vl_noop_handler
12383 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
12385 vat_main_t *vam = &vat_main;
12388 "%s; table-id %d, prefix %U/%d",
12389 mp->table.name, ntohl (mp->table.table_id));
12393 static void vl_api_ip_table_details_t_handler_json
12394 (vl_api_ip_table_details_t * mp)
12396 vat_main_t *vam = &vat_main;
12397 vat_json_node_t *node = NULL;
12399 if (VAT_JSON_ARRAY != vam->json_tree.type)
12401 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12402 vat_json_init_array (&vam->json_tree);
12404 node = vat_json_array_add (&vam->json_tree);
12406 vat_json_init_object (node);
12407 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
12411 api_ip_table_dump (vat_main_t * vam)
12413 vl_api_ip_table_dump_t *mp;
12414 vl_api_control_ping_t *mp_ping;
12417 M (IP_TABLE_DUMP, mp);
12420 /* Use a control ping for synchronization */
12421 MPING (CONTROL_PING, mp_ping);
12429 api_ip_mtable_dump (vat_main_t * vam)
12431 vl_api_ip_mtable_dump_t *mp;
12432 vl_api_control_ping_t *mp_ping;
12435 M (IP_MTABLE_DUMP, mp);
12438 /* Use a control ping for synchronization */
12439 MPING (CONTROL_PING, mp_ping);
12447 api_ip_mroute_dump (vat_main_t * vam)
12449 unformat_input_t *input = vam->input;
12450 vl_api_control_ping_t *mp_ping;
12451 vl_api_ip_mroute_dump_t *mp;
12456 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12458 if (unformat (input, "table_id %d", &table_id))
12460 else if (unformat (input, "ip6"))
12462 else if (unformat (input, "ip4"))
12467 if (table_id == ~0)
12469 errmsg ("missing table id");
12473 M (IP_MROUTE_DUMP, mp);
12474 mp->table.table_id = table_id;
12475 mp->table.is_ip6 = is_ip6;
12478 /* Use a control ping for synchronization */
12479 MPING (CONTROL_PING, mp_ping);
12486 #define vl_api_ip_route_details_t_endian vl_noop_handler
12487 #define vl_api_ip_route_details_t_print vl_noop_handler
12490 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
12492 vat_main_t *vam = &vat_main;
12493 u8 count = mp->route.n_paths;
12494 vl_api_fib_path_t *fp;
12498 "table-id %d, prefix %U/%d",
12499 ntohl (mp->route.table_id),
12500 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
12501 for (i = 0; i < count; i++)
12503 fp = &mp->route.paths[i];
12505 vl_api_fib_path_print (vam, fp);
12510 static void vl_api_ip_route_details_t_handler_json
12511 (vl_api_ip_route_details_t * mp)
12513 vat_main_t *vam = &vat_main;
12514 u8 count = mp->route.n_paths;
12515 vat_json_node_t *node = NULL;
12516 struct in_addr ip4;
12517 struct in6_addr ip6;
12518 vl_api_fib_path_t *fp;
12521 if (VAT_JSON_ARRAY != vam->json_tree.type)
12523 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12524 vat_json_init_array (&vam->json_tree);
12526 node = vat_json_array_add (&vam->json_tree);
12528 vat_json_init_object (node);
12529 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
12530 if (ADDRESS_IP6 == mp->route.prefix.address.af)
12532 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
12533 vat_json_object_add_ip6 (node, "prefix", ip6);
12537 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
12538 vat_json_object_add_ip4 (node, "prefix", ip4);
12540 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
12541 vat_json_object_add_uint (node, "path_count", count);
12542 for (i = 0; i < count; i++)
12544 fp = &mp->route.paths[i];
12545 vl_api_mpls_fib_path_json_print (node, fp);
12550 api_ip_route_dump (vat_main_t * vam)
12552 unformat_input_t *input = vam->input;
12553 vl_api_ip_route_dump_t *mp;
12554 vl_api_control_ping_t *mp_ping;
12560 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12562 if (unformat (input, "table_id %d", &table_id))
12564 else if (unformat (input, "ip6"))
12566 else if (unformat (input, "ip4"))
12571 if (table_id == ~0)
12573 errmsg ("missing table id");
12577 M (IP_ROUTE_DUMP, mp);
12579 mp->table.table_id = table_id;
12580 mp->table.is_ip6 = is_ip6;
12584 /* Use a control ping for synchronization */
12585 MPING (CONTROL_PING, mp_ping);
12593 api_classify_table_ids (vat_main_t * vam)
12595 vl_api_classify_table_ids_t *mp;
12598 /* Construct the API message */
12599 M (CLASSIFY_TABLE_IDS, mp);
12608 api_classify_table_by_interface (vat_main_t * vam)
12610 unformat_input_t *input = vam->input;
12611 vl_api_classify_table_by_interface_t *mp;
12613 u32 sw_if_index = ~0;
12615 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12617 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12619 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12624 if (sw_if_index == ~0)
12626 errmsg ("missing interface name or sw_if_index");
12630 /* Construct the API message */
12631 M (CLASSIFY_TABLE_BY_INTERFACE, mp);
12633 mp->sw_if_index = ntohl (sw_if_index);
12641 api_classify_table_info (vat_main_t * vam)
12643 unformat_input_t *input = vam->input;
12644 vl_api_classify_table_info_t *mp;
12648 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12650 if (unformat (input, "table_id %d", &table_id))
12655 if (table_id == ~0)
12657 errmsg ("missing table id");
12661 /* Construct the API message */
12662 M (CLASSIFY_TABLE_INFO, mp);
12664 mp->table_id = ntohl (table_id);
12672 api_classify_session_dump (vat_main_t * vam)
12674 unformat_input_t *input = vam->input;
12675 vl_api_classify_session_dump_t *mp;
12676 vl_api_control_ping_t *mp_ping;
12680 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
12682 if (unformat (input, "table_id %d", &table_id))
12687 if (table_id == ~0)
12689 errmsg ("missing table id");
12693 /* Construct the API message */
12694 M (CLASSIFY_SESSION_DUMP, mp);
12696 mp->table_id = ntohl (table_id);
12699 /* Use a control ping for synchronization */
12700 MPING (CONTROL_PING, mp_ping);
12708 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
12710 vat_main_t *vam = &vat_main;
12712 print (vam->ofp, "collector_address %U, collector_port %d, "
12713 "src_address %U, vrf_id %d, path_mtu %u, "
12714 "template_interval %u, udp_checksum %d",
12715 format_ip4_address, mp->collector_address,
12716 ntohs (mp->collector_port),
12717 format_ip4_address, mp->src_address,
12718 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
12719 ntohl (mp->template_interval), mp->udp_checksum);
12722 vam->result_ready = 1;
12726 vl_api_ipfix_exporter_details_t_handler_json
12727 (vl_api_ipfix_exporter_details_t * mp)
12729 vat_main_t *vam = &vat_main;
12730 vat_json_node_t node;
12731 struct in_addr collector_address;
12732 struct in_addr src_address;
12734 vat_json_init_object (&node);
12735 clib_memcpy (&collector_address, &mp->collector_address,
12736 sizeof (collector_address));
12737 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
12738 vat_json_object_add_uint (&node, "collector_port",
12739 ntohs (mp->collector_port));
12740 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
12741 vat_json_object_add_ip4 (&node, "src_address", src_address);
12742 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
12743 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
12744 vat_json_object_add_uint (&node, "template_interval",
12745 ntohl (mp->template_interval));
12746 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
12748 vat_json_print (vam->ofp, &node);
12749 vat_json_free (&node);
12751 vam->result_ready = 1;
12755 api_ipfix_exporter_dump (vat_main_t * vam)
12757 vl_api_ipfix_exporter_dump_t *mp;
12760 /* Construct the API message */
12761 M (IPFIX_EXPORTER_DUMP, mp);
12770 api_ipfix_classify_stream_dump (vat_main_t * vam)
12772 vl_api_ipfix_classify_stream_dump_t *mp;
12775 /* Construct the API message */
12776 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
12787 vl_api_ipfix_classify_stream_details_t_handler
12788 (vl_api_ipfix_classify_stream_details_t * mp)
12790 vat_main_t *vam = &vat_main;
12791 print (vam->ofp, "domain_id %d, src_port %d",
12792 ntohl (mp->domain_id), ntohs (mp->src_port));
12794 vam->result_ready = 1;
12798 vl_api_ipfix_classify_stream_details_t_handler_json
12799 (vl_api_ipfix_classify_stream_details_t * mp)
12801 vat_main_t *vam = &vat_main;
12802 vat_json_node_t node;
12804 vat_json_init_object (&node);
12805 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
12806 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
12808 vat_json_print (vam->ofp, &node);
12809 vat_json_free (&node);
12811 vam->result_ready = 1;
12815 api_ipfix_classify_table_dump (vat_main_t * vam)
12817 vl_api_ipfix_classify_table_dump_t *mp;
12818 vl_api_control_ping_t *mp_ping;
12821 if (!vam->json_output)
12823 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
12824 "transport_protocol");
12827 /* Construct the API message */
12828 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
12833 /* Use a control ping for synchronization */
12834 MPING (CONTROL_PING, mp_ping);
12842 vl_api_ipfix_classify_table_details_t_handler
12843 (vl_api_ipfix_classify_table_details_t * mp)
12845 vat_main_t *vam = &vat_main;
12846 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
12847 mp->transport_protocol);
12851 vl_api_ipfix_classify_table_details_t_handler_json
12852 (vl_api_ipfix_classify_table_details_t * mp)
12854 vat_json_node_t *node = NULL;
12855 vat_main_t *vam = &vat_main;
12857 if (VAT_JSON_ARRAY != vam->json_tree.type)
12859 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12860 vat_json_init_array (&vam->json_tree);
12863 node = vat_json_array_add (&vam->json_tree);
12864 vat_json_init_object (node);
12866 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
12867 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
12868 vat_json_object_add_uint (node, "transport_protocol",
12869 mp->transport_protocol);
12873 api_sw_interface_span_enable_disable (vat_main_t * vam)
12875 unformat_input_t *i = vam->input;
12876 vl_api_sw_interface_span_enable_disable_t *mp;
12877 u32 src_sw_if_index = ~0;
12878 u32 dst_sw_if_index = ~0;
12883 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12886 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
12888 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
12892 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
12894 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
12896 else if (unformat (i, "disable"))
12898 else if (unformat (i, "rx"))
12900 else if (unformat (i, "tx"))
12902 else if (unformat (i, "both"))
12904 else if (unformat (i, "l2"))
12910 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
12912 mp->sw_if_index_from = htonl (src_sw_if_index);
12913 mp->sw_if_index_to = htonl (dst_sw_if_index);
12923 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
12926 vat_main_t *vam = &vat_main;
12927 u8 *sw_if_from_name = 0;
12928 u8 *sw_if_to_name = 0;
12929 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12930 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12931 char *states[] = { "none", "rx", "tx", "both" };
12935 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12937 if ((u32) p->value[0] == sw_if_index_from)
12939 sw_if_from_name = (u8 *)(p->key);
12943 if ((u32) p->value[0] == sw_if_index_to)
12945 sw_if_to_name = (u8 *)(p->key);
12946 if (sw_if_from_name)
12951 print (vam->ofp, "%20s => %20s (%s) %s",
12952 sw_if_from_name, sw_if_to_name, states[mp->state],
12953 mp->is_l2 ? "l2" : "device");
12957 vl_api_sw_interface_span_details_t_handler_json
12958 (vl_api_sw_interface_span_details_t * mp)
12960 vat_main_t *vam = &vat_main;
12961 vat_json_node_t *node = NULL;
12962 u8 *sw_if_from_name = 0;
12963 u8 *sw_if_to_name = 0;
12964 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
12965 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
12969 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
12971 if ((u32) p->value[0] == sw_if_index_from)
12973 sw_if_from_name = (u8 *)(p->key);
12977 if ((u32) p->value[0] == sw_if_index_to)
12979 sw_if_to_name = (u8 *)(p->key);
12980 if (sw_if_from_name)
12986 if (VAT_JSON_ARRAY != vam->json_tree.type)
12988 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12989 vat_json_init_array (&vam->json_tree);
12991 node = vat_json_array_add (&vam->json_tree);
12993 vat_json_init_object (node);
12994 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
12995 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
12996 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
12997 if (0 != sw_if_to_name)
12999 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
13001 vat_json_object_add_uint (node, "state", mp->state);
13002 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
13006 api_sw_interface_span_dump (vat_main_t * vam)
13008 unformat_input_t *input = vam->input;
13009 vl_api_sw_interface_span_dump_t *mp;
13010 vl_api_control_ping_t *mp_ping;
13014 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13016 if (unformat (input, "l2"))
13022 M (SW_INTERFACE_SPAN_DUMP, mp);
13026 /* Use a control ping for synchronization */
13027 MPING (CONTROL_PING, mp_ping);
13035 api_pg_create_interface (vat_main_t * vam)
13037 unformat_input_t *input = vam->input;
13038 vl_api_pg_create_interface_t *mp;
13040 u32 if_id = ~0, gso_size = 0;
13041 u8 gso_enabled = 0;
13043 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13045 if (unformat (input, "if_id %d", &if_id))
13047 else if (unformat (input, "gso-enabled"))
13050 if (unformat (input, "gso-size %u", &gso_size))
13054 errmsg ("missing gso-size");
13063 errmsg ("missing pg interface index");
13067 /* Construct the API message */
13068 M (PG_CREATE_INTERFACE, mp);
13070 mp->interface_id = ntohl (if_id);
13071 mp->gso_enabled = gso_enabled;
13079 api_pg_capture (vat_main_t * vam)
13081 unformat_input_t *input = vam->input;
13082 vl_api_pg_capture_t *mp;
13087 u8 pcap_file_set = 0;
13090 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13092 if (unformat (input, "if_id %d", &if_id))
13094 else if (unformat (input, "pcap %s", &pcap_file))
13096 else if (unformat (input, "count %d", &count))
13098 else if (unformat (input, "disable"))
13105 errmsg ("missing pg interface index");
13108 if (pcap_file_set > 0)
13110 if (vec_len (pcap_file) > 255)
13112 errmsg ("pcap file name is too long");
13117 /* Construct the API message */
13118 M (PG_CAPTURE, mp);
13120 mp->interface_id = ntohl (if_id);
13121 mp->is_enabled = enable;
13122 mp->count = ntohl (count);
13123 if (pcap_file_set != 0)
13125 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
13127 vec_free (pcap_file);
13135 api_pg_enable_disable (vat_main_t * vam)
13137 unformat_input_t *input = vam->input;
13138 vl_api_pg_enable_disable_t *mp;
13141 u8 stream_name_set = 0;
13142 u8 *stream_name = 0;
13144 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13146 if (unformat (input, "stream %s", &stream_name))
13147 stream_name_set = 1;
13148 else if (unformat (input, "disable"))
13154 if (stream_name_set > 0)
13156 if (vec_len (stream_name) > 255)
13158 errmsg ("stream name too long");
13163 /* Construct the API message */
13164 M (PG_ENABLE_DISABLE, mp);
13166 mp->is_enabled = enable;
13167 if (stream_name_set != 0)
13169 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
13171 vec_free (stream_name);
13179 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
13181 unformat_input_t *input = vam->input;
13182 vl_api_pg_interface_enable_disable_coalesce_t *mp;
13184 u32 sw_if_index = ~0;
13187 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13189 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13191 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13193 else if (unformat (input, "disable"))
13199 if (sw_if_index == ~0)
13201 errmsg ("Interface required but not specified");
13205 /* Construct the API message */
13206 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
13208 mp->coalesce_enabled = enable;
13209 mp->sw_if_index = htonl (sw_if_index);
13217 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
13219 unformat_input_t *input = vam->input;
13220 vl_api_ip_source_and_port_range_check_add_del_t *mp;
13222 u16 *low_ports = 0;
13223 u16 *high_ports = 0;
13226 vl_api_prefix_t prefix;
13233 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13235 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
13237 else if (unformat (input, "vrf %d", &vrf_id))
13239 else if (unformat (input, "del"))
13241 else if (unformat (input, "port %d", &tmp))
13243 if (tmp == 0 || tmp > 65535)
13245 errmsg ("port %d out of range", tmp);
13249 this_hi = this_low + 1;
13250 vec_add1 (low_ports, this_low);
13251 vec_add1 (high_ports, this_hi);
13253 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13255 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
13257 errmsg ("incorrect range parameters");
13261 /* Note: in debug CLI +1 is added to high before
13262 passing to real fn that does "the work"
13263 (ip_source_and_port_range_check_add_del).
13264 This fn is a wrapper around the binary API fn a
13265 control plane will call, which expects this increment
13266 to have occurred. Hence letting the binary API control
13267 plane fn do the increment for consistency between VAT
13268 and other control planes.
13271 vec_add1 (low_ports, this_low);
13272 vec_add1 (high_ports, this_hi);
13278 if (prefix_set == 0)
13280 errmsg ("<address>/<mask> not specified");
13286 errmsg ("VRF ID required, not specified");
13293 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13297 if (vec_len (low_ports) == 0)
13299 errmsg ("At least one port or port range required");
13303 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
13305 mp->is_add = is_add;
13307 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
13309 mp->number_of_ranges = vec_len (low_ports);
13311 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
13312 vec_free (low_ports);
13314 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
13315 vec_free (high_ports);
13317 mp->vrf_id = ntohl (vrf_id);
13325 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13327 unformat_input_t *input = vam->input;
13328 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13329 u32 sw_if_index = ~0;
13331 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
13332 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
13336 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13338 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13340 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13342 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
13344 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
13346 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
13348 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
13350 else if (unformat (input, "del"))
13356 if (sw_if_index == ~0)
13358 errmsg ("Interface required but not specified");
13364 errmsg ("VRF ID required but not specified");
13368 if (tcp_out_vrf_id == 0
13369 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
13372 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
13376 /* Construct the API message */
13377 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
13379 mp->sw_if_index = ntohl (sw_if_index);
13380 mp->is_add = is_add;
13381 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
13382 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
13383 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
13384 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
13389 /* Wait for a reply... */
13395 api_set_punt (vat_main_t * vam)
13397 unformat_input_t *i = vam->input;
13398 vl_api_address_family_t af;
13399 vl_api_set_punt_t *mp;
13405 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13407 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
13409 else if (unformat (i, "protocol %d", &protocol))
13411 else if (unformat (i, "port %d", &port))
13413 else if (unformat (i, "del"))
13417 clib_warning ("parse error '%U'", format_unformat_error, i);
13424 mp->is_add = (u8) is_add;
13425 mp->punt.type = PUNT_API_TYPE_L4;
13426 mp->punt.punt.l4.af = af;
13427 mp->punt.punt.l4.protocol = (u8) protocol;
13428 mp->punt.punt.l4.port = htons ((u16) port);
13436 api_delete_subif (vat_main_t * vam)
13438 unformat_input_t *i = vam->input;
13439 vl_api_delete_subif_t *mp;
13440 u32 sw_if_index = ~0;
13443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13445 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13447 if (unformat (i, "sw_if_index %d", &sw_if_index))
13453 if (sw_if_index == ~0)
13455 errmsg ("missing sw_if_index");
13459 /* Construct the API message */
13460 M (DELETE_SUBIF, mp);
13461 mp->sw_if_index = ntohl (sw_if_index);
13468 #define foreach_pbb_vtr_op \
13469 _("disable", L2_VTR_DISABLED) \
13470 _("pop", L2_VTR_POP_2) \
13471 _("push", L2_VTR_PUSH_2)
13474 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
13476 unformat_input_t *i = vam->input;
13477 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
13478 u32 sw_if_index = ~0, vtr_op = ~0;
13479 u16 outer_tag = ~0;
13480 u8 dmac[6], smac[6];
13481 u8 dmac_set = 0, smac_set = 0;
13487 /* Shut up coverity */
13488 clib_memset (dmac, 0, sizeof (dmac));
13489 clib_memset (smac, 0, sizeof (smac));
13491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13493 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13495 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13497 else if (unformat (i, "vtr_op %d", &vtr_op))
13499 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
13502 else if (unformat (i, "translate_pbb_stag"))
13504 if (unformat (i, "%d", &tmp))
13506 vtr_op = L2_VTR_TRANSLATE_2_1;
13512 ("translate_pbb_stag operation requires outer tag definition");
13516 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
13518 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
13520 else if (unformat (i, "sid %d", &sid))
13522 else if (unformat (i, "vlanid %d", &tmp))
13526 clib_warning ("parse error '%U'", format_unformat_error, i);
13531 if ((sw_if_index == ~0) || (vtr_op == ~0))
13533 errmsg ("missing sw_if_index or vtr operation");
13536 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
13537 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
13540 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
13544 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
13545 mp->sw_if_index = ntohl (sw_if_index);
13546 mp->vtr_op = ntohl (vtr_op);
13547 mp->outer_tag = ntohs (outer_tag);
13548 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
13549 clib_memcpy (mp->b_smac, smac, sizeof (smac));
13550 mp->b_vlanid = ntohs (vlanid);
13551 mp->i_sid = ntohl (sid);
13559 api_flow_classify_set_interface (vat_main_t * vam)
13561 unformat_input_t *i = vam->input;
13562 vl_api_flow_classify_set_interface_t *mp;
13564 int sw_if_index_set;
13565 u32 ip4_table_index = ~0;
13566 u32 ip6_table_index = ~0;
13570 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13572 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13573 sw_if_index_set = 1;
13574 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13575 sw_if_index_set = 1;
13576 else if (unformat (i, "del"))
13578 else if (unformat (i, "ip4-table %d", &ip4_table_index))
13580 else if (unformat (i, "ip6-table %d", &ip6_table_index))
13584 clib_warning ("parse error '%U'", format_unformat_error, i);
13589 if (sw_if_index_set == 0)
13591 errmsg ("missing interface name or sw_if_index");
13595 M (FLOW_CLASSIFY_SET_INTERFACE, mp);
13597 mp->sw_if_index = ntohl (sw_if_index);
13598 mp->ip4_table_index = ntohl (ip4_table_index);
13599 mp->ip6_table_index = ntohl (ip6_table_index);
13600 mp->is_add = is_add;
13608 api_flow_classify_dump (vat_main_t * vam)
13610 unformat_input_t *i = vam->input;
13611 vl_api_flow_classify_dump_t *mp;
13612 vl_api_control_ping_t *mp_ping;
13613 u8 type = FLOW_CLASSIFY_N_TABLES;
13616 if (unformat (i, "type %U", unformat_flow_classify_table_type, &type))
13620 errmsg ("classify table type must be specified");
13624 if (!vam->json_output)
13626 print (vam->ofp, "%10s%20s", "Intfc idx", "Classify table");
13629 M (FLOW_CLASSIFY_DUMP, mp);
13634 /* Use a control ping for synchronization */
13635 MPING (CONTROL_PING, mp_ping);
13638 /* Wait for a reply... */
13644 api_feature_enable_disable (vat_main_t * vam)
13646 unformat_input_t *i = vam->input;
13647 vl_api_feature_enable_disable_t *mp;
13649 u8 *feature_name = 0;
13650 u32 sw_if_index = ~0;
13654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13656 if (unformat (i, "arc_name %s", &arc_name))
13658 else if (unformat (i, "feature_name %s", &feature_name))
13661 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13663 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13665 else if (unformat (i, "disable"))
13673 errmsg ("missing arc name");
13676 if (vec_len (arc_name) > 63)
13678 errmsg ("arc name too long");
13681 if (feature_name == 0)
13683 errmsg ("missing feature name");
13686 if (vec_len (feature_name) > 63)
13688 errmsg ("feature name too long");
13691 if (sw_if_index == ~0)
13693 errmsg ("missing interface name or sw_if_index");
13697 /* Construct the API message */
13698 M (FEATURE_ENABLE_DISABLE, mp);
13699 mp->sw_if_index = ntohl (sw_if_index);
13700 mp->enable = enable;
13701 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
13702 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
13703 vec_free (arc_name);
13704 vec_free (feature_name);
13712 api_feature_gso_enable_disable (vat_main_t * vam)
13714 unformat_input_t *i = vam->input;
13715 vl_api_feature_gso_enable_disable_t *mp;
13716 u32 sw_if_index = ~0;
13720 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13722 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13724 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13726 else if (unformat (i, "enable"))
13728 else if (unformat (i, "disable"))
13734 if (sw_if_index == ~0)
13736 errmsg ("missing interface name or sw_if_index");
13740 /* Construct the API message */
13741 M (FEATURE_GSO_ENABLE_DISABLE, mp);
13742 mp->sw_if_index = ntohl (sw_if_index);
13743 mp->enable_disable = enable;
13751 api_sw_interface_tag_add_del (vat_main_t * vam)
13753 unformat_input_t *i = vam->input;
13754 vl_api_sw_interface_tag_add_del_t *mp;
13755 u32 sw_if_index = ~0;
13760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13762 if (unformat (i, "tag %s", &tag))
13764 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13766 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13768 else if (unformat (i, "del"))
13774 if (sw_if_index == ~0)
13776 errmsg ("missing interface name or sw_if_index");
13780 if (enable && (tag == 0))
13782 errmsg ("no tag specified");
13786 /* Construct the API message */
13787 M (SW_INTERFACE_TAG_ADD_DEL, mp);
13788 mp->sw_if_index = ntohl (sw_if_index);
13789 mp->is_add = enable;
13791 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
13800 api_sw_interface_add_del_mac_address (vat_main_t * vam)
13802 unformat_input_t *i = vam->input;
13803 vl_api_mac_address_t mac = { 0 };
13804 vl_api_sw_interface_add_del_mac_address_t *mp;
13805 u32 sw_if_index = ~0;
13810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13812 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13814 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13816 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
13818 else if (unformat (i, "del"))
13824 if (sw_if_index == ~0)
13826 errmsg ("missing interface name or sw_if_index");
13832 errmsg ("missing MAC address");
13836 /* Construct the API message */
13837 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
13838 mp->sw_if_index = ntohl (sw_if_index);
13839 mp->is_add = is_add;
13840 clib_memcpy (&mp->addr, &mac, sizeof (mac));
13847 static void vl_api_l2_xconnect_details_t_handler
13848 (vl_api_l2_xconnect_details_t * mp)
13850 vat_main_t *vam = &vat_main;
13852 print (vam->ofp, "%15d%15d",
13853 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
13856 static void vl_api_l2_xconnect_details_t_handler_json
13857 (vl_api_l2_xconnect_details_t * mp)
13859 vat_main_t *vam = &vat_main;
13860 vat_json_node_t *node = NULL;
13862 if (VAT_JSON_ARRAY != vam->json_tree.type)
13864 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
13865 vat_json_init_array (&vam->json_tree);
13867 node = vat_json_array_add (&vam->json_tree);
13869 vat_json_init_object (node);
13870 vat_json_object_add_uint (node, "rx_sw_if_index",
13871 ntohl (mp->rx_sw_if_index));
13872 vat_json_object_add_uint (node, "tx_sw_if_index",
13873 ntohl (mp->tx_sw_if_index));
13877 api_l2_xconnect_dump (vat_main_t * vam)
13879 vl_api_l2_xconnect_dump_t *mp;
13880 vl_api_control_ping_t *mp_ping;
13883 if (!vam->json_output)
13885 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
13888 M (L2_XCONNECT_DUMP, mp);
13892 /* Use a control ping for synchronization */
13893 MPING (CONTROL_PING, mp_ping);
13901 api_hw_interface_set_mtu (vat_main_t * vam)
13903 unformat_input_t *i = vam->input;
13904 vl_api_hw_interface_set_mtu_t *mp;
13905 u32 sw_if_index = ~0;
13909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13911 if (unformat (i, "mtu %d", &mtu))
13913 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
13915 else if (unformat (i, "sw_if_index %d", &sw_if_index))
13921 if (sw_if_index == ~0)
13923 errmsg ("missing interface name or sw_if_index");
13929 errmsg ("no mtu specified");
13933 /* Construct the API message */
13934 M (HW_INTERFACE_SET_MTU, mp);
13935 mp->sw_if_index = ntohl (sw_if_index);
13936 mp->mtu = ntohs ((u16) mtu);
13944 api_p2p_ethernet_add (vat_main_t * vam)
13946 unformat_input_t *i = vam->input;
13947 vl_api_p2p_ethernet_add_t *mp;
13948 u32 parent_if_index = ~0;
13954 clib_memset (remote_mac, 0, sizeof (remote_mac));
13955 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
13957 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
13959 else if (unformat (i, "sw_if_index %d", &parent_if_index))
13963 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
13965 else if (unformat (i, "sub_id %d", &sub_id))
13969 clib_warning ("parse error '%U'", format_unformat_error, i);
13974 if (parent_if_index == ~0)
13976 errmsg ("missing interface name or sw_if_index");
13981 errmsg ("missing remote mac address");
13986 errmsg ("missing sub-interface id");
13990 M (P2P_ETHERNET_ADD, mp);
13991 mp->parent_if_index = ntohl (parent_if_index);
13992 mp->subif_id = ntohl (sub_id);
13993 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
14001 api_p2p_ethernet_del (vat_main_t * vam)
14003 unformat_input_t *i = vam->input;
14004 vl_api_p2p_ethernet_del_t *mp;
14005 u32 parent_if_index = ~0;
14010 clib_memset (remote_mac, 0, sizeof (remote_mac));
14011 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14013 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
14015 else if (unformat (i, "sw_if_index %d", &parent_if_index))
14019 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
14023 clib_warning ("parse error '%U'", format_unformat_error, i);
14028 if (parent_if_index == ~0)
14030 errmsg ("missing interface name or sw_if_index");
14035 errmsg ("missing remote mac address");
14039 M (P2P_ETHERNET_DEL, mp);
14040 mp->parent_if_index = ntohl (parent_if_index);
14041 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
14049 api_tcp_configure_src_addresses (vat_main_t * vam)
14051 vl_api_tcp_configure_src_addresses_t *mp;
14052 unformat_input_t *i = vam->input;
14053 vl_api_address_t first, last;
14058 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14060 if (unformat (i, "%U - %U",
14061 unformat_vl_api_address, &first,
14062 unformat_vl_api_address, &last))
14066 errmsg ("one range per message (range already set)");
14071 else if (unformat (i, "vrf %d", &vrf_id))
14077 if (range_set == 0)
14079 errmsg ("address range not set");
14083 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
14085 mp->vrf_id = ntohl (vrf_id);
14086 clib_memcpy (&mp->first_address, &first, sizeof (first));
14087 clib_memcpy (&mp->last_address, &last, sizeof (last));
14094 static void vl_api_app_namespace_add_del_reply_t_handler
14095 (vl_api_app_namespace_add_del_reply_t * mp)
14097 vat_main_t *vam = &vat_main;
14098 i32 retval = ntohl (mp->retval);
14099 if (vam->async_mode)
14101 vam->async_errors += (retval < 0);
14105 vam->retval = retval;
14107 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
14108 vam->result_ready = 1;
14112 static void vl_api_app_namespace_add_del_reply_t_handler_json
14113 (vl_api_app_namespace_add_del_reply_t * mp)
14115 vat_main_t *vam = &vat_main;
14116 vat_json_node_t node;
14118 vat_json_init_object (&node);
14119 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
14120 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
14122 vat_json_print (vam->ofp, &node);
14123 vat_json_free (&node);
14125 vam->retval = ntohl (mp->retval);
14126 vam->result_ready = 1;
14130 api_app_namespace_add_del (vat_main_t * vam)
14132 vl_api_app_namespace_add_del_t *mp;
14133 unformat_input_t *i = vam->input;
14134 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
14135 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
14139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14141 if (unformat (i, "id %_%v%_", &ns_id))
14143 else if (unformat (i, "secret %lu", &secret))
14145 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14146 sw_if_index_set = 1;
14147 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
14149 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
14154 if (!ns_id || !secret_set || !sw_if_index_set)
14156 errmsg ("namespace id, secret and sw_if_index must be set");
14159 if (vec_len (ns_id) > 64)
14161 errmsg ("namespace id too long");
14164 M (APP_NAMESPACE_ADD_DEL, mp);
14166 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
14167 mp->secret = clib_host_to_net_u64 (secret);
14168 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14169 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
14170 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
14178 api_sock_init_shm (vat_main_t * vam)
14180 #if VPP_API_TEST_BUILTIN == 0
14181 unformat_input_t *i = vam->input;
14182 vl_api_shm_elem_config_t *config = 0;
14183 u64 size = 64 << 20;
14186 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14188 if (unformat (i, "size %U", unformat_memory_size, &size))
14195 * Canned custom ring allocator config.
14196 * Should probably parse all of this
14198 vec_validate (config, 6);
14199 config[0].type = VL_API_VLIB_RING;
14200 config[0].size = 256;
14201 config[0].count = 32;
14203 config[1].type = VL_API_VLIB_RING;
14204 config[1].size = 1024;
14205 config[1].count = 16;
14207 config[2].type = VL_API_VLIB_RING;
14208 config[2].size = 4096;
14209 config[2].count = 2;
14211 config[3].type = VL_API_CLIENT_RING;
14212 config[3].size = 256;
14213 config[3].count = 32;
14215 config[4].type = VL_API_CLIENT_RING;
14216 config[4].size = 1024;
14217 config[4].count = 16;
14219 config[5].type = VL_API_CLIENT_RING;
14220 config[5].size = 4096;
14221 config[5].count = 2;
14223 config[6].type = VL_API_QUEUE;
14224 config[6].count = 128;
14225 config[6].size = sizeof (uword);
14227 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
14229 vam->client_index_invalid = 1;
14237 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
14239 vat_main_t *vam = &vat_main;
14240 fib_prefix_t lcl, rmt;
14242 ip_prefix_decode (&mp->lcl, &lcl);
14243 ip_prefix_decode (&mp->rmt, &rmt);
14245 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14248 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14249 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14250 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
14251 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
14252 &rmt.fp_addr.ip4, rmt.fp_len,
14253 clib_net_to_host_u16 (mp->rmt_port),
14254 clib_net_to_host_u32 (mp->action_index), mp->tag);
14259 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
14260 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
14261 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
14262 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
14263 &rmt.fp_addr.ip6, rmt.fp_len,
14264 clib_net_to_host_u16 (mp->rmt_port),
14265 clib_net_to_host_u32 (mp->action_index), mp->tag);
14270 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
14273 vat_main_t *vam = &vat_main;
14274 vat_json_node_t *node = NULL;
14275 struct in6_addr ip6;
14276 struct in_addr ip4;
14278 fib_prefix_t lcl, rmt;
14280 ip_prefix_decode (&mp->lcl, &lcl);
14281 ip_prefix_decode (&mp->rmt, &rmt);
14283 if (VAT_JSON_ARRAY != vam->json_tree.type)
14285 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
14286 vat_json_init_array (&vam->json_tree);
14288 node = vat_json_array_add (&vam->json_tree);
14289 vat_json_init_object (node);
14291 vat_json_object_add_uint (node, "appns_index",
14292 clib_net_to_host_u32 (mp->appns_index));
14293 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
14294 vat_json_object_add_uint (node, "scope", mp->scope);
14295 vat_json_object_add_uint (node, "action_index",
14296 clib_net_to_host_u32 (mp->action_index));
14297 vat_json_object_add_uint (node, "lcl_port",
14298 clib_net_to_host_u16 (mp->lcl_port));
14299 vat_json_object_add_uint (node, "rmt_port",
14300 clib_net_to_host_u16 (mp->rmt_port));
14301 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
14302 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
14303 vat_json_object_add_string_copy (node, "tag", mp->tag);
14304 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
14306 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
14307 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
14308 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
14309 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
14313 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
14314 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
14315 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
14316 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
14321 api_session_rule_add_del (vat_main_t * vam)
14323 vl_api_session_rule_add_del_t *mp;
14324 unformat_input_t *i = vam->input;
14325 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
14326 u32 appns_index = 0, scope = 0;
14327 ip4_address_t lcl_ip4, rmt_ip4;
14328 ip6_address_t lcl_ip6, rmt_ip6;
14329 u8 is_ip4 = 1, conn_set = 0;
14330 u8 is_add = 1, *tag = 0;
14332 fib_prefix_t lcl, rmt;
14334 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14336 if (unformat (i, "del"))
14338 else if (unformat (i, "add"))
14340 else if (unformat (i, "proto tcp"))
14342 else if (unformat (i, "proto udp"))
14344 else if (unformat (i, "appns %d", &appns_index))
14346 else if (unformat (i, "scope %d", &scope))
14348 else if (unformat (i, "tag %_%v%_", &tag))
14352 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
14353 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
14361 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
14362 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
14368 else if (unformat (i, "action %d", &action))
14373 if (proto == ~0 || !conn_set || action == ~0)
14375 errmsg ("transport proto, connection and action must be set");
14381 errmsg ("scope should be 0-3");
14385 M (SESSION_RULE_ADD_DEL, mp);
14387 clib_memset (&lcl, 0, sizeof (lcl));
14388 clib_memset (&rmt, 0, sizeof (rmt));
14391 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
14392 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
14393 lcl.fp_len = lcl_plen;
14394 rmt.fp_len = rmt_plen;
14398 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
14399 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
14400 lcl.fp_len = lcl_plen;
14401 rmt.fp_len = rmt_plen;
14405 ip_prefix_encode (&lcl, &mp->lcl);
14406 ip_prefix_encode (&rmt, &mp->rmt);
14407 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
14408 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
14409 mp->transport_proto =
14410 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
14411 mp->action_index = clib_host_to_net_u32 (action);
14412 mp->appns_index = clib_host_to_net_u32 (appns_index);
14414 mp->is_add = is_add;
14417 clib_memcpy (mp->tag, tag, vec_len (tag));
14427 api_session_rules_dump (vat_main_t * vam)
14429 vl_api_session_rules_dump_t *mp;
14430 vl_api_control_ping_t *mp_ping;
14433 if (!vam->json_output)
14435 print (vam->ofp, "%=20s", "Session Rules");
14438 M (SESSION_RULES_DUMP, mp);
14442 /* Use a control ping for synchronization */
14443 MPING (CONTROL_PING, mp_ping);
14446 /* Wait for a reply... */
14452 api_ip_container_proxy_add_del (vat_main_t * vam)
14454 vl_api_ip_container_proxy_add_del_t *mp;
14455 unformat_input_t *i = vam->input;
14456 u32 sw_if_index = ~0;
14457 vl_api_prefix_t pfx = { };
14461 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14463 if (unformat (i, "del"))
14465 else if (unformat (i, "add"))
14467 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
14469 else if (unformat (i, "sw_if_index %u", &sw_if_index))
14474 if (sw_if_index == ~0 || pfx.len == 0)
14476 errmsg ("address and sw_if_index must be set");
14480 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
14482 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
14483 mp->is_add = is_add;
14484 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
14492 api_qos_record_enable_disable (vat_main_t * vam)
14494 unformat_input_t *i = vam->input;
14495 vl_api_qos_record_enable_disable_t *mp;
14496 u32 sw_if_index, qs = 0xff;
14497 u8 sw_if_index_set = 0;
14501 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
14503 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
14504 sw_if_index_set = 1;
14505 else if (unformat (i, "sw_if_index %d", &sw_if_index))
14506 sw_if_index_set = 1;
14507 else if (unformat (i, "%U", unformat_qos_source, &qs))
14509 else if (unformat (i, "disable"))
14513 clib_warning ("parse error '%U'", format_unformat_error, i);
14518 if (sw_if_index_set == 0)
14520 errmsg ("missing interface name or sw_if_index");
14525 errmsg ("input location must be specified");
14529 M (QOS_RECORD_ENABLE_DISABLE, mp);
14531 mp->record.sw_if_index = ntohl (sw_if_index);
14532 mp->record.input_source = qs;
14533 mp->enable = enable;
14542 q_or_quit (vat_main_t * vam)
14544 #if VPP_API_TEST_BUILTIN == 0
14545 longjmp (vam->jump_buf, 1);
14547 return 0; /* not so much */
14551 q (vat_main_t * vam)
14553 return q_or_quit (vam);
14557 quit (vat_main_t * vam)
14559 return q_or_quit (vam);
14563 comment (vat_main_t * vam)
14569 elog_save (vat_main_t * vam)
14571 #if VPP_API_TEST_BUILTIN == 0
14572 elog_main_t *em = &vam->elog_main;
14573 unformat_input_t *i = vam->input;
14574 char *file, *chroot_file;
14575 clib_error_t *error;
14577 if (!unformat (i, "%s", &file))
14579 errmsg ("expected file name, got `%U'", format_unformat_error, i);
14583 /* It's fairly hard to get "../oopsie" through unformat; just in case */
14584 if (strstr (file, "..") || index (file, '/'))
14586 errmsg ("illegal characters in filename '%s'", file);
14590 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
14594 errmsg ("Saving %wd of %wd events to %s",
14595 elog_n_events_in_buffer (em),
14596 elog_buffer_capacity (em), chroot_file);
14598 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
14599 vec_free (chroot_file);
14602 clib_error_report (error);
14604 errmsg ("Use the vpp event loger...");
14611 elog_setup (vat_main_t * vam)
14613 #if VPP_API_TEST_BUILTIN == 0
14614 elog_main_t *em = &vam->elog_main;
14615 unformat_input_t *i = vam->input;
14616 u32 nevents = 128 << 10;
14618 (void) unformat (i, "nevents %d", &nevents);
14620 elog_init (em, nevents);
14621 vl_api_set_elog_main (em);
14622 vl_api_set_elog_trace_api_messages (1);
14623 errmsg ("Event logger initialized with %u events", nevents);
14625 errmsg ("Use the vpp event loger...");
14631 elog_enable (vat_main_t * vam)
14633 #if VPP_API_TEST_BUILTIN == 0
14634 elog_main_t *em = &vam->elog_main;
14636 elog_enable_disable (em, 1 /* enable */ );
14637 vl_api_set_elog_trace_api_messages (1);
14638 errmsg ("Event logger enabled...");
14640 errmsg ("Use the vpp event loger...");
14646 elog_disable (vat_main_t * vam)
14648 #if VPP_API_TEST_BUILTIN == 0
14649 elog_main_t *em = &vam->elog_main;
14651 elog_enable_disable (em, 0 /* enable */ );
14652 vl_api_set_elog_trace_api_messages (1);
14653 errmsg ("Event logger disabled...");
14655 errmsg ("Use the vpp event loger...");
14661 statseg (vat_main_t * vam)
14663 ssvm_private_t *ssvmp = &vam->stat_segment;
14664 ssvm_shared_header_t *shared_header = ssvmp->sh;
14665 vlib_counter_t **counters;
14666 u64 thread0_index1_packets;
14667 u64 thread0_index1_bytes;
14668 f64 vector_rate, input_rate;
14671 uword *counter_vector_by_name;
14672 if (vam->stat_segment_lockp == 0)
14674 errmsg ("Stat segment not mapped...");
14678 /* look up "/if/rx for sw_if_index 1 as a test */
14680 clib_spinlock_lock (vam->stat_segment_lockp);
14682 counter_vector_by_name = (uword *) shared_header->opaque[1];
14684 p = hash_get_mem (counter_vector_by_name, "/if/rx");
14687 clib_spinlock_unlock (vam->stat_segment_lockp);
14688 errmsg ("/if/tx not found?");
14692 /* Fish per-thread vector of combined counters from shared memory */
14693 counters = (vlib_counter_t **) p[0];
14695 if (vec_len (counters[0]) < 2)
14697 clib_spinlock_unlock (vam->stat_segment_lockp);
14698 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
14702 /* Read thread 0 sw_if_index 1 counter */
14703 thread0_index1_packets = counters[0][1].packets;
14704 thread0_index1_bytes = counters[0][1].bytes;
14706 p = hash_get_mem (counter_vector_by_name, "vector_rate");
14709 clib_spinlock_unlock (vam->stat_segment_lockp);
14710 errmsg ("vector_rate not found?");
14714 vector_rate = *(f64 *) (p[0]);
14715 p = hash_get_mem (counter_vector_by_name, "input_rate");
14718 clib_spinlock_unlock (vam->stat_segment_lockp);
14719 errmsg ("input_rate not found?");
14722 input_rate = *(f64 *) (p[0]);
14724 clib_spinlock_unlock (vam->stat_segment_lockp);
14726 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
14727 vector_rate, input_rate);
14728 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
14729 thread0_index1_packets, thread0_index1_bytes);
14735 cmd_cmp (void *a1, void *a2)
14740 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
14744 help (vat_main_t * vam)
14749 unformat_input_t *i = vam->input;
14752 if (unformat (i, "%s", &name))
14756 vec_add1 (name, 0);
14758 hs = hash_get_mem (vam->help_by_name, name);
14760 print (vam->ofp, "usage: %s %s", name, hs[0]);
14762 print (vam->ofp, "No such msg / command '%s'", name);
14767 print (vam->ofp, "Help is available for the following:");
14770 hash_foreach_pair (p, vam->function_by_name,
14772 vec_add1 (cmds, (u8 *)(p->key));
14776 vec_sort_with_function (cmds, cmd_cmp);
14778 for (j = 0; j < vec_len (cmds); j++)
14779 print (vam->ofp, "%s", cmds[j]);
14786 set (vat_main_t * vam)
14788 u8 *name = 0, *value = 0;
14789 unformat_input_t *i = vam->input;
14791 if (unformat (i, "%s", &name))
14793 /* The input buffer is a vector, not a string. */
14794 value = vec_dup (i->buffer);
14795 vec_delete (value, i->index, 0);
14796 /* Almost certainly has a trailing newline */
14797 if (value[vec_len (value) - 1] == '\n')
14798 value[vec_len (value) - 1] = 0;
14799 /* Make sure it's a proper string, one way or the other */
14800 vec_add1 (value, 0);
14801 (void) clib_macro_set_value (&vam->macro_main,
14802 (char *) name, (char *) value);
14805 errmsg ("usage: set <name> <value>");
14813 unset (vat_main_t * vam)
14817 if (unformat (vam->input, "%s", &name))
14818 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
14819 errmsg ("unset: %s wasn't set", name);
14832 macro_sort_cmp (void *a1, void *a2)
14834 macro_sort_t *s1 = a1;
14835 macro_sort_t *s2 = a2;
14837 return strcmp ((char *) (s1->name), (char *) (s2->name));
14841 dump_macro_table (vat_main_t * vam)
14843 macro_sort_t *sort_me = 0, *sm;
14848 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
14850 vec_add2 (sort_me, sm, 1);
14851 sm->name = (u8 *)(p->key);
14852 sm->value = (u8 *) (p->value[0]);
14856 vec_sort_with_function (sort_me, macro_sort_cmp);
14858 if (vec_len (sort_me))
14859 print (vam->ofp, "%-15s%s", "Name", "Value");
14861 print (vam->ofp, "The macro table is empty...");
14863 for (i = 0; i < vec_len (sort_me); i++)
14864 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
14869 dump_node_table (vat_main_t * vam)
14872 vlib_node_t *node, *next_node;
14874 if (vec_len (vam->graph_nodes) == 0)
14876 print (vam->ofp, "Node table empty, issue get_node_graph...");
14880 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
14882 node = vam->graph_nodes[0][i];
14883 print (vam->ofp, "[%d] %s", i, node->name);
14884 for (j = 0; j < vec_len (node->next_nodes); j++)
14886 if (node->next_nodes[j] != ~0)
14888 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14889 print (vam->ofp, " [%d] %s", j, next_node->name);
14897 value_sort_cmp (void *a1, void *a2)
14899 name_sort_t *n1 = a1;
14900 name_sort_t *n2 = a2;
14902 if (n1->value < n2->value)
14904 if (n1->value > n2->value)
14911 dump_msg_api_table (vat_main_t * vam)
14913 api_main_t *am = vlibapi_get_main ();
14914 name_sort_t *nses = 0, *ns;
14919 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
14921 vec_add2 (nses, ns, 1);
14922 ns->name = (u8 *)(hp->key);
14923 ns->value = (u32) hp->value[0];
14927 vec_sort_with_function (nses, value_sort_cmp);
14929 for (i = 0; i < vec_len (nses); i++)
14930 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
14936 get_msg_id (vat_main_t * vam)
14941 if (unformat (vam->input, "%s", &name_and_crc))
14943 message_index = vl_msg_api_get_msg_index (name_and_crc);
14944 if (message_index == ~0)
14946 print (vam->ofp, " '%s' not found", name_and_crc);
14949 print (vam->ofp, " '%s' has message index %d",
14950 name_and_crc, message_index);
14953 errmsg ("name_and_crc required...");
14958 search_node_table (vat_main_t * vam)
14960 unformat_input_t *line_input = vam->input;
14963 vlib_node_t *node, *next_node;
14966 if (vam->graph_node_index_by_name == 0)
14968 print (vam->ofp, "Node table empty, issue get_node_graph...");
14972 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
14974 if (unformat (line_input, "%s", &node_to_find))
14976 vec_add1 (node_to_find, 0);
14977 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
14980 print (vam->ofp, "%s not found...", node_to_find);
14983 node = vam->graph_nodes[0][p[0]];
14984 print (vam->ofp, "[%d] %s", p[0], node->name);
14985 for (j = 0; j < vec_len (node->next_nodes); j++)
14987 if (node->next_nodes[j] != ~0)
14989 next_node = vam->graph_nodes[0][node->next_nodes[j]];
14990 print (vam->ofp, " [%d] %s", j, next_node->name);
14997 clib_warning ("parse error '%U'", format_unformat_error,
15003 vec_free (node_to_find);
15012 script (vat_main_t * vam)
15014 #if (VPP_API_TEST_BUILTIN==0)
15016 char *save_current_file;
15017 unformat_input_t save_input;
15018 jmp_buf save_jump_buf;
15019 u32 save_line_number;
15021 FILE *new_fp, *save_ifp;
15023 if (unformat (vam->input, "%s", &s))
15025 new_fp = fopen ((char *) s, "r");
15028 errmsg ("Couldn't open script file %s", s);
15035 errmsg ("Missing script name");
15039 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
15040 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
15041 save_ifp = vam->ifp;
15042 save_line_number = vam->input_line_number;
15043 save_current_file = (char *) vam->current_file;
15045 vam->input_line_number = 0;
15047 vam->current_file = s;
15050 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
15051 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
15052 vam->ifp = save_ifp;
15053 vam->input_line_number = save_line_number;
15054 vam->current_file = (u8 *) save_current_file;
15059 clib_warning ("use the exec command...");
15065 echo (vat_main_t * vam)
15067 print (vam->ofp, "%v", vam->input->buffer);
15071 /* List of API message constructors, CLI names map to api_xxx */
15072 #define foreach_vpe_api_msg \
15073 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
15074 _(sw_interface_dump,"") \
15075 _(sw_interface_set_flags, \
15076 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
15077 _(sw_interface_add_del_address, \
15078 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
15079 _(sw_interface_set_rx_mode, \
15080 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
15081 _(sw_interface_set_rx_placement, \
15082 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
15083 _(sw_interface_rx_placement_dump, \
15084 "[<intfc> | sw_if_index <id>]") \
15085 _(sw_interface_set_table, \
15086 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
15087 _(sw_interface_set_mpls_enable, \
15088 "<intfc> | sw_if_index [disable | dis]") \
15089 _(sw_interface_set_vpath, \
15090 "<intfc> | sw_if_index <id> enable | disable") \
15091 _(sw_interface_set_vxlan_bypass, \
15092 "<intfc> | sw_if_index <id> [ip4 | ip6] [enable | disable]") \
15093 _(sw_interface_set_l2_xconnect, \
15094 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15095 "enable | disable") \
15096 _(sw_interface_set_l2_bridge, \
15097 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
15098 "[shg <split-horizon-group>] [bvi]\n" \
15099 "enable | disable") \
15100 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
15101 _(bridge_domain_add_del, \
15102 "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") \
15103 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
15105 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
15106 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
15107 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
15109 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15111 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
15113 "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]") \
15115 "<vpp-if-name> | sw_if_index <id>") \
15116 _(sw_interface_tap_v2_dump, "") \
15117 _(virtio_pci_create_v2, \
15118 "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]") \
15119 _(virtio_pci_delete, \
15120 "<vpp-if-name> | sw_if_index <id>") \
15121 _(sw_interface_virtio_pci_dump, "") \
15123 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
15124 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
15127 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
15128 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
15129 "[id <if-id>] [gso]") \
15131 "<vpp-if-name> | sw_if_index <id>") \
15132 _(bond_add_member, \
15133 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
15134 _(bond_detach_member, \
15135 "sw_if_index <n>") \
15136 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
15137 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
15138 _(sw_member_interface_dump, \
15139 "<vpp-if-name> | sw_if_index <id>") \
15140 _(ip_table_add_del, \
15141 "table <n> [ipv6] [add | del]\n") \
15142 _(ip_route_add_del, \
15143 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
15144 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
15145 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
15146 "[multipath] [count <n>] [del]") \
15147 _(ip_mroute_add_del, \
15148 "<src> <grp>/<mask> [table-id <n>]\n" \
15149 "[<intfc> | sw_if_index <id>] [local] [del]") \
15150 _(mpls_table_add_del, \
15151 "table <n> [add | del]\n") \
15152 _(mpls_route_add_del, \
15153 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
15154 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
15155 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
15156 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
15157 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
15158 "[count <n>] [del]") \
15159 _(mpls_ip_bind_unbind, \
15160 "<label> <addr/len>") \
15161 _(mpls_tunnel_add_del, \
15162 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
15163 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
15164 "[l2-only] [out-label <n>]") \
15165 _(sr_mpls_policy_add, \
15166 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
15167 _(sr_mpls_policy_del, \
15169 _(bier_table_add_del, \
15170 "<label> <sub-domain> <set> <bsl> [del]") \
15171 _(bier_route_add_del, \
15172 "<bit-position> <sub-domain> <set> <bsl> via <addr> [table-id <n>]\n" \
15173 "[<intfc> | sw_if_index <id>]" \
15174 "[weight <n>] [del] [multipath]") \
15175 _(sw_interface_set_unnumbered, \
15176 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
15177 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
15178 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
15179 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
15180 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
15181 "[outer_vlan_id_any][inner_vlan_id_any]") \
15182 _(ip_table_replace_begin, "table <n> [ipv6]") \
15183 _(ip_table_flush, "table <n> [ipv6]") \
15184 _(ip_table_replace_end, "table <n> [ipv6]") \
15185 _(set_ip_flow_hash, \
15186 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
15187 _(sw_interface_ip6_enable_disable, \
15188 "<intfc> | sw_if_index <id> enable | disable") \
15189 _(l2_patch_add_del, \
15190 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
15191 "enable | disable") \
15192 _(sr_localsid_add_del, \
15193 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
15194 "fib-table <num> (end.psp) sw_if_index <num>") \
15195 _(classify_add_del_table, \
15196 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
15197 " [del] [del-chain] mask <mask-value>\n" \
15198 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>\n" \
15199 " [current-data-flag <n>] [current-data-offset <nn>] [table <nn>]") \
15200 _(classify_add_del_session, \
15201 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
15202 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
15203 " [l3 [ip4|ip6]] [action set-ip4-fib-id <nn>]\n" \
15204 " [action set-ip6-fib-id <nn> | action <n> metadata <nn>] [del]") \
15205 _(classify_set_interface_ip_table, \
15206 "<intfc> | sw_if_index <nn> table <nn>") \
15207 _(classify_set_interface_l2_tables, \
15208 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15209 " [other-table <nn>]") \
15210 _(get_node_index, "node <node-name") \
15211 _(add_node_next, "node <node-name> next <next-node-name>") \
15212 _(vxlan_offload_rx, \
15213 "hw { <interface name> | hw_if_index <nn>} " \
15214 "rx { <vxlan tunnel name> | sw_if_index <nn> } [del]") \
15215 _(vxlan_add_del_tunnel, \
15216 "src <ip-addr> { dst <ip-addr> | group <mcast-ip-addr>\n" \
15217 "{ <intfc> | mcast_sw_if_index <nn> } [instance <id>]}\n" \
15218 "vni <vni> [encap-vrf-id <nn>] [decap-next <l2|nn>] [del]") \
15219 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15220 _(gre_tunnel_add_del, \
15221 "src <ip-addr> dst <ip-addr> [outer-fib-id <nn>] [instance <n>]\n" \
15222 "[teb | erspan <session-id>] [del]") \
15223 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15224 _(l2_fib_clear_table, "") \
15225 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
15226 _(l2_interface_vlan_tag_rewrite, \
15227 "<intfc> | sw_if_index <nn> \n" \
15228 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
15229 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
15230 _(create_vhost_user_if, \
15231 "socket <filename> [server] [renumber <dev_instance>] " \
15232 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
15233 "[mac <mac_address>] [packed]") \
15234 _(modify_vhost_user_if, \
15235 "<intfc> | sw_if_index <nn> socket <filename>\n" \
15236 "[server] [renumber <dev_instance>] [gso] [packed]") \
15237 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
15238 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
15239 _(show_version, "") \
15240 _(show_threads, "") \
15241 _(vxlan_gpe_add_del_tunnel, \
15242 "local <addr> remote <addr> | group <mcast-ip-addr>\n" \
15243 "{ <intfc> | mcast_sw_if_index <nn> } }\n" \
15244 "vni <nn> [encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
15245 "[next-ip4][next-ip6][next-ethernet] [next-nsh] [del]\n") \
15246 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
15247 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
15248 _(interface_name_renumber, \
15249 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
15250 _(input_acl_set_interface, \
15251 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15252 " [l2-table <nn>] [del]") \
15253 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
15254 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
15255 _(ip_dump, "ipv4 | ipv6") \
15256 _(ipsec_spd_add_del, "spd_id <n> [del]") \
15257 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
15259 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
15260 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
15261 " integ_alg <alg> integ_key <hex>") \
15262 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
15263 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
15264 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
15265 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
15266 _(ipsec_tunnel_if_add_del, "local_spi <n> remote_spi <n>\n" \
15267 " crypto_alg <alg> local_crypto_key <hex> remote_crypto_key <hex>\n" \
15268 " integ_alg <alg> local_integ_key <hex> remote_integ_key <hex>\n" \
15269 " local_ip <addr> remote_ip <addr> [esn] [anti_replay] [del]\n" \
15270 " [instance <n>]") \
15271 _(ipsec_sa_dump, "[sa_id <n>]") \
15272 _(ipsec_tunnel_if_set_sa, "<intfc> sa_id <n> <inbound|outbound>\n") \
15273 _(delete_loopback,"sw_if_index <nn>") \
15274 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
15275 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
15276 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
15277 _(want_interface_events, "enable|disable") \
15278 _(get_first_msg_id, "client <name>") \
15279 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
15280 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
15281 "fib-id <nn> [ip4][ip6][default]") \
15282 _(get_node_graph, " ") \
15283 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
15284 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
15285 _(ioam_disable, "") \
15286 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
15287 _(af_packet_delete, "name <host interface name>") \
15288 _(af_packet_dump, "") \
15289 _(policer_add_del, "name <policer name> <params> [del]") \
15290 _(policer_dump, "[name <policer name>]") \
15291 _(policer_classify_set_interface, \
15292 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15293 " [l2-table <nn>] [del]") \
15294 _(policer_classify_dump, "type [ip4|ip6|l2]") \
15295 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
15296 _(mpls_table_dump, "") \
15297 _(mpls_route_dump, "table-id <ID>") \
15298 _(classify_table_ids, "") \
15299 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
15300 _(classify_table_info, "table_id <nn>") \
15301 _(classify_session_dump, "table_id <nn>") \
15302 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
15303 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
15304 "[template_interval <nn>] [udp_checksum]") \
15305 _(ipfix_exporter_dump, "") \
15306 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
15307 _(ipfix_classify_stream_dump, "") \
15308 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
15309 _(ipfix_classify_table_dump, "") \
15310 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
15311 _(sw_interface_span_dump, "[l2]") \
15312 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
15313 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
15314 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
15315 _(pg_enable_disable, "[stream <id>] disable") \
15316 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
15317 _(ip_source_and_port_range_check_add_del, \
15318 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
15319 _(ip_source_and_port_range_check_interface_add_del, \
15320 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
15321 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
15322 _(delete_subif,"<intfc> | sw_if_index <nn>") \
15323 _(l2_interface_pbb_tag_rewrite, \
15324 "<intfc> | sw_if_index <nn> \n" \
15325 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
15326 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
15327 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
15328 _(flow_classify_set_interface, \
15329 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>] [del]") \
15330 _(flow_classify_dump, "type [ip4|ip6]") \
15331 _(ip_table_dump, "") \
15332 _(ip_route_dump, "table-id [ip4|ip6]") \
15333 _(ip_mtable_dump, "") \
15334 _(ip_mroute_dump, "table-id [ip4|ip6]") \
15335 _(feature_enable_disable, "arc_name <arc_name> " \
15336 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
15337 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
15338 "[enable | disable] ") \
15339 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
15341 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
15342 "mac <mac-address> [del]") \
15343 _(l2_xconnect_dump, "") \
15344 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
15345 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
15346 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
15347 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
15348 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
15349 _(sock_init_shm, "size <nnn>") \
15350 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
15351 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
15352 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
15353 _(session_rules_dump, "") \
15354 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
15355 _(output_acl_set_interface, \
15356 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
15357 " [l2-table <nn>] [del]") \
15358 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
15360 /* List of command functions, CLI names map directly to functions */
15361 #define foreach_cli_function \
15362 _(comment, "usage: comment <ignore-rest-of-line>") \
15363 _(dump_interface_table, "usage: dump_interface_table") \
15364 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
15365 _(dump_ipv4_table, "usage: dump_ipv4_table") \
15366 _(dump_ipv6_table, "usage: dump_ipv6_table") \
15367 _(dump_macro_table, "usage: dump_macro_table ") \
15368 _(dump_node_table, "usage: dump_node_table") \
15369 _(dump_msg_api_table, "usage: dump_msg_api_table") \
15370 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
15371 _(elog_disable, "usage: elog_disable") \
15372 _(elog_enable, "usage: elog_enable") \
15373 _(elog_save, "usage: elog_save <filename>") \
15374 _(get_msg_id, "usage: get_msg_id name_and_crc") \
15375 _(echo, "usage: echo <message>") \
15376 _(exec, "usage: exec <vpe-debug-CLI-command>") \
15377 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
15378 _(help, "usage: help") \
15379 _(q, "usage: quit") \
15380 _(quit, "usage: quit") \
15381 _(search_node_table, "usage: search_node_table <name>...") \
15382 _(set, "usage: set <variable-name> <value>") \
15383 _(script, "usage: script <file-name>") \
15384 _(statseg, "usage: statseg") \
15385 _(unset, "usage: unset <variable-name>")
15388 static void vl_api_##n##_t_handler_uni \
15389 (vl_api_##n##_t * mp) \
15391 vat_main_t * vam = &vat_main; \
15392 if (vam->json_output) { \
15393 vl_api_##n##_t_handler_json(mp); \
15395 vl_api_##n##_t_handler(mp); \
15398 foreach_vpe_api_reply_msg;
15399 #if VPP_API_TEST_BUILTIN == 0
15400 foreach_standalone_reply_msg;
15405 vat_api_hookup (vat_main_t * vam)
15408 vl_msg_api_set_handlers(VL_API_##N, #n, \
15409 vl_api_##n##_t_handler_uni, \
15411 vl_api_##n##_t_endian, \
15412 vl_api_##n##_t_print, \
15413 sizeof(vl_api_##n##_t), 1);
15414 foreach_vpe_api_reply_msg;
15415 #if VPP_API_TEST_BUILTIN == 0
15416 foreach_standalone_reply_msg;
15420 #if (VPP_API_TEST_BUILTIN==0)
15421 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
15423 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
15425 vam->function_by_name = hash_create_string (0, sizeof (uword));
15427 vam->help_by_name = hash_create_string (0, sizeof (uword));
15430 /* API messages we can send */
15431 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
15432 foreach_vpe_api_msg;
15436 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15437 foreach_vpe_api_msg;
15440 /* CLI functions */
15441 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
15442 foreach_cli_function;
15446 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
15447 foreach_cli_function;
15451 #if VPP_API_TEST_BUILTIN
15452 static clib_error_t *
15453 vat_api_hookup_shim (vlib_main_t * vm)
15455 vat_api_hookup (&vat_main);
15459 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
15463 * fd.io coding-style-patch-verification: ON
15466 * eval: (c-set-style "gnu")