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 _(sw_interface_span_enable_disable_reply) \
2855 _(pg_capture_reply) \
2856 _(pg_enable_disable_reply) \
2857 _(pg_interface_enable_disable_coalesce_reply) \
2858 _(ip_source_and_port_range_check_add_del_reply) \
2859 _(ip_source_and_port_range_check_interface_add_del_reply)\
2860 _(delete_subif_reply) \
2861 _(l2_interface_pbb_tag_rewrite_reply) \
2863 _(feature_enable_disable_reply) \
2864 _(sw_interface_tag_add_del_reply) \
2865 _(sw_interface_add_del_mac_address_reply) \
2866 _(hw_interface_set_mtu_reply) \
2867 _(p2p_ethernet_add_reply) \
2868 _(p2p_ethernet_del_reply) \
2869 _(tcp_configure_src_addresses_reply) \
2870 _(session_rule_add_del_reply) \
2871 _(ip_container_proxy_add_del_reply) \
2872 _(qos_record_enable_disable_reply) \
2875 static void vl_api_##n##_t_handler \
2876 (vl_api_##n##_t * mp) \
2878 vat_main_t * vam = &vat_main; \
2879 i32 retval = ntohl(mp->retval); \
2880 if (vam->async_mode) { \
2881 vam->async_errors += (retval < 0); \
2883 vam->retval = retval; \
2884 vam->result_ready = 1; \
2887 foreach_standard_reply_retval_handler;
2891 static void vl_api_##n##_t_handler_json \
2892 (vl_api_##n##_t * mp) \
2894 vat_main_t * vam = &vat_main; \
2895 vat_json_node_t node; \
2896 vat_json_init_object(&node); \
2897 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2898 vat_json_print(vam->ofp, &node); \
2899 vam->retval = ntohl(mp->retval); \
2900 vam->result_ready = 1; \
2902 foreach_standard_reply_retval_handler;
2906 * Table of message reply handlers, must include boilerplate handlers
2910 #define foreach_vpe_api_reply_msg \
2911 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2912 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2913 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2914 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2915 _(CONTROL_PING_REPLY, control_ping_reply) \
2916 _(CLI_REPLY, cli_reply) \
2917 _(CLI_INBAND_REPLY, cli_inband_reply) \
2918 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2919 sw_interface_add_del_address_reply) \
2920 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2921 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2922 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2923 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2924 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2925 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2926 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2927 sw_interface_set_l2_xconnect_reply) \
2928 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2929 sw_interface_set_l2_bridge_reply) \
2930 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2931 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2932 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2933 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2934 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2935 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2936 _(L2_FLAGS_REPLY, l2_flags_reply) \
2937 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2938 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
2939 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
2940 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
2941 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2942 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2943 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2944 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2945 _(BOND_CREATE_REPLY, bond_create_reply) \
2946 _(BOND_CREATE2_REPLY, bond_create2_reply) \
2947 _(BOND_DELETE_REPLY, bond_delete_reply) \
2948 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
2949 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
2950 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
2951 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
2952 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
2953 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2954 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2955 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2956 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2957 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2958 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2959 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2960 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2961 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2962 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2963 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2964 sw_interface_set_unnumbered_reply) \
2965 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2966 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2967 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2968 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2969 sw_interface_ip6_enable_disable_reply) \
2970 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2971 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
2972 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
2973 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
2974 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
2975 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
2976 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
2977 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
2978 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
2979 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2980 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2981 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2982 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2983 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2984 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2985 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2986 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2987 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2988 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2989 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2990 _(SHOW_VERSION_REPLY, show_version_reply) \
2991 _(SHOW_THREADS_REPLY, show_threads_reply) \
2992 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2993 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2994 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2995 _(L2_MACS_EVENT, l2_macs_event) \
2996 _(IP_ADDRESS_DETAILS, ip_address_details) \
2997 _(IP_DETAILS, ip_details) \
2998 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2999 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3000 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
3001 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
3002 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
3003 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3004 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3005 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
3006 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
3007 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3008 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3009 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3010 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3011 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
3012 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
3013 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3014 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3015 _(AF_PACKET_DETAILS, af_packet_details) \
3016 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3017 _(POLICER_DETAILS, policer_details) \
3018 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
3019 _(MPLS_TABLE_DETAILS, mpls_table_details) \
3020 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
3021 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
3022 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
3023 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3024 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3025 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3026 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3027 _(PG_INTERFACE_ENABLE_DISABLE_COALESCE_REPLY, pg_interface_enable_disable_coalesce_reply) \
3028 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3029 ip_source_and_port_range_check_add_del_reply) \
3030 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3031 ip_source_and_port_range_check_interface_add_del_reply) \
3032 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
3033 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
3034 _(SET_PUNT_REPLY, set_punt_reply) \
3035 _(IP_TABLE_DETAILS, ip_table_details) \
3036 _(IP_ROUTE_DETAILS, ip_route_details) \
3037 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3038 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3039 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3040 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3041 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3042 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3043 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3044 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3045 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3046 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3047 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3048 _(SESSION_RULES_DETAILS, session_rules_details) \
3049 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3050 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3052 #define foreach_standalone_reply_msg \
3053 _(SW_INTERFACE_EVENT, sw_interface_event)
3061 #define STR_VTR_OP_CASE(op) \
3062 case L2_VTR_ ## op: \
3066 str_vtr_op (u32 vtr_op)
3070 STR_VTR_OP_CASE (DISABLED);
3071 STR_VTR_OP_CASE (PUSH_1);
3072 STR_VTR_OP_CASE (PUSH_2);
3073 STR_VTR_OP_CASE (POP_1);
3074 STR_VTR_OP_CASE (POP_2);
3075 STR_VTR_OP_CASE (TRANSLATE_1_1);
3076 STR_VTR_OP_CASE (TRANSLATE_1_2);
3077 STR_VTR_OP_CASE (TRANSLATE_2_1);
3078 STR_VTR_OP_CASE (TRANSLATE_2_2);
3085 dump_sub_interface_table (vat_main_t * vam)
3087 const sw_interface_subif_t *sub = NULL;
3089 if (vam->json_output)
3092 ("JSON output supported only for VPE API calls and dump_stats_table");
3097 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3098 "Interface", "sw_if_index",
3099 "sub id", "dot1ad", "tags", "outer id",
3100 "inner id", "exact", "default", "outer any", "inner any");
3102 vec_foreach (sub, vam->sw_if_subif_table)
3105 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3106 sub->interface_name,
3108 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3109 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3110 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3111 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3112 if (sub->vtr_op != L2_VTR_DISABLED)
3115 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3116 "tag1: %d tag2: %d ]",
3117 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3118 sub->vtr_tag1, sub->vtr_tag2);
3126 name_sort_cmp (void *a1, void *a2)
3128 name_sort_t *n1 = a1;
3129 name_sort_t *n2 = a2;
3131 return strcmp ((char *) n1->name, (char *) n2->name);
3135 dump_interface_table (vat_main_t * vam)
3138 name_sort_t *nses = 0, *ns;
3140 if (vam->json_output)
3143 ("JSON output supported only for VPE API calls and dump_stats_table");
3148 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3150 vec_add2 (nses, ns, 1);
3151 ns->name = (u8 *)(p->key);
3152 ns->value = (u32) p->value[0];
3156 vec_sort_with_function (nses, name_sort_cmp);
3158 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3159 vec_foreach (ns, nses)
3161 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3168 dump_ip_table (vat_main_t * vam, int is_ipv6)
3170 const ip_details_t *det = NULL;
3171 const ip_address_details_t *address = NULL;
3174 print (vam->ofp, "%-12s", "sw_if_index");
3176 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3183 print (vam->ofp, "%-12d", i);
3184 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3189 vec_foreach (address, det->addr)
3193 is_ipv6 ? format_ip6_address : format_ip4_address,
3194 address->ip, address->prefix_length);
3202 dump_ipv4_table (vat_main_t * vam)
3204 if (vam->json_output)
3207 ("JSON output supported only for VPE API calls and dump_stats_table");
3211 return dump_ip_table (vam, 0);
3215 dump_ipv6_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, 1);
3228 * Pass CLI buffers directly in the CLI_INBAND API message,
3229 * instead of an additional shared memory area.
3232 exec_inband (vat_main_t * vam)
3234 vl_api_cli_inband_t *mp;
3235 unformat_input_t *i = vam->input;
3238 if (vec_len (i->buffer) == 0)
3241 if (vam->exec_mode == 0 && unformat (i, "mode"))
3246 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3253 * In order for the CLI command to work, it
3254 * must be a vector ending in \n, not a C-string ending
3257 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3258 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3262 /* json responses may or may not include a useful reply... */
3263 if (vec_len (vam->cmd_reply))
3264 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3269 exec (vat_main_t * vam)
3271 return exec_inband (vam);
3275 api_create_loopback (vat_main_t * vam)
3277 unformat_input_t *i = vam->input;
3278 vl_api_create_loopback_t *mp;
3279 vl_api_create_loopback_instance_t *mp_lbi;
3282 u8 is_specified = 0;
3283 u32 user_instance = 0;
3286 clib_memset (mac_address, 0, sizeof (mac_address));
3288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3290 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3292 if (unformat (i, "instance %d", &user_instance))
3300 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3301 mp_lbi->is_specified = is_specified;
3303 mp_lbi->user_instance = htonl (user_instance);
3305 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3310 /* Construct the API message */
3311 M (CREATE_LOOPBACK, mp);
3313 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3322 api_delete_loopback (vat_main_t * vam)
3324 unformat_input_t *i = vam->input;
3325 vl_api_delete_loopback_t *mp;
3326 u32 sw_if_index = ~0;
3329 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3331 if (unformat (i, "sw_if_index %d", &sw_if_index))
3337 if (sw_if_index == ~0)
3339 errmsg ("missing sw_if_index");
3343 /* Construct the API message */
3344 M (DELETE_LOOPBACK, mp);
3345 mp->sw_if_index = ntohl (sw_if_index);
3353 api_want_interface_events (vat_main_t * vam)
3355 unformat_input_t *i = vam->input;
3356 vl_api_want_interface_events_t *mp;
3360 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3362 if (unformat (i, "enable"))
3364 else if (unformat (i, "disable"))
3372 errmsg ("missing enable|disable");
3376 M (WANT_INTERFACE_EVENTS, mp);
3377 mp->enable_disable = enable;
3379 vam->interface_event_display = enable;
3387 /* Note: non-static, called once to set up the initial intfc table */
3389 api_sw_interface_dump (vat_main_t * vam)
3391 vl_api_sw_interface_dump_t *mp;
3392 vl_api_control_ping_t *mp_ping;
3394 name_sort_t *nses = 0, *ns;
3395 sw_interface_subif_t *sub = NULL;
3398 /* Toss the old name table */
3400 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3402 vec_add2 (nses, ns, 1);
3403 ns->name = (u8 *)(p->key);
3404 ns->value = (u32) p->value[0];
3408 hash_free (vam->sw_if_index_by_interface_name);
3410 vec_foreach (ns, nses) vec_free (ns->name);
3414 vec_foreach (sub, vam->sw_if_subif_table)
3416 vec_free (sub->interface_name);
3418 vec_free (vam->sw_if_subif_table);
3420 /* recreate the interface name hash table */
3421 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3424 * Ask for all interface names. Otherwise, the epic catalog of
3425 * name filters becomes ridiculously long, and vat ends up needing
3426 * to be taught about new interface types.
3428 M (SW_INTERFACE_DUMP, mp);
3431 /* Use a control ping for synchronization */
3432 MPING (CONTROL_PING, mp_ping);
3440 api_sw_interface_set_flags (vat_main_t * vam)
3442 unformat_input_t *i = vam->input;
3443 vl_api_sw_interface_set_flags_t *mp;
3445 u8 sw_if_index_set = 0;
3449 /* Parse args required to build the message */
3450 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3452 if (unformat (i, "admin-up"))
3454 else if (unformat (i, "admin-down"))
3457 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3458 sw_if_index_set = 1;
3459 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3460 sw_if_index_set = 1;
3465 if (sw_if_index_set == 0)
3467 errmsg ("missing interface name or sw_if_index");
3471 /* Construct the API message */
3472 M (SW_INTERFACE_SET_FLAGS, mp);
3473 mp->sw_if_index = ntohl (sw_if_index);
3474 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3479 /* Wait for a reply, return the good/bad news... */
3485 api_sw_interface_set_rx_mode (vat_main_t * vam)
3487 unformat_input_t *i = vam->input;
3488 vl_api_sw_interface_set_rx_mode_t *mp;
3490 u8 sw_if_index_set = 0;
3492 u8 queue_id_valid = 0;
3494 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3496 /* Parse args required to build the message */
3497 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3499 if (unformat (i, "queue %d", &queue_id))
3501 else if (unformat (i, "polling"))
3502 mode = VNET_HW_IF_RX_MODE_POLLING;
3503 else if (unformat (i, "interrupt"))
3504 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3505 else if (unformat (i, "adaptive"))
3506 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3508 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3509 sw_if_index_set = 1;
3510 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3511 sw_if_index_set = 1;
3516 if (sw_if_index_set == 0)
3518 errmsg ("missing interface name or sw_if_index");
3521 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3523 errmsg ("missing rx-mode");
3527 /* Construct the API message */
3528 M (SW_INTERFACE_SET_RX_MODE, mp);
3529 mp->sw_if_index = ntohl (sw_if_index);
3530 mp->mode = (vl_api_rx_mode_t) mode;
3531 mp->queue_id_valid = queue_id_valid;
3532 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3537 /* Wait for a reply, return the good/bad news... */
3543 api_sw_interface_set_rx_placement (vat_main_t * vam)
3545 unformat_input_t *i = vam->input;
3546 vl_api_sw_interface_set_rx_placement_t *mp;
3548 u8 sw_if_index_set = 0;
3551 u32 queue_id, thread_index;
3553 /* Parse args required to build the message */
3554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3556 if (unformat (i, "queue %d", &queue_id))
3558 else if (unformat (i, "main"))
3560 else if (unformat (i, "worker %d", &thread_index))
3563 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3564 sw_if_index_set = 1;
3565 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3566 sw_if_index_set = 1;
3571 if (sw_if_index_set == 0)
3573 errmsg ("missing interface name or sw_if_index");
3579 /* Construct the API message */
3580 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3581 mp->sw_if_index = ntohl (sw_if_index);
3582 mp->worker_id = ntohl (thread_index);
3583 mp->queue_id = ntohl (queue_id);
3584 mp->is_main = is_main;
3588 /* Wait for a reply, return the good/bad news... */
3593 static void vl_api_sw_interface_rx_placement_details_t_handler
3594 (vl_api_sw_interface_rx_placement_details_t * mp)
3596 vat_main_t *vam = &vat_main;
3597 u32 worker_id = ntohl (mp->worker_id);
3600 "\n%-11d %-11s %-6d %-5d %-9s",
3601 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3602 worker_id, ntohl (mp->queue_id),
3604 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3607 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3608 (vl_api_sw_interface_rx_placement_details_t * mp)
3610 vat_main_t *vam = &vat_main;
3611 vat_json_node_t *node = NULL;
3613 if (VAT_JSON_ARRAY != vam->json_tree.type)
3615 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3616 vat_json_init_array (&vam->json_tree);
3618 node = vat_json_array_add (&vam->json_tree);
3620 vat_json_init_object (node);
3621 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3622 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3623 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3624 vat_json_object_add_uint (node, "mode", mp->mode);
3628 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3630 unformat_input_t *i = vam->input;
3631 vl_api_sw_interface_rx_placement_dump_t *mp;
3632 vl_api_control_ping_t *mp_ping;
3635 u8 sw_if_index_set = 0;
3637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3639 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3641 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3648 "\n%-11s %-11s %-6s %-5s %-4s",
3649 "sw_if_index", "main/worker", "thread", "queue", "mode");
3651 /* Dump Interface rx placement */
3652 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3654 if (sw_if_index_set)
3655 mp->sw_if_index = htonl (sw_if_index);
3657 mp->sw_if_index = ~0;
3661 /* Use a control ping for synchronization */
3662 MPING (CONTROL_PING, mp_ping);
3670 api_sw_interface_clear_stats (vat_main_t * vam)
3672 unformat_input_t *i = vam->input;
3673 vl_api_sw_interface_clear_stats_t *mp;
3675 u8 sw_if_index_set = 0;
3678 /* Parse args required to build the message */
3679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3681 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3682 sw_if_index_set = 1;
3683 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3684 sw_if_index_set = 1;
3689 /* Construct the API message */
3690 M (SW_INTERFACE_CLEAR_STATS, mp);
3692 if (sw_if_index_set == 1)
3693 mp->sw_if_index = ntohl (sw_if_index);
3695 mp->sw_if_index = ~0;
3700 /* Wait for a reply, return the good/bad news... */
3706 api_sw_interface_add_del_address (vat_main_t * vam)
3708 unformat_input_t *i = vam->input;
3709 vl_api_sw_interface_add_del_address_t *mp;
3711 u8 sw_if_index_set = 0;
3712 u8 is_add = 1, del_all = 0;
3713 u32 address_length = 0;
3714 u8 v4_address_set = 0;
3715 u8 v6_address_set = 0;
3716 ip4_address_t v4address;
3717 ip6_address_t v6address;
3720 /* Parse args required to build the message */
3721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3723 if (unformat (i, "del-all"))
3725 else if (unformat (i, "del"))
3728 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3729 sw_if_index_set = 1;
3730 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3731 sw_if_index_set = 1;
3732 else if (unformat (i, "%U/%d",
3733 unformat_ip4_address, &v4address, &address_length))
3735 else if (unformat (i, "%U/%d",
3736 unformat_ip6_address, &v6address, &address_length))
3742 if (sw_if_index_set == 0)
3744 errmsg ("missing interface name or sw_if_index");
3747 if (v4_address_set && v6_address_set)
3749 errmsg ("both v4 and v6 addresses set");
3752 if (!v4_address_set && !v6_address_set && !del_all)
3754 errmsg ("no addresses set");
3758 /* Construct the API message */
3759 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3761 mp->sw_if_index = ntohl (sw_if_index);
3762 mp->is_add = is_add;
3763 mp->del_all = del_all;
3766 mp->prefix.address.af = ADDRESS_IP6;
3767 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3771 mp->prefix.address.af = ADDRESS_IP4;
3772 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3774 mp->prefix.len = address_length;
3779 /* Wait for a reply, return good/bad news */
3785 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3787 unformat_input_t *i = vam->input;
3788 vl_api_sw_interface_set_mpls_enable_t *mp;
3790 u8 sw_if_index_set = 0;
3794 /* Parse args required to build the message */
3795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3797 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3798 sw_if_index_set = 1;
3799 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3800 sw_if_index_set = 1;
3801 else if (unformat (i, "disable"))
3803 else if (unformat (i, "dis"))
3809 if (sw_if_index_set == 0)
3811 errmsg ("missing interface name or sw_if_index");
3815 /* Construct the API message */
3816 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3818 mp->sw_if_index = ntohl (sw_if_index);
3819 mp->enable = enable;
3824 /* Wait for a reply... */
3830 api_sw_interface_set_table (vat_main_t * vam)
3832 unformat_input_t *i = vam->input;
3833 vl_api_sw_interface_set_table_t *mp;
3834 u32 sw_if_index, vrf_id = 0;
3835 u8 sw_if_index_set = 0;
3839 /* Parse args required to build the message */
3840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3842 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3843 sw_if_index_set = 1;
3844 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3845 sw_if_index_set = 1;
3846 else if (unformat (i, "vrf %d", &vrf_id))
3848 else if (unformat (i, "ipv6"))
3854 if (sw_if_index_set == 0)
3856 errmsg ("missing interface name or sw_if_index");
3860 /* Construct the API message */
3861 M (SW_INTERFACE_SET_TABLE, mp);
3863 mp->sw_if_index = ntohl (sw_if_index);
3864 mp->is_ipv6 = is_ipv6;
3865 mp->vrf_id = ntohl (vrf_id);
3870 /* Wait for a reply... */
3875 static void vl_api_sw_interface_get_table_reply_t_handler
3876 (vl_api_sw_interface_get_table_reply_t * mp)
3878 vat_main_t *vam = &vat_main;
3880 print (vam->ofp, "%d", ntohl (mp->vrf_id));
3882 vam->retval = ntohl (mp->retval);
3883 vam->result_ready = 1;
3887 static void vl_api_sw_interface_get_table_reply_t_handler_json
3888 (vl_api_sw_interface_get_table_reply_t * mp)
3890 vat_main_t *vam = &vat_main;
3891 vat_json_node_t node;
3893 vat_json_init_object (&node);
3894 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3895 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3897 vat_json_print (vam->ofp, &node);
3898 vat_json_free (&node);
3900 vam->retval = ntohl (mp->retval);
3901 vam->result_ready = 1;
3905 api_sw_interface_get_table (vat_main_t * vam)
3907 unformat_input_t *i = vam->input;
3908 vl_api_sw_interface_get_table_t *mp;
3910 u8 sw_if_index_set = 0;
3914 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3916 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3917 sw_if_index_set = 1;
3918 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3919 sw_if_index_set = 1;
3920 else if (unformat (i, "ipv6"))
3926 if (sw_if_index_set == 0)
3928 errmsg ("missing interface name or sw_if_index");
3932 M (SW_INTERFACE_GET_TABLE, mp);
3933 mp->sw_if_index = htonl (sw_if_index);
3934 mp->is_ipv6 = is_ipv6;
3942 api_sw_interface_set_vpath (vat_main_t * vam)
3944 unformat_input_t *i = vam->input;
3945 vl_api_sw_interface_set_vpath_t *mp;
3946 u32 sw_if_index = 0;
3947 u8 sw_if_index_set = 0;
3951 /* Parse args required to build the message */
3952 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3954 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3955 sw_if_index_set = 1;
3956 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3957 sw_if_index_set = 1;
3958 else if (unformat (i, "enable"))
3960 else if (unformat (i, "disable"))
3966 if (sw_if_index_set == 0)
3968 errmsg ("missing interface name or sw_if_index");
3972 /* Construct the API message */
3973 M (SW_INTERFACE_SET_VPATH, mp);
3975 mp->sw_if_index = ntohl (sw_if_index);
3976 mp->enable = is_enable;
3981 /* Wait for a reply... */
3987 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3989 unformat_input_t *i = vam->input;
3990 vl_api_sw_interface_set_l2_xconnect_t *mp;
3992 u8 rx_sw_if_index_set = 0;
3994 u8 tx_sw_if_index_set = 0;
3998 /* Parse args required to build the message */
3999 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4001 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4002 rx_sw_if_index_set = 1;
4003 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4004 tx_sw_if_index_set = 1;
4005 else if (unformat (i, "rx"))
4007 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4009 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4011 rx_sw_if_index_set = 1;
4016 else if (unformat (i, "tx"))
4018 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4020 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
4022 tx_sw_if_index_set = 1;
4027 else if (unformat (i, "enable"))
4029 else if (unformat (i, "disable"))
4035 if (rx_sw_if_index_set == 0)
4037 errmsg ("missing rx interface name or rx_sw_if_index");
4041 if (enable && (tx_sw_if_index_set == 0))
4043 errmsg ("missing tx interface name or tx_sw_if_index");
4047 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4049 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4050 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4051 mp->enable = enable;
4059 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4061 unformat_input_t *i = vam->input;
4062 vl_api_sw_interface_set_l2_bridge_t *mp;
4063 vl_api_l2_port_type_t port_type;
4065 u8 rx_sw_if_index_set = 0;
4072 port_type = L2_API_PORT_TYPE_NORMAL;
4074 /* Parse args required to build the message */
4075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4077 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4078 rx_sw_if_index_set = 1;
4079 else if (unformat (i, "bd_id %d", &bd_id))
4083 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4084 rx_sw_if_index_set = 1;
4085 else if (unformat (i, "shg %d", &shg))
4087 else if (unformat (i, "bvi"))
4088 port_type = L2_API_PORT_TYPE_BVI;
4089 else if (unformat (i, "uu-fwd"))
4090 port_type = L2_API_PORT_TYPE_UU_FWD;
4091 else if (unformat (i, "enable"))
4093 else if (unformat (i, "disable"))
4099 if (rx_sw_if_index_set == 0)
4101 errmsg ("missing rx interface name or sw_if_index");
4105 if (enable && (bd_id_set == 0))
4107 errmsg ("missing bridge domain");
4111 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4113 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4114 mp->bd_id = ntohl (bd_id);
4116 mp->port_type = ntohl (port_type);
4117 mp->enable = enable;
4125 api_bridge_domain_dump (vat_main_t * vam)
4127 unformat_input_t *i = vam->input;
4128 vl_api_bridge_domain_dump_t *mp;
4129 vl_api_control_ping_t *mp_ping;
4133 /* Parse args required to build the message */
4134 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4136 if (unformat (i, "bd_id %d", &bd_id))
4142 M (BRIDGE_DOMAIN_DUMP, mp);
4143 mp->bd_id = ntohl (bd_id);
4146 /* Use a control ping for synchronization */
4147 MPING (CONTROL_PING, mp_ping);
4155 api_bridge_domain_add_del (vat_main_t * vam)
4157 unformat_input_t *i = vam->input;
4158 vl_api_bridge_domain_add_del_t *mp;
4161 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4166 /* Parse args required to build the message */
4167 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4169 if (unformat (i, "bd_id %d", &bd_id))
4171 else if (unformat (i, "flood %d", &flood))
4173 else if (unformat (i, "uu-flood %d", &uu_flood))
4175 else if (unformat (i, "forward %d", &forward))
4177 else if (unformat (i, "learn %d", &learn))
4179 else if (unformat (i, "arp-term %d", &arp_term))
4181 else if (unformat (i, "mac-age %d", &mac_age))
4183 else if (unformat (i, "bd-tag %s", &bd_tag))
4185 else if (unformat (i, "del"))
4188 flood = uu_flood = forward = learn = 0;
4196 errmsg ("missing bridge domain");
4203 errmsg ("mac age must be less than 256 ");
4208 if ((bd_tag) && (vec_len (bd_tag) > 63))
4210 errmsg ("bd-tag cannot be longer than 63");
4215 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4217 mp->bd_id = ntohl (bd_id);
4219 mp->uu_flood = uu_flood;
4220 mp->forward = forward;
4222 mp->arp_term = arp_term;
4223 mp->is_add = is_add;
4224 mp->mac_age = (u8) mac_age;
4227 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4228 mp->bd_tag[vec_len (bd_tag)] = 0;
4239 api_l2fib_flush_bd (vat_main_t * vam)
4241 unformat_input_t *i = vam->input;
4242 vl_api_l2fib_flush_bd_t *mp;
4246 /* Parse args required to build the message */
4247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4249 if (unformat (i, "bd_id %d", &bd_id));
4256 errmsg ("missing bridge domain");
4260 M (L2FIB_FLUSH_BD, mp);
4262 mp->bd_id = htonl (bd_id);
4270 api_l2fib_flush_int (vat_main_t * vam)
4272 unformat_input_t *i = vam->input;
4273 vl_api_l2fib_flush_int_t *mp;
4274 u32 sw_if_index = ~0;
4277 /* Parse args required to build the message */
4278 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4280 if (unformat (i, "sw_if_index %d", &sw_if_index));
4282 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4287 if (sw_if_index == ~0)
4289 errmsg ("missing interface name or sw_if_index");
4293 M (L2FIB_FLUSH_INT, mp);
4295 mp->sw_if_index = ntohl (sw_if_index);
4303 api_l2fib_add_del (vat_main_t * vam)
4305 unformat_input_t *i = vam->input;
4306 vl_api_l2fib_add_del_t *mp;
4312 u32 sw_if_index = 0;
4313 u8 sw_if_index_set = 0;
4322 /* Parse args required to build the message */
4323 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4325 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4327 else if (unformat (i, "bd_id %d", &bd_id))
4329 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4330 sw_if_index_set = 1;
4331 else if (unformat (i, "sw_if"))
4333 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4336 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4337 sw_if_index_set = 1;
4342 else if (unformat (i, "static"))
4344 else if (unformat (i, "filter"))
4349 else if (unformat (i, "bvi"))
4354 else if (unformat (i, "del"))
4356 else if (unformat (i, "count %d", &count))
4364 errmsg ("missing mac address");
4370 errmsg ("missing bridge domain");
4374 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4376 errmsg ("missing interface name or sw_if_index");
4382 /* Turn on async mode */
4383 vam->async_mode = 1;
4384 vam->async_errors = 0;
4385 before = vat_time_now (vam);
4388 for (j = 0; j < count; j++)
4390 M (L2FIB_ADD_DEL, mp);
4392 clib_memcpy (mp->mac, mac, 6);
4393 mp->bd_id = ntohl (bd_id);
4394 mp->is_add = is_add;
4395 mp->sw_if_index = ntohl (sw_if_index);
4399 mp->static_mac = static_mac;
4400 mp->filter_mac = filter_mac;
4401 mp->bvi_mac = bvi_mac;
4403 increment_mac_address (mac);
4410 vl_api_control_ping_t *mp_ping;
4413 /* Shut off async mode */
4414 vam->async_mode = 0;
4416 MPING (CONTROL_PING, mp_ping);
4419 timeout = vat_time_now (vam) + 1.0;
4420 while (vat_time_now (vam) < timeout)
4421 if (vam->result_ready == 1)
4426 if (vam->retval == -99)
4429 if (vam->async_errors > 0)
4431 errmsg ("%d asynchronous errors", vam->async_errors);
4434 vam->async_errors = 0;
4435 after = vat_time_now (vam);
4437 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4438 count, after - before, count / (after - before));
4444 /* Wait for a reply... */
4448 /* Return the good/bad news */
4449 return (vam->retval);
4453 api_bridge_domain_set_mac_age (vat_main_t * vam)
4455 unformat_input_t *i = vam->input;
4456 vl_api_bridge_domain_set_mac_age_t *mp;
4461 /* Parse args required to build the message */
4462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4464 if (unformat (i, "bd_id %d", &bd_id));
4465 else if (unformat (i, "mac-age %d", &mac_age));
4472 errmsg ("missing bridge domain");
4478 errmsg ("mac age must be less than 256 ");
4482 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4484 mp->bd_id = htonl (bd_id);
4485 mp->mac_age = (u8) mac_age;
4493 api_l2_flags (vat_main_t * vam)
4495 unformat_input_t *i = vam->input;
4496 vl_api_l2_flags_t *mp;
4499 u8 sw_if_index_set = 0;
4503 /* Parse args required to build the message */
4504 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4506 if (unformat (i, "sw_if_index %d", &sw_if_index))
4507 sw_if_index_set = 1;
4508 else if (unformat (i, "sw_if"))
4510 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4513 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4514 sw_if_index_set = 1;
4519 else if (unformat (i, "learn"))
4521 else if (unformat (i, "forward"))
4523 else if (unformat (i, "flood"))
4525 else if (unformat (i, "uu-flood"))
4526 flags |= L2_UU_FLOOD;
4527 else if (unformat (i, "arp-term"))
4528 flags |= L2_ARP_TERM;
4529 else if (unformat (i, "off"))
4531 else if (unformat (i, "disable"))
4537 if (sw_if_index_set == 0)
4539 errmsg ("missing interface name or sw_if_index");
4545 mp->sw_if_index = ntohl (sw_if_index);
4546 mp->feature_bitmap = ntohl (flags);
4547 mp->is_set = is_set;
4555 api_bridge_flags (vat_main_t * vam)
4557 unformat_input_t *i = vam->input;
4558 vl_api_bridge_flags_t *mp;
4562 bd_flags_t flags = 0;
4565 /* Parse args required to build the message */
4566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4568 if (unformat (i, "bd_id %d", &bd_id))
4570 else if (unformat (i, "learn"))
4571 flags |= BRIDGE_API_FLAG_LEARN;
4572 else if (unformat (i, "forward"))
4573 flags |= BRIDGE_API_FLAG_FWD;
4574 else if (unformat (i, "flood"))
4575 flags |= BRIDGE_API_FLAG_FLOOD;
4576 else if (unformat (i, "uu-flood"))
4577 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4578 else if (unformat (i, "arp-term"))
4579 flags |= BRIDGE_API_FLAG_ARP_TERM;
4580 else if (unformat (i, "off"))
4582 else if (unformat (i, "disable"))
4590 errmsg ("missing bridge domain");
4594 M (BRIDGE_FLAGS, mp);
4596 mp->bd_id = ntohl (bd_id);
4597 mp->flags = ntohl (flags);
4598 mp->is_set = is_set;
4606 api_bd_ip_mac_add_del (vat_main_t * vam)
4608 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4609 vl_api_mac_address_t mac = { 0 };
4610 unformat_input_t *i = vam->input;
4611 vl_api_bd_ip_mac_add_del_t *mp;
4620 /* Parse args required to build the message */
4621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4623 if (unformat (i, "bd_id %d", &bd_id))
4627 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4631 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4635 else if (unformat (i, "del"))
4643 errmsg ("missing bridge domain");
4646 else if (ip_set == 0)
4648 errmsg ("missing IP address");
4651 else if (mac_set == 0)
4653 errmsg ("missing MAC address");
4657 M (BD_IP_MAC_ADD_DEL, mp);
4659 mp->entry.bd_id = ntohl (bd_id);
4660 mp->is_add = is_add;
4662 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4663 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4671 api_bd_ip_mac_flush (vat_main_t * vam)
4673 unformat_input_t *i = vam->input;
4674 vl_api_bd_ip_mac_flush_t *mp;
4679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4681 if (unformat (i, "bd_id %d", &bd_id))
4691 errmsg ("missing bridge domain");
4695 M (BD_IP_MAC_FLUSH, mp);
4697 mp->bd_id = ntohl (bd_id);
4704 static void vl_api_bd_ip_mac_details_t_handler
4705 (vl_api_bd_ip_mac_details_t * mp)
4707 vat_main_t *vam = &vat_main;
4711 ntohl (mp->entry.bd_id),
4712 format_vl_api_mac_address, mp->entry.mac,
4713 format_vl_api_address, &mp->entry.ip);
4716 static void vl_api_bd_ip_mac_details_t_handler_json
4717 (vl_api_bd_ip_mac_details_t * mp)
4719 vat_main_t *vam = &vat_main;
4720 vat_json_node_t *node = NULL;
4722 if (VAT_JSON_ARRAY != vam->json_tree.type)
4724 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4725 vat_json_init_array (&vam->json_tree);
4727 node = vat_json_array_add (&vam->json_tree);
4729 vat_json_init_object (node);
4730 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4731 vat_json_object_add_string_copy (node, "mac_address",
4732 format (0, "%U", format_vl_api_mac_address,
4736 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4737 vat_json_object_add_string_copy (node, "ip_address", ip);
4742 api_bd_ip_mac_dump (vat_main_t * vam)
4744 unformat_input_t *i = vam->input;
4745 vl_api_bd_ip_mac_dump_t *mp;
4746 vl_api_control_ping_t *mp_ping;
4751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4753 if (unformat (i, "bd_id %d", &bd_id))
4762 "\n%-5s %-7s %-20s %-30s",
4763 "bd_id", "is_ipv6", "mac_address", "ip_address");
4765 /* Dump Bridge Domain Ip to Mac entries */
4766 M (BD_IP_MAC_DUMP, mp);
4769 mp->bd_id = htonl (bd_id);
4775 /* Use a control ping for synchronization */
4776 MPING (CONTROL_PING, mp_ping);
4784 api_tap_create_v2 (vat_main_t * vam)
4786 unformat_input_t *i = vam->input;
4787 vl_api_tap_create_v2_t *mp;
4791 u32 num_rx_queues = 0;
4792 u8 *host_if_name = 0;
4793 u8 host_if_name_set = 0;
4796 u8 host_mac_addr[6];
4797 u8 host_mac_addr_set = 0;
4798 u8 *host_bridge = 0;
4799 u8 host_bridge_set = 0;
4800 u8 host_ip4_prefix_set = 0;
4801 u8 host_ip6_prefix_set = 0;
4802 ip4_address_t host_ip4_addr;
4803 ip4_address_t host_ip4_gw;
4804 u8 host_ip4_gw_set = 0;
4805 u32 host_ip4_prefix_len = 0;
4806 ip6_address_t host_ip6_addr;
4807 ip6_address_t host_ip6_gw;
4808 u8 host_ip6_gw_set = 0;
4809 u32 host_ip6_prefix_len = 0;
4810 u32 host_mtu_size = 0;
4811 u8 host_mtu_set = 0;
4814 u32 rx_ring_sz = 0, tx_ring_sz = 0;
4816 clib_memset (mac_address, 0, sizeof (mac_address));
4818 /* Parse args required to build the message */
4819 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4821 if (unformat (i, "id %u", &id))
4825 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4827 else if (unformat (i, "host-if-name %s", &host_if_name))
4828 host_if_name_set = 1;
4829 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
4831 else if (unformat (i, "host-ns %s", &host_ns))
4833 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
4835 host_mac_addr_set = 1;
4836 else if (unformat (i, "host-bridge %s", &host_bridge))
4837 host_bridge_set = 1;
4838 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
4839 &host_ip4_addr, &host_ip4_prefix_len))
4840 host_ip4_prefix_set = 1;
4841 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
4842 &host_ip6_addr, &host_ip6_prefix_len))
4843 host_ip6_prefix_set = 1;
4844 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
4846 host_ip4_gw_set = 1;
4847 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
4849 host_ip6_gw_set = 1;
4850 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
4852 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
4854 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
4856 else if (unformat (i, "no-gso"))
4857 tap_flags &= ~TAP_API_FLAG_GSO;
4858 else if (unformat (i, "gso"))
4859 tap_flags |= TAP_API_FLAG_GSO;
4860 else if (unformat (i, "csum-offload"))
4861 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
4862 else if (unformat (i, "persist"))
4863 tap_flags |= TAP_API_FLAG_PERSIST;
4864 else if (unformat (i, "attach"))
4865 tap_flags |= TAP_API_FLAG_ATTACH;
4866 else if (unformat (i, "tun"))
4867 tap_flags |= TAP_API_FLAG_TUN;
4868 else if (unformat (i, "gro-coalesce"))
4869 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
4870 else if (unformat (i, "packed"))
4871 tap_flags |= TAP_API_FLAG_PACKED;
4872 else if (unformat (i, "in-order"))
4873 tap_flags |= TAP_API_FLAG_IN_ORDER;
4878 if (vec_len (host_if_name) > 63)
4880 errmsg ("tap name too long. ");
4883 if (vec_len (host_ns) > 63)
4885 errmsg ("host name space too long. ");
4888 if (vec_len (host_bridge) > 63)
4890 errmsg ("host bridge name too long. ");
4893 if (host_ip4_prefix_len > 32)
4895 errmsg ("host ip4 prefix length not valid. ");
4898 if (host_ip6_prefix_len > 128)
4900 errmsg ("host ip6 prefix length not valid. ");
4903 if (!is_pow2 (rx_ring_sz))
4905 errmsg ("rx ring size must be power of 2. ");
4908 if (rx_ring_sz > 32768)
4910 errmsg ("rx ring size must be 32768 or lower. ");
4913 if (!is_pow2 (tx_ring_sz))
4915 errmsg ("tx ring size must be power of 2. ");
4918 if (tx_ring_sz > 32768)
4920 errmsg ("tx ring size must be 32768 or lower. ");
4923 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
4925 errmsg ("host MTU size must be in between 64 and 65355. ");
4929 /* Construct the API message */
4930 M (TAP_CREATE_V2, mp);
4932 mp->id = ntohl (id);
4933 mp->use_random_mac = random_mac;
4934 mp->num_rx_queues = (u8) num_rx_queues;
4935 mp->tx_ring_sz = ntohs (tx_ring_sz);
4936 mp->rx_ring_sz = ntohs (rx_ring_sz);
4937 mp->host_mtu_set = host_mtu_set;
4938 mp->host_mtu_size = ntohl (host_mtu_size);
4939 mp->host_mac_addr_set = host_mac_addr_set;
4940 mp->host_ip4_prefix_set = host_ip4_prefix_set;
4941 mp->host_ip6_prefix_set = host_ip6_prefix_set;
4942 mp->host_ip4_gw_set = host_ip4_gw_set;
4943 mp->host_ip6_gw_set = host_ip6_gw_set;
4944 mp->tap_flags = ntohl (tap_flags);
4945 mp->host_namespace_set = host_ns_set;
4946 mp->host_if_name_set = host_if_name_set;
4947 mp->host_bridge_set = host_bridge_set;
4949 if (random_mac == 0)
4950 clib_memcpy (mp->mac_address, mac_address, 6);
4951 if (host_mac_addr_set)
4952 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
4953 if (host_if_name_set)
4954 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
4956 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
4957 if (host_bridge_set)
4958 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
4959 if (host_ip4_prefix_set)
4961 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
4962 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
4964 if (host_ip6_prefix_set)
4966 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
4967 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
4969 if (host_ip4_gw_set)
4970 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
4971 if (host_ip6_gw_set)
4972 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
4975 vec_free (host_if_name);
4976 vec_free (host_bridge);
4981 /* Wait for a reply... */
4987 api_tap_delete_v2 (vat_main_t * vam)
4989 unformat_input_t *i = vam->input;
4990 vl_api_tap_delete_v2_t *mp;
4991 u32 sw_if_index = ~0;
4992 u8 sw_if_index_set = 0;
4995 /* Parse args required to build the message */
4996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4998 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4999 sw_if_index_set = 1;
5000 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5001 sw_if_index_set = 1;
5006 if (sw_if_index_set == 0)
5008 errmsg ("missing vpp interface name. ");
5012 /* Construct the API message */
5013 M (TAP_DELETE_V2, mp);
5015 mp->sw_if_index = ntohl (sw_if_index);
5020 /* Wait for a reply... */
5026 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
5028 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
5031 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
5034 addr->domain = x[0];
5037 addr->function = x[3];
5043 api_virtio_pci_create_v2 (vat_main_t * vam)
5045 unformat_input_t *i = vam->input;
5046 vl_api_virtio_pci_create_v2_t *mp;
5050 u64 features = (u64) ~ (0ULL);
5051 u32 virtio_flags = 0;
5054 clib_memset (mac_address, 0, sizeof (mac_address));
5056 /* Parse args required to build the message */
5057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5059 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5063 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5065 else if (unformat (i, "features 0x%llx", &features))
5067 else if (unformat (i, "gso-enabled"))
5068 virtio_flags |= VIRTIO_API_FLAG_GSO;
5069 else if (unformat (i, "csum-offload-enabled"))
5070 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5071 else if (unformat (i, "gro-coalesce"))
5072 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5073 else if (unformat (i, "packed"))
5074 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5075 else if (unformat (i, "in-order"))
5076 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5077 else if (unformat (i, "buffering"))
5078 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5085 errmsg ("pci address must be non zero. ");
5089 /* Construct the API message */
5090 M (VIRTIO_PCI_CREATE_V2, mp);
5092 mp->use_random_mac = random_mac;
5094 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5095 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5096 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5097 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5099 mp->features = clib_host_to_net_u64 (features);
5100 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5102 if (random_mac == 0)
5103 clib_memcpy (mp->mac_address, mac_address, 6);
5108 /* Wait for a reply... */
5114 api_virtio_pci_delete (vat_main_t * vam)
5116 unformat_input_t *i = vam->input;
5117 vl_api_virtio_pci_delete_t *mp;
5118 u32 sw_if_index = ~0;
5119 u8 sw_if_index_set = 0;
5122 /* Parse args required to build the message */
5123 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5125 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5126 sw_if_index_set = 1;
5127 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5128 sw_if_index_set = 1;
5133 if (sw_if_index_set == 0)
5135 errmsg ("missing vpp interface name. ");
5139 /* Construct the API message */
5140 M (VIRTIO_PCI_DELETE, mp);
5142 mp->sw_if_index = htonl (sw_if_index);
5147 /* Wait for a reply... */
5153 api_bond_create (vat_main_t * vam)
5155 unformat_input_t *i = vam->input;
5156 vl_api_bond_create_t *mp;
5166 clib_memset (mac_address, 0, sizeof (mac_address));
5169 /* Parse args required to build the message */
5170 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5172 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5174 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5175 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5177 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5180 else if (unformat (i, "numa-only"))
5182 else if (unformat (i, "id %u", &id))
5188 if (mode_is_set == 0)
5190 errmsg ("Missing bond mode. ");
5194 /* Construct the API message */
5195 M (BOND_CREATE, mp);
5197 mp->use_custom_mac = custom_mac;
5199 mp->mode = htonl (mode);
5200 mp->lb = htonl (lb);
5201 mp->id = htonl (id);
5202 mp->numa_only = numa_only;
5205 clib_memcpy (mp->mac_address, mac_address, 6);
5210 /* Wait for a reply... */
5216 api_bond_create2 (vat_main_t * vam)
5218 unformat_input_t *i = vam->input;
5219 vl_api_bond_create2_t *mp;
5230 clib_memset (mac_address, 0, sizeof (mac_address));
5233 /* Parse args required to build the message */
5234 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5236 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5238 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5239 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5241 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5244 else if (unformat (i, "numa-only"))
5246 else if (unformat (i, "gso"))
5248 else if (unformat (i, "id %u", &id))
5254 if (mode_is_set == 0)
5256 errmsg ("Missing bond mode. ");
5260 /* Construct the API message */
5261 M (BOND_CREATE2, mp);
5263 mp->use_custom_mac = custom_mac;
5265 mp->mode = htonl (mode);
5266 mp->lb = htonl (lb);
5267 mp->id = htonl (id);
5268 mp->numa_only = numa_only;
5269 mp->enable_gso = gso;
5272 clib_memcpy (mp->mac_address, mac_address, 6);
5277 /* Wait for a reply... */
5283 api_bond_delete (vat_main_t * vam)
5285 unformat_input_t *i = vam->input;
5286 vl_api_bond_delete_t *mp;
5287 u32 sw_if_index = ~0;
5288 u8 sw_if_index_set = 0;
5291 /* Parse args required to build the message */
5292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5294 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5295 sw_if_index_set = 1;
5296 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5297 sw_if_index_set = 1;
5302 if (sw_if_index_set == 0)
5304 errmsg ("missing vpp interface name. ");
5308 /* Construct the API message */
5309 M (BOND_DELETE, mp);
5311 mp->sw_if_index = ntohl (sw_if_index);
5316 /* Wait for a reply... */
5322 api_bond_add_member (vat_main_t * vam)
5324 unformat_input_t *i = vam->input;
5325 vl_api_bond_add_member_t *mp;
5326 u32 bond_sw_if_index;
5330 u32 bond_sw_if_index_is_set = 0;
5332 u8 sw_if_index_is_set = 0;
5334 /* Parse args required to build the message */
5335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5337 if (unformat (i, "sw_if_index %d", &sw_if_index))
5338 sw_if_index_is_set = 1;
5339 else if (unformat (i, "bond %u", &bond_sw_if_index))
5340 bond_sw_if_index_is_set = 1;
5341 else if (unformat (i, "passive %d", &is_passive))
5343 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5349 if (bond_sw_if_index_is_set == 0)
5351 errmsg ("Missing bond sw_if_index. ");
5354 if (sw_if_index_is_set == 0)
5356 errmsg ("Missing member sw_if_index. ");
5360 /* Construct the API message */
5361 M (BOND_ADD_MEMBER, mp);
5363 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5364 mp->sw_if_index = ntohl (sw_if_index);
5365 mp->is_long_timeout = is_long_timeout;
5366 mp->is_passive = is_passive;
5371 /* Wait for a reply... */
5377 api_bond_detach_member (vat_main_t * vam)
5379 unformat_input_t *i = vam->input;
5380 vl_api_bond_detach_member_t *mp;
5381 u32 sw_if_index = ~0;
5382 u8 sw_if_index_set = 0;
5385 /* Parse args required to build the message */
5386 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5388 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5389 sw_if_index_set = 1;
5390 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5391 sw_if_index_set = 1;
5396 if (sw_if_index_set == 0)
5398 errmsg ("missing vpp interface name. ");
5402 /* Construct the API message */
5403 M (BOND_DETACH_MEMBER, mp);
5405 mp->sw_if_index = ntohl (sw_if_index);
5410 /* Wait for a reply... */
5416 api_ip_table_add_del (vat_main_t * vam)
5418 unformat_input_t *i = vam->input;
5419 vl_api_ip_table_add_del_t *mp;
5425 /* Parse args required to build the message */
5426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5428 if (unformat (i, "ipv6"))
5430 else if (unformat (i, "del"))
5432 else if (unformat (i, "add"))
5434 else if (unformat (i, "table %d", &table_id))
5438 clib_warning ("parse error '%U'", format_unformat_error, i);
5445 errmsg ("missing table-ID");
5449 /* Construct the API message */
5450 M (IP_TABLE_ADD_DEL, mp);
5452 mp->table.table_id = ntohl (table_id);
5453 mp->table.is_ip6 = is_ipv6;
5454 mp->is_add = is_add;
5459 /* Wait for a reply... */
5466 unformat_fib_path (unformat_input_t * input, va_list * args)
5468 vat_main_t *vam = va_arg (*args, vat_main_t *);
5469 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5470 u32 weight, preference;
5471 mpls_label_t out_label;
5473 clib_memset (path, 0, sizeof (*path));
5475 path->sw_if_index = ~0;
5479 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5481 if (unformat (input, "%U %U",
5482 unformat_vl_api_ip4_address,
5483 &path->nh.address.ip4,
5484 api_unformat_sw_if_index, vam, &path->sw_if_index))
5486 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5488 else if (unformat (input, "%U %U",
5489 unformat_vl_api_ip6_address,
5490 &path->nh.address.ip6,
5491 api_unformat_sw_if_index, vam, &path->sw_if_index))
5493 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5495 else if (unformat (input, "weight %u", &weight))
5497 path->weight = weight;
5499 else if (unformat (input, "preference %u", &preference))
5501 path->preference = preference;
5503 else if (unformat (input, "%U next-hop-table %d",
5504 unformat_vl_api_ip4_address,
5505 &path->nh.address.ip4, &path->table_id))
5507 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5509 else if (unformat (input, "%U next-hop-table %d",
5510 unformat_vl_api_ip6_address,
5511 &path->nh.address.ip6, &path->table_id))
5513 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5515 else if (unformat (input, "%U",
5516 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5519 * the recursive next-hops are by default in the default table
5522 path->sw_if_index = ~0;
5523 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5525 else if (unformat (input, "%U",
5526 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5529 * the recursive next-hops are by default in the default table
5532 path->sw_if_index = ~0;
5533 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5535 else if (unformat (input, "resolve-via-host"))
5537 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5539 else if (unformat (input, "resolve-via-attached"))
5541 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5543 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5545 path->type = FIB_API_PATH_TYPE_LOCAL;
5546 path->sw_if_index = ~0;
5547 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5549 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5551 path->type = FIB_API_PATH_TYPE_LOCAL;
5552 path->sw_if_index = ~0;
5553 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5555 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5557 else if (unformat (input, "via-label %d", &path->nh.via_label))
5559 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5560 path->sw_if_index = ~0;
5562 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5564 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5565 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5567 else if (unformat (input, "local"))
5569 path->type = FIB_API_PATH_TYPE_LOCAL;
5571 else if (unformat (input, "out-labels"))
5573 while (unformat (input, "%d", &out_label))
5575 path->label_stack[path->n_labels].label = out_label;
5576 path->label_stack[path->n_labels].is_uniform = 0;
5577 path->label_stack[path->n_labels].ttl = 64;
5581 else if (unformat (input, "via"))
5583 /* new path, back up and return */
5584 unformat_put_input (input);
5585 unformat_put_input (input);
5586 unformat_put_input (input);
5587 unformat_put_input (input);
5596 path->proto = ntohl (path->proto);
5597 path->type = ntohl (path->type);
5598 path->flags = ntohl (path->flags);
5599 path->table_id = ntohl (path->table_id);
5600 path->sw_if_index = ntohl (path->sw_if_index);
5606 api_ip_route_add_del (vat_main_t * vam)
5608 unformat_input_t *i = vam->input;
5609 vl_api_ip_route_add_del_t *mp;
5612 u8 is_multipath = 0;
5615 vl_api_prefix_t pfx = { };
5616 vl_api_fib_path_t paths[8];
5620 u32 random_add_del = 0;
5621 u32 *random_vector = 0;
5622 u32 random_seed = 0xdeaddabe;
5624 /* Parse args required to build the message */
5625 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5627 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5629 else if (unformat (i, "del"))
5631 else if (unformat (i, "add"))
5633 else if (unformat (i, "vrf %d", &vrf_id))
5635 else if (unformat (i, "count %d", &count))
5637 else if (unformat (i, "random"))
5639 else if (unformat (i, "multipath"))
5641 else if (unformat (i, "seed %d", &random_seed))
5645 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5648 if (8 == path_count)
5650 errmsg ("max 8 paths");
5656 clib_warning ("parse error '%U'", format_unformat_error, i);
5663 errmsg ("specify a path; via ...");
5666 if (prefix_set == 0)
5668 errmsg ("missing prefix");
5672 /* Generate a pile of unique, random routes */
5675 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5676 u32 this_random_address;
5679 random_hash = hash_create (count, sizeof (uword));
5681 hash_set (random_hash, i->as_u32, 1);
5682 for (j = 0; j <= count; j++)
5686 this_random_address = random_u32 (&random_seed);
5687 this_random_address =
5688 clib_host_to_net_u32 (this_random_address);
5690 while (hash_get (random_hash, this_random_address));
5691 vec_add1 (random_vector, this_random_address);
5692 hash_set (random_hash, this_random_address, 1);
5694 hash_free (random_hash);
5695 set_ip4_address (&pfx.address, random_vector[0]);
5700 /* Turn on async mode */
5701 vam->async_mode = 1;
5702 vam->async_errors = 0;
5703 before = vat_time_now (vam);
5706 for (j = 0; j < count; j++)
5708 /* Construct the API message */
5709 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5711 mp->is_add = is_add;
5712 mp->is_multipath = is_multipath;
5714 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5715 mp->route.table_id = ntohl (vrf_id);
5716 mp->route.n_paths = path_count;
5718 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5721 set_ip4_address (&pfx.address, random_vector[j + 1]);
5723 increment_address (&pfx.address);
5726 /* If we receive SIGTERM, stop now... */
5731 /* When testing multiple add/del ops, use a control-ping to sync */
5734 vl_api_control_ping_t *mp_ping;
5738 /* Shut off async mode */
5739 vam->async_mode = 0;
5741 MPING (CONTROL_PING, mp_ping);
5744 timeout = vat_time_now (vam) + 1.0;
5745 while (vat_time_now (vam) < timeout)
5746 if (vam->result_ready == 1)
5751 if (vam->retval == -99)
5754 if (vam->async_errors > 0)
5756 errmsg ("%d asynchronous errors", vam->async_errors);
5759 vam->async_errors = 0;
5760 after = vat_time_now (vam);
5762 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5766 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5767 count, after - before, count / (after - before));
5773 /* Wait for a reply... */
5778 /* Return the good/bad news */
5779 return (vam->retval);
5783 api_ip_mroute_add_del (vat_main_t * vam)
5785 unformat_input_t *i = vam->input;
5786 u8 path_set = 0, prefix_set = 0, is_add = 1;
5787 vl_api_ip_mroute_add_del_t *mp;
5788 mfib_entry_flags_t eflags = 0;
5789 vl_api_mfib_path_t path;
5790 vl_api_mprefix_t pfx = { };
5794 /* Parse args required to build the message */
5795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5797 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5800 pfx.grp_address_length = htons (pfx.grp_address_length);
5802 else if (unformat (i, "del"))
5804 else if (unformat (i, "add"))
5806 else if (unformat (i, "vrf %d", &vrf_id))
5808 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
5809 path.itf_flags = htonl (path.itf_flags);
5810 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
5812 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
5816 clib_warning ("parse error '%U'", format_unformat_error, i);
5821 if (prefix_set == 0)
5823 errmsg ("missing addresses\n");
5828 errmsg ("missing path\n");
5832 /* Construct the API message */
5833 M (IP_MROUTE_ADD_DEL, mp);
5835 mp->is_add = is_add;
5836 mp->is_multipath = 1;
5838 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5839 mp->route.table_id = htonl (vrf_id);
5840 mp->route.n_paths = 1;
5841 mp->route.entry_flags = htonl (eflags);
5843 clib_memcpy (&mp->route.paths, &path, sizeof (path));
5847 /* Wait for a reply... */
5853 api_mpls_table_add_del (vat_main_t * vam)
5855 unformat_input_t *i = vam->input;
5856 vl_api_mpls_table_add_del_t *mp;
5861 /* Parse args required to build the message */
5862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5864 if (unformat (i, "table %d", &table_id))
5866 else if (unformat (i, "del"))
5868 else if (unformat (i, "add"))
5872 clib_warning ("parse error '%U'", format_unformat_error, i);
5879 errmsg ("missing table-ID");
5883 /* Construct the API message */
5884 M (MPLS_TABLE_ADD_DEL, mp);
5886 mp->mt_table.mt_table_id = ntohl (table_id);
5887 mp->mt_is_add = is_add;
5892 /* Wait for a reply... */
5899 api_mpls_route_add_del (vat_main_t * vam)
5901 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
5902 mpls_label_t local_label = MPLS_LABEL_INVALID;
5903 unformat_input_t *i = vam->input;
5904 vl_api_mpls_route_add_del_t *mp;
5905 vl_api_fib_path_t paths[8];
5909 /* Parse args required to build the message */
5910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5912 if (unformat (i, "%d", &local_label))
5914 else if (unformat (i, "eos"))
5916 else if (unformat (i, "non-eos"))
5918 else if (unformat (i, "del"))
5920 else if (unformat (i, "add"))
5922 else if (unformat (i, "multipath"))
5924 else if (unformat (i, "count %d", &count))
5928 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5931 if (8 == path_count)
5933 errmsg ("max 8 paths");
5939 clib_warning ("parse error '%U'", format_unformat_error, i);
5946 errmsg ("specify a path; via ...");
5950 if (MPLS_LABEL_INVALID == local_label)
5952 errmsg ("missing label");
5958 /* Turn on async mode */
5959 vam->async_mode = 1;
5960 vam->async_errors = 0;
5961 before = vat_time_now (vam);
5964 for (j = 0; j < count; j++)
5966 /* Construct the API message */
5967 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5969 mp->mr_is_add = is_add;
5970 mp->mr_is_multipath = is_multipath;
5972 mp->mr_route.mr_label = local_label;
5973 mp->mr_route.mr_eos = is_eos;
5974 mp->mr_route.mr_table_id = 0;
5975 mp->mr_route.mr_n_paths = path_count;
5977 clib_memcpy (&mp->mr_route.mr_paths, paths,
5978 sizeof (paths[0]) * path_count);
5984 /* If we receive SIGTERM, stop now... */
5989 /* When testing multiple add/del ops, use a control-ping to sync */
5992 vl_api_control_ping_t *mp_ping;
5996 /* Shut off async mode */
5997 vam->async_mode = 0;
5999 MPING (CONTROL_PING, mp_ping);
6002 timeout = vat_time_now (vam) + 1.0;
6003 while (vat_time_now (vam) < timeout)
6004 if (vam->result_ready == 1)
6009 if (vam->retval == -99)
6012 if (vam->async_errors > 0)
6014 errmsg ("%d asynchronous errors", vam->async_errors);
6017 vam->async_errors = 0;
6018 after = vat_time_now (vam);
6020 /* slim chance, but we might have eaten SIGTERM on the first iteration */
6024 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
6025 count, after - before, count / (after - before));
6031 /* Wait for a reply... */
6036 /* Return the good/bad news */
6037 return (vam->retval);
6042 api_mpls_ip_bind_unbind (vat_main_t * vam)
6044 unformat_input_t *i = vam->input;
6045 vl_api_mpls_ip_bind_unbind_t *mp;
6046 u32 ip_table_id = 0;
6048 vl_api_prefix_t pfx;
6050 mpls_label_t local_label = MPLS_LABEL_INVALID;
6053 /* Parse args required to build the message */
6054 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6056 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6058 else if (unformat (i, "%d", &local_label))
6060 else if (unformat (i, "table-id %d", &ip_table_id))
6062 else if (unformat (i, "unbind"))
6064 else if (unformat (i, "bind"))
6068 clib_warning ("parse error '%U'", format_unformat_error, i);
6075 errmsg ("IP prefix not set");
6079 if (MPLS_LABEL_INVALID == local_label)
6081 errmsg ("missing label");
6085 /* Construct the API message */
6086 M (MPLS_IP_BIND_UNBIND, mp);
6088 mp->mb_is_bind = is_bind;
6089 mp->mb_ip_table_id = ntohl (ip_table_id);
6090 mp->mb_mpls_table_id = 0;
6091 mp->mb_label = ntohl (local_label);
6092 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6097 /* Wait for a reply... */
6104 api_sr_mpls_policy_add (vat_main_t * vam)
6106 unformat_input_t *i = vam->input;
6107 vl_api_sr_mpls_policy_add_t *mp;
6113 u32 *segments = NULL;
6116 /* Parse args required to build the message */
6117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6119 if (unformat (i, "bsid %d", &bsid))
6121 else if (unformat (i, "weight %d", &weight))
6123 else if (unformat (i, "spray"))
6125 else if (unformat (i, "next %d", &sid))
6128 vec_add1 (segments, htonl (sid));
6132 clib_warning ("parse error '%U'", format_unformat_error, i);
6139 errmsg ("bsid not set");
6143 if (n_segments == 0)
6145 errmsg ("no sid in segment stack");
6149 /* Construct the API message */
6150 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6152 mp->bsid = htonl (bsid);
6153 mp->weight = htonl (weight);
6154 mp->is_spray = type;
6155 mp->n_segments = n_segments;
6156 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6157 vec_free (segments);
6162 /* Wait for a reply... */
6168 api_sr_mpls_policy_del (vat_main_t * vam)
6170 unformat_input_t *i = vam->input;
6171 vl_api_sr_mpls_policy_del_t *mp;
6175 /* Parse args required to build the message */
6176 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6178 if (unformat (i, "bsid %d", &bsid))
6182 clib_warning ("parse error '%U'", format_unformat_error, i);
6189 errmsg ("bsid not set");
6193 /* Construct the API message */
6194 M (SR_MPLS_POLICY_DEL, mp);
6196 mp->bsid = htonl (bsid);
6201 /* Wait for a reply... */
6207 api_mpls_tunnel_add_del (vat_main_t * vam)
6209 unformat_input_t *i = vam->input;
6210 vl_api_mpls_tunnel_add_del_t *mp;
6212 vl_api_fib_path_t paths[8];
6213 u32 sw_if_index = ~0;
6219 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6221 if (unformat (i, "add"))
6225 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6227 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6229 else if (unformat (i, "l2-only"))
6233 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6236 if (8 == path_count)
6238 errmsg ("max 8 paths");
6244 clib_warning ("parse error '%U'", format_unformat_error, i);
6249 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6251 mp->mt_is_add = is_add;
6252 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6253 mp->mt_tunnel.mt_l2_only = l2_only;
6254 mp->mt_tunnel.mt_is_multicast = 0;
6255 mp->mt_tunnel.mt_n_paths = path_count;
6257 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6258 sizeof (paths[0]) * path_count);
6266 api_sw_interface_set_unnumbered (vat_main_t * vam)
6268 unformat_input_t *i = vam->input;
6269 vl_api_sw_interface_set_unnumbered_t *mp;
6271 u32 unnum_sw_index = ~0;
6273 u8 sw_if_index_set = 0;
6276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6278 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6279 sw_if_index_set = 1;
6280 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6281 sw_if_index_set = 1;
6282 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6284 else if (unformat (i, "del"))
6288 clib_warning ("parse error '%U'", format_unformat_error, i);
6293 if (sw_if_index_set == 0)
6295 errmsg ("missing interface name or sw_if_index");
6299 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6301 mp->sw_if_index = ntohl (sw_if_index);
6302 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6303 mp->is_add = is_add;
6312 api_create_vlan_subif (vat_main_t * vam)
6314 unformat_input_t *i = vam->input;
6315 vl_api_create_vlan_subif_t *mp;
6317 u8 sw_if_index_set = 0;
6322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6324 if (unformat (i, "sw_if_index %d", &sw_if_index))
6325 sw_if_index_set = 1;
6327 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6328 sw_if_index_set = 1;
6329 else if (unformat (i, "vlan %d", &vlan_id))
6333 clib_warning ("parse error '%U'", format_unformat_error, i);
6338 if (sw_if_index_set == 0)
6340 errmsg ("missing interface name or sw_if_index");
6344 if (vlan_id_set == 0)
6346 errmsg ("missing vlan_id");
6349 M (CREATE_VLAN_SUBIF, mp);
6351 mp->sw_if_index = ntohl (sw_if_index);
6352 mp->vlan_id = ntohl (vlan_id);
6359 #define foreach_create_subif_bit \
6366 _(outer_vlan_id_any) \
6367 _(inner_vlan_id_any)
6369 #define foreach_create_subif_flag \
6374 _(4, "exact_match") \
6375 _(5, "default_sub") \
6376 _(6, "outer_vlan_id_any") \
6377 _(7, "inner_vlan_id_any")
6380 api_create_subif (vat_main_t * vam)
6382 unformat_input_t *i = vam->input;
6383 vl_api_create_subif_t *mp;
6385 u8 sw_if_index_set = 0;
6388 u32 __attribute__ ((unused)) no_tags = 0;
6389 u32 __attribute__ ((unused)) one_tag = 0;
6390 u32 __attribute__ ((unused)) two_tags = 0;
6391 u32 __attribute__ ((unused)) dot1ad = 0;
6392 u32 __attribute__ ((unused)) exact_match = 0;
6393 u32 __attribute__ ((unused)) default_sub = 0;
6394 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
6395 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
6397 u16 outer_vlan_id = 0;
6398 u16 inner_vlan_id = 0;
6401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6403 if (unformat (i, "sw_if_index %d", &sw_if_index))
6404 sw_if_index_set = 1;
6406 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6407 sw_if_index_set = 1;
6408 else if (unformat (i, "sub_id %d", &sub_id))
6410 else if (unformat (i, "outer_vlan_id %d", &tmp))
6411 outer_vlan_id = tmp;
6412 else if (unformat (i, "inner_vlan_id %d", &tmp))
6413 inner_vlan_id = tmp;
6415 #define _(a) else if (unformat (i, #a)) a = 1 ;
6416 foreach_create_subif_bit
6420 clib_warning ("parse error '%U'", format_unformat_error, i);
6425 if (sw_if_index_set == 0)
6427 errmsg ("missing interface name or sw_if_index");
6431 if (sub_id_set == 0)
6433 errmsg ("missing sub_id");
6436 M (CREATE_SUBIF, mp);
6438 mp->sw_if_index = ntohl (sw_if_index);
6439 mp->sub_id = ntohl (sub_id);
6441 #define _(a,b) mp->sub_if_flags |= (1 << a);
6442 foreach_create_subif_flag;
6445 mp->outer_vlan_id = ntohs (outer_vlan_id);
6446 mp->inner_vlan_id = ntohs (inner_vlan_id);
6454 api_ip_table_replace_begin (vat_main_t * vam)
6456 unformat_input_t *i = vam->input;
6457 vl_api_ip_table_replace_begin_t *mp;
6462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6464 if (unformat (i, "table %d", &table_id))
6466 else if (unformat (i, "ipv6"))
6470 clib_warning ("parse error '%U'", format_unformat_error, i);
6475 M (IP_TABLE_REPLACE_BEGIN, mp);
6477 mp->table.table_id = ntohl (table_id);
6478 mp->table.is_ip6 = is_ipv6;
6486 api_ip_table_flush (vat_main_t * vam)
6488 unformat_input_t *i = vam->input;
6489 vl_api_ip_table_flush_t *mp;
6494 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6496 if (unformat (i, "table %d", &table_id))
6498 else if (unformat (i, "ipv6"))
6502 clib_warning ("parse error '%U'", format_unformat_error, i);
6507 M (IP_TABLE_FLUSH, mp);
6509 mp->table.table_id = ntohl (table_id);
6510 mp->table.is_ip6 = is_ipv6;
6518 api_ip_table_replace_end (vat_main_t * vam)
6520 unformat_input_t *i = vam->input;
6521 vl_api_ip_table_replace_end_t *mp;
6526 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6528 if (unformat (i, "table %d", &table_id))
6530 else if (unformat (i, "ipv6"))
6534 clib_warning ("parse error '%U'", format_unformat_error, i);
6539 M (IP_TABLE_REPLACE_END, mp);
6541 mp->table.table_id = ntohl (table_id);
6542 mp->table.is_ip6 = is_ipv6;
6550 api_set_ip_flow_hash (vat_main_t * vam)
6552 unformat_input_t *i = vam->input;
6553 vl_api_set_ip_flow_hash_t *mp;
6565 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6567 if (unformat (i, "vrf %d", &vrf_id))
6569 else if (unformat (i, "ipv6"))
6571 else if (unformat (i, "src"))
6573 else if (unformat (i, "dst"))
6575 else if (unformat (i, "sport"))
6577 else if (unformat (i, "dport"))
6579 else if (unformat (i, "proto"))
6581 else if (unformat (i, "reverse"))
6586 clib_warning ("parse error '%U'", format_unformat_error, i);
6591 if (vrf_id_set == 0)
6593 errmsg ("missing vrf id");
6597 M (SET_IP_FLOW_HASH, mp);
6603 mp->reverse = reverse;
6604 mp->vrf_id = ntohl (vrf_id);
6605 mp->is_ipv6 = is_ipv6;
6613 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6615 unformat_input_t *i = vam->input;
6616 vl_api_sw_interface_ip6_enable_disable_t *mp;
6618 u8 sw_if_index_set = 0;
6622 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6624 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6625 sw_if_index_set = 1;
6626 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6627 sw_if_index_set = 1;
6628 else if (unformat (i, "enable"))
6630 else if (unformat (i, "disable"))
6634 clib_warning ("parse error '%U'", format_unformat_error, i);
6639 if (sw_if_index_set == 0)
6641 errmsg ("missing interface name or sw_if_index");
6645 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6647 mp->sw_if_index = ntohl (sw_if_index);
6648 mp->enable = enable;
6657 api_l2_patch_add_del (vat_main_t * vam)
6659 unformat_input_t *i = vam->input;
6660 vl_api_l2_patch_add_del_t *mp;
6662 u8 rx_sw_if_index_set = 0;
6664 u8 tx_sw_if_index_set = 0;
6668 /* Parse args required to build the message */
6669 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6671 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6672 rx_sw_if_index_set = 1;
6673 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6674 tx_sw_if_index_set = 1;
6675 else if (unformat (i, "rx"))
6677 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6679 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6681 rx_sw_if_index_set = 1;
6686 else if (unformat (i, "tx"))
6688 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6690 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6692 tx_sw_if_index_set = 1;
6697 else if (unformat (i, "del"))
6703 if (rx_sw_if_index_set == 0)
6705 errmsg ("missing rx interface name or rx_sw_if_index");
6709 if (tx_sw_if_index_set == 0)
6711 errmsg ("missing tx interface name or tx_sw_if_index");
6715 M (L2_PATCH_ADD_DEL, mp);
6717 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6718 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6719 mp->is_add = is_add;
6727 u8 localsid_addr[16];
6736 api_sr_localsid_add_del (vat_main_t * vam)
6738 unformat_input_t *i = vam->input;
6739 vl_api_sr_localsid_add_del_t *mp;
6742 ip6_address_t localsid;
6746 u32 fib_table = ~(u32) 0;
6747 ip46_address_t nh_addr;
6748 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6750 bool nexthop_set = 0;
6754 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6756 if (unformat (i, "del"))
6758 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6759 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6761 else if (unformat (i, "behavior %u", &behavior));
6762 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6763 else if (unformat (i, "fib-table %u", &fib_table));
6764 else if (unformat (i, "end.psp %u", &behavior));
6769 M (SR_LOCALSID_ADD_DEL, mp);
6771 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6775 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6777 mp->behavior = behavior;
6778 mp->sw_if_index = ntohl (sw_if_index);
6779 mp->fib_table = ntohl (fib_table);
6780 mp->end_psp = end_psp;
6781 mp->is_del = is_del;
6789 api_ioam_enable (vat_main_t * vam)
6791 unformat_input_t *input = vam->input;
6792 vl_api_ioam_enable_t *mp;
6794 int has_trace_option = 0;
6795 int has_pot_option = 0;
6796 int has_seqno_option = 0;
6797 int has_analyse_option = 0;
6800 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6802 if (unformat (input, "trace"))
6803 has_trace_option = 1;
6804 else if (unformat (input, "pot"))
6806 else if (unformat (input, "seqno"))
6807 has_seqno_option = 1;
6808 else if (unformat (input, "analyse"))
6809 has_analyse_option = 1;
6813 M (IOAM_ENABLE, mp);
6814 mp->id = htons (id);
6815 mp->seqno = has_seqno_option;
6816 mp->analyse = has_analyse_option;
6817 mp->pot_enable = has_pot_option;
6818 mp->trace_enable = has_trace_option;
6827 api_ioam_disable (vat_main_t * vam)
6829 vl_api_ioam_disable_t *mp;
6832 M (IOAM_DISABLE, mp);
6838 #define foreach_tcp_proto_field \
6842 #define foreach_udp_proto_field \
6846 #define foreach_ip4_proto_field \
6858 u16 src_port, dst_port;
6861 #if VPP_API_TEST_BUILTIN == 0
6863 unformat_tcp_mask (unformat_input_t * input, va_list * args)
6865 u8 **maskp = va_arg (*args, u8 **);
6867 u8 found_something = 0;
6870 #define _(a) u8 a=0;
6871 foreach_tcp_proto_field;
6874 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6877 #define _(a) else if (unformat (input, #a)) a=1;
6878 foreach_tcp_proto_field
6884 #define _(a) found_something += a;
6885 foreach_tcp_proto_field;
6888 if (found_something == 0)
6891 vec_validate (mask, sizeof (*tcp) - 1);
6893 tcp = (tcp_header_t *) mask;
6895 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
6896 foreach_tcp_proto_field;
6904 unformat_udp_mask (unformat_input_t * input, va_list * args)
6906 u8 **maskp = va_arg (*args, u8 **);
6908 u8 found_something = 0;
6911 #define _(a) u8 a=0;
6912 foreach_udp_proto_field;
6915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6918 #define _(a) else if (unformat (input, #a)) a=1;
6919 foreach_udp_proto_field
6925 #define _(a) found_something += a;
6926 foreach_udp_proto_field;
6929 if (found_something == 0)
6932 vec_validate (mask, sizeof (*udp) - 1);
6934 udp = (udp_header_t *) mask;
6936 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
6937 foreach_udp_proto_field;
6945 unformat_l4_mask (unformat_input_t * input, va_list * args)
6947 u8 **maskp = va_arg (*args, u8 **);
6948 u16 src_port = 0, dst_port = 0;
6949 tcpudp_header_t *tcpudp;
6951 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6953 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
6955 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
6957 else if (unformat (input, "src_port"))
6959 else if (unformat (input, "dst_port"))
6965 if (!src_port && !dst_port)
6969 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
6971 tcpudp = (tcpudp_header_t *) mask;
6972 tcpudp->src_port = src_port;
6973 tcpudp->dst_port = dst_port;
6981 unformat_ip4_mask (unformat_input_t * input, va_list * args)
6983 u8 **maskp = va_arg (*args, u8 **);
6985 u8 found_something = 0;
6988 #define _(a) u8 a=0;
6989 foreach_ip4_proto_field;
6995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6997 if (unformat (input, "version"))
6999 else if (unformat (input, "hdr_length"))
7001 else if (unformat (input, "src"))
7003 else if (unformat (input, "dst"))
7005 else if (unformat (input, "proto"))
7008 #define _(a) else if (unformat (input, #a)) a=1;
7009 foreach_ip4_proto_field
7015 #define _(a) found_something += a;
7016 foreach_ip4_proto_field;
7019 if (found_something == 0)
7022 vec_validate (mask, sizeof (*ip) - 1);
7024 ip = (ip4_header_t *) mask;
7026 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7027 foreach_ip4_proto_field;
7030 ip->ip_version_and_header_length = 0;
7033 ip->ip_version_and_header_length |= 0xF0;
7036 ip->ip_version_and_header_length |= 0x0F;
7042 #define foreach_ip6_proto_field \
7050 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7052 u8 **maskp = va_arg (*args, u8 **);
7054 u8 found_something = 0;
7056 u32 ip_version_traffic_class_and_flow_label;
7058 #define _(a) u8 a=0;
7059 foreach_ip6_proto_field;
7062 u8 traffic_class = 0;
7065 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7067 if (unformat (input, "version"))
7069 else if (unformat (input, "traffic-class"))
7071 else if (unformat (input, "flow-label"))
7073 else if (unformat (input, "src"))
7075 else if (unformat (input, "dst"))
7077 else if (unformat (input, "proto"))
7080 #define _(a) else if (unformat (input, #a)) a=1;
7081 foreach_ip6_proto_field
7087 #define _(a) found_something += a;
7088 foreach_ip6_proto_field;
7091 if (found_something == 0)
7094 vec_validate (mask, sizeof (*ip) - 1);
7096 ip = (ip6_header_t *) mask;
7098 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7099 foreach_ip6_proto_field;
7102 ip_version_traffic_class_and_flow_label = 0;
7105 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7108 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7111 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7113 ip->ip_version_traffic_class_and_flow_label =
7114 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7121 unformat_l3_mask (unformat_input_t * input, va_list * args)
7123 u8 **maskp = va_arg (*args, u8 **);
7125 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7127 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7129 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7138 unformat_l2_mask (unformat_input_t * input, va_list * args)
7140 u8 **maskp = va_arg (*args, u8 **);
7155 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7157 if (unformat (input, "src"))
7159 else if (unformat (input, "dst"))
7161 else if (unformat (input, "proto"))
7163 else if (unformat (input, "tag1"))
7165 else if (unformat (input, "tag2"))
7167 else if (unformat (input, "ignore-tag1"))
7169 else if (unformat (input, "ignore-tag2"))
7171 else if (unformat (input, "cos1"))
7173 else if (unformat (input, "cos2"))
7175 else if (unformat (input, "dot1q"))
7177 else if (unformat (input, "dot1ad"))
7182 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7183 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7186 if (tag1 || ignore_tag1 || cos1 || dot1q)
7188 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7191 vec_validate (mask, len - 1);
7194 clib_memset (mask, 0xff, 6);
7197 clib_memset (mask + 6, 0xff, 6);
7201 /* inner vlan tag */
7210 mask[21] = mask[20] = 0xff;
7231 mask[16] = mask[17] = 0xff;
7241 mask[12] = mask[13] = 0xff;
7248 unformat_classify_mask (unformat_input_t * input, va_list * args)
7250 u8 **maskp = va_arg (*args, u8 **);
7251 u32 *skipp = va_arg (*args, u32 *);
7252 u32 *matchp = va_arg (*args, u32 *);
7260 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7262 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7264 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7266 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7268 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7282 if (mask || l2 || l3 || l4)
7286 /* "With a free Ethernet header in every package" */
7288 vec_validate (l2, 13);
7292 vec_append (mask, l3);
7297 vec_append (mask, l4);
7302 /* Scan forward looking for the first significant mask octet */
7303 for (i = 0; i < vec_len (mask); i++)
7307 /* compute (skip, match) params */
7308 *skipp = i / sizeof (u32x4);
7309 vec_delete (mask, *skipp * sizeof (u32x4), 0);
7311 /* Pad mask to an even multiple of the vector size */
7312 while (vec_len (mask) % sizeof (u32x4))
7315 match = vec_len (mask) / sizeof (u32x4);
7317 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
7319 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
7320 if (*tmp || *(tmp + 1))
7325 clib_warning ("BUG: match 0");
7327 _vec_len (mask) = match * sizeof (u32x4);
7337 #endif /* VPP_API_TEST_BUILTIN */
7339 #define foreach_l2_next \
7341 _(ethernet, ETHERNET_INPUT) \
7346 unformat_l2_next_index (unformat_input_t * input, va_list * args)
7348 u32 *miss_next_indexp = va_arg (*args, u32 *);
7353 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
7357 if (unformat (input, "%d", &tmp))
7366 *miss_next_indexp = next_index;
7370 #define foreach_ip_next \
7376 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
7378 u32 *miss_next_indexp = va_arg (*args, u32 *);
7383 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7387 if (unformat (input, "%d", &tmp))
7396 *miss_next_indexp = next_index;
7400 #define foreach_acl_next \
7404 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
7406 u32 *miss_next_indexp = va_arg (*args, u32 *);
7411 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7415 if (unformat (input, "permit"))
7420 else if (unformat (input, "%d", &tmp))
7429 *miss_next_indexp = next_index;
7434 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7436 u32 *r = va_arg (*args, u32 *);
7438 if (unformat (input, "conform-color"))
7439 *r = POLICE_CONFORM;
7440 else if (unformat (input, "exceed-color"))
7448 #if VPP_API_TEST_BUILTIN == 0
7450 unformat_l4_match (unformat_input_t * input, va_list * args)
7452 u8 **matchp = va_arg (*args, u8 **);
7454 u8 *proto_header = 0;
7460 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7462 if (unformat (input, "src_port %d", &src_port))
7464 else if (unformat (input, "dst_port %d", &dst_port))
7470 h.src_port = clib_host_to_net_u16 (src_port);
7471 h.dst_port = clib_host_to_net_u16 (dst_port);
7472 vec_validate (proto_header, sizeof (h) - 1);
7473 memcpy (proto_header, &h, sizeof (h));
7475 *matchp = proto_header;
7481 unformat_ip4_match (unformat_input_t * input, va_list * args)
7483 u8 **matchp = va_arg (*args, u8 **);
7490 int src = 0, dst = 0;
7491 ip4_address_t src_val, dst_val;
7498 int fragment_id = 0;
7499 u32 fragment_id_val;
7505 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7507 if (unformat (input, "version %d", &version_val))
7509 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7511 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7513 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7515 else if (unformat (input, "proto %d", &proto_val))
7517 else if (unformat (input, "tos %d", &tos_val))
7519 else if (unformat (input, "length %d", &length_val))
7521 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7523 else if (unformat (input, "ttl %d", &ttl_val))
7525 else if (unformat (input, "checksum %d", &checksum_val))
7531 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7532 + ttl + checksum == 0)
7536 * Aligned because we use the real comparison functions
7538 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7540 ip = (ip4_header_t *) match;
7542 /* These are realistically matched in practice */
7544 ip->src_address.as_u32 = src_val.as_u32;
7547 ip->dst_address.as_u32 = dst_val.as_u32;
7550 ip->protocol = proto_val;
7553 /* These are not, but they're included for completeness */
7555 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7558 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7564 ip->length = clib_host_to_net_u16 (length_val);
7570 ip->checksum = clib_host_to_net_u16 (checksum_val);
7577 unformat_ip6_match (unformat_input_t * input, va_list * args)
7579 u8 **matchp = va_arg (*args, u8 **);
7584 u8 traffic_class = 0;
7585 u32 traffic_class_val = 0;
7588 int src = 0, dst = 0;
7589 ip6_address_t src_val, dst_val;
7592 int payload_length = 0;
7593 u32 payload_length_val;
7596 u32 ip_version_traffic_class_and_flow_label;
7598 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7600 if (unformat (input, "version %d", &version_val))
7602 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7604 else if (unformat (input, "flow_label %d", &flow_label_val))
7606 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7608 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7610 else if (unformat (input, "proto %d", &proto_val))
7612 else if (unformat (input, "payload_length %d", &payload_length_val))
7614 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7620 if (version + traffic_class + flow_label + src + dst + proto +
7621 payload_length + hop_limit == 0)
7625 * Aligned because we use the real comparison functions
7627 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7629 ip = (ip6_header_t *) match;
7632 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7635 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7638 ip->protocol = proto_val;
7640 ip_version_traffic_class_and_flow_label = 0;
7643 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7646 ip_version_traffic_class_and_flow_label |=
7647 (traffic_class_val & 0xFF) << 20;
7650 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7652 ip->ip_version_traffic_class_and_flow_label =
7653 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7656 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7659 ip->hop_limit = hop_limit_val;
7666 unformat_l3_match (unformat_input_t * input, va_list * args)
7668 u8 **matchp = va_arg (*args, u8 **);
7670 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7672 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7674 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7683 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7685 u8 *tagp = va_arg (*args, u8 *);
7688 if (unformat (input, "%d", &tag))
7690 tagp[0] = (tag >> 8) & 0x0F;
7691 tagp[1] = tag & 0xFF;
7699 unformat_l2_match (unformat_input_t * input, va_list * args)
7701 u8 **matchp = va_arg (*args, u8 **);
7721 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7723 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7726 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7728 else if (unformat (input, "proto %U",
7729 unformat_ethernet_type_host_byte_order, &proto_val))
7731 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7733 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7735 else if (unformat (input, "ignore-tag1"))
7737 else if (unformat (input, "ignore-tag2"))
7739 else if (unformat (input, "cos1 %d", &cos1_val))
7741 else if (unformat (input, "cos2 %d", &cos2_val))
7746 if ((src + dst + proto + tag1 + tag2 +
7747 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7750 if (tag1 || ignore_tag1 || cos1)
7752 if (tag2 || ignore_tag2 || cos2)
7755 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7758 clib_memcpy (match, dst_val, 6);
7761 clib_memcpy (match + 6, src_val, 6);
7765 /* inner vlan tag */
7766 match[19] = tag2_val[1];
7767 match[18] = tag2_val[0];
7769 match[18] |= (cos2_val & 0x7) << 5;
7772 match[21] = proto_val & 0xff;
7773 match[20] = proto_val >> 8;
7777 match[15] = tag1_val[1];
7778 match[14] = tag1_val[0];
7781 match[14] |= (cos1_val & 0x7) << 5;
7787 match[15] = tag1_val[1];
7788 match[14] = tag1_val[0];
7791 match[17] = proto_val & 0xff;
7792 match[16] = proto_val >> 8;
7795 match[14] |= (cos1_val & 0x7) << 5;
7801 match[18] |= (cos2_val & 0x7) << 5;
7803 match[14] |= (cos1_val & 0x7) << 5;
7806 match[13] = proto_val & 0xff;
7807 match[12] = proto_val >> 8;
7815 unformat_qos_source (unformat_input_t * input, va_list * args)
7817 int *qs = va_arg (*args, int *);
7819 if (unformat (input, "ip"))
7820 *qs = QOS_SOURCE_IP;
7821 else if (unformat (input, "mpls"))
7822 *qs = QOS_SOURCE_MPLS;
7823 else if (unformat (input, "ext"))
7824 *qs = QOS_SOURCE_EXT;
7825 else if (unformat (input, "vlan"))
7826 *qs = QOS_SOURCE_VLAN;
7835 api_unformat_classify_match (unformat_input_t * input, va_list * args)
7837 u8 **matchp = va_arg (*args, u8 **);
7838 u32 skip_n_vectors = va_arg (*args, u32);
7839 u32 match_n_vectors = va_arg (*args, u32);
7846 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7848 if (unformat (input, "hex %U", unformat_hex_string, &match))
7850 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7852 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7854 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
7868 if (match || l2 || l3 || l4)
7872 /* "Win a free Ethernet header in every packet" */
7874 vec_validate_aligned (l2, 13, sizeof (u32x4));
7878 vec_append_aligned (match, l3, sizeof (u32x4));
7883 vec_append_aligned (match, l4, sizeof (u32x4));
7888 /* Make sure the vector is big enough even if key is all 0's */
7889 vec_validate_aligned
7890 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
7893 /* Set size, include skipped vectors */
7894 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
7905 api_get_node_index (vat_main_t * vam)
7907 unformat_input_t *i = vam->input;
7908 vl_api_get_node_index_t *mp;
7912 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7914 if (unformat (i, "node %s", &name))
7921 errmsg ("node name required");
7924 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7926 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7930 M (GET_NODE_INDEX, mp);
7931 clib_memcpy (mp->node_name, name, vec_len (name));
7940 api_get_next_index (vat_main_t * vam)
7942 unformat_input_t *i = vam->input;
7943 vl_api_get_next_index_t *mp;
7944 u8 *node_name = 0, *next_node_name = 0;
7947 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7949 if (unformat (i, "node-name %s", &node_name))
7951 else if (unformat (i, "next-node-name %s", &next_node_name))
7957 errmsg ("node name required");
7960 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
7962 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7966 if (next_node_name == 0)
7968 errmsg ("next node name required");
7971 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
7973 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
7977 M (GET_NEXT_INDEX, mp);
7978 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
7979 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
7980 vec_free (node_name);
7981 vec_free (next_node_name);
7989 api_add_node_next (vat_main_t * vam)
7991 unformat_input_t *i = vam->input;
7992 vl_api_add_node_next_t *mp;
7997 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7999 if (unformat (i, "node %s", &name))
8001 else if (unformat (i, "next %s", &next))
8008 errmsg ("node name required");
8011 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
8013 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
8018 errmsg ("next node required");
8021 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
8023 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
8027 M (ADD_NODE_NEXT, mp);
8028 clib_memcpy (mp->node_name, name, vec_len (name));
8029 clib_memcpy (mp->next_name, next, vec_len (next));
8038 static void vl_api_sw_interface_tap_v2_details_t_handler
8039 (vl_api_sw_interface_tap_v2_details_t * mp)
8041 vat_main_t *vam = &vat_main;
8044 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
8045 mp->host_ip4_prefix.len);
8047 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
8048 mp->host_ip6_prefix.len);
8051 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
8052 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
8053 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8054 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
8055 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
8061 static void vl_api_sw_interface_tap_v2_details_t_handler_json
8062 (vl_api_sw_interface_tap_v2_details_t * mp)
8064 vat_main_t *vam = &vat_main;
8065 vat_json_node_t *node = NULL;
8067 if (VAT_JSON_ARRAY != vam->json_tree.type)
8069 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8070 vat_json_init_array (&vam->json_tree);
8072 node = vat_json_array_add (&vam->json_tree);
8074 vat_json_init_object (node);
8075 vat_json_object_add_uint (node, "id", ntohl (mp->id));
8076 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8077 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
8078 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
8079 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8080 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8081 vat_json_object_add_string_copy (node, "host_mac_addr",
8082 format (0, "%U", format_ethernet_address,
8083 &mp->host_mac_addr));
8084 vat_json_object_add_string_copy (node, "host_namespace",
8085 mp->host_namespace);
8086 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
8087 vat_json_object_add_string_copy (node, "host_ip4_addr",
8088 format (0, "%U/%d", format_ip4_address,
8089 mp->host_ip4_prefix.address,
8090 mp->host_ip4_prefix.len));
8091 vat_json_object_add_string_copy (node, "host_ip6_prefix",
8092 format (0, "%U/%d", format_ip6_address,
8093 mp->host_ip6_prefix.address,
8094 mp->host_ip6_prefix.len));
8099 api_sw_interface_tap_v2_dump (vat_main_t * vam)
8101 vl_api_sw_interface_tap_v2_dump_t *mp;
8102 vl_api_control_ping_t *mp_ping;
8106 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
8107 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
8108 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
8111 /* Get list of tap interfaces */
8112 M (SW_INTERFACE_TAP_V2_DUMP, mp);
8115 /* Use a control ping for synchronization */
8116 MPING (CONTROL_PING, mp_ping);
8123 static void vl_api_sw_interface_virtio_pci_details_t_handler
8124 (vl_api_sw_interface_virtio_pci_details_t * mp)
8126 vat_main_t *vam = &vat_main;
8141 addr.domain = ntohs (mp->pci_addr.domain);
8142 addr.bus = mp->pci_addr.bus;
8143 addr.slot = mp->pci_addr.slot;
8144 addr.function = mp->pci_addr.function;
8146 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
8147 addr.slot, addr.function);
8150 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
8151 pci_addr, ntohl (mp->sw_if_index),
8152 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8153 format_ethernet_address, mp->mac_addr,
8154 clib_net_to_host_u64 (mp->features));
8155 vec_free (pci_addr);
8158 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
8159 (vl_api_sw_interface_virtio_pci_details_t * mp)
8161 vat_main_t *vam = &vat_main;
8162 vat_json_node_t *node = NULL;
8163 vlib_pci_addr_t pci_addr;
8165 if (VAT_JSON_ARRAY != vam->json_tree.type)
8167 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8168 vat_json_init_array (&vam->json_tree);
8170 node = vat_json_array_add (&vam->json_tree);
8172 pci_addr.domain = ntohs (mp->pci_addr.domain);
8173 pci_addr.bus = mp->pci_addr.bus;
8174 pci_addr.slot = mp->pci_addr.slot;
8175 pci_addr.function = mp->pci_addr.function;
8177 vat_json_init_object (node);
8178 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
8179 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8180 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8181 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8182 vat_json_object_add_uint (node, "features",
8183 clib_net_to_host_u64 (mp->features));
8184 vat_json_object_add_string_copy (node, "mac_addr",
8185 format (0, "%U", format_ethernet_address,
8190 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
8192 vl_api_sw_interface_virtio_pci_dump_t *mp;
8193 vl_api_control_ping_t *mp_ping;
8197 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
8198 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
8199 "mac_addr", "features");
8201 /* Get list of tap interfaces */
8202 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
8205 /* Use a control ping for synchronization */
8206 MPING (CONTROL_PING, mp_ping);
8214 api_l2_fib_clear_table (vat_main_t * vam)
8216 // unformat_input_t * i = vam->input;
8217 vl_api_l2_fib_clear_table_t *mp;
8220 M (L2_FIB_CLEAR_TABLE, mp);
8228 api_l2_interface_efp_filter (vat_main_t * vam)
8230 unformat_input_t *i = vam->input;
8231 vl_api_l2_interface_efp_filter_t *mp;
8234 u8 sw_if_index_set = 0;
8237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8239 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8240 sw_if_index_set = 1;
8241 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8242 sw_if_index_set = 1;
8243 else if (unformat (i, "enable"))
8245 else if (unformat (i, "disable"))
8249 clib_warning ("parse error '%U'", format_unformat_error, i);
8254 if (sw_if_index_set == 0)
8256 errmsg ("missing sw_if_index");
8260 M (L2_INTERFACE_EFP_FILTER, mp);
8262 mp->sw_if_index = ntohl (sw_if_index);
8263 mp->enable_disable = enable;
8270 #define foreach_vtr_op \
8271 _("disable", L2_VTR_DISABLED) \
8272 _("push-1", L2_VTR_PUSH_1) \
8273 _("push-2", L2_VTR_PUSH_2) \
8274 _("pop-1", L2_VTR_POP_1) \
8275 _("pop-2", L2_VTR_POP_2) \
8276 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8277 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8278 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8279 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8282 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8284 unformat_input_t *i = vam->input;
8285 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8287 u8 sw_if_index_set = 0;
8295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8297 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8298 sw_if_index_set = 1;
8299 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8300 sw_if_index_set = 1;
8301 else if (unformat (i, "vtr_op %d", &vtr_op))
8303 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8306 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8308 else if (unformat (i, "tag1 %d", &tag1))
8310 else if (unformat (i, "tag2 %d", &tag2))
8314 clib_warning ("parse error '%U'", format_unformat_error, i);
8319 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
8321 errmsg ("missing vtr operation or sw_if_index");
8325 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
8326 mp->sw_if_index = ntohl (sw_if_index);
8327 mp->vtr_op = ntohl (vtr_op);
8328 mp->push_dot1q = ntohl (push_dot1q);
8329 mp->tag1 = ntohl (tag1);
8330 mp->tag2 = ntohl (tag2);
8338 api_create_vhost_user_if (vat_main_t * vam)
8340 unformat_input_t *i = vam->input;
8341 vl_api_create_vhost_user_if_t *mp;
8344 u8 file_name_set = 0;
8345 u32 custom_dev_instance = ~0;
8347 u8 use_custom_mac = 0;
8348 u8 disable_mrg_rxbuf = 0;
8349 u8 disable_indirect_desc = 0;
8352 u8 enable_packed = 0;
8355 /* Shut up coverity */
8356 clib_memset (hwaddr, 0, sizeof (hwaddr));
8358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8360 if (unformat (i, "socket %s", &file_name))
8364 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8366 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8368 else if (unformat (i, "server"))
8370 else if (unformat (i, "disable_mrg_rxbuf"))
8371 disable_mrg_rxbuf = 1;
8372 else if (unformat (i, "disable_indirect_desc"))
8373 disable_indirect_desc = 1;
8374 else if (unformat (i, "gso"))
8376 else if (unformat (i, "packed"))
8378 else if (unformat (i, "tag %s", &tag))
8384 if (file_name_set == 0)
8386 errmsg ("missing socket file name");
8390 if (vec_len (file_name) > 255)
8392 errmsg ("socket file name too long");
8395 vec_add1 (file_name, 0);
8397 M (CREATE_VHOST_USER_IF, mp);
8399 mp->is_server = is_server;
8400 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8401 mp->disable_indirect_desc = disable_indirect_desc;
8402 mp->enable_gso = enable_gso;
8403 mp->enable_packed = enable_packed;
8404 mp->custom_dev_instance = ntohl (custom_dev_instance);
8405 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8406 vec_free (file_name);
8407 if (custom_dev_instance != ~0)
8410 mp->use_custom_mac = use_custom_mac;
8411 clib_memcpy (mp->mac_address, hwaddr, 6);
8413 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8422 api_modify_vhost_user_if (vat_main_t * vam)
8424 unformat_input_t *i = vam->input;
8425 vl_api_modify_vhost_user_if_t *mp;
8428 u8 file_name_set = 0;
8429 u32 custom_dev_instance = ~0;
8430 u8 sw_if_index_set = 0;
8431 u32 sw_if_index = (u32) ~ 0;
8433 u8 enable_packed = 0;
8436 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8438 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8439 sw_if_index_set = 1;
8440 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8441 sw_if_index_set = 1;
8442 else if (unformat (i, "socket %s", &file_name))
8446 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8448 else if (unformat (i, "server"))
8450 else if (unformat (i, "gso"))
8452 else if (unformat (i, "packed"))
8458 if (sw_if_index_set == 0)
8460 errmsg ("missing sw_if_index or interface name");
8464 if (file_name_set == 0)
8466 errmsg ("missing socket file name");
8470 if (vec_len (file_name) > 255)
8472 errmsg ("socket file name too long");
8475 vec_add1 (file_name, 0);
8477 M (MODIFY_VHOST_USER_IF, mp);
8479 mp->sw_if_index = ntohl (sw_if_index);
8480 mp->is_server = is_server;
8481 mp->enable_gso = enable_gso;
8482 mp->enable_packed = enable_packed;
8483 mp->custom_dev_instance = ntohl (custom_dev_instance);
8484 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8485 vec_free (file_name);
8486 if (custom_dev_instance != ~0)
8495 api_create_vhost_user_if_v2 (vat_main_t * vam)
8497 unformat_input_t *i = vam->input;
8498 vl_api_create_vhost_user_if_v2_t *mp;
8501 u8 file_name_set = 0;
8502 u32 custom_dev_instance = ~0;
8504 u8 use_custom_mac = 0;
8505 u8 disable_mrg_rxbuf = 0;
8506 u8 disable_indirect_desc = 0;
8509 u8 enable_packed = 0;
8510 u8 enable_event_idx = 0;
8513 /* Shut up coverity */
8514 clib_memset (hwaddr, 0, sizeof (hwaddr));
8516 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8518 if (unformat (i, "socket %s", &file_name))
8522 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8524 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8526 else if (unformat (i, "server"))
8528 else if (unformat (i, "disable_mrg_rxbuf"))
8529 disable_mrg_rxbuf = 1;
8530 else if (unformat (i, "disable_indirect_desc"))
8531 disable_indirect_desc = 1;
8532 else if (unformat (i, "gso"))
8534 else if (unformat (i, "packed"))
8536 else if (unformat (i, "event-idx"))
8537 enable_event_idx = 1;
8538 else if (unformat (i, "tag %s", &tag))
8544 if (file_name_set == 0)
8546 errmsg ("missing socket file name");
8550 if (vec_len (file_name) > 255)
8552 errmsg ("socket file name too long");
8555 vec_add1 (file_name, 0);
8557 M (CREATE_VHOST_USER_IF_V2, mp);
8559 mp->is_server = is_server;
8560 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8561 mp->disable_indirect_desc = disable_indirect_desc;
8562 mp->enable_gso = enable_gso;
8563 mp->enable_packed = enable_packed;
8564 mp->enable_event_idx = enable_event_idx;
8565 mp->custom_dev_instance = ntohl (custom_dev_instance);
8566 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8567 vec_free (file_name);
8568 if (custom_dev_instance != ~0)
8571 mp->use_custom_mac = use_custom_mac;
8572 clib_memcpy (mp->mac_address, hwaddr, 6);
8574 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8583 api_modify_vhost_user_if_v2 (vat_main_t * vam)
8585 unformat_input_t *i = vam->input;
8586 vl_api_modify_vhost_user_if_v2_t *mp;
8589 u8 file_name_set = 0;
8590 u32 custom_dev_instance = ~0;
8591 u8 sw_if_index_set = 0;
8592 u32 sw_if_index = (u32) ~ 0;
8594 u8 enable_packed = 0;
8595 u8 enable_event_idx = 0;
8598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8600 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8601 sw_if_index_set = 1;
8602 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8603 sw_if_index_set = 1;
8604 else if (unformat (i, "socket %s", &file_name))
8608 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8610 else if (unformat (i, "server"))
8612 else if (unformat (i, "gso"))
8614 else if (unformat (i, "packed"))
8616 else if (unformat (i, "event-idx"))
8617 enable_event_idx = 1;
8622 if (sw_if_index_set == 0)
8624 errmsg ("missing sw_if_index or interface name");
8628 if (file_name_set == 0)
8630 errmsg ("missing socket file name");
8634 if (vec_len (file_name) > 255)
8636 errmsg ("socket file name too long");
8639 vec_add1 (file_name, 0);
8641 M (MODIFY_VHOST_USER_IF_V2, mp);
8643 mp->sw_if_index = ntohl (sw_if_index);
8644 mp->is_server = is_server;
8645 mp->enable_gso = enable_gso;
8646 mp->enable_packed = enable_packed;
8647 mp->enable_event_idx = enable_event_idx;
8648 mp->custom_dev_instance = ntohl (custom_dev_instance);
8649 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8650 vec_free (file_name);
8651 if (custom_dev_instance != ~0)
8660 api_delete_vhost_user_if (vat_main_t * vam)
8662 unformat_input_t *i = vam->input;
8663 vl_api_delete_vhost_user_if_t *mp;
8664 u32 sw_if_index = ~0;
8665 u8 sw_if_index_set = 0;
8668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8670 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8671 sw_if_index_set = 1;
8672 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8673 sw_if_index_set = 1;
8678 if (sw_if_index_set == 0)
8680 errmsg ("missing sw_if_index or interface name");
8685 M (DELETE_VHOST_USER_IF, mp);
8687 mp->sw_if_index = ntohl (sw_if_index);
8694 static void vl_api_sw_interface_vhost_user_details_t_handler
8695 (vl_api_sw_interface_vhost_user_details_t * mp)
8697 vat_main_t *vam = &vat_main;
8701 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
8702 clib_net_to_host_u32
8703 (mp->features_last_32) <<
8706 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
8707 (char *) mp->interface_name, ntohl (mp->sw_if_index),
8708 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
8709 ntohl (mp->num_regions), (char *) mp->sock_filename);
8710 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
8713 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8714 (vl_api_sw_interface_vhost_user_details_t * mp)
8716 vat_main_t *vam = &vat_main;
8717 vat_json_node_t *node = NULL;
8719 if (VAT_JSON_ARRAY != vam->json_tree.type)
8721 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8722 vat_json_init_array (&vam->json_tree);
8724 node = vat_json_array_add (&vam->json_tree);
8726 vat_json_init_object (node);
8727 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8728 vat_json_object_add_string_copy (node, "interface_name",
8729 mp->interface_name);
8730 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
8731 ntohl (mp->virtio_net_hdr_sz));
8732 vat_json_object_add_uint (node, "features_first_32",
8733 clib_net_to_host_u32 (mp->features_first_32));
8734 vat_json_object_add_uint (node, "features_last_32",
8735 clib_net_to_host_u32 (mp->features_last_32));
8736 vat_json_object_add_uint (node, "is_server", mp->is_server);
8737 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
8738 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
8739 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
8743 api_sw_interface_vhost_user_dump (vat_main_t * vam)
8745 unformat_input_t *i = vam->input;
8746 vl_api_sw_interface_vhost_user_dump_t *mp;
8747 vl_api_control_ping_t *mp_ping;
8749 u32 sw_if_index = ~0;
8751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8753 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8761 print (vam->ofp, "Interface name idx hdr_sz features "
8762 "server regions filename");
8764 /* Get list of vhost-user interfaces */
8765 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
8766 mp->sw_if_index = ntohl (sw_if_index);
8769 /* Use a control ping for synchronization */
8770 MPING (CONTROL_PING, mp_ping);
8778 api_show_version (vat_main_t * vam)
8780 vl_api_show_version_t *mp;
8783 M (SHOW_VERSION, mp);
8790 static void vl_api_l2_fib_table_details_t_handler
8791 (vl_api_l2_fib_table_details_t * mp)
8793 vat_main_t *vam = &vat_main;
8795 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8797 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
8798 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
8802 static void vl_api_l2_fib_table_details_t_handler_json
8803 (vl_api_l2_fib_table_details_t * mp)
8805 vat_main_t *vam = &vat_main;
8806 vat_json_node_t *node = NULL;
8808 if (VAT_JSON_ARRAY != vam->json_tree.type)
8810 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8811 vat_json_init_array (&vam->json_tree);
8813 node = vat_json_array_add (&vam->json_tree);
8815 vat_json_init_object (node);
8816 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
8817 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
8818 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8819 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
8820 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
8821 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
8825 api_l2_fib_table_dump (vat_main_t * vam)
8827 unformat_input_t *i = vam->input;
8828 vl_api_l2_fib_table_dump_t *mp;
8829 vl_api_control_ping_t *mp_ping;
8834 /* Parse args required to build the message */
8835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8837 if (unformat (i, "bd_id %d", &bd_id))
8845 errmsg ("missing bridge domain");
8849 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
8851 /* Get list of l2 fib entries */
8852 M (L2_FIB_TABLE_DUMP, mp);
8854 mp->bd_id = ntohl (bd_id);
8857 /* Use a control ping for synchronization */
8858 MPING (CONTROL_PING, mp_ping);
8867 api_interface_name_renumber (vat_main_t * vam)
8869 unformat_input_t *line_input = vam->input;
8870 vl_api_interface_name_renumber_t *mp;
8871 u32 sw_if_index = ~0;
8872 u32 new_show_dev_instance = ~0;
8875 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8877 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
8880 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8882 else if (unformat (line_input, "new_show_dev_instance %d",
8883 &new_show_dev_instance))
8889 if (sw_if_index == ~0)
8891 errmsg ("missing interface name or sw_if_index");
8895 if (new_show_dev_instance == ~0)
8897 errmsg ("missing new_show_dev_instance");
8901 M (INTERFACE_NAME_RENUMBER, mp);
8903 mp->sw_if_index = ntohl (sw_if_index);
8904 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8912 api_want_l2_macs_events (vat_main_t * vam)
8914 unformat_input_t *line_input = vam->input;
8915 vl_api_want_l2_macs_events_t *mp;
8916 u8 enable_disable = 1;
8918 u32 max_macs_in_event = 0;
8919 u32 learn_limit = 0;
8922 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8924 if (unformat (line_input, "learn-limit %d", &learn_limit))
8926 else if (unformat (line_input, "scan-delay %d", &scan_delay))
8928 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
8930 else if (unformat (line_input, "disable"))
8936 M (WANT_L2_MACS_EVENTS, mp);
8937 mp->enable_disable = enable_disable;
8938 mp->pid = htonl (getpid ());
8939 mp->learn_limit = htonl (learn_limit);
8940 mp->scan_delay = (u8) scan_delay;
8941 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
8948 api_ip_address_dump (vat_main_t * vam)
8950 unformat_input_t *i = vam->input;
8951 vl_api_ip_address_dump_t *mp;
8952 vl_api_control_ping_t *mp_ping;
8953 u32 sw_if_index = ~0;
8954 u8 sw_if_index_set = 0;
8959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8961 if (unformat (i, "sw_if_index %d", &sw_if_index))
8962 sw_if_index_set = 1;
8964 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8965 sw_if_index_set = 1;
8966 else if (unformat (i, "ipv4"))
8968 else if (unformat (i, "ipv6"))
8974 if (ipv4_set && ipv6_set)
8976 errmsg ("ipv4 and ipv6 flags cannot be both set");
8980 if ((!ipv4_set) && (!ipv6_set))
8982 errmsg ("no ipv4 nor ipv6 flag set");
8986 if (sw_if_index_set == 0)
8988 errmsg ("missing interface name or sw_if_index");
8992 vam->current_sw_if_index = sw_if_index;
8993 vam->is_ipv6 = ipv6_set;
8995 M (IP_ADDRESS_DUMP, mp);
8996 mp->sw_if_index = ntohl (sw_if_index);
8997 mp->is_ipv6 = ipv6_set;
9000 /* Use a control ping for synchronization */
9001 MPING (CONTROL_PING, mp_ping);
9009 api_ip_dump (vat_main_t * vam)
9011 vl_api_ip_dump_t *mp;
9012 vl_api_control_ping_t *mp_ping;
9013 unformat_input_t *in = vam->input;
9020 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
9022 if (unformat (in, "ipv4"))
9024 else if (unformat (in, "ipv6"))
9030 if (ipv4_set && ipv6_set)
9032 errmsg ("ipv4 and ipv6 flags cannot be both set");
9036 if ((!ipv4_set) && (!ipv6_set))
9038 errmsg ("no ipv4 nor ipv6 flag set");
9043 vam->is_ipv6 = is_ipv6;
9046 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
9048 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9050 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
9053 mp->is_ipv6 = ipv6_set;
9056 /* Use a control ping for synchronization */
9057 MPING (CONTROL_PING, mp_ping);
9065 api_ipsec_spd_add_del (vat_main_t * vam)
9067 unformat_input_t *i = vam->input;
9068 vl_api_ipsec_spd_add_del_t *mp;
9073 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9075 if (unformat (i, "spd_id %d", &spd_id))
9077 else if (unformat (i, "del"))
9081 clib_warning ("parse error '%U'", format_unformat_error, i);
9087 errmsg ("spd_id must be set");
9091 M (IPSEC_SPD_ADD_DEL, mp);
9093 mp->spd_id = ntohl (spd_id);
9094 mp->is_add = is_add;
9102 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9104 unformat_input_t *i = vam->input;
9105 vl_api_ipsec_interface_add_del_spd_t *mp;
9107 u8 sw_if_index_set = 0;
9108 u32 spd_id = (u32) ~ 0;
9112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9114 if (unformat (i, "del"))
9116 else if (unformat (i, "spd_id %d", &spd_id))
9119 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9120 sw_if_index_set = 1;
9121 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9122 sw_if_index_set = 1;
9125 clib_warning ("parse error '%U'", format_unformat_error, i);
9131 if (spd_id == (u32) ~ 0)
9133 errmsg ("spd_id must be set");
9137 if (sw_if_index_set == 0)
9139 errmsg ("missing interface name or sw_if_index");
9143 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
9145 mp->spd_id = ntohl (spd_id);
9146 mp->sw_if_index = ntohl (sw_if_index);
9147 mp->is_add = is_add;
9155 api_ipsec_spd_entry_add_del (vat_main_t * vam)
9157 unformat_input_t *i = vam->input;
9158 vl_api_ipsec_spd_entry_add_del_t *mp;
9159 u8 is_add = 1, is_outbound = 0;
9160 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
9162 u32 rport_start = 0, rport_stop = (u32) ~ 0;
9163 u32 lport_start = 0, lport_stop = (u32) ~ 0;
9164 vl_api_address_t laddr_start = { }, laddr_stop =
9173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9175 if (unformat (i, "del"))
9177 if (unformat (i, "outbound"))
9179 if (unformat (i, "inbound"))
9181 else if (unformat (i, "spd_id %d", &spd_id))
9183 else if (unformat (i, "sa_id %d", &sa_id))
9185 else if (unformat (i, "priority %d", &priority))
9187 else if (unformat (i, "protocol %d", &protocol))
9189 else if (unformat (i, "lport_start %d", &lport_start))
9191 else if (unformat (i, "lport_stop %d", &lport_stop))
9193 else if (unformat (i, "rport_start %d", &rport_start))
9195 else if (unformat (i, "rport_stop %d", &rport_stop))
9197 else if (unformat (i, "laddr_start %U",
9198 unformat_vl_api_address, &laddr_start))
9200 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
9203 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
9206 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
9210 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9212 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
9214 clib_warning ("unsupported action: 'resolve'");
9220 clib_warning ("parse error '%U'", format_unformat_error, i);
9226 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
9228 mp->is_add = is_add;
9230 mp->entry.spd_id = ntohl (spd_id);
9231 mp->entry.priority = ntohl (priority);
9232 mp->entry.is_outbound = is_outbound;
9234 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
9235 sizeof (vl_api_address_t));
9236 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
9237 sizeof (vl_api_address_t));
9238 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
9239 sizeof (vl_api_address_t));
9240 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
9241 sizeof (vl_api_address_t));
9243 mp->entry.protocol = (u8) protocol;
9244 mp->entry.local_port_start = ntohs ((u16) lport_start);
9245 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
9246 mp->entry.remote_port_start = ntohs ((u16) rport_start);
9247 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
9248 mp->entry.policy = (u8) policy;
9249 mp->entry.sa_id = ntohl (sa_id);
9257 api_ipsec_sad_entry_add_del (vat_main_t * vam)
9259 unformat_input_t *i = vam->input;
9260 vl_api_ipsec_sad_entry_add_del_t *mp;
9261 u32 sad_id = 0, spi = 0;
9262 u8 *ck = 0, *ik = 0;
9265 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
9266 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
9267 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
9268 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
9269 vl_api_address_t tun_src, tun_dst;
9272 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9274 if (unformat (i, "del"))
9276 else if (unformat (i, "sad_id %d", &sad_id))
9278 else if (unformat (i, "spi %d", &spi))
9280 else if (unformat (i, "esp"))
9281 protocol = IPSEC_API_PROTO_ESP;
9283 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
9285 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9286 if (ADDRESS_IP6 == tun_src.af)
9287 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9290 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
9292 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9293 if (ADDRESS_IP6 == tun_src.af)
9294 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9297 if (unformat (i, "crypto_alg %U",
9298 unformat_ipsec_api_crypto_alg, &crypto_alg))
9300 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9302 else if (unformat (i, "integ_alg %U",
9303 unformat_ipsec_api_integ_alg, &integ_alg))
9305 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9309 clib_warning ("parse error '%U'", format_unformat_error, i);
9315 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
9317 mp->is_add = is_add;
9318 mp->entry.sad_id = ntohl (sad_id);
9319 mp->entry.protocol = protocol;
9320 mp->entry.spi = ntohl (spi);
9321 mp->entry.flags = flags;
9323 mp->entry.crypto_algorithm = crypto_alg;
9324 mp->entry.integrity_algorithm = integ_alg;
9325 mp->entry.crypto_key.length = vec_len (ck);
9326 mp->entry.integrity_key.length = vec_len (ik);
9328 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
9329 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
9331 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
9332 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
9335 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
9337 clib_memcpy (mp->entry.integrity_key.data, ik,
9338 mp->entry.integrity_key.length);
9340 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
9342 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
9343 sizeof (mp->entry.tunnel_src));
9344 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
9345 sizeof (mp->entry.tunnel_dst));
9354 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
9356 vat_main_t *vam = &vat_main;
9358 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
9359 "crypto_key %U integ_alg %u integ_key %U flags %x "
9360 "tunnel_src_addr %U tunnel_dst_addr %U "
9361 "salt %u seq_outbound %lu last_seq_inbound %lu "
9362 "replay_window %lu stat_index %u\n",
9363 ntohl (mp->entry.sad_id),
9364 ntohl (mp->sw_if_index),
9365 ntohl (mp->entry.spi),
9366 ntohl (mp->entry.protocol),
9367 ntohl (mp->entry.crypto_algorithm),
9368 format_hex_bytes, mp->entry.crypto_key.data,
9369 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
9370 format_hex_bytes, mp->entry.integrity_key.data,
9371 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
9372 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
9373 &mp->entry.tunnel_dst, ntohl (mp->salt),
9374 clib_net_to_host_u64 (mp->seq_outbound),
9375 clib_net_to_host_u64 (mp->last_seq_inbound),
9376 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
9379 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
9380 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
9382 static void vl_api_ipsec_sa_details_t_handler_json
9383 (vl_api_ipsec_sa_details_t * mp)
9385 vat_main_t *vam = &vat_main;
9386 vat_json_node_t *node = NULL;
9387 vl_api_ipsec_sad_flags_t flags;
9389 if (VAT_JSON_ARRAY != vam->json_tree.type)
9391 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9392 vat_json_init_array (&vam->json_tree);
9394 node = vat_json_array_add (&vam->json_tree);
9396 vat_json_init_object (node);
9397 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
9398 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9399 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
9400 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
9401 vat_json_object_add_uint (node, "crypto_alg",
9402 ntohl (mp->entry.crypto_algorithm));
9403 vat_json_object_add_uint (node, "integ_alg",
9404 ntohl (mp->entry.integrity_algorithm));
9405 flags = ntohl (mp->entry.flags);
9406 vat_json_object_add_uint (node, "use_esn",
9407 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
9408 vat_json_object_add_uint (node, "use_anti_replay",
9409 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
9410 vat_json_object_add_uint (node, "is_tunnel",
9411 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
9412 vat_json_object_add_uint (node, "is_tunnel_ip6",
9413 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
9414 vat_json_object_add_uint (node, "udp_encap",
9415 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
9416 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
9417 mp->entry.crypto_key.length);
9418 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
9419 mp->entry.integrity_key.length);
9420 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
9421 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
9422 vat_json_object_add_uint (node, "replay_window",
9423 clib_net_to_host_u64 (mp->replay_window));
9424 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
9428 api_ipsec_sa_dump (vat_main_t * vam)
9430 unformat_input_t *i = vam->input;
9431 vl_api_ipsec_sa_dump_t *mp;
9432 vl_api_control_ping_t *mp_ping;
9436 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9438 if (unformat (i, "sa_id %d", &sa_id))
9442 clib_warning ("parse error '%U'", format_unformat_error, i);
9447 M (IPSEC_SA_DUMP, mp);
9449 mp->sa_id = ntohl (sa_id);
9453 /* Use a control ping for synchronization */
9454 M (CONTROL_PING, mp_ping);
9462 api_get_first_msg_id (vat_main_t * vam)
9464 vl_api_get_first_msg_id_t *mp;
9465 unformat_input_t *i = vam->input;
9470 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9472 if (unformat (i, "client %s", &name))
9480 errmsg ("missing client name");
9485 if (vec_len (name) > 63)
9487 errmsg ("client name too long");
9491 M (GET_FIRST_MSG_ID, mp);
9492 clib_memcpy (mp->name, name, vec_len (name));
9499 api_get_node_graph (vat_main_t * vam)
9501 vl_api_get_node_graph_t *mp;
9504 M (GET_NODE_GRAPH, mp);
9508 /* Wait for the reply */
9514 api_af_packet_create (vat_main_t * vam)
9516 unformat_input_t *i = vam->input;
9517 vl_api_af_packet_create_t *mp;
9518 u8 *host_if_name = 0;
9520 u8 random_hw_addr = 1;
9523 clib_memset (hw_addr, 0, sizeof (hw_addr));
9525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9527 if (unformat (i, "name %s", &host_if_name))
9528 vec_add1 (host_if_name, 0);
9529 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
9535 if (!vec_len (host_if_name))
9537 errmsg ("host-interface name must be specified");
9541 if (vec_len (host_if_name) > 64)
9543 errmsg ("host-interface name too long");
9547 M (AF_PACKET_CREATE, mp);
9549 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9550 clib_memcpy (mp->hw_addr, hw_addr, 6);
9551 mp->use_random_hw_addr = random_hw_addr;
9552 vec_free (host_if_name);
9560 fprintf (vam->ofp ? vam->ofp : stderr,
9561 " new sw_if_index = %d\n", vam->sw_if_index);
9568 api_af_packet_delete (vat_main_t * vam)
9570 unformat_input_t *i = vam->input;
9571 vl_api_af_packet_delete_t *mp;
9572 u8 *host_if_name = 0;
9575 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9577 if (unformat (i, "name %s", &host_if_name))
9578 vec_add1 (host_if_name, 0);
9583 if (!vec_len (host_if_name))
9585 errmsg ("host-interface name must be specified");
9589 if (vec_len (host_if_name) > 64)
9591 errmsg ("host-interface name too long");
9595 M (AF_PACKET_DELETE, mp);
9597 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9598 vec_free (host_if_name);
9605 static void vl_api_af_packet_details_t_handler
9606 (vl_api_af_packet_details_t * mp)
9608 vat_main_t *vam = &vat_main;
9610 print (vam->ofp, "%-16s %d",
9611 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
9614 static void vl_api_af_packet_details_t_handler_json
9615 (vl_api_af_packet_details_t * mp)
9617 vat_main_t *vam = &vat_main;
9618 vat_json_node_t *node = NULL;
9620 if (VAT_JSON_ARRAY != vam->json_tree.type)
9622 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9623 vat_json_init_array (&vam->json_tree);
9625 node = vat_json_array_add (&vam->json_tree);
9627 vat_json_init_object (node);
9628 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9629 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
9633 api_af_packet_dump (vat_main_t * vam)
9635 vl_api_af_packet_dump_t *mp;
9636 vl_api_control_ping_t *mp_ping;
9639 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
9640 /* Get list of tap interfaces */
9641 M (AF_PACKET_DUMP, mp);
9644 /* Use a control ping for synchronization */
9645 MPING (CONTROL_PING, mp_ping);
9653 api_policer_add_del (vat_main_t * vam)
9655 unformat_input_t *i = vam->input;
9656 vl_api_policer_add_del_t *mp;
9667 qos_pol_action_params_st conform_action, exceed_action, violate_action;
9670 conform_action.action_type = QOS_ACTION_TRANSMIT;
9671 conform_action.dscp = 0;
9672 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
9673 exceed_action.dscp = 0;
9674 violate_action.action_type = QOS_ACTION_DROP;
9675 violate_action.dscp = 0;
9677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9679 if (unformat (i, "del"))
9681 else if (unformat (i, "name %s", &name))
9683 else if (unformat (i, "cir %u", &cir))
9685 else if (unformat (i, "eir %u", &eir))
9687 else if (unformat (i, "cb %u", &cb))
9689 else if (unformat (i, "eb %u", &eb))
9691 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
9694 else if (unformat (i, "round_type %U", unformat_policer_round_type,
9697 else if (unformat (i, "type %U", unformat_policer_type, &type))
9699 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
9702 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
9705 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
9708 else if (unformat (i, "color-aware"))
9714 if (!vec_len (name))
9716 errmsg ("policer name must be specified");
9720 if (vec_len (name) > 64)
9722 errmsg ("policer name too long");
9726 M (POLICER_ADD_DEL, mp);
9728 clib_memcpy (mp->name, name, vec_len (name));
9730 mp->is_add = is_add;
9731 mp->cir = ntohl (cir);
9732 mp->eir = ntohl (eir);
9733 mp->cb = clib_net_to_host_u64 (cb);
9734 mp->eb = clib_net_to_host_u64 (eb);
9735 mp->rate_type = rate_type;
9736 mp->round_type = round_type;
9738 mp->conform_action.type =
9739 (vl_api_sse2_qos_action_type_t) conform_action.action_type;
9740 mp->conform_action.dscp = conform_action.dscp;
9741 mp->exceed_action.type =
9742 (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
9743 mp->exceed_action.dscp = exceed_action.dscp;
9744 mp->violate_action.type =
9745 (vl_api_sse2_qos_action_type_t) violate_action.action_type;
9746 mp->violate_action.dscp = violate_action.dscp;
9747 mp->color_aware = color_aware;
9755 api_policer_dump (vat_main_t * vam)
9757 unformat_input_t *i = vam->input;
9758 vl_api_policer_dump_t *mp;
9759 vl_api_control_ping_t *mp_ping;
9761 u8 match_name_valid = 0;
9764 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9766 if (unformat (i, "name %s", &match_name))
9768 vec_add1 (match_name, 0);
9769 match_name_valid = 1;
9775 M (POLICER_DUMP, mp);
9776 mp->match_name_valid = match_name_valid;
9777 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
9778 vec_free (match_name);
9782 /* Use a control ping for synchronization */
9783 MPING (CONTROL_PING, mp_ping);
9786 /* Wait for a reply... */
9792 format_fib_api_path_nh_proto (u8 * s, va_list * args)
9794 vl_api_fib_path_nh_proto_t proto =
9795 va_arg (*args, vl_api_fib_path_nh_proto_t);
9799 case FIB_API_PATH_NH_PROTO_IP4:
9800 s = format (s, "ip4");
9802 case FIB_API_PATH_NH_PROTO_IP6:
9803 s = format (s, "ip6");
9805 case FIB_API_PATH_NH_PROTO_MPLS:
9806 s = format (s, "mpls");
9808 case FIB_API_PATH_NH_PROTO_BIER:
9809 s = format (s, "bier");
9811 case FIB_API_PATH_NH_PROTO_ETHERNET:
9812 s = format (s, "ethernet");
9820 format_vl_api_ip_address_union (u8 * s, va_list * args)
9822 vl_api_address_family_t af = va_arg (*args, int);
9823 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
9828 s = format (s, "%U", format_ip4_address, u->ip4);
9831 s = format (s, "%U", format_ip6_address, u->ip6);
9838 format_vl_api_fib_path_type (u8 * s, va_list * args)
9840 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
9844 case FIB_API_PATH_TYPE_NORMAL:
9845 s = format (s, "normal");
9847 case FIB_API_PATH_TYPE_LOCAL:
9848 s = format (s, "local");
9850 case FIB_API_PATH_TYPE_DROP:
9851 s = format (s, "drop");
9853 case FIB_API_PATH_TYPE_UDP_ENCAP:
9854 s = format (s, "udp-encap");
9856 case FIB_API_PATH_TYPE_BIER_IMP:
9857 s = format (s, "bier-imp");
9859 case FIB_API_PATH_TYPE_ICMP_UNREACH:
9860 s = format (s, "unreach");
9862 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
9863 s = format (s, "prohibit");
9865 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
9866 s = format (s, "src-lookup");
9868 case FIB_API_PATH_TYPE_DVR:
9869 s = format (s, "dvr");
9871 case FIB_API_PATH_TYPE_INTERFACE_RX:
9872 s = format (s, "interface-rx");
9874 case FIB_API_PATH_TYPE_CLASSIFY:
9875 s = format (s, "classify");
9883 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
9886 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
9887 ntohl (fp->weight), ntohl (fp->sw_if_index),
9888 format_vl_api_fib_path_type, fp->type,
9889 format_fib_api_path_nh_proto, fp->proto,
9890 format_vl_api_ip_address_union, &fp->nh.address);
9894 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
9895 vl_api_fib_path_t * fp)
9898 struct in6_addr ip6;
9900 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
9901 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
9902 vat_json_object_add_uint (node, "type", fp->type);
9903 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
9904 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
9906 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
9907 vat_json_object_add_ip4 (node, "next_hop", ip4);
9909 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
9911 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
9912 vat_json_object_add_ip6 (node, "next_hop", ip6);
9917 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
9919 vat_main_t *vam = &vat_main;
9920 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9921 vl_api_fib_path_t *fp;
9924 print (vam->ofp, "sw_if_index %d via:",
9925 ntohl (mp->mt_tunnel.mt_sw_if_index));
9926 fp = mp->mt_tunnel.mt_paths;
9927 for (i = 0; i < count; i++)
9929 vl_api_fib_path_print (vam, fp);
9933 print (vam->ofp, "");
9936 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
9937 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
9940 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
9942 vat_main_t *vam = &vat_main;
9943 vat_json_node_t *node = NULL;
9944 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9945 vl_api_fib_path_t *fp;
9948 if (VAT_JSON_ARRAY != vam->json_tree.type)
9950 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9951 vat_json_init_array (&vam->json_tree);
9953 node = vat_json_array_add (&vam->json_tree);
9955 vat_json_init_object (node);
9956 vat_json_object_add_uint (node, "sw_if_index",
9957 ntohl (mp->mt_tunnel.mt_sw_if_index));
9959 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
9961 fp = mp->mt_tunnel.mt_paths;
9962 for (i = 0; i < count; i++)
9964 vl_api_mpls_fib_path_json_print (node, fp);
9970 api_mpls_tunnel_dump (vat_main_t * vam)
9972 vl_api_mpls_tunnel_dump_t *mp;
9973 vl_api_control_ping_t *mp_ping;
9976 M (MPLS_TUNNEL_DUMP, mp);
9980 /* Use a control ping for synchronization */
9981 MPING (CONTROL_PING, mp_ping);
9988 #define vl_api_mpls_table_details_t_endian vl_noop_handler
9989 #define vl_api_mpls_table_details_t_print vl_noop_handler
9993 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
9995 vat_main_t *vam = &vat_main;
9997 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
10000 static void vl_api_mpls_table_details_t_handler_json
10001 (vl_api_mpls_table_details_t * mp)
10003 vat_main_t *vam = &vat_main;
10004 vat_json_node_t *node = NULL;
10006 if (VAT_JSON_ARRAY != vam->json_tree.type)
10008 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10009 vat_json_init_array (&vam->json_tree);
10011 node = vat_json_array_add (&vam->json_tree);
10013 vat_json_init_object (node);
10014 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
10018 api_mpls_table_dump (vat_main_t * vam)
10020 vl_api_mpls_table_dump_t *mp;
10021 vl_api_control_ping_t *mp_ping;
10024 M (MPLS_TABLE_DUMP, mp);
10027 /* Use a control ping for synchronization */
10028 MPING (CONTROL_PING, mp_ping);
10035 #define vl_api_mpls_route_details_t_endian vl_noop_handler
10036 #define vl_api_mpls_route_details_t_print vl_noop_handler
10039 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
10041 vat_main_t *vam = &vat_main;
10042 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
10043 vl_api_fib_path_t *fp;
10047 "table-id %d, label %u, ess_bit %u",
10048 ntohl (mp->mr_route.mr_table_id),
10049 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
10050 fp = mp->mr_route.mr_paths;
10051 for (i = 0; i < count; i++)
10053 vl_api_fib_path_print (vam, fp);
10058 static void vl_api_mpls_route_details_t_handler_json
10059 (vl_api_mpls_route_details_t * mp)
10061 vat_main_t *vam = &vat_main;
10062 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
10063 vat_json_node_t *node = NULL;
10064 vl_api_fib_path_t *fp;
10067 if (VAT_JSON_ARRAY != vam->json_tree.type)
10069 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10070 vat_json_init_array (&vam->json_tree);
10072 node = vat_json_array_add (&vam->json_tree);
10074 vat_json_init_object (node);
10075 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
10076 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
10077 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
10078 vat_json_object_add_uint (node, "path_count", count);
10079 fp = mp->mr_route.mr_paths;
10080 for (i = 0; i < count; i++)
10082 vl_api_mpls_fib_path_json_print (node, fp);
10088 api_mpls_route_dump (vat_main_t * vam)
10090 unformat_input_t *input = vam->input;
10091 vl_api_mpls_route_dump_t *mp;
10092 vl_api_control_ping_t *mp_ping;
10096 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10098 if (unformat (input, "table_id %d", &table_id))
10103 if (table_id == ~0)
10105 errmsg ("missing table id");
10109 M (MPLS_ROUTE_DUMP, mp);
10111 mp->table.mt_table_id = ntohl (table_id);
10114 /* Use a control ping for synchronization */
10115 MPING (CONTROL_PING, mp_ping);
10122 #define vl_api_ip_table_details_t_endian vl_noop_handler
10123 #define vl_api_ip_table_details_t_print vl_noop_handler
10126 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
10128 vat_main_t *vam = &vat_main;
10131 "%s; table-id %d, prefix %U/%d",
10132 mp->table.name, ntohl (mp->table.table_id));
10136 static void vl_api_ip_table_details_t_handler_json
10137 (vl_api_ip_table_details_t * mp)
10139 vat_main_t *vam = &vat_main;
10140 vat_json_node_t *node = NULL;
10142 if (VAT_JSON_ARRAY != vam->json_tree.type)
10144 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10145 vat_json_init_array (&vam->json_tree);
10147 node = vat_json_array_add (&vam->json_tree);
10149 vat_json_init_object (node);
10150 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
10154 api_ip_table_dump (vat_main_t * vam)
10156 vl_api_ip_table_dump_t *mp;
10157 vl_api_control_ping_t *mp_ping;
10160 M (IP_TABLE_DUMP, mp);
10163 /* Use a control ping for synchronization */
10164 MPING (CONTROL_PING, mp_ping);
10172 api_ip_mtable_dump (vat_main_t * vam)
10174 vl_api_ip_mtable_dump_t *mp;
10175 vl_api_control_ping_t *mp_ping;
10178 M (IP_MTABLE_DUMP, mp);
10181 /* Use a control ping for synchronization */
10182 MPING (CONTROL_PING, mp_ping);
10190 api_ip_mroute_dump (vat_main_t * vam)
10192 unformat_input_t *input = vam->input;
10193 vl_api_control_ping_t *mp_ping;
10194 vl_api_ip_mroute_dump_t *mp;
10199 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10201 if (unformat (input, "table_id %d", &table_id))
10203 else if (unformat (input, "ip6"))
10205 else if (unformat (input, "ip4"))
10210 if (table_id == ~0)
10212 errmsg ("missing table id");
10216 M (IP_MROUTE_DUMP, mp);
10217 mp->table.table_id = table_id;
10218 mp->table.is_ip6 = is_ip6;
10221 /* Use a control ping for synchronization */
10222 MPING (CONTROL_PING, mp_ping);
10229 #define vl_api_ip_route_details_t_endian vl_noop_handler
10230 #define vl_api_ip_route_details_t_print vl_noop_handler
10233 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
10235 vat_main_t *vam = &vat_main;
10236 u8 count = mp->route.n_paths;
10237 vl_api_fib_path_t *fp;
10241 "table-id %d, prefix %U/%d",
10242 ntohl (mp->route.table_id),
10243 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
10244 for (i = 0; i < count; i++)
10246 fp = &mp->route.paths[i];
10248 vl_api_fib_path_print (vam, fp);
10253 static void vl_api_ip_route_details_t_handler_json
10254 (vl_api_ip_route_details_t * mp)
10256 vat_main_t *vam = &vat_main;
10257 u8 count = mp->route.n_paths;
10258 vat_json_node_t *node = NULL;
10259 struct in_addr ip4;
10260 struct in6_addr ip6;
10261 vl_api_fib_path_t *fp;
10264 if (VAT_JSON_ARRAY != vam->json_tree.type)
10266 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10267 vat_json_init_array (&vam->json_tree);
10269 node = vat_json_array_add (&vam->json_tree);
10271 vat_json_init_object (node);
10272 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
10273 if (ADDRESS_IP6 == mp->route.prefix.address.af)
10275 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
10276 vat_json_object_add_ip6 (node, "prefix", ip6);
10280 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
10281 vat_json_object_add_ip4 (node, "prefix", ip4);
10283 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
10284 vat_json_object_add_uint (node, "path_count", count);
10285 for (i = 0; i < count; i++)
10287 fp = &mp->route.paths[i];
10288 vl_api_mpls_fib_path_json_print (node, fp);
10293 api_ip_route_dump (vat_main_t * vam)
10295 unformat_input_t *input = vam->input;
10296 vl_api_ip_route_dump_t *mp;
10297 vl_api_control_ping_t *mp_ping;
10303 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10305 if (unformat (input, "table_id %d", &table_id))
10307 else if (unformat (input, "ip6"))
10309 else if (unformat (input, "ip4"))
10314 if (table_id == ~0)
10316 errmsg ("missing table id");
10320 M (IP_ROUTE_DUMP, mp);
10322 mp->table.table_id = table_id;
10323 mp->table.is_ip6 = is_ip6;
10327 /* Use a control ping for synchronization */
10328 MPING (CONTROL_PING, mp_ping);
10336 api_sw_interface_span_enable_disable (vat_main_t * vam)
10338 unformat_input_t *i = vam->input;
10339 vl_api_sw_interface_span_enable_disable_t *mp;
10340 u32 src_sw_if_index = ~0;
10341 u32 dst_sw_if_index = ~0;
10346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10349 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
10351 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
10355 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
10357 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
10359 else if (unformat (i, "disable"))
10361 else if (unformat (i, "rx"))
10363 else if (unformat (i, "tx"))
10365 else if (unformat (i, "both"))
10367 else if (unformat (i, "l2"))
10373 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
10375 mp->sw_if_index_from = htonl (src_sw_if_index);
10376 mp->sw_if_index_to = htonl (dst_sw_if_index);
10386 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
10389 vat_main_t *vam = &vat_main;
10390 u8 *sw_if_from_name = 0;
10391 u8 *sw_if_to_name = 0;
10392 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10393 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10394 char *states[] = { "none", "rx", "tx", "both" };
10398 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10400 if ((u32) p->value[0] == sw_if_index_from)
10402 sw_if_from_name = (u8 *)(p->key);
10406 if ((u32) p->value[0] == sw_if_index_to)
10408 sw_if_to_name = (u8 *)(p->key);
10409 if (sw_if_from_name)
10414 print (vam->ofp, "%20s => %20s (%s) %s",
10415 sw_if_from_name, sw_if_to_name, states[mp->state],
10416 mp->is_l2 ? "l2" : "device");
10420 vl_api_sw_interface_span_details_t_handler_json
10421 (vl_api_sw_interface_span_details_t * mp)
10423 vat_main_t *vam = &vat_main;
10424 vat_json_node_t *node = NULL;
10425 u8 *sw_if_from_name = 0;
10426 u8 *sw_if_to_name = 0;
10427 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10428 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10432 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10434 if ((u32) p->value[0] == sw_if_index_from)
10436 sw_if_from_name = (u8 *)(p->key);
10440 if ((u32) p->value[0] == sw_if_index_to)
10442 sw_if_to_name = (u8 *)(p->key);
10443 if (sw_if_from_name)
10449 if (VAT_JSON_ARRAY != vam->json_tree.type)
10451 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10452 vat_json_init_array (&vam->json_tree);
10454 node = vat_json_array_add (&vam->json_tree);
10456 vat_json_init_object (node);
10457 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
10458 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
10459 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
10460 if (0 != sw_if_to_name)
10462 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
10464 vat_json_object_add_uint (node, "state", mp->state);
10465 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
10469 api_sw_interface_span_dump (vat_main_t * vam)
10471 unformat_input_t *input = vam->input;
10472 vl_api_sw_interface_span_dump_t *mp;
10473 vl_api_control_ping_t *mp_ping;
10477 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10479 if (unformat (input, "l2"))
10485 M (SW_INTERFACE_SPAN_DUMP, mp);
10489 /* Use a control ping for synchronization */
10490 MPING (CONTROL_PING, mp_ping);
10498 api_pg_create_interface (vat_main_t * vam)
10500 unformat_input_t *input = vam->input;
10501 vl_api_pg_create_interface_t *mp;
10503 u32 if_id = ~0, gso_size = 0;
10504 u8 gso_enabled = 0;
10506 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10508 if (unformat (input, "if_id %d", &if_id))
10510 else if (unformat (input, "gso-enabled"))
10513 if (unformat (input, "gso-size %u", &gso_size))
10517 errmsg ("missing gso-size");
10526 errmsg ("missing pg interface index");
10530 /* Construct the API message */
10531 M (PG_CREATE_INTERFACE, mp);
10533 mp->interface_id = ntohl (if_id);
10534 mp->gso_enabled = gso_enabled;
10542 api_pg_capture (vat_main_t * vam)
10544 unformat_input_t *input = vam->input;
10545 vl_api_pg_capture_t *mp;
10550 u8 pcap_file_set = 0;
10553 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10555 if (unformat (input, "if_id %d", &if_id))
10557 else if (unformat (input, "pcap %s", &pcap_file))
10559 else if (unformat (input, "count %d", &count))
10561 else if (unformat (input, "disable"))
10568 errmsg ("missing pg interface index");
10571 if (pcap_file_set > 0)
10573 if (vec_len (pcap_file) > 255)
10575 errmsg ("pcap file name is too long");
10580 /* Construct the API message */
10581 M (PG_CAPTURE, mp);
10583 mp->interface_id = ntohl (if_id);
10584 mp->is_enabled = enable;
10585 mp->count = ntohl (count);
10586 if (pcap_file_set != 0)
10588 vl_api_vec_to_api_string (pcap_file, &mp->pcap_file_name);
10590 vec_free (pcap_file);
10598 api_pg_enable_disable (vat_main_t * vam)
10600 unformat_input_t *input = vam->input;
10601 vl_api_pg_enable_disable_t *mp;
10604 u8 stream_name_set = 0;
10605 u8 *stream_name = 0;
10607 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10609 if (unformat (input, "stream %s", &stream_name))
10610 stream_name_set = 1;
10611 else if (unformat (input, "disable"))
10617 if (stream_name_set > 0)
10619 if (vec_len (stream_name) > 255)
10621 errmsg ("stream name too long");
10626 /* Construct the API message */
10627 M (PG_ENABLE_DISABLE, mp);
10629 mp->is_enabled = enable;
10630 if (stream_name_set != 0)
10632 vl_api_vec_to_api_string (stream_name, &mp->stream_name);
10634 vec_free (stream_name);
10642 api_pg_interface_enable_disable_coalesce (vat_main_t * vam)
10644 unformat_input_t *input = vam->input;
10645 vl_api_pg_interface_enable_disable_coalesce_t *mp;
10647 u32 sw_if_index = ~0;
10650 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10652 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10654 else if (unformat (input, "sw_if_index %d", &sw_if_index))
10656 else if (unformat (input, "disable"))
10662 if (sw_if_index == ~0)
10664 errmsg ("Interface required but not specified");
10668 /* Construct the API message */
10669 M (PG_INTERFACE_ENABLE_DISABLE_COALESCE, mp);
10671 mp->coalesce_enabled = enable;
10672 mp->sw_if_index = htonl (sw_if_index);
10680 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
10682 unformat_input_t *input = vam->input;
10683 vl_api_ip_source_and_port_range_check_add_del_t *mp;
10685 u16 *low_ports = 0;
10686 u16 *high_ports = 0;
10689 vl_api_prefix_t prefix;
10696 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10698 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
10700 else if (unformat (input, "vrf %d", &vrf_id))
10702 else if (unformat (input, "del"))
10704 else if (unformat (input, "port %d", &tmp))
10706 if (tmp == 0 || tmp > 65535)
10708 errmsg ("port %d out of range", tmp);
10712 this_hi = this_low + 1;
10713 vec_add1 (low_ports, this_low);
10714 vec_add1 (high_ports, this_hi);
10716 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
10718 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
10720 errmsg ("incorrect range parameters");
10724 /* Note: in debug CLI +1 is added to high before
10725 passing to real fn that does "the work"
10726 (ip_source_and_port_range_check_add_del).
10727 This fn is a wrapper around the binary API fn a
10728 control plane will call, which expects this increment
10729 to have occurred. Hence letting the binary API control
10730 plane fn do the increment for consistency between VAT
10731 and other control planes.
10734 vec_add1 (low_ports, this_low);
10735 vec_add1 (high_ports, this_hi);
10741 if (prefix_set == 0)
10743 errmsg ("<address>/<mask> not specified");
10749 errmsg ("VRF ID required, not specified");
10756 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10760 if (vec_len (low_ports) == 0)
10762 errmsg ("At least one port or port range required");
10766 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
10768 mp->is_add = is_add;
10770 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
10772 mp->number_of_ranges = vec_len (low_ports);
10774 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
10775 vec_free (low_ports);
10777 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
10778 vec_free (high_ports);
10780 mp->vrf_id = ntohl (vrf_id);
10788 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
10790 unformat_input_t *input = vam->input;
10791 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
10792 u32 sw_if_index = ~0;
10794 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
10795 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
10799 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10801 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10803 else if (unformat (input, "sw_if_index %d", &sw_if_index))
10805 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
10807 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
10809 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
10811 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
10813 else if (unformat (input, "del"))
10819 if (sw_if_index == ~0)
10821 errmsg ("Interface required but not specified");
10827 errmsg ("VRF ID required but not specified");
10831 if (tcp_out_vrf_id == 0
10832 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
10835 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10839 /* Construct the API message */
10840 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
10842 mp->sw_if_index = ntohl (sw_if_index);
10843 mp->is_add = is_add;
10844 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
10845 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
10846 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
10847 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
10852 /* Wait for a reply... */
10858 api_set_punt (vat_main_t * vam)
10860 unformat_input_t *i = vam->input;
10861 vl_api_address_family_t af;
10862 vl_api_set_punt_t *mp;
10868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10870 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
10872 else if (unformat (i, "protocol %d", &protocol))
10874 else if (unformat (i, "port %d", &port))
10876 else if (unformat (i, "del"))
10880 clib_warning ("parse error '%U'", format_unformat_error, i);
10887 mp->is_add = (u8) is_add;
10888 mp->punt.type = PUNT_API_TYPE_L4;
10889 mp->punt.punt.l4.af = af;
10890 mp->punt.punt.l4.protocol = (u8) protocol;
10891 mp->punt.punt.l4.port = htons ((u16) port);
10899 api_delete_subif (vat_main_t * vam)
10901 unformat_input_t *i = vam->input;
10902 vl_api_delete_subif_t *mp;
10903 u32 sw_if_index = ~0;
10906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10908 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10910 if (unformat (i, "sw_if_index %d", &sw_if_index))
10916 if (sw_if_index == ~0)
10918 errmsg ("missing sw_if_index");
10922 /* Construct the API message */
10923 M (DELETE_SUBIF, mp);
10924 mp->sw_if_index = ntohl (sw_if_index);
10931 #define foreach_pbb_vtr_op \
10932 _("disable", L2_VTR_DISABLED) \
10933 _("pop", L2_VTR_POP_2) \
10934 _("push", L2_VTR_PUSH_2)
10937 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
10939 unformat_input_t *i = vam->input;
10940 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
10941 u32 sw_if_index = ~0, vtr_op = ~0;
10942 u16 outer_tag = ~0;
10943 u8 dmac[6], smac[6];
10944 u8 dmac_set = 0, smac_set = 0;
10950 /* Shut up coverity */
10951 clib_memset (dmac, 0, sizeof (dmac));
10952 clib_memset (smac, 0, sizeof (smac));
10954 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10956 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10958 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10960 else if (unformat (i, "vtr_op %d", &vtr_op))
10962 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
10965 else if (unformat (i, "translate_pbb_stag"))
10967 if (unformat (i, "%d", &tmp))
10969 vtr_op = L2_VTR_TRANSLATE_2_1;
10975 ("translate_pbb_stag operation requires outer tag definition");
10979 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
10981 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
10983 else if (unformat (i, "sid %d", &sid))
10985 else if (unformat (i, "vlanid %d", &tmp))
10989 clib_warning ("parse error '%U'", format_unformat_error, i);
10994 if ((sw_if_index == ~0) || (vtr_op == ~0))
10996 errmsg ("missing sw_if_index or vtr operation");
10999 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
11000 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
11003 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
11007 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
11008 mp->sw_if_index = ntohl (sw_if_index);
11009 mp->vtr_op = ntohl (vtr_op);
11010 mp->outer_tag = ntohs (outer_tag);
11011 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
11012 clib_memcpy (mp->b_smac, smac, sizeof (smac));
11013 mp->b_vlanid = ntohs (vlanid);
11014 mp->i_sid = ntohl (sid);
11022 api_feature_enable_disable (vat_main_t * vam)
11024 unformat_input_t *i = vam->input;
11025 vl_api_feature_enable_disable_t *mp;
11027 u8 *feature_name = 0;
11028 u32 sw_if_index = ~0;
11032 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11034 if (unformat (i, "arc_name %s", &arc_name))
11036 else if (unformat (i, "feature_name %s", &feature_name))
11039 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11041 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11043 else if (unformat (i, "disable"))
11051 errmsg ("missing arc name");
11054 if (vec_len (arc_name) > 63)
11056 errmsg ("arc name too long");
11059 if (feature_name == 0)
11061 errmsg ("missing feature name");
11064 if (vec_len (feature_name) > 63)
11066 errmsg ("feature name too long");
11069 if (sw_if_index == ~0)
11071 errmsg ("missing interface name or sw_if_index");
11075 /* Construct the API message */
11076 M (FEATURE_ENABLE_DISABLE, mp);
11077 mp->sw_if_index = ntohl (sw_if_index);
11078 mp->enable = enable;
11079 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
11080 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
11081 vec_free (arc_name);
11082 vec_free (feature_name);
11090 api_sw_interface_tag_add_del (vat_main_t * vam)
11092 unformat_input_t *i = vam->input;
11093 vl_api_sw_interface_tag_add_del_t *mp;
11094 u32 sw_if_index = ~0;
11099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11101 if (unformat (i, "tag %s", &tag))
11103 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11105 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11107 else if (unformat (i, "del"))
11113 if (sw_if_index == ~0)
11115 errmsg ("missing interface name or sw_if_index");
11119 if (enable && (tag == 0))
11121 errmsg ("no tag specified");
11125 /* Construct the API message */
11126 M (SW_INTERFACE_TAG_ADD_DEL, mp);
11127 mp->sw_if_index = ntohl (sw_if_index);
11128 mp->is_add = enable;
11130 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
11139 api_sw_interface_add_del_mac_address (vat_main_t * vam)
11141 unformat_input_t *i = vam->input;
11142 vl_api_mac_address_t mac = { 0 };
11143 vl_api_sw_interface_add_del_mac_address_t *mp;
11144 u32 sw_if_index = ~0;
11149 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11151 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11153 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11155 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
11157 else if (unformat (i, "del"))
11163 if (sw_if_index == ~0)
11165 errmsg ("missing interface name or sw_if_index");
11171 errmsg ("missing MAC address");
11175 /* Construct the API message */
11176 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
11177 mp->sw_if_index = ntohl (sw_if_index);
11178 mp->is_add = is_add;
11179 clib_memcpy (&mp->addr, &mac, sizeof (mac));
11186 static void vl_api_l2_xconnect_details_t_handler
11187 (vl_api_l2_xconnect_details_t * mp)
11189 vat_main_t *vam = &vat_main;
11191 print (vam->ofp, "%15d%15d",
11192 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
11195 static void vl_api_l2_xconnect_details_t_handler_json
11196 (vl_api_l2_xconnect_details_t * mp)
11198 vat_main_t *vam = &vat_main;
11199 vat_json_node_t *node = NULL;
11201 if (VAT_JSON_ARRAY != vam->json_tree.type)
11203 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11204 vat_json_init_array (&vam->json_tree);
11206 node = vat_json_array_add (&vam->json_tree);
11208 vat_json_init_object (node);
11209 vat_json_object_add_uint (node, "rx_sw_if_index",
11210 ntohl (mp->rx_sw_if_index));
11211 vat_json_object_add_uint (node, "tx_sw_if_index",
11212 ntohl (mp->tx_sw_if_index));
11216 api_l2_xconnect_dump (vat_main_t * vam)
11218 vl_api_l2_xconnect_dump_t *mp;
11219 vl_api_control_ping_t *mp_ping;
11222 if (!vam->json_output)
11224 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
11227 M (L2_XCONNECT_DUMP, mp);
11231 /* Use a control ping for synchronization */
11232 MPING (CONTROL_PING, mp_ping);
11240 api_hw_interface_set_mtu (vat_main_t * vam)
11242 unformat_input_t *i = vam->input;
11243 vl_api_hw_interface_set_mtu_t *mp;
11244 u32 sw_if_index = ~0;
11248 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11250 if (unformat (i, "mtu %d", &mtu))
11252 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11254 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11260 if (sw_if_index == ~0)
11262 errmsg ("missing interface name or sw_if_index");
11268 errmsg ("no mtu specified");
11272 /* Construct the API message */
11273 M (HW_INTERFACE_SET_MTU, mp);
11274 mp->sw_if_index = ntohl (sw_if_index);
11275 mp->mtu = ntohs ((u16) mtu);
11283 api_p2p_ethernet_add (vat_main_t * vam)
11285 unformat_input_t *i = vam->input;
11286 vl_api_p2p_ethernet_add_t *mp;
11287 u32 parent_if_index = ~0;
11293 clib_memset (remote_mac, 0, sizeof (remote_mac));
11294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11296 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11298 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11302 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11304 else if (unformat (i, "sub_id %d", &sub_id))
11308 clib_warning ("parse error '%U'", format_unformat_error, i);
11313 if (parent_if_index == ~0)
11315 errmsg ("missing interface name or sw_if_index");
11320 errmsg ("missing remote mac address");
11325 errmsg ("missing sub-interface id");
11329 M (P2P_ETHERNET_ADD, mp);
11330 mp->parent_if_index = ntohl (parent_if_index);
11331 mp->subif_id = ntohl (sub_id);
11332 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11340 api_p2p_ethernet_del (vat_main_t * vam)
11342 unformat_input_t *i = vam->input;
11343 vl_api_p2p_ethernet_del_t *mp;
11344 u32 parent_if_index = ~0;
11349 clib_memset (remote_mac, 0, sizeof (remote_mac));
11350 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11352 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11354 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11358 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11362 clib_warning ("parse error '%U'", format_unformat_error, i);
11367 if (parent_if_index == ~0)
11369 errmsg ("missing interface name or sw_if_index");
11374 errmsg ("missing remote mac address");
11378 M (P2P_ETHERNET_DEL, mp);
11379 mp->parent_if_index = ntohl (parent_if_index);
11380 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11388 api_tcp_configure_src_addresses (vat_main_t * vam)
11390 vl_api_tcp_configure_src_addresses_t *mp;
11391 unformat_input_t *i = vam->input;
11392 vl_api_address_t first, last;
11397 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11399 if (unformat (i, "%U - %U",
11400 unformat_vl_api_address, &first,
11401 unformat_vl_api_address, &last))
11405 errmsg ("one range per message (range already set)");
11410 else if (unformat (i, "vrf %d", &vrf_id))
11416 if (range_set == 0)
11418 errmsg ("address range not set");
11422 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
11424 mp->vrf_id = ntohl (vrf_id);
11425 clib_memcpy (&mp->first_address, &first, sizeof (first));
11426 clib_memcpy (&mp->last_address, &last, sizeof (last));
11433 static void vl_api_app_namespace_add_del_reply_t_handler
11434 (vl_api_app_namespace_add_del_reply_t * mp)
11436 vat_main_t *vam = &vat_main;
11437 i32 retval = ntohl (mp->retval);
11438 if (vam->async_mode)
11440 vam->async_errors += (retval < 0);
11444 vam->retval = retval;
11446 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
11447 vam->result_ready = 1;
11451 static void vl_api_app_namespace_add_del_reply_t_handler_json
11452 (vl_api_app_namespace_add_del_reply_t * mp)
11454 vat_main_t *vam = &vat_main;
11455 vat_json_node_t node;
11457 vat_json_init_object (&node);
11458 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11459 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
11461 vat_json_print (vam->ofp, &node);
11462 vat_json_free (&node);
11464 vam->retval = ntohl (mp->retval);
11465 vam->result_ready = 1;
11469 api_app_namespace_add_del (vat_main_t * vam)
11471 vl_api_app_namespace_add_del_t *mp;
11472 unformat_input_t *i = vam->input;
11473 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
11474 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
11478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11480 if (unformat (i, "id %_%v%_", &ns_id))
11482 else if (unformat (i, "secret %lu", &secret))
11484 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11485 sw_if_index_set = 1;
11486 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
11488 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
11493 if (!ns_id || !secret_set || !sw_if_index_set)
11495 errmsg ("namespace id, secret and sw_if_index must be set");
11498 if (vec_len (ns_id) > 64)
11500 errmsg ("namespace id too long");
11503 M (APP_NAMESPACE_ADD_DEL, mp);
11505 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
11506 mp->secret = clib_host_to_net_u64 (secret);
11507 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
11508 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
11509 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
11517 api_sock_init_shm (vat_main_t * vam)
11519 #if VPP_API_TEST_BUILTIN == 0
11520 unformat_input_t *i = vam->input;
11521 vl_api_shm_elem_config_t *config = 0;
11522 u64 size = 64 << 20;
11525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11527 if (unformat (i, "size %U", unformat_memory_size, &size))
11534 * Canned custom ring allocator config.
11535 * Should probably parse all of this
11537 vec_validate (config, 6);
11538 config[0].type = VL_API_VLIB_RING;
11539 config[0].size = 256;
11540 config[0].count = 32;
11542 config[1].type = VL_API_VLIB_RING;
11543 config[1].size = 1024;
11544 config[1].count = 16;
11546 config[2].type = VL_API_VLIB_RING;
11547 config[2].size = 4096;
11548 config[2].count = 2;
11550 config[3].type = VL_API_CLIENT_RING;
11551 config[3].size = 256;
11552 config[3].count = 32;
11554 config[4].type = VL_API_CLIENT_RING;
11555 config[4].size = 1024;
11556 config[4].count = 16;
11558 config[5].type = VL_API_CLIENT_RING;
11559 config[5].size = 4096;
11560 config[5].count = 2;
11562 config[6].type = VL_API_QUEUE;
11563 config[6].count = 128;
11564 config[6].size = sizeof (uword);
11566 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
11568 vam->client_index_invalid = 1;
11576 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
11578 vat_main_t *vam = &vat_main;
11579 fib_prefix_t lcl, rmt;
11581 ip_prefix_decode (&mp->lcl, &lcl);
11582 ip_prefix_decode (&mp->rmt, &rmt);
11584 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
11587 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11588 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11589 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
11590 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
11591 &rmt.fp_addr.ip4, rmt.fp_len,
11592 clib_net_to_host_u16 (mp->rmt_port),
11593 clib_net_to_host_u32 (mp->action_index), mp->tag);
11598 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11599 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11600 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
11601 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
11602 &rmt.fp_addr.ip6, rmt.fp_len,
11603 clib_net_to_host_u16 (mp->rmt_port),
11604 clib_net_to_host_u32 (mp->action_index), mp->tag);
11609 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
11612 vat_main_t *vam = &vat_main;
11613 vat_json_node_t *node = NULL;
11614 struct in6_addr ip6;
11615 struct in_addr ip4;
11617 fib_prefix_t lcl, rmt;
11619 ip_prefix_decode (&mp->lcl, &lcl);
11620 ip_prefix_decode (&mp->rmt, &rmt);
11622 if (VAT_JSON_ARRAY != vam->json_tree.type)
11624 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11625 vat_json_init_array (&vam->json_tree);
11627 node = vat_json_array_add (&vam->json_tree);
11628 vat_json_init_object (node);
11630 vat_json_object_add_uint (node, "appns_index",
11631 clib_net_to_host_u32 (mp->appns_index));
11632 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
11633 vat_json_object_add_uint (node, "scope", mp->scope);
11634 vat_json_object_add_uint (node, "action_index",
11635 clib_net_to_host_u32 (mp->action_index));
11636 vat_json_object_add_uint (node, "lcl_port",
11637 clib_net_to_host_u16 (mp->lcl_port));
11638 vat_json_object_add_uint (node, "rmt_port",
11639 clib_net_to_host_u16 (mp->rmt_port));
11640 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
11641 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
11642 vat_json_object_add_string_copy (node, "tag", mp->tag);
11643 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
11645 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
11646 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
11647 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
11648 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
11652 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
11653 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
11654 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
11655 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
11660 api_session_rule_add_del (vat_main_t * vam)
11662 vl_api_session_rule_add_del_t *mp;
11663 unformat_input_t *i = vam->input;
11664 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
11665 u32 appns_index = 0, scope = 0;
11666 ip4_address_t lcl_ip4, rmt_ip4;
11667 ip6_address_t lcl_ip6, rmt_ip6;
11668 u8 is_ip4 = 1, conn_set = 0;
11669 u8 is_add = 1, *tag = 0;
11671 fib_prefix_t lcl, rmt;
11673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11675 if (unformat (i, "del"))
11677 else if (unformat (i, "add"))
11679 else if (unformat (i, "proto tcp"))
11681 else if (unformat (i, "proto udp"))
11683 else if (unformat (i, "appns %d", &appns_index))
11685 else if (unformat (i, "scope %d", &scope))
11687 else if (unformat (i, "tag %_%v%_", &tag))
11691 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
11692 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
11700 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
11701 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
11707 else if (unformat (i, "action %d", &action))
11712 if (proto == ~0 || !conn_set || action == ~0)
11714 errmsg ("transport proto, connection and action must be set");
11720 errmsg ("scope should be 0-3");
11724 M (SESSION_RULE_ADD_DEL, mp);
11726 clib_memset (&lcl, 0, sizeof (lcl));
11727 clib_memset (&rmt, 0, sizeof (rmt));
11730 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
11731 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
11732 lcl.fp_len = lcl_plen;
11733 rmt.fp_len = rmt_plen;
11737 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
11738 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
11739 lcl.fp_len = lcl_plen;
11740 rmt.fp_len = rmt_plen;
11744 ip_prefix_encode (&lcl, &mp->lcl);
11745 ip_prefix_encode (&rmt, &mp->rmt);
11746 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
11747 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
11748 mp->transport_proto =
11749 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
11750 mp->action_index = clib_host_to_net_u32 (action);
11751 mp->appns_index = clib_host_to_net_u32 (appns_index);
11753 mp->is_add = is_add;
11756 clib_memcpy (mp->tag, tag, vec_len (tag));
11766 api_session_rules_dump (vat_main_t * vam)
11768 vl_api_session_rules_dump_t *mp;
11769 vl_api_control_ping_t *mp_ping;
11772 if (!vam->json_output)
11774 print (vam->ofp, "%=20s", "Session Rules");
11777 M (SESSION_RULES_DUMP, mp);
11781 /* Use a control ping for synchronization */
11782 MPING (CONTROL_PING, mp_ping);
11785 /* Wait for a reply... */
11791 api_ip_container_proxy_add_del (vat_main_t * vam)
11793 vl_api_ip_container_proxy_add_del_t *mp;
11794 unformat_input_t *i = vam->input;
11795 u32 sw_if_index = ~0;
11796 vl_api_prefix_t pfx = { };
11800 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11802 if (unformat (i, "del"))
11804 else if (unformat (i, "add"))
11806 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
11808 else if (unformat (i, "sw_if_index %u", &sw_if_index))
11813 if (sw_if_index == ~0 || pfx.len == 0)
11815 errmsg ("address and sw_if_index must be set");
11819 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
11821 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
11822 mp->is_add = is_add;
11823 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
11831 api_qos_record_enable_disable (vat_main_t * vam)
11833 unformat_input_t *i = vam->input;
11834 vl_api_qos_record_enable_disable_t *mp;
11835 u32 sw_if_index, qs = 0xff;
11836 u8 sw_if_index_set = 0;
11840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11842 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11843 sw_if_index_set = 1;
11844 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11845 sw_if_index_set = 1;
11846 else if (unformat (i, "%U", unformat_qos_source, &qs))
11848 else if (unformat (i, "disable"))
11852 clib_warning ("parse error '%U'", format_unformat_error, i);
11857 if (sw_if_index_set == 0)
11859 errmsg ("missing interface name or sw_if_index");
11864 errmsg ("input location must be specified");
11868 M (QOS_RECORD_ENABLE_DISABLE, mp);
11870 mp->record.sw_if_index = ntohl (sw_if_index);
11871 mp->record.input_source = qs;
11872 mp->enable = enable;
11881 q_or_quit (vat_main_t * vam)
11883 #if VPP_API_TEST_BUILTIN == 0
11884 longjmp (vam->jump_buf, 1);
11886 return 0; /* not so much */
11890 q (vat_main_t * vam)
11892 return q_or_quit (vam);
11896 quit (vat_main_t * vam)
11898 return q_or_quit (vam);
11902 comment (vat_main_t * vam)
11908 elog_save (vat_main_t * vam)
11910 #if VPP_API_TEST_BUILTIN == 0
11911 elog_main_t *em = &vam->elog_main;
11912 unformat_input_t *i = vam->input;
11913 char *file, *chroot_file;
11914 clib_error_t *error;
11916 if (!unformat (i, "%s", &file))
11918 errmsg ("expected file name, got `%U'", format_unformat_error, i);
11922 /* It's fairly hard to get "../oopsie" through unformat; just in case */
11923 if (strstr (file, "..") || index (file, '/'))
11925 errmsg ("illegal characters in filename '%s'", file);
11929 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
11933 errmsg ("Saving %wd of %wd events to %s",
11934 elog_n_events_in_buffer (em),
11935 elog_buffer_capacity (em), chroot_file);
11937 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
11938 vec_free (chroot_file);
11941 clib_error_report (error);
11943 errmsg ("Use the vpp event loger...");
11950 elog_setup (vat_main_t * vam)
11952 #if VPP_API_TEST_BUILTIN == 0
11953 elog_main_t *em = &vam->elog_main;
11954 unformat_input_t *i = vam->input;
11955 u32 nevents = 128 << 10;
11957 (void) unformat (i, "nevents %d", &nevents);
11959 elog_init (em, nevents);
11960 vl_api_set_elog_main (em);
11961 vl_api_set_elog_trace_api_messages (1);
11962 errmsg ("Event logger initialized with %u events", nevents);
11964 errmsg ("Use the vpp event loger...");
11970 elog_enable (vat_main_t * vam)
11972 #if VPP_API_TEST_BUILTIN == 0
11973 elog_main_t *em = &vam->elog_main;
11975 elog_enable_disable (em, 1 /* enable */ );
11976 vl_api_set_elog_trace_api_messages (1);
11977 errmsg ("Event logger enabled...");
11979 errmsg ("Use the vpp event loger...");
11985 elog_disable (vat_main_t * vam)
11987 #if VPP_API_TEST_BUILTIN == 0
11988 elog_main_t *em = &vam->elog_main;
11990 elog_enable_disable (em, 0 /* enable */ );
11991 vl_api_set_elog_trace_api_messages (1);
11992 errmsg ("Event logger disabled...");
11994 errmsg ("Use the vpp event loger...");
12000 statseg (vat_main_t * vam)
12002 ssvm_private_t *ssvmp = &vam->stat_segment;
12003 ssvm_shared_header_t *shared_header = ssvmp->sh;
12004 vlib_counter_t **counters;
12005 u64 thread0_index1_packets;
12006 u64 thread0_index1_bytes;
12007 f64 vector_rate, input_rate;
12010 uword *counter_vector_by_name;
12011 if (vam->stat_segment_lockp == 0)
12013 errmsg ("Stat segment not mapped...");
12017 /* look up "/if/rx for sw_if_index 1 as a test */
12019 clib_spinlock_lock (vam->stat_segment_lockp);
12021 counter_vector_by_name = (uword *) shared_header->opaque[1];
12023 p = hash_get_mem (counter_vector_by_name, "/if/rx");
12026 clib_spinlock_unlock (vam->stat_segment_lockp);
12027 errmsg ("/if/tx not found?");
12031 /* Fish per-thread vector of combined counters from shared memory */
12032 counters = (vlib_counter_t **) p[0];
12034 if (vec_len (counters[0]) < 2)
12036 clib_spinlock_unlock (vam->stat_segment_lockp);
12037 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
12041 /* Read thread 0 sw_if_index 1 counter */
12042 thread0_index1_packets = counters[0][1].packets;
12043 thread0_index1_bytes = counters[0][1].bytes;
12045 p = hash_get_mem (counter_vector_by_name, "vector_rate");
12048 clib_spinlock_unlock (vam->stat_segment_lockp);
12049 errmsg ("vector_rate not found?");
12053 vector_rate = *(f64 *) (p[0]);
12054 p = hash_get_mem (counter_vector_by_name, "input_rate");
12057 clib_spinlock_unlock (vam->stat_segment_lockp);
12058 errmsg ("input_rate not found?");
12061 input_rate = *(f64 *) (p[0]);
12063 clib_spinlock_unlock (vam->stat_segment_lockp);
12065 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
12066 vector_rate, input_rate);
12067 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
12068 thread0_index1_packets, thread0_index1_bytes);
12074 cmd_cmp (void *a1, void *a2)
12079 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
12083 help (vat_main_t * vam)
12088 unformat_input_t *i = vam->input;
12091 if (unformat (i, "%s", &name))
12095 vec_add1 (name, 0);
12097 hs = hash_get_mem (vam->help_by_name, name);
12099 print (vam->ofp, "usage: %s %s", name, hs[0]);
12101 print (vam->ofp, "No such msg / command '%s'", name);
12106 print (vam->ofp, "Help is available for the following:");
12109 hash_foreach_pair (p, vam->function_by_name,
12111 vec_add1 (cmds, (u8 *)(p->key));
12115 vec_sort_with_function (cmds, cmd_cmp);
12117 for (j = 0; j < vec_len (cmds); j++)
12118 print (vam->ofp, "%s", cmds[j]);
12125 set (vat_main_t * vam)
12127 u8 *name = 0, *value = 0;
12128 unformat_input_t *i = vam->input;
12130 if (unformat (i, "%s", &name))
12132 /* The input buffer is a vector, not a string. */
12133 value = vec_dup (i->buffer);
12134 vec_delete (value, i->index, 0);
12135 /* Almost certainly has a trailing newline */
12136 if (value[vec_len (value) - 1] == '\n')
12137 value[vec_len (value) - 1] = 0;
12138 /* Make sure it's a proper string, one way or the other */
12139 vec_add1 (value, 0);
12140 (void) clib_macro_set_value (&vam->macro_main,
12141 (char *) name, (char *) value);
12144 errmsg ("usage: set <name> <value>");
12152 unset (vat_main_t * vam)
12156 if (unformat (vam->input, "%s", &name))
12157 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
12158 errmsg ("unset: %s wasn't set", name);
12171 macro_sort_cmp (void *a1, void *a2)
12173 macro_sort_t *s1 = a1;
12174 macro_sort_t *s2 = a2;
12176 return strcmp ((char *) (s1->name), (char *) (s2->name));
12180 dump_macro_table (vat_main_t * vam)
12182 macro_sort_t *sort_me = 0, *sm;
12187 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
12189 vec_add2 (sort_me, sm, 1);
12190 sm->name = (u8 *)(p->key);
12191 sm->value = (u8 *) (p->value[0]);
12195 vec_sort_with_function (sort_me, macro_sort_cmp);
12197 if (vec_len (sort_me))
12198 print (vam->ofp, "%-15s%s", "Name", "Value");
12200 print (vam->ofp, "The macro table is empty...");
12202 for (i = 0; i < vec_len (sort_me); i++)
12203 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
12208 dump_node_table (vat_main_t * vam)
12211 vlib_node_t *node, *next_node;
12213 if (vec_len (vam->graph_nodes) == 0)
12215 print (vam->ofp, "Node table empty, issue get_node_graph...");
12219 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
12221 node = vam->graph_nodes[0][i];
12222 print (vam->ofp, "[%d] %s", i, node->name);
12223 for (j = 0; j < vec_len (node->next_nodes); j++)
12225 if (node->next_nodes[j] != ~0)
12227 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12228 print (vam->ofp, " [%d] %s", j, next_node->name);
12236 value_sort_cmp (void *a1, void *a2)
12238 name_sort_t *n1 = a1;
12239 name_sort_t *n2 = a2;
12241 if (n1->value < n2->value)
12243 if (n1->value > n2->value)
12250 dump_msg_api_table (vat_main_t * vam)
12252 api_main_t *am = vlibapi_get_main ();
12253 name_sort_t *nses = 0, *ns;
12258 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
12260 vec_add2 (nses, ns, 1);
12261 ns->name = (u8 *)(hp->key);
12262 ns->value = (u32) hp->value[0];
12266 vec_sort_with_function (nses, value_sort_cmp);
12268 for (i = 0; i < vec_len (nses); i++)
12269 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
12275 get_msg_id (vat_main_t * vam)
12280 if (unformat (vam->input, "%s", &name_and_crc))
12282 message_index = vl_msg_api_get_msg_index (name_and_crc);
12283 if (message_index == ~0)
12285 print (vam->ofp, " '%s' not found", name_and_crc);
12288 print (vam->ofp, " '%s' has message index %d",
12289 name_and_crc, message_index);
12292 errmsg ("name_and_crc required...");
12297 search_node_table (vat_main_t * vam)
12299 unformat_input_t *line_input = vam->input;
12302 vlib_node_t *node, *next_node;
12305 if (vam->graph_node_index_by_name == 0)
12307 print (vam->ofp, "Node table empty, issue get_node_graph...");
12311 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12313 if (unformat (line_input, "%s", &node_to_find))
12315 vec_add1 (node_to_find, 0);
12316 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
12319 print (vam->ofp, "%s not found...", node_to_find);
12322 node = vam->graph_nodes[0][p[0]];
12323 print (vam->ofp, "[%d] %s", p[0], node->name);
12324 for (j = 0; j < vec_len (node->next_nodes); j++)
12326 if (node->next_nodes[j] != ~0)
12328 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12329 print (vam->ofp, " [%d] %s", j, next_node->name);
12336 clib_warning ("parse error '%U'", format_unformat_error,
12342 vec_free (node_to_find);
12351 script (vat_main_t * vam)
12353 #if (VPP_API_TEST_BUILTIN==0)
12355 char *save_current_file;
12356 unformat_input_t save_input;
12357 jmp_buf save_jump_buf;
12358 u32 save_line_number;
12360 FILE *new_fp, *save_ifp;
12362 if (unformat (vam->input, "%s", &s))
12364 new_fp = fopen ((char *) s, "r");
12367 errmsg ("Couldn't open script file %s", s);
12374 errmsg ("Missing script name");
12378 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
12379 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
12380 save_ifp = vam->ifp;
12381 save_line_number = vam->input_line_number;
12382 save_current_file = (char *) vam->current_file;
12384 vam->input_line_number = 0;
12386 vam->current_file = s;
12389 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
12390 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
12391 vam->ifp = save_ifp;
12392 vam->input_line_number = save_line_number;
12393 vam->current_file = (u8 *) save_current_file;
12398 clib_warning ("use the exec command...");
12404 echo (vat_main_t * vam)
12406 print (vam->ofp, "%v", vam->input->buffer);
12410 /* List of API message constructors, CLI names map to api_xxx */
12411 #define foreach_vpe_api_msg \
12412 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
12413 _(sw_interface_dump,"") \
12414 _(sw_interface_set_flags, \
12415 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
12416 _(sw_interface_add_del_address, \
12417 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
12418 _(sw_interface_set_rx_mode, \
12419 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
12420 _(sw_interface_set_rx_placement, \
12421 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
12422 _(sw_interface_rx_placement_dump, \
12423 "[<intfc> | sw_if_index <id>]") \
12424 _(sw_interface_set_table, \
12425 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
12426 _(sw_interface_set_mpls_enable, \
12427 "<intfc> | sw_if_index [disable | dis]") \
12428 _(sw_interface_set_vpath, \
12429 "<intfc> | sw_if_index <id> enable | disable") \
12430 _(sw_interface_set_l2_xconnect, \
12431 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12432 "enable | disable") \
12433 _(sw_interface_set_l2_bridge, \
12434 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
12435 "[shg <split-horizon-group>] [bvi]\n" \
12436 "enable | disable") \
12437 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
12438 _(bridge_domain_add_del, \
12439 "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") \
12440 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
12442 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
12443 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
12444 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
12446 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12448 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12450 "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]") \
12452 "<vpp-if-name> | sw_if_index <id>") \
12453 _(sw_interface_tap_v2_dump, "") \
12454 _(virtio_pci_create_v2, \
12455 "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]") \
12456 _(virtio_pci_delete, \
12457 "<vpp-if-name> | sw_if_index <id>") \
12458 _(sw_interface_virtio_pci_dump, "") \
12460 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
12461 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12464 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
12465 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12466 "[id <if-id>] [gso]") \
12468 "<vpp-if-name> | sw_if_index <id>") \
12469 _(bond_add_member, \
12470 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
12471 _(bond_detach_member, \
12472 "sw_if_index <n>") \
12473 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
12474 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
12475 _(sw_member_interface_dump, \
12476 "<vpp-if-name> | sw_if_index <id>") \
12477 _(ip_table_add_del, \
12478 "table <n> [ipv6] [add | del]\n") \
12479 _(ip_route_add_del, \
12480 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
12481 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
12482 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
12483 "[multipath] [count <n>] [del]") \
12484 _(ip_mroute_add_del, \
12485 "<src> <grp>/<mask> [table-id <n>]\n" \
12486 "[<intfc> | sw_if_index <id>] [local] [del]") \
12487 _(mpls_table_add_del, \
12488 "table <n> [add | del]\n") \
12489 _(mpls_route_add_del, \
12490 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
12491 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
12492 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
12493 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
12494 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
12495 "[count <n>] [del]") \
12496 _(mpls_ip_bind_unbind, \
12497 "<label> <addr/len>") \
12498 _(mpls_tunnel_add_del, \
12499 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
12500 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
12501 "[l2-only] [out-label <n>]") \
12502 _(sr_mpls_policy_add, \
12503 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
12504 _(sr_mpls_policy_del, \
12506 _(sw_interface_set_unnumbered, \
12507 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
12508 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
12509 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
12510 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
12511 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
12512 "[outer_vlan_id_any][inner_vlan_id_any]") \
12513 _(ip_table_replace_begin, "table <n> [ipv6]") \
12514 _(ip_table_flush, "table <n> [ipv6]") \
12515 _(ip_table_replace_end, "table <n> [ipv6]") \
12516 _(set_ip_flow_hash, \
12517 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
12518 _(sw_interface_ip6_enable_disable, \
12519 "<intfc> | sw_if_index <id> enable | disable") \
12520 _(l2_patch_add_del, \
12521 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12522 "enable | disable") \
12523 _(sr_localsid_add_del, \
12524 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
12525 "fib-table <num> (end.psp) sw_if_index <num>") \
12526 _(get_node_index, "node <node-name") \
12527 _(add_node_next, "node <node-name> next <next-node-name>") \
12528 _(l2_fib_clear_table, "") \
12529 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
12530 _(l2_interface_vlan_tag_rewrite, \
12531 "<intfc> | sw_if_index <nn> \n" \
12532 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
12533 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
12534 _(create_vhost_user_if, \
12535 "socket <filename> [server] [renumber <dev_instance>] " \
12536 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12537 "[mac <mac_address>] [packed]") \
12538 _(modify_vhost_user_if, \
12539 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12540 "[server] [renumber <dev_instance>] [gso] [packed]") \
12541 _(create_vhost_user_if_v2, \
12542 "socket <filename> [server] [renumber <dev_instance>] " \
12543 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12544 "[mac <mac_address>] [packed] [event-idx]") \
12545 _(modify_vhost_user_if_v2, \
12546 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12547 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
12548 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
12549 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
12550 _(show_version, "") \
12551 _(show_threads, "") \
12552 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
12553 _(interface_name_renumber, \
12554 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
12555 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
12556 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
12557 _(ip_dump, "ipv4 | ipv6") \
12558 _(ipsec_spd_add_del, "spd_id <n> [del]") \
12559 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
12561 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
12562 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
12563 " integ_alg <alg> integ_key <hex>") \
12564 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
12565 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
12566 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
12567 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
12568 _(ipsec_sa_dump, "[sa_id <n>]") \
12569 _(delete_loopback,"sw_if_index <nn>") \
12570 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
12571 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
12572 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
12573 _(want_interface_events, "enable|disable") \
12574 _(get_first_msg_id, "client <name>") \
12575 _(get_node_graph, " ") \
12576 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
12577 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
12578 _(ioam_disable, "") \
12579 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
12580 _(af_packet_delete, "name <host interface name>") \
12581 _(af_packet_dump, "") \
12582 _(policer_add_del, "name <policer name> <params> [del]") \
12583 _(policer_dump, "[name <policer name>]") \
12584 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
12585 _(mpls_table_dump, "") \
12586 _(mpls_route_dump, "table-id <ID>") \
12587 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
12588 _(sw_interface_span_dump, "[l2]") \
12589 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
12590 _(pg_create_interface, "if_id <nn> [gso-enabled gso-size <size>]") \
12591 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
12592 _(pg_enable_disable, "[stream <id>] disable") \
12593 _(pg_interface_enable_disable_coalesce, "<intf> | sw_if_index <nn> enable | disable") \
12594 _(ip_source_and_port_range_check_add_del, \
12595 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
12596 _(ip_source_and_port_range_check_interface_add_del, \
12597 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
12598 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
12599 _(delete_subif,"<intfc> | sw_if_index <nn>") \
12600 _(l2_interface_pbb_tag_rewrite, \
12601 "<intfc> | sw_if_index <nn> \n" \
12602 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
12603 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
12604 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
12605 _(ip_table_dump, "") \
12606 _(ip_route_dump, "table-id [ip4|ip6]") \
12607 _(ip_mtable_dump, "") \
12608 _(ip_mroute_dump, "table-id [ip4|ip6]") \
12609 _(feature_enable_disable, "arc_name <arc_name> " \
12610 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
12611 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
12613 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
12614 "mac <mac-address> [del]") \
12615 _(l2_xconnect_dump, "") \
12616 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
12617 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
12618 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
12619 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
12620 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
12621 _(sock_init_shm, "size <nnn>") \
12622 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
12623 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
12624 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
12625 _(session_rules_dump, "") \
12626 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
12627 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
12629 /* List of command functions, CLI names map directly to functions */
12630 #define foreach_cli_function \
12631 _(comment, "usage: comment <ignore-rest-of-line>") \
12632 _(dump_interface_table, "usage: dump_interface_table") \
12633 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
12634 _(dump_ipv4_table, "usage: dump_ipv4_table") \
12635 _(dump_ipv6_table, "usage: dump_ipv6_table") \
12636 _(dump_macro_table, "usage: dump_macro_table ") \
12637 _(dump_node_table, "usage: dump_node_table") \
12638 _(dump_msg_api_table, "usage: dump_msg_api_table") \
12639 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
12640 _(elog_disable, "usage: elog_disable") \
12641 _(elog_enable, "usage: elog_enable") \
12642 _(elog_save, "usage: elog_save <filename>") \
12643 _(get_msg_id, "usage: get_msg_id name_and_crc") \
12644 _(echo, "usage: echo <message>") \
12645 _(exec, "usage: exec <vpe-debug-CLI-command>") \
12646 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
12647 _(help, "usage: help") \
12648 _(q, "usage: quit") \
12649 _(quit, "usage: quit") \
12650 _(search_node_table, "usage: search_node_table <name>...") \
12651 _(set, "usage: set <variable-name> <value>") \
12652 _(script, "usage: script <file-name>") \
12653 _(statseg, "usage: statseg") \
12654 _(unset, "usage: unset <variable-name>")
12657 static void vl_api_##n##_t_handler_uni \
12658 (vl_api_##n##_t * mp) \
12660 vat_main_t * vam = &vat_main; \
12661 if (vam->json_output) { \
12662 vl_api_##n##_t_handler_json(mp); \
12664 vl_api_##n##_t_handler(mp); \
12667 foreach_vpe_api_reply_msg;
12668 #if VPP_API_TEST_BUILTIN == 0
12669 foreach_standalone_reply_msg;
12674 vat_api_hookup (vat_main_t * vam)
12677 vl_msg_api_set_handlers(VL_API_##N, #n, \
12678 vl_api_##n##_t_handler_uni, \
12680 vl_api_##n##_t_endian, \
12681 vl_api_##n##_t_print, \
12682 sizeof(vl_api_##n##_t), 1);
12683 foreach_vpe_api_reply_msg;
12684 #if VPP_API_TEST_BUILTIN == 0
12685 foreach_standalone_reply_msg;
12689 #if (VPP_API_TEST_BUILTIN==0)
12690 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
12692 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
12694 vam->function_by_name = hash_create_string (0, sizeof (uword));
12696 vam->help_by_name = hash_create_string (0, sizeof (uword));
12699 /* API messages we can send */
12700 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
12701 foreach_vpe_api_msg;
12705 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12706 foreach_vpe_api_msg;
12709 /* CLI functions */
12710 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
12711 foreach_cli_function;
12715 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12716 foreach_cli_function;
12720 #if VPP_API_TEST_BUILTIN
12721 static clib_error_t *
12722 vat_api_hookup_shim (vlib_main_t * vm)
12724 vat_api_hookup (&vat_main);
12728 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
12732 * fd.io coding-style-patch-verification: ON
12735 * eval: (c-set-style "gnu")