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);
2762 * Generate boilerplate reply handlers, which
2763 * dig the return value out of the xxx_reply_t API message,
2764 * stick it into vam->retval, and set vam->result_ready
2766 * Could also do this by pointing N message decode slots at
2767 * a single function, but that could break in subtle ways.
2770 #define foreach_standard_reply_retval_handler \
2771 _(sw_interface_set_flags_reply) \
2772 _(sw_interface_add_del_address_reply) \
2773 _(sw_interface_set_rx_mode_reply) \
2774 _(sw_interface_set_rx_placement_reply) \
2775 _(sw_interface_set_table_reply) \
2776 _(sw_interface_set_mpls_enable_reply) \
2777 _(sw_interface_set_vpath_reply) \
2778 _(sw_interface_set_l2_bridge_reply) \
2779 _(sw_interface_set_bond_weight_reply) \
2780 _(bridge_domain_add_del_reply) \
2781 _(sw_interface_set_l2_xconnect_reply) \
2782 _(l2fib_add_del_reply) \
2783 _(l2fib_flush_int_reply) \
2784 _(l2fib_flush_bd_reply) \
2785 _(ip_route_add_del_reply) \
2786 _(ip_table_add_del_reply) \
2787 _(ip_table_replace_begin_reply) \
2788 _(ip_table_flush_reply) \
2789 _(ip_table_replace_end_reply) \
2790 _(ip_mroute_add_del_reply) \
2791 _(mpls_route_add_del_reply) \
2792 _(mpls_table_add_del_reply) \
2793 _(mpls_ip_bind_unbind_reply) \
2794 _(sw_interface_set_unnumbered_reply) \
2795 _(set_ip_flow_hash_reply) \
2796 _(sw_interface_ip6_enable_disable_reply) \
2797 _(l2_patch_add_del_reply) \
2798 _(sr_mpls_policy_add_reply) \
2799 _(sr_mpls_policy_mod_reply) \
2800 _(sr_mpls_policy_del_reply) \
2801 _(sr_policy_add_reply) \
2802 _(sr_policy_mod_reply) \
2803 _(sr_policy_del_reply) \
2804 _(sr_localsid_add_del_reply) \
2805 _(sr_steering_add_del_reply) \
2806 _(l2_fib_clear_table_reply) \
2807 _(l2_interface_efp_filter_reply) \
2808 _(l2_interface_vlan_tag_rewrite_reply) \
2809 _(modify_vhost_user_if_reply) \
2810 _(modify_vhost_user_if_v2_reply) \
2811 _(delete_vhost_user_if_reply) \
2812 _(want_l2_macs_events_reply) \
2813 _(ipsec_spd_add_del_reply) \
2814 _(ipsec_interface_add_del_spd_reply) \
2815 _(ipsec_spd_entry_add_del_reply) \
2816 _(ipsec_sad_entry_add_del_reply) \
2817 _(delete_loopback_reply) \
2818 _(bd_ip_mac_add_del_reply) \
2819 _(bd_ip_mac_flush_reply) \
2820 _(want_interface_events_reply) \
2821 _(sw_interface_clear_stats_reply) \
2822 _(ioam_enable_reply) \
2823 _(ioam_disable_reply) \
2824 _(af_packet_delete_reply) \
2825 _(sw_interface_span_enable_disable_reply) \
2826 _(ip_source_and_port_range_check_add_del_reply) \
2827 _(ip_source_and_port_range_check_interface_add_del_reply)\
2828 _(delete_subif_reply) \
2829 _(l2_interface_pbb_tag_rewrite_reply) \
2831 _(feature_enable_disable_reply) \
2832 _(sw_interface_tag_add_del_reply) \
2833 _(sw_interface_add_del_mac_address_reply) \
2834 _(hw_interface_set_mtu_reply) \
2835 _(p2p_ethernet_add_reply) \
2836 _(p2p_ethernet_del_reply) \
2837 _(tcp_configure_src_addresses_reply) \
2838 _(session_rule_add_del_reply) \
2839 _(ip_container_proxy_add_del_reply) \
2840 _(qos_record_enable_disable_reply) \
2843 static void vl_api_##n##_t_handler \
2844 (vl_api_##n##_t * mp) \
2846 vat_main_t * vam = &vat_main; \
2847 i32 retval = ntohl(mp->retval); \
2848 if (vam->async_mode) { \
2849 vam->async_errors += (retval < 0); \
2851 vam->retval = retval; \
2852 vam->result_ready = 1; \
2855 foreach_standard_reply_retval_handler;
2859 static void vl_api_##n##_t_handler_json \
2860 (vl_api_##n##_t * mp) \
2862 vat_main_t * vam = &vat_main; \
2863 vat_json_node_t node; \
2864 vat_json_init_object(&node); \
2865 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2866 vat_json_print(vam->ofp, &node); \
2867 vam->retval = ntohl(mp->retval); \
2868 vam->result_ready = 1; \
2870 foreach_standard_reply_retval_handler;
2874 * Table of message reply handlers, must include boilerplate handlers
2878 #define foreach_vpe_api_reply_msg \
2879 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2880 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2881 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2882 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2883 _(CONTROL_PING_REPLY, control_ping_reply) \
2884 _(CLI_REPLY, cli_reply) \
2885 _(CLI_INBAND_REPLY, cli_inband_reply) \
2886 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2887 sw_interface_add_del_address_reply) \
2888 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2889 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2890 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2891 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2892 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2893 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2894 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2895 sw_interface_set_l2_xconnect_reply) \
2896 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2897 sw_interface_set_l2_bridge_reply) \
2898 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2899 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2900 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2901 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2902 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2903 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2904 _(L2_FLAGS_REPLY, l2_flags_reply) \
2905 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2906 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
2907 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
2908 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
2909 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2910 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2911 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2912 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2913 _(BOND_CREATE_REPLY, bond_create_reply) \
2914 _(BOND_CREATE2_REPLY, bond_create2_reply) \
2915 _(BOND_DELETE_REPLY, bond_delete_reply) \
2916 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
2917 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
2918 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
2919 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
2920 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
2921 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2922 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2923 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2924 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2925 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2926 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2927 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2928 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2929 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2930 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2931 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2932 sw_interface_set_unnumbered_reply) \
2933 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2934 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2935 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2936 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2937 sw_interface_ip6_enable_disable_reply) \
2938 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2939 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
2940 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
2941 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
2942 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
2943 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
2944 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
2945 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
2946 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
2947 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2948 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2949 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2950 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2951 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2952 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2953 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2954 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2955 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2956 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2957 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2958 _(SHOW_VERSION_REPLY, show_version_reply) \
2959 _(SHOW_THREADS_REPLY, show_threads_reply) \
2960 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2961 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2962 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2963 _(L2_MACS_EVENT, l2_macs_event) \
2964 _(IP_ADDRESS_DETAILS, ip_address_details) \
2965 _(IP_DETAILS, ip_details) \
2966 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2967 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2968 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
2969 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
2970 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
2971 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2972 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2973 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
2974 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
2975 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2976 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2977 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2978 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2979 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
2980 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
2981 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2982 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2983 _(AF_PACKET_DETAILS, af_packet_details) \
2984 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
2985 _(POLICER_DETAILS, policer_details) \
2986 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
2987 _(MPLS_TABLE_DETAILS, mpls_table_details) \
2988 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
2989 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
2990 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
2991 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
2992 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
2993 ip_source_and_port_range_check_add_del_reply) \
2994 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
2995 ip_source_and_port_range_check_interface_add_del_reply) \
2996 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
2997 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
2998 _(SET_PUNT_REPLY, set_punt_reply) \
2999 _(IP_TABLE_DETAILS, ip_table_details) \
3000 _(IP_ROUTE_DETAILS, ip_route_details) \
3001 _(FEATURE_ENABLE_DISABLE_REPLY, feature_enable_disable_reply) \
3002 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
3003 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
3004 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
3005 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
3006 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
3007 _(P2P_ETHERNET_ADD_REPLY, p2p_ethernet_add_reply) \
3008 _(P2P_ETHERNET_DEL_REPLY, p2p_ethernet_del_reply) \
3009 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
3010 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
3011 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
3012 _(SESSION_RULES_DETAILS, session_rules_details) \
3013 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
3014 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
3016 #define foreach_standalone_reply_msg \
3017 _(SW_INTERFACE_EVENT, sw_interface_event)
3025 #define STR_VTR_OP_CASE(op) \
3026 case L2_VTR_ ## op: \
3030 str_vtr_op (u32 vtr_op)
3034 STR_VTR_OP_CASE (DISABLED);
3035 STR_VTR_OP_CASE (PUSH_1);
3036 STR_VTR_OP_CASE (PUSH_2);
3037 STR_VTR_OP_CASE (POP_1);
3038 STR_VTR_OP_CASE (POP_2);
3039 STR_VTR_OP_CASE (TRANSLATE_1_1);
3040 STR_VTR_OP_CASE (TRANSLATE_1_2);
3041 STR_VTR_OP_CASE (TRANSLATE_2_1);
3042 STR_VTR_OP_CASE (TRANSLATE_2_2);
3049 dump_sub_interface_table (vat_main_t * vam)
3051 const sw_interface_subif_t *sub = NULL;
3053 if (vam->json_output)
3056 ("JSON output supported only for VPE API calls and dump_stats_table");
3061 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
3062 "Interface", "sw_if_index",
3063 "sub id", "dot1ad", "tags", "outer id",
3064 "inner id", "exact", "default", "outer any", "inner any");
3066 vec_foreach (sub, vam->sw_if_subif_table)
3069 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
3070 sub->interface_name,
3072 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3073 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3074 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3075 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3076 if (sub->vtr_op != L2_VTR_DISABLED)
3079 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3080 "tag1: %d tag2: %d ]",
3081 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
3082 sub->vtr_tag1, sub->vtr_tag2);
3090 name_sort_cmp (void *a1, void *a2)
3092 name_sort_t *n1 = a1;
3093 name_sort_t *n2 = a2;
3095 return strcmp ((char *) n1->name, (char *) n2->name);
3099 dump_interface_table (vat_main_t * vam)
3102 name_sort_t *nses = 0, *ns;
3104 if (vam->json_output)
3107 ("JSON output supported only for VPE API calls and dump_stats_table");
3112 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3114 vec_add2 (nses, ns, 1);
3115 ns->name = (u8 *)(p->key);
3116 ns->value = (u32) p->value[0];
3120 vec_sort_with_function (nses, name_sort_cmp);
3122 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
3123 vec_foreach (ns, nses)
3125 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
3132 dump_ip_table (vat_main_t * vam, int is_ipv6)
3134 const ip_details_t *det = NULL;
3135 const ip_address_details_t *address = NULL;
3138 print (vam->ofp, "%-12s", "sw_if_index");
3140 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
3147 print (vam->ofp, "%-12d", i);
3148 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
3153 vec_foreach (address, det->addr)
3157 is_ipv6 ? format_ip6_address : format_ip4_address,
3158 address->ip, address->prefix_length);
3166 dump_ipv4_table (vat_main_t * vam)
3168 if (vam->json_output)
3171 ("JSON output supported only for VPE API calls and dump_stats_table");
3175 return dump_ip_table (vam, 0);
3179 dump_ipv6_table (vat_main_t * vam)
3181 if (vam->json_output)
3184 ("JSON output supported only for VPE API calls and dump_stats_table");
3188 return dump_ip_table (vam, 1);
3192 * Pass CLI buffers directly in the CLI_INBAND API message,
3193 * instead of an additional shared memory area.
3196 exec_inband (vat_main_t * vam)
3198 vl_api_cli_inband_t *mp;
3199 unformat_input_t *i = vam->input;
3202 if (vec_len (i->buffer) == 0)
3205 if (vam->exec_mode == 0 && unformat (i, "mode"))
3210 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
3217 * In order for the CLI command to work, it
3218 * must be a vector ending in \n, not a C-string ending
3221 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
3222 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
3226 /* json responses may or may not include a useful reply... */
3227 if (vec_len (vam->cmd_reply))
3228 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
3233 exec (vat_main_t * vam)
3235 return exec_inband (vam);
3239 api_create_loopback (vat_main_t * vam)
3241 unformat_input_t *i = vam->input;
3242 vl_api_create_loopback_t *mp;
3243 vl_api_create_loopback_instance_t *mp_lbi;
3246 u8 is_specified = 0;
3247 u32 user_instance = 0;
3250 clib_memset (mac_address, 0, sizeof (mac_address));
3252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3254 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3256 if (unformat (i, "instance %d", &user_instance))
3264 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
3265 mp_lbi->is_specified = is_specified;
3267 mp_lbi->user_instance = htonl (user_instance);
3269 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
3274 /* Construct the API message */
3275 M (CREATE_LOOPBACK, mp);
3277 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3286 api_delete_loopback (vat_main_t * vam)
3288 unformat_input_t *i = vam->input;
3289 vl_api_delete_loopback_t *mp;
3290 u32 sw_if_index = ~0;
3293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3295 if (unformat (i, "sw_if_index %d", &sw_if_index))
3301 if (sw_if_index == ~0)
3303 errmsg ("missing sw_if_index");
3307 /* Construct the API message */
3308 M (DELETE_LOOPBACK, mp);
3309 mp->sw_if_index = ntohl (sw_if_index);
3317 api_want_interface_events (vat_main_t * vam)
3319 unformat_input_t *i = vam->input;
3320 vl_api_want_interface_events_t *mp;
3324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3326 if (unformat (i, "enable"))
3328 else if (unformat (i, "disable"))
3336 errmsg ("missing enable|disable");
3340 M (WANT_INTERFACE_EVENTS, mp);
3341 mp->enable_disable = enable;
3343 vam->interface_event_display = enable;
3351 /* Note: non-static, called once to set up the initial intfc table */
3353 api_sw_interface_dump (vat_main_t * vam)
3355 vl_api_sw_interface_dump_t *mp;
3356 vl_api_control_ping_t *mp_ping;
3358 name_sort_t *nses = 0, *ns;
3359 sw_interface_subif_t *sub = NULL;
3362 /* Toss the old name table */
3364 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3366 vec_add2 (nses, ns, 1);
3367 ns->name = (u8 *)(p->key);
3368 ns->value = (u32) p->value[0];
3372 hash_free (vam->sw_if_index_by_interface_name);
3374 vec_foreach (ns, nses) vec_free (ns->name);
3378 vec_foreach (sub, vam->sw_if_subif_table)
3380 vec_free (sub->interface_name);
3382 vec_free (vam->sw_if_subif_table);
3384 /* recreate the interface name hash table */
3385 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3388 * Ask for all interface names. Otherwise, the epic catalog of
3389 * name filters becomes ridiculously long, and vat ends up needing
3390 * to be taught about new interface types.
3392 M (SW_INTERFACE_DUMP, mp);
3395 /* Use a control ping for synchronization */
3396 MPING (CONTROL_PING, mp_ping);
3404 api_sw_interface_set_flags (vat_main_t * vam)
3406 unformat_input_t *i = vam->input;
3407 vl_api_sw_interface_set_flags_t *mp;
3409 u8 sw_if_index_set = 0;
3413 /* Parse args required to build the message */
3414 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3416 if (unformat (i, "admin-up"))
3418 else if (unformat (i, "admin-down"))
3421 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3422 sw_if_index_set = 1;
3423 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3424 sw_if_index_set = 1;
3429 if (sw_if_index_set == 0)
3431 errmsg ("missing interface name or sw_if_index");
3435 /* Construct the API message */
3436 M (SW_INTERFACE_SET_FLAGS, mp);
3437 mp->sw_if_index = ntohl (sw_if_index);
3438 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3443 /* Wait for a reply, return the good/bad news... */
3449 api_sw_interface_set_rx_mode (vat_main_t * vam)
3451 unformat_input_t *i = vam->input;
3452 vl_api_sw_interface_set_rx_mode_t *mp;
3454 u8 sw_if_index_set = 0;
3456 u8 queue_id_valid = 0;
3458 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3460 /* Parse args required to build the message */
3461 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3463 if (unformat (i, "queue %d", &queue_id))
3465 else if (unformat (i, "polling"))
3466 mode = VNET_HW_IF_RX_MODE_POLLING;
3467 else if (unformat (i, "interrupt"))
3468 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3469 else if (unformat (i, "adaptive"))
3470 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3472 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3473 sw_if_index_set = 1;
3474 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3475 sw_if_index_set = 1;
3480 if (sw_if_index_set == 0)
3482 errmsg ("missing interface name or sw_if_index");
3485 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3487 errmsg ("missing rx-mode");
3491 /* Construct the API message */
3492 M (SW_INTERFACE_SET_RX_MODE, mp);
3493 mp->sw_if_index = ntohl (sw_if_index);
3494 mp->mode = (vl_api_rx_mode_t) mode;
3495 mp->queue_id_valid = queue_id_valid;
3496 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3501 /* Wait for a reply, return the good/bad news... */
3507 api_sw_interface_set_rx_placement (vat_main_t * vam)
3509 unformat_input_t *i = vam->input;
3510 vl_api_sw_interface_set_rx_placement_t *mp;
3512 u8 sw_if_index_set = 0;
3515 u32 queue_id, thread_index;
3517 /* Parse args required to build the message */
3518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3520 if (unformat (i, "queue %d", &queue_id))
3522 else if (unformat (i, "main"))
3524 else if (unformat (i, "worker %d", &thread_index))
3527 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3528 sw_if_index_set = 1;
3529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3530 sw_if_index_set = 1;
3535 if (sw_if_index_set == 0)
3537 errmsg ("missing interface name or sw_if_index");
3543 /* Construct the API message */
3544 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3545 mp->sw_if_index = ntohl (sw_if_index);
3546 mp->worker_id = ntohl (thread_index);
3547 mp->queue_id = ntohl (queue_id);
3548 mp->is_main = is_main;
3552 /* Wait for a reply, return the good/bad news... */
3557 static void vl_api_sw_interface_rx_placement_details_t_handler
3558 (vl_api_sw_interface_rx_placement_details_t * mp)
3560 vat_main_t *vam = &vat_main;
3561 u32 worker_id = ntohl (mp->worker_id);
3564 "\n%-11d %-11s %-6d %-5d %-9s",
3565 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3566 worker_id, ntohl (mp->queue_id),
3568 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3571 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3572 (vl_api_sw_interface_rx_placement_details_t * mp)
3574 vat_main_t *vam = &vat_main;
3575 vat_json_node_t *node = NULL;
3577 if (VAT_JSON_ARRAY != vam->json_tree.type)
3579 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3580 vat_json_init_array (&vam->json_tree);
3582 node = vat_json_array_add (&vam->json_tree);
3584 vat_json_init_object (node);
3585 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3586 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3587 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3588 vat_json_object_add_uint (node, "mode", mp->mode);
3592 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3594 unformat_input_t *i = vam->input;
3595 vl_api_sw_interface_rx_placement_dump_t *mp;
3596 vl_api_control_ping_t *mp_ping;
3599 u8 sw_if_index_set = 0;
3601 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3603 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3605 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3612 "\n%-11s %-11s %-6s %-5s %-4s",
3613 "sw_if_index", "main/worker", "thread", "queue", "mode");
3615 /* Dump Interface rx placement */
3616 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3618 if (sw_if_index_set)
3619 mp->sw_if_index = htonl (sw_if_index);
3621 mp->sw_if_index = ~0;
3625 /* Use a control ping for synchronization */
3626 MPING (CONTROL_PING, mp_ping);
3634 api_sw_interface_clear_stats (vat_main_t * vam)
3636 unformat_input_t *i = vam->input;
3637 vl_api_sw_interface_clear_stats_t *mp;
3639 u8 sw_if_index_set = 0;
3642 /* Parse args required to build the message */
3643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3645 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3646 sw_if_index_set = 1;
3647 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3648 sw_if_index_set = 1;
3653 /* Construct the API message */
3654 M (SW_INTERFACE_CLEAR_STATS, mp);
3656 if (sw_if_index_set == 1)
3657 mp->sw_if_index = ntohl (sw_if_index);
3659 mp->sw_if_index = ~0;
3664 /* Wait for a reply, return the good/bad news... */
3670 api_sw_interface_add_del_address (vat_main_t * vam)
3672 unformat_input_t *i = vam->input;
3673 vl_api_sw_interface_add_del_address_t *mp;
3675 u8 sw_if_index_set = 0;
3676 u8 is_add = 1, del_all = 0;
3677 u32 address_length = 0;
3678 u8 v4_address_set = 0;
3679 u8 v6_address_set = 0;
3680 ip4_address_t v4address;
3681 ip6_address_t v6address;
3684 /* Parse args required to build the message */
3685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3687 if (unformat (i, "del-all"))
3689 else if (unformat (i, "del"))
3692 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3693 sw_if_index_set = 1;
3694 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3695 sw_if_index_set = 1;
3696 else if (unformat (i, "%U/%d",
3697 unformat_ip4_address, &v4address, &address_length))
3699 else if (unformat (i, "%U/%d",
3700 unformat_ip6_address, &v6address, &address_length))
3706 if (sw_if_index_set == 0)
3708 errmsg ("missing interface name or sw_if_index");
3711 if (v4_address_set && v6_address_set)
3713 errmsg ("both v4 and v6 addresses set");
3716 if (!v4_address_set && !v6_address_set && !del_all)
3718 errmsg ("no addresses set");
3722 /* Construct the API message */
3723 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3725 mp->sw_if_index = ntohl (sw_if_index);
3726 mp->is_add = is_add;
3727 mp->del_all = del_all;
3730 mp->prefix.address.af = ADDRESS_IP6;
3731 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3735 mp->prefix.address.af = ADDRESS_IP4;
3736 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3738 mp->prefix.len = address_length;
3743 /* Wait for a reply, return good/bad news */
3749 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3751 unformat_input_t *i = vam->input;
3752 vl_api_sw_interface_set_mpls_enable_t *mp;
3754 u8 sw_if_index_set = 0;
3758 /* Parse args required to build the message */
3759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3761 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3762 sw_if_index_set = 1;
3763 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3764 sw_if_index_set = 1;
3765 else if (unformat (i, "disable"))
3767 else if (unformat (i, "dis"))
3773 if (sw_if_index_set == 0)
3775 errmsg ("missing interface name or sw_if_index");
3779 /* Construct the API message */
3780 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3782 mp->sw_if_index = ntohl (sw_if_index);
3783 mp->enable = enable;
3788 /* Wait for a reply... */
3794 api_sw_interface_set_table (vat_main_t * vam)
3796 unformat_input_t *i = vam->input;
3797 vl_api_sw_interface_set_table_t *mp;
3798 u32 sw_if_index, vrf_id = 0;
3799 u8 sw_if_index_set = 0;
3803 /* Parse args required to build the message */
3804 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3806 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3807 sw_if_index_set = 1;
3808 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3809 sw_if_index_set = 1;
3810 else if (unformat (i, "vrf %d", &vrf_id))
3812 else if (unformat (i, "ipv6"))
3818 if (sw_if_index_set == 0)
3820 errmsg ("missing interface name or sw_if_index");
3824 /* Construct the API message */
3825 M (SW_INTERFACE_SET_TABLE, mp);
3827 mp->sw_if_index = ntohl (sw_if_index);
3828 mp->is_ipv6 = is_ipv6;
3829 mp->vrf_id = ntohl (vrf_id);
3834 /* Wait for a reply... */
3839 static void vl_api_sw_interface_get_table_reply_t_handler
3840 (vl_api_sw_interface_get_table_reply_t * mp)
3842 vat_main_t *vam = &vat_main;
3844 print (vam->ofp, "%d", ntohl (mp->vrf_id));
3846 vam->retval = ntohl (mp->retval);
3847 vam->result_ready = 1;
3851 static void vl_api_sw_interface_get_table_reply_t_handler_json
3852 (vl_api_sw_interface_get_table_reply_t * mp)
3854 vat_main_t *vam = &vat_main;
3855 vat_json_node_t node;
3857 vat_json_init_object (&node);
3858 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3859 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3861 vat_json_print (vam->ofp, &node);
3862 vat_json_free (&node);
3864 vam->retval = ntohl (mp->retval);
3865 vam->result_ready = 1;
3869 api_sw_interface_get_table (vat_main_t * vam)
3871 unformat_input_t *i = vam->input;
3872 vl_api_sw_interface_get_table_t *mp;
3874 u8 sw_if_index_set = 0;
3878 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3880 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3881 sw_if_index_set = 1;
3882 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3883 sw_if_index_set = 1;
3884 else if (unformat (i, "ipv6"))
3890 if (sw_if_index_set == 0)
3892 errmsg ("missing interface name or sw_if_index");
3896 M (SW_INTERFACE_GET_TABLE, mp);
3897 mp->sw_if_index = htonl (sw_if_index);
3898 mp->is_ipv6 = is_ipv6;
3906 api_sw_interface_set_vpath (vat_main_t * vam)
3908 unformat_input_t *i = vam->input;
3909 vl_api_sw_interface_set_vpath_t *mp;
3910 u32 sw_if_index = 0;
3911 u8 sw_if_index_set = 0;
3915 /* Parse args required to build the message */
3916 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3918 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3919 sw_if_index_set = 1;
3920 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3921 sw_if_index_set = 1;
3922 else if (unformat (i, "enable"))
3924 else if (unformat (i, "disable"))
3930 if (sw_if_index_set == 0)
3932 errmsg ("missing interface name or sw_if_index");
3936 /* Construct the API message */
3937 M (SW_INTERFACE_SET_VPATH, mp);
3939 mp->sw_if_index = ntohl (sw_if_index);
3940 mp->enable = is_enable;
3945 /* Wait for a reply... */
3951 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3953 unformat_input_t *i = vam->input;
3954 vl_api_sw_interface_set_l2_xconnect_t *mp;
3956 u8 rx_sw_if_index_set = 0;
3958 u8 tx_sw_if_index_set = 0;
3962 /* Parse args required to build the message */
3963 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3965 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3966 rx_sw_if_index_set = 1;
3967 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3968 tx_sw_if_index_set = 1;
3969 else if (unformat (i, "rx"))
3971 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3973 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3975 rx_sw_if_index_set = 1;
3980 else if (unformat (i, "tx"))
3982 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3984 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3986 tx_sw_if_index_set = 1;
3991 else if (unformat (i, "enable"))
3993 else if (unformat (i, "disable"))
3999 if (rx_sw_if_index_set == 0)
4001 errmsg ("missing rx interface name or rx_sw_if_index");
4005 if (enable && (tx_sw_if_index_set == 0))
4007 errmsg ("missing tx interface name or tx_sw_if_index");
4011 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
4013 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4014 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
4015 mp->enable = enable;
4023 api_sw_interface_set_l2_bridge (vat_main_t * vam)
4025 unformat_input_t *i = vam->input;
4026 vl_api_sw_interface_set_l2_bridge_t *mp;
4027 vl_api_l2_port_type_t port_type;
4029 u8 rx_sw_if_index_set = 0;
4036 port_type = L2_API_PORT_TYPE_NORMAL;
4038 /* Parse args required to build the message */
4039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4041 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4042 rx_sw_if_index_set = 1;
4043 else if (unformat (i, "bd_id %d", &bd_id))
4047 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
4048 rx_sw_if_index_set = 1;
4049 else if (unformat (i, "shg %d", &shg))
4051 else if (unformat (i, "bvi"))
4052 port_type = L2_API_PORT_TYPE_BVI;
4053 else if (unformat (i, "uu-fwd"))
4054 port_type = L2_API_PORT_TYPE_UU_FWD;
4055 else if (unformat (i, "enable"))
4057 else if (unformat (i, "disable"))
4063 if (rx_sw_if_index_set == 0)
4065 errmsg ("missing rx interface name or sw_if_index");
4069 if (enable && (bd_id_set == 0))
4071 errmsg ("missing bridge domain");
4075 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
4077 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
4078 mp->bd_id = ntohl (bd_id);
4080 mp->port_type = ntohl (port_type);
4081 mp->enable = enable;
4089 api_bridge_domain_dump (vat_main_t * vam)
4091 unformat_input_t *i = vam->input;
4092 vl_api_bridge_domain_dump_t *mp;
4093 vl_api_control_ping_t *mp_ping;
4097 /* Parse args required to build the message */
4098 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4100 if (unformat (i, "bd_id %d", &bd_id))
4106 M (BRIDGE_DOMAIN_DUMP, mp);
4107 mp->bd_id = ntohl (bd_id);
4110 /* Use a control ping for synchronization */
4111 MPING (CONTROL_PING, mp_ping);
4119 api_bridge_domain_add_del (vat_main_t * vam)
4121 unformat_input_t *i = vam->input;
4122 vl_api_bridge_domain_add_del_t *mp;
4125 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4130 /* Parse args required to build the message */
4131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4133 if (unformat (i, "bd_id %d", &bd_id))
4135 else if (unformat (i, "flood %d", &flood))
4137 else if (unformat (i, "uu-flood %d", &uu_flood))
4139 else if (unformat (i, "forward %d", &forward))
4141 else if (unformat (i, "learn %d", &learn))
4143 else if (unformat (i, "arp-term %d", &arp_term))
4145 else if (unformat (i, "mac-age %d", &mac_age))
4147 else if (unformat (i, "bd-tag %s", &bd_tag))
4149 else if (unformat (i, "del"))
4152 flood = uu_flood = forward = learn = 0;
4160 errmsg ("missing bridge domain");
4167 errmsg ("mac age must be less than 256 ");
4172 if ((bd_tag) && (vec_len (bd_tag) > 63))
4174 errmsg ("bd-tag cannot be longer than 63");
4179 M (BRIDGE_DOMAIN_ADD_DEL, mp);
4181 mp->bd_id = ntohl (bd_id);
4183 mp->uu_flood = uu_flood;
4184 mp->forward = forward;
4186 mp->arp_term = arp_term;
4187 mp->is_add = is_add;
4188 mp->mac_age = (u8) mac_age;
4191 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
4192 mp->bd_tag[vec_len (bd_tag)] = 0;
4203 api_l2fib_flush_bd (vat_main_t * vam)
4205 unformat_input_t *i = vam->input;
4206 vl_api_l2fib_flush_bd_t *mp;
4210 /* Parse args required to build the message */
4211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4213 if (unformat (i, "bd_id %d", &bd_id));
4220 errmsg ("missing bridge domain");
4224 M (L2FIB_FLUSH_BD, mp);
4226 mp->bd_id = htonl (bd_id);
4234 api_l2fib_flush_int (vat_main_t * vam)
4236 unformat_input_t *i = vam->input;
4237 vl_api_l2fib_flush_int_t *mp;
4238 u32 sw_if_index = ~0;
4241 /* Parse args required to build the message */
4242 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4244 if (unformat (i, "sw_if_index %d", &sw_if_index));
4246 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
4251 if (sw_if_index == ~0)
4253 errmsg ("missing interface name or sw_if_index");
4257 M (L2FIB_FLUSH_INT, mp);
4259 mp->sw_if_index = ntohl (sw_if_index);
4267 api_l2fib_add_del (vat_main_t * vam)
4269 unformat_input_t *i = vam->input;
4270 vl_api_l2fib_add_del_t *mp;
4276 u32 sw_if_index = 0;
4277 u8 sw_if_index_set = 0;
4286 /* Parse args required to build the message */
4287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4289 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
4291 else if (unformat (i, "bd_id %d", &bd_id))
4293 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4294 sw_if_index_set = 1;
4295 else if (unformat (i, "sw_if"))
4297 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4300 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4301 sw_if_index_set = 1;
4306 else if (unformat (i, "static"))
4308 else if (unformat (i, "filter"))
4313 else if (unformat (i, "bvi"))
4318 else if (unformat (i, "del"))
4320 else if (unformat (i, "count %d", &count))
4328 errmsg ("missing mac address");
4334 errmsg ("missing bridge domain");
4338 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
4340 errmsg ("missing interface name or sw_if_index");
4346 /* Turn on async mode */
4347 vam->async_mode = 1;
4348 vam->async_errors = 0;
4349 before = vat_time_now (vam);
4352 for (j = 0; j < count; j++)
4354 M (L2FIB_ADD_DEL, mp);
4356 clib_memcpy (mp->mac, mac, 6);
4357 mp->bd_id = ntohl (bd_id);
4358 mp->is_add = is_add;
4359 mp->sw_if_index = ntohl (sw_if_index);
4363 mp->static_mac = static_mac;
4364 mp->filter_mac = filter_mac;
4365 mp->bvi_mac = bvi_mac;
4367 increment_mac_address (mac);
4374 vl_api_control_ping_t *mp_ping;
4377 /* Shut off async mode */
4378 vam->async_mode = 0;
4380 MPING (CONTROL_PING, mp_ping);
4383 timeout = vat_time_now (vam) + 1.0;
4384 while (vat_time_now (vam) < timeout)
4385 if (vam->result_ready == 1)
4390 if (vam->retval == -99)
4393 if (vam->async_errors > 0)
4395 errmsg ("%d asynchronous errors", vam->async_errors);
4398 vam->async_errors = 0;
4399 after = vat_time_now (vam);
4401 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4402 count, after - before, count / (after - before));
4408 /* Wait for a reply... */
4412 /* Return the good/bad news */
4413 return (vam->retval);
4417 api_bridge_domain_set_mac_age (vat_main_t * vam)
4419 unformat_input_t *i = vam->input;
4420 vl_api_bridge_domain_set_mac_age_t *mp;
4425 /* Parse args required to build the message */
4426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4428 if (unformat (i, "bd_id %d", &bd_id));
4429 else if (unformat (i, "mac-age %d", &mac_age));
4436 errmsg ("missing bridge domain");
4442 errmsg ("mac age must be less than 256 ");
4446 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4448 mp->bd_id = htonl (bd_id);
4449 mp->mac_age = (u8) mac_age;
4457 api_l2_flags (vat_main_t * vam)
4459 unformat_input_t *i = vam->input;
4460 vl_api_l2_flags_t *mp;
4463 u8 sw_if_index_set = 0;
4467 /* Parse args required to build the message */
4468 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4470 if (unformat (i, "sw_if_index %d", &sw_if_index))
4471 sw_if_index_set = 1;
4472 else if (unformat (i, "sw_if"))
4474 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4477 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4478 sw_if_index_set = 1;
4483 else if (unformat (i, "learn"))
4485 else if (unformat (i, "forward"))
4487 else if (unformat (i, "flood"))
4489 else if (unformat (i, "uu-flood"))
4490 flags |= L2_UU_FLOOD;
4491 else if (unformat (i, "arp-term"))
4492 flags |= L2_ARP_TERM;
4493 else if (unformat (i, "off"))
4495 else if (unformat (i, "disable"))
4501 if (sw_if_index_set == 0)
4503 errmsg ("missing interface name or sw_if_index");
4509 mp->sw_if_index = ntohl (sw_if_index);
4510 mp->feature_bitmap = ntohl (flags);
4511 mp->is_set = is_set;
4519 api_bridge_flags (vat_main_t * vam)
4521 unformat_input_t *i = vam->input;
4522 vl_api_bridge_flags_t *mp;
4526 bd_flags_t flags = 0;
4529 /* Parse args required to build the message */
4530 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4532 if (unformat (i, "bd_id %d", &bd_id))
4534 else if (unformat (i, "learn"))
4535 flags |= BRIDGE_API_FLAG_LEARN;
4536 else if (unformat (i, "forward"))
4537 flags |= BRIDGE_API_FLAG_FWD;
4538 else if (unformat (i, "flood"))
4539 flags |= BRIDGE_API_FLAG_FLOOD;
4540 else if (unformat (i, "uu-flood"))
4541 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4542 else if (unformat (i, "arp-term"))
4543 flags |= BRIDGE_API_FLAG_ARP_TERM;
4544 else if (unformat (i, "off"))
4546 else if (unformat (i, "disable"))
4554 errmsg ("missing bridge domain");
4558 M (BRIDGE_FLAGS, mp);
4560 mp->bd_id = ntohl (bd_id);
4561 mp->flags = ntohl (flags);
4562 mp->is_set = is_set;
4570 api_bd_ip_mac_add_del (vat_main_t * vam)
4572 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4573 vl_api_mac_address_t mac = { 0 };
4574 unformat_input_t *i = vam->input;
4575 vl_api_bd_ip_mac_add_del_t *mp;
4584 /* Parse args required to build the message */
4585 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4587 if (unformat (i, "bd_id %d", &bd_id))
4591 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4595 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4599 else if (unformat (i, "del"))
4607 errmsg ("missing bridge domain");
4610 else if (ip_set == 0)
4612 errmsg ("missing IP address");
4615 else if (mac_set == 0)
4617 errmsg ("missing MAC address");
4621 M (BD_IP_MAC_ADD_DEL, mp);
4623 mp->entry.bd_id = ntohl (bd_id);
4624 mp->is_add = is_add;
4626 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4627 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4635 api_bd_ip_mac_flush (vat_main_t * vam)
4637 unformat_input_t *i = vam->input;
4638 vl_api_bd_ip_mac_flush_t *mp;
4643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4645 if (unformat (i, "bd_id %d", &bd_id))
4655 errmsg ("missing bridge domain");
4659 M (BD_IP_MAC_FLUSH, mp);
4661 mp->bd_id = ntohl (bd_id);
4668 static void vl_api_bd_ip_mac_details_t_handler
4669 (vl_api_bd_ip_mac_details_t * mp)
4671 vat_main_t *vam = &vat_main;
4675 ntohl (mp->entry.bd_id),
4676 format_vl_api_mac_address, mp->entry.mac,
4677 format_vl_api_address, &mp->entry.ip);
4680 static void vl_api_bd_ip_mac_details_t_handler_json
4681 (vl_api_bd_ip_mac_details_t * mp)
4683 vat_main_t *vam = &vat_main;
4684 vat_json_node_t *node = NULL;
4686 if (VAT_JSON_ARRAY != vam->json_tree.type)
4688 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4689 vat_json_init_array (&vam->json_tree);
4691 node = vat_json_array_add (&vam->json_tree);
4693 vat_json_init_object (node);
4694 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4695 vat_json_object_add_string_copy (node, "mac_address",
4696 format (0, "%U", format_vl_api_mac_address,
4700 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4701 vat_json_object_add_string_copy (node, "ip_address", ip);
4706 api_bd_ip_mac_dump (vat_main_t * vam)
4708 unformat_input_t *i = vam->input;
4709 vl_api_bd_ip_mac_dump_t *mp;
4710 vl_api_control_ping_t *mp_ping;
4715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4717 if (unformat (i, "bd_id %d", &bd_id))
4726 "\n%-5s %-7s %-20s %-30s",
4727 "bd_id", "is_ipv6", "mac_address", "ip_address");
4729 /* Dump Bridge Domain Ip to Mac entries */
4730 M (BD_IP_MAC_DUMP, mp);
4733 mp->bd_id = htonl (bd_id);
4739 /* Use a control ping for synchronization */
4740 MPING (CONTROL_PING, mp_ping);
4748 api_tap_create_v2 (vat_main_t * vam)
4750 unformat_input_t *i = vam->input;
4751 vl_api_tap_create_v2_t *mp;
4755 u32 num_rx_queues = 0;
4756 u8 *host_if_name = 0;
4757 u8 host_if_name_set = 0;
4760 u8 host_mac_addr[6];
4761 u8 host_mac_addr_set = 0;
4762 u8 *host_bridge = 0;
4763 u8 host_bridge_set = 0;
4764 u8 host_ip4_prefix_set = 0;
4765 u8 host_ip6_prefix_set = 0;
4766 ip4_address_t host_ip4_addr;
4767 ip4_address_t host_ip4_gw;
4768 u8 host_ip4_gw_set = 0;
4769 u32 host_ip4_prefix_len = 0;
4770 ip6_address_t host_ip6_addr;
4771 ip6_address_t host_ip6_gw;
4772 u8 host_ip6_gw_set = 0;
4773 u32 host_ip6_prefix_len = 0;
4774 u32 host_mtu_size = 0;
4775 u8 host_mtu_set = 0;
4778 u32 rx_ring_sz = 0, tx_ring_sz = 0;
4780 clib_memset (mac_address, 0, sizeof (mac_address));
4782 /* Parse args required to build the message */
4783 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4785 if (unformat (i, "id %u", &id))
4789 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4791 else if (unformat (i, "host-if-name %s", &host_if_name))
4792 host_if_name_set = 1;
4793 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
4795 else if (unformat (i, "host-ns %s", &host_ns))
4797 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
4799 host_mac_addr_set = 1;
4800 else if (unformat (i, "host-bridge %s", &host_bridge))
4801 host_bridge_set = 1;
4802 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
4803 &host_ip4_addr, &host_ip4_prefix_len))
4804 host_ip4_prefix_set = 1;
4805 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
4806 &host_ip6_addr, &host_ip6_prefix_len))
4807 host_ip6_prefix_set = 1;
4808 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
4810 host_ip4_gw_set = 1;
4811 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
4813 host_ip6_gw_set = 1;
4814 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
4816 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
4818 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
4820 else if (unformat (i, "no-gso"))
4821 tap_flags &= ~TAP_API_FLAG_GSO;
4822 else if (unformat (i, "gso"))
4823 tap_flags |= TAP_API_FLAG_GSO;
4824 else if (unformat (i, "csum-offload"))
4825 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
4826 else if (unformat (i, "persist"))
4827 tap_flags |= TAP_API_FLAG_PERSIST;
4828 else if (unformat (i, "attach"))
4829 tap_flags |= TAP_API_FLAG_ATTACH;
4830 else if (unformat (i, "tun"))
4831 tap_flags |= TAP_API_FLAG_TUN;
4832 else if (unformat (i, "gro-coalesce"))
4833 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
4834 else if (unformat (i, "packed"))
4835 tap_flags |= TAP_API_FLAG_PACKED;
4836 else if (unformat (i, "in-order"))
4837 tap_flags |= TAP_API_FLAG_IN_ORDER;
4842 if (vec_len (host_if_name) > 63)
4844 errmsg ("tap name too long. ");
4847 if (vec_len (host_ns) > 63)
4849 errmsg ("host name space too long. ");
4852 if (vec_len (host_bridge) > 63)
4854 errmsg ("host bridge name too long. ");
4857 if (host_ip4_prefix_len > 32)
4859 errmsg ("host ip4 prefix length not valid. ");
4862 if (host_ip6_prefix_len > 128)
4864 errmsg ("host ip6 prefix length not valid. ");
4867 if (!is_pow2 (rx_ring_sz))
4869 errmsg ("rx ring size must be power of 2. ");
4872 if (rx_ring_sz > 32768)
4874 errmsg ("rx ring size must be 32768 or lower. ");
4877 if (!is_pow2 (tx_ring_sz))
4879 errmsg ("tx ring size must be power of 2. ");
4882 if (tx_ring_sz > 32768)
4884 errmsg ("tx ring size must be 32768 or lower. ");
4887 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
4889 errmsg ("host MTU size must be in between 64 and 65355. ");
4893 /* Construct the API message */
4894 M (TAP_CREATE_V2, mp);
4896 mp->id = ntohl (id);
4897 mp->use_random_mac = random_mac;
4898 mp->num_rx_queues = (u8) num_rx_queues;
4899 mp->tx_ring_sz = ntohs (tx_ring_sz);
4900 mp->rx_ring_sz = ntohs (rx_ring_sz);
4901 mp->host_mtu_set = host_mtu_set;
4902 mp->host_mtu_size = ntohl (host_mtu_size);
4903 mp->host_mac_addr_set = host_mac_addr_set;
4904 mp->host_ip4_prefix_set = host_ip4_prefix_set;
4905 mp->host_ip6_prefix_set = host_ip6_prefix_set;
4906 mp->host_ip4_gw_set = host_ip4_gw_set;
4907 mp->host_ip6_gw_set = host_ip6_gw_set;
4908 mp->tap_flags = ntohl (tap_flags);
4909 mp->host_namespace_set = host_ns_set;
4910 mp->host_if_name_set = host_if_name_set;
4911 mp->host_bridge_set = host_bridge_set;
4913 if (random_mac == 0)
4914 clib_memcpy (mp->mac_address, mac_address, 6);
4915 if (host_mac_addr_set)
4916 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
4917 if (host_if_name_set)
4918 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
4920 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
4921 if (host_bridge_set)
4922 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
4923 if (host_ip4_prefix_set)
4925 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
4926 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
4928 if (host_ip6_prefix_set)
4930 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
4931 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
4933 if (host_ip4_gw_set)
4934 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
4935 if (host_ip6_gw_set)
4936 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
4939 vec_free (host_if_name);
4940 vec_free (host_bridge);
4945 /* Wait for a reply... */
4951 api_tap_delete_v2 (vat_main_t * vam)
4953 unformat_input_t *i = vam->input;
4954 vl_api_tap_delete_v2_t *mp;
4955 u32 sw_if_index = ~0;
4956 u8 sw_if_index_set = 0;
4959 /* Parse args required to build the message */
4960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4962 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4963 sw_if_index_set = 1;
4964 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4965 sw_if_index_set = 1;
4970 if (sw_if_index_set == 0)
4972 errmsg ("missing vpp interface name. ");
4976 /* Construct the API message */
4977 M (TAP_DELETE_V2, mp);
4979 mp->sw_if_index = ntohl (sw_if_index);
4984 /* Wait for a reply... */
4990 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
4992 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
4995 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
4998 addr->domain = x[0];
5001 addr->function = x[3];
5007 api_virtio_pci_create_v2 (vat_main_t * vam)
5009 unformat_input_t *i = vam->input;
5010 vl_api_virtio_pci_create_v2_t *mp;
5014 u64 features = (u64) ~ (0ULL);
5015 u32 virtio_flags = 0;
5018 clib_memset (mac_address, 0, sizeof (mac_address));
5020 /* Parse args required to build the message */
5021 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5023 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
5027 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
5029 else if (unformat (i, "features 0x%llx", &features))
5031 else if (unformat (i, "gso-enabled"))
5032 virtio_flags |= VIRTIO_API_FLAG_GSO;
5033 else if (unformat (i, "csum-offload-enabled"))
5034 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
5035 else if (unformat (i, "gro-coalesce"))
5036 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
5037 else if (unformat (i, "packed"))
5038 virtio_flags |= VIRTIO_API_FLAG_PACKED;
5039 else if (unformat (i, "in-order"))
5040 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
5041 else if (unformat (i, "buffering"))
5042 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
5049 errmsg ("pci address must be non zero. ");
5053 /* Construct the API message */
5054 M (VIRTIO_PCI_CREATE_V2, mp);
5056 mp->use_random_mac = random_mac;
5058 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
5059 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
5060 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
5061 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
5063 mp->features = clib_host_to_net_u64 (features);
5064 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
5066 if (random_mac == 0)
5067 clib_memcpy (mp->mac_address, mac_address, 6);
5072 /* Wait for a reply... */
5078 api_virtio_pci_delete (vat_main_t * vam)
5080 unformat_input_t *i = vam->input;
5081 vl_api_virtio_pci_delete_t *mp;
5082 u32 sw_if_index = ~0;
5083 u8 sw_if_index_set = 0;
5086 /* Parse args required to build the message */
5087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5089 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5090 sw_if_index_set = 1;
5091 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5092 sw_if_index_set = 1;
5097 if (sw_if_index_set == 0)
5099 errmsg ("missing vpp interface name. ");
5103 /* Construct the API message */
5104 M (VIRTIO_PCI_DELETE, mp);
5106 mp->sw_if_index = htonl (sw_if_index);
5111 /* Wait for a reply... */
5117 api_bond_create (vat_main_t * vam)
5119 unformat_input_t *i = vam->input;
5120 vl_api_bond_create_t *mp;
5130 clib_memset (mac_address, 0, sizeof (mac_address));
5133 /* Parse args required to build the message */
5134 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5136 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5138 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5139 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5141 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5144 else if (unformat (i, "numa-only"))
5146 else if (unformat (i, "id %u", &id))
5152 if (mode_is_set == 0)
5154 errmsg ("Missing bond mode. ");
5158 /* Construct the API message */
5159 M (BOND_CREATE, mp);
5161 mp->use_custom_mac = custom_mac;
5163 mp->mode = htonl (mode);
5164 mp->lb = htonl (lb);
5165 mp->id = htonl (id);
5166 mp->numa_only = numa_only;
5169 clib_memcpy (mp->mac_address, mac_address, 6);
5174 /* Wait for a reply... */
5180 api_bond_create2 (vat_main_t * vam)
5182 unformat_input_t *i = vam->input;
5183 vl_api_bond_create2_t *mp;
5194 clib_memset (mac_address, 0, sizeof (mac_address));
5197 /* Parse args required to build the message */
5198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5200 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
5202 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
5203 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
5205 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
5208 else if (unformat (i, "numa-only"))
5210 else if (unformat (i, "gso"))
5212 else if (unformat (i, "id %u", &id))
5218 if (mode_is_set == 0)
5220 errmsg ("Missing bond mode. ");
5224 /* Construct the API message */
5225 M (BOND_CREATE2, mp);
5227 mp->use_custom_mac = custom_mac;
5229 mp->mode = htonl (mode);
5230 mp->lb = htonl (lb);
5231 mp->id = htonl (id);
5232 mp->numa_only = numa_only;
5233 mp->enable_gso = gso;
5236 clib_memcpy (mp->mac_address, mac_address, 6);
5241 /* Wait for a reply... */
5247 api_bond_delete (vat_main_t * vam)
5249 unformat_input_t *i = vam->input;
5250 vl_api_bond_delete_t *mp;
5251 u32 sw_if_index = ~0;
5252 u8 sw_if_index_set = 0;
5255 /* Parse args required to build the message */
5256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5258 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5259 sw_if_index_set = 1;
5260 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5261 sw_if_index_set = 1;
5266 if (sw_if_index_set == 0)
5268 errmsg ("missing vpp interface name. ");
5272 /* Construct the API message */
5273 M (BOND_DELETE, mp);
5275 mp->sw_if_index = ntohl (sw_if_index);
5280 /* Wait for a reply... */
5286 api_bond_add_member (vat_main_t * vam)
5288 unformat_input_t *i = vam->input;
5289 vl_api_bond_add_member_t *mp;
5290 u32 bond_sw_if_index;
5294 u32 bond_sw_if_index_is_set = 0;
5296 u8 sw_if_index_is_set = 0;
5298 /* Parse args required to build the message */
5299 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5301 if (unformat (i, "sw_if_index %d", &sw_if_index))
5302 sw_if_index_is_set = 1;
5303 else if (unformat (i, "bond %u", &bond_sw_if_index))
5304 bond_sw_if_index_is_set = 1;
5305 else if (unformat (i, "passive %d", &is_passive))
5307 else if (unformat (i, "long-timeout %d", &is_long_timeout))
5313 if (bond_sw_if_index_is_set == 0)
5315 errmsg ("Missing bond sw_if_index. ");
5318 if (sw_if_index_is_set == 0)
5320 errmsg ("Missing member sw_if_index. ");
5324 /* Construct the API message */
5325 M (BOND_ADD_MEMBER, mp);
5327 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
5328 mp->sw_if_index = ntohl (sw_if_index);
5329 mp->is_long_timeout = is_long_timeout;
5330 mp->is_passive = is_passive;
5335 /* Wait for a reply... */
5341 api_bond_detach_member (vat_main_t * vam)
5343 unformat_input_t *i = vam->input;
5344 vl_api_bond_detach_member_t *mp;
5345 u32 sw_if_index = ~0;
5346 u8 sw_if_index_set = 0;
5349 /* Parse args required to build the message */
5350 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5352 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5353 sw_if_index_set = 1;
5354 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5355 sw_if_index_set = 1;
5360 if (sw_if_index_set == 0)
5362 errmsg ("missing vpp interface name. ");
5366 /* Construct the API message */
5367 M (BOND_DETACH_MEMBER, mp);
5369 mp->sw_if_index = ntohl (sw_if_index);
5374 /* Wait for a reply... */
5380 api_ip_table_add_del (vat_main_t * vam)
5382 unformat_input_t *i = vam->input;
5383 vl_api_ip_table_add_del_t *mp;
5389 /* Parse args required to build the message */
5390 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5392 if (unformat (i, "ipv6"))
5394 else if (unformat (i, "del"))
5396 else if (unformat (i, "add"))
5398 else if (unformat (i, "table %d", &table_id))
5402 clib_warning ("parse error '%U'", format_unformat_error, i);
5409 errmsg ("missing table-ID");
5413 /* Construct the API message */
5414 M (IP_TABLE_ADD_DEL, mp);
5416 mp->table.table_id = ntohl (table_id);
5417 mp->table.is_ip6 = is_ipv6;
5418 mp->is_add = is_add;
5423 /* Wait for a reply... */
5430 unformat_fib_path (unformat_input_t * input, va_list * args)
5432 vat_main_t *vam = va_arg (*args, vat_main_t *);
5433 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5434 u32 weight, preference;
5435 mpls_label_t out_label;
5437 clib_memset (path, 0, sizeof (*path));
5439 path->sw_if_index = ~0;
5443 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5445 if (unformat (input, "%U %U",
5446 unformat_vl_api_ip4_address,
5447 &path->nh.address.ip4,
5448 api_unformat_sw_if_index, vam, &path->sw_if_index))
5450 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5452 else if (unformat (input, "%U %U",
5453 unformat_vl_api_ip6_address,
5454 &path->nh.address.ip6,
5455 api_unformat_sw_if_index, vam, &path->sw_if_index))
5457 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5459 else if (unformat (input, "weight %u", &weight))
5461 path->weight = weight;
5463 else if (unformat (input, "preference %u", &preference))
5465 path->preference = preference;
5467 else if (unformat (input, "%U next-hop-table %d",
5468 unformat_vl_api_ip4_address,
5469 &path->nh.address.ip4, &path->table_id))
5471 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5473 else if (unformat (input, "%U next-hop-table %d",
5474 unformat_vl_api_ip6_address,
5475 &path->nh.address.ip6, &path->table_id))
5477 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5479 else if (unformat (input, "%U",
5480 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5483 * the recursive next-hops are by default in the default table
5486 path->sw_if_index = ~0;
5487 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5489 else if (unformat (input, "%U",
5490 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5493 * the recursive next-hops are by default in the default table
5496 path->sw_if_index = ~0;
5497 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5499 else if (unformat (input, "resolve-via-host"))
5501 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5503 else if (unformat (input, "resolve-via-attached"))
5505 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5507 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5509 path->type = FIB_API_PATH_TYPE_LOCAL;
5510 path->sw_if_index = ~0;
5511 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5513 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5515 path->type = FIB_API_PATH_TYPE_LOCAL;
5516 path->sw_if_index = ~0;
5517 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5519 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5521 else if (unformat (input, "via-label %d", &path->nh.via_label))
5523 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5524 path->sw_if_index = ~0;
5526 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5528 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5529 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5531 else if (unformat (input, "local"))
5533 path->type = FIB_API_PATH_TYPE_LOCAL;
5535 else if (unformat (input, "out-labels"))
5537 while (unformat (input, "%d", &out_label))
5539 path->label_stack[path->n_labels].label = out_label;
5540 path->label_stack[path->n_labels].is_uniform = 0;
5541 path->label_stack[path->n_labels].ttl = 64;
5545 else if (unformat (input, "via"))
5547 /* new path, back up and return */
5548 unformat_put_input (input);
5549 unformat_put_input (input);
5550 unformat_put_input (input);
5551 unformat_put_input (input);
5560 path->proto = ntohl (path->proto);
5561 path->type = ntohl (path->type);
5562 path->flags = ntohl (path->flags);
5563 path->table_id = ntohl (path->table_id);
5564 path->sw_if_index = ntohl (path->sw_if_index);
5570 api_ip_route_add_del (vat_main_t * vam)
5572 unformat_input_t *i = vam->input;
5573 vl_api_ip_route_add_del_t *mp;
5576 u8 is_multipath = 0;
5579 vl_api_prefix_t pfx = { };
5580 vl_api_fib_path_t paths[8];
5584 u32 random_add_del = 0;
5585 u32 *random_vector = 0;
5586 u32 random_seed = 0xdeaddabe;
5588 /* Parse args required to build the message */
5589 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5591 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5593 else if (unformat (i, "del"))
5595 else if (unformat (i, "add"))
5597 else if (unformat (i, "vrf %d", &vrf_id))
5599 else if (unformat (i, "count %d", &count))
5601 else if (unformat (i, "random"))
5603 else if (unformat (i, "multipath"))
5605 else if (unformat (i, "seed %d", &random_seed))
5609 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5612 if (8 == path_count)
5614 errmsg ("max 8 paths");
5620 clib_warning ("parse error '%U'", format_unformat_error, i);
5627 errmsg ("specify a path; via ...");
5630 if (prefix_set == 0)
5632 errmsg ("missing prefix");
5636 /* Generate a pile of unique, random routes */
5639 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5640 u32 this_random_address;
5643 random_hash = hash_create (count, sizeof (uword));
5645 hash_set (random_hash, i->as_u32, 1);
5646 for (j = 0; j <= count; j++)
5650 this_random_address = random_u32 (&random_seed);
5651 this_random_address =
5652 clib_host_to_net_u32 (this_random_address);
5654 while (hash_get (random_hash, this_random_address));
5655 vec_add1 (random_vector, this_random_address);
5656 hash_set (random_hash, this_random_address, 1);
5658 hash_free (random_hash);
5659 set_ip4_address (&pfx.address, random_vector[0]);
5664 /* Turn on async mode */
5665 vam->async_mode = 1;
5666 vam->async_errors = 0;
5667 before = vat_time_now (vam);
5670 for (j = 0; j < count; j++)
5672 /* Construct the API message */
5673 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5675 mp->is_add = is_add;
5676 mp->is_multipath = is_multipath;
5678 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5679 mp->route.table_id = ntohl (vrf_id);
5680 mp->route.n_paths = path_count;
5682 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5685 set_ip4_address (&pfx.address, random_vector[j + 1]);
5687 increment_address (&pfx.address);
5690 /* If we receive SIGTERM, stop now... */
5695 /* When testing multiple add/del ops, use a control-ping to sync */
5698 vl_api_control_ping_t *mp_ping;
5702 /* Shut off async mode */
5703 vam->async_mode = 0;
5705 MPING (CONTROL_PING, mp_ping);
5708 timeout = vat_time_now (vam) + 1.0;
5709 while (vat_time_now (vam) < timeout)
5710 if (vam->result_ready == 1)
5715 if (vam->retval == -99)
5718 if (vam->async_errors > 0)
5720 errmsg ("%d asynchronous errors", vam->async_errors);
5723 vam->async_errors = 0;
5724 after = vat_time_now (vam);
5726 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5730 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5731 count, after - before, count / (after - before));
5737 /* Wait for a reply... */
5742 /* Return the good/bad news */
5743 return (vam->retval);
5747 api_ip_mroute_add_del (vat_main_t * vam)
5749 unformat_input_t *i = vam->input;
5750 u8 path_set = 0, prefix_set = 0, is_add = 1;
5751 vl_api_ip_mroute_add_del_t *mp;
5752 mfib_entry_flags_t eflags = 0;
5753 vl_api_mfib_path_t path;
5754 vl_api_mprefix_t pfx = { };
5758 /* Parse args required to build the message */
5759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5761 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5764 pfx.grp_address_length = htons (pfx.grp_address_length);
5766 else if (unformat (i, "del"))
5768 else if (unformat (i, "add"))
5770 else if (unformat (i, "vrf %d", &vrf_id))
5772 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
5773 path.itf_flags = htonl (path.itf_flags);
5774 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
5776 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
5780 clib_warning ("parse error '%U'", format_unformat_error, i);
5785 if (prefix_set == 0)
5787 errmsg ("missing addresses\n");
5792 errmsg ("missing path\n");
5796 /* Construct the API message */
5797 M (IP_MROUTE_ADD_DEL, mp);
5799 mp->is_add = is_add;
5800 mp->is_multipath = 1;
5802 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5803 mp->route.table_id = htonl (vrf_id);
5804 mp->route.n_paths = 1;
5805 mp->route.entry_flags = htonl (eflags);
5807 clib_memcpy (&mp->route.paths, &path, sizeof (path));
5811 /* Wait for a reply... */
5817 api_mpls_table_add_del (vat_main_t * vam)
5819 unformat_input_t *i = vam->input;
5820 vl_api_mpls_table_add_del_t *mp;
5825 /* Parse args required to build the message */
5826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5828 if (unformat (i, "table %d", &table_id))
5830 else if (unformat (i, "del"))
5832 else if (unformat (i, "add"))
5836 clib_warning ("parse error '%U'", format_unformat_error, i);
5843 errmsg ("missing table-ID");
5847 /* Construct the API message */
5848 M (MPLS_TABLE_ADD_DEL, mp);
5850 mp->mt_table.mt_table_id = ntohl (table_id);
5851 mp->mt_is_add = is_add;
5856 /* Wait for a reply... */
5863 api_mpls_route_add_del (vat_main_t * vam)
5865 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
5866 mpls_label_t local_label = MPLS_LABEL_INVALID;
5867 unformat_input_t *i = vam->input;
5868 vl_api_mpls_route_add_del_t *mp;
5869 vl_api_fib_path_t paths[8];
5873 /* Parse args required to build the message */
5874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5876 if (unformat (i, "%d", &local_label))
5878 else if (unformat (i, "eos"))
5880 else if (unformat (i, "non-eos"))
5882 else if (unformat (i, "del"))
5884 else if (unformat (i, "add"))
5886 else if (unformat (i, "multipath"))
5888 else if (unformat (i, "count %d", &count))
5892 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5895 if (8 == path_count)
5897 errmsg ("max 8 paths");
5903 clib_warning ("parse error '%U'", format_unformat_error, i);
5910 errmsg ("specify a path; via ...");
5914 if (MPLS_LABEL_INVALID == local_label)
5916 errmsg ("missing label");
5922 /* Turn on async mode */
5923 vam->async_mode = 1;
5924 vam->async_errors = 0;
5925 before = vat_time_now (vam);
5928 for (j = 0; j < count; j++)
5930 /* Construct the API message */
5931 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5933 mp->mr_is_add = is_add;
5934 mp->mr_is_multipath = is_multipath;
5936 mp->mr_route.mr_label = local_label;
5937 mp->mr_route.mr_eos = is_eos;
5938 mp->mr_route.mr_table_id = 0;
5939 mp->mr_route.mr_n_paths = path_count;
5941 clib_memcpy (&mp->mr_route.mr_paths, paths,
5942 sizeof (paths[0]) * path_count);
5948 /* If we receive SIGTERM, stop now... */
5953 /* When testing multiple add/del ops, use a control-ping to sync */
5956 vl_api_control_ping_t *mp_ping;
5960 /* Shut off async mode */
5961 vam->async_mode = 0;
5963 MPING (CONTROL_PING, mp_ping);
5966 timeout = vat_time_now (vam) + 1.0;
5967 while (vat_time_now (vam) < timeout)
5968 if (vam->result_ready == 1)
5973 if (vam->retval == -99)
5976 if (vam->async_errors > 0)
5978 errmsg ("%d asynchronous errors", vam->async_errors);
5981 vam->async_errors = 0;
5982 after = vat_time_now (vam);
5984 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5988 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5989 count, after - before, count / (after - before));
5995 /* Wait for a reply... */
6000 /* Return the good/bad news */
6001 return (vam->retval);
6006 api_mpls_ip_bind_unbind (vat_main_t * vam)
6008 unformat_input_t *i = vam->input;
6009 vl_api_mpls_ip_bind_unbind_t *mp;
6010 u32 ip_table_id = 0;
6012 vl_api_prefix_t pfx;
6014 mpls_label_t local_label = MPLS_LABEL_INVALID;
6017 /* Parse args required to build the message */
6018 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6020 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
6022 else if (unformat (i, "%d", &local_label))
6024 else if (unformat (i, "table-id %d", &ip_table_id))
6026 else if (unformat (i, "unbind"))
6028 else if (unformat (i, "bind"))
6032 clib_warning ("parse error '%U'", format_unformat_error, i);
6039 errmsg ("IP prefix not set");
6043 if (MPLS_LABEL_INVALID == local_label)
6045 errmsg ("missing label");
6049 /* Construct the API message */
6050 M (MPLS_IP_BIND_UNBIND, mp);
6052 mp->mb_is_bind = is_bind;
6053 mp->mb_ip_table_id = ntohl (ip_table_id);
6054 mp->mb_mpls_table_id = 0;
6055 mp->mb_label = ntohl (local_label);
6056 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
6061 /* Wait for a reply... */
6068 api_sr_mpls_policy_add (vat_main_t * vam)
6070 unformat_input_t *i = vam->input;
6071 vl_api_sr_mpls_policy_add_t *mp;
6077 u32 *segments = NULL;
6080 /* Parse args required to build the message */
6081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6083 if (unformat (i, "bsid %d", &bsid))
6085 else if (unformat (i, "weight %d", &weight))
6087 else if (unformat (i, "spray"))
6089 else if (unformat (i, "next %d", &sid))
6092 vec_add1 (segments, htonl (sid));
6096 clib_warning ("parse error '%U'", format_unformat_error, i);
6103 errmsg ("bsid not set");
6107 if (n_segments == 0)
6109 errmsg ("no sid in segment stack");
6113 /* Construct the API message */
6114 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
6116 mp->bsid = htonl (bsid);
6117 mp->weight = htonl (weight);
6118 mp->is_spray = type;
6119 mp->n_segments = n_segments;
6120 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
6121 vec_free (segments);
6126 /* Wait for a reply... */
6132 api_sr_mpls_policy_del (vat_main_t * vam)
6134 unformat_input_t *i = vam->input;
6135 vl_api_sr_mpls_policy_del_t *mp;
6139 /* Parse args required to build the message */
6140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6142 if (unformat (i, "bsid %d", &bsid))
6146 clib_warning ("parse error '%U'", format_unformat_error, i);
6153 errmsg ("bsid not set");
6157 /* Construct the API message */
6158 M (SR_MPLS_POLICY_DEL, mp);
6160 mp->bsid = htonl (bsid);
6165 /* Wait for a reply... */
6171 api_mpls_tunnel_add_del (vat_main_t * vam)
6173 unformat_input_t *i = vam->input;
6174 vl_api_mpls_tunnel_add_del_t *mp;
6176 vl_api_fib_path_t paths[8];
6177 u32 sw_if_index = ~0;
6183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6185 if (unformat (i, "add"))
6189 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
6191 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
6193 else if (unformat (i, "l2-only"))
6197 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
6200 if (8 == path_count)
6202 errmsg ("max 8 paths");
6208 clib_warning ("parse error '%U'", format_unformat_error, i);
6213 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
6215 mp->mt_is_add = is_add;
6216 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
6217 mp->mt_tunnel.mt_l2_only = l2_only;
6218 mp->mt_tunnel.mt_is_multicast = 0;
6219 mp->mt_tunnel.mt_n_paths = path_count;
6221 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
6222 sizeof (paths[0]) * path_count);
6230 api_sw_interface_set_unnumbered (vat_main_t * vam)
6232 unformat_input_t *i = vam->input;
6233 vl_api_sw_interface_set_unnumbered_t *mp;
6235 u32 unnum_sw_index = ~0;
6237 u8 sw_if_index_set = 0;
6240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6242 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6243 sw_if_index_set = 1;
6244 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6245 sw_if_index_set = 1;
6246 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
6248 else if (unformat (i, "del"))
6252 clib_warning ("parse error '%U'", format_unformat_error, i);
6257 if (sw_if_index_set == 0)
6259 errmsg ("missing interface name or sw_if_index");
6263 M (SW_INTERFACE_SET_UNNUMBERED, mp);
6265 mp->sw_if_index = ntohl (sw_if_index);
6266 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
6267 mp->is_add = is_add;
6276 api_create_vlan_subif (vat_main_t * vam)
6278 unformat_input_t *i = vam->input;
6279 vl_api_create_vlan_subif_t *mp;
6281 u8 sw_if_index_set = 0;
6286 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6288 if (unformat (i, "sw_if_index %d", &sw_if_index))
6289 sw_if_index_set = 1;
6291 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6292 sw_if_index_set = 1;
6293 else if (unformat (i, "vlan %d", &vlan_id))
6297 clib_warning ("parse error '%U'", format_unformat_error, i);
6302 if (sw_if_index_set == 0)
6304 errmsg ("missing interface name or sw_if_index");
6308 if (vlan_id_set == 0)
6310 errmsg ("missing vlan_id");
6313 M (CREATE_VLAN_SUBIF, mp);
6315 mp->sw_if_index = ntohl (sw_if_index);
6316 mp->vlan_id = ntohl (vlan_id);
6323 #define foreach_create_subif_bit \
6330 _(outer_vlan_id_any) \
6331 _(inner_vlan_id_any)
6333 #define foreach_create_subif_flag \
6338 _(4, "exact_match") \
6339 _(5, "default_sub") \
6340 _(6, "outer_vlan_id_any") \
6341 _(7, "inner_vlan_id_any")
6344 api_create_subif (vat_main_t * vam)
6346 unformat_input_t *i = vam->input;
6347 vl_api_create_subif_t *mp;
6349 u8 sw_if_index_set = 0;
6352 u32 __attribute__ ((unused)) no_tags = 0;
6353 u32 __attribute__ ((unused)) one_tag = 0;
6354 u32 __attribute__ ((unused)) two_tags = 0;
6355 u32 __attribute__ ((unused)) dot1ad = 0;
6356 u32 __attribute__ ((unused)) exact_match = 0;
6357 u32 __attribute__ ((unused)) default_sub = 0;
6358 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
6359 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
6361 u16 outer_vlan_id = 0;
6362 u16 inner_vlan_id = 0;
6365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6367 if (unformat (i, "sw_if_index %d", &sw_if_index))
6368 sw_if_index_set = 1;
6370 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6371 sw_if_index_set = 1;
6372 else if (unformat (i, "sub_id %d", &sub_id))
6374 else if (unformat (i, "outer_vlan_id %d", &tmp))
6375 outer_vlan_id = tmp;
6376 else if (unformat (i, "inner_vlan_id %d", &tmp))
6377 inner_vlan_id = tmp;
6379 #define _(a) else if (unformat (i, #a)) a = 1 ;
6380 foreach_create_subif_bit
6384 clib_warning ("parse error '%U'", format_unformat_error, i);
6389 if (sw_if_index_set == 0)
6391 errmsg ("missing interface name or sw_if_index");
6395 if (sub_id_set == 0)
6397 errmsg ("missing sub_id");
6400 M (CREATE_SUBIF, mp);
6402 mp->sw_if_index = ntohl (sw_if_index);
6403 mp->sub_id = ntohl (sub_id);
6405 #define _(a,b) mp->sub_if_flags |= (1 << a);
6406 foreach_create_subif_flag;
6409 mp->outer_vlan_id = ntohs (outer_vlan_id);
6410 mp->inner_vlan_id = ntohs (inner_vlan_id);
6418 api_ip_table_replace_begin (vat_main_t * vam)
6420 unformat_input_t *i = vam->input;
6421 vl_api_ip_table_replace_begin_t *mp;
6426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6428 if (unformat (i, "table %d", &table_id))
6430 else if (unformat (i, "ipv6"))
6434 clib_warning ("parse error '%U'", format_unformat_error, i);
6439 M (IP_TABLE_REPLACE_BEGIN, mp);
6441 mp->table.table_id = ntohl (table_id);
6442 mp->table.is_ip6 = is_ipv6;
6450 api_ip_table_flush (vat_main_t * vam)
6452 unformat_input_t *i = vam->input;
6453 vl_api_ip_table_flush_t *mp;
6458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6460 if (unformat (i, "table %d", &table_id))
6462 else if (unformat (i, "ipv6"))
6466 clib_warning ("parse error '%U'", format_unformat_error, i);
6471 M (IP_TABLE_FLUSH, mp);
6473 mp->table.table_id = ntohl (table_id);
6474 mp->table.is_ip6 = is_ipv6;
6482 api_ip_table_replace_end (vat_main_t * vam)
6484 unformat_input_t *i = vam->input;
6485 vl_api_ip_table_replace_end_t *mp;
6490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6492 if (unformat (i, "table %d", &table_id))
6494 else if (unformat (i, "ipv6"))
6498 clib_warning ("parse error '%U'", format_unformat_error, i);
6503 M (IP_TABLE_REPLACE_END, mp);
6505 mp->table.table_id = ntohl (table_id);
6506 mp->table.is_ip6 = is_ipv6;
6514 api_set_ip_flow_hash (vat_main_t * vam)
6516 unformat_input_t *i = vam->input;
6517 vl_api_set_ip_flow_hash_t *mp;
6529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6531 if (unformat (i, "vrf %d", &vrf_id))
6533 else if (unformat (i, "ipv6"))
6535 else if (unformat (i, "src"))
6537 else if (unformat (i, "dst"))
6539 else if (unformat (i, "sport"))
6541 else if (unformat (i, "dport"))
6543 else if (unformat (i, "proto"))
6545 else if (unformat (i, "reverse"))
6550 clib_warning ("parse error '%U'", format_unformat_error, i);
6555 if (vrf_id_set == 0)
6557 errmsg ("missing vrf id");
6561 M (SET_IP_FLOW_HASH, mp);
6567 mp->reverse = reverse;
6568 mp->vrf_id = ntohl (vrf_id);
6569 mp->is_ipv6 = is_ipv6;
6577 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6579 unformat_input_t *i = vam->input;
6580 vl_api_sw_interface_ip6_enable_disable_t *mp;
6582 u8 sw_if_index_set = 0;
6586 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6588 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6589 sw_if_index_set = 1;
6590 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6591 sw_if_index_set = 1;
6592 else if (unformat (i, "enable"))
6594 else if (unformat (i, "disable"))
6598 clib_warning ("parse error '%U'", format_unformat_error, i);
6603 if (sw_if_index_set == 0)
6605 errmsg ("missing interface name or sw_if_index");
6609 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6611 mp->sw_if_index = ntohl (sw_if_index);
6612 mp->enable = enable;
6621 api_l2_patch_add_del (vat_main_t * vam)
6623 unformat_input_t *i = vam->input;
6624 vl_api_l2_patch_add_del_t *mp;
6626 u8 rx_sw_if_index_set = 0;
6628 u8 tx_sw_if_index_set = 0;
6632 /* Parse args required to build the message */
6633 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6635 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6636 rx_sw_if_index_set = 1;
6637 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6638 tx_sw_if_index_set = 1;
6639 else if (unformat (i, "rx"))
6641 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6643 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6645 rx_sw_if_index_set = 1;
6650 else if (unformat (i, "tx"))
6652 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6654 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6656 tx_sw_if_index_set = 1;
6661 else if (unformat (i, "del"))
6667 if (rx_sw_if_index_set == 0)
6669 errmsg ("missing rx interface name or rx_sw_if_index");
6673 if (tx_sw_if_index_set == 0)
6675 errmsg ("missing tx interface name or tx_sw_if_index");
6679 M (L2_PATCH_ADD_DEL, mp);
6681 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6682 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6683 mp->is_add = is_add;
6691 u8 localsid_addr[16];
6700 api_sr_localsid_add_del (vat_main_t * vam)
6702 unformat_input_t *i = vam->input;
6703 vl_api_sr_localsid_add_del_t *mp;
6706 ip6_address_t localsid;
6710 u32 fib_table = ~(u32) 0;
6711 ip46_address_t nh_addr;
6712 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6714 bool nexthop_set = 0;
6718 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6720 if (unformat (i, "del"))
6722 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6723 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6725 else if (unformat (i, "behavior %u", &behavior));
6726 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6727 else if (unformat (i, "fib-table %u", &fib_table));
6728 else if (unformat (i, "end.psp %u", &behavior));
6733 M (SR_LOCALSID_ADD_DEL, mp);
6735 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6739 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6741 mp->behavior = behavior;
6742 mp->sw_if_index = ntohl (sw_if_index);
6743 mp->fib_table = ntohl (fib_table);
6744 mp->end_psp = end_psp;
6745 mp->is_del = is_del;
6753 api_ioam_enable (vat_main_t * vam)
6755 unformat_input_t *input = vam->input;
6756 vl_api_ioam_enable_t *mp;
6758 int has_trace_option = 0;
6759 int has_pot_option = 0;
6760 int has_seqno_option = 0;
6761 int has_analyse_option = 0;
6764 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6766 if (unformat (input, "trace"))
6767 has_trace_option = 1;
6768 else if (unformat (input, "pot"))
6770 else if (unformat (input, "seqno"))
6771 has_seqno_option = 1;
6772 else if (unformat (input, "analyse"))
6773 has_analyse_option = 1;
6777 M (IOAM_ENABLE, mp);
6778 mp->id = htons (id);
6779 mp->seqno = has_seqno_option;
6780 mp->analyse = has_analyse_option;
6781 mp->pot_enable = has_pot_option;
6782 mp->trace_enable = has_trace_option;
6791 api_ioam_disable (vat_main_t * vam)
6793 vl_api_ioam_disable_t *mp;
6796 M (IOAM_DISABLE, mp);
6802 #define foreach_tcp_proto_field \
6806 #define foreach_udp_proto_field \
6810 #define foreach_ip4_proto_field \
6822 u16 src_port, dst_port;
6825 #if VPP_API_TEST_BUILTIN == 0
6827 unformat_tcp_mask (unformat_input_t * input, va_list * args)
6829 u8 **maskp = va_arg (*args, u8 **);
6831 u8 found_something = 0;
6834 #define _(a) u8 a=0;
6835 foreach_tcp_proto_field;
6838 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6841 #define _(a) else if (unformat (input, #a)) a=1;
6842 foreach_tcp_proto_field
6848 #define _(a) found_something += a;
6849 foreach_tcp_proto_field;
6852 if (found_something == 0)
6855 vec_validate (mask, sizeof (*tcp) - 1);
6857 tcp = (tcp_header_t *) mask;
6859 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
6860 foreach_tcp_proto_field;
6868 unformat_udp_mask (unformat_input_t * input, va_list * args)
6870 u8 **maskp = va_arg (*args, u8 **);
6872 u8 found_something = 0;
6875 #define _(a) u8 a=0;
6876 foreach_udp_proto_field;
6879 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6882 #define _(a) else if (unformat (input, #a)) a=1;
6883 foreach_udp_proto_field
6889 #define _(a) found_something += a;
6890 foreach_udp_proto_field;
6893 if (found_something == 0)
6896 vec_validate (mask, sizeof (*udp) - 1);
6898 udp = (udp_header_t *) mask;
6900 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
6901 foreach_udp_proto_field;
6909 unformat_l4_mask (unformat_input_t * input, va_list * args)
6911 u8 **maskp = va_arg (*args, u8 **);
6912 u16 src_port = 0, dst_port = 0;
6913 tcpudp_header_t *tcpudp;
6915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6917 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
6919 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
6921 else if (unformat (input, "src_port"))
6923 else if (unformat (input, "dst_port"))
6929 if (!src_port && !dst_port)
6933 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
6935 tcpudp = (tcpudp_header_t *) mask;
6936 tcpudp->src_port = src_port;
6937 tcpudp->dst_port = dst_port;
6945 unformat_ip4_mask (unformat_input_t * input, va_list * args)
6947 u8 **maskp = va_arg (*args, u8 **);
6949 u8 found_something = 0;
6952 #define _(a) u8 a=0;
6953 foreach_ip4_proto_field;
6959 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6961 if (unformat (input, "version"))
6963 else if (unformat (input, "hdr_length"))
6965 else if (unformat (input, "src"))
6967 else if (unformat (input, "dst"))
6969 else if (unformat (input, "proto"))
6972 #define _(a) else if (unformat (input, #a)) a=1;
6973 foreach_ip4_proto_field
6979 #define _(a) found_something += a;
6980 foreach_ip4_proto_field;
6983 if (found_something == 0)
6986 vec_validate (mask, sizeof (*ip) - 1);
6988 ip = (ip4_header_t *) mask;
6990 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
6991 foreach_ip4_proto_field;
6994 ip->ip_version_and_header_length = 0;
6997 ip->ip_version_and_header_length |= 0xF0;
7000 ip->ip_version_and_header_length |= 0x0F;
7006 #define foreach_ip6_proto_field \
7014 unformat_ip6_mask (unformat_input_t * input, va_list * args)
7016 u8 **maskp = va_arg (*args, u8 **);
7018 u8 found_something = 0;
7020 u32 ip_version_traffic_class_and_flow_label;
7022 #define _(a) u8 a=0;
7023 foreach_ip6_proto_field;
7026 u8 traffic_class = 0;
7029 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7031 if (unformat (input, "version"))
7033 else if (unformat (input, "traffic-class"))
7035 else if (unformat (input, "flow-label"))
7037 else if (unformat (input, "src"))
7039 else if (unformat (input, "dst"))
7041 else if (unformat (input, "proto"))
7044 #define _(a) else if (unformat (input, #a)) a=1;
7045 foreach_ip6_proto_field
7051 #define _(a) found_something += a;
7052 foreach_ip6_proto_field;
7055 if (found_something == 0)
7058 vec_validate (mask, sizeof (*ip) - 1);
7060 ip = (ip6_header_t *) mask;
7062 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
7063 foreach_ip6_proto_field;
7066 ip_version_traffic_class_and_flow_label = 0;
7069 ip_version_traffic_class_and_flow_label |= 0xF0000000;
7072 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
7075 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
7077 ip->ip_version_traffic_class_and_flow_label =
7078 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7085 unformat_l3_mask (unformat_input_t * input, va_list * args)
7087 u8 **maskp = va_arg (*args, u8 **);
7089 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7091 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
7093 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
7102 unformat_l2_mask (unformat_input_t * input, va_list * args)
7104 u8 **maskp = va_arg (*args, u8 **);
7119 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7121 if (unformat (input, "src"))
7123 else if (unformat (input, "dst"))
7125 else if (unformat (input, "proto"))
7127 else if (unformat (input, "tag1"))
7129 else if (unformat (input, "tag2"))
7131 else if (unformat (input, "ignore-tag1"))
7133 else if (unformat (input, "ignore-tag2"))
7135 else if (unformat (input, "cos1"))
7137 else if (unformat (input, "cos2"))
7139 else if (unformat (input, "dot1q"))
7141 else if (unformat (input, "dot1ad"))
7146 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7147 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7150 if (tag1 || ignore_tag1 || cos1 || dot1q)
7152 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7155 vec_validate (mask, len - 1);
7158 clib_memset (mask, 0xff, 6);
7161 clib_memset (mask + 6, 0xff, 6);
7165 /* inner vlan tag */
7174 mask[21] = mask[20] = 0xff;
7195 mask[16] = mask[17] = 0xff;
7205 mask[12] = mask[13] = 0xff;
7212 unformat_classify_mask (unformat_input_t * input, va_list * args)
7214 u8 **maskp = va_arg (*args, u8 **);
7215 u32 *skipp = va_arg (*args, u32 *);
7216 u32 *matchp = va_arg (*args, u32 *);
7224 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7226 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7228 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7230 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7232 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
7246 if (mask || l2 || l3 || l4)
7250 /* "With a free Ethernet header in every package" */
7252 vec_validate (l2, 13);
7256 vec_append (mask, l3);
7261 vec_append (mask, l4);
7266 /* Scan forward looking for the first significant mask octet */
7267 for (i = 0; i < vec_len (mask); i++)
7271 /* compute (skip, match) params */
7272 *skipp = i / sizeof (u32x4);
7273 vec_delete (mask, *skipp * sizeof (u32x4), 0);
7275 /* Pad mask to an even multiple of the vector size */
7276 while (vec_len (mask) % sizeof (u32x4))
7279 match = vec_len (mask) / sizeof (u32x4);
7281 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
7283 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
7284 if (*tmp || *(tmp + 1))
7289 clib_warning ("BUG: match 0");
7291 _vec_len (mask) = match * sizeof (u32x4);
7301 #endif /* VPP_API_TEST_BUILTIN */
7303 #define foreach_l2_next \
7305 _(ethernet, ETHERNET_INPUT) \
7310 unformat_l2_next_index (unformat_input_t * input, va_list * args)
7312 u32 *miss_next_indexp = va_arg (*args, u32 *);
7317 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
7321 if (unformat (input, "%d", &tmp))
7330 *miss_next_indexp = next_index;
7334 #define foreach_ip_next \
7340 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
7342 u32 *miss_next_indexp = va_arg (*args, u32 *);
7347 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7351 if (unformat (input, "%d", &tmp))
7360 *miss_next_indexp = next_index;
7364 #define foreach_acl_next \
7368 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
7370 u32 *miss_next_indexp = va_arg (*args, u32 *);
7375 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7379 if (unformat (input, "permit"))
7384 else if (unformat (input, "%d", &tmp))
7393 *miss_next_indexp = next_index;
7398 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7400 u32 *r = va_arg (*args, u32 *);
7402 if (unformat (input, "conform-color"))
7403 *r = POLICE_CONFORM;
7404 else if (unformat (input, "exceed-color"))
7412 #if VPP_API_TEST_BUILTIN == 0
7414 unformat_l4_match (unformat_input_t * input, va_list * args)
7416 u8 **matchp = va_arg (*args, u8 **);
7418 u8 *proto_header = 0;
7424 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7426 if (unformat (input, "src_port %d", &src_port))
7428 else if (unformat (input, "dst_port %d", &dst_port))
7434 h.src_port = clib_host_to_net_u16 (src_port);
7435 h.dst_port = clib_host_to_net_u16 (dst_port);
7436 vec_validate (proto_header, sizeof (h) - 1);
7437 memcpy (proto_header, &h, sizeof (h));
7439 *matchp = proto_header;
7445 unformat_ip4_match (unformat_input_t * input, va_list * args)
7447 u8 **matchp = va_arg (*args, u8 **);
7454 int src = 0, dst = 0;
7455 ip4_address_t src_val, dst_val;
7462 int fragment_id = 0;
7463 u32 fragment_id_val;
7469 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7471 if (unformat (input, "version %d", &version_val))
7473 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7475 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7477 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7479 else if (unformat (input, "proto %d", &proto_val))
7481 else if (unformat (input, "tos %d", &tos_val))
7483 else if (unformat (input, "length %d", &length_val))
7485 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7487 else if (unformat (input, "ttl %d", &ttl_val))
7489 else if (unformat (input, "checksum %d", &checksum_val))
7495 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7496 + ttl + checksum == 0)
7500 * Aligned because we use the real comparison functions
7502 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7504 ip = (ip4_header_t *) match;
7506 /* These are realistically matched in practice */
7508 ip->src_address.as_u32 = src_val.as_u32;
7511 ip->dst_address.as_u32 = dst_val.as_u32;
7514 ip->protocol = proto_val;
7517 /* These are not, but they're included for completeness */
7519 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7522 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7528 ip->length = clib_host_to_net_u16 (length_val);
7534 ip->checksum = clib_host_to_net_u16 (checksum_val);
7541 unformat_ip6_match (unformat_input_t * input, va_list * args)
7543 u8 **matchp = va_arg (*args, u8 **);
7548 u8 traffic_class = 0;
7549 u32 traffic_class_val = 0;
7552 int src = 0, dst = 0;
7553 ip6_address_t src_val, dst_val;
7556 int payload_length = 0;
7557 u32 payload_length_val;
7560 u32 ip_version_traffic_class_and_flow_label;
7562 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7564 if (unformat (input, "version %d", &version_val))
7566 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7568 else if (unformat (input, "flow_label %d", &flow_label_val))
7570 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7572 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7574 else if (unformat (input, "proto %d", &proto_val))
7576 else if (unformat (input, "payload_length %d", &payload_length_val))
7578 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7584 if (version + traffic_class + flow_label + src + dst + proto +
7585 payload_length + hop_limit == 0)
7589 * Aligned because we use the real comparison functions
7591 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7593 ip = (ip6_header_t *) match;
7596 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7599 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7602 ip->protocol = proto_val;
7604 ip_version_traffic_class_and_flow_label = 0;
7607 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7610 ip_version_traffic_class_and_flow_label |=
7611 (traffic_class_val & 0xFF) << 20;
7614 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7616 ip->ip_version_traffic_class_and_flow_label =
7617 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7620 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7623 ip->hop_limit = hop_limit_val;
7630 unformat_l3_match (unformat_input_t * input, va_list * args)
7632 u8 **matchp = va_arg (*args, u8 **);
7634 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7636 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7638 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7647 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7649 u8 *tagp = va_arg (*args, u8 *);
7652 if (unformat (input, "%d", &tag))
7654 tagp[0] = (tag >> 8) & 0x0F;
7655 tagp[1] = tag & 0xFF;
7663 unformat_l2_match (unformat_input_t * input, va_list * args)
7665 u8 **matchp = va_arg (*args, u8 **);
7685 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7687 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7690 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7692 else if (unformat (input, "proto %U",
7693 unformat_ethernet_type_host_byte_order, &proto_val))
7695 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7697 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7699 else if (unformat (input, "ignore-tag1"))
7701 else if (unformat (input, "ignore-tag2"))
7703 else if (unformat (input, "cos1 %d", &cos1_val))
7705 else if (unformat (input, "cos2 %d", &cos2_val))
7710 if ((src + dst + proto + tag1 + tag2 +
7711 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7714 if (tag1 || ignore_tag1 || cos1)
7716 if (tag2 || ignore_tag2 || cos2)
7719 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7722 clib_memcpy (match, dst_val, 6);
7725 clib_memcpy (match + 6, src_val, 6);
7729 /* inner vlan tag */
7730 match[19] = tag2_val[1];
7731 match[18] = tag2_val[0];
7733 match[18] |= (cos2_val & 0x7) << 5;
7736 match[21] = proto_val & 0xff;
7737 match[20] = proto_val >> 8;
7741 match[15] = tag1_val[1];
7742 match[14] = tag1_val[0];
7745 match[14] |= (cos1_val & 0x7) << 5;
7751 match[15] = tag1_val[1];
7752 match[14] = tag1_val[0];
7755 match[17] = proto_val & 0xff;
7756 match[16] = proto_val >> 8;
7759 match[14] |= (cos1_val & 0x7) << 5;
7765 match[18] |= (cos2_val & 0x7) << 5;
7767 match[14] |= (cos1_val & 0x7) << 5;
7770 match[13] = proto_val & 0xff;
7771 match[12] = proto_val >> 8;
7779 unformat_qos_source (unformat_input_t * input, va_list * args)
7781 int *qs = va_arg (*args, int *);
7783 if (unformat (input, "ip"))
7784 *qs = QOS_SOURCE_IP;
7785 else if (unformat (input, "mpls"))
7786 *qs = QOS_SOURCE_MPLS;
7787 else if (unformat (input, "ext"))
7788 *qs = QOS_SOURCE_EXT;
7789 else if (unformat (input, "vlan"))
7790 *qs = QOS_SOURCE_VLAN;
7799 api_unformat_classify_match (unformat_input_t * input, va_list * args)
7801 u8 **matchp = va_arg (*args, u8 **);
7802 u32 skip_n_vectors = va_arg (*args, u32);
7803 u32 match_n_vectors = va_arg (*args, u32);
7810 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7812 if (unformat (input, "hex %U", unformat_hex_string, &match))
7814 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7816 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7818 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
7832 if (match || l2 || l3 || l4)
7836 /* "Win a free Ethernet header in every packet" */
7838 vec_validate_aligned (l2, 13, sizeof (u32x4));
7842 vec_append_aligned (match, l3, sizeof (u32x4));
7847 vec_append_aligned (match, l4, sizeof (u32x4));
7852 /* Make sure the vector is big enough even if key is all 0's */
7853 vec_validate_aligned
7854 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
7857 /* Set size, include skipped vectors */
7858 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
7869 api_get_node_index (vat_main_t * vam)
7871 unformat_input_t *i = vam->input;
7872 vl_api_get_node_index_t *mp;
7876 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7878 if (unformat (i, "node %s", &name))
7885 errmsg ("node name required");
7888 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7890 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7894 M (GET_NODE_INDEX, mp);
7895 clib_memcpy (mp->node_name, name, vec_len (name));
7904 api_get_next_index (vat_main_t * vam)
7906 unformat_input_t *i = vam->input;
7907 vl_api_get_next_index_t *mp;
7908 u8 *node_name = 0, *next_node_name = 0;
7911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7913 if (unformat (i, "node-name %s", &node_name))
7915 else if (unformat (i, "next-node-name %s", &next_node_name))
7921 errmsg ("node name required");
7924 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
7926 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7930 if (next_node_name == 0)
7932 errmsg ("next node name required");
7935 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
7937 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
7941 M (GET_NEXT_INDEX, mp);
7942 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
7943 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
7944 vec_free (node_name);
7945 vec_free (next_node_name);
7953 api_add_node_next (vat_main_t * vam)
7955 unformat_input_t *i = vam->input;
7956 vl_api_add_node_next_t *mp;
7961 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7963 if (unformat (i, "node %s", &name))
7965 else if (unformat (i, "next %s", &next))
7972 errmsg ("node name required");
7975 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7977 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7982 errmsg ("next node required");
7985 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
7987 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
7991 M (ADD_NODE_NEXT, mp);
7992 clib_memcpy (mp->node_name, name, vec_len (name));
7993 clib_memcpy (mp->next_name, next, vec_len (next));
8002 static void vl_api_sw_interface_tap_v2_details_t_handler
8003 (vl_api_sw_interface_tap_v2_details_t * mp)
8005 vat_main_t *vam = &vat_main;
8008 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
8009 mp->host_ip4_prefix.len);
8011 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
8012 mp->host_ip6_prefix.len);
8015 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
8016 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
8017 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8018 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
8019 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
8025 static void vl_api_sw_interface_tap_v2_details_t_handler_json
8026 (vl_api_sw_interface_tap_v2_details_t * mp)
8028 vat_main_t *vam = &vat_main;
8029 vat_json_node_t *node = NULL;
8031 if (VAT_JSON_ARRAY != vam->json_tree.type)
8033 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8034 vat_json_init_array (&vam->json_tree);
8036 node = vat_json_array_add (&vam->json_tree);
8038 vat_json_init_object (node);
8039 vat_json_object_add_uint (node, "id", ntohl (mp->id));
8040 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8041 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
8042 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
8043 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8044 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8045 vat_json_object_add_string_copy (node, "host_mac_addr",
8046 format (0, "%U", format_ethernet_address,
8047 &mp->host_mac_addr));
8048 vat_json_object_add_string_copy (node, "host_namespace",
8049 mp->host_namespace);
8050 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
8051 vat_json_object_add_string_copy (node, "host_ip4_addr",
8052 format (0, "%U/%d", format_ip4_address,
8053 mp->host_ip4_prefix.address,
8054 mp->host_ip4_prefix.len));
8055 vat_json_object_add_string_copy (node, "host_ip6_prefix",
8056 format (0, "%U/%d", format_ip6_address,
8057 mp->host_ip6_prefix.address,
8058 mp->host_ip6_prefix.len));
8063 api_sw_interface_tap_v2_dump (vat_main_t * vam)
8065 vl_api_sw_interface_tap_v2_dump_t *mp;
8066 vl_api_control_ping_t *mp_ping;
8070 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
8071 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
8072 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
8075 /* Get list of tap interfaces */
8076 M (SW_INTERFACE_TAP_V2_DUMP, mp);
8079 /* Use a control ping for synchronization */
8080 MPING (CONTROL_PING, mp_ping);
8087 static void vl_api_sw_interface_virtio_pci_details_t_handler
8088 (vl_api_sw_interface_virtio_pci_details_t * mp)
8090 vat_main_t *vam = &vat_main;
8105 addr.domain = ntohs (mp->pci_addr.domain);
8106 addr.bus = mp->pci_addr.bus;
8107 addr.slot = mp->pci_addr.slot;
8108 addr.function = mp->pci_addr.function;
8110 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
8111 addr.slot, addr.function);
8114 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
8115 pci_addr, ntohl (mp->sw_if_index),
8116 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
8117 format_ethernet_address, mp->mac_addr,
8118 clib_net_to_host_u64 (mp->features));
8119 vec_free (pci_addr);
8122 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
8123 (vl_api_sw_interface_virtio_pci_details_t * mp)
8125 vat_main_t *vam = &vat_main;
8126 vat_json_node_t *node = NULL;
8127 vlib_pci_addr_t pci_addr;
8129 if (VAT_JSON_ARRAY != vam->json_tree.type)
8131 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8132 vat_json_init_array (&vam->json_tree);
8134 node = vat_json_array_add (&vam->json_tree);
8136 pci_addr.domain = ntohs (mp->pci_addr.domain);
8137 pci_addr.bus = mp->pci_addr.bus;
8138 pci_addr.slot = mp->pci_addr.slot;
8139 pci_addr.function = mp->pci_addr.function;
8141 vat_json_init_object (node);
8142 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
8143 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8144 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
8145 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
8146 vat_json_object_add_uint (node, "features",
8147 clib_net_to_host_u64 (mp->features));
8148 vat_json_object_add_string_copy (node, "mac_addr",
8149 format (0, "%U", format_ethernet_address,
8154 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
8156 vl_api_sw_interface_virtio_pci_dump_t *mp;
8157 vl_api_control_ping_t *mp_ping;
8161 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
8162 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
8163 "mac_addr", "features");
8165 /* Get list of tap interfaces */
8166 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
8169 /* Use a control ping for synchronization */
8170 MPING (CONTROL_PING, mp_ping);
8178 api_l2_fib_clear_table (vat_main_t * vam)
8180 // unformat_input_t * i = vam->input;
8181 vl_api_l2_fib_clear_table_t *mp;
8184 M (L2_FIB_CLEAR_TABLE, mp);
8192 api_l2_interface_efp_filter (vat_main_t * vam)
8194 unformat_input_t *i = vam->input;
8195 vl_api_l2_interface_efp_filter_t *mp;
8198 u8 sw_if_index_set = 0;
8201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8203 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8204 sw_if_index_set = 1;
8205 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8206 sw_if_index_set = 1;
8207 else if (unformat (i, "enable"))
8209 else if (unformat (i, "disable"))
8213 clib_warning ("parse error '%U'", format_unformat_error, i);
8218 if (sw_if_index_set == 0)
8220 errmsg ("missing sw_if_index");
8224 M (L2_INTERFACE_EFP_FILTER, mp);
8226 mp->sw_if_index = ntohl (sw_if_index);
8227 mp->enable_disable = enable;
8234 #define foreach_vtr_op \
8235 _("disable", L2_VTR_DISABLED) \
8236 _("push-1", L2_VTR_PUSH_1) \
8237 _("push-2", L2_VTR_PUSH_2) \
8238 _("pop-1", L2_VTR_POP_1) \
8239 _("pop-2", L2_VTR_POP_2) \
8240 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8241 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8242 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8243 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8246 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8248 unformat_input_t *i = vam->input;
8249 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8251 u8 sw_if_index_set = 0;
8259 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8261 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8262 sw_if_index_set = 1;
8263 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8264 sw_if_index_set = 1;
8265 else if (unformat (i, "vtr_op %d", &vtr_op))
8267 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8270 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8272 else if (unformat (i, "tag1 %d", &tag1))
8274 else if (unformat (i, "tag2 %d", &tag2))
8278 clib_warning ("parse error '%U'", format_unformat_error, i);
8283 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
8285 errmsg ("missing vtr operation or sw_if_index");
8289 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
8290 mp->sw_if_index = ntohl (sw_if_index);
8291 mp->vtr_op = ntohl (vtr_op);
8292 mp->push_dot1q = ntohl (push_dot1q);
8293 mp->tag1 = ntohl (tag1);
8294 mp->tag2 = ntohl (tag2);
8302 api_create_vhost_user_if (vat_main_t * vam)
8304 unformat_input_t *i = vam->input;
8305 vl_api_create_vhost_user_if_t *mp;
8308 u8 file_name_set = 0;
8309 u32 custom_dev_instance = ~0;
8311 u8 use_custom_mac = 0;
8312 u8 disable_mrg_rxbuf = 0;
8313 u8 disable_indirect_desc = 0;
8316 u8 enable_packed = 0;
8319 /* Shut up coverity */
8320 clib_memset (hwaddr, 0, sizeof (hwaddr));
8322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8324 if (unformat (i, "socket %s", &file_name))
8328 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8330 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8332 else if (unformat (i, "server"))
8334 else if (unformat (i, "disable_mrg_rxbuf"))
8335 disable_mrg_rxbuf = 1;
8336 else if (unformat (i, "disable_indirect_desc"))
8337 disable_indirect_desc = 1;
8338 else if (unformat (i, "gso"))
8340 else if (unformat (i, "packed"))
8342 else if (unformat (i, "tag %s", &tag))
8348 if (file_name_set == 0)
8350 errmsg ("missing socket file name");
8354 if (vec_len (file_name) > 255)
8356 errmsg ("socket file name too long");
8359 vec_add1 (file_name, 0);
8361 M (CREATE_VHOST_USER_IF, mp);
8363 mp->is_server = is_server;
8364 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8365 mp->disable_indirect_desc = disable_indirect_desc;
8366 mp->enable_gso = enable_gso;
8367 mp->enable_packed = enable_packed;
8368 mp->custom_dev_instance = ntohl (custom_dev_instance);
8369 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8370 vec_free (file_name);
8371 if (custom_dev_instance != ~0)
8374 mp->use_custom_mac = use_custom_mac;
8375 clib_memcpy (mp->mac_address, hwaddr, 6);
8377 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8386 api_modify_vhost_user_if (vat_main_t * vam)
8388 unformat_input_t *i = vam->input;
8389 vl_api_modify_vhost_user_if_t *mp;
8392 u8 file_name_set = 0;
8393 u32 custom_dev_instance = ~0;
8394 u8 sw_if_index_set = 0;
8395 u32 sw_if_index = (u32) ~ 0;
8397 u8 enable_packed = 0;
8400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8402 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8403 sw_if_index_set = 1;
8404 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8405 sw_if_index_set = 1;
8406 else if (unformat (i, "socket %s", &file_name))
8410 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8412 else if (unformat (i, "server"))
8414 else if (unformat (i, "gso"))
8416 else if (unformat (i, "packed"))
8422 if (sw_if_index_set == 0)
8424 errmsg ("missing sw_if_index or interface name");
8428 if (file_name_set == 0)
8430 errmsg ("missing socket file name");
8434 if (vec_len (file_name) > 255)
8436 errmsg ("socket file name too long");
8439 vec_add1 (file_name, 0);
8441 M (MODIFY_VHOST_USER_IF, mp);
8443 mp->sw_if_index = ntohl (sw_if_index);
8444 mp->is_server = is_server;
8445 mp->enable_gso = enable_gso;
8446 mp->enable_packed = enable_packed;
8447 mp->custom_dev_instance = ntohl (custom_dev_instance);
8448 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8449 vec_free (file_name);
8450 if (custom_dev_instance != ~0)
8459 api_create_vhost_user_if_v2 (vat_main_t * vam)
8461 unformat_input_t *i = vam->input;
8462 vl_api_create_vhost_user_if_v2_t *mp;
8465 u8 file_name_set = 0;
8466 u32 custom_dev_instance = ~0;
8468 u8 use_custom_mac = 0;
8469 u8 disable_mrg_rxbuf = 0;
8470 u8 disable_indirect_desc = 0;
8473 u8 enable_packed = 0;
8474 u8 enable_event_idx = 0;
8477 /* Shut up coverity */
8478 clib_memset (hwaddr, 0, sizeof (hwaddr));
8480 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8482 if (unformat (i, "socket %s", &file_name))
8486 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8488 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8490 else if (unformat (i, "server"))
8492 else if (unformat (i, "disable_mrg_rxbuf"))
8493 disable_mrg_rxbuf = 1;
8494 else if (unformat (i, "disable_indirect_desc"))
8495 disable_indirect_desc = 1;
8496 else if (unformat (i, "gso"))
8498 else if (unformat (i, "packed"))
8500 else if (unformat (i, "event-idx"))
8501 enable_event_idx = 1;
8502 else if (unformat (i, "tag %s", &tag))
8508 if (file_name_set == 0)
8510 errmsg ("missing socket file name");
8514 if (vec_len (file_name) > 255)
8516 errmsg ("socket file name too long");
8519 vec_add1 (file_name, 0);
8521 M (CREATE_VHOST_USER_IF_V2, mp);
8523 mp->is_server = is_server;
8524 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8525 mp->disable_indirect_desc = disable_indirect_desc;
8526 mp->enable_gso = enable_gso;
8527 mp->enable_packed = enable_packed;
8528 mp->enable_event_idx = enable_event_idx;
8529 mp->custom_dev_instance = ntohl (custom_dev_instance);
8530 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8531 vec_free (file_name);
8532 if (custom_dev_instance != ~0)
8535 mp->use_custom_mac = use_custom_mac;
8536 clib_memcpy (mp->mac_address, hwaddr, 6);
8538 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8547 api_modify_vhost_user_if_v2 (vat_main_t * vam)
8549 unformat_input_t *i = vam->input;
8550 vl_api_modify_vhost_user_if_v2_t *mp;
8553 u8 file_name_set = 0;
8554 u32 custom_dev_instance = ~0;
8555 u8 sw_if_index_set = 0;
8556 u32 sw_if_index = (u32) ~ 0;
8558 u8 enable_packed = 0;
8559 u8 enable_event_idx = 0;
8562 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8564 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8565 sw_if_index_set = 1;
8566 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8567 sw_if_index_set = 1;
8568 else if (unformat (i, "socket %s", &file_name))
8572 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8574 else if (unformat (i, "server"))
8576 else if (unformat (i, "gso"))
8578 else if (unformat (i, "packed"))
8580 else if (unformat (i, "event-idx"))
8581 enable_event_idx = 1;
8586 if (sw_if_index_set == 0)
8588 errmsg ("missing sw_if_index or interface name");
8592 if (file_name_set == 0)
8594 errmsg ("missing socket file name");
8598 if (vec_len (file_name) > 255)
8600 errmsg ("socket file name too long");
8603 vec_add1 (file_name, 0);
8605 M (MODIFY_VHOST_USER_IF_V2, mp);
8607 mp->sw_if_index = ntohl (sw_if_index);
8608 mp->is_server = is_server;
8609 mp->enable_gso = enable_gso;
8610 mp->enable_packed = enable_packed;
8611 mp->enable_event_idx = enable_event_idx;
8612 mp->custom_dev_instance = ntohl (custom_dev_instance);
8613 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8614 vec_free (file_name);
8615 if (custom_dev_instance != ~0)
8624 api_delete_vhost_user_if (vat_main_t * vam)
8626 unformat_input_t *i = vam->input;
8627 vl_api_delete_vhost_user_if_t *mp;
8628 u32 sw_if_index = ~0;
8629 u8 sw_if_index_set = 0;
8632 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8634 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8635 sw_if_index_set = 1;
8636 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8637 sw_if_index_set = 1;
8642 if (sw_if_index_set == 0)
8644 errmsg ("missing sw_if_index or interface name");
8649 M (DELETE_VHOST_USER_IF, mp);
8651 mp->sw_if_index = ntohl (sw_if_index);
8658 static void vl_api_sw_interface_vhost_user_details_t_handler
8659 (vl_api_sw_interface_vhost_user_details_t * mp)
8661 vat_main_t *vam = &vat_main;
8665 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
8666 clib_net_to_host_u32
8667 (mp->features_last_32) <<
8670 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
8671 (char *) mp->interface_name, ntohl (mp->sw_if_index),
8672 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
8673 ntohl (mp->num_regions), (char *) mp->sock_filename);
8674 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
8677 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8678 (vl_api_sw_interface_vhost_user_details_t * mp)
8680 vat_main_t *vam = &vat_main;
8681 vat_json_node_t *node = NULL;
8683 if (VAT_JSON_ARRAY != vam->json_tree.type)
8685 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8686 vat_json_init_array (&vam->json_tree);
8688 node = vat_json_array_add (&vam->json_tree);
8690 vat_json_init_object (node);
8691 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8692 vat_json_object_add_string_copy (node, "interface_name",
8693 mp->interface_name);
8694 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
8695 ntohl (mp->virtio_net_hdr_sz));
8696 vat_json_object_add_uint (node, "features_first_32",
8697 clib_net_to_host_u32 (mp->features_first_32));
8698 vat_json_object_add_uint (node, "features_last_32",
8699 clib_net_to_host_u32 (mp->features_last_32));
8700 vat_json_object_add_uint (node, "is_server", mp->is_server);
8701 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
8702 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
8703 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
8707 api_sw_interface_vhost_user_dump (vat_main_t * vam)
8709 unformat_input_t *i = vam->input;
8710 vl_api_sw_interface_vhost_user_dump_t *mp;
8711 vl_api_control_ping_t *mp_ping;
8713 u32 sw_if_index = ~0;
8715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8717 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8719 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8725 print (vam->ofp, "Interface name idx hdr_sz features "
8726 "server regions filename");
8728 /* Get list of vhost-user interfaces */
8729 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
8730 mp->sw_if_index = ntohl (sw_if_index);
8733 /* Use a control ping for synchronization */
8734 MPING (CONTROL_PING, mp_ping);
8742 api_show_version (vat_main_t * vam)
8744 vl_api_show_version_t *mp;
8747 M (SHOW_VERSION, mp);
8754 static void vl_api_l2_fib_table_details_t_handler
8755 (vl_api_l2_fib_table_details_t * mp)
8757 vat_main_t *vam = &vat_main;
8759 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8761 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
8762 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
8766 static void vl_api_l2_fib_table_details_t_handler_json
8767 (vl_api_l2_fib_table_details_t * mp)
8769 vat_main_t *vam = &vat_main;
8770 vat_json_node_t *node = NULL;
8772 if (VAT_JSON_ARRAY != vam->json_tree.type)
8774 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8775 vat_json_init_array (&vam->json_tree);
8777 node = vat_json_array_add (&vam->json_tree);
8779 vat_json_init_object (node);
8780 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
8781 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
8782 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8783 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
8784 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
8785 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
8789 api_l2_fib_table_dump (vat_main_t * vam)
8791 unformat_input_t *i = vam->input;
8792 vl_api_l2_fib_table_dump_t *mp;
8793 vl_api_control_ping_t *mp_ping;
8798 /* Parse args required to build the message */
8799 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8801 if (unformat (i, "bd_id %d", &bd_id))
8809 errmsg ("missing bridge domain");
8813 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
8815 /* Get list of l2 fib entries */
8816 M (L2_FIB_TABLE_DUMP, mp);
8818 mp->bd_id = ntohl (bd_id);
8821 /* Use a control ping for synchronization */
8822 MPING (CONTROL_PING, mp_ping);
8831 api_interface_name_renumber (vat_main_t * vam)
8833 unformat_input_t *line_input = vam->input;
8834 vl_api_interface_name_renumber_t *mp;
8835 u32 sw_if_index = ~0;
8836 u32 new_show_dev_instance = ~0;
8839 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8841 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
8844 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8846 else if (unformat (line_input, "new_show_dev_instance %d",
8847 &new_show_dev_instance))
8853 if (sw_if_index == ~0)
8855 errmsg ("missing interface name or sw_if_index");
8859 if (new_show_dev_instance == ~0)
8861 errmsg ("missing new_show_dev_instance");
8865 M (INTERFACE_NAME_RENUMBER, mp);
8867 mp->sw_if_index = ntohl (sw_if_index);
8868 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8876 api_want_l2_macs_events (vat_main_t * vam)
8878 unformat_input_t *line_input = vam->input;
8879 vl_api_want_l2_macs_events_t *mp;
8880 u8 enable_disable = 1;
8882 u32 max_macs_in_event = 0;
8883 u32 learn_limit = 0;
8886 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8888 if (unformat (line_input, "learn-limit %d", &learn_limit))
8890 else if (unformat (line_input, "scan-delay %d", &scan_delay))
8892 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
8894 else if (unformat (line_input, "disable"))
8900 M (WANT_L2_MACS_EVENTS, mp);
8901 mp->enable_disable = enable_disable;
8902 mp->pid = htonl (getpid ());
8903 mp->learn_limit = htonl (learn_limit);
8904 mp->scan_delay = (u8) scan_delay;
8905 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
8912 api_ip_address_dump (vat_main_t * vam)
8914 unformat_input_t *i = vam->input;
8915 vl_api_ip_address_dump_t *mp;
8916 vl_api_control_ping_t *mp_ping;
8917 u32 sw_if_index = ~0;
8918 u8 sw_if_index_set = 0;
8923 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8925 if (unformat (i, "sw_if_index %d", &sw_if_index))
8926 sw_if_index_set = 1;
8928 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8929 sw_if_index_set = 1;
8930 else if (unformat (i, "ipv4"))
8932 else if (unformat (i, "ipv6"))
8938 if (ipv4_set && ipv6_set)
8940 errmsg ("ipv4 and ipv6 flags cannot be both set");
8944 if ((!ipv4_set) && (!ipv6_set))
8946 errmsg ("no ipv4 nor ipv6 flag set");
8950 if (sw_if_index_set == 0)
8952 errmsg ("missing interface name or sw_if_index");
8956 vam->current_sw_if_index = sw_if_index;
8957 vam->is_ipv6 = ipv6_set;
8959 M (IP_ADDRESS_DUMP, mp);
8960 mp->sw_if_index = ntohl (sw_if_index);
8961 mp->is_ipv6 = ipv6_set;
8964 /* Use a control ping for synchronization */
8965 MPING (CONTROL_PING, mp_ping);
8973 api_ip_dump (vat_main_t * vam)
8975 vl_api_ip_dump_t *mp;
8976 vl_api_control_ping_t *mp_ping;
8977 unformat_input_t *in = vam->input;
8984 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
8986 if (unformat (in, "ipv4"))
8988 else if (unformat (in, "ipv6"))
8994 if (ipv4_set && ipv6_set)
8996 errmsg ("ipv4 and ipv6 flags cannot be both set");
9000 if ((!ipv4_set) && (!ipv6_set))
9002 errmsg ("no ipv4 nor ipv6 flag set");
9007 vam->is_ipv6 = is_ipv6;
9010 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
9012 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9014 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
9017 mp->is_ipv6 = ipv6_set;
9020 /* Use a control ping for synchronization */
9021 MPING (CONTROL_PING, mp_ping);
9029 api_ipsec_spd_add_del (vat_main_t * vam)
9031 unformat_input_t *i = vam->input;
9032 vl_api_ipsec_spd_add_del_t *mp;
9037 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9039 if (unformat (i, "spd_id %d", &spd_id))
9041 else if (unformat (i, "del"))
9045 clib_warning ("parse error '%U'", format_unformat_error, i);
9051 errmsg ("spd_id must be set");
9055 M (IPSEC_SPD_ADD_DEL, mp);
9057 mp->spd_id = ntohl (spd_id);
9058 mp->is_add = is_add;
9066 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9068 unformat_input_t *i = vam->input;
9069 vl_api_ipsec_interface_add_del_spd_t *mp;
9071 u8 sw_if_index_set = 0;
9072 u32 spd_id = (u32) ~ 0;
9076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9078 if (unformat (i, "del"))
9080 else if (unformat (i, "spd_id %d", &spd_id))
9083 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9084 sw_if_index_set = 1;
9085 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9086 sw_if_index_set = 1;
9089 clib_warning ("parse error '%U'", format_unformat_error, i);
9095 if (spd_id == (u32) ~ 0)
9097 errmsg ("spd_id must be set");
9101 if (sw_if_index_set == 0)
9103 errmsg ("missing interface name or sw_if_index");
9107 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
9109 mp->spd_id = ntohl (spd_id);
9110 mp->sw_if_index = ntohl (sw_if_index);
9111 mp->is_add = is_add;
9119 api_ipsec_spd_entry_add_del (vat_main_t * vam)
9121 unformat_input_t *i = vam->input;
9122 vl_api_ipsec_spd_entry_add_del_t *mp;
9123 u8 is_add = 1, is_outbound = 0;
9124 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
9126 u32 rport_start = 0, rport_stop = (u32) ~ 0;
9127 u32 lport_start = 0, lport_stop = (u32) ~ 0;
9128 vl_api_address_t laddr_start = { }, laddr_stop =
9137 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9139 if (unformat (i, "del"))
9141 if (unformat (i, "outbound"))
9143 if (unformat (i, "inbound"))
9145 else if (unformat (i, "spd_id %d", &spd_id))
9147 else if (unformat (i, "sa_id %d", &sa_id))
9149 else if (unformat (i, "priority %d", &priority))
9151 else if (unformat (i, "protocol %d", &protocol))
9153 else if (unformat (i, "lport_start %d", &lport_start))
9155 else if (unformat (i, "lport_stop %d", &lport_stop))
9157 else if (unformat (i, "rport_start %d", &rport_start))
9159 else if (unformat (i, "rport_stop %d", &rport_stop))
9161 else if (unformat (i, "laddr_start %U",
9162 unformat_vl_api_address, &laddr_start))
9164 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
9167 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
9170 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
9174 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9176 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
9178 clib_warning ("unsupported action: 'resolve'");
9184 clib_warning ("parse error '%U'", format_unformat_error, i);
9190 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
9192 mp->is_add = is_add;
9194 mp->entry.spd_id = ntohl (spd_id);
9195 mp->entry.priority = ntohl (priority);
9196 mp->entry.is_outbound = is_outbound;
9198 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
9199 sizeof (vl_api_address_t));
9200 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
9201 sizeof (vl_api_address_t));
9202 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
9203 sizeof (vl_api_address_t));
9204 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
9205 sizeof (vl_api_address_t));
9207 mp->entry.protocol = (u8) protocol;
9208 mp->entry.local_port_start = ntohs ((u16) lport_start);
9209 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
9210 mp->entry.remote_port_start = ntohs ((u16) rport_start);
9211 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
9212 mp->entry.policy = (u8) policy;
9213 mp->entry.sa_id = ntohl (sa_id);
9221 api_ipsec_sad_entry_add_del (vat_main_t * vam)
9223 unformat_input_t *i = vam->input;
9224 vl_api_ipsec_sad_entry_add_del_t *mp;
9225 u32 sad_id = 0, spi = 0;
9226 u8 *ck = 0, *ik = 0;
9229 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
9230 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
9231 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
9232 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
9233 vl_api_address_t tun_src, tun_dst;
9236 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9238 if (unformat (i, "del"))
9240 else if (unformat (i, "sad_id %d", &sad_id))
9242 else if (unformat (i, "spi %d", &spi))
9244 else if (unformat (i, "esp"))
9245 protocol = IPSEC_API_PROTO_ESP;
9247 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
9249 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9250 if (ADDRESS_IP6 == tun_src.af)
9251 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9254 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
9256 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
9257 if (ADDRESS_IP6 == tun_src.af)
9258 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
9261 if (unformat (i, "crypto_alg %U",
9262 unformat_ipsec_api_crypto_alg, &crypto_alg))
9264 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9266 else if (unformat (i, "integ_alg %U",
9267 unformat_ipsec_api_integ_alg, &integ_alg))
9269 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9273 clib_warning ("parse error '%U'", format_unformat_error, i);
9279 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
9281 mp->is_add = is_add;
9282 mp->entry.sad_id = ntohl (sad_id);
9283 mp->entry.protocol = protocol;
9284 mp->entry.spi = ntohl (spi);
9285 mp->entry.flags = flags;
9287 mp->entry.crypto_algorithm = crypto_alg;
9288 mp->entry.integrity_algorithm = integ_alg;
9289 mp->entry.crypto_key.length = vec_len (ck);
9290 mp->entry.integrity_key.length = vec_len (ik);
9292 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
9293 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
9295 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
9296 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
9299 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
9301 clib_memcpy (mp->entry.integrity_key.data, ik,
9302 mp->entry.integrity_key.length);
9304 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
9306 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
9307 sizeof (mp->entry.tunnel_src));
9308 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
9309 sizeof (mp->entry.tunnel_dst));
9318 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
9320 vat_main_t *vam = &vat_main;
9322 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
9323 "crypto_key %U integ_alg %u integ_key %U flags %x "
9324 "tunnel_src_addr %U tunnel_dst_addr %U "
9325 "salt %u seq_outbound %lu last_seq_inbound %lu "
9326 "replay_window %lu stat_index %u\n",
9327 ntohl (mp->entry.sad_id),
9328 ntohl (mp->sw_if_index),
9329 ntohl (mp->entry.spi),
9330 ntohl (mp->entry.protocol),
9331 ntohl (mp->entry.crypto_algorithm),
9332 format_hex_bytes, mp->entry.crypto_key.data,
9333 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
9334 format_hex_bytes, mp->entry.integrity_key.data,
9335 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
9336 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
9337 &mp->entry.tunnel_dst, ntohl (mp->salt),
9338 clib_net_to_host_u64 (mp->seq_outbound),
9339 clib_net_to_host_u64 (mp->last_seq_inbound),
9340 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
9343 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
9344 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
9346 static void vl_api_ipsec_sa_details_t_handler_json
9347 (vl_api_ipsec_sa_details_t * mp)
9349 vat_main_t *vam = &vat_main;
9350 vat_json_node_t *node = NULL;
9351 vl_api_ipsec_sad_flags_t flags;
9353 if (VAT_JSON_ARRAY != vam->json_tree.type)
9355 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9356 vat_json_init_array (&vam->json_tree);
9358 node = vat_json_array_add (&vam->json_tree);
9360 vat_json_init_object (node);
9361 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
9362 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9363 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
9364 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
9365 vat_json_object_add_uint (node, "crypto_alg",
9366 ntohl (mp->entry.crypto_algorithm));
9367 vat_json_object_add_uint (node, "integ_alg",
9368 ntohl (mp->entry.integrity_algorithm));
9369 flags = ntohl (mp->entry.flags);
9370 vat_json_object_add_uint (node, "use_esn",
9371 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
9372 vat_json_object_add_uint (node, "use_anti_replay",
9373 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
9374 vat_json_object_add_uint (node, "is_tunnel",
9375 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
9376 vat_json_object_add_uint (node, "is_tunnel_ip6",
9377 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
9378 vat_json_object_add_uint (node, "udp_encap",
9379 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
9380 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
9381 mp->entry.crypto_key.length);
9382 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
9383 mp->entry.integrity_key.length);
9384 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
9385 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
9386 vat_json_object_add_uint (node, "replay_window",
9387 clib_net_to_host_u64 (mp->replay_window));
9388 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
9392 api_ipsec_sa_dump (vat_main_t * vam)
9394 unformat_input_t *i = vam->input;
9395 vl_api_ipsec_sa_dump_t *mp;
9396 vl_api_control_ping_t *mp_ping;
9400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9402 if (unformat (i, "sa_id %d", &sa_id))
9406 clib_warning ("parse error '%U'", format_unformat_error, i);
9411 M (IPSEC_SA_DUMP, mp);
9413 mp->sa_id = ntohl (sa_id);
9417 /* Use a control ping for synchronization */
9418 M (CONTROL_PING, mp_ping);
9426 api_get_first_msg_id (vat_main_t * vam)
9428 vl_api_get_first_msg_id_t *mp;
9429 unformat_input_t *i = vam->input;
9434 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9436 if (unformat (i, "client %s", &name))
9444 errmsg ("missing client name");
9449 if (vec_len (name) > 63)
9451 errmsg ("client name too long");
9455 M (GET_FIRST_MSG_ID, mp);
9456 clib_memcpy (mp->name, name, vec_len (name));
9463 api_get_node_graph (vat_main_t * vam)
9465 vl_api_get_node_graph_t *mp;
9468 M (GET_NODE_GRAPH, mp);
9472 /* Wait for the reply */
9478 api_af_packet_create (vat_main_t * vam)
9480 unformat_input_t *i = vam->input;
9481 vl_api_af_packet_create_t *mp;
9482 u8 *host_if_name = 0;
9484 u8 random_hw_addr = 1;
9487 clib_memset (hw_addr, 0, sizeof (hw_addr));
9489 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9491 if (unformat (i, "name %s", &host_if_name))
9492 vec_add1 (host_if_name, 0);
9493 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
9499 if (!vec_len (host_if_name))
9501 errmsg ("host-interface name must be specified");
9505 if (vec_len (host_if_name) > 64)
9507 errmsg ("host-interface name too long");
9511 M (AF_PACKET_CREATE, mp);
9513 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9514 clib_memcpy (mp->hw_addr, hw_addr, 6);
9515 mp->use_random_hw_addr = random_hw_addr;
9516 vec_free (host_if_name);
9524 fprintf (vam->ofp ? vam->ofp : stderr,
9525 " new sw_if_index = %d\n", vam->sw_if_index);
9532 api_af_packet_delete (vat_main_t * vam)
9534 unformat_input_t *i = vam->input;
9535 vl_api_af_packet_delete_t *mp;
9536 u8 *host_if_name = 0;
9539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9541 if (unformat (i, "name %s", &host_if_name))
9542 vec_add1 (host_if_name, 0);
9547 if (!vec_len (host_if_name))
9549 errmsg ("host-interface name must be specified");
9553 if (vec_len (host_if_name) > 64)
9555 errmsg ("host-interface name too long");
9559 M (AF_PACKET_DELETE, mp);
9561 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9562 vec_free (host_if_name);
9569 static void vl_api_af_packet_details_t_handler
9570 (vl_api_af_packet_details_t * mp)
9572 vat_main_t *vam = &vat_main;
9574 print (vam->ofp, "%-16s %d",
9575 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
9578 static void vl_api_af_packet_details_t_handler_json
9579 (vl_api_af_packet_details_t * mp)
9581 vat_main_t *vam = &vat_main;
9582 vat_json_node_t *node = NULL;
9584 if (VAT_JSON_ARRAY != vam->json_tree.type)
9586 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9587 vat_json_init_array (&vam->json_tree);
9589 node = vat_json_array_add (&vam->json_tree);
9591 vat_json_init_object (node);
9592 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9593 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
9597 api_af_packet_dump (vat_main_t * vam)
9599 vl_api_af_packet_dump_t *mp;
9600 vl_api_control_ping_t *mp_ping;
9603 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
9604 /* Get list of tap interfaces */
9605 M (AF_PACKET_DUMP, mp);
9608 /* Use a control ping for synchronization */
9609 MPING (CONTROL_PING, mp_ping);
9617 api_policer_add_del (vat_main_t * vam)
9619 unformat_input_t *i = vam->input;
9620 vl_api_policer_add_del_t *mp;
9631 qos_pol_action_params_st conform_action, exceed_action, violate_action;
9634 conform_action.action_type = QOS_ACTION_TRANSMIT;
9635 conform_action.dscp = 0;
9636 exceed_action.action_type = QOS_ACTION_MARK_AND_TRANSMIT;
9637 exceed_action.dscp = 0;
9638 violate_action.action_type = QOS_ACTION_DROP;
9639 violate_action.dscp = 0;
9641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9643 if (unformat (i, "del"))
9645 else if (unformat (i, "name %s", &name))
9647 else if (unformat (i, "cir %u", &cir))
9649 else if (unformat (i, "eir %u", &eir))
9651 else if (unformat (i, "cb %u", &cb))
9653 else if (unformat (i, "eb %u", &eb))
9655 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
9658 else if (unformat (i, "round_type %U", unformat_policer_round_type,
9661 else if (unformat (i, "type %U", unformat_policer_type, &type))
9663 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
9666 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
9669 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
9672 else if (unformat (i, "color-aware"))
9678 if (!vec_len (name))
9680 errmsg ("policer name must be specified");
9684 if (vec_len (name) > 64)
9686 errmsg ("policer name too long");
9690 M (POLICER_ADD_DEL, mp);
9692 clib_memcpy (mp->name, name, vec_len (name));
9694 mp->is_add = is_add;
9695 mp->cir = ntohl (cir);
9696 mp->eir = ntohl (eir);
9697 mp->cb = clib_net_to_host_u64 (cb);
9698 mp->eb = clib_net_to_host_u64 (eb);
9699 mp->rate_type = rate_type;
9700 mp->round_type = round_type;
9702 mp->conform_action.type =
9703 (vl_api_sse2_qos_action_type_t) conform_action.action_type;
9704 mp->conform_action.dscp = conform_action.dscp;
9705 mp->exceed_action.type =
9706 (vl_api_sse2_qos_action_type_t) exceed_action.action_type;
9707 mp->exceed_action.dscp = exceed_action.dscp;
9708 mp->violate_action.type =
9709 (vl_api_sse2_qos_action_type_t) violate_action.action_type;
9710 mp->violate_action.dscp = violate_action.dscp;
9711 mp->color_aware = color_aware;
9719 api_policer_dump (vat_main_t * vam)
9721 unformat_input_t *i = vam->input;
9722 vl_api_policer_dump_t *mp;
9723 vl_api_control_ping_t *mp_ping;
9725 u8 match_name_valid = 0;
9728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9730 if (unformat (i, "name %s", &match_name))
9732 vec_add1 (match_name, 0);
9733 match_name_valid = 1;
9739 M (POLICER_DUMP, mp);
9740 mp->match_name_valid = match_name_valid;
9741 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
9742 vec_free (match_name);
9746 /* Use a control ping for synchronization */
9747 MPING (CONTROL_PING, mp_ping);
9750 /* Wait for a reply... */
9756 format_fib_api_path_nh_proto (u8 * s, va_list * args)
9758 vl_api_fib_path_nh_proto_t proto =
9759 va_arg (*args, vl_api_fib_path_nh_proto_t);
9763 case FIB_API_PATH_NH_PROTO_IP4:
9764 s = format (s, "ip4");
9766 case FIB_API_PATH_NH_PROTO_IP6:
9767 s = format (s, "ip6");
9769 case FIB_API_PATH_NH_PROTO_MPLS:
9770 s = format (s, "mpls");
9772 case FIB_API_PATH_NH_PROTO_BIER:
9773 s = format (s, "bier");
9775 case FIB_API_PATH_NH_PROTO_ETHERNET:
9776 s = format (s, "ethernet");
9784 format_vl_api_ip_address_union (u8 * s, va_list * args)
9786 vl_api_address_family_t af = va_arg (*args, int);
9787 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
9792 s = format (s, "%U", format_ip4_address, u->ip4);
9795 s = format (s, "%U", format_ip6_address, u->ip6);
9802 format_vl_api_fib_path_type (u8 * s, va_list * args)
9804 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
9808 case FIB_API_PATH_TYPE_NORMAL:
9809 s = format (s, "normal");
9811 case FIB_API_PATH_TYPE_LOCAL:
9812 s = format (s, "local");
9814 case FIB_API_PATH_TYPE_DROP:
9815 s = format (s, "drop");
9817 case FIB_API_PATH_TYPE_UDP_ENCAP:
9818 s = format (s, "udp-encap");
9820 case FIB_API_PATH_TYPE_BIER_IMP:
9821 s = format (s, "bier-imp");
9823 case FIB_API_PATH_TYPE_ICMP_UNREACH:
9824 s = format (s, "unreach");
9826 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
9827 s = format (s, "prohibit");
9829 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
9830 s = format (s, "src-lookup");
9832 case FIB_API_PATH_TYPE_DVR:
9833 s = format (s, "dvr");
9835 case FIB_API_PATH_TYPE_INTERFACE_RX:
9836 s = format (s, "interface-rx");
9838 case FIB_API_PATH_TYPE_CLASSIFY:
9839 s = format (s, "classify");
9847 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
9850 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
9851 ntohl (fp->weight), ntohl (fp->sw_if_index),
9852 format_vl_api_fib_path_type, fp->type,
9853 format_fib_api_path_nh_proto, fp->proto,
9854 format_vl_api_ip_address_union, &fp->nh.address);
9858 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
9859 vl_api_fib_path_t * fp)
9862 struct in6_addr ip6;
9864 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
9865 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
9866 vat_json_object_add_uint (node, "type", fp->type);
9867 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
9868 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
9870 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
9871 vat_json_object_add_ip4 (node, "next_hop", ip4);
9873 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
9875 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
9876 vat_json_object_add_ip6 (node, "next_hop", ip6);
9881 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
9883 vat_main_t *vam = &vat_main;
9884 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9885 vl_api_fib_path_t *fp;
9888 print (vam->ofp, "sw_if_index %d via:",
9889 ntohl (mp->mt_tunnel.mt_sw_if_index));
9890 fp = mp->mt_tunnel.mt_paths;
9891 for (i = 0; i < count; i++)
9893 vl_api_fib_path_print (vam, fp);
9897 print (vam->ofp, "");
9900 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
9901 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
9904 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
9906 vat_main_t *vam = &vat_main;
9907 vat_json_node_t *node = NULL;
9908 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9909 vl_api_fib_path_t *fp;
9912 if (VAT_JSON_ARRAY != vam->json_tree.type)
9914 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9915 vat_json_init_array (&vam->json_tree);
9917 node = vat_json_array_add (&vam->json_tree);
9919 vat_json_init_object (node);
9920 vat_json_object_add_uint (node, "sw_if_index",
9921 ntohl (mp->mt_tunnel.mt_sw_if_index));
9923 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
9925 fp = mp->mt_tunnel.mt_paths;
9926 for (i = 0; i < count; i++)
9928 vl_api_mpls_fib_path_json_print (node, fp);
9934 api_mpls_tunnel_dump (vat_main_t * vam)
9936 vl_api_mpls_tunnel_dump_t *mp;
9937 vl_api_control_ping_t *mp_ping;
9940 M (MPLS_TUNNEL_DUMP, mp);
9944 /* Use a control ping for synchronization */
9945 MPING (CONTROL_PING, mp_ping);
9952 #define vl_api_mpls_table_details_t_endian vl_noop_handler
9953 #define vl_api_mpls_table_details_t_print vl_noop_handler
9957 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
9959 vat_main_t *vam = &vat_main;
9961 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
9964 static void vl_api_mpls_table_details_t_handler_json
9965 (vl_api_mpls_table_details_t * mp)
9967 vat_main_t *vam = &vat_main;
9968 vat_json_node_t *node = NULL;
9970 if (VAT_JSON_ARRAY != vam->json_tree.type)
9972 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9973 vat_json_init_array (&vam->json_tree);
9975 node = vat_json_array_add (&vam->json_tree);
9977 vat_json_init_object (node);
9978 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
9982 api_mpls_table_dump (vat_main_t * vam)
9984 vl_api_mpls_table_dump_t *mp;
9985 vl_api_control_ping_t *mp_ping;
9988 M (MPLS_TABLE_DUMP, mp);
9991 /* Use a control ping for synchronization */
9992 MPING (CONTROL_PING, mp_ping);
9999 #define vl_api_mpls_route_details_t_endian vl_noop_handler
10000 #define vl_api_mpls_route_details_t_print vl_noop_handler
10003 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
10005 vat_main_t *vam = &vat_main;
10006 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
10007 vl_api_fib_path_t *fp;
10011 "table-id %d, label %u, ess_bit %u",
10012 ntohl (mp->mr_route.mr_table_id),
10013 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
10014 fp = mp->mr_route.mr_paths;
10015 for (i = 0; i < count; i++)
10017 vl_api_fib_path_print (vam, fp);
10022 static void vl_api_mpls_route_details_t_handler_json
10023 (vl_api_mpls_route_details_t * mp)
10025 vat_main_t *vam = &vat_main;
10026 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
10027 vat_json_node_t *node = NULL;
10028 vl_api_fib_path_t *fp;
10031 if (VAT_JSON_ARRAY != vam->json_tree.type)
10033 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10034 vat_json_init_array (&vam->json_tree);
10036 node = vat_json_array_add (&vam->json_tree);
10038 vat_json_init_object (node);
10039 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
10040 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
10041 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
10042 vat_json_object_add_uint (node, "path_count", count);
10043 fp = mp->mr_route.mr_paths;
10044 for (i = 0; i < count; i++)
10046 vl_api_mpls_fib_path_json_print (node, fp);
10052 api_mpls_route_dump (vat_main_t * vam)
10054 unformat_input_t *input = vam->input;
10055 vl_api_mpls_route_dump_t *mp;
10056 vl_api_control_ping_t *mp_ping;
10060 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10062 if (unformat (input, "table_id %d", &table_id))
10067 if (table_id == ~0)
10069 errmsg ("missing table id");
10073 M (MPLS_ROUTE_DUMP, mp);
10075 mp->table.mt_table_id = ntohl (table_id);
10078 /* Use a control ping for synchronization */
10079 MPING (CONTROL_PING, mp_ping);
10086 #define vl_api_ip_table_details_t_endian vl_noop_handler
10087 #define vl_api_ip_table_details_t_print vl_noop_handler
10090 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
10092 vat_main_t *vam = &vat_main;
10095 "%s; table-id %d, prefix %U/%d",
10096 mp->table.name, ntohl (mp->table.table_id));
10100 static void vl_api_ip_table_details_t_handler_json
10101 (vl_api_ip_table_details_t * mp)
10103 vat_main_t *vam = &vat_main;
10104 vat_json_node_t *node = NULL;
10106 if (VAT_JSON_ARRAY != vam->json_tree.type)
10108 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10109 vat_json_init_array (&vam->json_tree);
10111 node = vat_json_array_add (&vam->json_tree);
10113 vat_json_init_object (node);
10114 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
10118 api_ip_table_dump (vat_main_t * vam)
10120 vl_api_ip_table_dump_t *mp;
10121 vl_api_control_ping_t *mp_ping;
10124 M (IP_TABLE_DUMP, mp);
10127 /* Use a control ping for synchronization */
10128 MPING (CONTROL_PING, mp_ping);
10136 api_ip_mtable_dump (vat_main_t * vam)
10138 vl_api_ip_mtable_dump_t *mp;
10139 vl_api_control_ping_t *mp_ping;
10142 M (IP_MTABLE_DUMP, mp);
10145 /* Use a control ping for synchronization */
10146 MPING (CONTROL_PING, mp_ping);
10154 api_ip_mroute_dump (vat_main_t * vam)
10156 unformat_input_t *input = vam->input;
10157 vl_api_control_ping_t *mp_ping;
10158 vl_api_ip_mroute_dump_t *mp;
10163 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10165 if (unformat (input, "table_id %d", &table_id))
10167 else if (unformat (input, "ip6"))
10169 else if (unformat (input, "ip4"))
10174 if (table_id == ~0)
10176 errmsg ("missing table id");
10180 M (IP_MROUTE_DUMP, mp);
10181 mp->table.table_id = table_id;
10182 mp->table.is_ip6 = is_ip6;
10185 /* Use a control ping for synchronization */
10186 MPING (CONTROL_PING, mp_ping);
10193 #define vl_api_ip_route_details_t_endian vl_noop_handler
10194 #define vl_api_ip_route_details_t_print vl_noop_handler
10197 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
10199 vat_main_t *vam = &vat_main;
10200 u8 count = mp->route.n_paths;
10201 vl_api_fib_path_t *fp;
10205 "table-id %d, prefix %U/%d",
10206 ntohl (mp->route.table_id),
10207 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
10208 for (i = 0; i < count; i++)
10210 fp = &mp->route.paths[i];
10212 vl_api_fib_path_print (vam, fp);
10217 static void vl_api_ip_route_details_t_handler_json
10218 (vl_api_ip_route_details_t * mp)
10220 vat_main_t *vam = &vat_main;
10221 u8 count = mp->route.n_paths;
10222 vat_json_node_t *node = NULL;
10223 struct in_addr ip4;
10224 struct in6_addr ip6;
10225 vl_api_fib_path_t *fp;
10228 if (VAT_JSON_ARRAY != vam->json_tree.type)
10230 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10231 vat_json_init_array (&vam->json_tree);
10233 node = vat_json_array_add (&vam->json_tree);
10235 vat_json_init_object (node);
10236 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
10237 if (ADDRESS_IP6 == mp->route.prefix.address.af)
10239 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
10240 vat_json_object_add_ip6 (node, "prefix", ip6);
10244 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
10245 vat_json_object_add_ip4 (node, "prefix", ip4);
10247 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
10248 vat_json_object_add_uint (node, "path_count", count);
10249 for (i = 0; i < count; i++)
10251 fp = &mp->route.paths[i];
10252 vl_api_mpls_fib_path_json_print (node, fp);
10257 api_ip_route_dump (vat_main_t * vam)
10259 unformat_input_t *input = vam->input;
10260 vl_api_ip_route_dump_t *mp;
10261 vl_api_control_ping_t *mp_ping;
10267 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10269 if (unformat (input, "table_id %d", &table_id))
10271 else if (unformat (input, "ip6"))
10273 else if (unformat (input, "ip4"))
10278 if (table_id == ~0)
10280 errmsg ("missing table id");
10284 M (IP_ROUTE_DUMP, mp);
10286 mp->table.table_id = table_id;
10287 mp->table.is_ip6 = is_ip6;
10291 /* Use a control ping for synchronization */
10292 MPING (CONTROL_PING, mp_ping);
10300 api_sw_interface_span_enable_disable (vat_main_t * vam)
10302 unformat_input_t *i = vam->input;
10303 vl_api_sw_interface_span_enable_disable_t *mp;
10304 u32 src_sw_if_index = ~0;
10305 u32 dst_sw_if_index = ~0;
10310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10313 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
10315 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
10319 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
10321 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
10323 else if (unformat (i, "disable"))
10325 else if (unformat (i, "rx"))
10327 else if (unformat (i, "tx"))
10329 else if (unformat (i, "both"))
10331 else if (unformat (i, "l2"))
10337 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
10339 mp->sw_if_index_from = htonl (src_sw_if_index);
10340 mp->sw_if_index_to = htonl (dst_sw_if_index);
10350 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
10353 vat_main_t *vam = &vat_main;
10354 u8 *sw_if_from_name = 0;
10355 u8 *sw_if_to_name = 0;
10356 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10357 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10358 char *states[] = { "none", "rx", "tx", "both" };
10362 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10364 if ((u32) p->value[0] == sw_if_index_from)
10366 sw_if_from_name = (u8 *)(p->key);
10370 if ((u32) p->value[0] == sw_if_index_to)
10372 sw_if_to_name = (u8 *)(p->key);
10373 if (sw_if_from_name)
10378 print (vam->ofp, "%20s => %20s (%s) %s",
10379 sw_if_from_name, sw_if_to_name, states[mp->state],
10380 mp->is_l2 ? "l2" : "device");
10384 vl_api_sw_interface_span_details_t_handler_json
10385 (vl_api_sw_interface_span_details_t * mp)
10387 vat_main_t *vam = &vat_main;
10388 vat_json_node_t *node = NULL;
10389 u8 *sw_if_from_name = 0;
10390 u8 *sw_if_to_name = 0;
10391 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
10392 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
10396 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
10398 if ((u32) p->value[0] == sw_if_index_from)
10400 sw_if_from_name = (u8 *)(p->key);
10404 if ((u32) p->value[0] == sw_if_index_to)
10406 sw_if_to_name = (u8 *)(p->key);
10407 if (sw_if_from_name)
10413 if (VAT_JSON_ARRAY != vam->json_tree.type)
10415 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10416 vat_json_init_array (&vam->json_tree);
10418 node = vat_json_array_add (&vam->json_tree);
10420 vat_json_init_object (node);
10421 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
10422 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
10423 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
10424 if (0 != sw_if_to_name)
10426 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
10428 vat_json_object_add_uint (node, "state", mp->state);
10429 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
10433 api_sw_interface_span_dump (vat_main_t * vam)
10435 unformat_input_t *input = vam->input;
10436 vl_api_sw_interface_span_dump_t *mp;
10437 vl_api_control_ping_t *mp_ping;
10441 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10443 if (unformat (input, "l2"))
10449 M (SW_INTERFACE_SPAN_DUMP, mp);
10453 /* Use a control ping for synchronization */
10454 MPING (CONTROL_PING, mp_ping);
10462 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
10464 unformat_input_t *input = vam->input;
10465 vl_api_ip_source_and_port_range_check_add_del_t *mp;
10467 u16 *low_ports = 0;
10468 u16 *high_ports = 0;
10471 vl_api_prefix_t prefix;
10478 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10480 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
10482 else if (unformat (input, "vrf %d", &vrf_id))
10484 else if (unformat (input, "del"))
10486 else if (unformat (input, "port %d", &tmp))
10488 if (tmp == 0 || tmp > 65535)
10490 errmsg ("port %d out of range", tmp);
10494 this_hi = this_low + 1;
10495 vec_add1 (low_ports, this_low);
10496 vec_add1 (high_ports, this_hi);
10498 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
10500 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
10502 errmsg ("incorrect range parameters");
10506 /* Note: in debug CLI +1 is added to high before
10507 passing to real fn that does "the work"
10508 (ip_source_and_port_range_check_add_del).
10509 This fn is a wrapper around the binary API fn a
10510 control plane will call, which expects this increment
10511 to have occurred. Hence letting the binary API control
10512 plane fn do the increment for consistency between VAT
10513 and other control planes.
10516 vec_add1 (low_ports, this_low);
10517 vec_add1 (high_ports, this_hi);
10523 if (prefix_set == 0)
10525 errmsg ("<address>/<mask> not specified");
10531 errmsg ("VRF ID required, not specified");
10538 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10542 if (vec_len (low_ports) == 0)
10544 errmsg ("At least one port or port range required");
10548 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
10550 mp->is_add = is_add;
10552 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
10554 mp->number_of_ranges = vec_len (low_ports);
10556 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
10557 vec_free (low_ports);
10559 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
10560 vec_free (high_ports);
10562 mp->vrf_id = ntohl (vrf_id);
10570 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
10572 unformat_input_t *input = vam->input;
10573 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
10574 u32 sw_if_index = ~0;
10576 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
10577 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
10581 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10583 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10585 else if (unformat (input, "sw_if_index %d", &sw_if_index))
10587 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
10589 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
10591 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
10593 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
10595 else if (unformat (input, "del"))
10601 if (sw_if_index == ~0)
10603 errmsg ("Interface required but not specified");
10609 errmsg ("VRF ID required but not specified");
10613 if (tcp_out_vrf_id == 0
10614 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
10617 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10621 /* Construct the API message */
10622 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
10624 mp->sw_if_index = ntohl (sw_if_index);
10625 mp->is_add = is_add;
10626 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
10627 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
10628 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
10629 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
10634 /* Wait for a reply... */
10640 api_set_punt (vat_main_t * vam)
10642 unformat_input_t *i = vam->input;
10643 vl_api_address_family_t af;
10644 vl_api_set_punt_t *mp;
10650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10652 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
10654 else if (unformat (i, "protocol %d", &protocol))
10656 else if (unformat (i, "port %d", &port))
10658 else if (unformat (i, "del"))
10662 clib_warning ("parse error '%U'", format_unformat_error, i);
10669 mp->is_add = (u8) is_add;
10670 mp->punt.type = PUNT_API_TYPE_L4;
10671 mp->punt.punt.l4.af = af;
10672 mp->punt.punt.l4.protocol = (u8) protocol;
10673 mp->punt.punt.l4.port = htons ((u16) port);
10681 api_delete_subif (vat_main_t * vam)
10683 unformat_input_t *i = vam->input;
10684 vl_api_delete_subif_t *mp;
10685 u32 sw_if_index = ~0;
10688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10690 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10692 if (unformat (i, "sw_if_index %d", &sw_if_index))
10698 if (sw_if_index == ~0)
10700 errmsg ("missing sw_if_index");
10704 /* Construct the API message */
10705 M (DELETE_SUBIF, mp);
10706 mp->sw_if_index = ntohl (sw_if_index);
10713 #define foreach_pbb_vtr_op \
10714 _("disable", L2_VTR_DISABLED) \
10715 _("pop", L2_VTR_POP_2) \
10716 _("push", L2_VTR_PUSH_2)
10719 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
10721 unformat_input_t *i = vam->input;
10722 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
10723 u32 sw_if_index = ~0, vtr_op = ~0;
10724 u16 outer_tag = ~0;
10725 u8 dmac[6], smac[6];
10726 u8 dmac_set = 0, smac_set = 0;
10732 /* Shut up coverity */
10733 clib_memset (dmac, 0, sizeof (dmac));
10734 clib_memset (smac, 0, sizeof (smac));
10736 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10738 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10740 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10742 else if (unformat (i, "vtr_op %d", &vtr_op))
10744 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
10747 else if (unformat (i, "translate_pbb_stag"))
10749 if (unformat (i, "%d", &tmp))
10751 vtr_op = L2_VTR_TRANSLATE_2_1;
10757 ("translate_pbb_stag operation requires outer tag definition");
10761 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
10763 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
10765 else if (unformat (i, "sid %d", &sid))
10767 else if (unformat (i, "vlanid %d", &tmp))
10771 clib_warning ("parse error '%U'", format_unformat_error, i);
10776 if ((sw_if_index == ~0) || (vtr_op == ~0))
10778 errmsg ("missing sw_if_index or vtr operation");
10781 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
10782 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
10785 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
10789 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
10790 mp->sw_if_index = ntohl (sw_if_index);
10791 mp->vtr_op = ntohl (vtr_op);
10792 mp->outer_tag = ntohs (outer_tag);
10793 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
10794 clib_memcpy (mp->b_smac, smac, sizeof (smac));
10795 mp->b_vlanid = ntohs (vlanid);
10796 mp->i_sid = ntohl (sid);
10804 api_feature_enable_disable (vat_main_t * vam)
10806 unformat_input_t *i = vam->input;
10807 vl_api_feature_enable_disable_t *mp;
10809 u8 *feature_name = 0;
10810 u32 sw_if_index = ~0;
10814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10816 if (unformat (i, "arc_name %s", &arc_name))
10818 else if (unformat (i, "feature_name %s", &feature_name))
10821 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10823 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10825 else if (unformat (i, "disable"))
10833 errmsg ("missing arc name");
10836 if (vec_len (arc_name) > 63)
10838 errmsg ("arc name too long");
10841 if (feature_name == 0)
10843 errmsg ("missing feature name");
10846 if (vec_len (feature_name) > 63)
10848 errmsg ("feature name too long");
10851 if (sw_if_index == ~0)
10853 errmsg ("missing interface name or sw_if_index");
10857 /* Construct the API message */
10858 M (FEATURE_ENABLE_DISABLE, mp);
10859 mp->sw_if_index = ntohl (sw_if_index);
10860 mp->enable = enable;
10861 clib_memcpy (mp->arc_name, arc_name, vec_len (arc_name));
10862 clib_memcpy (mp->feature_name, feature_name, vec_len (feature_name));
10863 vec_free (arc_name);
10864 vec_free (feature_name);
10872 api_sw_interface_tag_add_del (vat_main_t * vam)
10874 unformat_input_t *i = vam->input;
10875 vl_api_sw_interface_tag_add_del_t *mp;
10876 u32 sw_if_index = ~0;
10881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10883 if (unformat (i, "tag %s", &tag))
10885 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10887 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10889 else if (unformat (i, "del"))
10895 if (sw_if_index == ~0)
10897 errmsg ("missing interface name or sw_if_index");
10901 if (enable && (tag == 0))
10903 errmsg ("no tag specified");
10907 /* Construct the API message */
10908 M (SW_INTERFACE_TAG_ADD_DEL, mp);
10909 mp->sw_if_index = ntohl (sw_if_index);
10910 mp->is_add = enable;
10912 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10921 api_sw_interface_add_del_mac_address (vat_main_t * vam)
10923 unformat_input_t *i = vam->input;
10924 vl_api_mac_address_t mac = { 0 };
10925 vl_api_sw_interface_add_del_mac_address_t *mp;
10926 u32 sw_if_index = ~0;
10931 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10933 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10935 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10937 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
10939 else if (unformat (i, "del"))
10945 if (sw_if_index == ~0)
10947 errmsg ("missing interface name or sw_if_index");
10953 errmsg ("missing MAC address");
10957 /* Construct the API message */
10958 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
10959 mp->sw_if_index = ntohl (sw_if_index);
10960 mp->is_add = is_add;
10961 clib_memcpy (&mp->addr, &mac, sizeof (mac));
10968 static void vl_api_l2_xconnect_details_t_handler
10969 (vl_api_l2_xconnect_details_t * mp)
10971 vat_main_t *vam = &vat_main;
10973 print (vam->ofp, "%15d%15d",
10974 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
10977 static void vl_api_l2_xconnect_details_t_handler_json
10978 (vl_api_l2_xconnect_details_t * mp)
10980 vat_main_t *vam = &vat_main;
10981 vat_json_node_t *node = NULL;
10983 if (VAT_JSON_ARRAY != vam->json_tree.type)
10985 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10986 vat_json_init_array (&vam->json_tree);
10988 node = vat_json_array_add (&vam->json_tree);
10990 vat_json_init_object (node);
10991 vat_json_object_add_uint (node, "rx_sw_if_index",
10992 ntohl (mp->rx_sw_if_index));
10993 vat_json_object_add_uint (node, "tx_sw_if_index",
10994 ntohl (mp->tx_sw_if_index));
10998 api_l2_xconnect_dump (vat_main_t * vam)
11000 vl_api_l2_xconnect_dump_t *mp;
11001 vl_api_control_ping_t *mp_ping;
11004 if (!vam->json_output)
11006 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
11009 M (L2_XCONNECT_DUMP, mp);
11013 /* Use a control ping for synchronization */
11014 MPING (CONTROL_PING, mp_ping);
11022 api_hw_interface_set_mtu (vat_main_t * vam)
11024 unformat_input_t *i = vam->input;
11025 vl_api_hw_interface_set_mtu_t *mp;
11026 u32 sw_if_index = ~0;
11030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11032 if (unformat (i, "mtu %d", &mtu))
11034 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11036 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11042 if (sw_if_index == ~0)
11044 errmsg ("missing interface name or sw_if_index");
11050 errmsg ("no mtu specified");
11054 /* Construct the API message */
11055 M (HW_INTERFACE_SET_MTU, mp);
11056 mp->sw_if_index = ntohl (sw_if_index);
11057 mp->mtu = ntohs ((u16) mtu);
11065 api_p2p_ethernet_add (vat_main_t * vam)
11067 unformat_input_t *i = vam->input;
11068 vl_api_p2p_ethernet_add_t *mp;
11069 u32 parent_if_index = ~0;
11075 clib_memset (remote_mac, 0, sizeof (remote_mac));
11076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11078 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11080 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11084 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11086 else if (unformat (i, "sub_id %d", &sub_id))
11090 clib_warning ("parse error '%U'", format_unformat_error, i);
11095 if (parent_if_index == ~0)
11097 errmsg ("missing interface name or sw_if_index");
11102 errmsg ("missing remote mac address");
11107 errmsg ("missing sub-interface id");
11111 M (P2P_ETHERNET_ADD, mp);
11112 mp->parent_if_index = ntohl (parent_if_index);
11113 mp->subif_id = ntohl (sub_id);
11114 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11122 api_p2p_ethernet_del (vat_main_t * vam)
11124 unformat_input_t *i = vam->input;
11125 vl_api_p2p_ethernet_del_t *mp;
11126 u32 parent_if_index = ~0;
11131 clib_memset (remote_mac, 0, sizeof (remote_mac));
11132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11134 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &parent_if_index))
11136 else if (unformat (i, "sw_if_index %d", &parent_if_index))
11140 (i, "remote_mac %U", unformat_ethernet_address, remote_mac))
11144 clib_warning ("parse error '%U'", format_unformat_error, i);
11149 if (parent_if_index == ~0)
11151 errmsg ("missing interface name or sw_if_index");
11156 errmsg ("missing remote mac address");
11160 M (P2P_ETHERNET_DEL, mp);
11161 mp->parent_if_index = ntohl (parent_if_index);
11162 clib_memcpy (mp->remote_mac, remote_mac, sizeof (remote_mac));
11170 api_tcp_configure_src_addresses (vat_main_t * vam)
11172 vl_api_tcp_configure_src_addresses_t *mp;
11173 unformat_input_t *i = vam->input;
11174 vl_api_address_t first, last;
11179 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11181 if (unformat (i, "%U - %U",
11182 unformat_vl_api_address, &first,
11183 unformat_vl_api_address, &last))
11187 errmsg ("one range per message (range already set)");
11192 else if (unformat (i, "vrf %d", &vrf_id))
11198 if (range_set == 0)
11200 errmsg ("address range not set");
11204 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
11206 mp->vrf_id = ntohl (vrf_id);
11207 clib_memcpy (&mp->first_address, &first, sizeof (first));
11208 clib_memcpy (&mp->last_address, &last, sizeof (last));
11215 static void vl_api_app_namespace_add_del_reply_t_handler
11216 (vl_api_app_namespace_add_del_reply_t * mp)
11218 vat_main_t *vam = &vat_main;
11219 i32 retval = ntohl (mp->retval);
11220 if (vam->async_mode)
11222 vam->async_errors += (retval < 0);
11226 vam->retval = retval;
11228 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
11229 vam->result_ready = 1;
11233 static void vl_api_app_namespace_add_del_reply_t_handler_json
11234 (vl_api_app_namespace_add_del_reply_t * mp)
11236 vat_main_t *vam = &vat_main;
11237 vat_json_node_t node;
11239 vat_json_init_object (&node);
11240 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
11241 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
11243 vat_json_print (vam->ofp, &node);
11244 vat_json_free (&node);
11246 vam->retval = ntohl (mp->retval);
11247 vam->result_ready = 1;
11251 api_app_namespace_add_del (vat_main_t * vam)
11253 vl_api_app_namespace_add_del_t *mp;
11254 unformat_input_t *i = vam->input;
11255 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
11256 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
11260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11262 if (unformat (i, "id %_%v%_", &ns_id))
11264 else if (unformat (i, "secret %lu", &secret))
11266 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11267 sw_if_index_set = 1;
11268 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
11270 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
11275 if (!ns_id || !secret_set || !sw_if_index_set)
11277 errmsg ("namespace id, secret and sw_if_index must be set");
11280 if (vec_len (ns_id) > 64)
11282 errmsg ("namespace id too long");
11285 M (APP_NAMESPACE_ADD_DEL, mp);
11287 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
11288 mp->secret = clib_host_to_net_u64 (secret);
11289 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
11290 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
11291 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
11299 api_sock_init_shm (vat_main_t * vam)
11301 #if VPP_API_TEST_BUILTIN == 0
11302 unformat_input_t *i = vam->input;
11303 vl_api_shm_elem_config_t *config = 0;
11304 u64 size = 64 << 20;
11307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11309 if (unformat (i, "size %U", unformat_memory_size, &size))
11316 * Canned custom ring allocator config.
11317 * Should probably parse all of this
11319 vec_validate (config, 6);
11320 config[0].type = VL_API_VLIB_RING;
11321 config[0].size = 256;
11322 config[0].count = 32;
11324 config[1].type = VL_API_VLIB_RING;
11325 config[1].size = 1024;
11326 config[1].count = 16;
11328 config[2].type = VL_API_VLIB_RING;
11329 config[2].size = 4096;
11330 config[2].count = 2;
11332 config[3].type = VL_API_CLIENT_RING;
11333 config[3].size = 256;
11334 config[3].count = 32;
11336 config[4].type = VL_API_CLIENT_RING;
11337 config[4].size = 1024;
11338 config[4].count = 16;
11340 config[5].type = VL_API_CLIENT_RING;
11341 config[5].size = 4096;
11342 config[5].count = 2;
11344 config[6].type = VL_API_QUEUE;
11345 config[6].count = 128;
11346 config[6].size = sizeof (uword);
11348 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
11350 vam->client_index_invalid = 1;
11358 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
11360 vat_main_t *vam = &vat_main;
11361 fib_prefix_t lcl, rmt;
11363 ip_prefix_decode (&mp->lcl, &lcl);
11364 ip_prefix_decode (&mp->rmt, &rmt);
11366 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
11369 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11370 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11371 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
11372 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
11373 &rmt.fp_addr.ip4, rmt.fp_len,
11374 clib_net_to_host_u16 (mp->rmt_port),
11375 clib_net_to_host_u32 (mp->action_index), mp->tag);
11380 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
11381 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
11382 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
11383 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
11384 &rmt.fp_addr.ip6, rmt.fp_len,
11385 clib_net_to_host_u16 (mp->rmt_port),
11386 clib_net_to_host_u32 (mp->action_index), mp->tag);
11391 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
11394 vat_main_t *vam = &vat_main;
11395 vat_json_node_t *node = NULL;
11396 struct in6_addr ip6;
11397 struct in_addr ip4;
11399 fib_prefix_t lcl, rmt;
11401 ip_prefix_decode (&mp->lcl, &lcl);
11402 ip_prefix_decode (&mp->rmt, &rmt);
11404 if (VAT_JSON_ARRAY != vam->json_tree.type)
11406 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
11407 vat_json_init_array (&vam->json_tree);
11409 node = vat_json_array_add (&vam->json_tree);
11410 vat_json_init_object (node);
11412 vat_json_object_add_uint (node, "appns_index",
11413 clib_net_to_host_u32 (mp->appns_index));
11414 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
11415 vat_json_object_add_uint (node, "scope", mp->scope);
11416 vat_json_object_add_uint (node, "action_index",
11417 clib_net_to_host_u32 (mp->action_index));
11418 vat_json_object_add_uint (node, "lcl_port",
11419 clib_net_to_host_u16 (mp->lcl_port));
11420 vat_json_object_add_uint (node, "rmt_port",
11421 clib_net_to_host_u16 (mp->rmt_port));
11422 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
11423 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
11424 vat_json_object_add_string_copy (node, "tag", mp->tag);
11425 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
11427 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
11428 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
11429 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
11430 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
11434 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
11435 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
11436 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
11437 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
11442 api_session_rule_add_del (vat_main_t * vam)
11444 vl_api_session_rule_add_del_t *mp;
11445 unformat_input_t *i = vam->input;
11446 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
11447 u32 appns_index = 0, scope = 0;
11448 ip4_address_t lcl_ip4, rmt_ip4;
11449 ip6_address_t lcl_ip6, rmt_ip6;
11450 u8 is_ip4 = 1, conn_set = 0;
11451 u8 is_add = 1, *tag = 0;
11453 fib_prefix_t lcl, rmt;
11455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11457 if (unformat (i, "del"))
11459 else if (unformat (i, "add"))
11461 else if (unformat (i, "proto tcp"))
11463 else if (unformat (i, "proto udp"))
11465 else if (unformat (i, "appns %d", &appns_index))
11467 else if (unformat (i, "scope %d", &scope))
11469 else if (unformat (i, "tag %_%v%_", &tag))
11473 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
11474 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
11482 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
11483 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
11489 else if (unformat (i, "action %d", &action))
11494 if (proto == ~0 || !conn_set || action == ~0)
11496 errmsg ("transport proto, connection and action must be set");
11502 errmsg ("scope should be 0-3");
11506 M (SESSION_RULE_ADD_DEL, mp);
11508 clib_memset (&lcl, 0, sizeof (lcl));
11509 clib_memset (&rmt, 0, sizeof (rmt));
11512 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
11513 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
11514 lcl.fp_len = lcl_plen;
11515 rmt.fp_len = rmt_plen;
11519 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
11520 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
11521 lcl.fp_len = lcl_plen;
11522 rmt.fp_len = rmt_plen;
11526 ip_prefix_encode (&lcl, &mp->lcl);
11527 ip_prefix_encode (&rmt, &mp->rmt);
11528 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
11529 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
11530 mp->transport_proto =
11531 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
11532 mp->action_index = clib_host_to_net_u32 (action);
11533 mp->appns_index = clib_host_to_net_u32 (appns_index);
11535 mp->is_add = is_add;
11538 clib_memcpy (mp->tag, tag, vec_len (tag));
11548 api_session_rules_dump (vat_main_t * vam)
11550 vl_api_session_rules_dump_t *mp;
11551 vl_api_control_ping_t *mp_ping;
11554 if (!vam->json_output)
11556 print (vam->ofp, "%=20s", "Session Rules");
11559 M (SESSION_RULES_DUMP, mp);
11563 /* Use a control ping for synchronization */
11564 MPING (CONTROL_PING, mp_ping);
11567 /* Wait for a reply... */
11573 api_ip_container_proxy_add_del (vat_main_t * vam)
11575 vl_api_ip_container_proxy_add_del_t *mp;
11576 unformat_input_t *i = vam->input;
11577 u32 sw_if_index = ~0;
11578 vl_api_prefix_t pfx = { };
11582 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11584 if (unformat (i, "del"))
11586 else if (unformat (i, "add"))
11588 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
11590 else if (unformat (i, "sw_if_index %u", &sw_if_index))
11595 if (sw_if_index == ~0 || pfx.len == 0)
11597 errmsg ("address and sw_if_index must be set");
11601 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
11603 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
11604 mp->is_add = is_add;
11605 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
11613 api_qos_record_enable_disable (vat_main_t * vam)
11615 unformat_input_t *i = vam->input;
11616 vl_api_qos_record_enable_disable_t *mp;
11617 u32 sw_if_index, qs = 0xff;
11618 u8 sw_if_index_set = 0;
11622 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
11624 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
11625 sw_if_index_set = 1;
11626 else if (unformat (i, "sw_if_index %d", &sw_if_index))
11627 sw_if_index_set = 1;
11628 else if (unformat (i, "%U", unformat_qos_source, &qs))
11630 else if (unformat (i, "disable"))
11634 clib_warning ("parse error '%U'", format_unformat_error, i);
11639 if (sw_if_index_set == 0)
11641 errmsg ("missing interface name or sw_if_index");
11646 errmsg ("input location must be specified");
11650 M (QOS_RECORD_ENABLE_DISABLE, mp);
11652 mp->record.sw_if_index = ntohl (sw_if_index);
11653 mp->record.input_source = qs;
11654 mp->enable = enable;
11663 q_or_quit (vat_main_t * vam)
11665 #if VPP_API_TEST_BUILTIN == 0
11666 longjmp (vam->jump_buf, 1);
11668 return 0; /* not so much */
11672 q (vat_main_t * vam)
11674 return q_or_quit (vam);
11678 quit (vat_main_t * vam)
11680 return q_or_quit (vam);
11684 comment (vat_main_t * vam)
11690 elog_save (vat_main_t * vam)
11692 #if VPP_API_TEST_BUILTIN == 0
11693 elog_main_t *em = &vam->elog_main;
11694 unformat_input_t *i = vam->input;
11695 char *file, *chroot_file;
11696 clib_error_t *error;
11698 if (!unformat (i, "%s", &file))
11700 errmsg ("expected file name, got `%U'", format_unformat_error, i);
11704 /* It's fairly hard to get "../oopsie" through unformat; just in case */
11705 if (strstr (file, "..") || index (file, '/'))
11707 errmsg ("illegal characters in filename '%s'", file);
11711 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
11715 errmsg ("Saving %wd of %wd events to %s",
11716 elog_n_events_in_buffer (em),
11717 elog_buffer_capacity (em), chroot_file);
11719 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
11720 vec_free (chroot_file);
11723 clib_error_report (error);
11725 errmsg ("Use the vpp event loger...");
11732 elog_setup (vat_main_t * vam)
11734 #if VPP_API_TEST_BUILTIN == 0
11735 elog_main_t *em = &vam->elog_main;
11736 unformat_input_t *i = vam->input;
11737 u32 nevents = 128 << 10;
11739 (void) unformat (i, "nevents %d", &nevents);
11741 elog_init (em, nevents);
11742 vl_api_set_elog_main (em);
11743 vl_api_set_elog_trace_api_messages (1);
11744 errmsg ("Event logger initialized with %u events", nevents);
11746 errmsg ("Use the vpp event loger...");
11752 elog_enable (vat_main_t * vam)
11754 #if VPP_API_TEST_BUILTIN == 0
11755 elog_main_t *em = &vam->elog_main;
11757 elog_enable_disable (em, 1 /* enable */ );
11758 vl_api_set_elog_trace_api_messages (1);
11759 errmsg ("Event logger enabled...");
11761 errmsg ("Use the vpp event loger...");
11767 elog_disable (vat_main_t * vam)
11769 #if VPP_API_TEST_BUILTIN == 0
11770 elog_main_t *em = &vam->elog_main;
11772 elog_enable_disable (em, 0 /* enable */ );
11773 vl_api_set_elog_trace_api_messages (1);
11774 errmsg ("Event logger disabled...");
11776 errmsg ("Use the vpp event loger...");
11782 statseg (vat_main_t * vam)
11784 ssvm_private_t *ssvmp = &vam->stat_segment;
11785 ssvm_shared_header_t *shared_header = ssvmp->sh;
11786 vlib_counter_t **counters;
11787 u64 thread0_index1_packets;
11788 u64 thread0_index1_bytes;
11789 f64 vector_rate, input_rate;
11792 uword *counter_vector_by_name;
11793 if (vam->stat_segment_lockp == 0)
11795 errmsg ("Stat segment not mapped...");
11799 /* look up "/if/rx for sw_if_index 1 as a test */
11801 clib_spinlock_lock (vam->stat_segment_lockp);
11803 counter_vector_by_name = (uword *) shared_header->opaque[1];
11805 p = hash_get_mem (counter_vector_by_name, "/if/rx");
11808 clib_spinlock_unlock (vam->stat_segment_lockp);
11809 errmsg ("/if/tx not found?");
11813 /* Fish per-thread vector of combined counters from shared memory */
11814 counters = (vlib_counter_t **) p[0];
11816 if (vec_len (counters[0]) < 2)
11818 clib_spinlock_unlock (vam->stat_segment_lockp);
11819 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
11823 /* Read thread 0 sw_if_index 1 counter */
11824 thread0_index1_packets = counters[0][1].packets;
11825 thread0_index1_bytes = counters[0][1].bytes;
11827 p = hash_get_mem (counter_vector_by_name, "vector_rate");
11830 clib_spinlock_unlock (vam->stat_segment_lockp);
11831 errmsg ("vector_rate not found?");
11835 vector_rate = *(f64 *) (p[0]);
11836 p = hash_get_mem (counter_vector_by_name, "input_rate");
11839 clib_spinlock_unlock (vam->stat_segment_lockp);
11840 errmsg ("input_rate not found?");
11843 input_rate = *(f64 *) (p[0]);
11845 clib_spinlock_unlock (vam->stat_segment_lockp);
11847 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
11848 vector_rate, input_rate);
11849 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
11850 thread0_index1_packets, thread0_index1_bytes);
11856 cmd_cmp (void *a1, void *a2)
11861 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
11865 help (vat_main_t * vam)
11870 unformat_input_t *i = vam->input;
11873 if (unformat (i, "%s", &name))
11877 vec_add1 (name, 0);
11879 hs = hash_get_mem (vam->help_by_name, name);
11881 print (vam->ofp, "usage: %s %s", name, hs[0]);
11883 print (vam->ofp, "No such msg / command '%s'", name);
11888 print (vam->ofp, "Help is available for the following:");
11891 hash_foreach_pair (p, vam->function_by_name,
11893 vec_add1 (cmds, (u8 *)(p->key));
11897 vec_sort_with_function (cmds, cmd_cmp);
11899 for (j = 0; j < vec_len (cmds); j++)
11900 print (vam->ofp, "%s", cmds[j]);
11907 set (vat_main_t * vam)
11909 u8 *name = 0, *value = 0;
11910 unformat_input_t *i = vam->input;
11912 if (unformat (i, "%s", &name))
11914 /* The input buffer is a vector, not a string. */
11915 value = vec_dup (i->buffer);
11916 vec_delete (value, i->index, 0);
11917 /* Almost certainly has a trailing newline */
11918 if (value[vec_len (value) - 1] == '\n')
11919 value[vec_len (value) - 1] = 0;
11920 /* Make sure it's a proper string, one way or the other */
11921 vec_add1 (value, 0);
11922 (void) clib_macro_set_value (&vam->macro_main,
11923 (char *) name, (char *) value);
11926 errmsg ("usage: set <name> <value>");
11934 unset (vat_main_t * vam)
11938 if (unformat (vam->input, "%s", &name))
11939 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
11940 errmsg ("unset: %s wasn't set", name);
11953 macro_sort_cmp (void *a1, void *a2)
11955 macro_sort_t *s1 = a1;
11956 macro_sort_t *s2 = a2;
11958 return strcmp ((char *) (s1->name), (char *) (s2->name));
11962 dump_macro_table (vat_main_t * vam)
11964 macro_sort_t *sort_me = 0, *sm;
11969 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
11971 vec_add2 (sort_me, sm, 1);
11972 sm->name = (u8 *)(p->key);
11973 sm->value = (u8 *) (p->value[0]);
11977 vec_sort_with_function (sort_me, macro_sort_cmp);
11979 if (vec_len (sort_me))
11980 print (vam->ofp, "%-15s%s", "Name", "Value");
11982 print (vam->ofp, "The macro table is empty...");
11984 for (i = 0; i < vec_len (sort_me); i++)
11985 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
11990 dump_node_table (vat_main_t * vam)
11993 vlib_node_t *node, *next_node;
11995 if (vec_len (vam->graph_nodes) == 0)
11997 print (vam->ofp, "Node table empty, issue get_node_graph...");
12001 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
12003 node = vam->graph_nodes[0][i];
12004 print (vam->ofp, "[%d] %s", i, node->name);
12005 for (j = 0; j < vec_len (node->next_nodes); j++)
12007 if (node->next_nodes[j] != ~0)
12009 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12010 print (vam->ofp, " [%d] %s", j, next_node->name);
12018 value_sort_cmp (void *a1, void *a2)
12020 name_sort_t *n1 = a1;
12021 name_sort_t *n2 = a2;
12023 if (n1->value < n2->value)
12025 if (n1->value > n2->value)
12032 dump_msg_api_table (vat_main_t * vam)
12034 api_main_t *am = vlibapi_get_main ();
12035 name_sort_t *nses = 0, *ns;
12040 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
12042 vec_add2 (nses, ns, 1);
12043 ns->name = (u8 *)(hp->key);
12044 ns->value = (u32) hp->value[0];
12048 vec_sort_with_function (nses, value_sort_cmp);
12050 for (i = 0; i < vec_len (nses); i++)
12051 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
12057 get_msg_id (vat_main_t * vam)
12062 if (unformat (vam->input, "%s", &name_and_crc))
12064 message_index = vl_msg_api_get_msg_index (name_and_crc);
12065 if (message_index == ~0)
12067 print (vam->ofp, " '%s' not found", name_and_crc);
12070 print (vam->ofp, " '%s' has message index %d",
12071 name_and_crc, message_index);
12074 errmsg ("name_and_crc required...");
12079 search_node_table (vat_main_t * vam)
12081 unformat_input_t *line_input = vam->input;
12084 vlib_node_t *node, *next_node;
12087 if (vam->graph_node_index_by_name == 0)
12089 print (vam->ofp, "Node table empty, issue get_node_graph...");
12093 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
12095 if (unformat (line_input, "%s", &node_to_find))
12097 vec_add1 (node_to_find, 0);
12098 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
12101 print (vam->ofp, "%s not found...", node_to_find);
12104 node = vam->graph_nodes[0][p[0]];
12105 print (vam->ofp, "[%d] %s", p[0], node->name);
12106 for (j = 0; j < vec_len (node->next_nodes); j++)
12108 if (node->next_nodes[j] != ~0)
12110 next_node = vam->graph_nodes[0][node->next_nodes[j]];
12111 print (vam->ofp, " [%d] %s", j, next_node->name);
12118 clib_warning ("parse error '%U'", format_unformat_error,
12124 vec_free (node_to_find);
12133 script (vat_main_t * vam)
12135 #if (VPP_API_TEST_BUILTIN==0)
12137 char *save_current_file;
12138 unformat_input_t save_input;
12139 jmp_buf save_jump_buf;
12140 u32 save_line_number;
12142 FILE *new_fp, *save_ifp;
12144 if (unformat (vam->input, "%s", &s))
12146 new_fp = fopen ((char *) s, "r");
12149 errmsg ("Couldn't open script file %s", s);
12156 errmsg ("Missing script name");
12160 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
12161 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
12162 save_ifp = vam->ifp;
12163 save_line_number = vam->input_line_number;
12164 save_current_file = (char *) vam->current_file;
12166 vam->input_line_number = 0;
12168 vam->current_file = s;
12171 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
12172 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
12173 vam->ifp = save_ifp;
12174 vam->input_line_number = save_line_number;
12175 vam->current_file = (u8 *) save_current_file;
12180 clib_warning ("use the exec command...");
12186 echo (vat_main_t * vam)
12188 print (vam->ofp, "%v", vam->input->buffer);
12192 /* List of API message constructors, CLI names map to api_xxx */
12193 #define foreach_vpe_api_msg \
12194 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
12195 _(sw_interface_dump,"") \
12196 _(sw_interface_set_flags, \
12197 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
12198 _(sw_interface_add_del_address, \
12199 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
12200 _(sw_interface_set_rx_mode, \
12201 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
12202 _(sw_interface_set_rx_placement, \
12203 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
12204 _(sw_interface_rx_placement_dump, \
12205 "[<intfc> | sw_if_index <id>]") \
12206 _(sw_interface_set_table, \
12207 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
12208 _(sw_interface_set_mpls_enable, \
12209 "<intfc> | sw_if_index [disable | dis]") \
12210 _(sw_interface_set_vpath, \
12211 "<intfc> | sw_if_index <id> enable | disable") \
12212 _(sw_interface_set_l2_xconnect, \
12213 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12214 "enable | disable") \
12215 _(sw_interface_set_l2_bridge, \
12216 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
12217 "[shg <split-horizon-group>] [bvi]\n" \
12218 "enable | disable") \
12219 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
12220 _(bridge_domain_add_del, \
12221 "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") \
12222 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
12224 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
12225 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
12226 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
12228 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12230 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12232 "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]") \
12234 "<vpp-if-name> | sw_if_index <id>") \
12235 _(sw_interface_tap_v2_dump, "") \
12236 _(virtio_pci_create_v2, \
12237 "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]") \
12238 _(virtio_pci_delete, \
12239 "<vpp-if-name> | sw_if_index <id>") \
12240 _(sw_interface_virtio_pci_dump, "") \
12242 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
12243 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12246 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
12247 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
12248 "[id <if-id>] [gso]") \
12250 "<vpp-if-name> | sw_if_index <id>") \
12251 _(bond_add_member, \
12252 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
12253 _(bond_detach_member, \
12254 "sw_if_index <n>") \
12255 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
12256 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
12257 _(sw_member_interface_dump, \
12258 "<vpp-if-name> | sw_if_index <id>") \
12259 _(ip_table_add_del, \
12260 "table <n> [ipv6] [add | del]\n") \
12261 _(ip_route_add_del, \
12262 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
12263 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
12264 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
12265 "[multipath] [count <n>] [del]") \
12266 _(ip_mroute_add_del, \
12267 "<src> <grp>/<mask> [table-id <n>]\n" \
12268 "[<intfc> | sw_if_index <id>] [local] [del]") \
12269 _(mpls_table_add_del, \
12270 "table <n> [add | del]\n") \
12271 _(mpls_route_add_del, \
12272 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
12273 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
12274 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
12275 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
12276 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
12277 "[count <n>] [del]") \
12278 _(mpls_ip_bind_unbind, \
12279 "<label> <addr/len>") \
12280 _(mpls_tunnel_add_del, \
12281 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
12282 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
12283 "[l2-only] [out-label <n>]") \
12284 _(sr_mpls_policy_add, \
12285 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
12286 _(sr_mpls_policy_del, \
12288 _(sw_interface_set_unnumbered, \
12289 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
12290 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
12291 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
12292 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
12293 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
12294 "[outer_vlan_id_any][inner_vlan_id_any]") \
12295 _(ip_table_replace_begin, "table <n> [ipv6]") \
12296 _(ip_table_flush, "table <n> [ipv6]") \
12297 _(ip_table_replace_end, "table <n> [ipv6]") \
12298 _(set_ip_flow_hash, \
12299 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
12300 _(sw_interface_ip6_enable_disable, \
12301 "<intfc> | sw_if_index <id> enable | disable") \
12302 _(l2_patch_add_del, \
12303 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12304 "enable | disable") \
12305 _(sr_localsid_add_del, \
12306 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
12307 "fib-table <num> (end.psp) sw_if_index <num>") \
12308 _(get_node_index, "node <node-name") \
12309 _(add_node_next, "node <node-name> next <next-node-name>") \
12310 _(l2_fib_clear_table, "") \
12311 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
12312 _(l2_interface_vlan_tag_rewrite, \
12313 "<intfc> | sw_if_index <nn> \n" \
12314 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
12315 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
12316 _(create_vhost_user_if, \
12317 "socket <filename> [server] [renumber <dev_instance>] " \
12318 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12319 "[mac <mac_address>] [packed]") \
12320 _(modify_vhost_user_if, \
12321 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12322 "[server] [renumber <dev_instance>] [gso] [packed]") \
12323 _(create_vhost_user_if_v2, \
12324 "socket <filename> [server] [renumber <dev_instance>] " \
12325 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
12326 "[mac <mac_address>] [packed] [event-idx]") \
12327 _(modify_vhost_user_if_v2, \
12328 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12329 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
12330 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
12331 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
12332 _(show_version, "") \
12333 _(show_threads, "") \
12334 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
12335 _(interface_name_renumber, \
12336 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
12337 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
12338 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
12339 _(ip_dump, "ipv4 | ipv6") \
12340 _(ipsec_spd_add_del, "spd_id <n> [del]") \
12341 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
12343 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
12344 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
12345 " integ_alg <alg> integ_key <hex>") \
12346 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
12347 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
12348 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
12349 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
12350 _(ipsec_sa_dump, "[sa_id <n>]") \
12351 _(delete_loopback,"sw_if_index <nn>") \
12352 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
12353 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
12354 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
12355 _(want_interface_events, "enable|disable") \
12356 _(get_first_msg_id, "client <name>") \
12357 _(get_node_graph, " ") \
12358 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
12359 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
12360 _(ioam_disable, "") \
12361 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
12362 _(af_packet_delete, "name <host interface name>") \
12363 _(af_packet_dump, "") \
12364 _(policer_add_del, "name <policer name> <params> [del]") \
12365 _(policer_dump, "[name <policer name>]") \
12366 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
12367 _(mpls_table_dump, "") \
12368 _(mpls_route_dump, "table-id <ID>") \
12369 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
12370 _(sw_interface_span_dump, "[l2]") \
12371 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
12372 _(ip_source_and_port_range_check_add_del, \
12373 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
12374 _(ip_source_and_port_range_check_interface_add_del, \
12375 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
12376 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
12377 _(delete_subif,"<intfc> | sw_if_index <nn>") \
12378 _(l2_interface_pbb_tag_rewrite, \
12379 "<intfc> | sw_if_index <nn> \n" \
12380 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
12381 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
12382 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
12383 _(ip_table_dump, "") \
12384 _(ip_route_dump, "table-id [ip4|ip6]") \
12385 _(ip_mtable_dump, "") \
12386 _(ip_mroute_dump, "table-id [ip4|ip6]") \
12387 _(feature_enable_disable, "arc_name <arc_name> " \
12388 "feature_name <feature_name> <intfc> | sw_if_index <nn> [disable]") \
12389 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
12391 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
12392 "mac <mac-address> [del]") \
12393 _(l2_xconnect_dump, "") \
12394 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
12395 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
12396 _(p2p_ethernet_add, "<intfc> | sw_if_index <nn> remote_mac <mac-address> sub_id <id>") \
12397 _(p2p_ethernet_del, "<intfc> | sw_if_index <nn> remote_mac <mac-address>") \
12398 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
12399 _(sock_init_shm, "size <nnn>") \
12400 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
12401 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
12402 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
12403 _(session_rules_dump, "") \
12404 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
12405 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
12407 /* List of command functions, CLI names map directly to functions */
12408 #define foreach_cli_function \
12409 _(comment, "usage: comment <ignore-rest-of-line>") \
12410 _(dump_interface_table, "usage: dump_interface_table") \
12411 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
12412 _(dump_ipv4_table, "usage: dump_ipv4_table") \
12413 _(dump_ipv6_table, "usage: dump_ipv6_table") \
12414 _(dump_macro_table, "usage: dump_macro_table ") \
12415 _(dump_node_table, "usage: dump_node_table") \
12416 _(dump_msg_api_table, "usage: dump_msg_api_table") \
12417 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
12418 _(elog_disable, "usage: elog_disable") \
12419 _(elog_enable, "usage: elog_enable") \
12420 _(elog_save, "usage: elog_save <filename>") \
12421 _(get_msg_id, "usage: get_msg_id name_and_crc") \
12422 _(echo, "usage: echo <message>") \
12423 _(exec, "usage: exec <vpe-debug-CLI-command>") \
12424 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
12425 _(help, "usage: help") \
12426 _(q, "usage: quit") \
12427 _(quit, "usage: quit") \
12428 _(search_node_table, "usage: search_node_table <name>...") \
12429 _(set, "usage: set <variable-name> <value>") \
12430 _(script, "usage: script <file-name>") \
12431 _(statseg, "usage: statseg") \
12432 _(unset, "usage: unset <variable-name>")
12435 static void vl_api_##n##_t_handler_uni \
12436 (vl_api_##n##_t * mp) \
12438 vat_main_t * vam = &vat_main; \
12439 if (vam->json_output) { \
12440 vl_api_##n##_t_handler_json(mp); \
12442 vl_api_##n##_t_handler(mp); \
12445 foreach_vpe_api_reply_msg;
12446 #if VPP_API_TEST_BUILTIN == 0
12447 foreach_standalone_reply_msg;
12452 vat_api_hookup (vat_main_t * vam)
12455 vl_msg_api_set_handlers(VL_API_##N, #n, \
12456 vl_api_##n##_t_handler_uni, \
12458 vl_api_##n##_t_endian, \
12459 vl_api_##n##_t_print, \
12460 sizeof(vl_api_##n##_t), 1);
12461 foreach_vpe_api_reply_msg;
12462 #if VPP_API_TEST_BUILTIN == 0
12463 foreach_standalone_reply_msg;
12467 #if (VPP_API_TEST_BUILTIN==0)
12468 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
12470 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
12472 vam->function_by_name = hash_create_string (0, sizeof (uword));
12474 vam->help_by_name = hash_create_string (0, sizeof (uword));
12477 /* API messages we can send */
12478 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
12479 foreach_vpe_api_msg;
12483 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12484 foreach_vpe_api_msg;
12487 /* CLI functions */
12488 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
12489 foreach_cli_function;
12493 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12494 foreach_cli_function;
12498 #if VPP_API_TEST_BUILTIN
12499 static clib_error_t *
12500 vat_api_hookup_shim (vlib_main_t * vm)
12502 vat_api_hookup (&vat_main);
12506 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
12510 * fd.io coding-style-patch-verification: ON
12513 * eval: (c-set-style "gnu")