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/udp/udp_local.h>
32 #include <vpp/api/vpe_msg_enum.h>
33 #include <vnet/l2/l2_classify.h>
34 #include <vnet/l2/l2_vtr.h>
35 #include <vnet/classify/in_out_acl.h>
36 #include <vnet/classify/policer_classify.h>
37 #include <vnet/classify/flow_classify.h>
38 #include <vnet/mpls/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
41 #include <vnet/ip/ip6_hop_by_hop.h>
42 #include <vnet/ip/ip_source_and_port_range_check.h>
43 #include <vnet/policer/xlate.h>
44 #include <vnet/span/span.h>
45 #include <vnet/policer/policer.h>
46 #include <vnet/policer/police.h>
47 #include <vnet/mfib/mfib_types.h>
48 #include <vnet/bonding/node.h>
49 #include <vnet/qos/qos_types.h>
50 #include <vnet/ethernet/ethernet_types_api.h>
51 #include <vnet/ip/ip_types_api.h>
52 #include "vat/json_format.h"
53 #include <vnet/ip/ip_types_api.h>
54 #include <vnet/ethernet/ethernet_types_api.h>
59 #define vl_typedefs /* define message structures */
60 #include <vpp/api/vpe_all_api_h.h>
63 /* declare message handlers for each api */
65 #define vl_endianfun /* define message structures */
66 #include <vpp/api/vpe_all_api_h.h>
69 /* instantiate all the print functions we know about */
70 #if VPP_API_TEST_BUILTIN == 0
71 #define vl_print(handle, ...)
73 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
76 #include <vpp/api/vpe_all_api_h.h>
79 #define __plugin_msg_base 0
80 #include <vlibapi/vat_helper_macros.h>
82 void vl_api_set_elog_main (elog_main_t * m);
83 int vl_api_set_elog_trace_api_messages (int enable);
85 #if VPP_API_TEST_BUILTIN == 0
95 vat_socket_connect (vat_main_t * vam)
98 api_main_t *am = vlibapi_get_main ();
99 vam->socket_client_main = &socket_client_main;
100 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
102 0 /* default socket rx, tx buffer */ )))
105 /* vpp expects the client index in network order */
106 vam->my_client_index = htonl (socket_client_main.client_index);
107 am->my_client_index = vam->my_client_index;
110 #else /* vpp built-in case, we don't do sockets... */
112 vat_socket_connect (vat_main_t * vam)
118 vl_socket_client_read (int wait)
124 vl_socket_client_write ()
130 vl_socket_client_msg_alloc (int nbytes)
138 vat_time_now (vat_main_t * vam)
140 #if VPP_API_TEST_BUILTIN
141 return vlib_time_now (vam->vlib_main);
143 return clib_time_now (&vam->clib_time);
148 errmsg (char *fmt, ...)
150 vat_main_t *vam = &vat_main;
155 s = va_format (0, fmt, &va);
160 #if VPP_API_TEST_BUILTIN
161 vlib_cli_output (vam->vlib_main, (char *) s);
164 if (vam->ifp != stdin)
165 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
166 vam->input_line_number);
168 fformat (vam->ofp, "%s\n", (char *) s);
176 #if VPP_API_TEST_BUILTIN == 0
178 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
180 vat_main_t *vam = va_arg (*args, vat_main_t *);
181 u32 *result = va_arg (*args, u32 *);
185 if (!unformat (input, "%s", &if_name))
188 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
195 /* Parse an IP4 address %d.%d.%d.%d. */
197 unformat_ip4_address (unformat_input_t * input, va_list * args)
199 u8 *result = va_arg (*args, u8 *);
202 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
205 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217 unformat_ethernet_address (unformat_input_t * input, va_list * args)
219 u8 *result = va_arg (*args, u8 *);
222 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
223 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
227 for (i = 0; i < 6; i++)
228 if (a[i] >= (1 << 8))
231 for (i = 0; i < 6; i++)
237 /* Returns ethernet type as an int in host byte order. */
239 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
242 u16 *result = va_arg (*args, u16 *);
246 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
248 if (type >= (1 << 16))
256 /* Parse an IP46 address. */
258 unformat_ip46_address (unformat_input_t * input, va_list * args)
260 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
261 ip46_type_t type = va_arg (*args, ip46_type_t);
262 if ((type != IP46_TYPE_IP6) &&
263 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
265 ip46_address_mask_ip4 (ip46);
268 else if ((type != IP46_TYPE_IP4) &&
269 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
276 /* Parse an IP6 address. */
278 unformat_ip6_address (unformat_input_t * input, va_list * args)
280 ip6_address_t *result = va_arg (*args, ip6_address_t *);
282 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
283 uword c, n_colon, double_colon_index;
285 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
286 double_colon_index = ARRAY_LEN (hex_quads);
287 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
290 if (c >= '0' && c <= '9')
292 else if (c >= 'a' && c <= 'f')
293 hex_digit = c + 10 - 'a';
294 else if (c >= 'A' && c <= 'F')
295 hex_digit = c + 10 - 'A';
296 else if (c == ':' && n_colon < 2)
300 unformat_put_input (input);
304 /* Too many hex quads. */
305 if (n_hex_quads >= ARRAY_LEN (hex_quads))
310 hex_quad = (hex_quad << 4) | hex_digit;
312 /* Hex quad must fit in 16 bits. */
313 if (n_hex_digits >= 4)
320 /* Save position of :: */
323 /* More than one :: ? */
324 if (double_colon_index < ARRAY_LEN (hex_quads))
326 double_colon_index = n_hex_quads;
329 if (n_colon > 0 && n_hex_digits > 0)
331 hex_quads[n_hex_quads++] = hex_quad;
337 if (n_hex_digits > 0)
338 hex_quads[n_hex_quads++] = hex_quad;
343 /* Expand :: to appropriate number of zero hex quads. */
344 if (double_colon_index < ARRAY_LEN (hex_quads))
346 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
348 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
349 hex_quads[n_zero + i] = hex_quads[i];
351 for (i = 0; i < n_zero; i++)
352 hex_quads[double_colon_index + i] = 0;
354 n_hex_quads = ARRAY_LEN (hex_quads);
357 /* Too few hex quads given. */
358 if (n_hex_quads < ARRAY_LEN (hex_quads))
361 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
362 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
369 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
371 u32 *r = va_arg (*args, u32 *);
374 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
375 foreach_ipsec_policy_action
383 format_ipsec_crypto_alg (u8 * s, va_list * args)
385 u32 i = va_arg (*args, u32);
390 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
391 foreach_ipsec_crypto_alg
394 return format (s, "unknown");
396 return format (s, "%s", t);
400 format_ipsec_integ_alg (u8 * s, va_list * args)
402 u32 i = va_arg (*args, u32);
407 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
408 foreach_ipsec_integ_alg
411 return format (s, "unknown");
413 return format (s, "%s", t);
416 #else /* VPP_API_TEST_BUILTIN == 1 */
418 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
420 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
421 vnet_main_t *vnm = vnet_get_main ();
422 u32 *result = va_arg (*args, u32 *);
424 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
427 #endif /* VPP_API_TEST_BUILTIN */
430 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
432 u32 *r = va_arg (*args, u32 *);
435 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
436 foreach_ipsec_crypto_alg
444 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
446 u32 *r = va_arg (*args, u32 *);
449 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
450 foreach_ipsec_integ_alg
458 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
460 u8 *r = va_arg (*args, u8 *);
462 if (unformat (input, "kbps"))
464 else if (unformat (input, "pps"))
472 unformat_policer_round_type (unformat_input_t * input, va_list * args)
474 u8 *r = va_arg (*args, u8 *);
476 if (unformat (input, "closest"))
477 *r = QOS_ROUND_TO_CLOSEST;
478 else if (unformat (input, "up"))
479 *r = QOS_ROUND_TO_UP;
480 else if (unformat (input, "down"))
481 *r = QOS_ROUND_TO_DOWN;
488 unformat_policer_type (unformat_input_t * input, va_list * args)
490 u8 *r = va_arg (*args, u8 *);
492 if (unformat (input, "1r2c"))
493 *r = QOS_POLICER_TYPE_1R2C;
494 else if (unformat (input, "1r3c"))
495 *r = QOS_POLICER_TYPE_1R3C_RFC_2697;
496 else if (unformat (input, "2r3c-2698"))
497 *r = QOS_POLICER_TYPE_2R3C_RFC_2698;
498 else if (unformat (input, "2r3c-4115"))
499 *r = QOS_POLICER_TYPE_2R3C_RFC_4115;
500 else if (unformat (input, "2r3c-mef5cf1"))
501 *r = QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
508 unformat_dscp (unformat_input_t * input, va_list * va)
510 u8 *r = va_arg (*va, u8 *);
513 #define _(v, f) else if (unformat (input, #f)) *r = IP_DSCP_##f;
521 unformat_policer_action_type (unformat_input_t * input, va_list * va)
523 qos_pol_action_params_st *a = va_arg (*va, qos_pol_action_params_st *);
525 if (unformat (input, "drop"))
526 a->action_type = QOS_ACTION_DROP;
527 else if (unformat (input, "transmit"))
528 a->action_type = QOS_ACTION_TRANSMIT;
529 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
530 a->action_type = QOS_ACTION_MARK_AND_TRANSMIT;
536 #if (VPP_API_TEST_BUILTIN==0)
538 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
539 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
540 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
541 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
544 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
546 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
547 mfib_itf_attribute_t attr;
550 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
552 if (unformat (input, mfib_itf_flag_long_names[attr]))
553 *iflags |= (1 << attr);
555 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
557 if (unformat (input, mfib_itf_flag_names[attr]))
558 *iflags |= (1 << attr);
561 return (old == *iflags ? 0 : 1);
565 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
567 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
568 mfib_entry_attribute_t attr;
571 FOR_EACH_MFIB_ATTRIBUTE (attr)
573 if (unformat (input, mfib_flag_long_names[attr]))
574 *eflags |= (1 << attr);
576 FOR_EACH_MFIB_ATTRIBUTE (attr)
578 if (unformat (input, mfib_flag_names[attr]))
579 *eflags |= (1 << attr);
582 return (old == *eflags ? 0 : 1);
586 format_ip4_address (u8 * s, va_list * args)
588 u8 *a = va_arg (*args, u8 *);
589 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
593 format_ip6_address (u8 * s, va_list * args)
595 ip6_address_t *a = va_arg (*args, ip6_address_t *);
596 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
598 i_max_n_zero = ARRAY_LEN (a->as_u16);
600 i_first_zero = i_max_n_zero;
602 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
604 u32 is_zero = a->as_u16[i] == 0;
605 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
611 if ((!is_zero && n_zeros > max_n_zeros)
612 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
614 i_max_n_zero = i_first_zero;
615 max_n_zeros = n_zeros;
616 i_first_zero = ARRAY_LEN (a->as_u16);
621 last_double_colon = 0;
622 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
624 if (i == i_max_n_zero && max_n_zeros > 1)
626 s = format (s, "::");
627 i += max_n_zeros - 1;
628 last_double_colon = 1;
632 s = format (s, "%s%x",
633 (last_double_colon || i == 0) ? "" : ":",
634 clib_net_to_host_u16 (a->as_u16[i]));
635 last_double_colon = 0;
642 /* Format an IP46 address. */
644 format_ip46_address (u8 * s, va_list * args)
646 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
647 ip46_type_t type = va_arg (*args, ip46_type_t);
653 is_ip4 = ip46_address_is_ip4 (ip46);
664 format (s, "%U", format_ip4_address, &ip46->ip4) :
665 format (s, "%U", format_ip6_address, &ip46->ip6);
669 format_ethernet_address (u8 * s, va_list * args)
671 u8 *a = va_arg (*args, u8 *);
673 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
674 a[0], a[1], a[2], a[3], a[4], a[5]);
679 increment_v4_address (vl_api_ip4_address_t * i)
681 ip4_address_t *a = (ip4_address_t *) i;
684 v = ntohl (a->as_u32) + 1;
685 a->as_u32 = ntohl (v);
689 increment_v6_address (vl_api_ip6_address_t * i)
691 ip6_address_t *a = (ip6_address_t *) i;
694 v0 = clib_net_to_host_u64 (a->as_u64[0]);
695 v1 = clib_net_to_host_u64 (a->as_u64[1]);
700 a->as_u64[0] = clib_net_to_host_u64 (v0);
701 a->as_u64[1] = clib_net_to_host_u64 (v1);
705 increment_address (vl_api_address_t * a)
707 if (a->af == ADDRESS_IP4)
708 increment_v4_address (&a->un.ip4);
709 else if (a->af == ADDRESS_IP6)
710 increment_v6_address (&a->un.ip6);
714 set_ip4_address (vl_api_address_t * a, u32 v)
716 if (a->af == ADDRESS_IP4)
718 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
724 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
727 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
729 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
730 sizeof (ip6_address_t));
734 increment_mac_address (u8 * mac)
736 u64 tmp = *((u64 *) mac);
737 tmp = clib_net_to_host_u64 (tmp);
738 tmp += 1 << 16; /* skip unused (least significant) octets */
739 tmp = clib_host_to_net_u64 (tmp);
741 clib_memcpy (mac, &tmp, 6);
745 vat_json_object_add_address (vat_json_node_t * node,
746 const char *str, const vl_api_address_t * addr)
748 if (ADDRESS_IP6 == addr->af)
752 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
753 vat_json_object_add_ip6 (node, str, ip6);
759 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
760 vat_json_object_add_ip4 (node, str, ip4);
765 vat_json_object_add_prefix (vat_json_node_t * node,
766 const vl_api_prefix_t * prefix)
768 vat_json_object_add_uint (node, "len", prefix->len);
769 vat_json_object_add_address (node, "address", &prefix->address);
772 static void vl_api_create_loopback_reply_t_handler
773 (vl_api_create_loopback_reply_t * mp)
775 vat_main_t *vam = &vat_main;
776 i32 retval = ntohl (mp->retval);
778 vam->retval = retval;
779 vam->regenerate_interface_table = 1;
780 vam->sw_if_index = ntohl (mp->sw_if_index);
781 vam->result_ready = 1;
784 static void vl_api_create_loopback_reply_t_handler_json
785 (vl_api_create_loopback_reply_t * mp)
787 vat_main_t *vam = &vat_main;
788 vat_json_node_t node;
790 vat_json_init_object (&node);
791 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
792 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
794 vat_json_print (vam->ofp, &node);
795 vat_json_free (&node);
796 vam->retval = ntohl (mp->retval);
797 vam->result_ready = 1;
800 static void vl_api_create_loopback_instance_reply_t_handler
801 (vl_api_create_loopback_instance_reply_t * mp)
803 vat_main_t *vam = &vat_main;
804 i32 retval = ntohl (mp->retval);
806 vam->retval = retval;
807 vam->regenerate_interface_table = 1;
808 vam->sw_if_index = ntohl (mp->sw_if_index);
809 vam->result_ready = 1;
812 static void vl_api_create_loopback_instance_reply_t_handler_json
813 (vl_api_create_loopback_instance_reply_t * mp)
815 vat_main_t *vam = &vat_main;
816 vat_json_node_t node;
818 vat_json_init_object (&node);
819 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
820 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
822 vat_json_print (vam->ofp, &node);
823 vat_json_free (&node);
824 vam->retval = ntohl (mp->retval);
825 vam->result_ready = 1;
828 static void vl_api_af_packet_create_reply_t_handler
829 (vl_api_af_packet_create_reply_t * mp)
831 vat_main_t *vam = &vat_main;
832 i32 retval = ntohl (mp->retval);
834 vam->retval = retval;
835 vam->regenerate_interface_table = 1;
836 vam->sw_if_index = ntohl (mp->sw_if_index);
837 vam->result_ready = 1;
840 static void vl_api_af_packet_create_reply_t_handler_json
841 (vl_api_af_packet_create_reply_t * mp)
843 vat_main_t *vam = &vat_main;
844 vat_json_node_t node;
846 vat_json_init_object (&node);
847 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
848 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
850 vat_json_print (vam->ofp, &node);
851 vat_json_free (&node);
853 vam->retval = ntohl (mp->retval);
854 vam->result_ready = 1;
857 static void vl_api_create_vlan_subif_reply_t_handler
858 (vl_api_create_vlan_subif_reply_t * mp)
860 vat_main_t *vam = &vat_main;
861 i32 retval = ntohl (mp->retval);
863 vam->retval = retval;
864 vam->regenerate_interface_table = 1;
865 vam->sw_if_index = ntohl (mp->sw_if_index);
866 vam->result_ready = 1;
869 static void vl_api_create_vlan_subif_reply_t_handler_json
870 (vl_api_create_vlan_subif_reply_t * mp)
872 vat_main_t *vam = &vat_main;
873 vat_json_node_t node;
875 vat_json_init_object (&node);
876 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
877 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
879 vat_json_print (vam->ofp, &node);
880 vat_json_free (&node);
882 vam->retval = ntohl (mp->retval);
883 vam->result_ready = 1;
886 static void vl_api_create_subif_reply_t_handler
887 (vl_api_create_subif_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_create_subif_reply_t_handler_json
899 (vl_api_create_subif_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_interface_name_renumber_reply_t_handler
916 (vl_api_interface_name_renumber_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->result_ready = 1;
926 static void vl_api_interface_name_renumber_reply_t_handler_json
927 (vl_api_interface_name_renumber_reply_t * mp)
929 vat_main_t *vam = &vat_main;
930 vat_json_node_t node;
932 vat_json_init_object (&node);
933 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
935 vat_json_print (vam->ofp, &node);
936 vat_json_free (&node);
938 vam->retval = ntohl (mp->retval);
939 vam->result_ready = 1;
943 * Special-case: build the interface table, maintain
944 * the next loopback sw_if_index vbl.
946 static void vl_api_sw_interface_details_t_handler
947 (vl_api_sw_interface_details_t * mp)
949 vat_main_t *vam = &vat_main;
950 u8 *s = format (0, "%s%c", mp->interface_name, 0);
952 hash_set_mem (vam->sw_if_index_by_interface_name, s,
953 ntohl (mp->sw_if_index));
955 /* In sub interface case, fill the sub interface table entry */
956 if (mp->sw_if_index != mp->sup_sw_if_index)
958 sw_interface_subif_t *sub = NULL;
960 vec_add2 (vam->sw_if_subif_table, sub, 1);
962 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
963 strncpy ((char *) sub->interface_name, (char *) s,
964 vec_len (sub->interface_name));
965 sub->sw_if_index = ntohl (mp->sw_if_index);
966 sub->sub_id = ntohl (mp->sub_id);
968 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
970 sub->sub_number_of_tags = mp->sub_number_of_tags;
971 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
972 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
974 /* vlan tag rewrite */
975 sub->vtr_op = ntohl (mp->vtr_op);
976 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
977 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
978 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
982 static void vl_api_sw_interface_details_t_handler_json
983 (vl_api_sw_interface_details_t * mp)
985 vat_main_t *vam = &vat_main;
986 vat_json_node_t *node = NULL;
988 if (VAT_JSON_ARRAY != vam->json_tree.type)
990 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
991 vat_json_init_array (&vam->json_tree);
993 node = vat_json_array_add (&vam->json_tree);
995 vat_json_init_object (node);
996 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
997 vat_json_object_add_uint (node, "sup_sw_if_index",
998 ntohl (mp->sup_sw_if_index));
999 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
1000 sizeof (mp->l2_address));
1001 vat_json_object_add_string_copy (node, "interface_name",
1002 mp->interface_name);
1003 vat_json_object_add_string_copy (node, "interface_dev_type",
1004 mp->interface_dev_type);
1005 vat_json_object_add_uint (node, "flags", mp->flags);
1006 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
1007 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
1008 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
1009 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
1010 vat_json_object_add_uint (node, "sub_number_of_tags",
1011 mp->sub_number_of_tags);
1012 vat_json_object_add_uint (node, "sub_outer_vlan_id",
1013 ntohs (mp->sub_outer_vlan_id));
1014 vat_json_object_add_uint (node, "sub_inner_vlan_id",
1015 ntohs (mp->sub_inner_vlan_id));
1016 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
1017 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
1018 vat_json_object_add_uint (node, "vtr_push_dot1q",
1019 ntohl (mp->vtr_push_dot1q));
1020 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
1021 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
1022 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
1024 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
1026 format_ethernet_address,
1028 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
1030 format_ethernet_address,
1032 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
1033 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
1037 #if VPP_API_TEST_BUILTIN == 0
1038 static void vl_api_sw_interface_event_t_handler
1039 (vl_api_sw_interface_event_t * mp)
1041 vat_main_t *vam = &vat_main;
1042 if (vam->interface_event_display)
1043 errmsg ("interface flags: sw_if_index %d %s %s",
1044 ntohl (mp->sw_if_index),
1045 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
1046 "admin-up" : "admin-down",
1047 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
1048 "link-up" : "link-down");
1052 __clib_unused static void
1053 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
1055 /* JSON output not supported */
1059 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
1061 vat_main_t *vam = &vat_main;
1062 i32 retval = ntohl (mp->retval);
1064 vam->retval = retval;
1065 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
1066 vam->result_ready = 1;
1070 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
1072 vat_main_t *vam = &vat_main;
1073 vat_json_node_t node;
1077 vat_json_init_object (&node);
1078 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1079 vat_json_object_add_uint (&node, "reply_in_shmem",
1080 ntohl (mp->reply_in_shmem));
1081 /* Toss the shared-memory original... */
1082 oldheap = vl_msg_push_heap ();
1084 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1087 vl_msg_pop_heap (oldheap);
1089 vat_json_print (vam->ofp, &node);
1090 vat_json_free (&node);
1092 vam->retval = ntohl (mp->retval);
1093 vam->result_ready = 1;
1097 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1099 vat_main_t *vam = &vat_main;
1100 i32 retval = ntohl (mp->retval);
1102 vec_reset_length (vam->cmd_reply);
1104 vam->retval = retval;
1106 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1107 vam->result_ready = 1;
1111 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1113 vat_main_t *vam = &vat_main;
1114 vat_json_node_t node;
1115 u8 *reply = 0; /* reply vector */
1117 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1118 vec_reset_length (vam->cmd_reply);
1120 vat_json_init_object (&node);
1121 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1122 vat_json_object_add_string_copy (&node, "reply", reply);
1124 vat_json_print (vam->ofp, &node);
1125 vat_json_free (&node);
1128 vam->retval = ntohl (mp->retval);
1129 vam->result_ready = 1;
1132 static void vl_api_get_node_index_reply_t_handler
1133 (vl_api_get_node_index_reply_t * mp)
1135 vat_main_t *vam = &vat_main;
1136 i32 retval = ntohl (mp->retval);
1137 if (vam->async_mode)
1139 vam->async_errors += (retval < 0);
1143 vam->retval = retval;
1145 errmsg ("node index %d", ntohl (mp->node_index));
1146 vam->result_ready = 1;
1150 static void vl_api_get_node_index_reply_t_handler_json
1151 (vl_api_get_node_index_reply_t * mp)
1153 vat_main_t *vam = &vat_main;
1154 vat_json_node_t node;
1156 vat_json_init_object (&node);
1157 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1158 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1160 vat_json_print (vam->ofp, &node);
1161 vat_json_free (&node);
1163 vam->retval = ntohl (mp->retval);
1164 vam->result_ready = 1;
1167 static void vl_api_get_next_index_reply_t_handler
1168 (vl_api_get_next_index_reply_t * mp)
1170 vat_main_t *vam = &vat_main;
1171 i32 retval = ntohl (mp->retval);
1172 if (vam->async_mode)
1174 vam->async_errors += (retval < 0);
1178 vam->retval = retval;
1180 errmsg ("next node index %d", ntohl (mp->next_index));
1181 vam->result_ready = 1;
1185 static void vl_api_get_next_index_reply_t_handler_json
1186 (vl_api_get_next_index_reply_t * mp)
1188 vat_main_t *vam = &vat_main;
1189 vat_json_node_t node;
1191 vat_json_init_object (&node);
1192 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1193 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1195 vat_json_print (vam->ofp, &node);
1196 vat_json_free (&node);
1198 vam->retval = ntohl (mp->retval);
1199 vam->result_ready = 1;
1202 static void vl_api_add_node_next_reply_t_handler
1203 (vl_api_add_node_next_reply_t * mp)
1205 vat_main_t *vam = &vat_main;
1206 i32 retval = ntohl (mp->retval);
1207 if (vam->async_mode)
1209 vam->async_errors += (retval < 0);
1213 vam->retval = retval;
1215 errmsg ("next index %d", ntohl (mp->next_index));
1216 vam->result_ready = 1;
1220 static void vl_api_add_node_next_reply_t_handler_json
1221 (vl_api_add_node_next_reply_t * mp)
1223 vat_main_t *vam = &vat_main;
1224 vat_json_node_t node;
1226 vat_json_init_object (&node);
1227 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1228 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1230 vat_json_print (vam->ofp, &node);
1231 vat_json_free (&node);
1233 vam->retval = ntohl (mp->retval);
1234 vam->result_ready = 1;
1237 static void vl_api_show_version_reply_t_handler
1238 (vl_api_show_version_reply_t * mp)
1240 vat_main_t *vam = &vat_main;
1241 i32 retval = ntohl (mp->retval);
1245 errmsg (" program: %s", mp->program);
1246 errmsg (" version: %s", mp->version);
1247 errmsg (" build date: %s", mp->build_date);
1248 errmsg ("build directory: %s", mp->build_directory);
1250 vam->retval = retval;
1251 vam->result_ready = 1;
1254 static void vl_api_show_version_reply_t_handler_json
1255 (vl_api_show_version_reply_t * mp)
1257 vat_main_t *vam = &vat_main;
1258 vat_json_node_t node;
1260 vat_json_init_object (&node);
1261 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1262 vat_json_object_add_string_copy (&node, "program", mp->program);
1263 vat_json_object_add_string_copy (&node, "version", mp->version);
1264 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1265 vat_json_object_add_string_copy (&node, "build_directory",
1266 mp->build_directory);
1268 vat_json_print (vam->ofp, &node);
1269 vat_json_free (&node);
1271 vam->retval = ntohl (mp->retval);
1272 vam->result_ready = 1;
1275 static void vl_api_show_threads_reply_t_handler
1276 (vl_api_show_threads_reply_t * mp)
1278 vat_main_t *vam = &vat_main;
1279 i32 retval = ntohl (mp->retval);
1283 count = ntohl (mp->count);
1285 for (i = 0; i < count; i++)
1287 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1288 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1289 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1290 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1291 ntohl (mp->thread_data[i].cpu_socket));
1293 vam->retval = retval;
1294 vam->result_ready = 1;
1297 static void vl_api_show_threads_reply_t_handler_json
1298 (vl_api_show_threads_reply_t * mp)
1300 vat_main_t *vam = &vat_main;
1301 vat_json_node_t node;
1302 vl_api_thread_data_t *td;
1303 i32 retval = ntohl (mp->retval);
1307 count = ntohl (mp->count);
1309 vat_json_init_object (&node);
1310 vat_json_object_add_int (&node, "retval", retval);
1311 vat_json_object_add_uint (&node, "count", count);
1313 for (i = 0; i < count; i++)
1315 td = &mp->thread_data[i];
1316 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1317 vat_json_object_add_string_copy (&node, "name", td->name);
1318 vat_json_object_add_string_copy (&node, "type", td->type);
1319 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1320 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1321 vat_json_object_add_int (&node, "core", ntohl (td->id));
1322 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1325 vat_json_print (vam->ofp, &node);
1326 vat_json_free (&node);
1328 vam->retval = retval;
1329 vam->result_ready = 1;
1333 api_show_threads (vat_main_t * vam)
1335 vl_api_show_threads_t *mp;
1339 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1340 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1342 M (SHOW_THREADS, mp);
1350 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1352 u32 n_macs = ntohl (mp->n_macs);
1353 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1354 ntohl (mp->pid), mp->client_index, n_macs);
1356 for (i = 0; i < n_macs; i++)
1358 vl_api_mac_entry_t *mac = &mp->mac[i];
1359 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1360 i + 1, ntohl (mac->sw_if_index),
1361 format_ethernet_address, mac->mac_addr, mac->action);
1368 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1370 /* JSON output not supported */
1373 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1374 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1377 * Special-case: build the bridge domain table, maintain
1378 * the next bd id vbl.
1380 static void vl_api_bridge_domain_details_t_handler
1381 (vl_api_bridge_domain_details_t * mp)
1383 vat_main_t *vam = &vat_main;
1384 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1387 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1388 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1390 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1391 ntohl (mp->bd_id), mp->learn, mp->forward,
1392 mp->flood, ntohl (mp->bvi_sw_if_index),
1393 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1397 vl_api_bridge_domain_sw_if_t *sw_ifs;
1398 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1401 sw_ifs = mp->sw_if_details;
1402 for (i = 0; i < n_sw_ifs; i++)
1408 sw_if_index = ntohl (sw_ifs->sw_if_index);
1411 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1413 if ((u32) p->value[0] == sw_if_index)
1415 sw_if_name = (u8 *)(p->key);
1420 print (vam->ofp, "%7d %3d %s", sw_if_index,
1421 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1422 "sw_if_index not found!");
1429 static void vl_api_bridge_domain_details_t_handler_json
1430 (vl_api_bridge_domain_details_t * mp)
1432 vat_main_t *vam = &vat_main;
1433 vat_json_node_t *node, *array = NULL;
1434 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1436 if (VAT_JSON_ARRAY != vam->json_tree.type)
1438 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1439 vat_json_init_array (&vam->json_tree);
1441 node = vat_json_array_add (&vam->json_tree);
1443 vat_json_init_object (node);
1444 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1445 vat_json_object_add_uint (node, "flood", mp->flood);
1446 vat_json_object_add_uint (node, "forward", mp->forward);
1447 vat_json_object_add_uint (node, "learn", mp->learn);
1448 vat_json_object_add_uint (node, "bvi_sw_if_index",
1449 ntohl (mp->bvi_sw_if_index));
1450 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1451 array = vat_json_object_add (node, "sw_if");
1452 vat_json_init_array (array);
1458 vl_api_bridge_domain_sw_if_t *sw_ifs;
1461 sw_ifs = mp->sw_if_details;
1462 for (i = 0; i < n_sw_ifs; i++)
1464 node = vat_json_array_add (array);
1465 vat_json_init_object (node);
1466 vat_json_object_add_uint (node, "sw_if_index",
1467 ntohl (sw_ifs->sw_if_index));
1468 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1474 static void vl_api_control_ping_reply_t_handler
1475 (vl_api_control_ping_reply_t * mp)
1477 vat_main_t *vam = &vat_main;
1478 i32 retval = ntohl (mp->retval);
1479 if (vam->async_mode)
1481 vam->async_errors += (retval < 0);
1485 vam->retval = retval;
1486 vam->result_ready = 1;
1488 if (vam->socket_client_main)
1489 vam->socket_client_main->control_pings_outstanding--;
1492 static void vl_api_control_ping_reply_t_handler_json
1493 (vl_api_control_ping_reply_t * mp)
1495 vat_main_t *vam = &vat_main;
1496 i32 retval = ntohl (mp->retval);
1498 if (VAT_JSON_NONE != vam->json_tree.type)
1500 vat_json_print (vam->ofp, &vam->json_tree);
1501 vat_json_free (&vam->json_tree);
1502 vam->json_tree.type = VAT_JSON_NONE;
1507 vat_json_init_array (&vam->json_tree);
1508 vat_json_print (vam->ofp, &vam->json_tree);
1509 vam->json_tree.type = VAT_JSON_NONE;
1512 vam->retval = retval;
1513 vam->result_ready = 1;
1517 vl_api_bridge_domain_set_mac_age_reply_t_handler
1518 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1520 vat_main_t *vam = &vat_main;
1521 i32 retval = ntohl (mp->retval);
1522 if (vam->async_mode)
1524 vam->async_errors += (retval < 0);
1528 vam->retval = retval;
1529 vam->result_ready = 1;
1533 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1534 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1536 vat_main_t *vam = &vat_main;
1537 vat_json_node_t node;
1539 vat_json_init_object (&node);
1540 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1542 vat_json_print (vam->ofp, &node);
1543 vat_json_free (&node);
1545 vam->retval = ntohl (mp->retval);
1546 vam->result_ready = 1;
1550 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1552 vat_main_t *vam = &vat_main;
1553 i32 retval = ntohl (mp->retval);
1554 if (vam->async_mode)
1556 vam->async_errors += (retval < 0);
1560 vam->retval = retval;
1561 vam->result_ready = 1;
1565 static void vl_api_l2_flags_reply_t_handler_json
1566 (vl_api_l2_flags_reply_t * mp)
1568 vat_main_t *vam = &vat_main;
1569 vat_json_node_t node;
1571 vat_json_init_object (&node);
1572 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1573 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1574 ntohl (mp->resulting_feature_bitmap));
1576 vat_json_print (vam->ofp, &node);
1577 vat_json_free (&node);
1579 vam->retval = ntohl (mp->retval);
1580 vam->result_ready = 1;
1583 static void vl_api_bridge_flags_reply_t_handler
1584 (vl_api_bridge_flags_reply_t * mp)
1586 vat_main_t *vam = &vat_main;
1587 i32 retval = ntohl (mp->retval);
1588 if (vam->async_mode)
1590 vam->async_errors += (retval < 0);
1594 vam->retval = retval;
1595 vam->result_ready = 1;
1599 static void vl_api_bridge_flags_reply_t_handler_json
1600 (vl_api_bridge_flags_reply_t * mp)
1602 vat_main_t *vam = &vat_main;
1603 vat_json_node_t node;
1605 vat_json_init_object (&node);
1606 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1607 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1608 ntohl (mp->resulting_feature_bitmap));
1610 vat_json_print (vam->ofp, &node);
1611 vat_json_free (&node);
1613 vam->retval = ntohl (mp->retval);
1614 vam->result_ready = 1;
1618 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1620 vat_main_t *vam = &vat_main;
1621 i32 retval = ntohl (mp->retval);
1622 if (vam->async_mode)
1624 vam->async_errors += (retval < 0);
1628 vam->retval = retval;
1629 vam->sw_if_index = ntohl (mp->sw_if_index);
1630 vam->result_ready = 1;
1635 static void vl_api_tap_create_v2_reply_t_handler_json
1636 (vl_api_tap_create_v2_reply_t * mp)
1638 vat_main_t *vam = &vat_main;
1639 vat_json_node_t node;
1641 vat_json_init_object (&node);
1642 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1643 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1645 vat_json_print (vam->ofp, &node);
1646 vat_json_free (&node);
1648 vam->retval = ntohl (mp->retval);
1649 vam->result_ready = 1;
1654 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1656 vat_main_t *vam = &vat_main;
1657 i32 retval = ntohl (mp->retval);
1658 if (vam->async_mode)
1660 vam->async_errors += (retval < 0);
1664 vam->retval = retval;
1665 vam->result_ready = 1;
1669 static void vl_api_tap_delete_v2_reply_t_handler_json
1670 (vl_api_tap_delete_v2_reply_t * mp)
1672 vat_main_t *vam = &vat_main;
1673 vat_json_node_t node;
1675 vat_json_init_object (&node);
1676 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1678 vat_json_print (vam->ofp, &node);
1679 vat_json_free (&node);
1681 vam->retval = ntohl (mp->retval);
1682 vam->result_ready = 1;
1686 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1689 vat_main_t *vam = &vat_main;
1690 i32 retval = ntohl (mp->retval);
1691 if (vam->async_mode)
1693 vam->async_errors += (retval < 0);
1697 vam->retval = retval;
1698 vam->sw_if_index = ntohl (mp->sw_if_index);
1699 vam->result_ready = 1;
1703 static void vl_api_virtio_pci_create_reply_t_handler_json
1704 (vl_api_virtio_pci_create_reply_t * mp)
1706 vat_main_t *vam = &vat_main;
1707 vat_json_node_t node;
1709 vat_json_init_object (&node);
1710 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1711 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1713 vat_json_print (vam->ofp, &node);
1714 vat_json_free (&node);
1716 vam->retval = ntohl (mp->retval);
1717 vam->result_ready = 1;
1722 vl_api_virtio_pci_create_v2_reply_t_handler
1723 (vl_api_virtio_pci_create_v2_reply_t * mp)
1725 vat_main_t *vam = &vat_main;
1726 i32 retval = ntohl (mp->retval);
1727 if (vam->async_mode)
1729 vam->async_errors += (retval < 0);
1733 vam->retval = retval;
1734 vam->sw_if_index = ntohl (mp->sw_if_index);
1735 vam->result_ready = 1;
1739 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1740 (vl_api_virtio_pci_create_v2_reply_t * mp)
1742 vat_main_t *vam = &vat_main;
1743 vat_json_node_t node;
1745 vat_json_init_object (&node);
1746 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1747 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1749 vat_json_print (vam->ofp, &node);
1750 vat_json_free (&node);
1752 vam->retval = ntohl (mp->retval);
1753 vam->result_ready = 1;
1757 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1760 vat_main_t *vam = &vat_main;
1761 i32 retval = ntohl (mp->retval);
1762 if (vam->async_mode)
1764 vam->async_errors += (retval < 0);
1768 vam->retval = retval;
1769 vam->result_ready = 1;
1773 static void vl_api_virtio_pci_delete_reply_t_handler_json
1774 (vl_api_virtio_pci_delete_reply_t * mp)
1776 vat_main_t *vam = &vat_main;
1777 vat_json_node_t node;
1779 vat_json_init_object (&node);
1780 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1782 vat_json_print (vam->ofp, &node);
1783 vat_json_free (&node);
1785 vam->retval = ntohl (mp->retval);
1786 vam->result_ready = 1;
1790 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1792 vat_main_t *vam = &vat_main;
1793 i32 retval = ntohl (mp->retval);
1795 if (vam->async_mode)
1797 vam->async_errors += (retval < 0);
1801 vam->retval = retval;
1802 vam->sw_if_index = ntohl (mp->sw_if_index);
1803 vam->result_ready = 1;
1807 static void vl_api_bond_create_reply_t_handler_json
1808 (vl_api_bond_create_reply_t * mp)
1810 vat_main_t *vam = &vat_main;
1811 vat_json_node_t node;
1813 vat_json_init_object (&node);
1814 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1815 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1817 vat_json_print (vam->ofp, &node);
1818 vat_json_free (&node);
1820 vam->retval = ntohl (mp->retval);
1821 vam->result_ready = 1;
1825 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1827 vat_main_t *vam = &vat_main;
1828 i32 retval = ntohl (mp->retval);
1830 if (vam->async_mode)
1832 vam->async_errors += (retval < 0);
1836 vam->retval = retval;
1837 vam->sw_if_index = ntohl (mp->sw_if_index);
1838 vam->result_ready = 1;
1842 static void vl_api_bond_create2_reply_t_handler_json
1843 (vl_api_bond_create2_reply_t * mp)
1845 vat_main_t *vam = &vat_main;
1846 vat_json_node_t node;
1848 vat_json_init_object (&node);
1849 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1850 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1852 vat_json_print (vam->ofp, &node);
1853 vat_json_free (&node);
1855 vam->retval = ntohl (mp->retval);
1856 vam->result_ready = 1;
1860 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1862 vat_main_t *vam = &vat_main;
1863 i32 retval = ntohl (mp->retval);
1865 if (vam->async_mode)
1867 vam->async_errors += (retval < 0);
1871 vam->retval = retval;
1872 vam->result_ready = 1;
1876 static void vl_api_bond_delete_reply_t_handler_json
1877 (vl_api_bond_delete_reply_t * mp)
1879 vat_main_t *vam = &vat_main;
1880 vat_json_node_t node;
1882 vat_json_init_object (&node);
1883 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1885 vat_json_print (vam->ofp, &node);
1886 vat_json_free (&node);
1888 vam->retval = ntohl (mp->retval);
1889 vam->result_ready = 1;
1893 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
1895 vat_main_t *vam = &vat_main;
1896 i32 retval = ntohl (mp->retval);
1898 if (vam->async_mode)
1900 vam->async_errors += (retval < 0);
1904 vam->retval = retval;
1905 vam->result_ready = 1;
1909 static void vl_api_bond_add_member_reply_t_handler_json
1910 (vl_api_bond_add_member_reply_t * mp)
1912 vat_main_t *vam = &vat_main;
1913 vat_json_node_t node;
1915 vat_json_init_object (&node);
1916 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1918 vat_json_print (vam->ofp, &node);
1919 vat_json_free (&node);
1921 vam->retval = ntohl (mp->retval);
1922 vam->result_ready = 1;
1926 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
1929 vat_main_t *vam = &vat_main;
1930 i32 retval = ntohl (mp->retval);
1932 if (vam->async_mode)
1934 vam->async_errors += (retval < 0);
1938 vam->retval = retval;
1939 vam->result_ready = 1;
1943 static void vl_api_bond_detach_member_reply_t_handler_json
1944 (vl_api_bond_detach_member_reply_t * mp)
1946 vat_main_t *vam = &vat_main;
1947 vat_json_node_t node;
1949 vat_json_init_object (&node);
1950 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1952 vat_json_print (vam->ofp, &node);
1953 vat_json_free (&node);
1955 vam->retval = ntohl (mp->retval);
1956 vam->result_ready = 1;
1960 api_sw_interface_set_bond_weight (vat_main_t * vam)
1962 unformat_input_t *i = vam->input;
1963 vl_api_sw_interface_set_bond_weight_t *mp;
1964 u32 sw_if_index = ~0;
1966 u8 weight_enter = 0;
1969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1971 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1973 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1975 else if (unformat (i, "weight %u", &weight))
1981 if (sw_if_index == ~0)
1983 errmsg ("missing interface name or sw_if_index");
1986 if (weight_enter == 0)
1988 errmsg ("missing valid weight");
1992 /* Construct the API message */
1993 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
1994 mp->sw_if_index = ntohl (sw_if_index);
1995 mp->weight = ntohl (weight);
2002 static void vl_api_sw_bond_interface_details_t_handler
2003 (vl_api_sw_bond_interface_details_t * mp)
2005 vat_main_t *vam = &vat_main;
2008 "%-16s %-12d %-12U %-13U %-14u %-14u",
2009 mp->interface_name, ntohl (mp->sw_if_index),
2010 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
2011 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
2014 static void vl_api_sw_bond_interface_details_t_handler_json
2015 (vl_api_sw_bond_interface_details_t * mp)
2017 vat_main_t *vam = &vat_main;
2018 vat_json_node_t *node = NULL;
2020 if (VAT_JSON_ARRAY != vam->json_tree.type)
2022 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2023 vat_json_init_array (&vam->json_tree);
2025 node = vat_json_array_add (&vam->json_tree);
2027 vat_json_init_object (node);
2028 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2029 vat_json_object_add_string_copy (node, "interface_name",
2030 mp->interface_name);
2031 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
2032 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
2033 vat_json_object_add_uint (node, "active_members",
2034 ntohl (mp->active_members));
2035 vat_json_object_add_uint (node, "members", ntohl (mp->members));
2039 api_sw_bond_interface_dump (vat_main_t * vam)
2041 unformat_input_t *i = vam->input;
2042 vl_api_sw_bond_interface_dump_t *mp;
2043 vl_api_control_ping_t *mp_ping;
2045 u32 sw_if_index = ~0;
2047 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2049 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2058 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
2059 "interface name", "sw_if_index", "mode", "load balance",
2060 "active members", "members");
2062 /* Get list of bond interfaces */
2063 M (SW_BOND_INTERFACE_DUMP, mp);
2064 mp->sw_if_index = ntohl (sw_if_index);
2067 /* Use a control ping for synchronization */
2068 MPING (CONTROL_PING, mp_ping);
2075 static void vl_api_sw_member_interface_details_t_handler
2076 (vl_api_sw_member_interface_details_t * mp)
2078 vat_main_t *vam = &vat_main;
2081 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2082 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2083 ntohl (mp->weight), mp->is_local_numa);
2086 static void vl_api_sw_member_interface_details_t_handler_json
2087 (vl_api_sw_member_interface_details_t * mp)
2089 vat_main_t *vam = &vat_main;
2090 vat_json_node_t *node = NULL;
2092 if (VAT_JSON_ARRAY != vam->json_tree.type)
2094 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2095 vat_json_init_array (&vam->json_tree);
2097 node = vat_json_array_add (&vam->json_tree);
2099 vat_json_init_object (node);
2100 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2101 vat_json_object_add_string_copy (node, "interface_name",
2102 mp->interface_name);
2103 vat_json_object_add_uint (node, "passive", mp->is_passive);
2104 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2105 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2106 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2110 api_sw_member_interface_dump (vat_main_t * vam)
2112 unformat_input_t *i = vam->input;
2113 vl_api_sw_member_interface_dump_t *mp;
2114 vl_api_control_ping_t *mp_ping;
2115 u32 sw_if_index = ~0;
2116 u8 sw_if_index_set = 0;
2119 /* Parse args required to build the message */
2120 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2122 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2123 sw_if_index_set = 1;
2124 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2125 sw_if_index_set = 1;
2130 if (sw_if_index_set == 0)
2132 errmsg ("missing vpp interface name. ");
2137 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2138 "member interface name", "sw_if_index", "passive", "long_timeout",
2139 "weight", "local numa");
2141 /* Get list of bond interfaces */
2142 M (SW_MEMBER_INTERFACE_DUMP, mp);
2143 mp->sw_if_index = ntohl (sw_if_index);
2146 /* Use a control ping for synchronization */
2147 MPING (CONTROL_PING, mp_ping);
2154 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2155 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2157 vat_main_t *vam = &vat_main;
2158 i32 retval = ntohl (mp->retval);
2159 if (vam->async_mode)
2161 vam->async_errors += (retval < 0);
2165 vam->retval = retval;
2166 vam->sw_if_index = ntohl (mp->sw_if_index);
2167 vam->result_ready = 1;
2169 vam->regenerate_interface_table = 1;
2172 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2173 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2175 vat_main_t *vam = &vat_main;
2176 vat_json_node_t node;
2178 vat_json_init_object (&node);
2179 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2180 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2181 ntohl (mp->sw_if_index));
2183 vat_json_print (vam->ofp, &node);
2184 vat_json_free (&node);
2186 vam->retval = ntohl (mp->retval);
2187 vam->result_ready = 1;
2190 static void vl_api_create_vhost_user_if_reply_t_handler
2191 (vl_api_create_vhost_user_if_reply_t * mp)
2193 vat_main_t *vam = &vat_main;
2194 i32 retval = ntohl (mp->retval);
2195 if (vam->async_mode)
2197 vam->async_errors += (retval < 0);
2201 vam->retval = retval;
2202 vam->sw_if_index = ntohl (mp->sw_if_index);
2203 vam->result_ready = 1;
2205 vam->regenerate_interface_table = 1;
2208 static void vl_api_create_vhost_user_if_reply_t_handler_json
2209 (vl_api_create_vhost_user_if_reply_t * mp)
2211 vat_main_t *vam = &vat_main;
2212 vat_json_node_t node;
2214 vat_json_init_object (&node);
2215 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2216 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2218 vat_json_print (vam->ofp, &node);
2219 vat_json_free (&node);
2221 vam->retval = ntohl (mp->retval);
2222 vam->result_ready = 1;
2225 static void vl_api_create_vhost_user_if_v2_reply_t_handler
2226 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2228 vat_main_t *vam = &vat_main;
2229 i32 retval = ntohl (mp->retval);
2230 if (vam->async_mode)
2232 vam->async_errors += (retval < 0);
2236 vam->retval = retval;
2237 vam->sw_if_index = ntohl (mp->sw_if_index);
2238 vam->result_ready = 1;
2240 vam->regenerate_interface_table = 1;
2243 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2244 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2246 vat_main_t *vam = &vat_main;
2247 vat_json_node_t node;
2249 vat_json_init_object (&node);
2250 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2251 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2253 vat_json_print (vam->ofp, &node);
2254 vat_json_free (&node);
2256 vam->retval = ntohl (mp->retval);
2257 vam->result_ready = 1;
2260 static void vl_api_ip_address_details_t_handler
2261 (vl_api_ip_address_details_t * mp)
2263 vat_main_t *vam = &vat_main;
2264 static ip_address_details_t empty_ip_address_details = { {0} };
2265 ip_address_details_t *address = NULL;
2266 ip_details_t *current_ip_details = NULL;
2267 ip_details_t *details = NULL;
2269 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2271 if (!details || vam->current_sw_if_index >= vec_len (details)
2272 || !details[vam->current_sw_if_index].present)
2274 errmsg ("ip address details arrived but not stored");
2275 errmsg ("ip_dump should be called first");
2279 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2281 #define addresses (current_ip_details->addr)
2283 vec_validate_init_empty (addresses, vec_len (addresses),
2284 empty_ip_address_details);
2286 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2288 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2289 address->prefix_length = mp->prefix.len;
2293 static void vl_api_ip_address_details_t_handler_json
2294 (vl_api_ip_address_details_t * mp)
2296 vat_main_t *vam = &vat_main;
2297 vat_json_node_t *node = NULL;
2299 if (VAT_JSON_ARRAY != vam->json_tree.type)
2301 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2302 vat_json_init_array (&vam->json_tree);
2304 node = vat_json_array_add (&vam->json_tree);
2306 vat_json_init_object (node);
2307 vat_json_object_add_prefix (node, &mp->prefix);
2311 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2313 vat_main_t *vam = &vat_main;
2314 static ip_details_t empty_ip_details = { 0 };
2315 ip_details_t *ip = NULL;
2316 u32 sw_if_index = ~0;
2318 sw_if_index = ntohl (mp->sw_if_index);
2320 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2321 sw_if_index, empty_ip_details);
2323 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2330 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2332 vat_main_t *vam = &vat_main;
2334 if (VAT_JSON_ARRAY != vam->json_tree.type)
2336 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2337 vat_json_init_array (&vam->json_tree);
2339 vat_json_array_add_uint (&vam->json_tree,
2340 clib_net_to_host_u32 (mp->sw_if_index));
2343 static void vl_api_get_first_msg_id_reply_t_handler
2344 (vl_api_get_first_msg_id_reply_t * mp)
2346 vat_main_t *vam = &vat_main;
2347 i32 retval = ntohl (mp->retval);
2349 if (vam->async_mode)
2351 vam->async_errors += (retval < 0);
2355 vam->retval = retval;
2356 vam->result_ready = 1;
2360 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2364 static void vl_api_get_first_msg_id_reply_t_handler_json
2365 (vl_api_get_first_msg_id_reply_t * mp)
2367 vat_main_t *vam = &vat_main;
2368 vat_json_node_t node;
2370 vat_json_init_object (&node);
2371 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2372 vat_json_object_add_uint (&node, "first_msg_id",
2373 (uint) ntohs (mp->first_msg_id));
2375 vat_json_print (vam->ofp, &node);
2376 vat_json_free (&node);
2378 vam->retval = ntohl (mp->retval);
2379 vam->result_ready = 1;
2382 static void vl_api_get_node_graph_reply_t_handler
2383 (vl_api_get_node_graph_reply_t * mp)
2385 vat_main_t *vam = &vat_main;
2386 i32 retval = ntohl (mp->retval);
2387 u8 *pvt_copy, *reply;
2392 if (vam->async_mode)
2394 vam->async_errors += (retval < 0);
2398 vam->retval = retval;
2399 vam->result_ready = 1;
2402 /* "Should never happen..." */
2406 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2407 pvt_copy = vec_dup (reply);
2409 /* Toss the shared-memory original... */
2410 oldheap = vl_msg_push_heap ();
2414 vl_msg_pop_heap (oldheap);
2416 if (vam->graph_nodes)
2418 hash_free (vam->graph_node_index_by_name);
2420 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2422 node = vam->graph_nodes[0][i];
2423 vec_free (node->name);
2424 vec_free (node->next_nodes);
2427 vec_free (vam->graph_nodes[0]);
2428 vec_free (vam->graph_nodes);
2431 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2432 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2433 vec_free (pvt_copy);
2435 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2437 node = vam->graph_nodes[0][i];
2438 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2442 static void vl_api_get_node_graph_reply_t_handler_json
2443 (vl_api_get_node_graph_reply_t * mp)
2445 vat_main_t *vam = &vat_main;
2447 vat_json_node_t node;
2450 /* $$$$ make this real? */
2451 vat_json_init_object (&node);
2452 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2453 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2455 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2457 /* Toss the shared-memory original... */
2458 oldheap = vl_msg_push_heap ();
2462 vl_msg_pop_heap (oldheap);
2464 vat_json_print (vam->ofp, &node);
2465 vat_json_free (&node);
2467 vam->retval = ntohl (mp->retval);
2468 vam->result_ready = 1;
2472 format_policer_type (u8 * s, va_list * va)
2474 u32 i = va_arg (*va, u32);
2476 if (i == QOS_POLICER_TYPE_1R2C)
2477 s = format (s, "1r2c");
2478 else if (i == QOS_POLICER_TYPE_1R3C_RFC_2697)
2479 s = format (s, "1r3c");
2480 else if (i == QOS_POLICER_TYPE_2R3C_RFC_2698)
2481 s = format (s, "2r3c-2698");
2482 else if (i == QOS_POLICER_TYPE_2R3C_RFC_4115)
2483 s = format (s, "2r3c-4115");
2484 else if (i == QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2485 s = format (s, "2r3c-mef5cf1");
2487 s = format (s, "ILLEGAL");
2492 format_policer_rate_type (u8 * s, va_list * va)
2494 u32 i = va_arg (*va, u32);
2496 if (i == QOS_RATE_KBPS)
2497 s = format (s, "kbps");
2498 else if (i == QOS_RATE_PPS)
2499 s = format (s, "pps");
2501 s = format (s, "ILLEGAL");
2506 format_policer_round_type (u8 * s, va_list * va)
2508 u32 i = va_arg (*va, u32);
2510 if (i == QOS_ROUND_TO_CLOSEST)
2511 s = format (s, "closest");
2512 else if (i == QOS_ROUND_TO_UP)
2513 s = format (s, "up");
2514 else if (i == QOS_ROUND_TO_DOWN)
2515 s = format (s, "down");
2517 s = format (s, "ILLEGAL");
2522 format_policer_action_type (u8 * s, va_list * va)
2524 u32 i = va_arg (*va, u32);
2526 if (i == QOS_ACTION_DROP)
2527 s = format (s, "drop");
2528 else if (i == QOS_ACTION_TRANSMIT)
2529 s = format (s, "transmit");
2530 else if (i == QOS_ACTION_MARK_AND_TRANSMIT)
2531 s = format (s, "mark-and-transmit");
2533 s = format (s, "ILLEGAL");
2538 format_dscp (u8 * s, va_list * va)
2540 u32 i = va_arg (*va, u32);
2547 return (format (s, "%s", #f));
2551 s = format (s, "%s", t);
2552 return (format (s, "ILLEGAL"));
2556 vl_api_policer_details_t_handler (vl_api_policer_details_t * mp)
2558 vat_main_t *vam = &vat_main;
2559 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2561 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2562 conform_dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2564 conform_dscp_str = format (0, "");
2566 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2567 exceed_dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2569 exceed_dscp_str = format (0, "");
2571 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2572 violate_dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2574 violate_dscp_str = format (0, "");
2576 print (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2577 "rate type %U, round type %U, %s rate, %s color-aware, "
2578 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2579 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2580 "conform action %U%s, exceed action %U%s, violate action %U%s",
2582 format_policer_type, mp->type,
2585 clib_net_to_host_u64 (mp->cb),
2586 clib_net_to_host_u64 (mp->eb),
2587 format_policer_rate_type, mp->rate_type,
2588 format_policer_round_type, mp->round_type,
2589 mp->single_rate ? "single" : "dual",
2590 mp->color_aware ? "is" : "not",
2591 ntohl (mp->cir_tokens_per_period),
2592 ntohl (mp->pir_tokens_per_period),
2594 ntohl (mp->current_limit),
2595 ntohl (mp->current_bucket),
2596 ntohl (mp->extended_limit),
2597 ntohl (mp->extended_bucket),
2598 clib_net_to_host_u64 (mp->last_update_time),
2599 format_policer_action_type, mp->conform_action.type,
2601 format_policer_action_type, mp->exceed_action.type,
2603 format_policer_action_type, mp->violate_action.type,
2606 vec_free (conform_dscp_str);
2607 vec_free (exceed_dscp_str);
2608 vec_free (violate_dscp_str);
2611 static void vl_api_policer_details_t_handler_json
2612 (vl_api_policer_details_t * mp)
2614 vat_main_t *vam = &vat_main;
2615 vat_json_node_t *node;
2616 u8 *rate_type_str, *round_type_str, *type_str;
2617 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2619 rate_type_str = format (0, "%U", format_policer_rate_type, mp->rate_type);
2621 format (0, "%U", format_policer_round_type, mp->round_type);
2622 type_str = format (0, "%U", format_policer_type, mp->type);
2623 conform_action_str = format (0, "%U", format_policer_action_type,
2624 mp->conform_action.type);
2625 exceed_action_str = format (0, "%U", format_policer_action_type,
2626 mp->exceed_action.type);
2627 violate_action_str = format (0, "%U", format_policer_action_type,
2628 mp->violate_action.type);
2630 if (VAT_JSON_ARRAY != vam->json_tree.type)
2632 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2633 vat_json_init_array (&vam->json_tree);
2635 node = vat_json_array_add (&vam->json_tree);
2637 vat_json_init_object (node);
2638 vat_json_object_add_string_copy (node, "name", mp->name);
2639 vat_json_object_add_uint (node, "cir", ntohl (mp->cir));
2640 vat_json_object_add_uint (node, "eir", ntohl (mp->eir));
2641 vat_json_object_add_uint (node, "cb", clib_net_to_host_u64 (mp->cb));
2642 vat_json_object_add_uint (node, "eb", clib_net_to_host_u64 (mp->eb));
2643 vat_json_object_add_string_copy (node, "rate_type", rate_type_str);
2644 vat_json_object_add_string_copy (node, "round_type", round_type_str);
2645 vat_json_object_add_string_copy (node, "type", type_str);
2646 vat_json_object_add_uint (node, "single_rate", mp->single_rate);
2647 vat_json_object_add_uint (node, "color_aware", mp->color_aware);
2648 vat_json_object_add_uint (node, "scale", ntohl (mp->scale));
2649 vat_json_object_add_uint (node, "cir_tokens_per_period",
2650 ntohl (mp->cir_tokens_per_period));
2651 vat_json_object_add_uint (node, "eir_tokens_per_period",
2652 ntohl (mp->pir_tokens_per_period));
2653 vat_json_object_add_uint (node, "current_limit", ntohl (mp->current_limit));
2654 vat_json_object_add_uint (node, "current_bucket",
2655 ntohl (mp->current_bucket));
2656 vat_json_object_add_uint (node, "extended_limit",
2657 ntohl (mp->extended_limit));
2658 vat_json_object_add_uint (node, "extended_bucket",
2659 ntohl (mp->extended_bucket));
2660 vat_json_object_add_uint (node, "last_update_time",
2661 ntohl (mp->last_update_time));
2662 vat_json_object_add_string_copy (node, "conform_action",
2663 conform_action_str);
2664 if (mp->conform_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2666 u8 *dscp_str = format (0, "%U", format_dscp, mp->conform_action.dscp);
2667 vat_json_object_add_string_copy (node, "conform_dscp", dscp_str);
2668 vec_free (dscp_str);
2670 vat_json_object_add_string_copy (node, "exceed_action", exceed_action_str);
2671 if (mp->exceed_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2673 u8 *dscp_str = format (0, "%U", format_dscp, mp->exceed_action.dscp);
2674 vat_json_object_add_string_copy (node, "exceed_dscp", dscp_str);
2675 vec_free (dscp_str);
2677 vat_json_object_add_string_copy (node, "violate_action",
2678 violate_action_str);
2679 if (mp->violate_action.type == SSE2_QOS_ACTION_API_MARK_AND_TRANSMIT)
2681 u8 *dscp_str = format (0, "%U", format_dscp, mp->violate_action.dscp);
2682 vat_json_object_add_string_copy (node, "violate_dscp", dscp_str);
2683 vec_free (dscp_str);
2686 vec_free (rate_type_str);
2687 vec_free (round_type_str);
2688 vec_free (type_str);
2689 vec_free (conform_action_str);
2690 vec_free (exceed_action_str);
2691 vec_free (violate_action_str);
2694 static void vl_api_policer_add_del_reply_t_handler
2695 (vl_api_policer_add_del_reply_t * mp)
2697 vat_main_t *vam = &vat_main;
2698 i32 retval = ntohl (mp->retval);
2699 if (vam->async_mode)
2701 vam->async_errors += (retval < 0);
2705 vam->retval = retval;
2706 vam->result_ready = 1;
2707 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2709 * Note: this is just barely thread-safe, depends on
2710 * the main thread spinning waiting for an answer...
2712 errmsg ("policer index %d", ntohl (mp->policer_index));
2716 static void vl_api_policer_add_del_reply_t_handler_json
2717 (vl_api_policer_add_del_reply_t * mp)
2719 vat_main_t *vam = &vat_main;
2720 vat_json_node_t node;
2722 vat_json_init_object (&node);
2723 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2724 vat_json_object_add_uint (&node, "policer_index",
2725 ntohl (mp->policer_index));
2727 vat_json_print (vam->ofp, &node);
2728 vat_json_free (&node);
2730 vam->retval = ntohl (mp->retval);
2731 vam->result_ready = 1;
2734 /* Format hex dump. */
2736 format_hex_bytes (u8 * s, va_list * va)
2738 u8 *bytes = va_arg (*va, u8 *);
2739 int n_bytes = va_arg (*va, int);
2742 /* Print short or long form depending on byte count. */
2743 uword short_form = n_bytes <= 32;
2744 u32 indent = format_get_indent (s);
2749 for (i = 0; i < n_bytes; i++)
2751 if (!short_form && (i % 32) == 0)
2752 s = format (s, "%08x: ", i);
2753 s = format (s, "%02x", bytes[i]);
2754 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2755 s = format (s, "\n%U", format_white_space, indent);
2761 static void vl_api_pg_create_interface_reply_t_handler
2762 (vl_api_pg_create_interface_reply_t * mp)
2764 vat_main_t *vam = &vat_main;
2766 vam->retval = ntohl (mp->retval);
2767 vam->result_ready = 1;
2770 static void vl_api_pg_create_interface_reply_t_handler_json
2771 (vl_api_pg_create_interface_reply_t * mp)
2773 vat_main_t *vam = &vat_main;
2774 vat_json_node_t node;
2776 i32 retval = ntohl (mp->retval);
2779 vat_json_init_object (&node);
2781 vat_json_object_add_int (&node, "sw_if_index", ntohl (mp->sw_if_index));
2783 vat_json_print (vam->ofp, &node);
2784 vat_json_free (&node);
2786 vam->retval = ntohl (mp->retval);
2787 vam->result_ready = 1;
2791 * Generate boilerplate reply handlers, which
2792 * dig the return value out of the xxx_reply_t API message,
2793 * stick it into vam->retval, and set vam->result_ready
2795 * Could also do this by pointing N message decode slots at
2796 * a single function, but that could break in subtle ways.
2799 #define foreach_standard_reply_retval_handler \
2800 _(sw_interface_set_flags_reply) \
2801 _(sw_interface_add_del_address_reply) \
2802 _(sw_interface_set_rx_mode_reply) \
2803 _(sw_interface_set_rx_placement_reply) \
2804 _(sw_interface_set_table_reply) \
2805 _(sw_interface_set_mpls_enable_reply) \
2806 _(sw_interface_set_vpath_reply) \
2807 _(sw_interface_set_l2_bridge_reply) \
2808 _(sw_interface_set_bond_weight_reply) \
2809 _(bridge_domain_add_del_reply) \
2810 _(sw_interface_set_l2_xconnect_reply) \
2811 _(l2fib_add_del_reply) \
2812 _(l2fib_flush_int_reply) \
2813 _(l2fib_flush_bd_reply) \
2814 _(ip_route_add_del_reply) \
2815 _(ip_table_add_del_reply) \
2816 _(ip_table_replace_begin_reply) \
2817 _(ip_table_flush_reply) \
2818 _(ip_table_replace_end_reply) \
2819 _(ip_mroute_add_del_reply) \
2820 _(mpls_route_add_del_reply) \
2821 _(mpls_table_add_del_reply) \
2822 _(mpls_ip_bind_unbind_reply) \
2823 _(sw_interface_set_unnumbered_reply) \
2824 _(set_ip_flow_hash_reply) \
2825 _(sw_interface_ip6_enable_disable_reply) \
2826 _(l2_patch_add_del_reply) \
2827 _(sr_mpls_policy_add_reply) \
2828 _(sr_mpls_policy_mod_reply) \
2829 _(sr_mpls_policy_del_reply) \
2830 _(sr_policy_add_reply) \
2831 _(sr_policy_mod_reply) \
2832 _(sr_policy_del_reply) \
2833 _(sr_localsid_add_del_reply) \
2834 _(sr_steering_add_del_reply) \
2835 _(l2_fib_clear_table_reply) \
2836 _(l2_interface_efp_filter_reply) \
2837 _(l2_interface_vlan_tag_rewrite_reply) \
2838 _(modify_vhost_user_if_reply) \
2839 _(modify_vhost_user_if_v2_reply) \
2840 _(delete_vhost_user_if_reply) \
2841 _(want_l2_macs_events_reply) \
2842 _(ipsec_spd_add_del_reply) \
2843 _(ipsec_interface_add_del_spd_reply) \
2844 _(ipsec_spd_entry_add_del_reply) \
2845 _(ipsec_sad_entry_add_del_reply) \
2846 _(delete_loopback_reply) \
2847 _(bd_ip_mac_add_del_reply) \
2848 _(bd_ip_mac_flush_reply) \
2849 _(want_interface_events_reply) \
2850 _(sw_interface_clear_stats_reply) \
2851 _(ioam_enable_reply) \
2852 _(ioam_disable_reply) \
2853 _(af_packet_delete_reply) \
2854 _(set_ipfix_exporter_reply) \
2855 _(set_ipfix_classify_stream_reply) \
2856 _(ipfix_classify_table_add_del_reply) \
2857 _(sw_interface_span_enable_disable_reply) \
2858 _(pg_capture_reply) \
2859 _(pg_enable_disable_reply) \
2860 _(pg_interface_enable_disable_coalesce_reply) \
2861 _(ip_source_and_port_range_check_add_del_reply) \
2862 _(ip_source_and_port_range_check_interface_add_del_reply)\
2863 _(delete_subif_reply) \
2864 _(l2_interface_pbb_tag_rewrite_reply) \
2866 _(feature_enable_disable_reply) \
2867 _(feature_gso_enable_disable_reply) \
2868 _(sw_interface_tag_add_del_reply) \
2869 _(sw_interface_add_del_mac_address_reply) \
2870 _(hw_interface_set_mtu_reply) \
2871 _(p2p_ethernet_add_reply) \
2872 _(p2p_ethernet_del_reply) \
2873 _(tcp_configure_src_addresses_reply) \
2874 _(session_rule_add_del_reply) \
2875 _(ip_container_proxy_add_del_reply) \
2876 _(qos_record_enable_disable_reply) \
2880 static void vl_api_##n##_t_handler \
2881 (vl_api_##n##_t * mp) \
2883 vat_main_t * vam = &vat_main; \
2884 i32 retval = ntohl(mp->retval); \
2885 if (vam->async_mode) { \
2886 vam->async_errors += (retval < 0); \
2888 vam->retval = retval; \
2889 vam->result_ready = 1; \
2892 foreach_standard_reply_retval_handler;
2896 static void vl_api_##n##_t_handler_json \
2897 (vl_api_##n##_t * mp) \
2899 vat_main_t * vam = &vat_main; \
2900 vat_json_node_t node; \
2901 vat_json_init_object(&node); \
2902 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2903 vat_json_print(vam->ofp, &node); \
2904 vam->retval = ntohl(mp->retval); \
2905 vam->result_ready = 1; \
2907 foreach_standard_reply_retval_handler;
2911 * Table of message reply handlers, must include boilerplate handlers
2915 #define foreach_vpe_api_reply_msg \
2916 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2917 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2918 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2919 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2920 _(CONTROL_PING_REPLY, control_ping_reply) \
2921 _(CLI_REPLY, cli_reply) \
2922 _(CLI_INBAND_REPLY, cli_inband_reply) \
2923 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2924 sw_interface_add_del_address_reply) \
2925 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2926 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2927 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2928 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2929 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2930 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2931 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2932 sw_interface_set_l2_xconnect_reply) \
2933 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2934 sw_interface_set_l2_bridge_reply) \
2935 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2936 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2937 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2938 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2939 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2940 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2941 _(L2_FLAGS_REPLY, l2_flags_reply) \
2942 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2943 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
2944 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
2945 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
2946 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2947 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2948 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2949 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2950 _(BOND_CREATE_REPLY, bond_create_reply) \
2951 _(BOND_CREATE2_REPLY, bond_create2_reply) \
2952 _(BOND_DELETE_REPLY, bond_delete_reply) \
2953 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
2954 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
2955 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
2956 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
2957 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
2958 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2959 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2960 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2961 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2962 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2963 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2964 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2965 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2966 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2967 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2968 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2969 sw_interface_set_unnumbered_reply) \
2970 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2971 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2972 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2973 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2974 sw_interface_ip6_enable_disable_reply) \
2975 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2976 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
2977 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
2978 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
2979 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
2980 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
2981 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
2982 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
2983 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
2984 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2985 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2986 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2987 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2988 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2989 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2990 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2991 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2992 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2993 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2994 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2995 _(SHOW_VERSION_REPLY, show_version_reply) \
2996 _(SHOW_THREADS_REPLY, show_threads_reply) \
2997 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2998 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2999 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
3000 _(L2_MACS_EVENT, l2_macs_event) \
3001 _(IP_ADDRESS_DETAILS, ip_address_details) \
3002 _(IP_DETAILS, ip_details) \
3003 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3004 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3005 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3006 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3007 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3008 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3009 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3010 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3011 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3012 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3013 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3014 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3015 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3016 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3017 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3018 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3019 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3020 _(AF_PACKET_DETAILS, af_packet_details) \
3021 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3022 _(POLICER_DETAILS, policer_details) \
3023 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3024 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3025 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3026 _(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \
3027 _(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \
3028 _(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \
3029 _(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \
3030 _(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \
3031 _(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \
3032 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3033 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3034 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3035 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3036 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3037 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3038 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3039 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3040 ip_source_and_port_range_check_add_del_reply) \
3041 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3042 ip_source_and_port_range_check_interface_add_del_reply) \
3043 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3044 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3045 _(SET_PUNT_REPLY, set_punt_reply) \
3046 _(IP_TABLE_DETAILS, ip_table_details) \
3047 _(IP_ROUTE_DETAILS, ip_route_details) \
3048 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3049 _(FEATURE_GSO_ENABLE_DISABLE_REPLY, feature_gso_enable_disable_reply) \
3050 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3051 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3052 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3053 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3054 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3055 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3056 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3057 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3058 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3059 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3060 _(SESSION_RULES_DETAILS, session_rules_details) \
3061 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3062 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3063 _(FLOW_ADD_REPLY, flow_add_reply) \
3065 #define foreach_standalone_reply_msg \
3066 _(SW_INTERFACE_EVENT, sw_interface_event)
3074 #define STR_VTR_OP_CASE(op) \
3075 case L2_VTR_ ## op: \
3079 str_vtr_op (u32 vtr_op)
3083 STR_VTR_OP_CASE (DISABLED);
3084 STR_VTR_OP_CASE (PUSH_1);
3085 STR_VTR_OP_CASE (PUSH_2);
3086 STR_VTR_OP_CASE (POP_1);
3087 STR_VTR_OP_CASE (POP_2);
3088 STR_VTR_OP_CASE (TRANSLATE_1_1);
3089 STR_VTR_OP_CASE (TRANSLATE_1_2);
3090 STR_VTR_OP_CASE (TRANSLATE_2_1);
3091 STR_VTR_OP_CASE (TRANSLATE_2_2);
3098 dump_sub_interface_table (vat_main_t * vam)
3100 const sw_interface_subif_t *sub = NULL;
3102 if (vam->json_output)
3105 ("JSON output supported only for VPE API calls and dump_stats_table");
3110 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3111 "Interface", "sw_if_index",
3112 "sub id", "dot1ad", "tags", "outer id",
3113 "inner id", "exact", "default", "outer any", "inner any");
3115 vec_foreach (sub, vam->sw_if_subif_table)
3118 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3119 sub->interface_name,
3121 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3122 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3123 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3124 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3125 if (sub->vtr_op != L2_VTR_DISABLED)
3128 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3129 "tag1: %d tag2: %d ]",
3130 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3131 sub->vtr_tag1, sub->vtr_tag2);
3139 name_sort_cmp (void *a1, void *a2)
3141 name_sort_t *n1 = a1;
3142 name_sort_t *n2 = a2;
3144 return strcmp ((char *) n1->name, (char *) n2->name);
3148 dump_interface_table (vat_main_t * vam)
3151 name_sort_t *nses = 0, *ns;
3153 if (vam->json_output)
3156 ("JSON output supported only for VPE API calls and dump_stats_table");
3161 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3163 vec_add2 (nses, ns, 1);
3164 ns->name = (u8 *)(p->key);
3165 ns->value = (u32) p->value[0];
3169 vec_sort_with_function (nses, name_sort_cmp);
3171 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3172 vec_foreach (ns, nses)
3174 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3181 dump_ip_table (vat_main_t * vam, int is_ipv6)
3183 const ip_details_t *det = NULL;
3184 const ip_address_details_t *address = NULL;
3187 print (vam->ofp, "%-12s", "sw_if_index");
3189 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3196 print (vam->ofp, "%-12d", i);
3197 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3202 vec_foreach (address, det->addr)
3206 is_ipv6 ? format_ip6_address : format_ip4_address,
3207 address->ip, address->prefix_length);
3215 dump_ipv4_table (vat_main_t * vam)
3217 if (vam->json_output)
3220 ("JSON output supported only for VPE API calls and dump_stats_table");
3224 return dump_ip_table (vam, 0);
3228 dump_ipv6_table (vat_main_t * vam)
3230 if (vam->json_output)
3233 ("JSON output supported only for VPE API calls and dump_stats_table");
3237 return dump_ip_table (vam, 1);
3241 * Pass CLI buffers directly in the CLI_INBAND API message,
3242 * instead of an additional shared memory area.
3245 exec_inband (vat_main_t * vam)
3247 vl_api_cli_inband_t *mp;
3248 unformat_input_t *i = vam->input;
3251 if (vec_len (i->buffer) == 0)
3254 if (vam->exec_mode == 0 && unformat (i, "mode"))
3259 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3266 * In order for the CLI command to work, it
3267 * must be a vector ending in \n, not a C-string ending
3270 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3271 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3275 /* json responses may or may not include a useful reply... */
3276 if (vec_len (vam->cmd_reply))
3277 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3282 exec (vat_main_t * vam)
3284 return exec_inband (vam);
3288 api_create_loopback (vat_main_t * vam)
3290 unformat_input_t *i = vam->input;
3291 vl_api_create_loopback_t *mp;
3292 vl_api_create_loopback_instance_t *mp_lbi;
3295 u8 is_specified = 0;
3296 u32 user_instance = 0;
3299 clib_memset (mac_address, 0, sizeof (mac_address));
3301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3303 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3305 if (unformat (i, "instance %d", &user_instance))
3313 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3314 mp_lbi->is_specified = is_specified;
3316 mp_lbi->user_instance = htonl (user_instance);
3318 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3323 /* Construct the API message */
3324 M (CREATE_LOOPBACK, mp);
3326 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3335 api_delete_loopback (vat_main_t * vam)
3337 unformat_input_t *i = vam->input;
3338 vl_api_delete_loopback_t *mp;
3339 u32 sw_if_index = ~0;
3342 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3344 if (unformat (i, "sw_if_index %d", &sw_if_index))
3350 if (sw_if_index == ~0)
3352 errmsg ("missing sw_if_index");
3356 /* Construct the API message */
3357 M (DELETE_LOOPBACK, mp);
3358 mp->sw_if_index = ntohl (sw_if_index);
3366 api_want_interface_events (vat_main_t * vam)
3368 unformat_input_t *i = vam->input;
3369 vl_api_want_interface_events_t *mp;
3373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3375 if (unformat (i, "enable"))
3377 else if (unformat (i, "disable"))
3385 errmsg ("missing enable|disable");
3389 M (WANT_INTERFACE_EVENTS, mp);
3390 mp->enable_disable = enable;
3392 vam->interface_event_display = enable;
3400 /* Note: non-static, called once to set up the initial intfc table */
3402 api_sw_interface_dump (vat_main_t * vam)
3404 vl_api_sw_interface_dump_t *mp;
3405 vl_api_control_ping_t *mp_ping;
3407 name_sort_t *nses = 0, *ns;
3408 sw_interface_subif_t *sub = NULL;
3411 /* Toss the old name table */
3413 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3415 vec_add2 (nses, ns, 1);
3416 ns->name = (u8 *)(p->key);
3417 ns->value = (u32) p->value[0];
3421 hash_free (vam->sw_if_index_by_interface_name);
3423 vec_foreach (ns, nses) vec_free (ns->name);
3427 vec_foreach (sub, vam->sw_if_subif_table)
3429 vec_free (sub->interface_name);
3431 vec_free (vam->sw_if_subif_table);
3433 /* recreate the interface name hash table */
3434 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3437 * Ask for all interface names. Otherwise, the epic catalog of
3438 * name filters becomes ridiculously long, and vat ends up needing
3439 * to be taught about new interface types.
3441 M (SW_INTERFACE_DUMP, mp);
3444 /* Use a control ping for synchronization */
3445 MPING (CONTROL_PING, mp_ping);
3453 api_sw_interface_set_flags (vat_main_t * vam)
3455 unformat_input_t *i = vam->input;
3456 vl_api_sw_interface_set_flags_t *mp;
3458 u8 sw_if_index_set = 0;
3462 /* Parse args required to build the message */
3463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3465 if (unformat (i, "admin-up"))
3467 else if (unformat (i, "admin-down"))
3470 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3471 sw_if_index_set = 1;
3472 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3473 sw_if_index_set = 1;
3478 if (sw_if_index_set == 0)
3480 errmsg ("missing interface name or sw_if_index");
3484 /* Construct the API message */
3485 M (SW_INTERFACE_SET_FLAGS, mp);
3486 mp->sw_if_index = ntohl (sw_if_index);
3487 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3492 /* Wait for a reply, return the good/bad news... */
3498 api_sw_interface_set_rx_mode (vat_main_t * vam)
3500 unformat_input_t *i = vam->input;
3501 vl_api_sw_interface_set_rx_mode_t *mp;
3503 u8 sw_if_index_set = 0;
3505 u8 queue_id_valid = 0;
3507 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3509 /* Parse args required to build the message */
3510 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3512 if (unformat (i, "queue %d", &queue_id))
3514 else if (unformat (i, "polling"))
3515 mode = VNET_HW_IF_RX_MODE_POLLING;
3516 else if (unformat (i, "interrupt"))
3517 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3518 else if (unformat (i, "adaptive"))
3519 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3521 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3522 sw_if_index_set = 1;
3523 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3524 sw_if_index_set = 1;
3529 if (sw_if_index_set == 0)
3531 errmsg ("missing interface name or sw_if_index");
3534 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3536 errmsg ("missing rx-mode");
3540 /* Construct the API message */
3541 M (SW_INTERFACE_SET_RX_MODE, mp);
3542 mp->sw_if_index = ntohl (sw_if_index);
3543 mp->mode = (vl_api_rx_mode_t) mode;
3544 mp->queue_id_valid = queue_id_valid;
3545 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3550 /* Wait for a reply, return the good/bad news... */
3556 api_sw_interface_set_rx_placement (vat_main_t * vam)
3558 unformat_input_t *i = vam->input;
3559 vl_api_sw_interface_set_rx_placement_t *mp;
3561 u8 sw_if_index_set = 0;
3564 u32 queue_id, thread_index;
3566 /* Parse args required to build the message */
3567 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3569 if (unformat (i, "queue %d", &queue_id))
3571 else if (unformat (i, "main"))
3573 else if (unformat (i, "worker %d", &thread_index))
3576 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3577 sw_if_index_set = 1;
3578 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3579 sw_if_index_set = 1;
3584 if (sw_if_index_set == 0)
3586 errmsg ("missing interface name or sw_if_index");
3592 /* Construct the API message */
3593 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3594 mp->sw_if_index = ntohl (sw_if_index);
3595 mp->worker_id = ntohl (thread_index);
3596 mp->queue_id = ntohl (queue_id);
3597 mp->is_main = is_main;
3601 /* Wait for a reply, return the good/bad news... */
3606 static void vl_api_sw_interface_rx_placement_details_t_handler
3607 (vl_api_sw_interface_rx_placement_details_t * mp)
3609 vat_main_t *vam = &vat_main;
3610 u32 worker_id = ntohl (mp->worker_id);
3613 "\n%-11d %-11s %-6d %-5d %-9s",
3614 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3615 worker_id, ntohl (mp->queue_id),
3617 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3620 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3621 (vl_api_sw_interface_rx_placement_details_t * mp)
3623 vat_main_t *vam = &vat_main;
3624 vat_json_node_t *node = NULL;
3626 if (VAT_JSON_ARRAY != vam->json_tree.type)
3628 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3629 vat_json_init_array (&vam->json_tree);
3631 node = vat_json_array_add (&vam->json_tree);
3633 vat_json_init_object (node);
3634 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3635 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3636 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3637 vat_json_object_add_uint (node, "mode", mp->mode);
3641 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3643 unformat_input_t *i = vam->input;
3644 vl_api_sw_interface_rx_placement_dump_t *mp;
3645 vl_api_control_ping_t *mp_ping;
3648 u8 sw_if_index_set = 0;
3650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3652 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3654 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3661 "\n%-11s %-11s %-6s %-5s %-4s",
3662 "sw_if_index", "main/worker", "thread", "queue", "mode");
3664 /* Dump Interface rx placement */
3665 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3667 if (sw_if_index_set)
3668 mp->sw_if_index = htonl (sw_if_index);
3670 mp->sw_if_index = ~0;
3674 /* Use a control ping for synchronization */
3675 MPING (CONTROL_PING, mp_ping);
3683 api_sw_interface_clear_stats (vat_main_t * vam)
3685 unformat_input_t *i = vam->input;
3686 vl_api_sw_interface_clear_stats_t *mp;
3688 u8 sw_if_index_set = 0;
3691 /* Parse args required to build the message */
3692 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3694 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3695 sw_if_index_set = 1;
3696 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3697 sw_if_index_set = 1;
3702 /* Construct the API message */
3703 M (SW_INTERFACE_CLEAR_STATS, mp);
3705 if (sw_if_index_set == 1)
3706 mp->sw_if_index = ntohl (sw_if_index);
3708 mp->sw_if_index = ~0;
3713 /* Wait for a reply, return the good/bad news... */
3719 api_sw_interface_add_del_address (vat_main_t * vam)
3721 unformat_input_t *i = vam->input;
3722 vl_api_sw_interface_add_del_address_t *mp;
3724 u8 sw_if_index_set = 0;
3725 u8 is_add = 1, del_all = 0;
3726 u32 address_length = 0;
3727 u8 v4_address_set = 0;
3728 u8 v6_address_set = 0;
3729 ip4_address_t v4address;
3730 ip6_address_t v6address;
3733 /* Parse args required to build the message */
3734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3736 if (unformat (i, "del-all"))
3738 else if (unformat (i, "del"))
3741 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3742 sw_if_index_set = 1;
3743 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3744 sw_if_index_set = 1;
3745 else if (unformat (i, "%U/%d",
3746 unformat_ip4_address, &v4address, &address_length))
3748 else if (unformat (i, "%U/%d",
3749 unformat_ip6_address, &v6address, &address_length))
3755 if (sw_if_index_set == 0)
3757 errmsg ("missing interface name or sw_if_index");
3760 if (v4_address_set && v6_address_set)
3762 errmsg ("both v4 and v6 addresses set");
3765 if (!v4_address_set && !v6_address_set && !del_all)
3767 errmsg ("no addresses set");
3771 /* Construct the API message */
3772 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3774 mp->sw_if_index = ntohl (sw_if_index);
3775 mp->is_add = is_add;
3776 mp->del_all = del_all;
3779 mp->prefix.address.af = ADDRESS_IP6;
3780 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3784 mp->prefix.address.af = ADDRESS_IP4;
3785 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3787 mp->prefix.len = address_length;
3792 /* Wait for a reply, return good/bad news */
3798 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3800 unformat_input_t *i = vam->input;
3801 vl_api_sw_interface_set_mpls_enable_t *mp;
3803 u8 sw_if_index_set = 0;
3807 /* Parse args required to build the message */
3808 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3810 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3811 sw_if_index_set = 1;
3812 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3813 sw_if_index_set = 1;
3814 else if (unformat (i, "disable"))
3816 else if (unformat (i, "dis"))
3822 if (sw_if_index_set == 0)
3824 errmsg ("missing interface name or sw_if_index");
3828 /* Construct the API message */
3829 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3831 mp->sw_if_index = ntohl (sw_if_index);
3832 mp->enable = enable;
3837 /* Wait for a reply... */
3843 api_sw_interface_set_table (vat_main_t * vam)
3845 unformat_input_t *i = vam->input;
3846 vl_api_sw_interface_set_table_t *mp;
3847 u32 sw_if_index, vrf_id = 0;
3848 u8 sw_if_index_set = 0;
3852 /* Parse args required to build the message */
3853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3855 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3856 sw_if_index_set = 1;
3857 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3858 sw_if_index_set = 1;
3859 else if (unformat (i, "vrf %d", &vrf_id))
3861 else if (unformat (i, "ipv6"))
3867 if (sw_if_index_set == 0)
3869 errmsg ("missing interface name or sw_if_index");
3873 /* Construct the API message */
3874 M (SW_INTERFACE_SET_TABLE, mp);
3876 mp->sw_if_index = ntohl (sw_if_index);
3877 mp->is_ipv6 = is_ipv6;
3878 mp->vrf_id = ntohl (vrf_id);
3883 /* Wait for a reply... */
3888 static void vl_api_sw_interface_get_table_reply_t_handler
3889 (vl_api_sw_interface_get_table_reply_t * mp)
3891 vat_main_t *vam = &vat_main;
3893 print (vam->ofp, "%d", ntohl (mp->vrf_id));
3895 vam->retval = ntohl (mp->retval);
3896 vam->result_ready = 1;
3900 static void vl_api_sw_interface_get_table_reply_t_handler_json
3901 (vl_api_sw_interface_get_table_reply_t * mp)
3903 vat_main_t *vam = &vat_main;
3904 vat_json_node_t node;
3906 vat_json_init_object (&node);
3907 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3908 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3910 vat_json_print (vam->ofp, &node);
3911 vat_json_free (&node);
3913 vam->retval = ntohl (mp->retval);
3914 vam->result_ready = 1;
3918 api_sw_interface_get_table (vat_main_t * vam)
3920 unformat_input_t *i = vam->input;
3921 vl_api_sw_interface_get_table_t *mp;
3923 u8 sw_if_index_set = 0;
3927 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3929 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3930 sw_if_index_set = 1;
3931 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3932 sw_if_index_set = 1;
3933 else if (unformat (i, "ipv6"))
3939 if (sw_if_index_set == 0)
3941 errmsg ("missing interface name or sw_if_index");
3945 M (SW_INTERFACE_GET_TABLE, mp);
3946 mp->sw_if_index = htonl (sw_if_index);
3947 mp->is_ipv6 = is_ipv6;
3955 api_sw_interface_set_vpath (vat_main_t * vam)
3957 unformat_input_t *i = vam->input;
3958 vl_api_sw_interface_set_vpath_t *mp;
3959 u32 sw_if_index = 0;
3960 u8 sw_if_index_set = 0;
3964 /* Parse args required to build the message */
3965 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3967 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3968 sw_if_index_set = 1;
3969 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3970 sw_if_index_set = 1;
3971 else if (unformat (i, "enable"))
3973 else if (unformat (i, "disable"))
3979 if (sw_if_index_set == 0)
3981 errmsg ("missing interface name or sw_if_index");
3985 /* Construct the API message */
3986 M (SW_INTERFACE_SET_VPATH, mp);
3988 mp->sw_if_index = ntohl (sw_if_index);
3989 mp->enable = is_enable;
3994 /* Wait for a reply... */
4000 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4002 unformat_input_t *i = vam->input;
4003 vl_api_sw_interface_set_l2_xconnect_t *mp;
4005 u8 rx_sw_if_index_set = 0;
4007 u8 tx_sw_if_index_set = 0;
4011 /* Parse args required to build the message */
4012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4014 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4015 rx_sw_if_index_set = 1;
4016 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4017 tx_sw_if_index_set = 1;
4018 else if (unformat (i, "rx"))
4020 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4022 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4024 rx_sw_if_index_set = 1;
4029 else if (unformat (i, "tx"))
4031 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4033 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4035 tx_sw_if_index_set = 1;
4040 else if (unformat (i, "enable"))
4042 else if (unformat (i, "disable"))
4048 if (rx_sw_if_index_set == 0)
4050 errmsg ("missing rx interface name or rx_sw_if_index");
4054 if (enable && (tx_sw_if_index_set == 0))
4056 errmsg ("missing tx interface name or tx_sw_if_index");
4060 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4062 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4063 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4064 mp->enable = enable;
4072 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4074 unformat_input_t *i = vam->input;
4075 vl_api_sw_interface_set_l2_bridge_t *mp;
4076 vl_api_l2_port_type_t port_type;
4078 u8 rx_sw_if_index_set = 0;
4085 port_type = L2_API_PORT_TYPE_NORMAL;
4087 /* Parse args required to build the message */
4088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4090 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4091 rx_sw_if_index_set = 1;
4092 else if (unformat (i, "bd_id %d", &bd_id))
4096 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4097 rx_sw_if_index_set = 1;
4098 else if (unformat (i, "shg %d", &shg))
4100 else if (unformat (i, "bvi"))
4101 port_type = L2_API_PORT_TYPE_BVI;
4102 else if (unformat (i, "uu-fwd"))
4103 port_type = L2_API_PORT_TYPE_UU_FWD;
4104 else if (unformat (i, "enable"))
4106 else if (unformat (i, "disable"))
4112 if (rx_sw_if_index_set == 0)
4114 errmsg ("missing rx interface name or sw_if_index");
4118 if (enable && (bd_id_set == 0))
4120 errmsg ("missing bridge domain");
4124 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4126 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4127 mp->bd_id = ntohl (bd_id);
4129 mp->port_type = ntohl (port_type);
4130 mp->enable = enable;
4138 api_bridge_domain_dump (vat_main_t * vam)
4140 unformat_input_t *i = vam->input;
4141 vl_api_bridge_domain_dump_t *mp;
4142 vl_api_control_ping_t *mp_ping;
4146 /* Parse args required to build the message */
4147 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4149 if (unformat (i, "bd_id %d", &bd_id))
4155 M (BRIDGE_DOMAIN_DUMP, mp);
4156 mp->bd_id = ntohl (bd_id);
4159 /* Use a control ping for synchronization */
4160 MPING (CONTROL_PING, mp_ping);
4168 api_bridge_domain_add_del (vat_main_t * vam)
4170 unformat_input_t *i = vam->input;
4171 vl_api_bridge_domain_add_del_t *mp;
4174 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4179 /* Parse args required to build the message */
4180 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4182 if (unformat (i, "bd_id %d", &bd_id))
4184 else if (unformat (i, "flood %d", &flood))
4186 else if (unformat (i, "uu-flood %d", &uu_flood))
4188 else if (unformat (i, "forward %d", &forward))
4190 else if (unformat (i, "learn %d", &learn))
4192 else if (unformat (i, "arp-term %d", &arp_term))
4194 else if (unformat (i, "mac-age %d", &mac_age))
4196 else if (unformat (i, "bd-tag %s", &bd_tag))
4198 else if (unformat (i, "del"))
4201 flood = uu_flood = forward = learn = 0;
4209 errmsg ("missing bridge domain");
4216 errmsg ("mac age must be less than 256 ");
4221 if ((bd_tag) && (vec_len (bd_tag) > 63))
4223 errmsg ("bd-tag cannot be longer than 63");
4228 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4230 mp->bd_id = ntohl (bd_id);
4232 mp->uu_flood = uu_flood;
4233 mp->forward = forward;
4235 mp->arp_term = arp_term;
4236 mp->is_add = is_add;
4237 mp->mac_age = (u8) mac_age;
4240 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4241 mp->bd_tag[vec_len (bd_tag)] = 0;
4252 api_l2fib_flush_bd (vat_main_t * vam)
4254 unformat_input_t *i = vam->input;
4255 vl_api_l2fib_flush_bd_t *mp;
4259 /* Parse args required to build the message */
4260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4262 if (unformat (i, "bd_id %d", &bd_id));
4269 errmsg ("missing bridge domain");
4273 M (L2FIB_FLUSH_BD, mp);
4275 mp->bd_id = htonl (bd_id);
4283 api_l2fib_flush_int (vat_main_t * vam)
4285 unformat_input_t *i = vam->input;
4286 vl_api_l2fib_flush_int_t *mp;
4287 u32 sw_if_index = ~0;
4290 /* Parse args required to build the message */
4291 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4293 if (unformat (i, "sw_if_index %d", &sw_if_index));
4295 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4300 if (sw_if_index == ~0)
4302 errmsg ("missing interface name or sw_if_index");
4306 M (L2FIB_FLUSH_INT, mp);
4308 mp->sw_if_index = ntohl (sw_if_index);
4316 api_l2fib_add_del (vat_main_t * vam)
4318 unformat_input_t *i = vam->input;
4319 vl_api_l2fib_add_del_t *mp;
4325 u32 sw_if_index = 0;
4326 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, "mac %U", unformat_ethernet_address, mac))
4340 else if (unformat (i, "bd_id %d", &bd_id))
4342 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4343 sw_if_index_set = 1;
4344 else if (unformat (i, "sw_if"))
4346 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4349 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4350 sw_if_index_set = 1;
4355 else if (unformat (i, "static"))
4357 else if (unformat (i, "filter"))
4362 else if (unformat (i, "bvi"))
4367 else if (unformat (i, "del"))
4369 else if (unformat (i, "count %d", &count))
4377 errmsg ("missing mac address");
4383 errmsg ("missing bridge domain");
4387 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4389 errmsg ("missing interface name or sw_if_index");
4395 /* Turn on async mode */
4396 vam->async_mode = 1;
4397 vam->async_errors = 0;
4398 before = vat_time_now (vam);
4401 for (j = 0; j < count; j++)
4403 M (L2FIB_ADD_DEL, mp);
4405 clib_memcpy (mp->mac, mac, 6);
4406 mp->bd_id = ntohl (bd_id);
4407 mp->is_add = is_add;
4408 mp->sw_if_index = ntohl (sw_if_index);
4412 mp->static_mac = static_mac;
4413 mp->filter_mac = filter_mac;
4414 mp->bvi_mac = bvi_mac;
4416 increment_mac_address (mac);
4423 vl_api_control_ping_t *mp_ping;
4426 /* Shut off async mode */
4427 vam->async_mode = 0;
4429 MPING (CONTROL_PING, mp_ping);
4432 timeout = vat_time_now (vam) + 1.0;
4433 while (vat_time_now (vam) < timeout)
4434 if (vam->result_ready == 1)
4439 if (vam->retval == -99)
4442 if (vam->async_errors > 0)
4444 errmsg ("%d asynchronous errors", vam->async_errors);
4447 vam->async_errors = 0;
4448 after = vat_time_now (vam);
4450 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4451 count, after - before, count / (after - before));
4457 /* Wait for a reply... */
4461 /* Return the good/bad news */
4462 return (vam->retval);
4466 api_bridge_domain_set_mac_age (vat_main_t * vam)
4468 unformat_input_t *i = vam->input;
4469 vl_api_bridge_domain_set_mac_age_t *mp;
4474 /* Parse args required to build the message */
4475 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4477 if (unformat (i, "bd_id %d", &bd_id));
4478 else if (unformat (i, "mac-age %d", &mac_age));
4485 errmsg ("missing bridge domain");
4491 errmsg ("mac age must be less than 256 ");
4495 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4497 mp->bd_id = htonl (bd_id);
4498 mp->mac_age = (u8) mac_age;
4506 api_l2_flags (vat_main_t * vam)
4508 unformat_input_t *i = vam->input;
4509 vl_api_l2_flags_t *mp;
4512 u8 sw_if_index_set = 0;
4516 /* Parse args required to build the message */
4517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4519 if (unformat (i, "sw_if_index %d", &sw_if_index))
4520 sw_if_index_set = 1;
4521 else if (unformat (i, "sw_if"))
4523 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4526 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4527 sw_if_index_set = 1;
4532 else if (unformat (i, "learn"))
4534 else if (unformat (i, "forward"))
4536 else if (unformat (i, "flood"))
4538 else if (unformat (i, "uu-flood"))
4539 flags |= L2_UU_FLOOD;
4540 else if (unformat (i, "arp-term"))
4541 flags |= L2_ARP_TERM;
4542 else if (unformat (i, "off"))
4544 else if (unformat (i, "disable"))
4550 if (sw_if_index_set == 0)
4552 errmsg ("missing interface name or sw_if_index");
4558 mp->sw_if_index = ntohl (sw_if_index);
4559 mp->feature_bitmap = ntohl (flags);
4560 mp->is_set = is_set;
4568 api_bridge_flags (vat_main_t * vam)
4570 unformat_input_t *i = vam->input;
4571 vl_api_bridge_flags_t *mp;
4575 bd_flags_t flags = 0;
4578 /* Parse args required to build the message */
4579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4581 if (unformat (i, "bd_id %d", &bd_id))
4583 else if (unformat (i, "learn"))
4584 flags |= BRIDGE_API_FLAG_LEARN;
4585 else if (unformat (i, "forward"))
4586 flags |= BRIDGE_API_FLAG_FWD;
4587 else if (unformat (i, "flood"))
4588 flags |= BRIDGE_API_FLAG_FLOOD;
4589 else if (unformat (i, "uu-flood"))
4590 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4591 else if (unformat (i, "arp-term"))
4592 flags |= BRIDGE_API_FLAG_ARP_TERM;
4593 else if (unformat (i, "off"))
4595 else if (unformat (i, "disable"))
4603 errmsg ("missing bridge domain");
4607 M (BRIDGE_FLAGS, mp);
4609 mp->bd_id = ntohl (bd_id);
4610 mp->flags = ntohl (flags);
4611 mp->is_set = is_set;
4619 api_bd_ip_mac_add_del (vat_main_t * vam)
4621 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4622 vl_api_mac_address_t mac = { 0 };
4623 unformat_input_t *i = vam->input;
4624 vl_api_bd_ip_mac_add_del_t *mp;
4633 /* Parse args required to build the message */
4634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4636 if (unformat (i, "bd_id %d", &bd_id))
4640 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4644 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4648 else if (unformat (i, "del"))
4656 errmsg ("missing bridge domain");
4659 else if (ip_set == 0)
4661 errmsg ("missing IP address");
4664 else if (mac_set == 0)
4666 errmsg ("missing MAC address");
4670 M (BD_IP_MAC_ADD_DEL, mp);
4672 mp->entry.bd_id = ntohl (bd_id);
4673 mp->is_add = is_add;
4675 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4676 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4684 api_bd_ip_mac_flush (vat_main_t * vam)
4686 unformat_input_t *i = vam->input;
4687 vl_api_bd_ip_mac_flush_t *mp;
4692 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4694 if (unformat (i, "bd_id %d", &bd_id))
4704 errmsg ("missing bridge domain");
4708 M (BD_IP_MAC_FLUSH, mp);
4710 mp->bd_id = ntohl (bd_id);
4717 static void vl_api_bd_ip_mac_details_t_handler
4718 (vl_api_bd_ip_mac_details_t * mp)
4720 vat_main_t *vam = &vat_main;
4724 ntohl (mp->entry.bd_id),
4725 format_vl_api_mac_address, mp->entry.mac,
4726 format_vl_api_address, &mp->entry.ip);
4729 static void vl_api_bd_ip_mac_details_t_handler_json
4730 (vl_api_bd_ip_mac_details_t * mp)
4732 vat_main_t *vam = &vat_main;
4733 vat_json_node_t *node = NULL;
4735 if (VAT_JSON_ARRAY != vam->json_tree.type)
4737 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4738 vat_json_init_array (&vam->json_tree);
4740 node = vat_json_array_add (&vam->json_tree);
4742 vat_json_init_object (node);
4743 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4744 vat_json_object_add_string_copy (node, "mac_address",
4745 format (0, "%U", format_vl_api_mac_address,
4749 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4750 vat_json_object_add_string_copy (node, "ip_address", ip);
4755 api_bd_ip_mac_dump (vat_main_t * vam)
4757 unformat_input_t *i = vam->input;
4758 vl_api_bd_ip_mac_dump_t *mp;
4759 vl_api_control_ping_t *mp_ping;
4764 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4766 if (unformat (i, "bd_id %d", &bd_id))
4775 "\n%-5s %-7s %-20s %-30s",
4776 "bd_id", "is_ipv6", "mac_address", "ip_address");
4778 /* Dump Bridge Domain Ip to Mac entries */
4779 M (BD_IP_MAC_DUMP, mp);
4782 mp->bd_id = htonl (bd_id);
4788 /* Use a control ping for synchronization */
4789 MPING (CONTROL_PING, mp_ping);
4797 api_tap_create_v2 (vat_main_t * vam)
4799 unformat_input_t *i = vam->input;
4800 vl_api_tap_create_v2_t *mp;
4804 u32 num_rx_queues = 0;
4805 u8 *host_if_name = 0;
4806 u8 host_if_name_set = 0;
4809 u8 host_mac_addr[6];
4810 u8 host_mac_addr_set = 0;
4811 u8 *host_bridge = 0;
4812 u8 host_bridge_set = 0;
4813 u8 host_ip4_prefix_set = 0;
4814 u8 host_ip6_prefix_set = 0;
4815 ip4_address_t host_ip4_addr;
4816 ip4_address_t host_ip4_gw;
4817 u8 host_ip4_gw_set = 0;
4818 u32 host_ip4_prefix_len = 0;
4819 ip6_address_t host_ip6_addr;
4820 ip6_address_t host_ip6_gw;
4821 u8 host_ip6_gw_set = 0;
4822 u32 host_ip6_prefix_len = 0;
4823 u32 host_mtu_size = 0;
4824 u8 host_mtu_set = 0;
4827 u32 rx_ring_sz = 0, tx_ring_sz = 0;
4829 clib_memset (mac_address, 0, sizeof (mac_address));
4831 /* Parse args required to build the message */
4832 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4834 if (unformat (i, "id %u", &id))
4838 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4840 else if (unformat (i, "host-if-name %s", &host_if_name))
4841 host_if_name_set = 1;
4842 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
4844 else if (unformat (i, "host-ns %s", &host_ns))
4846 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
4848 host_mac_addr_set = 1;
4849 else if (unformat (i, "host-bridge %s", &host_bridge))
4850 host_bridge_set = 1;
4851 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
4852 &host_ip4_addr, &host_ip4_prefix_len))
4853 host_ip4_prefix_set = 1;
4854 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
4855 &host_ip6_addr, &host_ip6_prefix_len))
4856 host_ip6_prefix_set = 1;
4857 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
4859 host_ip4_gw_set = 1;
4860 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
4862 host_ip6_gw_set = 1;
4863 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
4865 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
4867 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
4869 else if (unformat (i, "no-gso"))
4870 tap_flags &= ~TAP_API_FLAG_GSO;
4871 else if (unformat (i, "gso"))
4872 tap_flags |= TAP_API_FLAG_GSO;
4873 else if (unformat (i, "csum-offload"))
4874 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
4875 else if (unformat (i, "persist"))
4876 tap_flags |= TAP_API_FLAG_PERSIST;
4877 else if (unformat (i, "attach"))
4878 tap_flags |= TAP_API_FLAG_ATTACH;
4879 else if (unformat (i, "tun"))
4880 tap_flags |= TAP_API_FLAG_TUN;
4881 else if (unformat (i, "gro-coalesce"))
4882 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
4883 else if (unformat (i, "packed"))
4884 tap_flags |= TAP_API_FLAG_PACKED;
4885 else if (unformat (i, "in-order"))
4886 tap_flags |= TAP_API_FLAG_IN_ORDER;
4891 if (vec_len (host_if_name) > 63)
4893 errmsg ("tap name too long. ");
4896 if (vec_len (host_ns) > 63)
4898 errmsg ("host name space too long. ");
4901 if (vec_len (host_bridge) > 63)
4903 errmsg ("host bridge name too long. ");
4906 if (host_ip4_prefix_len > 32)
4908 errmsg ("host ip4 prefix length not valid. ");
4911 if (host_ip6_prefix_len > 128)
4913 errmsg ("host ip6 prefix length not valid. ");
4916 if (!is_pow2 (rx_ring_sz))
4918 errmsg ("rx ring size must be power of 2. ");
4921 if (rx_ring_sz > 32768)
4923 errmsg ("rx ring size must be 32768 or lower. ");
4926 if (!is_pow2 (tx_ring_sz))
4928 errmsg ("tx ring size must be power of 2. ");
4931 if (tx_ring_sz > 32768)
4933 errmsg ("tx ring size must be 32768 or lower. ");
4936 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
4938 errmsg ("host MTU size must be in between 64 and 65355. ");
4942 /* Construct the API message */
4943 M (TAP_CREATE_V2, mp);
4945 mp->id = ntohl (id);
4946 mp->use_random_mac = random_mac;
4947 mp->num_rx_queues = (u8) num_rx_queues;
4948 mp->tx_ring_sz = ntohs (tx_ring_sz);
4949 mp->rx_ring_sz = ntohs (rx_ring_sz);
4950 mp->host_mtu_set = host_mtu_set;
4951 mp->host_mtu_size = ntohl (host_mtu_size);
4952 mp->host_mac_addr_set = host_mac_addr_set;
4953 mp->host_ip4_prefix_set = host_ip4_prefix_set;
4954 mp->host_ip6_prefix_set = host_ip6_prefix_set;
4955 mp->host_ip4_gw_set = host_ip4_gw_set;
4956 mp->host_ip6_gw_set = host_ip6_gw_set;
4957 mp->tap_flags = ntohl (tap_flags);
4958 mp->host_namespace_set = host_ns_set;
4959 mp->host_if_name_set = host_if_name_set;
4960 mp->host_bridge_set = host_bridge_set;
4962 if (random_mac == 0)
4963 clib_memcpy (mp->mac_address, mac_address, 6);
4964 if (host_mac_addr_set)
4965 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
4966 if (host_if_name_set)
4967 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
4969 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
4970 if (host_bridge_set)
4971 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
4972 if (host_ip4_prefix_set)
4974 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
4975 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
4977 if (host_ip6_prefix_set)
4979 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
4980 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
4982 if (host_ip4_gw_set)
4983 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
4984 if (host_ip6_gw_set)
4985 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
4988 vec_free (host_if_name);
4989 vec_free (host_bridge);
4994 /* Wait for a reply... */
5000 api_tap_delete_v2 (vat_main_t * vam)
5002 unformat_input_t *i = vam->input;
5003 vl_api_tap_delete_v2_t *mp;
5004 u32 sw_if_index = ~0;
5005 u8 sw_if_index_set = 0;
5008 /* Parse args required to build the message */
5009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5011 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5012 sw_if_index_set = 1;
5013 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5014 sw_if_index_set = 1;
5019 if (sw_if_index_set == 0)
5021 errmsg ("missing vpp interface name. ");
5025 /* Construct the API message */
5026 M (TAP_DELETE_V2, mp);
5028 mp->sw_if_index = ntohl (sw_if_index);
5033 /* Wait for a reply... */
5039 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5041 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5044 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5047 addr->domain = x[0];
5050 addr->function = x[3];
5056 api_virtio_pci_create_v2 (vat_main_t * vam)
5058 unformat_input_t *i = vam->input;
5059 vl_api_virtio_pci_create_v2_t *mp;
5063 u64 features = (u64) ~ (0ULL);
5064 u32 virtio_flags = 0;
5067 clib_memset (mac_address, 0, sizeof (mac_address));
5069 /* Parse args required to build the message */
5070 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5072 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5076 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5078 else if (unformat (i, "features 0x%llx", &features))
5080 else if (unformat (i, "gso-enabled"))
5081 virtio_flags |= VIRTIO_API_FLAG_GSO;
5082 else if (unformat (i, "csum-offload-enabled"))
5083 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5084 else if (unformat (i, "gro-coalesce"))
5085 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5086 else if (unformat (i, "packed"))
5087 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5088 else if (unformat (i, "in-order"))
5089 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5090 else if (unformat (i, "buffering"))
5091 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5098 errmsg ("pci address must be non zero. ");
5102 /* Construct the API message */
5103 M (VIRTIO_PCI_CREATE_V2, mp);
5105 mp->use_random_mac = random_mac;
5107 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5108 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5109 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5110 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5112 mp->features = clib_host_to_net_u64 (features);
5113 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5115 if (random_mac == 0)
5116 clib_memcpy (mp->mac_address, mac_address, 6);
5121 /* Wait for a reply... */
5127 api_virtio_pci_delete (vat_main_t * vam)
5129 unformat_input_t *i = vam->input;
5130 vl_api_virtio_pci_delete_t *mp;
5131 u32 sw_if_index = ~0;
5132 u8 sw_if_index_set = 0;
5135 /* Parse args required to build the message */
5136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5138 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5139 sw_if_index_set = 1;
5140 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5141 sw_if_index_set = 1;
5146 if (sw_if_index_set == 0)
5148 errmsg ("missing vpp interface name. ");
5152 /* Construct the API message */
5153 M (VIRTIO_PCI_DELETE, mp);
5155 mp->sw_if_index = htonl (sw_if_index);
5160 /* Wait for a reply... */
5166 api_bond_create (vat_main_t * vam)
5168 unformat_input_t *i = vam->input;
5169 vl_api_bond_create_t *mp;
5179 clib_memset (mac_address, 0, sizeof (mac_address));
5182 /* Parse args required to build the message */
5183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5185 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5187 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5188 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5190 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5193 else if (unformat (i, "numa-only"))
5195 else if (unformat (i, "id %u", &id))
5201 if (mode_is_set == 0)
5203 errmsg ("Missing bond mode. ");
5207 /* Construct the API message */
5208 M (BOND_CREATE, mp);
5210 mp->use_custom_mac = custom_mac;
5212 mp->mode = htonl (mode);
5213 mp->lb = htonl (lb);
5214 mp->id = htonl (id);
5215 mp->numa_only = numa_only;
5218 clib_memcpy (mp->mac_address, mac_address, 6);
5223 /* Wait for a reply... */
5229 api_bond_create2 (vat_main_t * vam)
5231 unformat_input_t *i = vam->input;
5232 vl_api_bond_create2_t *mp;
5243 clib_memset (mac_address, 0, sizeof (mac_address));
5246 /* Parse args required to build the message */
5247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5249 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5251 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5252 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5254 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5257 else if (unformat (i, "numa-only"))
5259 else if (unformat (i, "gso"))
5261 else if (unformat (i, "id %u", &id))
5267 if (mode_is_set == 0)
5269 errmsg ("Missing bond mode. ");
5273 /* Construct the API message */
5274 M (BOND_CREATE2, mp);
5276 mp->use_custom_mac = custom_mac;
5278 mp->mode = htonl (mode);
5279 mp->lb = htonl (lb);
5280 mp->id = htonl (id);
5281 mp->numa_only = numa_only;
5282 mp->enable_gso = gso;
5285 clib_memcpy (mp->mac_address, mac_address, 6);
5290 /* Wait for a reply... */
5296 api_bond_delete (vat_main_t * vam)
5298 unformat_input_t *i = vam->input;
5299 vl_api_bond_delete_t *mp;
5300 u32 sw_if_index = ~0;
5301 u8 sw_if_index_set = 0;
5304 /* Parse args required to build the message */
5305 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5307 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5308 sw_if_index_set = 1;
5309 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5310 sw_if_index_set = 1;
5315 if (sw_if_index_set == 0)
5317 errmsg ("missing vpp interface name. ");
5321 /* Construct the API message */
5322 M (BOND_DELETE, mp);
5324 mp->sw_if_index = ntohl (sw_if_index);
5329 /* Wait for a reply... */
5335 api_bond_add_member (vat_main_t * vam)
5337 unformat_input_t *i = vam->input;
5338 vl_api_bond_add_member_t *mp;
5339 u32 bond_sw_if_index;
5343 u32 bond_sw_if_index_is_set = 0;
5345 u8 sw_if_index_is_set = 0;
5347 /* Parse args required to build the message */
5348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5350 if (unformat (i, "sw_if_index %d", &sw_if_index))
5351 sw_if_index_is_set = 1;
5352 else if (unformat (i, "bond %u", &bond_sw_if_index))
5353 bond_sw_if_index_is_set = 1;
5354 else if (unformat (i, "passive %d", &is_passive))
5356 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5362 if (bond_sw_if_index_is_set == 0)
5364 errmsg ("Missing bond sw_if_index. ");
5367 if (sw_if_index_is_set == 0)
5369 errmsg ("Missing member sw_if_index. ");
5373 /* Construct the API message */
5374 M (BOND_ADD_MEMBER, mp);
5376 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5377 mp->sw_if_index = ntohl (sw_if_index);
5378 mp->is_long_timeout = is_long_timeout;
5379 mp->is_passive = is_passive;
5384 /* Wait for a reply... */
5390 api_bond_detach_member (vat_main_t * vam)
5392 unformat_input_t *i = vam->input;
5393 vl_api_bond_detach_member_t *mp;
5394 u32 sw_if_index = ~0;
5395 u8 sw_if_index_set = 0;
5398 /* Parse args required to build the message */
5399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5401 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5402 sw_if_index_set = 1;
5403 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5404 sw_if_index_set = 1;
5409 if (sw_if_index_set == 0)
5411 errmsg ("missing vpp interface name. ");
5415 /* Construct the API message */
5416 M (BOND_DETACH_MEMBER, mp);
5418 mp->sw_if_index = ntohl (sw_if_index);
5423 /* Wait for a reply... */
5429 api_ip_table_add_del (vat_main_t * vam)
5431 unformat_input_t *i = vam->input;
5432 vl_api_ip_table_add_del_t *mp;
5438 /* Parse args required to build the message */
5439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5441 if (unformat (i, "ipv6"))
5443 else if (unformat (i, "del"))
5445 else if (unformat (i, "add"))
5447 else if (unformat (i, "table %d", &table_id))
5451 clib_warning ("parse error '%U'", format_unformat_error, i);
5458 errmsg ("missing table-ID");
5462 /* Construct the API message */
5463 M (IP_TABLE_ADD_DEL, mp);
5465 mp->table.table_id = ntohl (table_id);
5466 mp->table.is_ip6 = is_ipv6;
5467 mp->is_add = is_add;
5472 /* Wait for a reply... */
5479 unformat_fib_path (unformat_input_t * input, va_list * args)
5481 vat_main_t *vam = va_arg (*args, vat_main_t *);
5482 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5483 u32 weight, preference;
5484 mpls_label_t out_label;
5486 clib_memset (path, 0, sizeof (*path));
5488 path->sw_if_index = ~0;
5492 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5494 if (unformat (input, "%U %U",
5495 unformat_vl_api_ip4_address,
5496 &path->nh.address.ip4,
5497 api_unformat_sw_if_index, vam, &path->sw_if_index))
5499 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5501 else if (unformat (input, "%U %U",
5502 unformat_vl_api_ip6_address,
5503 &path->nh.address.ip6,
5504 api_unformat_sw_if_index, vam, &path->sw_if_index))
5506 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5508 else if (unformat (input, "weight %u", &weight))
5510 path->weight = weight;
5512 else if (unformat (input, "preference %u", &preference))
5514 path->preference = preference;
5516 else if (unformat (input, "%U next-hop-table %d",
5517 unformat_vl_api_ip4_address,
5518 &path->nh.address.ip4, &path->table_id))
5520 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5522 else if (unformat (input, "%U next-hop-table %d",
5523 unformat_vl_api_ip6_address,
5524 &path->nh.address.ip6, &path->table_id))
5526 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5528 else if (unformat (input, "%U",
5529 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5532 * the recursive next-hops are by default in the default table
5535 path->sw_if_index = ~0;
5536 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5538 else if (unformat (input, "%U",
5539 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5542 * the recursive next-hops are by default in the default table
5545 path->sw_if_index = ~0;
5546 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5548 else if (unformat (input, "resolve-via-host"))
5550 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5552 else if (unformat (input, "resolve-via-attached"))
5554 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5556 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5558 path->type = FIB_API_PATH_TYPE_LOCAL;
5559 path->sw_if_index = ~0;
5560 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5562 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5564 path->type = FIB_API_PATH_TYPE_LOCAL;
5565 path->sw_if_index = ~0;
5566 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5568 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5570 else if (unformat (input, "via-label %d", &path->nh.via_label))
5572 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5573 path->sw_if_index = ~0;
5575 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5577 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5578 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5580 else if (unformat (input, "local"))
5582 path->type = FIB_API_PATH_TYPE_LOCAL;
5584 else if (unformat (input, "out-labels"))
5586 while (unformat (input, "%d", &out_label))
5588 path->label_stack[path->n_labels].label = out_label;
5589 path->label_stack[path->n_labels].is_uniform = 0;
5590 path->label_stack[path->n_labels].ttl = 64;
5594 else if (unformat (input, "via"))
5596 /* new path, back up and return */
5597 unformat_put_input (input);
5598 unformat_put_input (input);
5599 unformat_put_input (input);
5600 unformat_put_input (input);
5609 path->proto = ntohl (path->proto);
5610 path->type = ntohl (path->type);
5611 path->flags = ntohl (path->flags);
5612 path->table_id = ntohl (path->table_id);
5613 path->sw_if_index = ntohl (path->sw_if_index);
5619 api_ip_route_add_del (vat_main_t * vam)
5621 unformat_input_t *i = vam->input;
5622 vl_api_ip_route_add_del_t *mp;
5625 u8 is_multipath = 0;
5628 vl_api_prefix_t pfx = { };
5629 vl_api_fib_path_t paths[8];
5633 u32 random_add_del = 0;
5634 u32 *random_vector = 0;
5635 u32 random_seed = 0xdeaddabe;
5637 /* Parse args required to build the message */
5638 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5640 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5642 else if (unformat (i, "del"))
5644 else if (unformat (i, "add"))
5646 else if (unformat (i, "vrf %d", &vrf_id))
5648 else if (unformat (i, "count %d", &count))
5650 else if (unformat (i, "random"))
5652 else if (unformat (i, "multipath"))
5654 else if (unformat (i, "seed %d", &random_seed))
5658 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5661 if (8 == path_count)
5663 errmsg ("max 8 paths");
5669 clib_warning ("parse error '%U'", format_unformat_error, i);
5676 errmsg ("specify a path; via ...");
5679 if (prefix_set == 0)
5681 errmsg ("missing prefix");
5685 /* Generate a pile of unique, random routes */
5688 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5689 u32 this_random_address;
5692 random_hash = hash_create (count, sizeof (uword));
5694 hash_set (random_hash, i->as_u32, 1);
5695 for (j = 0; j <= count; j++)
5699 this_random_address = random_u32 (&random_seed);
5700 this_random_address =
5701 clib_host_to_net_u32 (this_random_address);
5703 while (hash_get (random_hash, this_random_address));
5704 vec_add1 (random_vector, this_random_address);
5705 hash_set (random_hash, this_random_address, 1);
5707 hash_free (random_hash);
5708 set_ip4_address (&pfx.address, random_vector[0]);
5713 /* Turn on async mode */
5714 vam->async_mode = 1;
5715 vam->async_errors = 0;
5716 before = vat_time_now (vam);
5719 for (j = 0; j < count; j++)
5721 /* Construct the API message */
5722 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5724 mp->is_add = is_add;
5725 mp->is_multipath = is_multipath;
5727 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5728 mp->route.table_id = ntohl (vrf_id);
5729 mp->route.n_paths = path_count;
5731 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5734 set_ip4_address (&pfx.address, random_vector[j + 1]);
5736 increment_address (&pfx.address);
5739 /* If we receive SIGTERM, stop now... */
5744 /* When testing multiple add/del ops, use a control-ping to sync */
5747 vl_api_control_ping_t *mp_ping;
5751 /* Shut off async mode */
5752 vam->async_mode = 0;
5754 MPING (CONTROL_PING, mp_ping);
5757 timeout = vat_time_now (vam) + 1.0;
5758 while (vat_time_now (vam) < timeout)
5759 if (vam->result_ready == 1)
5764 if (vam->retval == -99)
5767 if (vam->async_errors > 0)
5769 errmsg ("%d asynchronous errors", vam->async_errors);
5772 vam->async_errors = 0;
5773 after = vat_time_now (vam);
5775 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5779 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5780 count, after - before, count / (after - before));
5786 /* Wait for a reply... */
5791 /* Return the good/bad news */
5792 return (vam->retval);
5796 api_ip_mroute_add_del (vat_main_t * vam)
5798 unformat_input_t *i = vam->input;
5799 u8 path_set = 0, prefix_set = 0, is_add = 1;
5800 vl_api_ip_mroute_add_del_t *mp;
5801 mfib_entry_flags_t eflags = 0;
5802 vl_api_mfib_path_t path;
5803 vl_api_mprefix_t pfx = { };
5807 /* Parse args required to build the message */
5808 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5810 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5813 pfx.grp_address_length = htons (pfx.grp_address_length);
5815 else if (unformat (i, "del"))
5817 else if (unformat (i, "add"))
5819 else if (unformat (i, "vrf %d", &vrf_id))
5821 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
5822 path.itf_flags = htonl (path.itf_flags);
5823 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
5825 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
5829 clib_warning ("parse error '%U'", format_unformat_error, i);
5834 if (prefix_set == 0)
5836 errmsg ("missing addresses\n");
5841 errmsg ("missing path\n");
5845 /* Construct the API message */
5846 M (IP_MROUTE_ADD_DEL, mp);
5848 mp->is_add = is_add;
5849 mp->is_multipath = 1;
5851 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5852 mp->route.table_id = htonl (vrf_id);
5853 mp->route.n_paths = 1;
5854 mp->route.entry_flags = htonl (eflags);
5856 clib_memcpy (&mp->route.paths, &path, sizeof (path));
5860 /* Wait for a reply... */
5866 api_mpls_table_add_del (vat_main_t * vam)
5868 unformat_input_t *i = vam->input;
5869 vl_api_mpls_table_add_del_t *mp;
5874 /* Parse args required to build the message */
5875 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5877 if (unformat (i, "table %d", &table_id))
5879 else if (unformat (i, "del"))
5881 else if (unformat (i, "add"))
5885 clib_warning ("parse error '%U'", format_unformat_error, i);
5892 errmsg ("missing table-ID");
5896 /* Construct the API message */
5897 M (MPLS_TABLE_ADD_DEL, mp);
5899 mp->mt_table.mt_table_id = ntohl (table_id);
5900 mp->mt_is_add = is_add;
5905 /* Wait for a reply... */
5912 api_mpls_route_add_del (vat_main_t * vam)
5914 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
5915 mpls_label_t local_label = MPLS_LABEL_INVALID;
5916 unformat_input_t *i = vam->input;
5917 vl_api_mpls_route_add_del_t *mp;
5918 vl_api_fib_path_t paths[8];
5922 /* Parse args required to build the message */
5923 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5925 if (unformat (i, "%d", &local_label))
5927 else if (unformat (i, "eos"))
5929 else if (unformat (i, "non-eos"))
5931 else if (unformat (i, "del"))
5933 else if (unformat (i, "add"))
5935 else if (unformat (i, "multipath"))
5937 else if (unformat (i, "count %d", &count))
5941 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5944 if (8 == path_count)
5946 errmsg ("max 8 paths");
5952 clib_warning ("parse error '%U'", format_unformat_error, i);
5959 errmsg ("specify a path; via ...");
5963 if (MPLS_LABEL_INVALID == local_label)
5965 errmsg ("missing label");
5971 /* Turn on async mode */
5972 vam->async_mode = 1;
5973 vam->async_errors = 0;
5974 before = vat_time_now (vam);
5977 for (j = 0; j < count; j++)
5979 /* Construct the API message */
5980 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5982 mp->mr_is_add = is_add;
5983 mp->mr_is_multipath = is_multipath;
5985 mp->mr_route.mr_label = local_label;
5986 mp->mr_route.mr_eos = is_eos;
5987 mp->mr_route.mr_table_id = 0;
5988 mp->mr_route.mr_n_paths = path_count;
5990 clib_memcpy (&mp->mr_route.mr_paths, paths,
5991 sizeof (paths[0]) * path_count);
5997 /* If we receive SIGTERM, stop now... */
6002 /* When testing multiple add/del ops, use a control-ping to sync */
6005 vl_api_control_ping_t *mp_ping;
6009 /* Shut off async mode */
6010 vam->async_mode = 0;
6012 MPING (CONTROL_PING, mp_ping);
6015 timeout = vat_time_now (vam) + 1.0;
6016 while (vat_time_now (vam) < timeout)
6017 if (vam->result_ready == 1)
6022 if (vam->retval == -99)
6025 if (vam->async_errors > 0)
6027 errmsg ("%d asynchronous errors", vam->async_errors);
6030 vam->async_errors = 0;
6031 after = vat_time_now (vam);
6033 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6037 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6038 count, after - before, count / (after - before));
6044 /* Wait for a reply... */
6049 /* Return the good/bad news */
6050 return (vam->retval);
6055 api_mpls_ip_bind_unbind (vat_main_t * vam)
6057 unformat_input_t *i = vam->input;
6058 vl_api_mpls_ip_bind_unbind_t *mp;
6059 u32 ip_table_id = 0;
6061 vl_api_prefix_t pfx;
6063 mpls_label_t local_label = MPLS_LABEL_INVALID;
6066 /* Parse args required to build the message */
6067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6069 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6071 else if (unformat (i, "%d", &local_label))
6073 else if (unformat (i, "table-id %d", &ip_table_id))
6075 else if (unformat (i, "unbind"))
6077 else if (unformat (i, "bind"))
6081 clib_warning ("parse error '%U'", format_unformat_error, i);
6088 errmsg ("IP prefix not set");
6092 if (MPLS_LABEL_INVALID == local_label)
6094 errmsg ("missing label");
6098 /* Construct the API message */
6099 M (MPLS_IP_BIND_UNBIND, mp);
6101 mp->mb_is_bind = is_bind;
6102 mp->mb_ip_table_id = ntohl (ip_table_id);
6103 mp->mb_mpls_table_id = 0;
6104 mp->mb_label = ntohl (local_label);
6105 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6110 /* Wait for a reply... */
6117 api_sr_mpls_policy_add (vat_main_t * vam)
6119 unformat_input_t *i = vam->input;
6120 vl_api_sr_mpls_policy_add_t *mp;
6126 u32 *segments = NULL;
6129 /* Parse args required to build the message */
6130 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6132 if (unformat (i, "bsid %d", &bsid))
6134 else if (unformat (i, "weight %d", &weight))
6136 else if (unformat (i, "spray"))
6138 else if (unformat (i, "next %d", &sid))
6141 vec_add1 (segments, htonl (sid));
6145 clib_warning ("parse error '%U'", format_unformat_error, i);
6152 errmsg ("bsid not set");
6156 if (n_segments == 0)
6158 errmsg ("no sid in segment stack");
6162 /* Construct the API message */
6163 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6165 mp->bsid = htonl (bsid);
6166 mp->weight = htonl (weight);
6167 mp->is_spray = type;
6168 mp->n_segments = n_segments;
6169 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6170 vec_free (segments);
6175 /* Wait for a reply... */
6181 api_sr_mpls_policy_del (vat_main_t * vam)
6183 unformat_input_t *i = vam->input;
6184 vl_api_sr_mpls_policy_del_t *mp;
6188 /* Parse args required to build the message */
6189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6191 if (unformat (i, "bsid %d", &bsid))
6195 clib_warning ("parse error '%U'", format_unformat_error, i);
6202 errmsg ("bsid not set");
6206 /* Construct the API message */
6207 M (SR_MPLS_POLICY_DEL, mp);
6209 mp->bsid = htonl (bsid);
6214 /* Wait for a reply... */
6220 api_mpls_tunnel_add_del (vat_main_t * vam)
6222 unformat_input_t *i = vam->input;
6223 vl_api_mpls_tunnel_add_del_t *mp;
6225 vl_api_fib_path_t paths[8];
6226 u32 sw_if_index = ~0;
6232 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6234 if (unformat (i, "add"))
6238 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6240 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6242 else if (unformat (i, "l2-only"))
6246 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6249 if (8 == path_count)
6251 errmsg ("max 8 paths");
6257 clib_warning ("parse error '%U'", format_unformat_error, i);
6262 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6264 mp->mt_is_add = is_add;
6265 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6266 mp->mt_tunnel.mt_l2_only = l2_only;
6267 mp->mt_tunnel.mt_is_multicast = 0;
6268 mp->mt_tunnel.mt_n_paths = path_count;
6270 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6271 sizeof (paths[0]) * path_count);
6279 api_sw_interface_set_unnumbered (vat_main_t * vam)
6281 unformat_input_t *i = vam->input;
6282 vl_api_sw_interface_set_unnumbered_t *mp;
6284 u32 unnum_sw_index = ~0;
6286 u8 sw_if_index_set = 0;
6289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6291 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6292 sw_if_index_set = 1;
6293 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6294 sw_if_index_set = 1;
6295 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6297 else if (unformat (i, "del"))
6301 clib_warning ("parse error '%U'", format_unformat_error, i);
6306 if (sw_if_index_set == 0)
6308 errmsg ("missing interface name or sw_if_index");
6312 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6314 mp->sw_if_index = ntohl (sw_if_index);
6315 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6316 mp->is_add = is_add;
6325 api_create_vlan_subif (vat_main_t * vam)
6327 unformat_input_t *i = vam->input;
6328 vl_api_create_vlan_subif_t *mp;
6330 u8 sw_if_index_set = 0;
6335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6337 if (unformat (i, "sw_if_index %d", &sw_if_index))
6338 sw_if_index_set = 1;
6340 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6341 sw_if_index_set = 1;
6342 else if (unformat (i, "vlan %d", &vlan_id))
6346 clib_warning ("parse error '%U'", format_unformat_error, i);
6351 if (sw_if_index_set == 0)
6353 errmsg ("missing interface name or sw_if_index");
6357 if (vlan_id_set == 0)
6359 errmsg ("missing vlan_id");
6362 M (CREATE_VLAN_SUBIF, mp);
6364 mp->sw_if_index = ntohl (sw_if_index);
6365 mp->vlan_id = ntohl (vlan_id);
6372 #define foreach_create_subif_bit \
6379 _(outer_vlan_id_any) \
6380 _(inner_vlan_id_any)
6382 #define foreach_create_subif_flag \
6387 _(4, "exact_match") \
6388 _(5, "default_sub") \
6389 _(6, "outer_vlan_id_any") \
6390 _(7, "inner_vlan_id_any")
6393 api_create_subif (vat_main_t * vam)
6395 unformat_input_t *i = vam->input;
6396 vl_api_create_subif_t *mp;
6398 u8 sw_if_index_set = 0;
6401 u32 __attribute__ ((unused)) no_tags = 0;
6402 u32 __attribute__ ((unused)) one_tag = 0;
6403 u32 __attribute__ ((unused)) two_tags = 0;
6404 u32 __attribute__ ((unused)) dot1ad = 0;
6405 u32 __attribute__ ((unused)) exact_match = 0;
6406 u32 __attribute__ ((unused)) default_sub = 0;
6407 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
6408 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
6410 u16 outer_vlan_id = 0;
6411 u16 inner_vlan_id = 0;
6414 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6416 if (unformat (i, "sw_if_index %d", &sw_if_index))
6417 sw_if_index_set = 1;
6419 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6420 sw_if_index_set = 1;
6421 else if (unformat (i, "sub_id %d", &sub_id))
6423 else if (unformat (i, "outer_vlan_id %d", &tmp))
6424 outer_vlan_id = tmp;
6425 else if (unformat (i, "inner_vlan_id %d", &tmp))
6426 inner_vlan_id = tmp;
6428 #define _(a) else if (unformat (i, #a)) a = 1 ;
6429 foreach_create_subif_bit
6433 clib_warning ("parse error '%U'", format_unformat_error, i);
6438 if (sw_if_index_set == 0)
6440 errmsg ("missing interface name or sw_if_index");
6444 if (sub_id_set == 0)
6446 errmsg ("missing sub_id");
6449 M (CREATE_SUBIF, mp);
6451 mp->sw_if_index = ntohl (sw_if_index);
6452 mp->sub_id = ntohl (sub_id);
6454 #define _(a,b) mp->sub_if_flags |= (1 << a);
6455 foreach_create_subif_flag;
6458 mp->outer_vlan_id = ntohs (outer_vlan_id);
6459 mp->inner_vlan_id = ntohs (inner_vlan_id);
6467 api_ip_table_replace_begin (vat_main_t * vam)
6469 unformat_input_t *i = vam->input;
6470 vl_api_ip_table_replace_begin_t *mp;
6475 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6477 if (unformat (i, "table %d", &table_id))
6479 else if (unformat (i, "ipv6"))
6483 clib_warning ("parse error '%U'", format_unformat_error, i);
6488 M (IP_TABLE_REPLACE_BEGIN, mp);
6490 mp->table.table_id = ntohl (table_id);
6491 mp->table.is_ip6 = is_ipv6;
6499 api_ip_table_flush (vat_main_t * vam)
6501 unformat_input_t *i = vam->input;
6502 vl_api_ip_table_flush_t *mp;
6507 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6509 if (unformat (i, "table %d", &table_id))
6511 else if (unformat (i, "ipv6"))
6515 clib_warning ("parse error '%U'", format_unformat_error, i);
6520 M (IP_TABLE_FLUSH, mp);
6522 mp->table.table_id = ntohl (table_id);
6523 mp->table.is_ip6 = is_ipv6;
6531 api_ip_table_replace_end (vat_main_t * vam)
6533 unformat_input_t *i = vam->input;
6534 vl_api_ip_table_replace_end_t *mp;
6539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6541 if (unformat (i, "table %d", &table_id))
6543 else if (unformat (i, "ipv6"))
6547 clib_warning ("parse error '%U'", format_unformat_error, i);
6552 M (IP_TABLE_REPLACE_END, mp);
6554 mp->table.table_id = ntohl (table_id);
6555 mp->table.is_ip6 = is_ipv6;
6563 api_set_ip_flow_hash (vat_main_t * vam)
6565 unformat_input_t *i = vam->input;
6566 vl_api_set_ip_flow_hash_t *mp;
6578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6580 if (unformat (i, "vrf %d", &vrf_id))
6582 else if (unformat (i, "ipv6"))
6584 else if (unformat (i, "src"))
6586 else if (unformat (i, "dst"))
6588 else if (unformat (i, "sport"))
6590 else if (unformat (i, "dport"))
6592 else if (unformat (i, "proto"))
6594 else if (unformat (i, "reverse"))
6599 clib_warning ("parse error '%U'", format_unformat_error, i);
6604 if (vrf_id_set == 0)
6606 errmsg ("missing vrf id");
6610 M (SET_IP_FLOW_HASH, mp);
6616 mp->reverse = reverse;
6617 mp->vrf_id = ntohl (vrf_id);
6618 mp->is_ipv6 = is_ipv6;
6626 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6628 unformat_input_t *i = vam->input;
6629 vl_api_sw_interface_ip6_enable_disable_t *mp;
6631 u8 sw_if_index_set = 0;
6635 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6637 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6638 sw_if_index_set = 1;
6639 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6640 sw_if_index_set = 1;
6641 else if (unformat (i, "enable"))
6643 else if (unformat (i, "disable"))
6647 clib_warning ("parse error '%U'", format_unformat_error, i);
6652 if (sw_if_index_set == 0)
6654 errmsg ("missing interface name or sw_if_index");
6658 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6660 mp->sw_if_index = ntohl (sw_if_index);
6661 mp->enable = enable;
6670 api_l2_patch_add_del (vat_main_t * vam)
6672 unformat_input_t *i = vam->input;
6673 vl_api_l2_patch_add_del_t *mp;
6675 u8 rx_sw_if_index_set = 0;
6677 u8 tx_sw_if_index_set = 0;
6681 /* Parse args required to build the message */
6682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6684 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6685 rx_sw_if_index_set = 1;
6686 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6687 tx_sw_if_index_set = 1;
6688 else if (unformat (i, "rx"))
6690 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6692 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6694 rx_sw_if_index_set = 1;
6699 else if (unformat (i, "tx"))
6701 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6703 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6705 tx_sw_if_index_set = 1;
6710 else if (unformat (i, "del"))
6716 if (rx_sw_if_index_set == 0)
6718 errmsg ("missing rx interface name or rx_sw_if_index");
6722 if (tx_sw_if_index_set == 0)
6724 errmsg ("missing tx interface name or tx_sw_if_index");
6728 M (L2_PATCH_ADD_DEL, mp);
6730 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6731 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6732 mp->is_add = is_add;
6740 u8 localsid_addr[16];
6749 api_sr_localsid_add_del (vat_main_t * vam)
6751 unformat_input_t *i = vam->input;
6752 vl_api_sr_localsid_add_del_t *mp;
6755 ip6_address_t localsid;
6759 u32 fib_table = ~(u32) 0;
6760 ip46_address_t nh_addr;
6761 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6763 bool nexthop_set = 0;
6767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6769 if (unformat (i, "del"))
6771 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6772 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6774 else if (unformat (i, "behavior %u", &behavior));
6775 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6776 else if (unformat (i, "fib-table %u", &fib_table));
6777 else if (unformat (i, "end.psp %u", &behavior));
6782 M (SR_LOCALSID_ADD_DEL, mp);
6784 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6788 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6790 mp->behavior = behavior;
6791 mp->sw_if_index = ntohl (sw_if_index);
6792 mp->fib_table = ntohl (fib_table);
6793 mp->end_psp = end_psp;
6794 mp->is_del = is_del;
6802 api_ioam_enable (vat_main_t * vam)
6804 unformat_input_t *input = vam->input;
6805 vl_api_ioam_enable_t *mp;
6807 int has_trace_option = 0;
6808 int has_pot_option = 0;
6809 int has_seqno_option = 0;
6810 int has_analyse_option = 0;
6813 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6815 if (unformat (input, "trace"))
6816 has_trace_option = 1;
6817 else if (unformat (input, "pot"))
6819 else if (unformat (input, "seqno"))
6820 has_seqno_option = 1;
6821 else if (unformat (input, "analyse"))
6822 has_analyse_option = 1;
6826 M (IOAM_ENABLE, mp);
6827 mp->id = htons (id);
6828 mp->seqno = has_seqno_option;
6829 mp->analyse = has_analyse_option;
6830 mp->pot_enable = has_pot_option;
6831 mp->trace_enable = has_trace_option;
6840 api_ioam_disable (vat_main_t * vam)
6842 vl_api_ioam_disable_t *mp;
6845 M (IOAM_DISABLE, mp);
6851 #define foreach_tcp_proto_field \
6855 #define foreach_udp_proto_field \
6859 #define foreach_ip4_proto_field \
6871 u16 src_port, dst_port;
6874 #if VPP_API_TEST_BUILTIN == 0
6876 unformat_tcp_mask (unformat_input_t * input, va_list * args)
6878 u8 **maskp = va_arg (*args, u8 **);
6880 u8 found_something = 0;
6883 #define _(a) u8 a=0;
6884 foreach_tcp_proto_field;
6887 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6890 #define _(a) else if (unformat (input, #a)) a=1;
6891 foreach_tcp_proto_field
6897 #define _(a) found_something += a;
6898 foreach_tcp_proto_field;
6901 if (found_something == 0)
6904 vec_validate (mask, sizeof (*tcp) - 1);
6906 tcp = (tcp_header_t *) mask;
6908 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
6909 foreach_tcp_proto_field;
6917 unformat_udp_mask (unformat_input_t * input, va_list * args)
6919 u8 **maskp = va_arg (*args, u8 **);
6921 u8 found_something = 0;
6924 #define _(a) u8 a=0;
6925 foreach_udp_proto_field;
6928 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6931 #define _(a) else if (unformat (input, #a)) a=1;
6932 foreach_udp_proto_field
6938 #define _(a) found_something += a;
6939 foreach_udp_proto_field;
6942 if (found_something == 0)
6945 vec_validate (mask, sizeof (*udp) - 1);
6947 udp = (udp_header_t *) mask;
6949 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
6950 foreach_udp_proto_field;
6958 unformat_l4_mask (unformat_input_t * input, va_list * args)
6960 u8 **maskp = va_arg (*args, u8 **);
6961 u16 src_port = 0, dst_port = 0;
6962 tcpudp_header_t *tcpudp;
6964 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6966 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
6968 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
6970 else if (unformat (input, "src_port"))
6972 else if (unformat (input, "dst_port"))
6978 if (!src_port && !dst_port)
6982 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
6984 tcpudp = (tcpudp_header_t *) mask;
6985 tcpudp->src_port = src_port;
6986 tcpudp->dst_port = dst_port;
6994 unformat_ip4_mask (unformat_input_t * input, va_list * args)
6996 u8 **maskp = va_arg (*args, u8 **);
6998 u8 found_something = 0;
7001 #define _(a) u8 a=0;
7002 foreach_ip4_proto_field;
7008 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7010 if (unformat (input, "version"))
7012 else if (unformat (input, "hdr_length"))
7014 else if (unformat (input, "src"))
7016 else if (unformat (input, "dst"))
7018 else if (unformat (input, "proto"))
7021 #define _(a) else if (unformat (input, #a)) a=1;
7022 foreach_ip4_proto_field
7028 #define _(a) found_something += a;
7029 foreach_ip4_proto_field;
7032 if (found_something == 0)
7035 vec_validate (mask, sizeof (*ip) - 1);
7037 ip = (ip4_header_t *) mask;
7039 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7040 foreach_ip4_proto_field;
7043 ip->ip_version_and_header_length = 0;
7046 ip->ip_version_and_header_length |= 0xF0;
7049 ip->ip_version_and_header_length |= 0x0F;
7055 #define foreach_ip6_proto_field \
7063 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7065 u8 **maskp = va_arg (*args, u8 **);
7067 u8 found_something = 0;
7069 u32 ip_version_traffic_class_and_flow_label;
7071 #define _(a) u8 a=0;
7072 foreach_ip6_proto_field;
7075 u8 traffic_class = 0;
7078 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7080 if (unformat (input, "version"))
7082 else if (unformat (input, "traffic-class"))
7084 else if (unformat (input, "flow-label"))
7086 else if (unformat (input, "src"))
7088 else if (unformat (input, "dst"))
7090 else if (unformat (input, "proto"))
7093 #define _(a) else if (unformat (input, #a)) a=1;
7094 foreach_ip6_proto_field
7100 #define _(a) found_something += a;
7101 foreach_ip6_proto_field;
7104 if (found_something == 0)
7107 vec_validate (mask, sizeof (*ip) - 1);
7109 ip = (ip6_header_t *) mask;
7111 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7112 foreach_ip6_proto_field;
7115 ip_version_traffic_class_and_flow_label = 0;
7118 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7121 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7124 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7126 ip->ip_version_traffic_class_and_flow_label =
7127 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7134 unformat_l3_mask (unformat_input_t * input, va_list * args)
7136 u8 **maskp = va_arg (*args, u8 **);
7138 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7140 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7142 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7151 unformat_l2_mask (unformat_input_t * input, va_list * args)
7153 u8 **maskp = va_arg (*args, u8 **);
7168 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7170 if (unformat (input, "src"))
7172 else if (unformat (input, "dst"))
7174 else if (unformat (input, "proto"))
7176 else if (unformat (input, "tag1"))
7178 else if (unformat (input, "tag2"))
7180 else if (unformat (input, "ignore-tag1"))
7182 else if (unformat (input, "ignore-tag2"))
7184 else if (unformat (input, "cos1"))
7186 else if (unformat (input, "cos2"))
7188 else if (unformat (input, "dot1q"))
7190 else if (unformat (input, "dot1ad"))
7195 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7196 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7199 if (tag1 || ignore_tag1 || cos1 || dot1q)
7201 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7204 vec_validate (mask, len - 1);
7207 clib_memset (mask, 0xff, 6);
7210 clib_memset (mask + 6, 0xff, 6);
7214 /* inner vlan tag */
7223 mask[21] = mask[20] = 0xff;
7244 mask[16] = mask[17] = 0xff;
7254 mask[12] = mask[13] = 0xff;
7261 unformat_classify_mask (unformat_input_t * input, va_list * args)
7263 u8 **maskp = va_arg (*args, u8 **);
7264 u32 *skipp = va_arg (*args, u32 *);
7265 u32 *matchp = va_arg (*args, u32 *);
7273 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7275 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7277 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7279 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7281 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7295 if (mask || l2 || l3 || l4)
7299 /* "With a free Ethernet header in every package" */
7301 vec_validate (l2, 13);
7305 vec_append (mask, l3);
7310 vec_append (mask, l4);
7315 /* Scan forward looking for the first significant mask octet */
7316 for (i = 0; i < vec_len (mask); i++)
7320 /* compute (skip, match) params */
7321 *skipp = i / sizeof (u32x4);
7322 vec_delete (mask, *skipp * sizeof (u32x4), 0);
7324 /* Pad mask to an even multiple of the vector size */
7325 while (vec_len (mask) % sizeof (u32x4))
7328 match = vec_len (mask) / sizeof (u32x4);
7330 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
7332 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
7333 if (*tmp || *(tmp + 1))
7338 clib_warning ("BUG: match 0");
7340 _vec_len (mask) = match * sizeof (u32x4);
7350 #endif /* VPP_API_TEST_BUILTIN */
7352 #define foreach_l2_next \
7354 _(ethernet, ETHERNET_INPUT) \
7359 unformat_l2_next_index (unformat_input_t * input, va_list * args)
7361 u32 *miss_next_indexp = va_arg (*args, u32 *);
7366 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
7370 if (unformat (input, "%d", &tmp))
7379 *miss_next_indexp = next_index;
7383 #define foreach_ip_next \
7389 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
7391 u32 *miss_next_indexp = va_arg (*args, u32 *);
7396 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7400 if (unformat (input, "%d", &tmp))
7409 *miss_next_indexp = next_index;
7413 #define foreach_acl_next \
7417 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
7419 u32 *miss_next_indexp = va_arg (*args, u32 *);
7424 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7428 if (unformat (input, "permit"))
7433 else if (unformat (input, "%d", &tmp))
7442 *miss_next_indexp = next_index;
7447 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7449 u32 *r = va_arg (*args, u32 *);
7451 if (unformat (input, "conform-color"))
7452 *r = POLICE_CONFORM;
7453 else if (unformat (input, "exceed-color"))
7461 #if VPP_API_TEST_BUILTIN == 0
7463 unformat_l4_match (unformat_input_t * input, va_list * args)
7465 u8 **matchp = va_arg (*args, u8 **);
7467 u8 *proto_header = 0;
7473 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7475 if (unformat (input, "src_port %d", &src_port))
7477 else if (unformat (input, "dst_port %d", &dst_port))
7483 h.src_port = clib_host_to_net_u16 (src_port);
7484 h.dst_port = clib_host_to_net_u16 (dst_port);
7485 vec_validate (proto_header, sizeof (h) - 1);
7486 memcpy (proto_header, &h, sizeof (h));
7488 *matchp = proto_header;
7494 unformat_ip4_match (unformat_input_t * input, va_list * args)
7496 u8 **matchp = va_arg (*args, u8 **);
7503 int src = 0, dst = 0;
7504 ip4_address_t src_val, dst_val;
7511 int fragment_id = 0;
7512 u32 fragment_id_val;
7518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7520 if (unformat (input, "version %d", &version_val))
7522 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7524 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7526 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7528 else if (unformat (input, "proto %d", &proto_val))
7530 else if (unformat (input, "tos %d", &tos_val))
7532 else if (unformat (input, "length %d", &length_val))
7534 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7536 else if (unformat (input, "ttl %d", &ttl_val))
7538 else if (unformat (input, "checksum %d", &checksum_val))
7544 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7545 + ttl + checksum == 0)
7549 * Aligned because we use the real comparison functions
7551 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7553 ip = (ip4_header_t *) match;
7555 /* These are realistically matched in practice */
7557 ip->src_address.as_u32 = src_val.as_u32;
7560 ip->dst_address.as_u32 = dst_val.as_u32;
7563 ip->protocol = proto_val;
7566 /* These are not, but they're included for completeness */
7568 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7571 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7577 ip->length = clib_host_to_net_u16 (length_val);
7583 ip->checksum = clib_host_to_net_u16 (checksum_val);
7590 unformat_ip6_match (unformat_input_t * input, va_list * args)
7592 u8 **matchp = va_arg (*args, u8 **);
7597 u8 traffic_class = 0;
7598 u32 traffic_class_val = 0;
7601 int src = 0, dst = 0;
7602 ip6_address_t src_val, dst_val;
7605 int payload_length = 0;
7606 u32 payload_length_val;
7609 u32 ip_version_traffic_class_and_flow_label;
7611 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7613 if (unformat (input, "version %d", &version_val))
7615 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7617 else if (unformat (input, "flow_label %d", &flow_label_val))
7619 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7621 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7623 else if (unformat (input, "proto %d", &proto_val))
7625 else if (unformat (input, "payload_length %d", &payload_length_val))
7627 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7633 if (version + traffic_class + flow_label + src + dst + proto +
7634 payload_length + hop_limit == 0)
7638 * Aligned because we use the real comparison functions
7640 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7642 ip = (ip6_header_t *) match;
7645 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7648 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7651 ip->protocol = proto_val;
7653 ip_version_traffic_class_and_flow_label = 0;
7656 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7659 ip_version_traffic_class_and_flow_label |=
7660 (traffic_class_val & 0xFF) << 20;
7663 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7665 ip->ip_version_traffic_class_and_flow_label =
7666 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7669 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7672 ip->hop_limit = hop_limit_val;
7679 unformat_l3_match (unformat_input_t * input, va_list * args)
7681 u8 **matchp = va_arg (*args, u8 **);
7683 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7685 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7687 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7696 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7698 u8 *tagp = va_arg (*args, u8 *);
7701 if (unformat (input, "%d", &tag))
7703 tagp[0] = (tag >> 8) & 0x0F;
7704 tagp[1] = tag & 0xFF;
7712 unformat_l2_match (unformat_input_t * input, va_list * args)
7714 u8 **matchp = va_arg (*args, u8 **);
7734 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7736 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7739 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7741 else if (unformat (input, "proto %U",
7742 unformat_ethernet_type_host_byte_order, &proto_val))
7744 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7746 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7748 else if (unformat (input, "ignore-tag1"))
7750 else if (unformat (input, "ignore-tag2"))
7752 else if (unformat (input, "cos1 %d", &cos1_val))
7754 else if (unformat (input, "cos2 %d", &cos2_val))
7759 if ((src + dst + proto + tag1 + tag2 +
7760 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7763 if (tag1 || ignore_tag1 || cos1)
7765 if (tag2 || ignore_tag2 || cos2)
7768 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7771 clib_memcpy (match, dst_val, 6);
7774 clib_memcpy (match + 6, src_val, 6);
7778 /* inner vlan tag */
7779 match[19] = tag2_val[1];
7780 match[18] = tag2_val[0];
7782 match[18] |= (cos2_val & 0x7) << 5;
7785 match[21] = proto_val & 0xff;
7786 match[20] = proto_val >> 8;
7790 match[15] = tag1_val[1];
7791 match[14] = tag1_val[0];
7794 match[14] |= (cos1_val & 0x7) << 5;
7800 match[15] = tag1_val[1];
7801 match[14] = tag1_val[0];
7804 match[17] = proto_val & 0xff;
7805 match[16] = proto_val >> 8;
7808 match[14] |= (cos1_val & 0x7) << 5;
7814 match[18] |= (cos2_val & 0x7) << 5;
7816 match[14] |= (cos1_val & 0x7) << 5;
7819 match[13] = proto_val & 0xff;
7820 match[12] = proto_val >> 8;
7828 unformat_qos_source (unformat_input_t * input, va_list * args)
7830 int *qs = va_arg (*args, int *);
7832 if (unformat (input, "ip"))
7833 *qs = QOS_SOURCE_IP;
7834 else if (unformat (input, "mpls"))
7835 *qs = QOS_SOURCE_MPLS;
7836 else if (unformat (input, "ext"))
7837 *qs = QOS_SOURCE_EXT;
7838 else if (unformat (input, "vlan"))
7839 *qs = QOS_SOURCE_VLAN;
7848 api_unformat_classify_match (unformat_input_t * input, va_list * args)
7850 u8 **matchp = va_arg (*args, u8 **);
7851 u32 skip_n_vectors = va_arg (*args, u32);
7852 u32 match_n_vectors = va_arg (*args, u32);
7859 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7861 if (unformat (input, "hex %U", unformat_hex_string, &match))
7863 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7865 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7867 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
7881 if (match || l2 || l3 || l4)
7885 /* "Win a free Ethernet header in every packet" */
7887 vec_validate_aligned (l2, 13, sizeof (u32x4));
7891 vec_append_aligned (match, l3, sizeof (u32x4));
7896 vec_append_aligned (match, l4, sizeof (u32x4));
7901 /* Make sure the vector is big enough even if key is all 0's */
7902 vec_validate_aligned
7903 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
7906 /* Set size, include skipped vectors */
7907 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
7918 api_set_ipfix_exporter (vat_main_t *vam)
7920 unformat_input_t *i = vam->input;
7921 vl_api_set_ipfix_exporter_t *mp;
7922 ip4_address_t collector_address;
7923 u8 collector_address_set = 0;
7924 u32 collector_port = ~0;
7925 ip4_address_t src_address;
7926 u8 src_address_set = 0;
7929 u32 template_interval = ~0;
7930 u8 udp_checksum = 0;
7933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7935 if (unformat (i, "collector_address %U", unformat_ip4_address,
7936 &collector_address))
7937 collector_address_set = 1;
7938 else if (unformat (i, "collector_port %d", &collector_port))
7940 else if (unformat (i, "src_address %U", unformat_ip4_address,
7942 src_address_set = 1;
7943 else if (unformat (i, "vrf_id %d", &vrf_id))
7945 else if (unformat (i, "path_mtu %d", &path_mtu))
7947 else if (unformat (i, "template_interval %d", &template_interval))
7949 else if (unformat (i, "udp_checksum"))
7955 if (collector_address_set == 0)
7957 errmsg ("collector_address required");
7961 if (src_address_set == 0)
7963 errmsg ("src_address required");
7967 M (SET_IPFIX_EXPORTER, mp);
7969 memcpy (mp->collector_address.un.ip4, collector_address.data,
7970 sizeof (collector_address.data));
7971 mp->collector_port = htons ((u16) collector_port);
7972 memcpy (mp->src_address.un.ip4, src_address.data,
7973 sizeof (src_address.data));
7974 mp->vrf_id = htonl (vrf_id);
7975 mp->path_mtu = htonl (path_mtu);
7976 mp->template_interval = htonl (template_interval);
7977 mp->udp_checksum = udp_checksum;
7985 api_set_ipfix_classify_stream (vat_main_t * vam)
7987 unformat_input_t *i = vam->input;
7988 vl_api_set_ipfix_classify_stream_t *mp;
7990 u32 src_port = UDP_DST_PORT_ipfix;
7993 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7995 if (unformat (i, "domain %d", &domain_id))
7997 else if (unformat (i, "src_port %d", &src_port))
8001 errmsg ("unknown input `%U'", format_unformat_error, i);
8006 M (SET_IPFIX_CLASSIFY_STREAM, mp);
8008 mp->domain_id = htonl (domain_id);
8009 mp->src_port = htons ((u16) src_port);
8017 api_ipfix_classify_table_add_del (vat_main_t * vam)
8019 unformat_input_t *i = vam->input;
8020 vl_api_ipfix_classify_table_add_del_t *mp;
8022 u32 classify_table_index = ~0;
8024 u8 transport_protocol = 255;
8027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8029 if (unformat (i, "add"))
8031 else if (unformat (i, "del"))
8033 else if (unformat (i, "table %d", &classify_table_index))
8035 else if (unformat (i, "ip4"))
8037 else if (unformat (i, "ip6"))
8039 else if (unformat (i, "tcp"))
8040 transport_protocol = 6;
8041 else if (unformat (i, "udp"))
8042 transport_protocol = 17;
8045 errmsg ("unknown input `%U'", format_unformat_error, i);
8052 errmsg ("expecting: add|del");
8055 if (classify_table_index == ~0)
8057 errmsg ("classifier table not specified");
8060 if (ip_version == 0)
8062 errmsg ("IP version not specified");
8066 M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp);
8068 mp->is_add = is_add;
8069 mp->table_id = htonl (classify_table_index);
8070 mp->ip_version = ip_version;
8071 mp->transport_protocol = transport_protocol;
8079 api_get_node_index (vat_main_t * vam)
8081 unformat_input_t *i = vam->input;
8082 vl_api_get_node_index_t *mp;
8086 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8088 if (unformat (i, "node %s", &name))
8095 errmsg ("node name required");
8098 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
8100 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8104 M (GET_NODE_INDEX, mp);
8105 clib_memcpy (mp->node_name, name, vec_len (name));
8114 api_get_next_index (vat_main_t * vam)
8116 unformat_input_t *i = vam->input;
8117 vl_api_get_next_index_t *mp;
8118 u8 *node_name = 0, *next_node_name = 0;
8121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8123 if (unformat (i, "node-name %s", &node_name))
8125 else if (unformat (i, "next-node-name %s", &next_node_name))
8131 errmsg ("node name required");
8134 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
8136 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8140 if (next_node_name == 0)
8142 errmsg ("next node name required");
8145 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
8147 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
8151 M (GET_NEXT_INDEX, mp);
8152 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
8153 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
8154 vec_free (node_name);
8155 vec_free (next_node_name);
8163 api_add_node_next (vat_main_t * vam)
8165 unformat_input_t *i = vam->input;
8166 vl_api_add_node_next_t *mp;
8171 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8173 if (unformat (i, "node %s", &name))
8175 else if (unformat (i, "next %s", &next))
8182 errmsg ("node name required");
8185 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
8187 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8192 errmsg ("next node required");
8195 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
8197 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
8201 M (ADD_NODE_NEXT, mp);
8202 clib_memcpy (mp->node_name, name, vec_len (name));
8203 clib_memcpy (mp->next_name, next, vec_len (next));
8212 static void vl_api_sw_interface_tap_v2_details_t_handler
8213 (vl_api_sw_interface_tap_v2_details_t * mp)
8215 vat_main_t *vam = &vat_main;
8218 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
8219 mp->host_ip4_prefix.len);
8221 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
8222 mp->host_ip6_prefix.len);
8225 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
8226 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
8227 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8228 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
8229 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
8235 static void vl_api_sw_interface_tap_v2_details_t_handler_json
8236 (vl_api_sw_interface_tap_v2_details_t * mp)
8238 vat_main_t *vam = &vat_main;
8239 vat_json_node_t *node = NULL;
8241 if (VAT_JSON_ARRAY != vam->json_tree.type)
8243 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8244 vat_json_init_array (&vam->json_tree);
8246 node = vat_json_array_add (&vam->json_tree);
8248 vat_json_init_object (node);
8249 vat_json_object_add_uint (node, "id", ntohl (mp->id));
8250 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8251 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
8252 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
8253 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8254 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8255 vat_json_object_add_string_copy (node, "host_mac_addr",
8256 format (0, "%U", format_ethernet_address,
8257 &mp->host_mac_addr));
8258 vat_json_object_add_string_copy (node, "host_namespace",
8259 mp->host_namespace);
8260 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
8261 vat_json_object_add_string_copy (node, "host_ip4_addr",
8262 format (0, "%U/%d", format_ip4_address,
8263 mp->host_ip4_prefix.address,
8264 mp->host_ip4_prefix.len));
8265 vat_json_object_add_string_copy (node, "host_ip6_prefix",
8266 format (0, "%U/%d", format_ip6_address,
8267 mp->host_ip6_prefix.address,
8268 mp->host_ip6_prefix.len));
8273 api_sw_interface_tap_v2_dump (vat_main_t * vam)
8275 vl_api_sw_interface_tap_v2_dump_t *mp;
8276 vl_api_control_ping_t *mp_ping;
8280 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
8281 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
8282 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
8285 /* Get list of tap interfaces */
8286 M (SW_INTERFACE_TAP_V2_DUMP, mp);
8289 /* Use a control ping for synchronization */
8290 MPING (CONTROL_PING, mp_ping);
8297 static void vl_api_sw_interface_virtio_pci_details_t_handler
8298 (vl_api_sw_interface_virtio_pci_details_t * mp)
8300 vat_main_t *vam = &vat_main;
8315 addr.domain = ntohs (mp->pci_addr.domain);
8316 addr.bus = mp->pci_addr.bus;
8317 addr.slot = mp->pci_addr.slot;
8318 addr.function = mp->pci_addr.function;
8320 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
8321 addr.slot, addr.function);
8324 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
8325 pci_addr, ntohl (mp->sw_if_index),
8326 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8327 format_ethernet_address, mp->mac_addr,
8328 clib_net_to_host_u64 (mp->features));
8329 vec_free (pci_addr);
8332 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
8333 (vl_api_sw_interface_virtio_pci_details_t * mp)
8335 vat_main_t *vam = &vat_main;
8336 vat_json_node_t *node = NULL;
8337 vlib_pci_addr_t pci_addr;
8339 if (VAT_JSON_ARRAY != vam->json_tree.type)
8341 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8342 vat_json_init_array (&vam->json_tree);
8344 node = vat_json_array_add (&vam->json_tree);
8346 pci_addr.domain = ntohs (mp->pci_addr.domain);
8347 pci_addr.bus = mp->pci_addr.bus;
8348 pci_addr.slot = mp->pci_addr.slot;
8349 pci_addr.function = mp->pci_addr.function;
8351 vat_json_init_object (node);
8352 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
8353 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8354 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8355 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8356 vat_json_object_add_uint (node, "features",
8357 clib_net_to_host_u64 (mp->features));
8358 vat_json_object_add_string_copy (node, "mac_addr",
8359 format (0, "%U", format_ethernet_address,
8364 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
8366 vl_api_sw_interface_virtio_pci_dump_t *mp;
8367 vl_api_control_ping_t *mp_ping;
8371 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
8372 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
8373 "mac_addr", "features");
8375 /* Get list of tap interfaces */
8376 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
8379 /* Use a control ping for synchronization */
8380 MPING (CONTROL_PING, mp_ping);
8388 api_l2_fib_clear_table (vat_main_t * vam)
8390 // unformat_input_t * i = vam->input;
8391 vl_api_l2_fib_clear_table_t *mp;
8394 M (L2_FIB_CLEAR_TABLE, mp);
8402 api_l2_interface_efp_filter (vat_main_t * vam)
8404 unformat_input_t *i = vam->input;
8405 vl_api_l2_interface_efp_filter_t *mp;
8408 u8 sw_if_index_set = 0;
8411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8413 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8414 sw_if_index_set = 1;
8415 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8416 sw_if_index_set = 1;
8417 else if (unformat (i, "enable"))
8419 else if (unformat (i, "disable"))
8423 clib_warning ("parse error '%U'", format_unformat_error, i);
8428 if (sw_if_index_set == 0)
8430 errmsg ("missing sw_if_index");
8434 M (L2_INTERFACE_EFP_FILTER, mp);
8436 mp->sw_if_index = ntohl (sw_if_index);
8437 mp->enable_disable = enable;
8444 #define foreach_vtr_op \
8445 _("disable", L2_VTR_DISABLED) \
8446 _("push-1", L2_VTR_PUSH_1) \
8447 _("push-2", L2_VTR_PUSH_2) \
8448 _("pop-1", L2_VTR_POP_1) \
8449 _("pop-2", L2_VTR_POP_2) \
8450 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8451 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8452 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8453 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8456 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8458 unformat_input_t *i = vam->input;
8459 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8461 u8 sw_if_index_set = 0;
8469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8471 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8472 sw_if_index_set = 1;
8473 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8474 sw_if_index_set = 1;
8475 else if (unformat (i, "vtr_op %d", &vtr_op))
8477 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8480 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8482 else if (unformat (i, "tag1 %d", &tag1))
8484 else if (unformat (i, "tag2 %d", &tag2))
8488 clib_warning ("parse error '%U'", format_unformat_error, i);
8493 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
8495 errmsg ("missing vtr operation or sw_if_index");
8499 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
8500 mp->sw_if_index = ntohl (sw_if_index);
8501 mp->vtr_op = ntohl (vtr_op);
8502 mp->push_dot1q = ntohl (push_dot1q);
8503 mp->tag1 = ntohl (tag1);
8504 mp->tag2 = ntohl (tag2);
8512 api_create_vhost_user_if (vat_main_t * vam)
8514 unformat_input_t *i = vam->input;
8515 vl_api_create_vhost_user_if_t *mp;
8518 u8 file_name_set = 0;
8519 u32 custom_dev_instance = ~0;
8521 u8 use_custom_mac = 0;
8522 u8 disable_mrg_rxbuf = 0;
8523 u8 disable_indirect_desc = 0;
8526 u8 enable_packed = 0;
8529 /* Shut up coverity */
8530 clib_memset (hwaddr, 0, sizeof (hwaddr));
8532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8534 if (unformat (i, "socket %s", &file_name))
8538 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8540 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8542 else if (unformat (i, "server"))
8544 else if (unformat (i, "disable_mrg_rxbuf"))
8545 disable_mrg_rxbuf = 1;
8546 else if (unformat (i, "disable_indirect_desc"))
8547 disable_indirect_desc = 1;
8548 else if (unformat (i, "gso"))
8550 else if (unformat (i, "packed"))
8552 else if (unformat (i, "tag %s", &tag))
8558 if (file_name_set == 0)
8560 errmsg ("missing socket file name");
8564 if (vec_len (file_name) > 255)
8566 errmsg ("socket file name too long");
8569 vec_add1 (file_name, 0);
8571 M (CREATE_VHOST_USER_IF, mp);
8573 mp->is_server = is_server;
8574 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8575 mp->disable_indirect_desc = disable_indirect_desc;
8576 mp->enable_gso = enable_gso;
8577 mp->enable_packed = enable_packed;
8578 mp->custom_dev_instance = ntohl (custom_dev_instance);
8579 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8580 vec_free (file_name);
8581 if (custom_dev_instance != ~0)
8584 mp->use_custom_mac = use_custom_mac;
8585 clib_memcpy (mp->mac_address, hwaddr, 6);
8587 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8596 api_modify_vhost_user_if (vat_main_t * vam)
8598 unformat_input_t *i = vam->input;
8599 vl_api_modify_vhost_user_if_t *mp;
8602 u8 file_name_set = 0;
8603 u32 custom_dev_instance = ~0;
8604 u8 sw_if_index_set = 0;
8605 u32 sw_if_index = (u32) ~ 0;
8607 u8 enable_packed = 0;
8610 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8612 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8613 sw_if_index_set = 1;
8614 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8615 sw_if_index_set = 1;
8616 else if (unformat (i, "socket %s", &file_name))
8620 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8622 else if (unformat (i, "server"))
8624 else if (unformat (i, "gso"))
8626 else if (unformat (i, "packed"))
8632 if (sw_if_index_set == 0)
8634 errmsg ("missing sw_if_index or interface name");
8638 if (file_name_set == 0)
8640 errmsg ("missing socket file name");
8644 if (vec_len (file_name) > 255)
8646 errmsg ("socket file name too long");
8649 vec_add1 (file_name, 0);
8651 M (MODIFY_VHOST_USER_IF, mp);
8653 mp->sw_if_index = ntohl (sw_if_index);
8654 mp->is_server = is_server;
8655 mp->enable_gso = enable_gso;
8656 mp->enable_packed = enable_packed;
8657 mp->custom_dev_instance = ntohl (custom_dev_instance);
8658 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8659 vec_free (file_name);
8660 if (custom_dev_instance != ~0)
8669 api_create_vhost_user_if_v2 (vat_main_t * vam)
8671 unformat_input_t *i = vam->input;
8672 vl_api_create_vhost_user_if_v2_t *mp;
8675 u8 file_name_set = 0;
8676 u32 custom_dev_instance = ~0;
8678 u8 use_custom_mac = 0;
8679 u8 disable_mrg_rxbuf = 0;
8680 u8 disable_indirect_desc = 0;
8683 u8 enable_packed = 0;
8684 u8 enable_event_idx = 0;
8687 /* Shut up coverity */
8688 clib_memset (hwaddr, 0, sizeof (hwaddr));
8690 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8692 if (unformat (i, "socket %s", &file_name))
8696 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8698 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8700 else if (unformat (i, "server"))
8702 else if (unformat (i, "disable_mrg_rxbuf"))
8703 disable_mrg_rxbuf = 1;
8704 else if (unformat (i, "disable_indirect_desc"))
8705 disable_indirect_desc = 1;
8706 else if (unformat (i, "gso"))
8708 else if (unformat (i, "packed"))
8710 else if (unformat (i, "event-idx"))
8711 enable_event_idx = 1;
8712 else if (unformat (i, "tag %s", &tag))
8718 if (file_name_set == 0)
8720 errmsg ("missing socket file name");
8724 if (vec_len (file_name) > 255)
8726 errmsg ("socket file name too long");
8729 vec_add1 (file_name, 0);
8731 M (CREATE_VHOST_USER_IF_V2, mp);
8733 mp->is_server = is_server;
8734 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8735 mp->disable_indirect_desc = disable_indirect_desc;
8736 mp->enable_gso = enable_gso;
8737 mp->enable_packed = enable_packed;
8738 mp->enable_event_idx = enable_event_idx;
8739 mp->custom_dev_instance = ntohl (custom_dev_instance);
8740 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8741 vec_free (file_name);
8742 if (custom_dev_instance != ~0)
8745 mp->use_custom_mac = use_custom_mac;
8746 clib_memcpy (mp->mac_address, hwaddr, 6);
8748 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8757 api_modify_vhost_user_if_v2 (vat_main_t * vam)
8759 unformat_input_t *i = vam->input;
8760 vl_api_modify_vhost_user_if_v2_t *mp;
8763 u8 file_name_set = 0;
8764 u32 custom_dev_instance = ~0;
8765 u8 sw_if_index_set = 0;
8766 u32 sw_if_index = (u32) ~ 0;
8768 u8 enable_packed = 0;
8769 u8 enable_event_idx = 0;
8772 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8774 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8775 sw_if_index_set = 1;
8776 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8777 sw_if_index_set = 1;
8778 else if (unformat (i, "socket %s", &file_name))
8782 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8784 else if (unformat (i, "server"))
8786 else if (unformat (i, "gso"))
8788 else if (unformat (i, "packed"))
8790 else if (unformat (i, "event-idx"))
8791 enable_event_idx = 1;
8796 if (sw_if_index_set == 0)
8798 errmsg ("missing sw_if_index or interface name");
8802 if (file_name_set == 0)
8804 errmsg ("missing socket file name");
8808 if (vec_len (file_name) > 255)
8810 errmsg ("socket file name too long");
8813 vec_add1 (file_name, 0);
8815 M (MODIFY_VHOST_USER_IF_V2, mp);
8817 mp->sw_if_index = ntohl (sw_if_index);
8818 mp->is_server = is_server;
8819 mp->enable_gso = enable_gso;
8820 mp->enable_packed = enable_packed;
8821 mp->enable_event_idx = enable_event_idx;
8822 mp->custom_dev_instance = ntohl (custom_dev_instance);
8823 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8824 vec_free (file_name);
8825 if (custom_dev_instance != ~0)
8834 api_delete_vhost_user_if (vat_main_t * vam)
8836 unformat_input_t *i = vam->input;
8837 vl_api_delete_vhost_user_if_t *mp;
8838 u32 sw_if_index = ~0;
8839 u8 sw_if_index_set = 0;
8842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8844 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8845 sw_if_index_set = 1;
8846 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8847 sw_if_index_set = 1;
8852 if (sw_if_index_set == 0)
8854 errmsg ("missing sw_if_index or interface name");
8859 M (DELETE_VHOST_USER_IF, mp);
8861 mp->sw_if_index = ntohl (sw_if_index);
8868 static void vl_api_sw_interface_vhost_user_details_t_handler
8869 (vl_api_sw_interface_vhost_user_details_t * mp)
8871 vat_main_t *vam = &vat_main;
8875 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
8876 clib_net_to_host_u32
8877 (mp->features_last_32) <<
8880 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
8881 (char *) mp->interface_name, ntohl (mp->sw_if_index),
8882 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
8883 ntohl (mp->num_regions), (char *) mp->sock_filename);
8884 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
8887 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8888 (vl_api_sw_interface_vhost_user_details_t * mp)
8890 vat_main_t *vam = &vat_main;
8891 vat_json_node_t *node = NULL;
8893 if (VAT_JSON_ARRAY != vam->json_tree.type)
8895 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8896 vat_json_init_array (&vam->json_tree);
8898 node = vat_json_array_add (&vam->json_tree);
8900 vat_json_init_object (node);
8901 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8902 vat_json_object_add_string_copy (node, "interface_name",
8903 mp->interface_name);
8904 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
8905 ntohl (mp->virtio_net_hdr_sz));
8906 vat_json_object_add_uint (node, "features_first_32",
8907 clib_net_to_host_u32 (mp->features_first_32));
8908 vat_json_object_add_uint (node, "features_last_32",
8909 clib_net_to_host_u32 (mp->features_last_32));
8910 vat_json_object_add_uint (node, "is_server", mp->is_server);
8911 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
8912 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
8913 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
8917 api_sw_interface_vhost_user_dump (vat_main_t * vam)
8919 unformat_input_t *i = vam->input;
8920 vl_api_sw_interface_vhost_user_dump_t *mp;
8921 vl_api_control_ping_t *mp_ping;
8923 u32 sw_if_index = ~0;
8925 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8927 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8929 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8935 print (vam->ofp, "Interface name idx hdr_sz features "
8936 "server regions filename");
8938 /* Get list of vhost-user interfaces */
8939 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
8940 mp->sw_if_index = ntohl (sw_if_index);
8943 /* Use a control ping for synchronization */
8944 MPING (CONTROL_PING, mp_ping);
8952 api_show_version (vat_main_t * vam)
8954 vl_api_show_version_t *mp;
8957 M (SHOW_VERSION, mp);
8964 static void vl_api_l2_fib_table_details_t_handler
8965 (vl_api_l2_fib_table_details_t * mp)
8967 vat_main_t *vam = &vat_main;
8969 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8971 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
8972 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
8976 static void vl_api_l2_fib_table_details_t_handler_json
8977 (vl_api_l2_fib_table_details_t * mp)
8979 vat_main_t *vam = &vat_main;
8980 vat_json_node_t *node = NULL;
8982 if (VAT_JSON_ARRAY != vam->json_tree.type)
8984 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8985 vat_json_init_array (&vam->json_tree);
8987 node = vat_json_array_add (&vam->json_tree);
8989 vat_json_init_object (node);
8990 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
8991 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
8992 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8993 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
8994 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
8995 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
8999 api_l2_fib_table_dump (vat_main_t * vam)
9001 unformat_input_t *i = vam->input;
9002 vl_api_l2_fib_table_dump_t *mp;
9003 vl_api_control_ping_t *mp_ping;
9008 /* Parse args required to build the message */
9009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9011 if (unformat (i, "bd_id %d", &bd_id))
9019 errmsg ("missing bridge domain");
9023 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
9025 /* Get list of l2 fib entries */
9026 M (L2_FIB_TABLE_DUMP, mp);
9028 mp->bd_id = ntohl (bd_id);
9031 /* Use a control ping for synchronization */
9032 MPING (CONTROL_PING, mp_ping);
9041 api_interface_name_renumber (vat_main_t * vam)
9043 unformat_input_t *line_input = vam->input;
9044 vl_api_interface_name_renumber_t *mp;
9045 u32 sw_if_index = ~0;
9046 u32 new_show_dev_instance = ~0;
9049 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9051 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
9054 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9056 else if (unformat (line_input, "new_show_dev_instance %d",
9057 &new_show_dev_instance))
9063 if (sw_if_index == ~0)
9065 errmsg ("missing interface name or sw_if_index");
9069 if (new_show_dev_instance == ~0)
9071 errmsg ("missing new_show_dev_instance");
9075 M (INTERFACE_NAME_RENUMBER, mp);
9077 mp->sw_if_index = ntohl (sw_if_index);
9078 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
9086 api_want_l2_macs_events (vat_main_t * vam)
9088 unformat_input_t *line_input = vam->input;
9089 vl_api_want_l2_macs_events_t *mp;
9090 u8 enable_disable = 1;
9092 u32 max_macs_in_event = 0;
9093 u32 learn_limit = 0;
9096 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9098 if (unformat (line_input, "learn-limit %d", &learn_limit))
9100 else if (unformat (line_input, "scan-delay %d", &scan_delay))
9102 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
9104 else if (unformat (line_input, "disable"))
9110 M (WANT_L2_MACS_EVENTS, mp);
9111 mp->enable_disable = enable_disable;
9112 mp->pid = htonl (getpid ());
9113 mp->learn_limit = htonl (learn_limit);
9114 mp->scan_delay = (u8) scan_delay;
9115 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
9122 api_ip_address_dump (vat_main_t * vam)
9124 unformat_input_t *i = vam->input;
9125 vl_api_ip_address_dump_t *mp;
9126 vl_api_control_ping_t *mp_ping;
9127 u32 sw_if_index = ~0;
9128 u8 sw_if_index_set = 0;
9133 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9135 if (unformat (i, "sw_if_index %d", &sw_if_index))
9136 sw_if_index_set = 1;
9138 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9139 sw_if_index_set = 1;
9140 else if (unformat (i, "ipv4"))
9142 else if (unformat (i, "ipv6"))
9148 if (ipv4_set && ipv6_set)
9150 errmsg ("ipv4 and ipv6 flags cannot be both set");
9154 if ((!ipv4_set) && (!ipv6_set))
9156 errmsg ("no ipv4 nor ipv6 flag set");
9160 if (sw_if_index_set == 0)
9162 errmsg ("missing interface name or sw_if_index");
9166 vam->current_sw_if_index = sw_if_index;
9167 vam->is_ipv6 = ipv6_set;
9169 M (IP_ADDRESS_DUMP, mp);
9170 mp->sw_if_index = ntohl (sw_if_index);
9171 mp->is_ipv6 = ipv6_set;
9174 /* Use a control ping for synchronization */
9175 MPING (CONTROL_PING, mp_ping);
9183 api_ip_dump (vat_main_t * vam)
9185 vl_api_ip_dump_t *mp;
9186 vl_api_control_ping_t *mp_ping;
9187 unformat_input_t *in = vam->input;
9194 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
9196 if (unformat (in, "ipv4"))
9198 else if (unformat (in, "ipv6"))
9204 if (ipv4_set && ipv6_set)
9206 errmsg ("ipv4 and ipv6 flags cannot be both set");
9210 if ((!ipv4_set) && (!ipv6_set))
9212 errmsg ("no ipv4 nor ipv6 flag set");
9217 vam->is_ipv6 = is_ipv6;
9220 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
9222 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9224 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
9227 mp->is_ipv6 = ipv6_set;
9230 /* Use a control ping for synchronization */
9231 MPING (CONTROL_PING, mp_ping);
9239 api_ipsec_spd_add_del (vat_main_t * vam)
9241 unformat_input_t *i = vam->input;
9242 vl_api_ipsec_spd_add_del_t *mp;
9247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9249 if (unformat (i, "spd_id %d", &spd_id))
9251 else if (unformat (i, "del"))
9255 clib_warning ("parse error '%U'", format_unformat_error, i);
9261 errmsg ("spd_id must be set");
9265 M (IPSEC_SPD_ADD_DEL, mp);
9267 mp->spd_id = ntohl (spd_id);
9268 mp->is_add = is_add;
9276 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9278 unformat_input_t *i = vam->input;
9279 vl_api_ipsec_interface_add_del_spd_t *mp;
9281 u8 sw_if_index_set = 0;
9282 u32 spd_id = (u32) ~ 0;
9286 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9288 if (unformat (i, "del"))
9290 else if (unformat (i, "spd_id %d", &spd_id))
9293 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9294 sw_if_index_set = 1;
9295 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9296 sw_if_index_set = 1;
9299 clib_warning ("parse error '%U'", format_unformat_error, i);
9305 if (spd_id == (u32) ~ 0)
9307 errmsg ("spd_id must be set");
9311 if (sw_if_index_set == 0)
9313 errmsg ("missing interface name or sw_if_index");
9317 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
9319 mp->spd_id = ntohl (spd_id);
9320 mp->sw_if_index = ntohl (sw_if_index);
9321 mp->is_add = is_add;
9329 api_ipsec_spd_entry_add_del (vat_main_t * vam)
9331 unformat_input_t *i = vam->input;
9332 vl_api_ipsec_spd_entry_add_del_t *mp;
9333 u8 is_add = 1, is_outbound = 0;
9334 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
9336 u32 rport_start = 0, rport_stop = (u32) ~ 0;
9337 u32 lport_start = 0, lport_stop = (u32) ~ 0;
9338 vl_api_address_t laddr_start = { }, laddr_stop =
9347 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9349 if (unformat (i, "del"))
9351 if (unformat (i, "outbound"))
9353 if (unformat (i, "inbound"))
9355 else if (unformat (i, "spd_id %d", &spd_id))
9357 else if (unformat (i, "sa_id %d", &sa_id))
9359 else if (unformat (i, "priority %d", &priority))
9361 else if (unformat (i, "protocol %d", &protocol))
9363 else if (unformat (i, "lport_start %d", &lport_start))
9365 else if (unformat (i, "lport_stop %d", &lport_stop))
9367 else if (unformat (i, "rport_start %d", &rport_start))
9369 else if (unformat (i, "rport_stop %d", &rport_stop))
9371 else if (unformat (i, "laddr_start %U",
9372 unformat_vl_api_address, &laddr_start))
9374 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
9377 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
9380 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
9384 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9386 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
9388 clib_warning ("unsupported action: 'resolve'");
9394 clib_warning ("parse error '%U'", format_unformat_error, i);
9400 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
9402 mp->is_add = is_add;
9404 mp->entry.spd_id = ntohl (spd_id);
9405 mp->entry.priority = ntohl (priority);
9406 mp->entry.is_outbound = is_outbound;
9408 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
9409 sizeof (vl_api_address_t));
9410 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
9411 sizeof (vl_api_address_t));
9412 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
9413 sizeof (vl_api_address_t));
9414 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
9415 sizeof (vl_api_address_t));
9417 mp->entry.protocol = (u8) protocol;
9418 mp->entry.local_port_start = ntohs ((u16) lport_start);
9419 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
9420 mp->entry.remote_port_start = ntohs ((u16) rport_start);
9421 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
9422 mp->entry.policy = (u8) policy;
9423 mp->entry.sa_id = ntohl (sa_id);
9431 api_ipsec_sad_entry_add_del (vat_main_t * vam)
9433 unformat_input_t *i = vam->input;
9434 vl_api_ipsec_sad_entry_add_del_t *mp;
9435 u32 sad_id = 0, spi = 0;
9436 u8 *ck = 0, *ik = 0;
9439 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
9440 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
9441 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
9442 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
9443 vl_api_address_t tun_src, tun_dst;
9446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9448 if (unformat (i, "del"))
9450 else if (unformat (i, "sad_id %d", &sad_id))
9452 else if (unformat (i, "spi %d", &spi))
9454 else if (unformat (i, "esp"))
9455 protocol = IPSEC_API_PROTO_ESP;
9457 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
9459 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9460 if (ADDRESS_IP6 == tun_src.af)
9461 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9464 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
9466 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9467 if (ADDRESS_IP6 == tun_src.af)
9468 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9471 if (unformat (i, "crypto_alg %U",
9472 unformat_ipsec_api_crypto_alg, &crypto_alg))
9474 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9476 else if (unformat (i, "integ_alg %U",
9477 unformat_ipsec_api_integ_alg, &integ_alg))
9479 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9483 clib_warning ("parse error '%U'", format_unformat_error, i);
9489 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
9491 mp->is_add = is_add;
9492 mp->entry.sad_id = ntohl (sad_id);
9493 mp->entry.protocol = protocol;
9494 mp->entry.spi = ntohl (spi);
9495 mp->entry.flags = flags;
9497 mp->entry.crypto_algorithm = crypto_alg;
9498 mp->entry.integrity_algorithm = integ_alg;
9499 mp->entry.crypto_key.length = vec_len (ck);
9500 mp->entry.integrity_key.length = vec_len (ik);
9502 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
9503 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
9505 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
9506 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
9509 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
9511 clib_memcpy (mp->entry.integrity_key.data, ik,
9512 mp->entry.integrity_key.length);
9514 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
9516 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
9517 sizeof (mp->entry.tunnel_src));
9518 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
9519 sizeof (mp->entry.tunnel_dst));
9528 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
9530 vat_main_t *vam = &vat_main;
9532 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
9533 "crypto_key %U integ_alg %u integ_key %U flags %x "
9534 "tunnel_src_addr %U tunnel_dst_addr %U "
9535 "salt %u seq_outbound %lu last_seq_inbound %lu "
9536 "replay_window %lu stat_index %u\n",
9537 ntohl (mp->entry.sad_id),
9538 ntohl (mp->sw_if_index),
9539 ntohl (mp->entry.spi),
9540 ntohl (mp->entry.protocol),
9541 ntohl (mp->entry.crypto_algorithm),
9542 format_hex_bytes, mp->entry.crypto_key.data,
9543 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
9544 format_hex_bytes, mp->entry.integrity_key.data,
9545 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
9546 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
9547 &mp->entry.tunnel_dst, ntohl (mp->salt),
9548 clib_net_to_host_u64 (mp->seq_outbound),
9549 clib_net_to_host_u64 (mp->last_seq_inbound),
9550 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
9553 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
9554 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
9556 static void vl_api_ipsec_sa_details_t_handler_json
9557 (vl_api_ipsec_sa_details_t * mp)
9559 vat_main_t *vam = &vat_main;
9560 vat_json_node_t *node = NULL;
9561 vl_api_ipsec_sad_flags_t flags;
9563 if (VAT_JSON_ARRAY != vam->json_tree.type)
9565 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9566 vat_json_init_array (&vam->json_tree);
9568 node = vat_json_array_add (&vam->json_tree);
9570 vat_json_init_object (node);
9571 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
9572 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9573 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
9574 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
9575 vat_json_object_add_uint (node, "crypto_alg",
9576 ntohl (mp->entry.crypto_algorithm));
9577 vat_json_object_add_uint (node, "integ_alg",
9578 ntohl (mp->entry.integrity_algorithm));
9579 flags = ntohl (mp->entry.flags);
9580 vat_json_object_add_uint (node, "use_esn",
9581 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
9582 vat_json_object_add_uint (node, "use_anti_replay",
9583 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
9584 vat_json_object_add_uint (node, "is_tunnel",
9585 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
9586 vat_json_object_add_uint (node, "is_tunnel_ip6",
9587 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
9588 vat_json_object_add_uint (node, "udp_encap",
9589 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
9590 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
9591 mp->entry.crypto_key.length);
9592 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
9593 mp->entry.integrity_key.length);
9594 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
9595 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
9596 vat_json_object_add_uint (node, "replay_window",
9597 clib_net_to_host_u64 (mp->replay_window));
9598 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
9602 api_ipsec_sa_dump (vat_main_t * vam)
9604 unformat_input_t *i = vam->input;
9605 vl_api_ipsec_sa_dump_t *mp;
9606 vl_api_control_ping_t *mp_ping;
9610 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9612 if (unformat (i, "sa_id %d", &sa_id))
9616 clib_warning ("parse error '%U'", format_unformat_error, i);
9621 M (IPSEC_SA_DUMP, mp);
9623 mp->sa_id = ntohl (sa_id);
9627 /* Use a control ping for synchronization */
9628 M (CONTROL_PING, mp_ping);
9636 api_get_first_msg_id (vat_main_t * vam)
9638 vl_api_get_first_msg_id_t *mp;
9639 unformat_input_t *i = vam->input;
9644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9646 if (unformat (i, "client %s", &name))
9654 errmsg ("missing client name");
9659 if (vec_len (name) > 63)
9661 errmsg ("client name too long");
9665 M (GET_FIRST_MSG_ID, mp);
9666 clib_memcpy (mp->name, name, vec_len (name));
9673 api_get_node_graph (vat_main_t * vam)
9675 vl_api_get_node_graph_t *mp;
9678 M (GET_NODE_GRAPH, mp);
9682 /* Wait for the reply */
9688 api_af_packet_create (vat_main_t * vam)
9690 unformat_input_t *i = vam->input;
9691 vl_api_af_packet_create_t *mp;
9692 u8 *host_if_name = 0;
9694 u8 random_hw_addr = 1;
9697 clib_memset (hw_addr, 0, sizeof (hw_addr));
9699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9701 if (unformat (i, "name %s", &host_if_name))
9702 vec_add1 (host_if_name, 0);
9703 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
9709 if (!vec_len (host_if_name))
9711 errmsg ("host-interface name must be specified");
9715 if (vec_len (host_if_name) > 64)
9717 errmsg ("host-interface name too long");
9721 M (AF_PACKET_CREATE, mp);
9723 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9724 clib_memcpy (mp->hw_addr, hw_addr, 6);
9725 mp->use_random_hw_addr = random_hw_addr;
9726 vec_free (host_if_name);
9734 fprintf (vam->ofp ? vam->ofp : stderr,
9735 " new sw_if_index = %d\n", vam->sw_if_index);
9742 api_af_packet_delete (vat_main_t * vam)
9744 unformat_input_t *i = vam->input;
9745 vl_api_af_packet_delete_t *mp;
9746 u8 *host_if_name = 0;
9749 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9751 if (unformat (i, "name %s", &host_if_name))
9752 vec_add1 (host_if_name, 0);
9757 if (!vec_len (host_if_name))
9759 errmsg ("host-interface name must be specified");
9763 if (vec_len (host_if_name) > 64)
9765 errmsg ("host-interface name too long");
9769 M (AF_PACKET_DELETE, mp);
9771 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9772 vec_free (host_if_name);
9779 static void vl_api_af_packet_details_t_handler
9780 (vl_api_af_packet_details_t * mp)
9782 vat_main_t *vam = &vat_main;
9784 print (vam->ofp, "%-16s %d",
9785 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
9788 static void vl_api_af_packet_details_t_handler_json
9789 (vl_api_af_packet_details_t * mp)
9791 vat_main_t *vam = &vat_main;
9792 vat_json_node_t *node = NULL;
9794 if (VAT_JSON_ARRAY != vam->json_tree.type)
9796 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9797 vat_json_init_array (&vam->json_tree);
9799 node = vat_json_array_add (&vam->json_tree);
9801 vat_json_init_object (node);
9802 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9803 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
9807 api_af_packet_dump (vat_main_t * vam)
9809 vl_api_af_packet_dump_t *mp;
9810 vl_api_control_ping_t *mp_ping;
9813 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
9814 /* Get list of tap interfaces */
9815 M (AF_PACKET_DUMP, mp);
9818 /* Use a control ping for synchronization */
9819 MPING (CONTROL_PING, mp_ping);
9827 api_policer_add_del (vat_main_t * vam)
9829 unformat_input_t *i = vam->input;
9830 vl_api_policer_add_del_t *mp;
9841 qos_pol_action_params_st conform_action, exceed_action, violate_action;
9844 conform_action.action_type = QOS_ACTION_TRANSMIT;
9845 conform_action.dscp = 0;
9846 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
9847 exceed_action.dscp = 0;
9848 violate_action.action_type = QOS_ACTION_DROP;
9849 violate_action.dscp = 0;
9851 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9853 if (unformat (i, "del"))
9855 else if (unformat (i, "name %s", &name))
9857 else if (unformat (i, "cir %u", &cir))
9859 else if (unformat (i, "eir %u", &eir))
9861 else if (unformat (i, "cb %u", &cb))
9863 else if (unformat (i, "eb %u", &eb))
9865 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
9868 else if (unformat (i, "round_type %U", unformat_policer_round_type,
9871 else if (unformat (i, "type %U", unformat_policer_type, &type))
9873 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
9876 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
9879 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
9882 else if (unformat (i, "color-aware"))
9888 if (!vec_len (name))
9890 errmsg ("policer name must be specified");
9894 if (vec_len (name) > 64)
9896 errmsg ("policer name too long");
9900 M (POLICER_ADD_DEL, mp);
9902 clib_memcpy (mp->name, name, vec_len (name));
9904 mp->is_add = is_add;
9905 mp->cir = ntohl (cir);
9906 mp->eir = ntohl (eir);
9907 mp->cb = clib_net_to_host_u64 (cb);
9908 mp->eb = clib_net_to_host_u64 (eb);
9909 mp->rate_type = rate_type;
9910 mp->round_type = round_type;
9912 mp->conform_action.type =
9913 (vl_api_sse2_qos_action_type_t) conform_action.action_type;
9914 mp->conform_action.dscp = conform_action.dscp;
9915 mp->exceed_action.type =
9916 (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
9917 mp->exceed_action.dscp = exceed_action.dscp;
9918 mp->violate_action.type =
9919 (vl_api_sse2_qos_action_type_t) violate_action.action_type;
9920 mp->violate_action.dscp = violate_action.dscp;
9921 mp->color_aware = color_aware;
9929 api_policer_dump (vat_main_t * vam)
9931 unformat_input_t *i = vam->input;
9932 vl_api_policer_dump_t *mp;
9933 vl_api_control_ping_t *mp_ping;
9935 u8 match_name_valid = 0;
9938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9940 if (unformat (i, "name %s", &match_name))
9942 vec_add1 (match_name, 0);
9943 match_name_valid = 1;
9949 M (POLICER_DUMP, mp);
9950 mp->match_name_valid = match_name_valid;
9951 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
9952 vec_free (match_name);
9956 /* Use a control ping for synchronization */
9957 MPING (CONTROL_PING, mp_ping);
9960 /* Wait for a reply... */
9966 format_fib_api_path_nh_proto (u8 * s, va_list * args)
9968 vl_api_fib_path_nh_proto_t proto =
9969 va_arg (*args, vl_api_fib_path_nh_proto_t);
9973 case FIB_API_PATH_NH_PROTO_IP4:
9974 s = format (s, "ip4");
9976 case FIB_API_PATH_NH_PROTO_IP6:
9977 s = format (s, "ip6");
9979 case FIB_API_PATH_NH_PROTO_MPLS:
9980 s = format (s, "mpls");
9982 case FIB_API_PATH_NH_PROTO_BIER:
9983 s = format (s, "bier");
9985 case FIB_API_PATH_NH_PROTO_ETHERNET:
9986 s = format (s, "ethernet");
9994 format_vl_api_ip_address_union (u8 * s, va_list * args)
9996 vl_api_address_family_t af = va_arg (*args, int);
9997 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
10002 s = format (s, "%U", format_ip4_address, u->ip4);
10005 s = format (s, "%U", format_ip6_address, u->ip6);
10012 format_vl_api_fib_path_type (u8 * s, va_list * args)
10014 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
10018 case FIB_API_PATH_TYPE_NORMAL:
10019 s = format (s, "normal");
10021 case FIB_API_PATH_TYPE_LOCAL:
10022 s = format (s, "local");
10024 case FIB_API_PATH_TYPE_DROP:
10025 s = format (s, "drop");
10027 case FIB_API_PATH_TYPE_UDP_ENCAP:
10028 s = format (s, "udp-encap");
10030 case FIB_API_PATH_TYPE_BIER_IMP:
10031 s = format (s, "bier-imp");
10033 case FIB_API_PATH_TYPE_ICMP_UNREACH:
10034 s = format (s, "unreach");
10036 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
10037 s = format (s, "prohibit");
10039 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
10040 s = format (s, "src-lookup");
10042 case FIB_API_PATH_TYPE_DVR:
10043 s = format (s, "dvr");
10045 case FIB_API_PATH_TYPE_INTERFACE_RX:
10046 s = format (s, "interface-rx");
10048 case FIB_API_PATH_TYPE_CLASSIFY:
10049 s = format (s, "classify");
10057 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
10060 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
10061 ntohl (fp->weight), ntohl (fp->sw_if_index),
10062 format_vl_api_fib_path_type, fp->type,
10063 format_fib_api_path_nh_proto, fp->proto,
10064 format_vl_api_ip_address_union, &fp->nh.address);
10068 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
10069 vl_api_fib_path_t * fp)
10071 struct in_addr ip4;
10072 struct in6_addr ip6;
10074 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
10075 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
10076 vat_json_object_add_uint (node, "type", fp->type);
10077 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
10078 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
10080 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
10081 vat_json_object_add_ip4 (node, "next_hop", ip4);
10083 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
10085 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
10086 vat_json_object_add_ip6 (node, "next_hop", ip6);
10091 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
10093 vat_main_t *vam = &vat_main;
10094 int count = ntohl (mp->mt_tunnel.mt_n_paths);
10095 vl_api_fib_path_t *fp;
10098 print (vam->ofp, "sw_if_index %d via:",
10099 ntohl (mp->mt_tunnel.mt_sw_if_index));
10100 fp = mp->mt_tunnel.mt_paths;
10101 for (i = 0; i < count; i++)
10103 vl_api_fib_path_print (vam, fp);
10107 print (vam->ofp, "");
10110 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
10111 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
10114 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
10116 vat_main_t *vam = &vat_main;
10117 vat_json_node_t *node = NULL;
10118 int count = ntohl (mp->mt_tunnel.mt_n_paths);
10119 vl_api_fib_path_t *fp;
10122 if (VAT_JSON_ARRAY != vam->json_tree.type)
10124 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10125 vat_json_init_array (&vam->json_tree);
10127 node = vat_json_array_add (&vam->json_tree);
10129 vat_json_init_object (node);
10130 vat_json_object_add_uint (node, "sw_if_index",
10131 ntohl (mp->mt_tunnel.mt_sw_if_index));
10133 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
10135 fp = mp->mt_tunnel.mt_paths;
10136 for (i = 0; i < count; i++)
10138 vl_api_mpls_fib_path_json_print (node, fp);
10144 api_mpls_tunnel_dump (vat_main_t * vam)
10146 vl_api_mpls_tunnel_dump_t *mp;
10147 vl_api_control_ping_t *mp_ping;
10150 M (MPLS_TUNNEL_DUMP, mp);
10154 /* Use a control ping for synchronization */
10155 MPING (CONTROL_PING, mp_ping);
10162 #define vl_api_mpls_table_details_t_endian vl_noop_handler
10163 #define vl_api_mpls_table_details_t_print vl_noop_handler
10167 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
10169 vat_main_t *vam = &vat_main;
10171 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
10174 static void vl_api_mpls_table_details_t_handler_json
10175 (vl_api_mpls_table_details_t * mp)
10177 vat_main_t *vam = &vat_main;
10178 vat_json_node_t *node = NULL;
10180 if (VAT_JSON_ARRAY != vam->json_tree.type)
10182 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10183 vat_json_init_array (&vam->json_tree);
10185 node = vat_json_array_add (&vam->json_tree);
10187 vat_json_init_object (node);
10188 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
10192 api_mpls_table_dump (vat_main_t * vam)
10194 vl_api_mpls_table_dump_t *mp;
10195 vl_api_control_ping_t *mp_ping;
10198 M (MPLS_TABLE_DUMP, mp);
10201 /* Use a control ping for synchronization */
10202 MPING (CONTROL_PING, mp_ping);
10209 #define vl_api_mpls_route_details_t_endian vl_noop_handler
10210 #define vl_api_mpls_route_details_t_print vl_noop_handler
10213 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
10215 vat_main_t *vam = &vat_main;
10216 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
10217 vl_api_fib_path_t *fp;
10221 "table-id %d, label %u, ess_bit %u",
10222 ntohl (mp->mr_route.mr_table_id),
10223 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
10224 fp = mp->mr_route.mr_paths;
10225 for (i = 0; i < count; i++)
10227 vl_api_fib_path_print (vam, fp);
10232 static void vl_api_mpls_route_details_t_handler_json
10233 (vl_api_mpls_route_details_t * mp)
10235 vat_main_t *vam = &vat_main;
10236 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
10237 vat_json_node_t *node = NULL;
10238 vl_api_fib_path_t *fp;
10241 if (VAT_JSON_ARRAY != vam->json_tree.type)
10243 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10244 vat_json_init_array (&vam->json_tree);
10246 node = vat_json_array_add (&vam->json_tree);
10248 vat_json_init_object (node);
10249 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
10250 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
10251 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
10252 vat_json_object_add_uint (node, "path_count", count);
10253 fp = mp->mr_route.mr_paths;
10254 for (i = 0; i < count; i++)
10256 vl_api_mpls_fib_path_json_print (node, fp);
10262 api_mpls_route_dump (vat_main_t * vam)
10264 unformat_input_t *input = vam->input;
10265 vl_api_mpls_route_dump_t *mp;
10266 vl_api_control_ping_t *mp_ping;
10270 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10272 if (unformat (input, "table_id %d", &table_id))
10277 if (table_id == ~0)
10279 errmsg ("missing table id");
10283 M (MPLS_ROUTE_DUMP, mp);
10285 mp->table.mt_table_id = ntohl (table_id);
10288 /* Use a control ping for synchronization */
10289 MPING (CONTROL_PING, mp_ping);
10296 #define vl_api_ip_table_details_t_endian vl_noop_handler
10297 #define vl_api_ip_table_details_t_print vl_noop_handler
10300 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
10302 vat_main_t *vam = &vat_main;
10305 "%s; table-id %d, prefix %U/%d",
10306 mp->table.name, ntohl (mp->table.table_id));
10310 static void vl_api_ip_table_details_t_handler_json
10311 (vl_api_ip_table_details_t * mp)
10313 vat_main_t *vam = &vat_main;
10314 vat_json_node_t *node = NULL;
10316 if (VAT_JSON_ARRAY != vam->json_tree.type)
10318 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10319 vat_json_init_array (&vam->json_tree);
10321 node = vat_json_array_add (&vam->json_tree);
10323 vat_json_init_object (node);
10324 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
10328 api_ip_table_dump (vat_main_t * vam)
10330 vl_api_ip_table_dump_t *mp;
10331 vl_api_control_ping_t *mp_ping;
10334 M (IP_TABLE_DUMP, mp);
10337 /* Use a control ping for synchronization */
10338 MPING (CONTROL_PING, mp_ping);
10346 api_ip_mtable_dump (vat_main_t * vam)
10348 vl_api_ip_mtable_dump_t *mp;
10349 vl_api_control_ping_t *mp_ping;
10352 M (IP_MTABLE_DUMP, mp);
10355 /* Use a control ping for synchronization */
10356 MPING (CONTROL_PING, mp_ping);
10364 api_ip_mroute_dump (vat_main_t * vam)
10366 unformat_input_t *input = vam->input;
10367 vl_api_control_ping_t *mp_ping;
10368 vl_api_ip_mroute_dump_t *mp;
10373 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10375 if (unformat (input, "table_id %d", &table_id))
10377 else if (unformat (input, "ip6"))
10379 else if (unformat (input, "ip4"))
10384 if (table_id == ~0)
10386 errmsg ("missing table id");
10390 M (IP_MROUTE_DUMP, mp);
10391 mp->table.table_id = table_id;
10392 mp->table.is_ip6 = is_ip6;
10395 /* Use a control ping for synchronization */
10396 MPING (CONTROL_PING, mp_ping);
10403 #define vl_api_ip_route_details_t_endian vl_noop_handler
10404 #define vl_api_ip_route_details_t_print vl_noop_handler
10407 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
10409 vat_main_t *vam = &vat_main;
10410 u8 count = mp->route.n_paths;
10411 vl_api_fib_path_t *fp;
10415 "table-id %d, prefix %U/%d",
10416 ntohl (mp->route.table_id),
10417 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
10418 for (i = 0; i < count; i++)
10420 fp = &mp->route.paths[i];
10422 vl_api_fib_path_print (vam, fp);
10427 static void vl_api_ip_route_details_t_handler_json
10428 (vl_api_ip_route_details_t * mp)
10430 vat_main_t *vam = &vat_main;
10431 u8 count = mp->route.n_paths;
10432 vat_json_node_t *node = NULL;
10433 struct in_addr ip4;
10434 struct in6_addr ip6;
10435 vl_api_fib_path_t *fp;
10438 if (VAT_JSON_ARRAY != vam->json_tree.type)
10440 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10441 vat_json_init_array (&vam->json_tree);
10443 node = vat_json_array_add (&vam->json_tree);
10445 vat_json_init_object (node);
10446 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
10447 if (ADDRESS_IP6 == mp->route.prefix.address.af)
10449 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
10450 vat_json_object_add_ip6 (node, "prefix", ip6);
10454 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
10455 vat_json_object_add_ip4 (node, "prefix", ip4);
10457 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
10458 vat_json_object_add_uint (node, "path_count", count);
10459 for (i = 0; i < count; i++)
10461 fp = &mp->route.paths[i];
10462 vl_api_mpls_fib_path_json_print (node, fp);
10467 api_ip_route_dump (vat_main_t * vam)
10469 unformat_input_t *input = vam->input;
10470 vl_api_ip_route_dump_t *mp;
10471 vl_api_control_ping_t *mp_ping;
10477 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10479 if (unformat (input, "table_id %d", &table_id))
10481 else if (unformat (input, "ip6"))
10483 else if (unformat (input, "ip4"))
10488 if (table_id == ~0)
10490 errmsg ("missing table id");
10494 M (IP_ROUTE_DUMP, mp);
10496 mp->table.table_id = table_id;
10497 mp->table.is_ip6 = is_ip6;
10501 /* Use a control ping for synchronization */
10502 MPING (CONTROL_PING, mp_ping);
10510 vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp)
10512 vat_main_t *vam = &vat_main;
10514 print (vam->ofp, "collector_address %U, collector_port %d, "
10515 "src_address %U, vrf_id %d, path_mtu %u, "
10516 "template_interval %u, udp_checksum %d",
10517 format_ip4_address, mp->collector_address,
10518 ntohs (mp->collector_port),
10519 format_ip4_address, mp->src_address,
10520 ntohl (mp->vrf_id), ntohl (mp->path_mtu),
10521 ntohl (mp->template_interval), mp->udp_checksum);
10524 vam->result_ready = 1;
10528 vl_api_ipfix_exporter_details_t_handler_json
10529 (vl_api_ipfix_exporter_details_t * mp)
10531 vat_main_t *vam = &vat_main;
10532 vat_json_node_t node;
10533 struct in_addr collector_address;
10534 struct in_addr src_address;
10536 vat_json_init_object (&node);
10537 clib_memcpy (&collector_address, &mp->collector_address,
10538 sizeof (collector_address));
10539 vat_json_object_add_ip4 (&node, "collector_address", collector_address);
10540 vat_json_object_add_uint (&node, "collector_port",
10541 ntohs (mp->collector_port));
10542 clib_memcpy (&src_address, &mp->src_address, sizeof (src_address));
10543 vat_json_object_add_ip4 (&node, "src_address", src_address);
10544 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
10545 vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu));
10546 vat_json_object_add_uint (&node, "template_interval",
10547 ntohl (mp->template_interval));
10548 vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum);
10550 vat_json_print (vam->ofp, &node);
10551 vat_json_free (&node);
10553 vam->result_ready = 1;
10557 api_ipfix_exporter_dump (vat_main_t * vam)
10559 vl_api_ipfix_exporter_dump_t *mp;
10562 /* Construct the API message */
10563 M (IPFIX_EXPORTER_DUMP, mp);
10572 api_ipfix_classify_stream_dump (vat_main_t * vam)
10574 vl_api_ipfix_classify_stream_dump_t *mp;
10577 /* Construct the API message */
10578 M (IPFIX_CLASSIFY_STREAM_DUMP, mp);
10589 vl_api_ipfix_classify_stream_details_t_handler
10590 (vl_api_ipfix_classify_stream_details_t * mp)
10592 vat_main_t *vam = &vat_main;
10593 print (vam->ofp, "domain_id %d, src_port %d",
10594 ntohl (mp->domain_id), ntohs (mp->src_port));
10596 vam->result_ready = 1;
10600 vl_api_ipfix_classify_stream_details_t_handler_json
10601 (vl_api_ipfix_classify_stream_details_t * mp)
10603 vat_main_t *vam = &vat_main;
10604 vat_json_node_t node;
10606 vat_json_init_object (&node);
10607 vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id));
10608 vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port));
10610 vat_json_print (vam->ofp, &node);
10611 vat_json_free (&node);
10613 vam->result_ready = 1;
10617 api_ipfix_classify_table_dump (vat_main_t * vam)
10619 vl_api_ipfix_classify_table_dump_t *mp;
10620 vl_api_control_ping_t *mp_ping;
10623 if (!vam->json_output)
10625 print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version",
10626 "transport_protocol");
10629 /* Construct the API message */
10630 M (IPFIX_CLASSIFY_TABLE_DUMP, mp);
10635 /* Use a control ping for synchronization */
10636 MPING (CONTROL_PING, mp_ping);
10644 vl_api_ipfix_classify_table_details_t_handler
10645 (vl_api_ipfix_classify_table_details_t * mp)
10647 vat_main_t *vam = &vat_main;
10648 print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version,
10649 mp->transport_protocol);
10653 vl_api_ipfix_classify_table_details_t_handler_json
10654 (vl_api_ipfix_classify_table_details_t * mp)
10656 vat_json_node_t *node = NULL;
10657 vat_main_t *vam = &vat_main;
10659 if (VAT_JSON_ARRAY != vam->json_tree.type)
10661 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10662 vat_json_init_array (&vam->json_tree);
10665 node = vat_json_array_add (&vam->json_tree);
10666 vat_json_init_object (node);
10668 vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id));
10669 vat_json_object_add_uint (node, "ip_version", mp->ip_version);
10670 vat_json_object_add_uint (node, "transport_protocol",
10671 mp->transport_protocol);
10675 api_sw_interface_span_enable_disable (vat_main_t * vam)
10677 unformat_input_t *i = vam->input;
10678 vl_api_sw_interface_span_enable_disable_t *mp;
10679 u32 src_sw_if_index = ~0;
10680 u32 dst_sw_if_index = ~0;
10685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10688 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
10690 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
10694 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
10696 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
10698 else if (unformat (i, "disable"))
10700 else if (unformat (i, "rx"))
10702 else if (unformat (i, "tx"))
10704 else if (unformat (i, "both"))
10706 else if (unformat (i, "l2"))
10712 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
10714 mp->sw_if_index_from = htonl (src_sw_if_index);
10715 mp->sw_if_index_to = htonl (dst_sw_if_index);
10725 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
10728 vat_main_t *vam = &vat_main;
10729 u8 *sw_if_from_name = 0;
10730 u8 *sw_if_to_name = 0;
10731 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10732 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10733 char *states[] = { "none", "rx", "tx", "both" };
10737 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10739 if ((u32) p->value[0] == sw_if_index_from)
10741 sw_if_from_name = (u8 *)(p->key);
10745 if ((u32) p->value[0] == sw_if_index_to)
10747 sw_if_to_name = (u8 *)(p->key);
10748 if (sw_if_from_name)
10753 print (vam->ofp, "%20s => %20s (%s) %s",
10754 sw_if_from_name, sw_if_to_name, states[mp->state],
10755 mp->is_l2 ? "l2" : "device");
10759 vl_api_sw_interface_span_details_t_handler_json
10760 (vl_api_sw_interface_span_details_t * mp)
10762 vat_main_t *vam = &vat_main;
10763 vat_json_node_t *node = NULL;
10764 u8 *sw_if_from_name = 0;
10765 u8 *sw_if_to_name = 0;
10766 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10767 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10771 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10773 if ((u32) p->value[0] == sw_if_index_from)
10775 sw_if_from_name = (u8 *)(p->key);
10779 if ((u32) p->value[0] == sw_if_index_to)
10781 sw_if_to_name = (u8 *)(p->key);
10782 if (sw_if_from_name)
10788 if (VAT_JSON_ARRAY != vam->json_tree.type)
10790 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10791 vat_json_init_array (&vam->json_tree);
10793 node = vat_json_array_add (&vam->json_tree);
10795 vat_json_init_object (node);
10796 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
10797 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
10798 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
10799 if (0 != sw_if_to_name)
10801 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
10803 vat_json_object_add_uint (node, "state", mp->state);
10804 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
10808 api_sw_interface_span_dump (vat_main_t * vam)
10810 unformat_input_t *input = vam->input;
10811 vl_api_sw_interface_span_dump_t *mp;
10812 vl_api_control_ping_t *mp_ping;
10816 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10818 if (unformat (input, "l2"))
10824 M (SW_INTERFACE_SPAN_DUMP, mp);
10828 /* Use a control ping for synchronization */
10829 MPING (CONTROL_PING, mp_ping);
10837 api_pg_create_interface (vat_main_t * vam)
10839 unformat_input_t *input = vam->input;
10840 vl_api_pg_create_interface_t *mp;
10842 u32 if_id = ~0, gso_size = 0;
10843 u8 gso_enabled = 0;
10845 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10847 if (unformat (input, "if_id %d", &if_id))
10849 else if (unformat (input, "gso-enabled"))
10852 if (unformat (input, "gso-size %u", &gso_size))
10856 errmsg ("missing gso-size");
10865 errmsg ("missing pg interface index");
10869 /* Construct the API message */
10870 M (PG_CREATE_INTERFACE, mp);
10872 mp->interface_id = ntohl (if_id);
10873 mp->gso_enabled = gso_enabled;
10881 api_pg_capture (vat_main_t * vam)
10883 unformat_input_t *input = vam->input;
10884 vl_api_pg_capture_t *mp;
10889 u8 pcap_file_set = 0;
10892 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10894 if (unformat (input, "if_id %d", &if_id))
10896 else if (unformat (input, "pcap %s", &pcap_file))
10898 else if (unformat (input, "count %d", &count))
10900 else if (unformat (input, "disable"))
10907 errmsg ("missing pg interface index");
10910 if (pcap_file_set > 0)
10912 if (vec_len (pcap_file) > 255)
10914 errmsg ("pcap file name is too long");
10919 /* Construct the API message */
10920 M (PG_CAPTURE, mp);
10922 mp->interface_id = ntohl (if_id);
10923 mp->is_enabled = enable;
10924 mp->count = ntohl (count);
10925 if (pcap_file_set != 0)
10927 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
10929 vec_free (pcap_file);
10937 api_pg_enable_disable (vat_main_t * vam)
10939 unformat_input_t *input = vam->input;
10940 vl_api_pg_enable_disable_t *mp;
10943 u8 stream_name_set = 0;
10944 u8 *stream_name = 0;
10946 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10948 if (unformat (input, "stream %s", &stream_name))
10949 stream_name_set = 1;
10950 else if (unformat (input, "disable"))
10956 if (stream_name_set > 0)
10958 if (vec_len (stream_name) > 255)
10960 errmsg ("stream name too long");
10965 /* Construct the API message */
10966 M (PG_ENABLE_DISABLE, mp);
10968 mp->is_enabled = enable;
10969 if (stream_name_set != 0)
10971 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
10973 vec_free (stream_name);
10981 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
10983 unformat_input_t *input = vam->input;
10984 vl_api_pg_interface_enable_disable_coalesce_t *mp;
10986 u32 sw_if_index = ~0;
10989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10991 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10993 else if (unformat (input, "sw_if_index %d", &sw_if_index))
10995 else if (unformat (input, "disable"))
11001 if (sw_if_index == ~0)
11003 errmsg ("Interface required but not specified");
11007 /* Construct the API message */
11008 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
11010 mp->coalesce_enabled = enable;
11011 mp->sw_if_index = htonl (sw_if_index);
11019 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
11021 unformat_input_t *input = vam->input;
11022 vl_api_ip_source_and_port_range_check_add_del_t *mp;
11024 u16 *low_ports = 0;
11025 u16 *high_ports = 0;
11028 vl_api_prefix_t prefix;
11035 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11037 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
11039 else if (unformat (input, "vrf %d", &vrf_id))
11041 else if (unformat (input, "del"))
11043 else if (unformat (input, "port %d", &tmp))
11045 if (tmp == 0 || tmp > 65535)
11047 errmsg ("port %d out of range", tmp);
11051 this_hi = this_low + 1;
11052 vec_add1 (low_ports, this_low);
11053 vec_add1 (high_ports, this_hi);
11055 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
11057 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
11059 errmsg ("incorrect range parameters");
11063 /* Note: in debug CLI +1 is added to high before
11064 passing to real fn that does "the work"
11065 (ip_source_and_port_range_check_add_del).
11066 This fn is a wrapper around the binary API fn a
11067 control plane will call, which expects this increment
11068 to have occurred. Hence letting the binary API control
11069 plane fn do the increment for consistency between VAT
11070 and other control planes.
11073 vec_add1 (low_ports, this_low);
11074 vec_add1 (high_ports, this_hi);
11080 if (prefix_set == 0)
11082 errmsg ("<address>/<mask> not specified");
11088 errmsg ("VRF ID required, not specified");
11095 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
11099 if (vec_len (low_ports) == 0)
11101 errmsg ("At least one port or port range required");
11105 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
11107 mp->is_add = is_add;
11109 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
11111 mp->number_of_ranges = vec_len (low_ports);
11113 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
11114 vec_free (low_ports);
11116 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
11117 vec_free (high_ports);
11119 mp->vrf_id = ntohl (vrf_id);
11127 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
11129 unformat_input_t *input = vam->input;
11130 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
11131 u32 sw_if_index = ~0;
11133 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
11134 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
11138 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11140 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11142 else if (unformat (input, "sw_if_index %d", &sw_if_index))
11144 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
11146 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
11148 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
11150 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
11152 else if (unformat (input, "del"))
11158 if (sw_if_index == ~0)
11160 errmsg ("Interface required but not specified");
11166 errmsg ("VRF ID required but not specified");
11170 if (tcp_out_vrf_id == 0
11171 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
11174 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
11178 /* Construct the API message */
11179 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
11181 mp->sw_if_index = ntohl (sw_if_index);
11182 mp->is_add = is_add;
11183 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
11184 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
11185 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
11186 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
11191 /* Wait for a reply... */
11197 api_set_punt (vat_main_t * vam)
11199 unformat_input_t *i = vam->input;
11200 vl_api_address_family_t af;
11201 vl_api_set_punt_t *mp;
11207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11209 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
11211 else if (unformat (i, "protocol %d", &protocol))
11213 else if (unformat (i, "port %d", &port))
11215 else if (unformat (i, "del"))
11219 clib_warning ("parse error '%U'", format_unformat_error, i);
11226 mp->is_add = (u8) is_add;
11227 mp->punt.type = PUNT_API_TYPE_L4;
11228 mp->punt.punt.l4.af = af;
11229 mp->punt.punt.l4.protocol = (u8) protocol;
11230 mp->punt.punt.l4.port = htons ((u16) port);
11238 api_delete_subif (vat_main_t * vam)
11240 unformat_input_t *i = vam->input;
11241 vl_api_delete_subif_t *mp;
11242 u32 sw_if_index = ~0;
11245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11247 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11249 if (unformat (i, "sw_if_index %d", &sw_if_index))
11255 if (sw_if_index == ~0)
11257 errmsg ("missing sw_if_index");
11261 /* Construct the API message */
11262 M (DELETE_SUBIF, mp);
11263 mp->sw_if_index = ntohl (sw_if_index);
11270 #define foreach_pbb_vtr_op \
11271 _("disable", L2_VTR_DISABLED) \
11272 _("pop", L2_VTR_POP_2) \
11273 _("push", L2_VTR_PUSH_2)
11276 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
11278 unformat_input_t *i = vam->input;
11279 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
11280 u32 sw_if_index = ~0, vtr_op = ~0;
11281 u16 outer_tag = ~0;
11282 u8 dmac[6], smac[6];
11283 u8 dmac_set = 0, smac_set = 0;
11289 /* Shut up coverity */
11290 clib_memset (dmac, 0, sizeof (dmac));
11291 clib_memset (smac, 0, sizeof (smac));
11293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11295 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11297 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11299 else if (unformat (i, "vtr_op %d", &vtr_op))
11301 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
11304 else if (unformat (i, "translate_pbb_stag"))
11306 if (unformat (i, "%d", &tmp))
11308 vtr_op = L2_VTR_TRANSLATE_2_1;
11314 ("translate_pbb_stag operation requires outer tag definition");
11318 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
11320 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
11322 else if (unformat (i, "sid %d", &sid))
11324 else if (unformat (i, "vlanid %d", &tmp))
11328 clib_warning ("parse error '%U'", format_unformat_error, i);
11333 if ((sw_if_index == ~0) || (vtr_op == ~0))
11335 errmsg ("missing sw_if_index or vtr operation");
11338 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
11339 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
11342 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
11346 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
11347 mp->sw_if_index = ntohl (sw_if_index);
11348 mp->vtr_op = ntohl (vtr_op);
11349 mp->outer_tag = ntohs (outer_tag);
11350 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
11351 clib_memcpy (mp->b_smac, smac, sizeof (smac));
11352 mp->b_vlanid = ntohs (vlanid);
11353 mp->i_sid = ntohl (sid);
11361 api_feature_enable_disable (vat_main_t * vam)
11363 unformat_input_t *i = vam->input;
11364 vl_api_feature_enable_disable_t *mp;
11366 u8 *feature_name = 0;
11367 u32 sw_if_index = ~0;
11371 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11373 if (unformat (i, "arc_name %s", &arc_name))
11375 else if (unformat (i, "feature_name %s", &feature_name))
11378 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11380 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11382 else if (unformat (i, "disable"))
11390 errmsg ("missing arc name");
11393 if (vec_len (arc_name) > 63)
11395 errmsg ("arc name too long");
11398 if (feature_name == 0)
11400 errmsg ("missing feature name");
11403 if (vec_len (feature_name) > 63)
11405 errmsg ("feature name too long");
11408 if (sw_if_index == ~0)
11410 errmsg ("missing interface name or sw_if_index");
11414 /* Construct the API message */
11415 M (FEATURE_ENABLE_DISABLE, mp);
11416 mp->sw_if_index = ntohl (sw_if_index);
11417 mp->enable = enable;
11418 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
11419 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
11420 vec_free (arc_name);
11421 vec_free (feature_name);
11429 api_feature_gso_enable_disable (vat_main_t * vam)
11431 unformat_input_t *i = vam->input;
11432 vl_api_feature_gso_enable_disable_t *mp;
11433 u32 sw_if_index = ~0;
11437 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11439 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11441 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11443 else if (unformat (i, "enable"))
11445 else if (unformat (i, "disable"))
11451 if (sw_if_index == ~0)
11453 errmsg ("missing interface name or sw_if_index");
11457 /* Construct the API message */
11458 M (FEATURE_GSO_ENABLE_DISABLE, mp);
11459 mp->sw_if_index = ntohl (sw_if_index);
11460 mp->enable_disable = enable;
11468 api_sw_interface_tag_add_del (vat_main_t * vam)
11470 unformat_input_t *i = vam->input;
11471 vl_api_sw_interface_tag_add_del_t *mp;
11472 u32 sw_if_index = ~0;
11477 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11479 if (unformat (i, "tag %s", &tag))
11481 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11483 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11485 else if (unformat (i, "del"))
11491 if (sw_if_index == ~0)
11493 errmsg ("missing interface name or sw_if_index");
11497 if (enable && (tag == 0))
11499 errmsg ("no tag specified");
11503 /* Construct the API message */
11504 M (SW_INTERFACE_TAG_ADD_DEL, mp);
11505 mp->sw_if_index = ntohl (sw_if_index);
11506 mp->is_add = enable;
11508 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
11517 api_sw_interface_add_del_mac_address (vat_main_t * vam)
11519 unformat_input_t *i = vam->input;
11520 vl_api_mac_address_t mac = { 0 };
11521 vl_api_sw_interface_add_del_mac_address_t *mp;
11522 u32 sw_if_index = ~0;
11527 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11529 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11531 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11533 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
11535 else if (unformat (i, "del"))
11541 if (sw_if_index == ~0)
11543 errmsg ("missing interface name or sw_if_index");
11549 errmsg ("missing MAC address");
11553 /* Construct the API message */
11554 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
11555 mp->sw_if_index = ntohl (sw_if_index);
11556 mp->is_add = is_add;
11557 clib_memcpy (&mp->addr, &mac, sizeof (mac));
11564 static void vl_api_l2_xconnect_details_t_handler
11565 (vl_api_l2_xconnect_details_t * mp)
11567 vat_main_t *vam = &vat_main;
11569 print (vam->ofp, "%15d%15d",
11570 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
11573 static void vl_api_l2_xconnect_details_t_handler_json
11574 (vl_api_l2_xconnect_details_t * mp)
11576 vat_main_t *vam = &vat_main;
11577 vat_json_node_t *node = NULL;
11579 if (VAT_JSON_ARRAY != vam->json_tree.type)
11581 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11582 vat_json_init_array (&vam->json_tree);
11584 node = vat_json_array_add (&vam->json_tree);
11586 vat_json_init_object (node);
11587 vat_json_object_add_uint (node, "rx_sw_if_index",
11588 ntohl (mp->rx_sw_if_index));
11589 vat_json_object_add_uint (node, "tx_sw_if_index",
11590 ntohl (mp->tx_sw_if_index));
11594 api_l2_xconnect_dump (vat_main_t * vam)
11596 vl_api_l2_xconnect_dump_t *mp;
11597 vl_api_control_ping_t *mp_ping;
11600 if (!vam->json_output)
11602 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
11605 M (L2_XCONNECT_DUMP, mp);
11609 /* Use a control ping for synchronization */
11610 MPING (CONTROL_PING, mp_ping);
11618 api_hw_interface_set_mtu (vat_main_t * vam)
11620 unformat_input_t *i = vam->input;
11621 vl_api_hw_interface_set_mtu_t *mp;
11622 u32 sw_if_index = ~0;
11626 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11628 if (unformat (i, "mtu %d", &mtu))
11630 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11632 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11638 if (sw_if_index == ~0)
11640 errmsg ("missing interface name or sw_if_index");
11646 errmsg ("no mtu specified");
11650 /* Construct the API message */
11651 M (HW_INTERFACE_SET_MTU, mp);
11652 mp->sw_if_index = ntohl (sw_if_index);
11653 mp->mtu = ntohs ((u16) mtu);
11661 api_p2p_ethernet_add (vat_main_t * vam)
11663 unformat_input_t *i = vam->input;
11664 vl_api_p2p_ethernet_add_t *mp;
11665 u32 parent_if_index = ~0;
11671 clib_memset (remote_mac, 0, sizeof (remote_mac));
11672 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11674 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11676 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11680 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11682 else if (unformat (i, "sub_id %d", &sub_id))
11686 clib_warning ("parse error '%U'", format_unformat_error, i);
11691 if (parent_if_index == ~0)
11693 errmsg ("missing interface name or sw_if_index");
11698 errmsg ("missing remote mac address");
11703 errmsg ("missing sub-interface id");
11707 M (P2P_ETHERNET_ADD, mp);
11708 mp->parent_if_index = ntohl (parent_if_index);
11709 mp->subif_id = ntohl (sub_id);
11710 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11718 api_p2p_ethernet_del (vat_main_t * vam)
11720 unformat_input_t *i = vam->input;
11721 vl_api_p2p_ethernet_del_t *mp;
11722 u32 parent_if_index = ~0;
11727 clib_memset (remote_mac, 0, sizeof (remote_mac));
11728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11730 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11732 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11736 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11740 clib_warning ("parse error '%U'", format_unformat_error, i);
11745 if (parent_if_index == ~0)
11747 errmsg ("missing interface name or sw_if_index");
11752 errmsg ("missing remote mac address");
11756 M (P2P_ETHERNET_DEL, mp);
11757 mp->parent_if_index = ntohl (parent_if_index);
11758 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11766 api_tcp_configure_src_addresses (vat_main_t * vam)
11768 vl_api_tcp_configure_src_addresses_t *mp;
11769 unformat_input_t *i = vam->input;
11770 vl_api_address_t first, last;
11775 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11777 if (unformat (i, "%U - %U",
11778 unformat_vl_api_address, &first,
11779 unformat_vl_api_address, &last))
11783 errmsg ("one range per message (range already set)");
11788 else if (unformat (i, "vrf %d", &vrf_id))
11794 if (range_set == 0)
11796 errmsg ("address range not set");
11800 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
11802 mp->vrf_id = ntohl (vrf_id);
11803 clib_memcpy (&mp->first_address, &first, sizeof (first));
11804 clib_memcpy (&mp->last_address, &last, sizeof (last));
11811 static void vl_api_app_namespace_add_del_reply_t_handler
11812 (vl_api_app_namespace_add_del_reply_t * mp)
11814 vat_main_t *vam = &vat_main;
11815 i32 retval = ntohl (mp->retval);
11816 if (vam->async_mode)
11818 vam->async_errors += (retval < 0);
11822 vam->retval = retval;
11824 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
11825 vam->result_ready = 1;
11829 static void vl_api_app_namespace_add_del_reply_t_handler_json
11830 (vl_api_app_namespace_add_del_reply_t * mp)
11832 vat_main_t *vam = &vat_main;
11833 vat_json_node_t node;
11835 vat_json_init_object (&node);
11836 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11837 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
11839 vat_json_print (vam->ofp, &node);
11840 vat_json_free (&node);
11842 vam->retval = ntohl (mp->retval);
11843 vam->result_ready = 1;
11847 api_app_namespace_add_del (vat_main_t * vam)
11849 vl_api_app_namespace_add_del_t *mp;
11850 unformat_input_t *i = vam->input;
11851 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
11852 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
11856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11858 if (unformat (i, "id %_%v%_", &ns_id))
11860 else if (unformat (i, "secret %lu", &secret))
11862 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11863 sw_if_index_set = 1;
11864 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
11866 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
11871 if (!ns_id || !secret_set || !sw_if_index_set)
11873 errmsg ("namespace id, secret and sw_if_index must be set");
11876 if (vec_len (ns_id) > 64)
11878 errmsg ("namespace id too long");
11881 M (APP_NAMESPACE_ADD_DEL, mp);
11883 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
11884 mp->secret = clib_host_to_net_u64 (secret);
11885 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
11886 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
11887 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
11895 api_sock_init_shm (vat_main_t * vam)
11897 #if VPP_API_TEST_BUILTIN == 0
11898 unformat_input_t *i = vam->input;
11899 vl_api_shm_elem_config_t *config = 0;
11900 u64 size = 64 << 20;
11903 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11905 if (unformat (i, "size %U", unformat_memory_size, &size))
11912 * Canned custom ring allocator config.
11913 * Should probably parse all of this
11915 vec_validate (config, 6);
11916 config[0].type = VL_API_VLIB_RING;
11917 config[0].size = 256;
11918 config[0].count = 32;
11920 config[1].type = VL_API_VLIB_RING;
11921 config[1].size = 1024;
11922 config[1].count = 16;
11924 config[2].type = VL_API_VLIB_RING;
11925 config[2].size = 4096;
11926 config[2].count = 2;
11928 config[3].type = VL_API_CLIENT_RING;
11929 config[3].size = 256;
11930 config[3].count = 32;
11932 config[4].type = VL_API_CLIENT_RING;
11933 config[4].size = 1024;
11934 config[4].count = 16;
11936 config[5].type = VL_API_CLIENT_RING;
11937 config[5].size = 4096;
11938 config[5].count = 2;
11940 config[6].type = VL_API_QUEUE;
11941 config[6].count = 128;
11942 config[6].size = sizeof (uword);
11944 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
11946 vam->client_index_invalid = 1;
11954 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
11956 vat_main_t *vam = &vat_main;
11957 fib_prefix_t lcl, rmt;
11959 ip_prefix_decode (&mp->lcl, &lcl);
11960 ip_prefix_decode (&mp->rmt, &rmt);
11962 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
11965 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11966 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11967 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
11968 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
11969 &rmt.fp_addr.ip4, rmt.fp_len,
11970 clib_net_to_host_u16 (mp->rmt_port),
11971 clib_net_to_host_u32 (mp->action_index), mp->tag);
11976 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11977 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11978 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
11979 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
11980 &rmt.fp_addr.ip6, rmt.fp_len,
11981 clib_net_to_host_u16 (mp->rmt_port),
11982 clib_net_to_host_u32 (mp->action_index), mp->tag);
11987 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
11990 vat_main_t *vam = &vat_main;
11991 vat_json_node_t *node = NULL;
11992 struct in6_addr ip6;
11993 struct in_addr ip4;
11995 fib_prefix_t lcl, rmt;
11997 ip_prefix_decode (&mp->lcl, &lcl);
11998 ip_prefix_decode (&mp->rmt, &rmt);
12000 if (VAT_JSON_ARRAY != vam->json_tree.type)
12002 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
12003 vat_json_init_array (&vam->json_tree);
12005 node = vat_json_array_add (&vam->json_tree);
12006 vat_json_init_object (node);
12008 vat_json_object_add_uint (node, "appns_index",
12009 clib_net_to_host_u32 (mp->appns_index));
12010 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
12011 vat_json_object_add_uint (node, "scope", mp->scope);
12012 vat_json_object_add_uint (node, "action_index",
12013 clib_net_to_host_u32 (mp->action_index));
12014 vat_json_object_add_uint (node, "lcl_port",
12015 clib_net_to_host_u16 (mp->lcl_port));
12016 vat_json_object_add_uint (node, "rmt_port",
12017 clib_net_to_host_u16 (mp->rmt_port));
12018 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
12019 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
12020 vat_json_object_add_string_copy (node, "tag", mp->tag);
12021 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
12023 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
12024 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
12025 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
12026 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
12030 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
12031 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
12032 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
12033 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
12038 api_session_rule_add_del (vat_main_t * vam)
12040 vl_api_session_rule_add_del_t *mp;
12041 unformat_input_t *i = vam->input;
12042 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
12043 u32 appns_index = 0, scope = 0;
12044 ip4_address_t lcl_ip4, rmt_ip4;
12045 ip6_address_t lcl_ip6, rmt_ip6;
12046 u8 is_ip4 = 1, conn_set = 0;
12047 u8 is_add = 1, *tag = 0;
12049 fib_prefix_t lcl, rmt;
12051 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12053 if (unformat (i, "del"))
12055 else if (unformat (i, "add"))
12057 else if (unformat (i, "proto tcp"))
12059 else if (unformat (i, "proto udp"))
12061 else if (unformat (i, "appns %d", &appns_index))
12063 else if (unformat (i, "scope %d", &scope))
12065 else if (unformat (i, "tag %_%v%_", &tag))
12069 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
12070 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
12078 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
12079 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
12085 else if (unformat (i, "action %d", &action))
12090 if (proto == ~0 || !conn_set || action == ~0)
12092 errmsg ("transport proto, connection and action must be set");
12098 errmsg ("scope should be 0-3");
12102 M (SESSION_RULE_ADD_DEL, mp);
12104 clib_memset (&lcl, 0, sizeof (lcl));
12105 clib_memset (&rmt, 0, sizeof (rmt));
12108 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
12109 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
12110 lcl.fp_len = lcl_plen;
12111 rmt.fp_len = rmt_plen;
12115 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
12116 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
12117 lcl.fp_len = lcl_plen;
12118 rmt.fp_len = rmt_plen;
12122 ip_prefix_encode (&lcl, &mp->lcl);
12123 ip_prefix_encode (&rmt, &mp->rmt);
12124 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
12125 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
12126 mp->transport_proto =
12127 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
12128 mp->action_index = clib_host_to_net_u32 (action);
12129 mp->appns_index = clib_host_to_net_u32 (appns_index);
12131 mp->is_add = is_add;
12134 clib_memcpy (mp->tag, tag, vec_len (tag));
12144 api_session_rules_dump (vat_main_t * vam)
12146 vl_api_session_rules_dump_t *mp;
12147 vl_api_control_ping_t *mp_ping;
12150 if (!vam->json_output)
12152 print (vam->ofp, "%=20s", "Session Rules");
12155 M (SESSION_RULES_DUMP, mp);
12159 /* Use a control ping for synchronization */
12160 MPING (CONTROL_PING, mp_ping);
12163 /* Wait for a reply... */
12169 api_ip_container_proxy_add_del (vat_main_t * vam)
12171 vl_api_ip_container_proxy_add_del_t *mp;
12172 unformat_input_t *i = vam->input;
12173 u32 sw_if_index = ~0;
12174 vl_api_prefix_t pfx = { };
12178 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12180 if (unformat (i, "del"))
12182 else if (unformat (i, "add"))
12184 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
12186 else if (unformat (i, "sw_if_index %u", &sw_if_index))
12191 if (sw_if_index == ~0 || pfx.len == 0)
12193 errmsg ("address and sw_if_index must be set");
12197 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
12199 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
12200 mp->is_add = is_add;
12201 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
12209 api_qos_record_enable_disable (vat_main_t * vam)
12211 unformat_input_t *i = vam->input;
12212 vl_api_qos_record_enable_disable_t *mp;
12213 u32 sw_if_index, qs = 0xff;
12214 u8 sw_if_index_set = 0;
12218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
12220 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
12221 sw_if_index_set = 1;
12222 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12223 sw_if_index_set = 1;
12224 else if (unformat (i, "%U", unformat_qos_source, &qs))
12226 else if (unformat (i, "disable"))
12230 clib_warning ("parse error '%U'", format_unformat_error, i);
12235 if (sw_if_index_set == 0)
12237 errmsg ("missing interface name or sw_if_index");
12242 errmsg ("input location must be specified");
12246 M (QOS_RECORD_ENABLE_DISABLE, mp);
12248 mp->record.sw_if_index = ntohl (sw_if_index);
12249 mp->record.input_source = qs;
12250 mp->enable = enable;
12259 q_or_quit (vat_main_t * vam)
12261 #if VPP_API_TEST_BUILTIN == 0
12262 longjmp (vam->jump_buf, 1);
12264 return 0; /* not so much */
12268 q (vat_main_t * vam)
12270 return q_or_quit (vam);
12274 quit (vat_main_t * vam)
12276 return q_or_quit (vam);
12280 comment (vat_main_t * vam)
12286 elog_save (vat_main_t * vam)
12288 #if VPP_API_TEST_BUILTIN == 0
12289 elog_main_t *em = &vam->elog_main;
12290 unformat_input_t *i = vam->input;
12291 char *file, *chroot_file;
12292 clib_error_t *error;
12294 if (!unformat (i, "%s", &file))
12296 errmsg ("expected file name, got `%U'", format_unformat_error, i);
12300 /* It's fairly hard to get "../oopsie" through unformat; just in case */
12301 if (strstr (file, "..") || index (file, '/'))
12303 errmsg ("illegal characters in filename '%s'", file);
12307 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
12311 errmsg ("Saving %wd of %wd events to %s",
12312 elog_n_events_in_buffer (em),
12313 elog_buffer_capacity (em), chroot_file);
12315 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
12316 vec_free (chroot_file);
12319 clib_error_report (error);
12321 errmsg ("Use the vpp event loger...");
12328 elog_setup (vat_main_t * vam)
12330 #if VPP_API_TEST_BUILTIN == 0
12331 elog_main_t *em = &vam->elog_main;
12332 unformat_input_t *i = vam->input;
12333 u32 nevents = 128 << 10;
12335 (void) unformat (i, "nevents %d", &nevents);
12337 elog_init (em, nevents);
12338 vl_api_set_elog_main (em);
12339 vl_api_set_elog_trace_api_messages (1);
12340 errmsg ("Event logger initialized with %u events", nevents);
12342 errmsg ("Use the vpp event loger...");
12348 elog_enable (vat_main_t * vam)
12350 #if VPP_API_TEST_BUILTIN == 0
12351 elog_main_t *em = &vam->elog_main;
12353 elog_enable_disable (em, 1 /* enable */ );
12354 vl_api_set_elog_trace_api_messages (1);
12355 errmsg ("Event logger enabled...");
12357 errmsg ("Use the vpp event loger...");
12363 elog_disable (vat_main_t * vam)
12365 #if VPP_API_TEST_BUILTIN == 0
12366 elog_main_t *em = &vam->elog_main;
12368 elog_enable_disable (em, 0 /* enable */ );
12369 vl_api_set_elog_trace_api_messages (1);
12370 errmsg ("Event logger disabled...");
12372 errmsg ("Use the vpp event loger...");
12378 statseg (vat_main_t * vam)
12380 ssvm_private_t *ssvmp = &vam->stat_segment;
12381 ssvm_shared_header_t *shared_header = ssvmp->sh;
12382 vlib_counter_t **counters;
12383 u64 thread0_index1_packets;
12384 u64 thread0_index1_bytes;
12385 f64 vector_rate, input_rate;
12388 uword *counter_vector_by_name;
12389 if (vam->stat_segment_lockp == 0)
12391 errmsg ("Stat segment not mapped...");
12395 /* look up "/if/rx for sw_if_index 1 as a test */
12397 clib_spinlock_lock (vam->stat_segment_lockp);
12399 counter_vector_by_name = (uword *) shared_header->opaque[1];
12401 p = hash_get_mem (counter_vector_by_name, "/if/rx");
12404 clib_spinlock_unlock (vam->stat_segment_lockp);
12405 errmsg ("/if/tx not found?");
12409 /* Fish per-thread vector of combined counters from shared memory */
12410 counters = (vlib_counter_t **) p[0];
12412 if (vec_len (counters[0]) < 2)
12414 clib_spinlock_unlock (vam->stat_segment_lockp);
12415 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
12419 /* Read thread 0 sw_if_index 1 counter */
12420 thread0_index1_packets = counters[0][1].packets;
12421 thread0_index1_bytes = counters[0][1].bytes;
12423 p = hash_get_mem (counter_vector_by_name, "vector_rate");
12426 clib_spinlock_unlock (vam->stat_segment_lockp);
12427 errmsg ("vector_rate not found?");
12431 vector_rate = *(f64 *) (p[0]);
12432 p = hash_get_mem (counter_vector_by_name, "input_rate");
12435 clib_spinlock_unlock (vam->stat_segment_lockp);
12436 errmsg ("input_rate not found?");
12439 input_rate = *(f64 *) (p[0]);
12441 clib_spinlock_unlock (vam->stat_segment_lockp);
12443 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
12444 vector_rate, input_rate);
12445 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
12446 thread0_index1_packets, thread0_index1_bytes);
12452 cmd_cmp (void *a1, void *a2)
12457 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
12461 help (vat_main_t * vam)
12466 unformat_input_t *i = vam->input;
12469 if (unformat (i, "%s", &name))
12473 vec_add1 (name, 0);
12475 hs = hash_get_mem (vam->help_by_name, name);
12477 print (vam->ofp, "usage: %s %s", name, hs[0]);
12479 print (vam->ofp, "No such msg / command '%s'", name);
12484 print (vam->ofp, "Help is available for the following:");
12487 hash_foreach_pair (p, vam->function_by_name,
12489 vec_add1 (cmds, (u8 *)(p->key));
12493 vec_sort_with_function (cmds, cmd_cmp);
12495 for (j = 0; j < vec_len (cmds); j++)
12496 print (vam->ofp, "%s", cmds[j]);
12503 set (vat_main_t * vam)
12505 u8 *name = 0, *value = 0;
12506 unformat_input_t *i = vam->input;
12508 if (unformat (i, "%s", &name))
12510 /* The input buffer is a vector, not a string. */
12511 value = vec_dup (i->buffer);
12512 vec_delete (value, i->index, 0);
12513 /* Almost certainly has a trailing newline */
12514 if (value[vec_len (value) - 1] == '\n')
12515 value[vec_len (value) - 1] = 0;
12516 /* Make sure it's a proper string, one way or the other */
12517 vec_add1 (value, 0);
12518 (void) clib_macro_set_value (&vam->macro_main,
12519 (char *) name, (char *) value);
12522 errmsg ("usage: set <name> <value>");
12530 unset (vat_main_t * vam)
12534 if (unformat (vam->input, "%s", &name))
12535 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
12536 errmsg ("unset: %s wasn't set", name);
12549 macro_sort_cmp (void *a1, void *a2)
12551 macro_sort_t *s1 = a1;
12552 macro_sort_t *s2 = a2;
12554 return strcmp ((char *) (s1->name), (char *) (s2->name));
12558 dump_macro_table (vat_main_t * vam)
12560 macro_sort_t *sort_me = 0, *sm;
12565 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
12567 vec_add2 (sort_me, sm, 1);
12568 sm->name = (u8 *)(p->key);
12569 sm->value = (u8 *) (p->value[0]);
12573 vec_sort_with_function (sort_me, macro_sort_cmp);
12575 if (vec_len (sort_me))
12576 print (vam->ofp, "%-15s%s", "Name", "Value");
12578 print (vam->ofp, "The macro table is empty...");
12580 for (i = 0; i < vec_len (sort_me); i++)
12581 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
12586 dump_node_table (vat_main_t * vam)
12589 vlib_node_t *node, *next_node;
12591 if (vec_len (vam->graph_nodes) == 0)
12593 print (vam->ofp, "Node table empty, issue get_node_graph...");
12597 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
12599 node = vam->graph_nodes[0][i];
12600 print (vam->ofp, "[%d] %s", i, node->name);
12601 for (j = 0; j < vec_len (node->next_nodes); j++)
12603 if (node->next_nodes[j] != ~0)
12605 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12606 print (vam->ofp, " [%d] %s", j, next_node->name);
12614 value_sort_cmp (void *a1, void *a2)
12616 name_sort_t *n1 = a1;
12617 name_sort_t *n2 = a2;
12619 if (n1->value < n2->value)
12621 if (n1->value > n2->value)
12628 dump_msg_api_table (vat_main_t * vam)
12630 api_main_t *am = vlibapi_get_main ();
12631 name_sort_t *nses = 0, *ns;
12636 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
12638 vec_add2 (nses, ns, 1);
12639 ns->name = (u8 *)(hp->key);
12640 ns->value = (u32) hp->value[0];
12644 vec_sort_with_function (nses, value_sort_cmp);
12646 for (i = 0; i < vec_len (nses); i++)
12647 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
12653 get_msg_id (vat_main_t * vam)
12658 if (unformat (vam->input, "%s", &name_and_crc))
12660 message_index = vl_msg_api_get_msg_index (name_and_crc);
12661 if (message_index == ~0)
12663 print (vam->ofp, " '%s' not found", name_and_crc);
12666 print (vam->ofp, " '%s' has message index %d",
12667 name_and_crc, message_index);
12670 errmsg ("name_and_crc required...");
12675 search_node_table (vat_main_t * vam)
12677 unformat_input_t *line_input = vam->input;
12680 vlib_node_t *node, *next_node;
12683 if (vam->graph_node_index_by_name == 0)
12685 print (vam->ofp, "Node table empty, issue get_node_graph...");
12689 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12691 if (unformat (line_input, "%s", &node_to_find))
12693 vec_add1 (node_to_find, 0);
12694 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
12697 print (vam->ofp, "%s not found...", node_to_find);
12700 node = vam->graph_nodes[0][p[0]];
12701 print (vam->ofp, "[%d] %s", p[0], node->name);
12702 for (j = 0; j < vec_len (node->next_nodes); j++)
12704 if (node->next_nodes[j] != ~0)
12706 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12707 print (vam->ofp, " [%d] %s", j, next_node->name);
12714 clib_warning ("parse error '%U'", format_unformat_error,
12720 vec_free (node_to_find);
12729 script (vat_main_t * vam)
12731 #if (VPP_API_TEST_BUILTIN==0)
12733 char *save_current_file;
12734 unformat_input_t save_input;
12735 jmp_buf save_jump_buf;
12736 u32 save_line_number;
12738 FILE *new_fp, *save_ifp;
12740 if (unformat (vam->input, "%s", &s))
12742 new_fp = fopen ((char *) s, "r");
12745 errmsg ("Couldn't open script file %s", s);
12752 errmsg ("Missing script name");
12756 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
12757 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
12758 save_ifp = vam->ifp;
12759 save_line_number = vam->input_line_number;
12760 save_current_file = (char *) vam->current_file;
12762 vam->input_line_number = 0;
12764 vam->current_file = s;
12767 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
12768 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
12769 vam->ifp = save_ifp;
12770 vam->input_line_number = save_line_number;
12771 vam->current_file = (u8 *) save_current_file;
12776 clib_warning ("use the exec command...");
12782 echo (vat_main_t * vam)
12784 print (vam->ofp, "%v", vam->input->buffer);
12788 /* List of API message constructors, CLI names map to api_xxx */
12789 #define foreach_vpe_api_msg \
12790 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
12791 _(sw_interface_dump,"") \
12792 _(sw_interface_set_flags, \
12793 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
12794 _(sw_interface_add_del_address, \
12795 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
12796 _(sw_interface_set_rx_mode, \
12797 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
12798 _(sw_interface_set_rx_placement, \
12799 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
12800 _(sw_interface_rx_placement_dump, \
12801 "[<intfc> | sw_if_index <id>]") \
12802 _(sw_interface_set_table, \
12803 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
12804 _(sw_interface_set_mpls_enable, \
12805 "<intfc> | sw_if_index [disable | dis]") \
12806 _(sw_interface_set_vpath, \
12807 "<intfc> | sw_if_index <id> enable | disable") \
12808 _(sw_interface_set_l2_xconnect, \
12809 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12810 "enable | disable") \
12811 _(sw_interface_set_l2_bridge, \
12812 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
12813 "[shg <split-horizon-group>] [bvi]\n" \
12814 "enable | disable") \
12815 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
12816 _(bridge_domain_add_del, \
12817 "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") \
12818 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
12820 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
12821 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
12822 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
12824 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12826 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12828 "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]") \
12830 "<vpp-if-name> | sw_if_index <id>") \
12831 _(sw_interface_tap_v2_dump, "") \
12832 _(virtio_pci_create_v2, \
12833 "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]") \
12834 _(virtio_pci_delete, \
12835 "<vpp-if-name> | sw_if_index <id>") \
12836 _(sw_interface_virtio_pci_dump, "") \
12838 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
12839 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12842 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
12843 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12844 "[id <if-id>] [gso]") \
12846 "<vpp-if-name> | sw_if_index <id>") \
12847 _(bond_add_member, \
12848 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
12849 _(bond_detach_member, \
12850 "sw_if_index <n>") \
12851 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
12852 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
12853 _(sw_member_interface_dump, \
12854 "<vpp-if-name> | sw_if_index <id>") \
12855 _(ip_table_add_del, \
12856 "table <n> [ipv6] [add | del]\n") \
12857 _(ip_route_add_del, \
12858 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
12859 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
12860 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
12861 "[multipath] [count <n>] [del]") \
12862 _(ip_mroute_add_del, \
12863 "<src> <grp>/<mask> [table-id <n>]\n" \
12864 "[<intfc> | sw_if_index <id>] [local] [del]") \
12865 _(mpls_table_add_del, \
12866 "table <n> [add | del]\n") \
12867 _(mpls_route_add_del, \
12868 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
12869 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
12870 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
12871 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
12872 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
12873 "[count <n>] [del]") \
12874 _(mpls_ip_bind_unbind, \
12875 "<label> <addr/len>") \
12876 _(mpls_tunnel_add_del, \
12877 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
12878 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
12879 "[l2-only] [out-label <n>]") \
12880 _(sr_mpls_policy_add, \
12881 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
12882 _(sr_mpls_policy_del, \
12884 _(sw_interface_set_unnumbered, \
12885 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
12886 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
12887 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
12888 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
12889 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
12890 "[outer_vlan_id_any][inner_vlan_id_any]") \
12891 _(ip_table_replace_begin, "table <n> [ipv6]") \
12892 _(ip_table_flush, "table <n> [ipv6]") \
12893 _(ip_table_replace_end, "table <n> [ipv6]") \
12894 _(set_ip_flow_hash, \
12895 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
12896 _(sw_interface_ip6_enable_disable, \
12897 "<intfc> | sw_if_index <id> enable | disable") \
12898 _(l2_patch_add_del, \
12899 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12900 "enable | disable") \
12901 _(sr_localsid_add_del, \
12902 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
12903 "fib-table <num> (end.psp) sw_if_index <num>") \
12904 _(get_node_index, "node <node-name") \
12905 _(add_node_next, "node <node-name> next <next-node-name>") \
12906 _(l2_fib_clear_table, "") \
12907 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
12908 _(l2_interface_vlan_tag_rewrite, \
12909 "<intfc> | sw_if_index <nn> \n" \
12910 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
12911 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
12912 _(create_vhost_user_if, \
12913 "socket <filename> [server] [renumber <dev_instance>] " \
12914 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12915 "[mac <mac_address>] [packed]") \
12916 _(modify_vhost_user_if, \
12917 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12918 "[server] [renumber <dev_instance>] [gso] [packed]") \
12919 _(create_vhost_user_if_v2, \
12920 "socket <filename> [server] [renumber <dev_instance>] " \
12921 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12922 "[mac <mac_address>] [packed] [event-idx]") \
12923 _(modify_vhost_user_if_v2, \
12924 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12925 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
12926 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
12927 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
12928 _(show_version, "") \
12929 _(show_threads, "") \
12930 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
12931 _(interface_name_renumber, \
12932 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
12933 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
12934 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
12935 _(ip_dump, "ipv4 | ipv6") \
12936 _(ipsec_spd_add_del, "spd_id <n> [del]") \
12937 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
12939 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
12940 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
12941 " integ_alg <alg> integ_key <hex>") \
12942 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
12943 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
12944 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
12945 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
12946 _(ipsec_sa_dump, "[sa_id <n>]") \
12947 _(delete_loopback,"sw_if_index <nn>") \
12948 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
12949 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
12950 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
12951 _(want_interface_events, "enable|disable") \
12952 _(get_first_msg_id, "client <name>") \
12953 _(get_node_graph, " ") \
12954 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
12955 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
12956 _(ioam_disable, "") \
12957 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
12958 _(af_packet_delete, "name <host interface name>") \
12959 _(af_packet_dump, "") \
12960 _(policer_add_del, "name <policer name> <params> [del]") \
12961 _(policer_dump, "[name <policer name>]") \
12962 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
12963 _(mpls_table_dump, "") \
12964 _(mpls_route_dump, "table-id <ID>") \
12965 _(set_ipfix_exporter, "collector_address <ip4> [collector_port <nn>] " \
12966 "src_address <ip4> [vrf_id <nn>] [path_mtu <nn>] " \
12967 "[template_interval <nn>] [udp_checksum]") \
12968 _(ipfix_exporter_dump, "") \
12969 _(set_ipfix_classify_stream, "[domain <domain-id>] [src_port <src-port>]") \
12970 _(ipfix_classify_stream_dump, "") \
12971 _(ipfix_classify_table_add_del, "table <table-index> ip4|ip6 [tcp|udp]") \
12972 _(ipfix_classify_table_dump, "") \
12973 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
12974 _(sw_interface_span_dump, "[l2]") \
12975 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
12976 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
12977 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
12978 _(pg_enable_disable, "[stream <id>] disable") \
12979 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
12980 _(ip_source_and_port_range_check_add_del, \
12981 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
12982 _(ip_source_and_port_range_check_interface_add_del, \
12983 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
12984 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
12985 _(delete_subif,"<intfc> | sw_if_index <nn>") \
12986 _(l2_interface_pbb_tag_rewrite, \
12987 "<intfc> | sw_if_index <nn> \n" \
12988 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
12989 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
12990 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
12991 _(ip_table_dump, "") \
12992 _(ip_route_dump, "table-id [ip4|ip6]") \
12993 _(ip_mtable_dump, "") \
12994 _(ip_mroute_dump, "table-id [ip4|ip6]") \
12995 _(feature_enable_disable, "arc_name <arc_name> " \
12996 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
12997 _(feature_gso_enable_disable, "<intfc> | sw_if_index <nn> " \
12998 "[enable | disable] ") \
12999 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
13001 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
13002 "mac <mac-address> [del]") \
13003 _(l2_xconnect_dump, "") \
13004 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
13005 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
13006 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
13007 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
13008 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
13009 _(sock_init_shm, "size <nnn>") \
13010 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
13011 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
13012 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
13013 _(session_rules_dump, "") \
13014 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
13015 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
13017 /* List of command functions, CLI names map directly to functions */
13018 #define foreach_cli_function \
13019 _(comment, "usage: comment <ignore-rest-of-line>") \
13020 _(dump_interface_table, "usage: dump_interface_table") \
13021 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
13022 _(dump_ipv4_table, "usage: dump_ipv4_table") \
13023 _(dump_ipv6_table, "usage: dump_ipv6_table") \
13024 _(dump_macro_table, "usage: dump_macro_table ") \
13025 _(dump_node_table, "usage: dump_node_table") \
13026 _(dump_msg_api_table, "usage: dump_msg_api_table") \
13027 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
13028 _(elog_disable, "usage: elog_disable") \
13029 _(elog_enable, "usage: elog_enable") \
13030 _(elog_save, "usage: elog_save <filename>") \
13031 _(get_msg_id, "usage: get_msg_id name_and_crc") \
13032 _(echo, "usage: echo <message>") \
13033 _(exec, "usage: exec <vpe-debug-CLI-command>") \
13034 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
13035 _(help, "usage: help") \
13036 _(q, "usage: quit") \
13037 _(quit, "usage: quit") \
13038 _(search_node_table, "usage: search_node_table <name>...") \
13039 _(set, "usage: set <variable-name> <value>") \
13040 _(script, "usage: script <file-name>") \
13041 _(statseg, "usage: statseg") \
13042 _(unset, "usage: unset <variable-name>")
13045 static void vl_api_##n##_t_handler_uni \
13046 (vl_api_##n##_t * mp) \
13048 vat_main_t * vam = &vat_main; \
13049 if (vam->json_output) { \
13050 vl_api_##n##_t_handler_json(mp); \
13052 vl_api_##n##_t_handler(mp); \
13055 foreach_vpe_api_reply_msg;
13056 #if VPP_API_TEST_BUILTIN == 0
13057 foreach_standalone_reply_msg;
13062 vat_api_hookup (vat_main_t * vam)
13065 vl_msg_api_set_handlers(VL_API_##N, #n, \
13066 vl_api_##n##_t_handler_uni, \
13068 vl_api_##n##_t_endian, \
13069 vl_api_##n##_t_print, \
13070 sizeof(vl_api_##n##_t), 1);
13071 foreach_vpe_api_reply_msg;
13072 #if VPP_API_TEST_BUILTIN == 0
13073 foreach_standalone_reply_msg;
13077 #if (VPP_API_TEST_BUILTIN==0)
13078 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
13080 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
13082 vam->function_by_name = hash_create_string (0, sizeof (uword));
13084 vam->help_by_name = hash_create_string (0, sizeof (uword));
13087 /* API messages we can send */
13088 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
13089 foreach_vpe_api_msg;
13093 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13094 foreach_vpe_api_msg;
13097 /* CLI functions */
13098 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
13099 foreach_cli_function;
13103 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13104 foreach_cli_function;
13108 #if VPP_API_TEST_BUILTIN
13109 static clib_error_t *
13110 vat_api_hookup_shim (vlib_main_t * vm)
13112 vat_api_hookup (&vat_main);
13116 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
13120 * fd.io coding-style-patch-verification: ON
13123 * eval: (c-set-style "gnu")