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 */
429 #if (VPP_API_TEST_BUILTIN==0)
431 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
432 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
433 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
434 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
437 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
439 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
440 mfib_itf_attribute_t attr;
443 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
445 if (unformat (input, mfib_itf_flag_long_names[attr]))
446 *iflags |= (1 << attr);
448 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
450 if (unformat (input, mfib_itf_flag_names[attr]))
451 *iflags |= (1 << attr);
454 return (old == *iflags ? 0 : 1);
458 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
460 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
461 mfib_entry_attribute_t attr;
464 FOR_EACH_MFIB_ATTRIBUTE (attr)
466 if (unformat (input, mfib_flag_long_names[attr]))
467 *eflags |= (1 << attr);
469 FOR_EACH_MFIB_ATTRIBUTE (attr)
471 if (unformat (input, mfib_flag_names[attr]))
472 *eflags |= (1 << attr);
475 return (old == *eflags ? 0 : 1);
479 format_ip4_address (u8 * s, va_list * args)
481 u8 *a = va_arg (*args, u8 *);
482 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
486 format_ip6_address (u8 * s, va_list * args)
488 ip6_address_t *a = va_arg (*args, ip6_address_t *);
489 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
491 i_max_n_zero = ARRAY_LEN (a->as_u16);
493 i_first_zero = i_max_n_zero;
495 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
497 u32 is_zero = a->as_u16[i] == 0;
498 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
504 if ((!is_zero && n_zeros > max_n_zeros)
505 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
507 i_max_n_zero = i_first_zero;
508 max_n_zeros = n_zeros;
509 i_first_zero = ARRAY_LEN (a->as_u16);
514 last_double_colon = 0;
515 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
517 if (i == i_max_n_zero && max_n_zeros > 1)
519 s = format (s, "::");
520 i += max_n_zeros - 1;
521 last_double_colon = 1;
525 s = format (s, "%s%x",
526 (last_double_colon || i == 0) ? "" : ":",
527 clib_net_to_host_u16 (a->as_u16[i]));
528 last_double_colon = 0;
535 /* Format an IP46 address. */
537 format_ip46_address (u8 * s, va_list * args)
539 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
540 ip46_type_t type = va_arg (*args, ip46_type_t);
546 is_ip4 = ip46_address_is_ip4 (ip46);
557 format (s, "%U", format_ip4_address, &ip46->ip4) :
558 format (s, "%U", format_ip6_address, &ip46->ip6);
562 format_ethernet_address (u8 * s, va_list * args)
564 u8 *a = va_arg (*args, u8 *);
566 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
567 a[0], a[1], a[2], a[3], a[4], a[5]);
572 increment_v4_address (vl_api_ip4_address_t * i)
574 ip4_address_t *a = (ip4_address_t *) i;
577 v = ntohl (a->as_u32) + 1;
578 a->as_u32 = ntohl (v);
582 increment_v6_address (vl_api_ip6_address_t * i)
584 ip6_address_t *a = (ip6_address_t *) i;
587 v0 = clib_net_to_host_u64 (a->as_u64[0]);
588 v1 = clib_net_to_host_u64 (a->as_u64[1]);
593 a->as_u64[0] = clib_net_to_host_u64 (v0);
594 a->as_u64[1] = clib_net_to_host_u64 (v1);
598 increment_address (vl_api_address_t * a)
600 if (a->af == ADDRESS_IP4)
601 increment_v4_address (&a->un.ip4);
602 else if (a->af == ADDRESS_IP6)
603 increment_v6_address (&a->un.ip6);
607 set_ip4_address (vl_api_address_t * a, u32 v)
609 if (a->af == ADDRESS_IP4)
611 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
617 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
620 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
622 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
623 sizeof (ip6_address_t));
627 increment_mac_address (u8 * mac)
629 u64 tmp = *((u64 *) mac);
630 tmp = clib_net_to_host_u64 (tmp);
631 tmp += 1 << 16; /* skip unused (least significant) octets */
632 tmp = clib_host_to_net_u64 (tmp);
634 clib_memcpy (mac, &tmp, 6);
638 vat_json_object_add_address (vat_json_node_t * node,
639 const char *str, const vl_api_address_t * addr)
641 if (ADDRESS_IP6 == addr->af)
645 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
646 vat_json_object_add_ip6 (node, str, ip6);
652 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
653 vat_json_object_add_ip4 (node, str, ip4);
658 vat_json_object_add_prefix (vat_json_node_t * node,
659 const vl_api_prefix_t * prefix)
661 vat_json_object_add_uint (node, "len", prefix->len);
662 vat_json_object_add_address (node, "address", &prefix->address);
665 static void vl_api_create_loopback_reply_t_handler
666 (vl_api_create_loopback_reply_t * mp)
668 vat_main_t *vam = &vat_main;
669 i32 retval = ntohl (mp->retval);
671 vam->retval = retval;
672 vam->regenerate_interface_table = 1;
673 vam->sw_if_index = ntohl (mp->sw_if_index);
674 vam->result_ready = 1;
677 static void vl_api_create_loopback_reply_t_handler_json
678 (vl_api_create_loopback_reply_t * mp)
680 vat_main_t *vam = &vat_main;
681 vat_json_node_t node;
683 vat_json_init_object (&node);
684 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
685 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
687 vat_json_print (vam->ofp, &node);
688 vat_json_free (&node);
689 vam->retval = ntohl (mp->retval);
690 vam->result_ready = 1;
693 static void vl_api_create_loopback_instance_reply_t_handler
694 (vl_api_create_loopback_instance_reply_t * mp)
696 vat_main_t *vam = &vat_main;
697 i32 retval = ntohl (mp->retval);
699 vam->retval = retval;
700 vam->regenerate_interface_table = 1;
701 vam->sw_if_index = ntohl (mp->sw_if_index);
702 vam->result_ready = 1;
705 static void vl_api_create_loopback_instance_reply_t_handler_json
706 (vl_api_create_loopback_instance_reply_t * mp)
708 vat_main_t *vam = &vat_main;
709 vat_json_node_t node;
711 vat_json_init_object (&node);
712 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
713 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
715 vat_json_print (vam->ofp, &node);
716 vat_json_free (&node);
717 vam->retval = ntohl (mp->retval);
718 vam->result_ready = 1;
721 static void vl_api_af_packet_create_reply_t_handler
722 (vl_api_af_packet_create_reply_t * mp)
724 vat_main_t *vam = &vat_main;
725 i32 retval = ntohl (mp->retval);
727 vam->retval = retval;
728 vam->regenerate_interface_table = 1;
729 vam->sw_if_index = ntohl (mp->sw_if_index);
730 vam->result_ready = 1;
733 static void vl_api_af_packet_create_reply_t_handler_json
734 (vl_api_af_packet_create_reply_t * mp)
736 vat_main_t *vam = &vat_main;
737 vat_json_node_t node;
739 vat_json_init_object (&node);
740 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
741 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
743 vat_json_print (vam->ofp, &node);
744 vat_json_free (&node);
746 vam->retval = ntohl (mp->retval);
747 vam->result_ready = 1;
750 static void vl_api_create_vlan_subif_reply_t_handler
751 (vl_api_create_vlan_subif_reply_t * mp)
753 vat_main_t *vam = &vat_main;
754 i32 retval = ntohl (mp->retval);
756 vam->retval = retval;
757 vam->regenerate_interface_table = 1;
758 vam->sw_if_index = ntohl (mp->sw_if_index);
759 vam->result_ready = 1;
762 static void vl_api_create_vlan_subif_reply_t_handler_json
763 (vl_api_create_vlan_subif_reply_t * mp)
765 vat_main_t *vam = &vat_main;
766 vat_json_node_t node;
768 vat_json_init_object (&node);
769 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
770 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
772 vat_json_print (vam->ofp, &node);
773 vat_json_free (&node);
775 vam->retval = ntohl (mp->retval);
776 vam->result_ready = 1;
779 static void vl_api_create_subif_reply_t_handler
780 (vl_api_create_subif_reply_t * mp)
782 vat_main_t *vam = &vat_main;
783 i32 retval = ntohl (mp->retval);
785 vam->retval = retval;
786 vam->regenerate_interface_table = 1;
787 vam->sw_if_index = ntohl (mp->sw_if_index);
788 vam->result_ready = 1;
791 static void vl_api_create_subif_reply_t_handler_json
792 (vl_api_create_subif_reply_t * mp)
794 vat_main_t *vam = &vat_main;
795 vat_json_node_t node;
797 vat_json_init_object (&node);
798 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
799 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
801 vat_json_print (vam->ofp, &node);
802 vat_json_free (&node);
804 vam->retval = ntohl (mp->retval);
805 vam->result_ready = 1;
808 static void vl_api_interface_name_renumber_reply_t_handler
809 (vl_api_interface_name_renumber_reply_t * mp)
811 vat_main_t *vam = &vat_main;
812 i32 retval = ntohl (mp->retval);
814 vam->retval = retval;
815 vam->regenerate_interface_table = 1;
816 vam->result_ready = 1;
819 static void vl_api_interface_name_renumber_reply_t_handler_json
820 (vl_api_interface_name_renumber_reply_t * mp)
822 vat_main_t *vam = &vat_main;
823 vat_json_node_t node;
825 vat_json_init_object (&node);
826 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
828 vat_json_print (vam->ofp, &node);
829 vat_json_free (&node);
831 vam->retval = ntohl (mp->retval);
832 vam->result_ready = 1;
836 * Special-case: build the interface table, maintain
837 * the next loopback sw_if_index vbl.
839 static void vl_api_sw_interface_details_t_handler
840 (vl_api_sw_interface_details_t * mp)
842 vat_main_t *vam = &vat_main;
843 u8 *s = format (0, "%s%c", mp->interface_name, 0);
845 hash_set_mem (vam->sw_if_index_by_interface_name, s,
846 ntohl (mp->sw_if_index));
848 /* In sub interface case, fill the sub interface table entry */
849 if (mp->sw_if_index != mp->sup_sw_if_index)
851 sw_interface_subif_t *sub = NULL;
853 vec_add2 (vam->sw_if_subif_table, sub, 1);
855 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
856 strncpy ((char *) sub->interface_name, (char *) s,
857 vec_len (sub->interface_name));
858 sub->sw_if_index = ntohl (mp->sw_if_index);
859 sub->sub_id = ntohl (mp->sub_id);
861 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
863 sub->sub_number_of_tags = mp->sub_number_of_tags;
864 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
865 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
867 /* vlan tag rewrite */
868 sub->vtr_op = ntohl (mp->vtr_op);
869 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
870 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
871 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
875 static void vl_api_sw_interface_details_t_handler_json
876 (vl_api_sw_interface_details_t * mp)
878 vat_main_t *vam = &vat_main;
879 vat_json_node_t *node = NULL;
881 if (VAT_JSON_ARRAY != vam->json_tree.type)
883 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
884 vat_json_init_array (&vam->json_tree);
886 node = vat_json_array_add (&vam->json_tree);
888 vat_json_init_object (node);
889 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
890 vat_json_object_add_uint (node, "sup_sw_if_index",
891 ntohl (mp->sup_sw_if_index));
892 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
893 sizeof (mp->l2_address));
894 vat_json_object_add_string_copy (node, "interface_name",
896 vat_json_object_add_string_copy (node, "interface_dev_type",
897 mp->interface_dev_type);
898 vat_json_object_add_uint (node, "flags", mp->flags);
899 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
900 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
901 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
902 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
903 vat_json_object_add_uint (node, "sub_number_of_tags",
904 mp->sub_number_of_tags);
905 vat_json_object_add_uint (node, "sub_outer_vlan_id",
906 ntohs (mp->sub_outer_vlan_id));
907 vat_json_object_add_uint (node, "sub_inner_vlan_id",
908 ntohs (mp->sub_inner_vlan_id));
909 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
910 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
911 vat_json_object_add_uint (node, "vtr_push_dot1q",
912 ntohl (mp->vtr_push_dot1q));
913 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
914 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
915 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
917 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
919 format_ethernet_address,
921 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
923 format_ethernet_address,
925 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
926 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
930 #if VPP_API_TEST_BUILTIN == 0
931 static void vl_api_sw_interface_event_t_handler
932 (vl_api_sw_interface_event_t * mp)
934 vat_main_t *vam = &vat_main;
935 if (vam->interface_event_display)
936 errmsg ("interface flags: sw_if_index %d %s %s",
937 ntohl (mp->sw_if_index),
938 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
939 "admin-up" : "admin-down",
940 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
941 "link-up" : "link-down");
945 __clib_unused static void
946 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
948 /* JSON output not supported */
952 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
954 vat_main_t *vam = &vat_main;
955 i32 retval = ntohl (mp->retval);
957 vam->retval = retval;
958 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
959 vam->result_ready = 1;
963 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
965 vat_main_t *vam = &vat_main;
966 vat_json_node_t node;
970 vat_json_init_object (&node);
971 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
972 vat_json_object_add_uint (&node, "reply_in_shmem",
973 ntohl (mp->reply_in_shmem));
974 /* Toss the shared-memory original... */
975 oldheap = vl_msg_push_heap ();
977 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
980 vl_msg_pop_heap (oldheap);
982 vat_json_print (vam->ofp, &node);
983 vat_json_free (&node);
985 vam->retval = ntohl (mp->retval);
986 vam->result_ready = 1;
990 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
992 vat_main_t *vam = &vat_main;
993 i32 retval = ntohl (mp->retval);
995 vec_reset_length (vam->cmd_reply);
997 vam->retval = retval;
999 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1000 vam->result_ready = 1;
1004 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1006 vat_main_t *vam = &vat_main;
1007 vat_json_node_t node;
1008 u8 *reply = 0; /* reply vector */
1010 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1011 vec_reset_length (vam->cmd_reply);
1013 vat_json_init_object (&node);
1014 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1015 vat_json_object_add_string_copy (&node, "reply", reply);
1017 vat_json_print (vam->ofp, &node);
1018 vat_json_free (&node);
1021 vam->retval = ntohl (mp->retval);
1022 vam->result_ready = 1;
1025 static void vl_api_get_node_index_reply_t_handler
1026 (vl_api_get_node_index_reply_t * mp)
1028 vat_main_t *vam = &vat_main;
1029 i32 retval = ntohl (mp->retval);
1030 if (vam->async_mode)
1032 vam->async_errors += (retval < 0);
1036 vam->retval = retval;
1038 errmsg ("node index %d", ntohl (mp->node_index));
1039 vam->result_ready = 1;
1043 static void vl_api_get_node_index_reply_t_handler_json
1044 (vl_api_get_node_index_reply_t * mp)
1046 vat_main_t *vam = &vat_main;
1047 vat_json_node_t node;
1049 vat_json_init_object (&node);
1050 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1051 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1053 vat_json_print (vam->ofp, &node);
1054 vat_json_free (&node);
1056 vam->retval = ntohl (mp->retval);
1057 vam->result_ready = 1;
1060 static void vl_api_get_next_index_reply_t_handler
1061 (vl_api_get_next_index_reply_t * mp)
1063 vat_main_t *vam = &vat_main;
1064 i32 retval = ntohl (mp->retval);
1065 if (vam->async_mode)
1067 vam->async_errors += (retval < 0);
1071 vam->retval = retval;
1073 errmsg ("next node index %d", ntohl (mp->next_index));
1074 vam->result_ready = 1;
1078 static void vl_api_get_next_index_reply_t_handler_json
1079 (vl_api_get_next_index_reply_t * mp)
1081 vat_main_t *vam = &vat_main;
1082 vat_json_node_t node;
1084 vat_json_init_object (&node);
1085 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1086 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1088 vat_json_print (vam->ofp, &node);
1089 vat_json_free (&node);
1091 vam->retval = ntohl (mp->retval);
1092 vam->result_ready = 1;
1095 static void vl_api_add_node_next_reply_t_handler
1096 (vl_api_add_node_next_reply_t * mp)
1098 vat_main_t *vam = &vat_main;
1099 i32 retval = ntohl (mp->retval);
1100 if (vam->async_mode)
1102 vam->async_errors += (retval < 0);
1106 vam->retval = retval;
1108 errmsg ("next index %d", ntohl (mp->next_index));
1109 vam->result_ready = 1;
1113 static void vl_api_add_node_next_reply_t_handler_json
1114 (vl_api_add_node_next_reply_t * mp)
1116 vat_main_t *vam = &vat_main;
1117 vat_json_node_t node;
1119 vat_json_init_object (&node);
1120 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1121 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1123 vat_json_print (vam->ofp, &node);
1124 vat_json_free (&node);
1126 vam->retval = ntohl (mp->retval);
1127 vam->result_ready = 1;
1130 static void vl_api_show_version_reply_t_handler
1131 (vl_api_show_version_reply_t * mp)
1133 vat_main_t *vam = &vat_main;
1134 i32 retval = ntohl (mp->retval);
1138 errmsg (" program: %s", mp->program);
1139 errmsg (" version: %s", mp->version);
1140 errmsg (" build date: %s", mp->build_date);
1141 errmsg ("build directory: %s", mp->build_directory);
1143 vam->retval = retval;
1144 vam->result_ready = 1;
1147 static void vl_api_show_version_reply_t_handler_json
1148 (vl_api_show_version_reply_t * mp)
1150 vat_main_t *vam = &vat_main;
1151 vat_json_node_t node;
1153 vat_json_init_object (&node);
1154 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1155 vat_json_object_add_string_copy (&node, "program", mp->program);
1156 vat_json_object_add_string_copy (&node, "version", mp->version);
1157 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1158 vat_json_object_add_string_copy (&node, "build_directory",
1159 mp->build_directory);
1161 vat_json_print (vam->ofp, &node);
1162 vat_json_free (&node);
1164 vam->retval = ntohl (mp->retval);
1165 vam->result_ready = 1;
1168 static void vl_api_show_threads_reply_t_handler
1169 (vl_api_show_threads_reply_t * mp)
1171 vat_main_t *vam = &vat_main;
1172 i32 retval = ntohl (mp->retval);
1176 count = ntohl (mp->count);
1178 for (i = 0; i < count; i++)
1180 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1181 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1182 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1183 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1184 ntohl (mp->thread_data[i].cpu_socket));
1186 vam->retval = retval;
1187 vam->result_ready = 1;
1190 static void vl_api_show_threads_reply_t_handler_json
1191 (vl_api_show_threads_reply_t * mp)
1193 vat_main_t *vam = &vat_main;
1194 vat_json_node_t node;
1195 vl_api_thread_data_t *td;
1196 i32 retval = ntohl (mp->retval);
1200 count = ntohl (mp->count);
1202 vat_json_init_object (&node);
1203 vat_json_object_add_int (&node, "retval", retval);
1204 vat_json_object_add_uint (&node, "count", count);
1206 for (i = 0; i < count; i++)
1208 td = &mp->thread_data[i];
1209 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1210 vat_json_object_add_string_copy (&node, "name", td->name);
1211 vat_json_object_add_string_copy (&node, "type", td->type);
1212 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1213 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1214 vat_json_object_add_int (&node, "core", ntohl (td->id));
1215 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1218 vat_json_print (vam->ofp, &node);
1219 vat_json_free (&node);
1221 vam->retval = retval;
1222 vam->result_ready = 1;
1226 api_show_threads (vat_main_t * vam)
1228 vl_api_show_threads_t *mp;
1232 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1233 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1235 M (SHOW_THREADS, mp);
1243 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1245 u32 n_macs = ntohl (mp->n_macs);
1246 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1247 ntohl (mp->pid), mp->client_index, n_macs);
1249 for (i = 0; i < n_macs; i++)
1251 vl_api_mac_entry_t *mac = &mp->mac[i];
1252 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1253 i + 1, ntohl (mac->sw_if_index),
1254 format_ethernet_address, mac->mac_addr, mac->action);
1261 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1263 /* JSON output not supported */
1266 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1267 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1270 * Special-case: build the bridge domain table, maintain
1271 * the next bd id vbl.
1273 static void vl_api_bridge_domain_details_t_handler
1274 (vl_api_bridge_domain_details_t * mp)
1276 vat_main_t *vam = &vat_main;
1277 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1280 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1281 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1283 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1284 ntohl (mp->bd_id), mp->learn, mp->forward,
1285 mp->flood, ntohl (mp->bvi_sw_if_index),
1286 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1290 vl_api_bridge_domain_sw_if_t *sw_ifs;
1291 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1294 sw_ifs = mp->sw_if_details;
1295 for (i = 0; i < n_sw_ifs; i++)
1301 sw_if_index = ntohl (sw_ifs->sw_if_index);
1304 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1306 if ((u32) p->value[0] == sw_if_index)
1308 sw_if_name = (u8 *)(p->key);
1313 print (vam->ofp, "%7d %3d %s", sw_if_index,
1314 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1315 "sw_if_index not found!");
1322 static void vl_api_bridge_domain_details_t_handler_json
1323 (vl_api_bridge_domain_details_t * mp)
1325 vat_main_t *vam = &vat_main;
1326 vat_json_node_t *node, *array = NULL;
1327 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1329 if (VAT_JSON_ARRAY != vam->json_tree.type)
1331 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1332 vat_json_init_array (&vam->json_tree);
1334 node = vat_json_array_add (&vam->json_tree);
1336 vat_json_init_object (node);
1337 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1338 vat_json_object_add_uint (node, "flood", mp->flood);
1339 vat_json_object_add_uint (node, "forward", mp->forward);
1340 vat_json_object_add_uint (node, "learn", mp->learn);
1341 vat_json_object_add_uint (node, "bvi_sw_if_index",
1342 ntohl (mp->bvi_sw_if_index));
1343 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1344 array = vat_json_object_add (node, "sw_if");
1345 vat_json_init_array (array);
1351 vl_api_bridge_domain_sw_if_t *sw_ifs;
1354 sw_ifs = mp->sw_if_details;
1355 for (i = 0; i < n_sw_ifs; i++)
1357 node = vat_json_array_add (array);
1358 vat_json_init_object (node);
1359 vat_json_object_add_uint (node, "sw_if_index",
1360 ntohl (sw_ifs->sw_if_index));
1361 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1367 static void vl_api_control_ping_reply_t_handler
1368 (vl_api_control_ping_reply_t * mp)
1370 vat_main_t *vam = &vat_main;
1371 i32 retval = ntohl (mp->retval);
1372 if (vam->async_mode)
1374 vam->async_errors += (retval < 0);
1378 vam->retval = retval;
1379 vam->result_ready = 1;
1381 if (vam->socket_client_main)
1382 vam->socket_client_main->control_pings_outstanding--;
1385 static void vl_api_control_ping_reply_t_handler_json
1386 (vl_api_control_ping_reply_t * mp)
1388 vat_main_t *vam = &vat_main;
1389 i32 retval = ntohl (mp->retval);
1391 if (VAT_JSON_NONE != vam->json_tree.type)
1393 vat_json_print (vam->ofp, &vam->json_tree);
1394 vat_json_free (&vam->json_tree);
1395 vam->json_tree.type = VAT_JSON_NONE;
1400 vat_json_init_array (&vam->json_tree);
1401 vat_json_print (vam->ofp, &vam->json_tree);
1402 vam->json_tree.type = VAT_JSON_NONE;
1405 vam->retval = retval;
1406 vam->result_ready = 1;
1410 vl_api_bridge_domain_set_mac_age_reply_t_handler
1411 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1413 vat_main_t *vam = &vat_main;
1414 i32 retval = ntohl (mp->retval);
1415 if (vam->async_mode)
1417 vam->async_errors += (retval < 0);
1421 vam->retval = retval;
1422 vam->result_ready = 1;
1426 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1427 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1429 vat_main_t *vam = &vat_main;
1430 vat_json_node_t node;
1432 vat_json_init_object (&node);
1433 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1435 vat_json_print (vam->ofp, &node);
1436 vat_json_free (&node);
1438 vam->retval = ntohl (mp->retval);
1439 vam->result_ready = 1;
1443 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1445 vat_main_t *vam = &vat_main;
1446 i32 retval = ntohl (mp->retval);
1447 if (vam->async_mode)
1449 vam->async_errors += (retval < 0);
1453 vam->retval = retval;
1454 vam->result_ready = 1;
1458 static void vl_api_l2_flags_reply_t_handler_json
1459 (vl_api_l2_flags_reply_t * mp)
1461 vat_main_t *vam = &vat_main;
1462 vat_json_node_t node;
1464 vat_json_init_object (&node);
1465 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1466 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1467 ntohl (mp->resulting_feature_bitmap));
1469 vat_json_print (vam->ofp, &node);
1470 vat_json_free (&node);
1472 vam->retval = ntohl (mp->retval);
1473 vam->result_ready = 1;
1476 static void vl_api_bridge_flags_reply_t_handler
1477 (vl_api_bridge_flags_reply_t * mp)
1479 vat_main_t *vam = &vat_main;
1480 i32 retval = ntohl (mp->retval);
1481 if (vam->async_mode)
1483 vam->async_errors += (retval < 0);
1487 vam->retval = retval;
1488 vam->result_ready = 1;
1492 static void vl_api_bridge_flags_reply_t_handler_json
1493 (vl_api_bridge_flags_reply_t * mp)
1495 vat_main_t *vam = &vat_main;
1496 vat_json_node_t node;
1498 vat_json_init_object (&node);
1499 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1500 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1501 ntohl (mp->resulting_feature_bitmap));
1503 vat_json_print (vam->ofp, &node);
1504 vat_json_free (&node);
1506 vam->retval = ntohl (mp->retval);
1507 vam->result_ready = 1;
1511 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1514 vat_main_t *vam = &vat_main;
1515 i32 retval = ntohl (mp->retval);
1516 if (vam->async_mode)
1518 vam->async_errors += (retval < 0);
1522 vam->retval = retval;
1523 vam->sw_if_index = ntohl (mp->sw_if_index);
1524 vam->result_ready = 1;
1528 static void vl_api_virtio_pci_create_reply_t_handler_json
1529 (vl_api_virtio_pci_create_reply_t * mp)
1531 vat_main_t *vam = &vat_main;
1532 vat_json_node_t node;
1534 vat_json_init_object (&node);
1535 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1536 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1538 vat_json_print (vam->ofp, &node);
1539 vat_json_free (&node);
1541 vam->retval = ntohl (mp->retval);
1542 vam->result_ready = 1;
1547 vl_api_virtio_pci_create_v2_reply_t_handler
1548 (vl_api_virtio_pci_create_v2_reply_t * mp)
1550 vat_main_t *vam = &vat_main;
1551 i32 retval = ntohl (mp->retval);
1552 if (vam->async_mode)
1554 vam->async_errors += (retval < 0);
1558 vam->retval = retval;
1559 vam->sw_if_index = ntohl (mp->sw_if_index);
1560 vam->result_ready = 1;
1564 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1565 (vl_api_virtio_pci_create_v2_reply_t * mp)
1567 vat_main_t *vam = &vat_main;
1568 vat_json_node_t node;
1570 vat_json_init_object (&node);
1571 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1572 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1574 vat_json_print (vam->ofp, &node);
1575 vat_json_free (&node);
1577 vam->retval = ntohl (mp->retval);
1578 vam->result_ready = 1;
1582 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1585 vat_main_t *vam = &vat_main;
1586 i32 retval = ntohl (mp->retval);
1587 if (vam->async_mode)
1589 vam->async_errors += (retval < 0);
1593 vam->retval = retval;
1594 vam->result_ready = 1;
1598 static void vl_api_virtio_pci_delete_reply_t_handler_json
1599 (vl_api_virtio_pci_delete_reply_t * mp)
1601 vat_main_t *vam = &vat_main;
1602 vat_json_node_t node;
1604 vat_json_init_object (&node);
1605 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1607 vat_json_print (vam->ofp, &node);
1608 vat_json_free (&node);
1610 vam->retval = ntohl (mp->retval);
1611 vam->result_ready = 1;
1614 static void vl_api_mpls_tunnel_add_del_reply_t_handler
1615 (vl_api_mpls_tunnel_add_del_reply_t * mp)
1617 vat_main_t *vam = &vat_main;
1618 i32 retval = ntohl (mp->retval);
1619 if (vam->async_mode)
1621 vam->async_errors += (retval < 0);
1625 vam->retval = retval;
1626 vam->sw_if_index = ntohl (mp->sw_if_index);
1627 vam->result_ready = 1;
1629 vam->regenerate_interface_table = 1;
1632 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
1633 (vl_api_mpls_tunnel_add_del_reply_t * mp)
1635 vat_main_t *vam = &vat_main;
1636 vat_json_node_t node;
1638 vat_json_init_object (&node);
1639 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1640 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
1641 ntohl (mp->sw_if_index));
1643 vat_json_print (vam->ofp, &node);
1644 vat_json_free (&node);
1646 vam->retval = ntohl (mp->retval);
1647 vam->result_ready = 1;
1650 static void vl_api_create_vhost_user_if_reply_t_handler
1651 (vl_api_create_vhost_user_if_reply_t * mp)
1653 vat_main_t *vam = &vat_main;
1654 i32 retval = ntohl (mp->retval);
1655 if (vam->async_mode)
1657 vam->async_errors += (retval < 0);
1661 vam->retval = retval;
1662 vam->sw_if_index = ntohl (mp->sw_if_index);
1663 vam->result_ready = 1;
1665 vam->regenerate_interface_table = 1;
1668 static void vl_api_create_vhost_user_if_reply_t_handler_json
1669 (vl_api_create_vhost_user_if_reply_t * mp)
1671 vat_main_t *vam = &vat_main;
1672 vat_json_node_t node;
1674 vat_json_init_object (&node);
1675 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1676 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1678 vat_json_print (vam->ofp, &node);
1679 vat_json_free (&node);
1681 vam->retval = ntohl (mp->retval);
1682 vam->result_ready = 1;
1685 static void vl_api_create_vhost_user_if_v2_reply_t_handler
1686 (vl_api_create_vhost_user_if_v2_reply_t * mp)
1688 vat_main_t *vam = &vat_main;
1689 i32 retval = ntohl (mp->retval);
1690 if (vam->async_mode)
1692 vam->async_errors += (retval < 0);
1696 vam->retval = retval;
1697 vam->sw_if_index = ntohl (mp->sw_if_index);
1698 vam->result_ready = 1;
1700 vam->regenerate_interface_table = 1;
1703 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
1704 (vl_api_create_vhost_user_if_v2_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;
1720 static void vl_api_ip_address_details_t_handler
1721 (vl_api_ip_address_details_t * mp)
1723 vat_main_t *vam = &vat_main;
1724 static ip_address_details_t empty_ip_address_details = { {0} };
1725 ip_address_details_t *address = NULL;
1726 ip_details_t *current_ip_details = NULL;
1727 ip_details_t *details = NULL;
1729 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1731 if (!details || vam->current_sw_if_index >= vec_len (details)
1732 || !details[vam->current_sw_if_index].present)
1734 errmsg ("ip address details arrived but not stored");
1735 errmsg ("ip_dump should be called first");
1739 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
1741 #define addresses (current_ip_details->addr)
1743 vec_validate_init_empty (addresses, vec_len (addresses),
1744 empty_ip_address_details);
1746 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
1748 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
1749 address->prefix_length = mp->prefix.len;
1753 static void vl_api_ip_address_details_t_handler_json
1754 (vl_api_ip_address_details_t * mp)
1756 vat_main_t *vam = &vat_main;
1757 vat_json_node_t *node = NULL;
1759 if (VAT_JSON_ARRAY != vam->json_tree.type)
1761 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1762 vat_json_init_array (&vam->json_tree);
1764 node = vat_json_array_add (&vam->json_tree);
1766 vat_json_init_object (node);
1767 vat_json_object_add_prefix (node, &mp->prefix);
1771 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1773 vat_main_t *vam = &vat_main;
1774 static ip_details_t empty_ip_details = { 0 };
1775 ip_details_t *ip = NULL;
1776 u32 sw_if_index = ~0;
1778 sw_if_index = ntohl (mp->sw_if_index);
1780 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1781 sw_if_index, empty_ip_details);
1783 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
1790 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1792 vat_main_t *vam = &vat_main;
1794 if (VAT_JSON_ARRAY != vam->json_tree.type)
1796 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1797 vat_json_init_array (&vam->json_tree);
1799 vat_json_array_add_uint (&vam->json_tree,
1800 clib_net_to_host_u32 (mp->sw_if_index));
1803 static void vl_api_get_first_msg_id_reply_t_handler
1804 (vl_api_get_first_msg_id_reply_t * mp)
1806 vat_main_t *vam = &vat_main;
1807 i32 retval = ntohl (mp->retval);
1809 if (vam->async_mode)
1811 vam->async_errors += (retval < 0);
1815 vam->retval = retval;
1816 vam->result_ready = 1;
1820 errmsg ("first message id %d", ntohs (mp->first_msg_id));
1824 static void vl_api_get_first_msg_id_reply_t_handler_json
1825 (vl_api_get_first_msg_id_reply_t * mp)
1827 vat_main_t *vam = &vat_main;
1828 vat_json_node_t node;
1830 vat_json_init_object (&node);
1831 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1832 vat_json_object_add_uint (&node, "first_msg_id",
1833 (uint) ntohs (mp->first_msg_id));
1835 vat_json_print (vam->ofp, &node);
1836 vat_json_free (&node);
1838 vam->retval = ntohl (mp->retval);
1839 vam->result_ready = 1;
1842 static void vl_api_get_node_graph_reply_t_handler
1843 (vl_api_get_node_graph_reply_t * mp)
1845 vat_main_t *vam = &vat_main;
1846 i32 retval = ntohl (mp->retval);
1847 u8 *pvt_copy, *reply;
1852 if (vam->async_mode)
1854 vam->async_errors += (retval < 0);
1858 vam->retval = retval;
1859 vam->result_ready = 1;
1862 /* "Should never happen..." */
1866 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1867 pvt_copy = vec_dup (reply);
1869 /* Toss the shared-memory original... */
1870 oldheap = vl_msg_push_heap ();
1874 vl_msg_pop_heap (oldheap);
1876 if (vam->graph_nodes)
1878 hash_free (vam->graph_node_index_by_name);
1880 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
1882 node = vam->graph_nodes[0][i];
1883 vec_free (node->name);
1884 vec_free (node->next_nodes);
1887 vec_free (vam->graph_nodes[0]);
1888 vec_free (vam->graph_nodes);
1891 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
1892 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1893 vec_free (pvt_copy);
1895 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
1897 node = vam->graph_nodes[0][i];
1898 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1902 static void vl_api_get_node_graph_reply_t_handler_json
1903 (vl_api_get_node_graph_reply_t * mp)
1905 vat_main_t *vam = &vat_main;
1907 vat_json_node_t node;
1910 /* $$$$ make this real? */
1911 vat_json_init_object (&node);
1912 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1913 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
1915 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1917 /* Toss the shared-memory original... */
1918 oldheap = vl_msg_push_heap ();
1922 vl_msg_pop_heap (oldheap);
1924 vat_json_print (vam->ofp, &node);
1925 vat_json_free (&node);
1927 vam->retval = ntohl (mp->retval);
1928 vam->result_ready = 1;
1931 /* Format hex dump. */
1933 format_hex_bytes (u8 * s, va_list * va)
1935 u8 *bytes = va_arg (*va, u8 *);
1936 int n_bytes = va_arg (*va, int);
1939 /* Print short or long form depending on byte count. */
1940 uword short_form = n_bytes <= 32;
1941 u32 indent = format_get_indent (s);
1946 for (i = 0; i < n_bytes; i++)
1948 if (!short_form && (i % 32) == 0)
1949 s = format (s, "%08x: ", i);
1950 s = format (s, "%02x", bytes[i]);
1951 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
1952 s = format (s, "\n%U", format_white_space, indent);
1959 * Generate boilerplate reply handlers, which
1960 * dig the return value out of the xxx_reply_t API message,
1961 * stick it into vam->retval, and set vam->result_ready
1963 * Could also do this by pointing N message decode slots at
1964 * a single function, but that could break in subtle ways.
1967 #define foreach_standard_reply_retval_handler \
1968 _(sw_interface_set_flags_reply) \
1969 _(sw_interface_add_del_address_reply) \
1970 _(sw_interface_set_rx_mode_reply) \
1971 _(sw_interface_set_rx_placement_reply) \
1972 _(sw_interface_set_table_reply) \
1973 _(sw_interface_set_mpls_enable_reply) \
1974 _(sw_interface_set_vpath_reply) \
1975 _(sw_interface_set_l2_bridge_reply) \
1976 _(bridge_domain_add_del_reply) \
1977 _(sw_interface_set_l2_xconnect_reply) \
1978 _(l2fib_add_del_reply) \
1979 _(l2fib_flush_int_reply) \
1980 _(l2fib_flush_bd_reply) \
1981 _(ip_route_add_del_reply) \
1982 _(ip_table_add_del_reply) \
1983 _(ip_table_replace_begin_reply) \
1984 _(ip_table_flush_reply) \
1985 _(ip_table_replace_end_reply) \
1986 _(ip_mroute_add_del_reply) \
1987 _(mpls_route_add_del_reply) \
1988 _(mpls_table_add_del_reply) \
1989 _(mpls_ip_bind_unbind_reply) \
1990 _(sw_interface_set_unnumbered_reply) \
1991 _(set_ip_flow_hash_reply) \
1992 _(sw_interface_ip6_enable_disable_reply) \
1993 _(l2_patch_add_del_reply) \
1994 _(l2_fib_clear_table_reply) \
1995 _(l2_interface_efp_filter_reply) \
1996 _(l2_interface_vlan_tag_rewrite_reply) \
1997 _(modify_vhost_user_if_reply) \
1998 _(modify_vhost_user_if_v2_reply) \
1999 _(delete_vhost_user_if_reply) \
2000 _(want_l2_macs_events_reply) \
2001 _(delete_loopback_reply) \
2002 _(bd_ip_mac_add_del_reply) \
2003 _(bd_ip_mac_flush_reply) \
2004 _(want_interface_events_reply) \
2005 _(sw_interface_clear_stats_reply) \
2006 _(ioam_enable_reply) \
2007 _(ioam_disable_reply) \
2008 _(af_packet_delete_reply) \
2009 _(sw_interface_span_enable_disable_reply) \
2010 _(ip_source_and_port_range_check_add_del_reply) \
2011 _(ip_source_and_port_range_check_interface_add_del_reply)\
2012 _(delete_subif_reply) \
2013 _(l2_interface_pbb_tag_rewrite_reply) \
2015 _(sw_interface_tag_add_del_reply) \
2016 _(sw_interface_add_del_mac_address_reply) \
2017 _(hw_interface_set_mtu_reply) \
2018 _(tcp_configure_src_addresses_reply) \
2019 _(session_rule_add_del_reply) \
2020 _(ip_container_proxy_add_del_reply) \
2021 _(qos_record_enable_disable_reply) \
2024 static void vl_api_##n##_t_handler \
2025 (vl_api_##n##_t * mp) \
2027 vat_main_t * vam = &vat_main; \
2028 i32 retval = ntohl(mp->retval); \
2029 if (vam->async_mode) { \
2030 vam->async_errors += (retval < 0); \
2032 vam->retval = retval; \
2033 vam->result_ready = 1; \
2036 foreach_standard_reply_retval_handler;
2040 static void vl_api_##n##_t_handler_json \
2041 (vl_api_##n##_t * mp) \
2043 vat_main_t * vam = &vat_main; \
2044 vat_json_node_t node; \
2045 vat_json_init_object(&node); \
2046 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2047 vat_json_print(vam->ofp, &node); \
2048 vam->retval = ntohl(mp->retval); \
2049 vam->result_ready = 1; \
2051 foreach_standard_reply_retval_handler;
2055 * Table of message reply handlers, must include boilerplate handlers
2059 #define foreach_vpe_api_reply_msg \
2060 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2061 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2062 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2063 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2064 _(CONTROL_PING_REPLY, control_ping_reply) \
2065 _(CLI_REPLY, cli_reply) \
2066 _(CLI_INBAND_REPLY, cli_inband_reply) \
2067 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2068 sw_interface_add_del_address_reply) \
2069 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2070 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2071 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2072 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2073 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2074 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2075 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2076 sw_interface_set_l2_xconnect_reply) \
2077 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2078 sw_interface_set_l2_bridge_reply) \
2079 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2080 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2081 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2082 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2083 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2084 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2085 _(L2_FLAGS_REPLY, l2_flags_reply) \
2086 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2087 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2088 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2089 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2090 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2091 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2092 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2093 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2094 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2095 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2096 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2097 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2098 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2099 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2100 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2101 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2102 sw_interface_set_unnumbered_reply) \
2103 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2104 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2105 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2106 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2107 sw_interface_ip6_enable_disable_reply) \
2108 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2109 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2110 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2111 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2112 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2113 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2114 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2115 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2116 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2117 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2118 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2119 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2120 _(SHOW_VERSION_REPLY, show_version_reply) \
2121 _(SHOW_THREADS_REPLY, show_threads_reply) \
2122 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2123 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2124 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2125 _(L2_MACS_EVENT, l2_macs_event) \
2126 _(IP_ADDRESS_DETAILS, ip_address_details) \
2127 _(IP_DETAILS, ip_details) \
2128 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2129 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2130 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
2131 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
2132 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2133 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2134 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2135 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2136 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
2137 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
2138 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2139 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2140 _(AF_PACKET_DETAILS, af_packet_details) \
2141 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
2142 _(MPLS_TABLE_DETAILS, mpls_table_details) \
2143 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
2144 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
2145 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
2146 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
2147 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
2148 ip_source_and_port_range_check_add_del_reply) \
2149 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
2150 ip_source_and_port_range_check_interface_add_del_reply) \
2151 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
2152 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
2153 _(SET_PUNT_REPLY, set_punt_reply) \
2154 _(IP_TABLE_DETAILS, ip_table_details) \
2155 _(IP_ROUTE_DETAILS, ip_route_details) \
2156 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
2157 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
2158 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
2159 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
2160 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
2161 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
2162 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
2163 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
2164 _(SESSION_RULES_DETAILS, session_rules_details) \
2165 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
2166 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
2168 #define foreach_standalone_reply_msg \
2169 _(SW_INTERFACE_EVENT, sw_interface_event)
2177 #define STR_VTR_OP_CASE(op) \
2178 case L2_VTR_ ## op: \
2182 str_vtr_op (u32 vtr_op)
2186 STR_VTR_OP_CASE (DISABLED);
2187 STR_VTR_OP_CASE (PUSH_1);
2188 STR_VTR_OP_CASE (PUSH_2);
2189 STR_VTR_OP_CASE (POP_1);
2190 STR_VTR_OP_CASE (POP_2);
2191 STR_VTR_OP_CASE (TRANSLATE_1_1);
2192 STR_VTR_OP_CASE (TRANSLATE_1_2);
2193 STR_VTR_OP_CASE (TRANSLATE_2_1);
2194 STR_VTR_OP_CASE (TRANSLATE_2_2);
2201 dump_sub_interface_table (vat_main_t * vam)
2203 const sw_interface_subif_t *sub = NULL;
2205 if (vam->json_output)
2208 ("JSON output supported only for VPE API calls and dump_stats_table");
2213 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
2214 "Interface", "sw_if_index",
2215 "sub id", "dot1ad", "tags", "outer id",
2216 "inner id", "exact", "default", "outer any", "inner any");
2218 vec_foreach (sub, vam->sw_if_subif_table)
2221 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
2222 sub->interface_name,
2224 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2225 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2226 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2227 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2228 if (sub->vtr_op != L2_VTR_DISABLED)
2231 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2232 "tag1: %d tag2: %d ]",
2233 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
2234 sub->vtr_tag1, sub->vtr_tag2);
2242 name_sort_cmp (void *a1, void *a2)
2244 name_sort_t *n1 = a1;
2245 name_sort_t *n2 = a2;
2247 return strcmp ((char *) n1->name, (char *) n2->name);
2251 dump_interface_table (vat_main_t * vam)
2254 name_sort_t *nses = 0, *ns;
2256 if (vam->json_output)
2259 ("JSON output supported only for VPE API calls and dump_stats_table");
2264 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2266 vec_add2 (nses, ns, 1);
2267 ns->name = (u8 *)(p->key);
2268 ns->value = (u32) p->value[0];
2272 vec_sort_with_function (nses, name_sort_cmp);
2274 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
2275 vec_foreach (ns, nses)
2277 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
2284 dump_ip_table (vat_main_t * vam, int is_ipv6)
2286 const ip_details_t *det = NULL;
2287 const ip_address_details_t *address = NULL;
2290 print (vam->ofp, "%-12s", "sw_if_index");
2292 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
2299 print (vam->ofp, "%-12d", i);
2300 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
2305 vec_foreach (address, det->addr)
2309 is_ipv6 ? format_ip6_address : format_ip4_address,
2310 address->ip, address->prefix_length);
2318 dump_ipv4_table (vat_main_t * vam)
2320 if (vam->json_output)
2323 ("JSON output supported only for VPE API calls and dump_stats_table");
2327 return dump_ip_table (vam, 0);
2331 dump_ipv6_table (vat_main_t * vam)
2333 if (vam->json_output)
2336 ("JSON output supported only for VPE API calls and dump_stats_table");
2340 return dump_ip_table (vam, 1);
2344 * Pass CLI buffers directly in the CLI_INBAND API message,
2345 * instead of an additional shared memory area.
2348 exec_inband (vat_main_t * vam)
2350 vl_api_cli_inband_t *mp;
2351 unformat_input_t *i = vam->input;
2354 if (vec_len (i->buffer) == 0)
2357 if (vam->exec_mode == 0 && unformat (i, "mode"))
2362 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
2369 * In order for the CLI command to work, it
2370 * must be a vector ending in \n, not a C-string ending
2373 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
2374 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
2378 /* json responses may or may not include a useful reply... */
2379 if (vec_len (vam->cmd_reply))
2380 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
2385 exec (vat_main_t * vam)
2387 return exec_inband (vam);
2391 api_create_loopback (vat_main_t * vam)
2393 unformat_input_t *i = vam->input;
2394 vl_api_create_loopback_t *mp;
2395 vl_api_create_loopback_instance_t *mp_lbi;
2398 u8 is_specified = 0;
2399 u32 user_instance = 0;
2402 clib_memset (mac_address, 0, sizeof (mac_address));
2404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2406 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2408 if (unformat (i, "instance %d", &user_instance))
2416 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
2417 mp_lbi->is_specified = is_specified;
2419 mp_lbi->user_instance = htonl (user_instance);
2421 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
2426 /* Construct the API message */
2427 M (CREATE_LOOPBACK, mp);
2429 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2438 api_delete_loopback (vat_main_t * vam)
2440 unformat_input_t *i = vam->input;
2441 vl_api_delete_loopback_t *mp;
2442 u32 sw_if_index = ~0;
2445 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2447 if (unformat (i, "sw_if_index %d", &sw_if_index))
2453 if (sw_if_index == ~0)
2455 errmsg ("missing sw_if_index");
2459 /* Construct the API message */
2460 M (DELETE_LOOPBACK, mp);
2461 mp->sw_if_index = ntohl (sw_if_index);
2469 api_want_interface_events (vat_main_t * vam)
2471 unformat_input_t *i = vam->input;
2472 vl_api_want_interface_events_t *mp;
2476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2478 if (unformat (i, "enable"))
2480 else if (unformat (i, "disable"))
2488 errmsg ("missing enable|disable");
2492 M (WANT_INTERFACE_EVENTS, mp);
2493 mp->enable_disable = enable;
2495 vam->interface_event_display = enable;
2503 /* Note: non-static, called once to set up the initial intfc table */
2505 api_sw_interface_dump (vat_main_t * vam)
2507 vl_api_sw_interface_dump_t *mp;
2508 vl_api_control_ping_t *mp_ping;
2510 name_sort_t *nses = 0, *ns;
2511 sw_interface_subif_t *sub = NULL;
2514 /* Toss the old name table */
2516 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2518 vec_add2 (nses, ns, 1);
2519 ns->name = (u8 *)(p->key);
2520 ns->value = (u32) p->value[0];
2524 hash_free (vam->sw_if_index_by_interface_name);
2526 vec_foreach (ns, nses) vec_free (ns->name);
2530 vec_foreach (sub, vam->sw_if_subif_table)
2532 vec_free (sub->interface_name);
2534 vec_free (vam->sw_if_subif_table);
2536 /* recreate the interface name hash table */
2537 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
2540 * Ask for all interface names. Otherwise, the epic catalog of
2541 * name filters becomes ridiculously long, and vat ends up needing
2542 * to be taught about new interface types.
2544 M (SW_INTERFACE_DUMP, mp);
2547 /* Use a control ping for synchronization */
2548 MPING (CONTROL_PING, mp_ping);
2556 api_sw_interface_set_flags (vat_main_t * vam)
2558 unformat_input_t *i = vam->input;
2559 vl_api_sw_interface_set_flags_t *mp;
2561 u8 sw_if_index_set = 0;
2565 /* Parse args required to build the message */
2566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2568 if (unformat (i, "admin-up"))
2570 else if (unformat (i, "admin-down"))
2573 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2574 sw_if_index_set = 1;
2575 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2576 sw_if_index_set = 1;
2581 if (sw_if_index_set == 0)
2583 errmsg ("missing interface name or sw_if_index");
2587 /* Construct the API message */
2588 M (SW_INTERFACE_SET_FLAGS, mp);
2589 mp->sw_if_index = ntohl (sw_if_index);
2590 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
2595 /* Wait for a reply, return the good/bad news... */
2601 api_sw_interface_set_rx_mode (vat_main_t * vam)
2603 unformat_input_t *i = vam->input;
2604 vl_api_sw_interface_set_rx_mode_t *mp;
2606 u8 sw_if_index_set = 0;
2608 u8 queue_id_valid = 0;
2610 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
2612 /* Parse args required to build the message */
2613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2615 if (unformat (i, "queue %d", &queue_id))
2617 else if (unformat (i, "polling"))
2618 mode = VNET_HW_IF_RX_MODE_POLLING;
2619 else if (unformat (i, "interrupt"))
2620 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
2621 else if (unformat (i, "adaptive"))
2622 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
2624 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2625 sw_if_index_set = 1;
2626 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2627 sw_if_index_set = 1;
2632 if (sw_if_index_set == 0)
2634 errmsg ("missing interface name or sw_if_index");
2637 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
2639 errmsg ("missing rx-mode");
2643 /* Construct the API message */
2644 M (SW_INTERFACE_SET_RX_MODE, mp);
2645 mp->sw_if_index = ntohl (sw_if_index);
2646 mp->mode = (vl_api_rx_mode_t) mode;
2647 mp->queue_id_valid = queue_id_valid;
2648 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
2653 /* Wait for a reply, return the good/bad news... */
2659 api_sw_interface_set_rx_placement (vat_main_t * vam)
2661 unformat_input_t *i = vam->input;
2662 vl_api_sw_interface_set_rx_placement_t *mp;
2664 u8 sw_if_index_set = 0;
2667 u32 queue_id, thread_index;
2669 /* Parse args required to build the message */
2670 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2672 if (unformat (i, "queue %d", &queue_id))
2674 else if (unformat (i, "main"))
2676 else if (unformat (i, "worker %d", &thread_index))
2679 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2680 sw_if_index_set = 1;
2681 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2682 sw_if_index_set = 1;
2687 if (sw_if_index_set == 0)
2689 errmsg ("missing interface name or sw_if_index");
2695 /* Construct the API message */
2696 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
2697 mp->sw_if_index = ntohl (sw_if_index);
2698 mp->worker_id = ntohl (thread_index);
2699 mp->queue_id = ntohl (queue_id);
2700 mp->is_main = is_main;
2704 /* Wait for a reply, return the good/bad news... */
2709 static void vl_api_sw_interface_rx_placement_details_t_handler
2710 (vl_api_sw_interface_rx_placement_details_t * mp)
2712 vat_main_t *vam = &vat_main;
2713 u32 worker_id = ntohl (mp->worker_id);
2716 "\n%-11d %-11s %-6d %-5d %-9s",
2717 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
2718 worker_id, ntohl (mp->queue_id),
2720 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
2723 static void vl_api_sw_interface_rx_placement_details_t_handler_json
2724 (vl_api_sw_interface_rx_placement_details_t * mp)
2726 vat_main_t *vam = &vat_main;
2727 vat_json_node_t *node = NULL;
2729 if (VAT_JSON_ARRAY != vam->json_tree.type)
2731 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2732 vat_json_init_array (&vam->json_tree);
2734 node = vat_json_array_add (&vam->json_tree);
2736 vat_json_init_object (node);
2737 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2738 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
2739 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
2740 vat_json_object_add_uint (node, "mode", mp->mode);
2744 api_sw_interface_rx_placement_dump (vat_main_t * vam)
2746 unformat_input_t *i = vam->input;
2747 vl_api_sw_interface_rx_placement_dump_t *mp;
2748 vl_api_control_ping_t *mp_ping;
2751 u8 sw_if_index_set = 0;
2753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2755 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2757 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2764 "\n%-11s %-11s %-6s %-5s %-4s",
2765 "sw_if_index", "main/worker", "thread", "queue", "mode");
2767 /* Dump Interface rx placement */
2768 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
2770 if (sw_if_index_set)
2771 mp->sw_if_index = htonl (sw_if_index);
2773 mp->sw_if_index = ~0;
2777 /* Use a control ping for synchronization */
2778 MPING (CONTROL_PING, mp_ping);
2786 api_sw_interface_clear_stats (vat_main_t * vam)
2788 unformat_input_t *i = vam->input;
2789 vl_api_sw_interface_clear_stats_t *mp;
2791 u8 sw_if_index_set = 0;
2794 /* Parse args required to build the message */
2795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2797 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2798 sw_if_index_set = 1;
2799 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2800 sw_if_index_set = 1;
2805 /* Construct the API message */
2806 M (SW_INTERFACE_CLEAR_STATS, mp);
2808 if (sw_if_index_set == 1)
2809 mp->sw_if_index = ntohl (sw_if_index);
2811 mp->sw_if_index = ~0;
2816 /* Wait for a reply, return the good/bad news... */
2822 api_sw_interface_add_del_address (vat_main_t * vam)
2824 unformat_input_t *i = vam->input;
2825 vl_api_sw_interface_add_del_address_t *mp;
2827 u8 sw_if_index_set = 0;
2828 u8 is_add = 1, del_all = 0;
2829 u32 address_length = 0;
2830 u8 v4_address_set = 0;
2831 u8 v6_address_set = 0;
2832 ip4_address_t v4address;
2833 ip6_address_t v6address;
2836 /* Parse args required to build the message */
2837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2839 if (unformat (i, "del-all"))
2841 else if (unformat (i, "del"))
2844 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2845 sw_if_index_set = 1;
2846 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2847 sw_if_index_set = 1;
2848 else if (unformat (i, "%U/%d",
2849 unformat_ip4_address, &v4address, &address_length))
2851 else if (unformat (i, "%U/%d",
2852 unformat_ip6_address, &v6address, &address_length))
2858 if (sw_if_index_set == 0)
2860 errmsg ("missing interface name or sw_if_index");
2863 if (v4_address_set && v6_address_set)
2865 errmsg ("both v4 and v6 addresses set");
2868 if (!v4_address_set && !v6_address_set && !del_all)
2870 errmsg ("no addresses set");
2874 /* Construct the API message */
2875 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
2877 mp->sw_if_index = ntohl (sw_if_index);
2878 mp->is_add = is_add;
2879 mp->del_all = del_all;
2882 mp->prefix.address.af = ADDRESS_IP6;
2883 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
2887 mp->prefix.address.af = ADDRESS_IP4;
2888 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
2890 mp->prefix.len = address_length;
2895 /* Wait for a reply, return good/bad news */
2901 api_sw_interface_set_mpls_enable (vat_main_t * vam)
2903 unformat_input_t *i = vam->input;
2904 vl_api_sw_interface_set_mpls_enable_t *mp;
2906 u8 sw_if_index_set = 0;
2910 /* Parse args required to build the message */
2911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2913 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2914 sw_if_index_set = 1;
2915 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2916 sw_if_index_set = 1;
2917 else if (unformat (i, "disable"))
2919 else if (unformat (i, "dis"))
2925 if (sw_if_index_set == 0)
2927 errmsg ("missing interface name or sw_if_index");
2931 /* Construct the API message */
2932 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
2934 mp->sw_if_index = ntohl (sw_if_index);
2935 mp->enable = enable;
2940 /* Wait for a reply... */
2946 api_sw_interface_set_table (vat_main_t * vam)
2948 unformat_input_t *i = vam->input;
2949 vl_api_sw_interface_set_table_t *mp;
2950 u32 sw_if_index, vrf_id = 0;
2951 u8 sw_if_index_set = 0;
2955 /* Parse args required to build the message */
2956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2958 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2959 sw_if_index_set = 1;
2960 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2961 sw_if_index_set = 1;
2962 else if (unformat (i, "vrf %d", &vrf_id))
2964 else if (unformat (i, "ipv6"))
2970 if (sw_if_index_set == 0)
2972 errmsg ("missing interface name or sw_if_index");
2976 /* Construct the API message */
2977 M (SW_INTERFACE_SET_TABLE, mp);
2979 mp->sw_if_index = ntohl (sw_if_index);
2980 mp->is_ipv6 = is_ipv6;
2981 mp->vrf_id = ntohl (vrf_id);
2986 /* Wait for a reply... */
2991 static void vl_api_sw_interface_get_table_reply_t_handler
2992 (vl_api_sw_interface_get_table_reply_t * mp)
2994 vat_main_t *vam = &vat_main;
2996 print (vam->ofp, "%d", ntohl (mp->vrf_id));
2998 vam->retval = ntohl (mp->retval);
2999 vam->result_ready = 1;
3003 static void vl_api_sw_interface_get_table_reply_t_handler_json
3004 (vl_api_sw_interface_get_table_reply_t * mp)
3006 vat_main_t *vam = &vat_main;
3007 vat_json_node_t node;
3009 vat_json_init_object (&node);
3010 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3011 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3013 vat_json_print (vam->ofp, &node);
3014 vat_json_free (&node);
3016 vam->retval = ntohl (mp->retval);
3017 vam->result_ready = 1;
3021 api_sw_interface_get_table (vat_main_t * vam)
3023 unformat_input_t *i = vam->input;
3024 vl_api_sw_interface_get_table_t *mp;
3026 u8 sw_if_index_set = 0;
3030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3032 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3033 sw_if_index_set = 1;
3034 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3035 sw_if_index_set = 1;
3036 else if (unformat (i, "ipv6"))
3042 if (sw_if_index_set == 0)
3044 errmsg ("missing interface name or sw_if_index");
3048 M (SW_INTERFACE_GET_TABLE, mp);
3049 mp->sw_if_index = htonl (sw_if_index);
3050 mp->is_ipv6 = is_ipv6;
3058 api_sw_interface_set_vpath (vat_main_t * vam)
3060 unformat_input_t *i = vam->input;
3061 vl_api_sw_interface_set_vpath_t *mp;
3062 u32 sw_if_index = 0;
3063 u8 sw_if_index_set = 0;
3067 /* Parse args required to build the message */
3068 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3070 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3071 sw_if_index_set = 1;
3072 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3073 sw_if_index_set = 1;
3074 else if (unformat (i, "enable"))
3076 else if (unformat (i, "disable"))
3082 if (sw_if_index_set == 0)
3084 errmsg ("missing interface name or sw_if_index");
3088 /* Construct the API message */
3089 M (SW_INTERFACE_SET_VPATH, mp);
3091 mp->sw_if_index = ntohl (sw_if_index);
3092 mp->enable = is_enable;
3097 /* Wait for a reply... */
3103 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3105 unformat_input_t *i = vam->input;
3106 vl_api_sw_interface_set_l2_xconnect_t *mp;
3108 u8 rx_sw_if_index_set = 0;
3110 u8 tx_sw_if_index_set = 0;
3114 /* Parse args required to build the message */
3115 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3117 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3118 rx_sw_if_index_set = 1;
3119 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3120 tx_sw_if_index_set = 1;
3121 else if (unformat (i, "rx"))
3123 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3125 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3127 rx_sw_if_index_set = 1;
3132 else if (unformat (i, "tx"))
3134 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3136 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3138 tx_sw_if_index_set = 1;
3143 else if (unformat (i, "enable"))
3145 else if (unformat (i, "disable"))
3151 if (rx_sw_if_index_set == 0)
3153 errmsg ("missing rx interface name or rx_sw_if_index");
3157 if (enable && (tx_sw_if_index_set == 0))
3159 errmsg ("missing tx interface name or tx_sw_if_index");
3163 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
3165 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3166 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
3167 mp->enable = enable;
3175 api_sw_interface_set_l2_bridge (vat_main_t * vam)
3177 unformat_input_t *i = vam->input;
3178 vl_api_sw_interface_set_l2_bridge_t *mp;
3179 vl_api_l2_port_type_t port_type;
3181 u8 rx_sw_if_index_set = 0;
3188 port_type = L2_API_PORT_TYPE_NORMAL;
3190 /* Parse args required to build the message */
3191 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3193 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3194 rx_sw_if_index_set = 1;
3195 else if (unformat (i, "bd_id %d", &bd_id))
3199 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
3200 rx_sw_if_index_set = 1;
3201 else if (unformat (i, "shg %d", &shg))
3203 else if (unformat (i, "bvi"))
3204 port_type = L2_API_PORT_TYPE_BVI;
3205 else if (unformat (i, "uu-fwd"))
3206 port_type = L2_API_PORT_TYPE_UU_FWD;
3207 else if (unformat (i, "enable"))
3209 else if (unformat (i, "disable"))
3215 if (rx_sw_if_index_set == 0)
3217 errmsg ("missing rx interface name or sw_if_index");
3221 if (enable && (bd_id_set == 0))
3223 errmsg ("missing bridge domain");
3227 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
3229 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3230 mp->bd_id = ntohl (bd_id);
3232 mp->port_type = ntohl (port_type);
3233 mp->enable = enable;
3241 api_bridge_domain_dump (vat_main_t * vam)
3243 unformat_input_t *i = vam->input;
3244 vl_api_bridge_domain_dump_t *mp;
3245 vl_api_control_ping_t *mp_ping;
3249 /* Parse args required to build the message */
3250 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3252 if (unformat (i, "bd_id %d", &bd_id))
3258 M (BRIDGE_DOMAIN_DUMP, mp);
3259 mp->bd_id = ntohl (bd_id);
3262 /* Use a control ping for synchronization */
3263 MPING (CONTROL_PING, mp_ping);
3271 api_bridge_domain_add_del (vat_main_t * vam)
3273 unformat_input_t *i = vam->input;
3274 vl_api_bridge_domain_add_del_t *mp;
3277 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3282 /* Parse args required to build the message */
3283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3285 if (unformat (i, "bd_id %d", &bd_id))
3287 else if (unformat (i, "flood %d", &flood))
3289 else if (unformat (i, "uu-flood %d", &uu_flood))
3291 else if (unformat (i, "forward %d", &forward))
3293 else if (unformat (i, "learn %d", &learn))
3295 else if (unformat (i, "arp-term %d", &arp_term))
3297 else if (unformat (i, "mac-age %d", &mac_age))
3299 else if (unformat (i, "bd-tag %s", &bd_tag))
3301 else if (unformat (i, "del"))
3304 flood = uu_flood = forward = learn = 0;
3312 errmsg ("missing bridge domain");
3319 errmsg ("mac age must be less than 256 ");
3324 if ((bd_tag) && (vec_len (bd_tag) > 63))
3326 errmsg ("bd-tag cannot be longer than 63");
3331 M (BRIDGE_DOMAIN_ADD_DEL, mp);
3333 mp->bd_id = ntohl (bd_id);
3335 mp->uu_flood = uu_flood;
3336 mp->forward = forward;
3338 mp->arp_term = arp_term;
3339 mp->is_add = is_add;
3340 mp->mac_age = (u8) mac_age;
3343 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
3344 mp->bd_tag[vec_len (bd_tag)] = 0;
3355 api_l2fib_flush_bd (vat_main_t * vam)
3357 unformat_input_t *i = vam->input;
3358 vl_api_l2fib_flush_bd_t *mp;
3362 /* Parse args required to build the message */
3363 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3365 if (unformat (i, "bd_id %d", &bd_id));
3372 errmsg ("missing bridge domain");
3376 M (L2FIB_FLUSH_BD, mp);
3378 mp->bd_id = htonl (bd_id);
3386 api_l2fib_flush_int (vat_main_t * vam)
3388 unformat_input_t *i = vam->input;
3389 vl_api_l2fib_flush_int_t *mp;
3390 u32 sw_if_index = ~0;
3393 /* Parse args required to build the message */
3394 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3396 if (unformat (i, "sw_if_index %d", &sw_if_index));
3398 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
3403 if (sw_if_index == ~0)
3405 errmsg ("missing interface name or sw_if_index");
3409 M (L2FIB_FLUSH_INT, mp);
3411 mp->sw_if_index = ntohl (sw_if_index);
3419 api_l2fib_add_del (vat_main_t * vam)
3421 unformat_input_t *i = vam->input;
3422 vl_api_l2fib_add_del_t *mp;
3428 u32 sw_if_index = 0;
3429 u8 sw_if_index_set = 0;
3438 /* Parse args required to build the message */
3439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3441 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
3443 else if (unformat (i, "bd_id %d", &bd_id))
3445 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3446 sw_if_index_set = 1;
3447 else if (unformat (i, "sw_if"))
3449 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3452 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3453 sw_if_index_set = 1;
3458 else if (unformat (i, "static"))
3460 else if (unformat (i, "filter"))
3465 else if (unformat (i, "bvi"))
3470 else if (unformat (i, "del"))
3472 else if (unformat (i, "count %d", &count))
3480 errmsg ("missing mac address");
3486 errmsg ("missing bridge domain");
3490 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
3492 errmsg ("missing interface name or sw_if_index");
3498 /* Turn on async mode */
3499 vam->async_mode = 1;
3500 vam->async_errors = 0;
3501 before = vat_time_now (vam);
3504 for (j = 0; j < count; j++)
3506 M (L2FIB_ADD_DEL, mp);
3508 clib_memcpy (mp->mac, mac, 6);
3509 mp->bd_id = ntohl (bd_id);
3510 mp->is_add = is_add;
3511 mp->sw_if_index = ntohl (sw_if_index);
3515 mp->static_mac = static_mac;
3516 mp->filter_mac = filter_mac;
3517 mp->bvi_mac = bvi_mac;
3519 increment_mac_address (mac);
3526 vl_api_control_ping_t *mp_ping;
3529 /* Shut off async mode */
3530 vam->async_mode = 0;
3532 MPING (CONTROL_PING, mp_ping);
3535 timeout = vat_time_now (vam) + 1.0;
3536 while (vat_time_now (vam) < timeout)
3537 if (vam->result_ready == 1)
3542 if (vam->retval == -99)
3545 if (vam->async_errors > 0)
3547 errmsg ("%d asynchronous errors", vam->async_errors);
3550 vam->async_errors = 0;
3551 after = vat_time_now (vam);
3553 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
3554 count, after - before, count / (after - before));
3560 /* Wait for a reply... */
3564 /* Return the good/bad news */
3565 return (vam->retval);
3569 api_bridge_domain_set_mac_age (vat_main_t * vam)
3571 unformat_input_t *i = vam->input;
3572 vl_api_bridge_domain_set_mac_age_t *mp;
3577 /* Parse args required to build the message */
3578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3580 if (unformat (i, "bd_id %d", &bd_id));
3581 else if (unformat (i, "mac-age %d", &mac_age));
3588 errmsg ("missing bridge domain");
3594 errmsg ("mac age must be less than 256 ");
3598 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
3600 mp->bd_id = htonl (bd_id);
3601 mp->mac_age = (u8) mac_age;
3609 api_l2_flags (vat_main_t * vam)
3611 unformat_input_t *i = vam->input;
3612 vl_api_l2_flags_t *mp;
3615 u8 sw_if_index_set = 0;
3619 /* Parse args required to build the message */
3620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3622 if (unformat (i, "sw_if_index %d", &sw_if_index))
3623 sw_if_index_set = 1;
3624 else if (unformat (i, "sw_if"))
3626 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3629 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3630 sw_if_index_set = 1;
3635 else if (unformat (i, "learn"))
3637 else if (unformat (i, "forward"))
3639 else if (unformat (i, "flood"))
3641 else if (unformat (i, "uu-flood"))
3642 flags |= L2_UU_FLOOD;
3643 else if (unformat (i, "arp-term"))
3644 flags |= L2_ARP_TERM;
3645 else if (unformat (i, "off"))
3647 else if (unformat (i, "disable"))
3653 if (sw_if_index_set == 0)
3655 errmsg ("missing interface name or sw_if_index");
3661 mp->sw_if_index = ntohl (sw_if_index);
3662 mp->feature_bitmap = ntohl (flags);
3663 mp->is_set = is_set;
3671 api_bridge_flags (vat_main_t * vam)
3673 unformat_input_t *i = vam->input;
3674 vl_api_bridge_flags_t *mp;
3678 bd_flags_t flags = 0;
3681 /* Parse args required to build the message */
3682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3684 if (unformat (i, "bd_id %d", &bd_id))
3686 else if (unformat (i, "learn"))
3687 flags |= BRIDGE_API_FLAG_LEARN;
3688 else if (unformat (i, "forward"))
3689 flags |= BRIDGE_API_FLAG_FWD;
3690 else if (unformat (i, "flood"))
3691 flags |= BRIDGE_API_FLAG_FLOOD;
3692 else if (unformat (i, "uu-flood"))
3693 flags |= BRIDGE_API_FLAG_UU_FLOOD;
3694 else if (unformat (i, "arp-term"))
3695 flags |= BRIDGE_API_FLAG_ARP_TERM;
3696 else if (unformat (i, "off"))
3698 else if (unformat (i, "disable"))
3706 errmsg ("missing bridge domain");
3710 M (BRIDGE_FLAGS, mp);
3712 mp->bd_id = ntohl (bd_id);
3713 mp->flags = ntohl (flags);
3714 mp->is_set = is_set;
3722 api_bd_ip_mac_add_del (vat_main_t * vam)
3724 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
3725 vl_api_mac_address_t mac = { 0 };
3726 unformat_input_t *i = vam->input;
3727 vl_api_bd_ip_mac_add_del_t *mp;
3736 /* Parse args required to build the message */
3737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3739 if (unformat (i, "bd_id %d", &bd_id))
3743 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
3747 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
3751 else if (unformat (i, "del"))
3759 errmsg ("missing bridge domain");
3762 else if (ip_set == 0)
3764 errmsg ("missing IP address");
3767 else if (mac_set == 0)
3769 errmsg ("missing MAC address");
3773 M (BD_IP_MAC_ADD_DEL, mp);
3775 mp->entry.bd_id = ntohl (bd_id);
3776 mp->is_add = is_add;
3778 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
3779 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
3787 api_bd_ip_mac_flush (vat_main_t * vam)
3789 unformat_input_t *i = vam->input;
3790 vl_api_bd_ip_mac_flush_t *mp;
3795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3797 if (unformat (i, "bd_id %d", &bd_id))
3807 errmsg ("missing bridge domain");
3811 M (BD_IP_MAC_FLUSH, mp);
3813 mp->bd_id = ntohl (bd_id);
3820 static void vl_api_bd_ip_mac_details_t_handler
3821 (vl_api_bd_ip_mac_details_t * mp)
3823 vat_main_t *vam = &vat_main;
3827 ntohl (mp->entry.bd_id),
3828 format_vl_api_mac_address, mp->entry.mac,
3829 format_vl_api_address, &mp->entry.ip);
3832 static void vl_api_bd_ip_mac_details_t_handler_json
3833 (vl_api_bd_ip_mac_details_t * mp)
3835 vat_main_t *vam = &vat_main;
3836 vat_json_node_t *node = NULL;
3838 if (VAT_JSON_ARRAY != vam->json_tree.type)
3840 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3841 vat_json_init_array (&vam->json_tree);
3843 node = vat_json_array_add (&vam->json_tree);
3845 vat_json_init_object (node);
3846 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
3847 vat_json_object_add_string_copy (node, "mac_address",
3848 format (0, "%U", format_vl_api_mac_address,
3852 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
3853 vat_json_object_add_string_copy (node, "ip_address", ip);
3858 api_bd_ip_mac_dump (vat_main_t * vam)
3860 unformat_input_t *i = vam->input;
3861 vl_api_bd_ip_mac_dump_t *mp;
3862 vl_api_control_ping_t *mp_ping;
3867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3869 if (unformat (i, "bd_id %d", &bd_id))
3878 "\n%-5s %-7s %-20s %-30s",
3879 "bd_id", "is_ipv6", "mac_address", "ip_address");
3881 /* Dump Bridge Domain Ip to Mac entries */
3882 M (BD_IP_MAC_DUMP, mp);
3885 mp->bd_id = htonl (bd_id);
3891 /* Use a control ping for synchronization */
3892 MPING (CONTROL_PING, mp_ping);
3900 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
3902 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
3905 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
3908 addr->domain = x[0];
3911 addr->function = x[3];
3917 api_virtio_pci_create_v2 (vat_main_t * vam)
3919 unformat_input_t *i = vam->input;
3920 vl_api_virtio_pci_create_v2_t *mp;
3924 u64 features = (u64) ~ (0ULL);
3925 u32 virtio_flags = 0;
3928 clib_memset (mac_address, 0, sizeof (mac_address));
3930 /* Parse args required to build the message */
3931 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3933 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
3937 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
3939 else if (unformat (i, "features 0x%llx", &features))
3941 else if (unformat (i, "gso-enabled"))
3942 virtio_flags |= VIRTIO_API_FLAG_GSO;
3943 else if (unformat (i, "csum-offload-enabled"))
3944 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
3945 else if (unformat (i, "gro-coalesce"))
3946 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
3947 else if (unformat (i, "packed"))
3948 virtio_flags |= VIRTIO_API_FLAG_PACKED;
3949 else if (unformat (i, "in-order"))
3950 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
3951 else if (unformat (i, "buffering"))
3952 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
3959 errmsg ("pci address must be non zero. ");
3963 /* Construct the API message */
3964 M (VIRTIO_PCI_CREATE_V2, mp);
3966 mp->use_random_mac = random_mac;
3968 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
3969 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
3970 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
3971 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
3973 mp->features = clib_host_to_net_u64 (features);
3974 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
3976 if (random_mac == 0)
3977 clib_memcpy (mp->mac_address, mac_address, 6);
3982 /* Wait for a reply... */
3988 api_virtio_pci_delete (vat_main_t * vam)
3990 unformat_input_t *i = vam->input;
3991 vl_api_virtio_pci_delete_t *mp;
3992 u32 sw_if_index = ~0;
3993 u8 sw_if_index_set = 0;
3996 /* Parse args required to build the message */
3997 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3999 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4000 sw_if_index_set = 1;
4001 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4002 sw_if_index_set = 1;
4007 if (sw_if_index_set == 0)
4009 errmsg ("missing vpp interface name. ");
4013 /* Construct the API message */
4014 M (VIRTIO_PCI_DELETE, mp);
4016 mp->sw_if_index = htonl (sw_if_index);
4021 /* Wait for a reply... */
4027 api_ip_table_add_del (vat_main_t * vam)
4029 unformat_input_t *i = vam->input;
4030 vl_api_ip_table_add_del_t *mp;
4036 /* Parse args required to build the message */
4037 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4039 if (unformat (i, "ipv6"))
4041 else if (unformat (i, "del"))
4043 else if (unformat (i, "add"))
4045 else if (unformat (i, "table %d", &table_id))
4049 clib_warning ("parse error '%U'", format_unformat_error, i);
4056 errmsg ("missing table-ID");
4060 /* Construct the API message */
4061 M (IP_TABLE_ADD_DEL, mp);
4063 mp->table.table_id = ntohl (table_id);
4064 mp->table.is_ip6 = is_ipv6;
4065 mp->is_add = is_add;
4070 /* Wait for a reply... */
4077 unformat_fib_path (unformat_input_t * input, va_list * args)
4079 vat_main_t *vam = va_arg (*args, vat_main_t *);
4080 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
4081 u32 weight, preference;
4082 mpls_label_t out_label;
4084 clib_memset (path, 0, sizeof (*path));
4086 path->sw_if_index = ~0;
4090 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4092 if (unformat (input, "%U %U",
4093 unformat_vl_api_ip4_address,
4094 &path->nh.address.ip4,
4095 api_unformat_sw_if_index, vam, &path->sw_if_index))
4097 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4099 else if (unformat (input, "%U %U",
4100 unformat_vl_api_ip6_address,
4101 &path->nh.address.ip6,
4102 api_unformat_sw_if_index, vam, &path->sw_if_index))
4104 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4106 else if (unformat (input, "weight %u", &weight))
4108 path->weight = weight;
4110 else if (unformat (input, "preference %u", &preference))
4112 path->preference = preference;
4114 else if (unformat (input, "%U next-hop-table %d",
4115 unformat_vl_api_ip4_address,
4116 &path->nh.address.ip4, &path->table_id))
4118 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4120 else if (unformat (input, "%U next-hop-table %d",
4121 unformat_vl_api_ip6_address,
4122 &path->nh.address.ip6, &path->table_id))
4124 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4126 else if (unformat (input, "%U",
4127 unformat_vl_api_ip4_address, &path->nh.address.ip4))
4130 * the recursive next-hops are by default in the default table
4133 path->sw_if_index = ~0;
4134 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4136 else if (unformat (input, "%U",
4137 unformat_vl_api_ip6_address, &path->nh.address.ip6))
4140 * the recursive next-hops are by default in the default table
4143 path->sw_if_index = ~0;
4144 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4146 else if (unformat (input, "resolve-via-host"))
4148 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
4150 else if (unformat (input, "resolve-via-attached"))
4152 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
4154 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
4156 path->type = FIB_API_PATH_TYPE_LOCAL;
4157 path->sw_if_index = ~0;
4158 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4160 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
4162 path->type = FIB_API_PATH_TYPE_LOCAL;
4163 path->sw_if_index = ~0;
4164 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4166 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
4168 else if (unformat (input, "via-label %d", &path->nh.via_label))
4170 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
4171 path->sw_if_index = ~0;
4173 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
4175 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
4176 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
4178 else if (unformat (input, "local"))
4180 path->type = FIB_API_PATH_TYPE_LOCAL;
4182 else if (unformat (input, "out-labels"))
4184 while (unformat (input, "%d", &out_label))
4186 path->label_stack[path->n_labels].label = out_label;
4187 path->label_stack[path->n_labels].is_uniform = 0;
4188 path->label_stack[path->n_labels].ttl = 64;
4192 else if (unformat (input, "via"))
4194 /* new path, back up and return */
4195 unformat_put_input (input);
4196 unformat_put_input (input);
4197 unformat_put_input (input);
4198 unformat_put_input (input);
4207 path->proto = ntohl (path->proto);
4208 path->type = ntohl (path->type);
4209 path->flags = ntohl (path->flags);
4210 path->table_id = ntohl (path->table_id);
4211 path->sw_if_index = ntohl (path->sw_if_index);
4217 api_ip_route_add_del (vat_main_t * vam)
4219 unformat_input_t *i = vam->input;
4220 vl_api_ip_route_add_del_t *mp;
4223 u8 is_multipath = 0;
4226 vl_api_prefix_t pfx = { };
4227 vl_api_fib_path_t paths[8];
4231 u32 random_add_del = 0;
4232 u32 *random_vector = 0;
4233 u32 random_seed = 0xdeaddabe;
4235 /* Parse args required to build the message */
4236 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4238 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
4240 else if (unformat (i, "del"))
4242 else if (unformat (i, "add"))
4244 else if (unformat (i, "vrf %d", &vrf_id))
4246 else if (unformat (i, "count %d", &count))
4248 else if (unformat (i, "random"))
4250 else if (unformat (i, "multipath"))
4252 else if (unformat (i, "seed %d", &random_seed))
4256 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4259 if (8 == path_count)
4261 errmsg ("max 8 paths");
4267 clib_warning ("parse error '%U'", format_unformat_error, i);
4274 errmsg ("specify a path; via ...");
4277 if (prefix_set == 0)
4279 errmsg ("missing prefix");
4283 /* Generate a pile of unique, random routes */
4286 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
4287 u32 this_random_address;
4290 random_hash = hash_create (count, sizeof (uword));
4292 hash_set (random_hash, i->as_u32, 1);
4293 for (j = 0; j <= count; j++)
4297 this_random_address = random_u32 (&random_seed);
4298 this_random_address =
4299 clib_host_to_net_u32 (this_random_address);
4301 while (hash_get (random_hash, this_random_address));
4302 vec_add1 (random_vector, this_random_address);
4303 hash_set (random_hash, this_random_address, 1);
4305 hash_free (random_hash);
4306 set_ip4_address (&pfx.address, random_vector[0]);
4311 /* Turn on async mode */
4312 vam->async_mode = 1;
4313 vam->async_errors = 0;
4314 before = vat_time_now (vam);
4317 for (j = 0; j < count; j++)
4319 /* Construct the API message */
4320 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4322 mp->is_add = is_add;
4323 mp->is_multipath = is_multipath;
4325 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
4326 mp->route.table_id = ntohl (vrf_id);
4327 mp->route.n_paths = path_count;
4329 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
4332 set_ip4_address (&pfx.address, random_vector[j + 1]);
4334 increment_address (&pfx.address);
4337 /* If we receive SIGTERM, stop now... */
4342 /* When testing multiple add/del ops, use a control-ping to sync */
4345 vl_api_control_ping_t *mp_ping;
4349 /* Shut off async mode */
4350 vam->async_mode = 0;
4352 MPING (CONTROL_PING, mp_ping);
4355 timeout = vat_time_now (vam) + 1.0;
4356 while (vat_time_now (vam) < timeout)
4357 if (vam->result_ready == 1)
4362 if (vam->retval == -99)
4365 if (vam->async_errors > 0)
4367 errmsg ("%d asynchronous errors", vam->async_errors);
4370 vam->async_errors = 0;
4371 after = vat_time_now (vam);
4373 /* slim chance, but we might have eaten SIGTERM on the first iteration */
4377 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4378 count, after - before, count / (after - before));
4384 /* Wait for a reply... */
4389 /* Return the good/bad news */
4390 return (vam->retval);
4394 api_ip_mroute_add_del (vat_main_t * vam)
4396 unformat_input_t *i = vam->input;
4397 u8 path_set = 0, prefix_set = 0, is_add = 1;
4398 vl_api_ip_mroute_add_del_t *mp;
4399 mfib_entry_flags_t eflags = 0;
4400 vl_api_mfib_path_t path;
4401 vl_api_mprefix_t pfx = { };
4405 /* Parse args required to build the message */
4406 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4408 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
4411 pfx.grp_address_length = htons (pfx.grp_address_length);
4413 else if (unformat (i, "del"))
4415 else if (unformat (i, "add"))
4417 else if (unformat (i, "vrf %d", &vrf_id))
4419 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
4420 path.itf_flags = htonl (path.itf_flags);
4421 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
4423 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
4427 clib_warning ("parse error '%U'", format_unformat_error, i);
4432 if (prefix_set == 0)
4434 errmsg ("missing addresses\n");
4439 errmsg ("missing path\n");
4443 /* Construct the API message */
4444 M (IP_MROUTE_ADD_DEL, mp);
4446 mp->is_add = is_add;
4447 mp->is_multipath = 1;
4449 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
4450 mp->route.table_id = htonl (vrf_id);
4451 mp->route.n_paths = 1;
4452 mp->route.entry_flags = htonl (eflags);
4454 clib_memcpy (&mp->route.paths, &path, sizeof (path));
4458 /* Wait for a reply... */
4464 api_mpls_table_add_del (vat_main_t * vam)
4466 unformat_input_t *i = vam->input;
4467 vl_api_mpls_table_add_del_t *mp;
4472 /* Parse args required to build the message */
4473 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4475 if (unformat (i, "table %d", &table_id))
4477 else if (unformat (i, "del"))
4479 else if (unformat (i, "add"))
4483 clib_warning ("parse error '%U'", format_unformat_error, i);
4490 errmsg ("missing table-ID");
4494 /* Construct the API message */
4495 M (MPLS_TABLE_ADD_DEL, mp);
4497 mp->mt_table.mt_table_id = ntohl (table_id);
4498 mp->mt_is_add = is_add;
4503 /* Wait for a reply... */
4510 api_mpls_route_add_del (vat_main_t * vam)
4512 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
4513 mpls_label_t local_label = MPLS_LABEL_INVALID;
4514 unformat_input_t *i = vam->input;
4515 vl_api_mpls_route_add_del_t *mp;
4516 vl_api_fib_path_t paths[8];
4520 /* Parse args required to build the message */
4521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4523 if (unformat (i, "%d", &local_label))
4525 else if (unformat (i, "eos"))
4527 else if (unformat (i, "non-eos"))
4529 else if (unformat (i, "del"))
4531 else if (unformat (i, "add"))
4533 else if (unformat (i, "multipath"))
4535 else if (unformat (i, "count %d", &count))
4539 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4542 if (8 == path_count)
4544 errmsg ("max 8 paths");
4550 clib_warning ("parse error '%U'", format_unformat_error, i);
4557 errmsg ("specify a path; via ...");
4561 if (MPLS_LABEL_INVALID == local_label)
4563 errmsg ("missing label");
4569 /* Turn on async mode */
4570 vam->async_mode = 1;
4571 vam->async_errors = 0;
4572 before = vat_time_now (vam);
4575 for (j = 0; j < count; j++)
4577 /* Construct the API message */
4578 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4580 mp->mr_is_add = is_add;
4581 mp->mr_is_multipath = is_multipath;
4583 mp->mr_route.mr_label = local_label;
4584 mp->mr_route.mr_eos = is_eos;
4585 mp->mr_route.mr_table_id = 0;
4586 mp->mr_route.mr_n_paths = path_count;
4588 clib_memcpy (&mp->mr_route.mr_paths, paths,
4589 sizeof (paths[0]) * path_count);
4595 /* If we receive SIGTERM, stop now... */
4600 /* When testing multiple add/del ops, use a control-ping to sync */
4603 vl_api_control_ping_t *mp_ping;
4607 /* Shut off async mode */
4608 vam->async_mode = 0;
4610 MPING (CONTROL_PING, mp_ping);
4613 timeout = vat_time_now (vam) + 1.0;
4614 while (vat_time_now (vam) < timeout)
4615 if (vam->result_ready == 1)
4620 if (vam->retval == -99)
4623 if (vam->async_errors > 0)
4625 errmsg ("%d asynchronous errors", vam->async_errors);
4628 vam->async_errors = 0;
4629 after = vat_time_now (vam);
4631 /* slim chance, but we might have eaten SIGTERM on the first iteration */
4635 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4636 count, after - before, count / (after - before));
4642 /* Wait for a reply... */
4647 /* Return the good/bad news */
4648 return (vam->retval);
4653 api_mpls_ip_bind_unbind (vat_main_t * vam)
4655 unformat_input_t *i = vam->input;
4656 vl_api_mpls_ip_bind_unbind_t *mp;
4657 u32 ip_table_id = 0;
4659 vl_api_prefix_t pfx;
4661 mpls_label_t local_label = MPLS_LABEL_INVALID;
4664 /* Parse args required to build the message */
4665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4667 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
4669 else if (unformat (i, "%d", &local_label))
4671 else if (unformat (i, "table-id %d", &ip_table_id))
4673 else if (unformat (i, "unbind"))
4675 else if (unformat (i, "bind"))
4679 clib_warning ("parse error '%U'", format_unformat_error, i);
4686 errmsg ("IP prefix not set");
4690 if (MPLS_LABEL_INVALID == local_label)
4692 errmsg ("missing label");
4696 /* Construct the API message */
4697 M (MPLS_IP_BIND_UNBIND, mp);
4699 mp->mb_is_bind = is_bind;
4700 mp->mb_ip_table_id = ntohl (ip_table_id);
4701 mp->mb_mpls_table_id = 0;
4702 mp->mb_label = ntohl (local_label);
4703 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
4708 /* Wait for a reply... */
4715 api_mpls_tunnel_add_del (vat_main_t * vam)
4717 unformat_input_t *i = vam->input;
4718 vl_api_mpls_tunnel_add_del_t *mp;
4720 vl_api_fib_path_t paths[8];
4721 u32 sw_if_index = ~0;
4727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4729 if (unformat (i, "add"))
4733 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
4735 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
4737 else if (unformat (i, "l2-only"))
4741 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4744 if (8 == path_count)
4746 errmsg ("max 8 paths");
4752 clib_warning ("parse error '%U'", format_unformat_error, i);
4757 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4759 mp->mt_is_add = is_add;
4760 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
4761 mp->mt_tunnel.mt_l2_only = l2_only;
4762 mp->mt_tunnel.mt_is_multicast = 0;
4763 mp->mt_tunnel.mt_n_paths = path_count;
4765 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
4766 sizeof (paths[0]) * path_count);
4774 api_sw_interface_set_unnumbered (vat_main_t * vam)
4776 unformat_input_t *i = vam->input;
4777 vl_api_sw_interface_set_unnumbered_t *mp;
4779 u32 unnum_sw_index = ~0;
4781 u8 sw_if_index_set = 0;
4784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4786 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4787 sw_if_index_set = 1;
4788 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4789 sw_if_index_set = 1;
4790 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4792 else if (unformat (i, "del"))
4796 clib_warning ("parse error '%U'", format_unformat_error, i);
4801 if (sw_if_index_set == 0)
4803 errmsg ("missing interface name or sw_if_index");
4807 M (SW_INTERFACE_SET_UNNUMBERED, mp);
4809 mp->sw_if_index = ntohl (sw_if_index);
4810 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
4811 mp->is_add = is_add;
4820 api_create_vlan_subif (vat_main_t * vam)
4822 unformat_input_t *i = vam->input;
4823 vl_api_create_vlan_subif_t *mp;
4825 u8 sw_if_index_set = 0;
4830 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4832 if (unformat (i, "sw_if_index %d", &sw_if_index))
4833 sw_if_index_set = 1;
4835 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4836 sw_if_index_set = 1;
4837 else if (unformat (i, "vlan %d", &vlan_id))
4841 clib_warning ("parse error '%U'", format_unformat_error, i);
4846 if (sw_if_index_set == 0)
4848 errmsg ("missing interface name or sw_if_index");
4852 if (vlan_id_set == 0)
4854 errmsg ("missing vlan_id");
4857 M (CREATE_VLAN_SUBIF, mp);
4859 mp->sw_if_index = ntohl (sw_if_index);
4860 mp->vlan_id = ntohl (vlan_id);
4867 #define foreach_create_subif_bit \
4874 _(outer_vlan_id_any) \
4875 _(inner_vlan_id_any)
4877 #define foreach_create_subif_flag \
4882 _(4, "exact_match") \
4883 _(5, "default_sub") \
4884 _(6, "outer_vlan_id_any") \
4885 _(7, "inner_vlan_id_any")
4888 api_create_subif (vat_main_t * vam)
4890 unformat_input_t *i = vam->input;
4891 vl_api_create_subif_t *mp;
4893 u8 sw_if_index_set = 0;
4896 u32 __attribute__ ((unused)) no_tags = 0;
4897 u32 __attribute__ ((unused)) one_tag = 0;
4898 u32 __attribute__ ((unused)) two_tags = 0;
4899 u32 __attribute__ ((unused)) dot1ad = 0;
4900 u32 __attribute__ ((unused)) exact_match = 0;
4901 u32 __attribute__ ((unused)) default_sub = 0;
4902 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
4903 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
4905 u16 outer_vlan_id = 0;
4906 u16 inner_vlan_id = 0;
4909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4911 if (unformat (i, "sw_if_index %d", &sw_if_index))
4912 sw_if_index_set = 1;
4914 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4915 sw_if_index_set = 1;
4916 else if (unformat (i, "sub_id %d", &sub_id))
4918 else if (unformat (i, "outer_vlan_id %d", &tmp))
4919 outer_vlan_id = tmp;
4920 else if (unformat (i, "inner_vlan_id %d", &tmp))
4921 inner_vlan_id = tmp;
4923 #define _(a) else if (unformat (i, #a)) a = 1 ;
4924 foreach_create_subif_bit
4928 clib_warning ("parse error '%U'", format_unformat_error, i);
4933 if (sw_if_index_set == 0)
4935 errmsg ("missing interface name or sw_if_index");
4939 if (sub_id_set == 0)
4941 errmsg ("missing sub_id");
4944 M (CREATE_SUBIF, mp);
4946 mp->sw_if_index = ntohl (sw_if_index);
4947 mp->sub_id = ntohl (sub_id);
4949 #define _(a,b) mp->sub_if_flags |= (1 << a);
4950 foreach_create_subif_flag;
4953 mp->outer_vlan_id = ntohs (outer_vlan_id);
4954 mp->inner_vlan_id = ntohs (inner_vlan_id);
4962 api_ip_table_replace_begin (vat_main_t * vam)
4964 unformat_input_t *i = vam->input;
4965 vl_api_ip_table_replace_begin_t *mp;
4970 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4972 if (unformat (i, "table %d", &table_id))
4974 else if (unformat (i, "ipv6"))
4978 clib_warning ("parse error '%U'", format_unformat_error, i);
4983 M (IP_TABLE_REPLACE_BEGIN, mp);
4985 mp->table.table_id = ntohl (table_id);
4986 mp->table.is_ip6 = is_ipv6;
4994 api_ip_table_flush (vat_main_t * vam)
4996 unformat_input_t *i = vam->input;
4997 vl_api_ip_table_flush_t *mp;
5002 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5004 if (unformat (i, "table %d", &table_id))
5006 else if (unformat (i, "ipv6"))
5010 clib_warning ("parse error '%U'", format_unformat_error, i);
5015 M (IP_TABLE_FLUSH, mp);
5017 mp->table.table_id = ntohl (table_id);
5018 mp->table.is_ip6 = is_ipv6;
5026 api_ip_table_replace_end (vat_main_t * vam)
5028 unformat_input_t *i = vam->input;
5029 vl_api_ip_table_replace_end_t *mp;
5034 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5036 if (unformat (i, "table %d", &table_id))
5038 else if (unformat (i, "ipv6"))
5042 clib_warning ("parse error '%U'", format_unformat_error, i);
5047 M (IP_TABLE_REPLACE_END, mp);
5049 mp->table.table_id = ntohl (table_id);
5050 mp->table.is_ip6 = is_ipv6;
5058 api_set_ip_flow_hash (vat_main_t * vam)
5060 unformat_input_t *i = vam->input;
5061 vl_api_set_ip_flow_hash_t *mp;
5073 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5075 if (unformat (i, "vrf %d", &vrf_id))
5077 else if (unformat (i, "ipv6"))
5079 else if (unformat (i, "src"))
5081 else if (unformat (i, "dst"))
5083 else if (unformat (i, "sport"))
5085 else if (unformat (i, "dport"))
5087 else if (unformat (i, "proto"))
5089 else if (unformat (i, "reverse"))
5094 clib_warning ("parse error '%U'", format_unformat_error, i);
5099 if (vrf_id_set == 0)
5101 errmsg ("missing vrf id");
5105 M (SET_IP_FLOW_HASH, mp);
5111 mp->reverse = reverse;
5112 mp->vrf_id = ntohl (vrf_id);
5113 mp->is_ipv6 = is_ipv6;
5121 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5123 unformat_input_t *i = vam->input;
5124 vl_api_sw_interface_ip6_enable_disable_t *mp;
5126 u8 sw_if_index_set = 0;
5130 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5132 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5133 sw_if_index_set = 1;
5134 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5135 sw_if_index_set = 1;
5136 else if (unformat (i, "enable"))
5138 else if (unformat (i, "disable"))
5142 clib_warning ("parse error '%U'", format_unformat_error, i);
5147 if (sw_if_index_set == 0)
5149 errmsg ("missing interface name or sw_if_index");
5153 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
5155 mp->sw_if_index = ntohl (sw_if_index);
5156 mp->enable = enable;
5165 api_l2_patch_add_del (vat_main_t * vam)
5167 unformat_input_t *i = vam->input;
5168 vl_api_l2_patch_add_del_t *mp;
5170 u8 rx_sw_if_index_set = 0;
5172 u8 tx_sw_if_index_set = 0;
5176 /* Parse args required to build the message */
5177 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5179 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5180 rx_sw_if_index_set = 1;
5181 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5182 tx_sw_if_index_set = 1;
5183 else if (unformat (i, "rx"))
5185 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5187 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
5189 rx_sw_if_index_set = 1;
5194 else if (unformat (i, "tx"))
5196 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5198 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
5200 tx_sw_if_index_set = 1;
5205 else if (unformat (i, "del"))
5211 if (rx_sw_if_index_set == 0)
5213 errmsg ("missing rx interface name or rx_sw_if_index");
5217 if (tx_sw_if_index_set == 0)
5219 errmsg ("missing tx interface name or tx_sw_if_index");
5223 M (L2_PATCH_ADD_DEL, mp);
5225 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5226 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5227 mp->is_add = is_add;
5235 u8 localsid_addr[16];
5244 api_ioam_enable (vat_main_t * vam)
5246 unformat_input_t *input = vam->input;
5247 vl_api_ioam_enable_t *mp;
5249 int has_trace_option = 0;
5250 int has_pot_option = 0;
5251 int has_seqno_option = 0;
5252 int has_analyse_option = 0;
5255 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5257 if (unformat (input, "trace"))
5258 has_trace_option = 1;
5259 else if (unformat (input, "pot"))
5261 else if (unformat (input, "seqno"))
5262 has_seqno_option = 1;
5263 else if (unformat (input, "analyse"))
5264 has_analyse_option = 1;
5268 M (IOAM_ENABLE, mp);
5269 mp->id = htons (id);
5270 mp->seqno = has_seqno_option;
5271 mp->analyse = has_analyse_option;
5272 mp->pot_enable = has_pot_option;
5273 mp->trace_enable = has_trace_option;
5282 api_ioam_disable (vat_main_t * vam)
5284 vl_api_ioam_disable_t *mp;
5287 M (IOAM_DISABLE, mp);
5293 #define foreach_tcp_proto_field \
5297 #define foreach_udp_proto_field \
5301 #define foreach_ip4_proto_field \
5313 u16 src_port, dst_port;
5316 #if VPP_API_TEST_BUILTIN == 0
5318 unformat_tcp_mask (unformat_input_t * input, va_list * args)
5320 u8 **maskp = va_arg (*args, u8 **);
5322 u8 found_something = 0;
5325 #define _(a) u8 a=0;
5326 foreach_tcp_proto_field;
5329 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5332 #define _(a) else if (unformat (input, #a)) a=1;
5333 foreach_tcp_proto_field
5339 #define _(a) found_something += a;
5340 foreach_tcp_proto_field;
5343 if (found_something == 0)
5346 vec_validate (mask, sizeof (*tcp) - 1);
5348 tcp = (tcp_header_t *) mask;
5350 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
5351 foreach_tcp_proto_field;
5359 unformat_udp_mask (unformat_input_t * input, va_list * args)
5361 u8 **maskp = va_arg (*args, u8 **);
5363 u8 found_something = 0;
5366 #define _(a) u8 a=0;
5367 foreach_udp_proto_field;
5370 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5373 #define _(a) else if (unformat (input, #a)) a=1;
5374 foreach_udp_proto_field
5380 #define _(a) found_something += a;
5381 foreach_udp_proto_field;
5384 if (found_something == 0)
5387 vec_validate (mask, sizeof (*udp) - 1);
5389 udp = (udp_header_t *) mask;
5391 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
5392 foreach_udp_proto_field;
5400 unformat_l4_mask (unformat_input_t * input, va_list * args)
5402 u8 **maskp = va_arg (*args, u8 **);
5403 u16 src_port = 0, dst_port = 0;
5404 tcpudp_header_t *tcpudp;
5406 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5408 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
5410 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
5412 else if (unformat (input, "src_port"))
5414 else if (unformat (input, "dst_port"))
5420 if (!src_port && !dst_port)
5424 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
5426 tcpudp = (tcpudp_header_t *) mask;
5427 tcpudp->src_port = src_port;
5428 tcpudp->dst_port = dst_port;
5436 unformat_ip4_mask (unformat_input_t * input, va_list * args)
5438 u8 **maskp = va_arg (*args, u8 **);
5440 u8 found_something = 0;
5443 #define _(a) u8 a=0;
5444 foreach_ip4_proto_field;
5450 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5452 if (unformat (input, "version"))
5454 else if (unformat (input, "hdr_length"))
5456 else if (unformat (input, "src"))
5458 else if (unformat (input, "dst"))
5460 else if (unformat (input, "proto"))
5463 #define _(a) else if (unformat (input, #a)) a=1;
5464 foreach_ip4_proto_field
5470 #define _(a) found_something += a;
5471 foreach_ip4_proto_field;
5474 if (found_something == 0)
5477 vec_validate (mask, sizeof (*ip) - 1);
5479 ip = (ip4_header_t *) mask;
5481 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
5482 foreach_ip4_proto_field;
5485 ip->ip_version_and_header_length = 0;
5488 ip->ip_version_and_header_length |= 0xF0;
5491 ip->ip_version_and_header_length |= 0x0F;
5497 #define foreach_ip6_proto_field \
5505 unformat_ip6_mask (unformat_input_t * input, va_list * args)
5507 u8 **maskp = va_arg (*args, u8 **);
5509 u8 found_something = 0;
5511 u32 ip_version_traffic_class_and_flow_label;
5513 #define _(a) u8 a=0;
5514 foreach_ip6_proto_field;
5517 u8 traffic_class = 0;
5520 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5522 if (unformat (input, "version"))
5524 else if (unformat (input, "traffic-class"))
5526 else if (unformat (input, "flow-label"))
5528 else if (unformat (input, "src"))
5530 else if (unformat (input, "dst"))
5532 else if (unformat (input, "proto"))
5535 #define _(a) else if (unformat (input, #a)) a=1;
5536 foreach_ip6_proto_field
5542 #define _(a) found_something += a;
5543 foreach_ip6_proto_field;
5546 if (found_something == 0)
5549 vec_validate (mask, sizeof (*ip) - 1);
5551 ip = (ip6_header_t *) mask;
5553 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
5554 foreach_ip6_proto_field;
5557 ip_version_traffic_class_and_flow_label = 0;
5560 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5563 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5566 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5568 ip->ip_version_traffic_class_and_flow_label =
5569 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5576 unformat_l3_mask (unformat_input_t * input, va_list * args)
5578 u8 **maskp = va_arg (*args, u8 **);
5580 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5582 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5584 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5593 unformat_l2_mask (unformat_input_t * input, va_list * args)
5595 u8 **maskp = va_arg (*args, u8 **);
5610 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5612 if (unformat (input, "src"))
5614 else if (unformat (input, "dst"))
5616 else if (unformat (input, "proto"))
5618 else if (unformat (input, "tag1"))
5620 else if (unformat (input, "tag2"))
5622 else if (unformat (input, "ignore-tag1"))
5624 else if (unformat (input, "ignore-tag2"))
5626 else if (unformat (input, "cos1"))
5628 else if (unformat (input, "cos2"))
5630 else if (unformat (input, "dot1q"))
5632 else if (unformat (input, "dot1ad"))
5637 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5638 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5641 if (tag1 || ignore_tag1 || cos1 || dot1q)
5643 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5646 vec_validate (mask, len - 1);
5649 clib_memset (mask, 0xff, 6);
5652 clib_memset (mask + 6, 0xff, 6);
5656 /* inner vlan tag */
5665 mask[21] = mask[20] = 0xff;
5686 mask[16] = mask[17] = 0xff;
5696 mask[12] = mask[13] = 0xff;
5703 unformat_classify_mask (unformat_input_t * input, va_list * args)
5705 u8 **maskp = va_arg (*args, u8 **);
5706 u32 *skipp = va_arg (*args, u32 *);
5707 u32 *matchp = va_arg (*args, u32 *);
5715 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5717 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5719 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5721 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5723 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
5737 if (mask || l2 || l3 || l4)
5741 /* "With a free Ethernet header in every package" */
5743 vec_validate (l2, 13);
5747 vec_append (mask, l3);
5752 vec_append (mask, l4);
5757 /* Scan forward looking for the first significant mask octet */
5758 for (i = 0; i < vec_len (mask); i++)
5762 /* compute (skip, match) params */
5763 *skipp = i / sizeof (u32x4);
5764 vec_delete (mask, *skipp * sizeof (u32x4), 0);
5766 /* Pad mask to an even multiple of the vector size */
5767 while (vec_len (mask) % sizeof (u32x4))
5770 match = vec_len (mask) / sizeof (u32x4);
5772 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
5774 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
5775 if (*tmp || *(tmp + 1))
5780 clib_warning ("BUG: match 0");
5782 _vec_len (mask) = match * sizeof (u32x4);
5792 #endif /* VPP_API_TEST_BUILTIN */
5794 #define foreach_l2_next \
5796 _(ethernet, ETHERNET_INPUT) \
5801 unformat_l2_next_index (unformat_input_t * input, va_list * args)
5803 u32 *miss_next_indexp = va_arg (*args, u32 *);
5808 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
5812 if (unformat (input, "%d", &tmp))
5821 *miss_next_indexp = next_index;
5825 #define foreach_ip_next \
5831 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
5833 u32 *miss_next_indexp = va_arg (*args, u32 *);
5838 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5842 if (unformat (input, "%d", &tmp))
5851 *miss_next_indexp = next_index;
5855 #define foreach_acl_next \
5859 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
5861 u32 *miss_next_indexp = va_arg (*args, u32 *);
5866 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5870 if (unformat (input, "permit"))
5875 else if (unformat (input, "%d", &tmp))
5884 *miss_next_indexp = next_index;
5889 unformat_policer_precolor (unformat_input_t * input, va_list * args)
5891 u32 *r = va_arg (*args, u32 *);
5893 if (unformat (input, "conform-color"))
5894 *r = POLICE_CONFORM;
5895 else if (unformat (input, "exceed-color"))
5903 #if VPP_API_TEST_BUILTIN == 0
5905 unformat_l4_match (unformat_input_t * input, va_list * args)
5907 u8 **matchp = va_arg (*args, u8 **);
5909 u8 *proto_header = 0;
5915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5917 if (unformat (input, "src_port %d", &src_port))
5919 else if (unformat (input, "dst_port %d", &dst_port))
5925 h.src_port = clib_host_to_net_u16 (src_port);
5926 h.dst_port = clib_host_to_net_u16 (dst_port);
5927 vec_validate (proto_header, sizeof (h) - 1);
5928 memcpy (proto_header, &h, sizeof (h));
5930 *matchp = proto_header;
5936 unformat_ip4_match (unformat_input_t * input, va_list * args)
5938 u8 **matchp = va_arg (*args, u8 **);
5945 int src = 0, dst = 0;
5946 ip4_address_t src_val, dst_val;
5953 int fragment_id = 0;
5954 u32 fragment_id_val;
5960 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5962 if (unformat (input, "version %d", &version_val))
5964 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5966 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5968 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5970 else if (unformat (input, "proto %d", &proto_val))
5972 else if (unformat (input, "tos %d", &tos_val))
5974 else if (unformat (input, "length %d", &length_val))
5976 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5978 else if (unformat (input, "ttl %d", &ttl_val))
5980 else if (unformat (input, "checksum %d", &checksum_val))
5986 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5987 + ttl + checksum == 0)
5991 * Aligned because we use the real comparison functions
5993 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
5995 ip = (ip4_header_t *) match;
5997 /* These are realistically matched in practice */
5999 ip->src_address.as_u32 = src_val.as_u32;
6002 ip->dst_address.as_u32 = dst_val.as_u32;
6005 ip->protocol = proto_val;
6008 /* These are not, but they're included for completeness */
6010 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
6013 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6019 ip->length = clib_host_to_net_u16 (length_val);
6025 ip->checksum = clib_host_to_net_u16 (checksum_val);
6032 unformat_ip6_match (unformat_input_t * input, va_list * args)
6034 u8 **matchp = va_arg (*args, u8 **);
6039 u8 traffic_class = 0;
6040 u32 traffic_class_val = 0;
6043 int src = 0, dst = 0;
6044 ip6_address_t src_val, dst_val;
6047 int payload_length = 0;
6048 u32 payload_length_val;
6051 u32 ip_version_traffic_class_and_flow_label;
6053 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6055 if (unformat (input, "version %d", &version_val))
6057 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6059 else if (unformat (input, "flow_label %d", &flow_label_val))
6061 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6063 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6065 else if (unformat (input, "proto %d", &proto_val))
6067 else if (unformat (input, "payload_length %d", &payload_length_val))
6069 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6075 if (version + traffic_class + flow_label + src + dst + proto +
6076 payload_length + hop_limit == 0)
6080 * Aligned because we use the real comparison functions
6082 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
6084 ip = (ip6_header_t *) match;
6087 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6090 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6093 ip->protocol = proto_val;
6095 ip_version_traffic_class_and_flow_label = 0;
6098 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6101 ip_version_traffic_class_and_flow_label |=
6102 (traffic_class_val & 0xFF) << 20;
6105 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6107 ip->ip_version_traffic_class_and_flow_label =
6108 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6111 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6114 ip->hop_limit = hop_limit_val;
6121 unformat_l3_match (unformat_input_t * input, va_list * args)
6123 u8 **matchp = va_arg (*args, u8 **);
6125 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6127 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6129 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6138 unformat_vlan_tag (unformat_input_t * input, va_list * args)
6140 u8 *tagp = va_arg (*args, u8 *);
6143 if (unformat (input, "%d", &tag))
6145 tagp[0] = (tag >> 8) & 0x0F;
6146 tagp[1] = tag & 0xFF;
6154 unformat_l2_match (unformat_input_t * input, va_list * args)
6156 u8 **matchp = va_arg (*args, u8 **);
6176 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6178 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6181 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6183 else if (unformat (input, "proto %U",
6184 unformat_ethernet_type_host_byte_order, &proto_val))
6186 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6188 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6190 else if (unformat (input, "ignore-tag1"))
6192 else if (unformat (input, "ignore-tag2"))
6194 else if (unformat (input, "cos1 %d", &cos1_val))
6196 else if (unformat (input, "cos2 %d", &cos2_val))
6201 if ((src + dst + proto + tag1 + tag2 +
6202 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6205 if (tag1 || ignore_tag1 || cos1)
6207 if (tag2 || ignore_tag2 || cos2)
6210 vec_validate_aligned (match, len - 1, sizeof (u32x4));
6213 clib_memcpy (match, dst_val, 6);
6216 clib_memcpy (match + 6, src_val, 6);
6220 /* inner vlan tag */
6221 match[19] = tag2_val[1];
6222 match[18] = tag2_val[0];
6224 match[18] |= (cos2_val & 0x7) << 5;
6227 match[21] = proto_val & 0xff;
6228 match[20] = proto_val >> 8;
6232 match[15] = tag1_val[1];
6233 match[14] = tag1_val[0];
6236 match[14] |= (cos1_val & 0x7) << 5;
6242 match[15] = tag1_val[1];
6243 match[14] = tag1_val[0];
6246 match[17] = proto_val & 0xff;
6247 match[16] = proto_val >> 8;
6250 match[14] |= (cos1_val & 0x7) << 5;
6256 match[18] |= (cos2_val & 0x7) << 5;
6258 match[14] |= (cos1_val & 0x7) << 5;
6261 match[13] = proto_val & 0xff;
6262 match[12] = proto_val >> 8;
6270 unformat_qos_source (unformat_input_t * input, va_list * args)
6272 int *qs = va_arg (*args, int *);
6274 if (unformat (input, "ip"))
6275 *qs = QOS_SOURCE_IP;
6276 else if (unformat (input, "mpls"))
6277 *qs = QOS_SOURCE_MPLS;
6278 else if (unformat (input, "ext"))
6279 *qs = QOS_SOURCE_EXT;
6280 else if (unformat (input, "vlan"))
6281 *qs = QOS_SOURCE_VLAN;
6290 api_unformat_classify_match (unformat_input_t * input, va_list * args)
6292 u8 **matchp = va_arg (*args, u8 **);
6293 u32 skip_n_vectors = va_arg (*args, u32);
6294 u32 match_n_vectors = va_arg (*args, u32);
6301 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6303 if (unformat (input, "hex %U", unformat_hex_string, &match))
6305 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6307 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6309 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
6323 if (match || l2 || l3 || l4)
6327 /* "Win a free Ethernet header in every packet" */
6329 vec_validate_aligned (l2, 13, sizeof (u32x4));
6333 vec_append_aligned (match, l3, sizeof (u32x4));
6338 vec_append_aligned (match, l4, sizeof (u32x4));
6343 /* Make sure the vector is big enough even if key is all 0's */
6344 vec_validate_aligned
6345 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
6348 /* Set size, include skipped vectors */
6349 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
6360 api_get_node_index (vat_main_t * vam)
6362 unformat_input_t *i = vam->input;
6363 vl_api_get_node_index_t *mp;
6367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6369 if (unformat (i, "node %s", &name))
6376 errmsg ("node name required");
6379 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
6381 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6385 M (GET_NODE_INDEX, mp);
6386 clib_memcpy (mp->node_name, name, vec_len (name));
6395 api_get_next_index (vat_main_t * vam)
6397 unformat_input_t *i = vam->input;
6398 vl_api_get_next_index_t *mp;
6399 u8 *node_name = 0, *next_node_name = 0;
6402 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6404 if (unformat (i, "node-name %s", &node_name))
6406 else if (unformat (i, "next-node-name %s", &next_node_name))
6412 errmsg ("node name required");
6415 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
6417 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6421 if (next_node_name == 0)
6423 errmsg ("next node name required");
6426 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
6428 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
6432 M (GET_NEXT_INDEX, mp);
6433 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
6434 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
6435 vec_free (node_name);
6436 vec_free (next_node_name);
6444 api_add_node_next (vat_main_t * vam)
6446 unformat_input_t *i = vam->input;
6447 vl_api_add_node_next_t *mp;
6452 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6454 if (unformat (i, "node %s", &name))
6456 else if (unformat (i, "next %s", &next))
6463 errmsg ("node name required");
6466 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
6468 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6473 errmsg ("next node required");
6476 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
6478 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
6482 M (ADD_NODE_NEXT, mp);
6483 clib_memcpy (mp->node_name, name, vec_len (name));
6484 clib_memcpy (mp->next_name, next, vec_len (next));
6493 static void vl_api_sw_interface_virtio_pci_details_t_handler
6494 (vl_api_sw_interface_virtio_pci_details_t * mp)
6496 vat_main_t *vam = &vat_main;
6511 addr.domain = ntohs (mp->pci_addr.domain);
6512 addr.bus = mp->pci_addr.bus;
6513 addr.slot = mp->pci_addr.slot;
6514 addr.function = mp->pci_addr.function;
6516 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
6517 addr.slot, addr.function);
6520 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
6521 pci_addr, ntohl (mp->sw_if_index),
6522 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
6523 format_ethernet_address, mp->mac_addr,
6524 clib_net_to_host_u64 (mp->features));
6525 vec_free (pci_addr);
6528 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
6529 (vl_api_sw_interface_virtio_pci_details_t * mp)
6531 vat_main_t *vam = &vat_main;
6532 vat_json_node_t *node = NULL;
6533 vlib_pci_addr_t pci_addr;
6535 if (VAT_JSON_ARRAY != vam->json_tree.type)
6537 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6538 vat_json_init_array (&vam->json_tree);
6540 node = vat_json_array_add (&vam->json_tree);
6542 pci_addr.domain = ntohs (mp->pci_addr.domain);
6543 pci_addr.bus = mp->pci_addr.bus;
6544 pci_addr.slot = mp->pci_addr.slot;
6545 pci_addr.function = mp->pci_addr.function;
6547 vat_json_init_object (node);
6548 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
6549 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6550 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
6551 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
6552 vat_json_object_add_uint (node, "features",
6553 clib_net_to_host_u64 (mp->features));
6554 vat_json_object_add_string_copy (node, "mac_addr",
6555 format (0, "%U", format_ethernet_address,
6560 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
6562 vl_api_sw_interface_virtio_pci_dump_t *mp;
6563 vl_api_control_ping_t *mp_ping;
6567 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
6568 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
6569 "mac_addr", "features");
6571 /* Get list of tap interfaces */
6572 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
6575 /* Use a control ping for synchronization */
6576 MPING (CONTROL_PING, mp_ping);
6584 api_l2_fib_clear_table (vat_main_t * vam)
6586 // unformat_input_t * i = vam->input;
6587 vl_api_l2_fib_clear_table_t *mp;
6590 M (L2_FIB_CLEAR_TABLE, mp);
6598 api_l2_interface_efp_filter (vat_main_t * vam)
6600 unformat_input_t *i = vam->input;
6601 vl_api_l2_interface_efp_filter_t *mp;
6604 u8 sw_if_index_set = 0;
6607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6609 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6610 sw_if_index_set = 1;
6611 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6612 sw_if_index_set = 1;
6613 else if (unformat (i, "enable"))
6615 else if (unformat (i, "disable"))
6619 clib_warning ("parse error '%U'", format_unformat_error, i);
6624 if (sw_if_index_set == 0)
6626 errmsg ("missing sw_if_index");
6630 M (L2_INTERFACE_EFP_FILTER, mp);
6632 mp->sw_if_index = ntohl (sw_if_index);
6633 mp->enable_disable = enable;
6640 #define foreach_vtr_op \
6641 _("disable", L2_VTR_DISABLED) \
6642 _("push-1", L2_VTR_PUSH_1) \
6643 _("push-2", L2_VTR_PUSH_2) \
6644 _("pop-1", L2_VTR_POP_1) \
6645 _("pop-2", L2_VTR_POP_2) \
6646 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6647 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6648 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6649 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6652 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6654 unformat_input_t *i = vam->input;
6655 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6657 u8 sw_if_index_set = 0;
6665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6667 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6668 sw_if_index_set = 1;
6669 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6670 sw_if_index_set = 1;
6671 else if (unformat (i, "vtr_op %d", &vtr_op))
6673 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6676 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6678 else if (unformat (i, "tag1 %d", &tag1))
6680 else if (unformat (i, "tag2 %d", &tag2))
6684 clib_warning ("parse error '%U'", format_unformat_error, i);
6689 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
6691 errmsg ("missing vtr operation or sw_if_index");
6695 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
6696 mp->sw_if_index = ntohl (sw_if_index);
6697 mp->vtr_op = ntohl (vtr_op);
6698 mp->push_dot1q = ntohl (push_dot1q);
6699 mp->tag1 = ntohl (tag1);
6700 mp->tag2 = ntohl (tag2);
6708 api_create_vhost_user_if (vat_main_t * vam)
6710 unformat_input_t *i = vam->input;
6711 vl_api_create_vhost_user_if_t *mp;
6714 u8 file_name_set = 0;
6715 u32 custom_dev_instance = ~0;
6717 u8 use_custom_mac = 0;
6718 u8 disable_mrg_rxbuf = 0;
6719 u8 disable_indirect_desc = 0;
6722 u8 enable_packed = 0;
6725 /* Shut up coverity */
6726 clib_memset (hwaddr, 0, sizeof (hwaddr));
6728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6730 if (unformat (i, "socket %s", &file_name))
6734 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6736 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6738 else if (unformat (i, "server"))
6740 else if (unformat (i, "disable_mrg_rxbuf"))
6741 disable_mrg_rxbuf = 1;
6742 else if (unformat (i, "disable_indirect_desc"))
6743 disable_indirect_desc = 1;
6744 else if (unformat (i, "gso"))
6746 else if (unformat (i, "packed"))
6748 else if (unformat (i, "tag %s", &tag))
6754 if (file_name_set == 0)
6756 errmsg ("missing socket file name");
6760 if (vec_len (file_name) > 255)
6762 errmsg ("socket file name too long");
6765 vec_add1 (file_name, 0);
6767 M (CREATE_VHOST_USER_IF, mp);
6769 mp->is_server = is_server;
6770 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
6771 mp->disable_indirect_desc = disable_indirect_desc;
6772 mp->enable_gso = enable_gso;
6773 mp->enable_packed = enable_packed;
6774 mp->custom_dev_instance = ntohl (custom_dev_instance);
6775 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6776 vec_free (file_name);
6777 if (custom_dev_instance != ~0)
6780 mp->use_custom_mac = use_custom_mac;
6781 clib_memcpy (mp->mac_address, hwaddr, 6);
6783 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
6792 api_modify_vhost_user_if (vat_main_t * vam)
6794 unformat_input_t *i = vam->input;
6795 vl_api_modify_vhost_user_if_t *mp;
6798 u8 file_name_set = 0;
6799 u32 custom_dev_instance = ~0;
6800 u8 sw_if_index_set = 0;
6801 u32 sw_if_index = (u32) ~ 0;
6803 u8 enable_packed = 0;
6806 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6808 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6809 sw_if_index_set = 1;
6810 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6811 sw_if_index_set = 1;
6812 else if (unformat (i, "socket %s", &file_name))
6816 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6818 else if (unformat (i, "server"))
6820 else if (unformat (i, "gso"))
6822 else if (unformat (i, "packed"))
6828 if (sw_if_index_set == 0)
6830 errmsg ("missing sw_if_index or interface name");
6834 if (file_name_set == 0)
6836 errmsg ("missing socket file name");
6840 if (vec_len (file_name) > 255)
6842 errmsg ("socket file name too long");
6845 vec_add1 (file_name, 0);
6847 M (MODIFY_VHOST_USER_IF, mp);
6849 mp->sw_if_index = ntohl (sw_if_index);
6850 mp->is_server = is_server;
6851 mp->enable_gso = enable_gso;
6852 mp->enable_packed = enable_packed;
6853 mp->custom_dev_instance = ntohl (custom_dev_instance);
6854 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6855 vec_free (file_name);
6856 if (custom_dev_instance != ~0)
6865 api_create_vhost_user_if_v2 (vat_main_t * vam)
6867 unformat_input_t *i = vam->input;
6868 vl_api_create_vhost_user_if_v2_t *mp;
6871 u8 file_name_set = 0;
6872 u32 custom_dev_instance = ~0;
6874 u8 use_custom_mac = 0;
6875 u8 disable_mrg_rxbuf = 0;
6876 u8 disable_indirect_desc = 0;
6879 u8 enable_packed = 0;
6880 u8 enable_event_idx = 0;
6883 /* Shut up coverity */
6884 clib_memset (hwaddr, 0, sizeof (hwaddr));
6886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6888 if (unformat (i, "socket %s", &file_name))
6892 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6894 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6896 else if (unformat (i, "server"))
6898 else if (unformat (i, "disable_mrg_rxbuf"))
6899 disable_mrg_rxbuf = 1;
6900 else if (unformat (i, "disable_indirect_desc"))
6901 disable_indirect_desc = 1;
6902 else if (unformat (i, "gso"))
6904 else if (unformat (i, "packed"))
6906 else if (unformat (i, "event-idx"))
6907 enable_event_idx = 1;
6908 else if (unformat (i, "tag %s", &tag))
6914 if (file_name_set == 0)
6916 errmsg ("missing socket file name");
6920 if (vec_len (file_name) > 255)
6922 errmsg ("socket file name too long");
6925 vec_add1 (file_name, 0);
6927 M (CREATE_VHOST_USER_IF_V2, mp);
6929 mp->is_server = is_server;
6930 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
6931 mp->disable_indirect_desc = disable_indirect_desc;
6932 mp->enable_gso = enable_gso;
6933 mp->enable_packed = enable_packed;
6934 mp->enable_event_idx = enable_event_idx;
6935 mp->custom_dev_instance = ntohl (custom_dev_instance);
6936 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6937 vec_free (file_name);
6938 if (custom_dev_instance != ~0)
6941 mp->use_custom_mac = use_custom_mac;
6942 clib_memcpy (mp->mac_address, hwaddr, 6);
6944 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
6953 api_modify_vhost_user_if_v2 (vat_main_t * vam)
6955 unformat_input_t *i = vam->input;
6956 vl_api_modify_vhost_user_if_v2_t *mp;
6959 u8 file_name_set = 0;
6960 u32 custom_dev_instance = ~0;
6961 u8 sw_if_index_set = 0;
6962 u32 sw_if_index = (u32) ~ 0;
6964 u8 enable_packed = 0;
6965 u8 enable_event_idx = 0;
6968 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6970 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6971 sw_if_index_set = 1;
6972 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6973 sw_if_index_set = 1;
6974 else if (unformat (i, "socket %s", &file_name))
6978 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6980 else if (unformat (i, "server"))
6982 else if (unformat (i, "gso"))
6984 else if (unformat (i, "packed"))
6986 else if (unformat (i, "event-idx"))
6987 enable_event_idx = 1;
6992 if (sw_if_index_set == 0)
6994 errmsg ("missing sw_if_index or interface name");
6998 if (file_name_set == 0)
7000 errmsg ("missing socket file name");
7004 if (vec_len (file_name) > 255)
7006 errmsg ("socket file name too long");
7009 vec_add1 (file_name, 0);
7011 M (MODIFY_VHOST_USER_IF_V2, mp);
7013 mp->sw_if_index = ntohl (sw_if_index);
7014 mp->is_server = is_server;
7015 mp->enable_gso = enable_gso;
7016 mp->enable_packed = enable_packed;
7017 mp->enable_event_idx = enable_event_idx;
7018 mp->custom_dev_instance = ntohl (custom_dev_instance);
7019 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
7020 vec_free (file_name);
7021 if (custom_dev_instance != ~0)
7030 api_delete_vhost_user_if (vat_main_t * vam)
7032 unformat_input_t *i = vam->input;
7033 vl_api_delete_vhost_user_if_t *mp;
7034 u32 sw_if_index = ~0;
7035 u8 sw_if_index_set = 0;
7038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7040 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7041 sw_if_index_set = 1;
7042 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7043 sw_if_index_set = 1;
7048 if (sw_if_index_set == 0)
7050 errmsg ("missing sw_if_index or interface name");
7055 M (DELETE_VHOST_USER_IF, mp);
7057 mp->sw_if_index = ntohl (sw_if_index);
7064 static void vl_api_sw_interface_vhost_user_details_t_handler
7065 (vl_api_sw_interface_vhost_user_details_t * mp)
7067 vat_main_t *vam = &vat_main;
7071 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
7072 clib_net_to_host_u32
7073 (mp->features_last_32) <<
7076 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
7077 (char *) mp->interface_name, ntohl (mp->sw_if_index),
7078 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
7079 ntohl (mp->num_regions), (char *) mp->sock_filename);
7080 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
7083 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7084 (vl_api_sw_interface_vhost_user_details_t * mp)
7086 vat_main_t *vam = &vat_main;
7087 vat_json_node_t *node = NULL;
7089 if (VAT_JSON_ARRAY != vam->json_tree.type)
7091 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7092 vat_json_init_array (&vam->json_tree);
7094 node = vat_json_array_add (&vam->json_tree);
7096 vat_json_init_object (node);
7097 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7098 vat_json_object_add_string_copy (node, "interface_name",
7099 mp->interface_name);
7100 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
7101 ntohl (mp->virtio_net_hdr_sz));
7102 vat_json_object_add_uint (node, "features_first_32",
7103 clib_net_to_host_u32 (mp->features_first_32));
7104 vat_json_object_add_uint (node, "features_last_32",
7105 clib_net_to_host_u32 (mp->features_last_32));
7106 vat_json_object_add_uint (node, "is_server", mp->is_server);
7107 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
7108 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
7109 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
7113 api_sw_interface_vhost_user_dump (vat_main_t * vam)
7115 unformat_input_t *i = vam->input;
7116 vl_api_sw_interface_vhost_user_dump_t *mp;
7117 vl_api_control_ping_t *mp_ping;
7119 u32 sw_if_index = ~0;
7121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7123 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7125 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7131 print (vam->ofp, "Interface name idx hdr_sz features "
7132 "server regions filename");
7134 /* Get list of vhost-user interfaces */
7135 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
7136 mp->sw_if_index = ntohl (sw_if_index);
7139 /* Use a control ping for synchronization */
7140 MPING (CONTROL_PING, mp_ping);
7148 api_show_version (vat_main_t * vam)
7150 vl_api_show_version_t *mp;
7153 M (SHOW_VERSION, mp);
7160 static void vl_api_l2_fib_table_details_t_handler
7161 (vl_api_l2_fib_table_details_t * mp)
7163 vat_main_t *vam = &vat_main;
7165 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7167 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
7168 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
7172 static void vl_api_l2_fib_table_details_t_handler_json
7173 (vl_api_l2_fib_table_details_t * mp)
7175 vat_main_t *vam = &vat_main;
7176 vat_json_node_t *node = NULL;
7178 if (VAT_JSON_ARRAY != vam->json_tree.type)
7180 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7181 vat_json_init_array (&vam->json_tree);
7183 node = vat_json_array_add (&vam->json_tree);
7185 vat_json_init_object (node);
7186 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
7187 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
7188 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7189 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
7190 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
7191 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
7195 api_l2_fib_table_dump (vat_main_t * vam)
7197 unformat_input_t *i = vam->input;
7198 vl_api_l2_fib_table_dump_t *mp;
7199 vl_api_control_ping_t *mp_ping;
7204 /* Parse args required to build the message */
7205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7207 if (unformat (i, "bd_id %d", &bd_id))
7215 errmsg ("missing bridge domain");
7219 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
7221 /* Get list of l2 fib entries */
7222 M (L2_FIB_TABLE_DUMP, mp);
7224 mp->bd_id = ntohl (bd_id);
7227 /* Use a control ping for synchronization */
7228 MPING (CONTROL_PING, mp_ping);
7237 api_interface_name_renumber (vat_main_t * vam)
7239 unformat_input_t *line_input = vam->input;
7240 vl_api_interface_name_renumber_t *mp;
7241 u32 sw_if_index = ~0;
7242 u32 new_show_dev_instance = ~0;
7245 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
7247 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
7250 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7252 else if (unformat (line_input, "new_show_dev_instance %d",
7253 &new_show_dev_instance))
7259 if (sw_if_index == ~0)
7261 errmsg ("missing interface name or sw_if_index");
7265 if (new_show_dev_instance == ~0)
7267 errmsg ("missing new_show_dev_instance");
7271 M (INTERFACE_NAME_RENUMBER, mp);
7273 mp->sw_if_index = ntohl (sw_if_index);
7274 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7282 api_want_l2_macs_events (vat_main_t * vam)
7284 unformat_input_t *line_input = vam->input;
7285 vl_api_want_l2_macs_events_t *mp;
7286 u8 enable_disable = 1;
7288 u32 max_macs_in_event = 0;
7289 u32 learn_limit = 0;
7292 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
7294 if (unformat (line_input, "learn-limit %d", &learn_limit))
7296 else if (unformat (line_input, "scan-delay %d", &scan_delay))
7298 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
7300 else if (unformat (line_input, "disable"))
7306 M (WANT_L2_MACS_EVENTS, mp);
7307 mp->enable_disable = enable_disable;
7308 mp->pid = htonl (getpid ());
7309 mp->learn_limit = htonl (learn_limit);
7310 mp->scan_delay = (u8) scan_delay;
7311 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
7318 api_ip_address_dump (vat_main_t * vam)
7320 unformat_input_t *i = vam->input;
7321 vl_api_ip_address_dump_t *mp;
7322 vl_api_control_ping_t *mp_ping;
7323 u32 sw_if_index = ~0;
7324 u8 sw_if_index_set = 0;
7329 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7331 if (unformat (i, "sw_if_index %d", &sw_if_index))
7332 sw_if_index_set = 1;
7334 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7335 sw_if_index_set = 1;
7336 else if (unformat (i, "ipv4"))
7338 else if (unformat (i, "ipv6"))
7344 if (ipv4_set && ipv6_set)
7346 errmsg ("ipv4 and ipv6 flags cannot be both set");
7350 if ((!ipv4_set) && (!ipv6_set))
7352 errmsg ("no ipv4 nor ipv6 flag set");
7356 if (sw_if_index_set == 0)
7358 errmsg ("missing interface name or sw_if_index");
7362 vam->current_sw_if_index = sw_if_index;
7363 vam->is_ipv6 = ipv6_set;
7365 M (IP_ADDRESS_DUMP, mp);
7366 mp->sw_if_index = ntohl (sw_if_index);
7367 mp->is_ipv6 = ipv6_set;
7370 /* Use a control ping for synchronization */
7371 MPING (CONTROL_PING, mp_ping);
7379 api_ip_dump (vat_main_t * vam)
7381 vl_api_ip_dump_t *mp;
7382 vl_api_control_ping_t *mp_ping;
7383 unformat_input_t *in = vam->input;
7390 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
7392 if (unformat (in, "ipv4"))
7394 else if (unformat (in, "ipv6"))
7400 if (ipv4_set && ipv6_set)
7402 errmsg ("ipv4 and ipv6 flags cannot be both set");
7406 if ((!ipv4_set) && (!ipv6_set))
7408 errmsg ("no ipv4 nor ipv6 flag set");
7413 vam->is_ipv6 = is_ipv6;
7416 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
7418 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7420 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
7423 mp->is_ipv6 = ipv6_set;
7426 /* Use a control ping for synchronization */
7427 MPING (CONTROL_PING, mp_ping);
7435 api_get_first_msg_id (vat_main_t * vam)
7437 vl_api_get_first_msg_id_t *mp;
7438 unformat_input_t *i = vam->input;
7443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7445 if (unformat (i, "client %s", &name))
7453 errmsg ("missing client name");
7458 if (vec_len (name) > 63)
7460 errmsg ("client name too long");
7464 M (GET_FIRST_MSG_ID, mp);
7465 clib_memcpy (mp->name, name, vec_len (name));
7472 api_get_node_graph (vat_main_t * vam)
7474 vl_api_get_node_graph_t *mp;
7477 M (GET_NODE_GRAPH, mp);
7481 /* Wait for the reply */
7487 api_af_packet_create (vat_main_t * vam)
7489 unformat_input_t *i = vam->input;
7490 vl_api_af_packet_create_t *mp;
7491 u8 *host_if_name = 0;
7493 u8 random_hw_addr = 1;
7496 clib_memset (hw_addr, 0, sizeof (hw_addr));
7498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7500 if (unformat (i, "name %s", &host_if_name))
7501 vec_add1 (host_if_name, 0);
7502 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
7508 if (!vec_len (host_if_name))
7510 errmsg ("host-interface name must be specified");
7514 if (vec_len (host_if_name) > 64)
7516 errmsg ("host-interface name too long");
7520 M (AF_PACKET_CREATE, mp);
7522 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7523 clib_memcpy (mp->hw_addr, hw_addr, 6);
7524 mp->use_random_hw_addr = random_hw_addr;
7525 vec_free (host_if_name);
7533 fprintf (vam->ofp ? vam->ofp : stderr,
7534 " new sw_if_index = %d\n", vam->sw_if_index);
7541 api_af_packet_delete (vat_main_t * vam)
7543 unformat_input_t *i = vam->input;
7544 vl_api_af_packet_delete_t *mp;
7545 u8 *host_if_name = 0;
7548 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7550 if (unformat (i, "name %s", &host_if_name))
7551 vec_add1 (host_if_name, 0);
7556 if (!vec_len (host_if_name))
7558 errmsg ("host-interface name must be specified");
7562 if (vec_len (host_if_name) > 64)
7564 errmsg ("host-interface name too long");
7568 M (AF_PACKET_DELETE, mp);
7570 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7571 vec_free (host_if_name);
7578 static void vl_api_af_packet_details_t_handler
7579 (vl_api_af_packet_details_t * mp)
7581 vat_main_t *vam = &vat_main;
7583 print (vam->ofp, "%-16s %d",
7584 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
7587 static void vl_api_af_packet_details_t_handler_json
7588 (vl_api_af_packet_details_t * mp)
7590 vat_main_t *vam = &vat_main;
7591 vat_json_node_t *node = NULL;
7593 if (VAT_JSON_ARRAY != vam->json_tree.type)
7595 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7596 vat_json_init_array (&vam->json_tree);
7598 node = vat_json_array_add (&vam->json_tree);
7600 vat_json_init_object (node);
7601 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7602 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
7606 api_af_packet_dump (vat_main_t * vam)
7608 vl_api_af_packet_dump_t *mp;
7609 vl_api_control_ping_t *mp_ping;
7612 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
7613 /* Get list of tap interfaces */
7614 M (AF_PACKET_DUMP, mp);
7617 /* Use a control ping for synchronization */
7618 MPING (CONTROL_PING, mp_ping);
7626 format_fib_api_path_nh_proto (u8 * s, va_list * args)
7628 vl_api_fib_path_nh_proto_t proto =
7629 va_arg (*args, vl_api_fib_path_nh_proto_t);
7633 case FIB_API_PATH_NH_PROTO_IP4:
7634 s = format (s, "ip4");
7636 case FIB_API_PATH_NH_PROTO_IP6:
7637 s = format (s, "ip6");
7639 case FIB_API_PATH_NH_PROTO_MPLS:
7640 s = format (s, "mpls");
7642 case FIB_API_PATH_NH_PROTO_BIER:
7643 s = format (s, "bier");
7645 case FIB_API_PATH_NH_PROTO_ETHERNET:
7646 s = format (s, "ethernet");
7654 format_vl_api_ip_address_union (u8 * s, va_list * args)
7656 vl_api_address_family_t af = va_arg (*args, int);
7657 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
7662 s = format (s, "%U", format_ip4_address, u->ip4);
7665 s = format (s, "%U", format_ip6_address, u->ip6);
7672 format_vl_api_fib_path_type (u8 * s, va_list * args)
7674 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
7678 case FIB_API_PATH_TYPE_NORMAL:
7679 s = format (s, "normal");
7681 case FIB_API_PATH_TYPE_LOCAL:
7682 s = format (s, "local");
7684 case FIB_API_PATH_TYPE_DROP:
7685 s = format (s, "drop");
7687 case FIB_API_PATH_TYPE_UDP_ENCAP:
7688 s = format (s, "udp-encap");
7690 case FIB_API_PATH_TYPE_BIER_IMP:
7691 s = format (s, "bier-imp");
7693 case FIB_API_PATH_TYPE_ICMP_UNREACH:
7694 s = format (s, "unreach");
7696 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
7697 s = format (s, "prohibit");
7699 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
7700 s = format (s, "src-lookup");
7702 case FIB_API_PATH_TYPE_DVR:
7703 s = format (s, "dvr");
7705 case FIB_API_PATH_TYPE_INTERFACE_RX:
7706 s = format (s, "interface-rx");
7708 case FIB_API_PATH_TYPE_CLASSIFY:
7709 s = format (s, "classify");
7717 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
7720 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
7721 ntohl (fp->weight), ntohl (fp->sw_if_index),
7722 format_vl_api_fib_path_type, fp->type,
7723 format_fib_api_path_nh_proto, fp->proto,
7724 format_vl_api_ip_address_union, &fp->nh.address);
7728 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
7729 vl_api_fib_path_t * fp)
7732 struct in6_addr ip6;
7734 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
7735 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
7736 vat_json_object_add_uint (node, "type", fp->type);
7737 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
7738 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
7740 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
7741 vat_json_object_add_ip4 (node, "next_hop", ip4);
7743 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
7745 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
7746 vat_json_object_add_ip6 (node, "next_hop", ip6);
7751 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
7753 vat_main_t *vam = &vat_main;
7754 int count = ntohl (mp->mt_tunnel.mt_n_paths);
7755 vl_api_fib_path_t *fp;
7758 print (vam->ofp, "sw_if_index %d via:",
7759 ntohl (mp->mt_tunnel.mt_sw_if_index));
7760 fp = mp->mt_tunnel.mt_paths;
7761 for (i = 0; i < count; i++)
7763 vl_api_fib_path_print (vam, fp);
7767 print (vam->ofp, "");
7770 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
7771 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
7774 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
7776 vat_main_t *vam = &vat_main;
7777 vat_json_node_t *node = NULL;
7778 int count = ntohl (mp->mt_tunnel.mt_n_paths);
7779 vl_api_fib_path_t *fp;
7782 if (VAT_JSON_ARRAY != vam->json_tree.type)
7784 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7785 vat_json_init_array (&vam->json_tree);
7787 node = vat_json_array_add (&vam->json_tree);
7789 vat_json_init_object (node);
7790 vat_json_object_add_uint (node, "sw_if_index",
7791 ntohl (mp->mt_tunnel.mt_sw_if_index));
7793 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
7795 fp = mp->mt_tunnel.mt_paths;
7796 for (i = 0; i < count; i++)
7798 vl_api_mpls_fib_path_json_print (node, fp);
7804 api_mpls_tunnel_dump (vat_main_t * vam)
7806 vl_api_mpls_tunnel_dump_t *mp;
7807 vl_api_control_ping_t *mp_ping;
7810 M (MPLS_TUNNEL_DUMP, mp);
7814 /* Use a control ping for synchronization */
7815 MPING (CONTROL_PING, mp_ping);
7822 #define vl_api_mpls_table_details_t_endian vl_noop_handler
7823 #define vl_api_mpls_table_details_t_print vl_noop_handler
7827 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
7829 vat_main_t *vam = &vat_main;
7831 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
7834 static void vl_api_mpls_table_details_t_handler_json
7835 (vl_api_mpls_table_details_t * mp)
7837 vat_main_t *vam = &vat_main;
7838 vat_json_node_t *node = NULL;
7840 if (VAT_JSON_ARRAY != vam->json_tree.type)
7842 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7843 vat_json_init_array (&vam->json_tree);
7845 node = vat_json_array_add (&vam->json_tree);
7847 vat_json_init_object (node);
7848 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
7852 api_mpls_table_dump (vat_main_t * vam)
7854 vl_api_mpls_table_dump_t *mp;
7855 vl_api_control_ping_t *mp_ping;
7858 M (MPLS_TABLE_DUMP, mp);
7861 /* Use a control ping for synchronization */
7862 MPING (CONTROL_PING, mp_ping);
7869 #define vl_api_mpls_route_details_t_endian vl_noop_handler
7870 #define vl_api_mpls_route_details_t_print vl_noop_handler
7873 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
7875 vat_main_t *vam = &vat_main;
7876 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
7877 vl_api_fib_path_t *fp;
7881 "table-id %d, label %u, ess_bit %u",
7882 ntohl (mp->mr_route.mr_table_id),
7883 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
7884 fp = mp->mr_route.mr_paths;
7885 for (i = 0; i < count; i++)
7887 vl_api_fib_path_print (vam, fp);
7892 static void vl_api_mpls_route_details_t_handler_json
7893 (vl_api_mpls_route_details_t * mp)
7895 vat_main_t *vam = &vat_main;
7896 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
7897 vat_json_node_t *node = NULL;
7898 vl_api_fib_path_t *fp;
7901 if (VAT_JSON_ARRAY != vam->json_tree.type)
7903 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7904 vat_json_init_array (&vam->json_tree);
7906 node = vat_json_array_add (&vam->json_tree);
7908 vat_json_init_object (node);
7909 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
7910 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
7911 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
7912 vat_json_object_add_uint (node, "path_count", count);
7913 fp = mp->mr_route.mr_paths;
7914 for (i = 0; i < count; i++)
7916 vl_api_mpls_fib_path_json_print (node, fp);
7922 api_mpls_route_dump (vat_main_t * vam)
7924 unformat_input_t *input = vam->input;
7925 vl_api_mpls_route_dump_t *mp;
7926 vl_api_control_ping_t *mp_ping;
7930 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7932 if (unformat (input, "table_id %d", &table_id))
7939 errmsg ("missing table id");
7943 M (MPLS_ROUTE_DUMP, mp);
7945 mp->table.mt_table_id = ntohl (table_id);
7948 /* Use a control ping for synchronization */
7949 MPING (CONTROL_PING, mp_ping);
7956 #define vl_api_ip_table_details_t_endian vl_noop_handler
7957 #define vl_api_ip_table_details_t_print vl_noop_handler
7960 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
7962 vat_main_t *vam = &vat_main;
7965 "%s; table-id %d, prefix %U/%d",
7966 mp->table.name, ntohl (mp->table.table_id));
7970 static void vl_api_ip_table_details_t_handler_json
7971 (vl_api_ip_table_details_t * mp)
7973 vat_main_t *vam = &vat_main;
7974 vat_json_node_t *node = NULL;
7976 if (VAT_JSON_ARRAY != vam->json_tree.type)
7978 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7979 vat_json_init_array (&vam->json_tree);
7981 node = vat_json_array_add (&vam->json_tree);
7983 vat_json_init_object (node);
7984 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
7988 api_ip_table_dump (vat_main_t * vam)
7990 vl_api_ip_table_dump_t *mp;
7991 vl_api_control_ping_t *mp_ping;
7994 M (IP_TABLE_DUMP, mp);
7997 /* Use a control ping for synchronization */
7998 MPING (CONTROL_PING, mp_ping);
8006 api_ip_mtable_dump (vat_main_t * vam)
8008 vl_api_ip_mtable_dump_t *mp;
8009 vl_api_control_ping_t *mp_ping;
8012 M (IP_MTABLE_DUMP, mp);
8015 /* Use a control ping for synchronization */
8016 MPING (CONTROL_PING, mp_ping);
8024 api_ip_mroute_dump (vat_main_t * vam)
8026 unformat_input_t *input = vam->input;
8027 vl_api_control_ping_t *mp_ping;
8028 vl_api_ip_mroute_dump_t *mp;
8033 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8035 if (unformat (input, "table_id %d", &table_id))
8037 else if (unformat (input, "ip6"))
8039 else if (unformat (input, "ip4"))
8046 errmsg ("missing table id");
8050 M (IP_MROUTE_DUMP, mp);
8051 mp->table.table_id = table_id;
8052 mp->table.is_ip6 = is_ip6;
8055 /* Use a control ping for synchronization */
8056 MPING (CONTROL_PING, mp_ping);
8063 #define vl_api_ip_route_details_t_endian vl_noop_handler
8064 #define vl_api_ip_route_details_t_print vl_noop_handler
8067 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
8069 vat_main_t *vam = &vat_main;
8070 u8 count = mp->route.n_paths;
8071 vl_api_fib_path_t *fp;
8075 "table-id %d, prefix %U/%d",
8076 ntohl (mp->route.table_id),
8077 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
8078 for (i = 0; i < count; i++)
8080 fp = &mp->route.paths[i];
8082 vl_api_fib_path_print (vam, fp);
8087 static void vl_api_ip_route_details_t_handler_json
8088 (vl_api_ip_route_details_t * mp)
8090 vat_main_t *vam = &vat_main;
8091 u8 count = mp->route.n_paths;
8092 vat_json_node_t *node = NULL;
8094 struct in6_addr ip6;
8095 vl_api_fib_path_t *fp;
8098 if (VAT_JSON_ARRAY != vam->json_tree.type)
8100 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8101 vat_json_init_array (&vam->json_tree);
8103 node = vat_json_array_add (&vam->json_tree);
8105 vat_json_init_object (node);
8106 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
8107 if (ADDRESS_IP6 == mp->route.prefix.address.af)
8109 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
8110 vat_json_object_add_ip6 (node, "prefix", ip6);
8114 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
8115 vat_json_object_add_ip4 (node, "prefix", ip4);
8117 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
8118 vat_json_object_add_uint (node, "path_count", count);
8119 for (i = 0; i < count; i++)
8121 fp = &mp->route.paths[i];
8122 vl_api_mpls_fib_path_json_print (node, fp);
8127 api_ip_route_dump (vat_main_t * vam)
8129 unformat_input_t *input = vam->input;
8130 vl_api_ip_route_dump_t *mp;
8131 vl_api_control_ping_t *mp_ping;
8137 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8139 if (unformat (input, "table_id %d", &table_id))
8141 else if (unformat (input, "ip6"))
8143 else if (unformat (input, "ip4"))
8150 errmsg ("missing table id");
8154 M (IP_ROUTE_DUMP, mp);
8156 mp->table.table_id = table_id;
8157 mp->table.is_ip6 = is_ip6;
8161 /* Use a control ping for synchronization */
8162 MPING (CONTROL_PING, mp_ping);
8170 api_sw_interface_span_enable_disable (vat_main_t * vam)
8172 unformat_input_t *i = vam->input;
8173 vl_api_sw_interface_span_enable_disable_t *mp;
8174 u32 src_sw_if_index = ~0;
8175 u32 dst_sw_if_index = ~0;
8180 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8183 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
8185 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
8189 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
8191 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
8193 else if (unformat (i, "disable"))
8195 else if (unformat (i, "rx"))
8197 else if (unformat (i, "tx"))
8199 else if (unformat (i, "both"))
8201 else if (unformat (i, "l2"))
8207 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
8209 mp->sw_if_index_from = htonl (src_sw_if_index);
8210 mp->sw_if_index_to = htonl (dst_sw_if_index);
8220 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
8223 vat_main_t *vam = &vat_main;
8224 u8 *sw_if_from_name = 0;
8225 u8 *sw_if_to_name = 0;
8226 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
8227 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
8228 char *states[] = { "none", "rx", "tx", "both" };
8232 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
8234 if ((u32) p->value[0] == sw_if_index_from)
8236 sw_if_from_name = (u8 *)(p->key);
8240 if ((u32) p->value[0] == sw_if_index_to)
8242 sw_if_to_name = (u8 *)(p->key);
8243 if (sw_if_from_name)
8248 print (vam->ofp, "%20s => %20s (%s) %s",
8249 sw_if_from_name, sw_if_to_name, states[mp->state],
8250 mp->is_l2 ? "l2" : "device");
8254 vl_api_sw_interface_span_details_t_handler_json
8255 (vl_api_sw_interface_span_details_t * mp)
8257 vat_main_t *vam = &vat_main;
8258 vat_json_node_t *node = NULL;
8259 u8 *sw_if_from_name = 0;
8260 u8 *sw_if_to_name = 0;
8261 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
8262 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
8266 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
8268 if ((u32) p->value[0] == sw_if_index_from)
8270 sw_if_from_name = (u8 *)(p->key);
8274 if ((u32) p->value[0] == sw_if_index_to)
8276 sw_if_to_name = (u8 *)(p->key);
8277 if (sw_if_from_name)
8283 if (VAT_JSON_ARRAY != vam->json_tree.type)
8285 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8286 vat_json_init_array (&vam->json_tree);
8288 node = vat_json_array_add (&vam->json_tree);
8290 vat_json_init_object (node);
8291 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
8292 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
8293 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
8294 if (0 != sw_if_to_name)
8296 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
8298 vat_json_object_add_uint (node, "state", mp->state);
8299 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
8303 api_sw_interface_span_dump (vat_main_t * vam)
8305 unformat_input_t *input = vam->input;
8306 vl_api_sw_interface_span_dump_t *mp;
8307 vl_api_control_ping_t *mp_ping;
8311 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8313 if (unformat (input, "l2"))
8319 M (SW_INTERFACE_SPAN_DUMP, mp);
8323 /* Use a control ping for synchronization */
8324 MPING (CONTROL_PING, mp_ping);
8332 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
8334 unformat_input_t *input = vam->input;
8335 vl_api_ip_source_and_port_range_check_add_del_t *mp;
8338 u16 *high_ports = 0;
8341 vl_api_prefix_t prefix;
8348 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8350 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
8352 else if (unformat (input, "vrf %d", &vrf_id))
8354 else if (unformat (input, "del"))
8356 else if (unformat (input, "port %d", &tmp))
8358 if (tmp == 0 || tmp > 65535)
8360 errmsg ("port %d out of range", tmp);
8364 this_hi = this_low + 1;
8365 vec_add1 (low_ports, this_low);
8366 vec_add1 (high_ports, this_hi);
8368 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
8370 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
8372 errmsg ("incorrect range parameters");
8376 /* Note: in debug CLI +1 is added to high before
8377 passing to real fn that does "the work"
8378 (ip_source_and_port_range_check_add_del).
8379 This fn is a wrapper around the binary API fn a
8380 control plane will call, which expects this increment
8381 to have occurred. Hence letting the binary API control
8382 plane fn do the increment for consistency between VAT
8383 and other control planes.
8386 vec_add1 (low_ports, this_low);
8387 vec_add1 (high_ports, this_hi);
8393 if (prefix_set == 0)
8395 errmsg ("<address>/<mask> not specified");
8401 errmsg ("VRF ID required, not specified");
8408 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
8412 if (vec_len (low_ports) == 0)
8414 errmsg ("At least one port or port range required");
8418 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
8420 mp->is_add = is_add;
8422 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
8424 mp->number_of_ranges = vec_len (low_ports);
8426 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
8427 vec_free (low_ports);
8429 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
8430 vec_free (high_ports);
8432 mp->vrf_id = ntohl (vrf_id);
8440 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
8442 unformat_input_t *input = vam->input;
8443 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
8444 u32 sw_if_index = ~0;
8446 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
8447 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
8451 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8453 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8455 else if (unformat (input, "sw_if_index %d", &sw_if_index))
8457 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
8459 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
8461 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
8463 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
8465 else if (unformat (input, "del"))
8471 if (sw_if_index == ~0)
8473 errmsg ("Interface required but not specified");
8479 errmsg ("VRF ID required but not specified");
8483 if (tcp_out_vrf_id == 0
8484 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
8487 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
8491 /* Construct the API message */
8492 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
8494 mp->sw_if_index = ntohl (sw_if_index);
8495 mp->is_add = is_add;
8496 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
8497 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
8498 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
8499 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
8504 /* Wait for a reply... */
8510 api_set_punt (vat_main_t * vam)
8512 unformat_input_t *i = vam->input;
8513 vl_api_address_family_t af;
8514 vl_api_set_punt_t *mp;
8520 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8522 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
8524 else if (unformat (i, "protocol %d", &protocol))
8526 else if (unformat (i, "port %d", &port))
8528 else if (unformat (i, "del"))
8532 clib_warning ("parse error '%U'", format_unformat_error, i);
8539 mp->is_add = (u8) is_add;
8540 mp->punt.type = PUNT_API_TYPE_L4;
8541 mp->punt.punt.l4.af = af;
8542 mp->punt.punt.l4.protocol = (u8) protocol;
8543 mp->punt.punt.l4.port = htons ((u16) port);
8551 api_delete_subif (vat_main_t * vam)
8553 unformat_input_t *i = vam->input;
8554 vl_api_delete_subif_t *mp;
8555 u32 sw_if_index = ~0;
8558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8560 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8562 if (unformat (i, "sw_if_index %d", &sw_if_index))
8568 if (sw_if_index == ~0)
8570 errmsg ("missing sw_if_index");
8574 /* Construct the API message */
8575 M (DELETE_SUBIF, mp);
8576 mp->sw_if_index = ntohl (sw_if_index);
8583 #define foreach_pbb_vtr_op \
8584 _("disable", L2_VTR_DISABLED) \
8585 _("pop", L2_VTR_POP_2) \
8586 _("push", L2_VTR_PUSH_2)
8589 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
8591 unformat_input_t *i = vam->input;
8592 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
8593 u32 sw_if_index = ~0, vtr_op = ~0;
8595 u8 dmac[6], smac[6];
8596 u8 dmac_set = 0, smac_set = 0;
8602 /* Shut up coverity */
8603 clib_memset (dmac, 0, sizeof (dmac));
8604 clib_memset (smac, 0, sizeof (smac));
8606 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8608 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8610 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8612 else if (unformat (i, "vtr_op %d", &vtr_op))
8614 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
8617 else if (unformat (i, "translate_pbb_stag"))
8619 if (unformat (i, "%d", &tmp))
8621 vtr_op = L2_VTR_TRANSLATE_2_1;
8627 ("translate_pbb_stag operation requires outer tag definition");
8631 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
8633 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
8635 else if (unformat (i, "sid %d", &sid))
8637 else if (unformat (i, "vlanid %d", &tmp))
8641 clib_warning ("parse error '%U'", format_unformat_error, i);
8646 if ((sw_if_index == ~0) || (vtr_op == ~0))
8648 errmsg ("missing sw_if_index or vtr operation");
8651 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
8652 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
8655 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
8659 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
8660 mp->sw_if_index = ntohl (sw_if_index);
8661 mp->vtr_op = ntohl (vtr_op);
8662 mp->outer_tag = ntohs (outer_tag);
8663 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
8664 clib_memcpy (mp->b_smac, smac, sizeof (smac));
8665 mp->b_vlanid = ntohs (vlanid);
8666 mp->i_sid = ntohl (sid);
8674 api_sw_interface_tag_add_del (vat_main_t * vam)
8676 unformat_input_t *i = vam->input;
8677 vl_api_sw_interface_tag_add_del_t *mp;
8678 u32 sw_if_index = ~0;
8683 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8685 if (unformat (i, "tag %s", &tag))
8687 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8689 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8691 else if (unformat (i, "del"))
8697 if (sw_if_index == ~0)
8699 errmsg ("missing interface name or sw_if_index");
8703 if (enable && (tag == 0))
8705 errmsg ("no tag specified");
8709 /* Construct the API message */
8710 M (SW_INTERFACE_TAG_ADD_DEL, mp);
8711 mp->sw_if_index = ntohl (sw_if_index);
8712 mp->is_add = enable;
8714 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8723 api_sw_interface_add_del_mac_address (vat_main_t * vam)
8725 unformat_input_t *i = vam->input;
8726 vl_api_mac_address_t mac = { 0 };
8727 vl_api_sw_interface_add_del_mac_address_t *mp;
8728 u32 sw_if_index = ~0;
8733 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8735 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8737 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8739 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
8741 else if (unformat (i, "del"))
8747 if (sw_if_index == ~0)
8749 errmsg ("missing interface name or sw_if_index");
8755 errmsg ("missing MAC address");
8759 /* Construct the API message */
8760 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
8761 mp->sw_if_index = ntohl (sw_if_index);
8762 mp->is_add = is_add;
8763 clib_memcpy (&mp->addr, &mac, sizeof (mac));
8770 static void vl_api_l2_xconnect_details_t_handler
8771 (vl_api_l2_xconnect_details_t * mp)
8773 vat_main_t *vam = &vat_main;
8775 print (vam->ofp, "%15d%15d",
8776 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
8779 static void vl_api_l2_xconnect_details_t_handler_json
8780 (vl_api_l2_xconnect_details_t * mp)
8782 vat_main_t *vam = &vat_main;
8783 vat_json_node_t *node = NULL;
8785 if (VAT_JSON_ARRAY != vam->json_tree.type)
8787 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8788 vat_json_init_array (&vam->json_tree);
8790 node = vat_json_array_add (&vam->json_tree);
8792 vat_json_init_object (node);
8793 vat_json_object_add_uint (node, "rx_sw_if_index",
8794 ntohl (mp->rx_sw_if_index));
8795 vat_json_object_add_uint (node, "tx_sw_if_index",
8796 ntohl (mp->tx_sw_if_index));
8800 api_l2_xconnect_dump (vat_main_t * vam)
8802 vl_api_l2_xconnect_dump_t *mp;
8803 vl_api_control_ping_t *mp_ping;
8806 if (!vam->json_output)
8808 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
8811 M (L2_XCONNECT_DUMP, mp);
8815 /* Use a control ping for synchronization */
8816 MPING (CONTROL_PING, mp_ping);
8824 api_hw_interface_set_mtu (vat_main_t * vam)
8826 unformat_input_t *i = vam->input;
8827 vl_api_hw_interface_set_mtu_t *mp;
8828 u32 sw_if_index = ~0;
8832 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8834 if (unformat (i, "mtu %d", &mtu))
8836 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8838 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8844 if (sw_if_index == ~0)
8846 errmsg ("missing interface name or sw_if_index");
8852 errmsg ("no mtu specified");
8856 /* Construct the API message */
8857 M (HW_INTERFACE_SET_MTU, mp);
8858 mp->sw_if_index = ntohl (sw_if_index);
8859 mp->mtu = ntohs ((u16) mtu);
8867 api_tcp_configure_src_addresses (vat_main_t * vam)
8869 vl_api_tcp_configure_src_addresses_t *mp;
8870 unformat_input_t *i = vam->input;
8871 vl_api_address_t first, last;
8876 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8878 if (unformat (i, "%U - %U",
8879 unformat_vl_api_address, &first,
8880 unformat_vl_api_address, &last))
8884 errmsg ("one range per message (range already set)");
8889 else if (unformat (i, "vrf %d", &vrf_id))
8897 errmsg ("address range not set");
8901 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
8903 mp->vrf_id = ntohl (vrf_id);
8904 clib_memcpy (&mp->first_address, &first, sizeof (first));
8905 clib_memcpy (&mp->last_address, &last, sizeof (last));
8912 static void vl_api_app_namespace_add_del_reply_t_handler
8913 (vl_api_app_namespace_add_del_reply_t * mp)
8915 vat_main_t *vam = &vat_main;
8916 i32 retval = ntohl (mp->retval);
8917 if (vam->async_mode)
8919 vam->async_errors += (retval < 0);
8923 vam->retval = retval;
8925 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
8926 vam->result_ready = 1;
8930 static void vl_api_app_namespace_add_del_reply_t_handler_json
8931 (vl_api_app_namespace_add_del_reply_t * mp)
8933 vat_main_t *vam = &vat_main;
8934 vat_json_node_t node;
8936 vat_json_init_object (&node);
8937 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
8938 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
8940 vat_json_print (vam->ofp, &node);
8941 vat_json_free (&node);
8943 vam->retval = ntohl (mp->retval);
8944 vam->result_ready = 1;
8948 api_app_namespace_add_del (vat_main_t * vam)
8950 vl_api_app_namespace_add_del_t *mp;
8951 unformat_input_t *i = vam->input;
8952 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
8953 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
8957 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8959 if (unformat (i, "id %_%v%_", &ns_id))
8961 else if (unformat (i, "secret %lu", &secret))
8963 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8964 sw_if_index_set = 1;
8965 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
8967 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
8972 if (!ns_id || !secret_set || !sw_if_index_set)
8974 errmsg ("namespace id, secret and sw_if_index must be set");
8977 if (vec_len (ns_id) > 64)
8979 errmsg ("namespace id too long");
8982 M (APP_NAMESPACE_ADD_DEL, mp);
8984 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
8985 mp->secret = clib_host_to_net_u64 (secret);
8986 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
8987 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
8988 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
8996 api_sock_init_shm (vat_main_t * vam)
8998 #if VPP_API_TEST_BUILTIN == 0
8999 unformat_input_t *i = vam->input;
9000 vl_api_shm_elem_config_t *config = 0;
9001 u64 size = 64 << 20;
9004 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9006 if (unformat (i, "size %U", unformat_memory_size, &size))
9013 * Canned custom ring allocator config.
9014 * Should probably parse all of this
9016 vec_validate (config, 6);
9017 config[0].type = VL_API_VLIB_RING;
9018 config[0].size = 256;
9019 config[0].count = 32;
9021 config[1].type = VL_API_VLIB_RING;
9022 config[1].size = 1024;
9023 config[1].count = 16;
9025 config[2].type = VL_API_VLIB_RING;
9026 config[2].size = 4096;
9027 config[2].count = 2;
9029 config[3].type = VL_API_CLIENT_RING;
9030 config[3].size = 256;
9031 config[3].count = 32;
9033 config[4].type = VL_API_CLIENT_RING;
9034 config[4].size = 1024;
9035 config[4].count = 16;
9037 config[5].type = VL_API_CLIENT_RING;
9038 config[5].size = 4096;
9039 config[5].count = 2;
9041 config[6].type = VL_API_QUEUE;
9042 config[6].count = 128;
9043 config[6].size = sizeof (uword);
9045 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
9047 vam->client_index_invalid = 1;
9055 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
9057 vat_main_t *vam = &vat_main;
9058 fib_prefix_t lcl, rmt;
9060 ip_prefix_decode (&mp->lcl, &lcl);
9061 ip_prefix_decode (&mp->rmt, &rmt);
9063 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
9066 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
9067 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
9068 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
9069 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
9070 &rmt.fp_addr.ip4, rmt.fp_len,
9071 clib_net_to_host_u16 (mp->rmt_port),
9072 clib_net_to_host_u32 (mp->action_index), mp->tag);
9077 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
9078 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
9079 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
9080 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
9081 &rmt.fp_addr.ip6, rmt.fp_len,
9082 clib_net_to_host_u16 (mp->rmt_port),
9083 clib_net_to_host_u32 (mp->action_index), mp->tag);
9088 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
9091 vat_main_t *vam = &vat_main;
9092 vat_json_node_t *node = NULL;
9093 struct in6_addr ip6;
9096 fib_prefix_t lcl, rmt;
9098 ip_prefix_decode (&mp->lcl, &lcl);
9099 ip_prefix_decode (&mp->rmt, &rmt);
9101 if (VAT_JSON_ARRAY != vam->json_tree.type)
9103 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9104 vat_json_init_array (&vam->json_tree);
9106 node = vat_json_array_add (&vam->json_tree);
9107 vat_json_init_object (node);
9109 vat_json_object_add_uint (node, "appns_index",
9110 clib_net_to_host_u32 (mp->appns_index));
9111 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
9112 vat_json_object_add_uint (node, "scope", mp->scope);
9113 vat_json_object_add_uint (node, "action_index",
9114 clib_net_to_host_u32 (mp->action_index));
9115 vat_json_object_add_uint (node, "lcl_port",
9116 clib_net_to_host_u16 (mp->lcl_port));
9117 vat_json_object_add_uint (node, "rmt_port",
9118 clib_net_to_host_u16 (mp->rmt_port));
9119 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
9120 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
9121 vat_json_object_add_string_copy (node, "tag", mp->tag);
9122 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
9124 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
9125 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
9126 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
9127 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
9131 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
9132 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
9133 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
9134 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
9139 api_session_rule_add_del (vat_main_t * vam)
9141 vl_api_session_rule_add_del_t *mp;
9142 unformat_input_t *i = vam->input;
9143 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
9144 u32 appns_index = 0, scope = 0;
9145 ip4_address_t lcl_ip4, rmt_ip4;
9146 ip6_address_t lcl_ip6, rmt_ip6;
9147 u8 is_ip4 = 1, conn_set = 0;
9148 u8 is_add = 1, *tag = 0;
9150 fib_prefix_t lcl, rmt;
9152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9154 if (unformat (i, "del"))
9156 else if (unformat (i, "add"))
9158 else if (unformat (i, "proto tcp"))
9160 else if (unformat (i, "proto udp"))
9162 else if (unformat (i, "appns %d", &appns_index))
9164 else if (unformat (i, "scope %d", &scope))
9166 else if (unformat (i, "tag %_%v%_", &tag))
9170 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
9171 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
9179 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
9180 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
9186 else if (unformat (i, "action %d", &action))
9191 if (proto == ~0 || !conn_set || action == ~0)
9193 errmsg ("transport proto, connection and action must be set");
9199 errmsg ("scope should be 0-3");
9203 M (SESSION_RULE_ADD_DEL, mp);
9205 clib_memset (&lcl, 0, sizeof (lcl));
9206 clib_memset (&rmt, 0, sizeof (rmt));
9209 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
9210 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
9211 lcl.fp_len = lcl_plen;
9212 rmt.fp_len = rmt_plen;
9216 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
9217 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
9218 lcl.fp_len = lcl_plen;
9219 rmt.fp_len = rmt_plen;
9223 ip_prefix_encode (&lcl, &mp->lcl);
9224 ip_prefix_encode (&rmt, &mp->rmt);
9225 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
9226 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
9227 mp->transport_proto =
9228 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
9229 mp->action_index = clib_host_to_net_u32 (action);
9230 mp->appns_index = clib_host_to_net_u32 (appns_index);
9232 mp->is_add = is_add;
9235 clib_memcpy (mp->tag, tag, vec_len (tag));
9245 api_session_rules_dump (vat_main_t * vam)
9247 vl_api_session_rules_dump_t *mp;
9248 vl_api_control_ping_t *mp_ping;
9251 if (!vam->json_output)
9253 print (vam->ofp, "%=20s", "Session Rules");
9256 M (SESSION_RULES_DUMP, mp);
9260 /* Use a control ping for synchronization */
9261 MPING (CONTROL_PING, mp_ping);
9264 /* Wait for a reply... */
9270 api_ip_container_proxy_add_del (vat_main_t * vam)
9272 vl_api_ip_container_proxy_add_del_t *mp;
9273 unformat_input_t *i = vam->input;
9274 u32 sw_if_index = ~0;
9275 vl_api_prefix_t pfx = { };
9279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9281 if (unformat (i, "del"))
9283 else if (unformat (i, "add"))
9285 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
9287 else if (unformat (i, "sw_if_index %u", &sw_if_index))
9292 if (sw_if_index == ~0 || pfx.len == 0)
9294 errmsg ("address and sw_if_index must be set");
9298 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
9300 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
9301 mp->is_add = is_add;
9302 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
9310 api_qos_record_enable_disable (vat_main_t * vam)
9312 unformat_input_t *i = vam->input;
9313 vl_api_qos_record_enable_disable_t *mp;
9314 u32 sw_if_index, qs = 0xff;
9315 u8 sw_if_index_set = 0;
9319 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9321 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
9322 sw_if_index_set = 1;
9323 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9324 sw_if_index_set = 1;
9325 else if (unformat (i, "%U", unformat_qos_source, &qs))
9327 else if (unformat (i, "disable"))
9331 clib_warning ("parse error '%U'", format_unformat_error, i);
9336 if (sw_if_index_set == 0)
9338 errmsg ("missing interface name or sw_if_index");
9343 errmsg ("input location must be specified");
9347 M (QOS_RECORD_ENABLE_DISABLE, mp);
9349 mp->record.sw_if_index = ntohl (sw_if_index);
9350 mp->record.input_source = qs;
9351 mp->enable = enable;
9360 q_or_quit (vat_main_t * vam)
9362 #if VPP_API_TEST_BUILTIN == 0
9363 longjmp (vam->jump_buf, 1);
9365 return 0; /* not so much */
9369 q (vat_main_t * vam)
9371 return q_or_quit (vam);
9375 quit (vat_main_t * vam)
9377 return q_or_quit (vam);
9381 comment (vat_main_t * vam)
9387 elog_save (vat_main_t * vam)
9389 #if VPP_API_TEST_BUILTIN == 0
9390 elog_main_t *em = &vam->elog_main;
9391 unformat_input_t *i = vam->input;
9392 char *file, *chroot_file;
9393 clib_error_t *error;
9395 if (!unformat (i, "%s", &file))
9397 errmsg ("expected file name, got `%U'", format_unformat_error, i);
9401 /* It's fairly hard to get "../oopsie" through unformat; just in case */
9402 if (strstr (file, "..") || index (file, '/'))
9404 errmsg ("illegal characters in filename '%s'", file);
9408 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
9412 errmsg ("Saving %wd of %wd events to %s",
9413 elog_n_events_in_buffer (em),
9414 elog_buffer_capacity (em), chroot_file);
9416 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
9417 vec_free (chroot_file);
9420 clib_error_report (error);
9422 errmsg ("Use the vpp event loger...");
9429 elog_setup (vat_main_t * vam)
9431 #if VPP_API_TEST_BUILTIN == 0
9432 elog_main_t *em = &vam->elog_main;
9433 unformat_input_t *i = vam->input;
9434 u32 nevents = 128 << 10;
9436 (void) unformat (i, "nevents %d", &nevents);
9438 elog_init (em, nevents);
9439 vl_api_set_elog_main (em);
9440 vl_api_set_elog_trace_api_messages (1);
9441 errmsg ("Event logger initialized with %u events", nevents);
9443 errmsg ("Use the vpp event loger...");
9449 elog_enable (vat_main_t * vam)
9451 #if VPP_API_TEST_BUILTIN == 0
9452 elog_main_t *em = &vam->elog_main;
9454 elog_enable_disable (em, 1 /* enable */ );
9455 vl_api_set_elog_trace_api_messages (1);
9456 errmsg ("Event logger enabled...");
9458 errmsg ("Use the vpp event loger...");
9464 elog_disable (vat_main_t * vam)
9466 #if VPP_API_TEST_BUILTIN == 0
9467 elog_main_t *em = &vam->elog_main;
9469 elog_enable_disable (em, 0 /* enable */ );
9470 vl_api_set_elog_trace_api_messages (1);
9471 errmsg ("Event logger disabled...");
9473 errmsg ("Use the vpp event loger...");
9479 statseg (vat_main_t * vam)
9481 ssvm_private_t *ssvmp = &vam->stat_segment;
9482 ssvm_shared_header_t *shared_header = ssvmp->sh;
9483 vlib_counter_t **counters;
9484 u64 thread0_index1_packets;
9485 u64 thread0_index1_bytes;
9486 f64 vector_rate, input_rate;
9489 uword *counter_vector_by_name;
9490 if (vam->stat_segment_lockp == 0)
9492 errmsg ("Stat segment not mapped...");
9496 /* look up "/if/rx for sw_if_index 1 as a test */
9498 clib_spinlock_lock (vam->stat_segment_lockp);
9500 counter_vector_by_name = (uword *) shared_header->opaque[1];
9502 p = hash_get_mem (counter_vector_by_name, "/if/rx");
9505 clib_spinlock_unlock (vam->stat_segment_lockp);
9506 errmsg ("/if/tx not found?");
9510 /* Fish per-thread vector of combined counters from shared memory */
9511 counters = (vlib_counter_t **) p[0];
9513 if (vec_len (counters[0]) < 2)
9515 clib_spinlock_unlock (vam->stat_segment_lockp);
9516 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
9520 /* Read thread 0 sw_if_index 1 counter */
9521 thread0_index1_packets = counters[0][1].packets;
9522 thread0_index1_bytes = counters[0][1].bytes;
9524 p = hash_get_mem (counter_vector_by_name, "vector_rate");
9527 clib_spinlock_unlock (vam->stat_segment_lockp);
9528 errmsg ("vector_rate not found?");
9532 vector_rate = *(f64 *) (p[0]);
9533 p = hash_get_mem (counter_vector_by_name, "input_rate");
9536 clib_spinlock_unlock (vam->stat_segment_lockp);
9537 errmsg ("input_rate not found?");
9540 input_rate = *(f64 *) (p[0]);
9542 clib_spinlock_unlock (vam->stat_segment_lockp);
9544 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
9545 vector_rate, input_rate);
9546 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
9547 thread0_index1_packets, thread0_index1_bytes);
9553 cmd_cmp (void *a1, void *a2)
9558 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
9562 help (vat_main_t * vam)
9567 unformat_input_t *i = vam->input;
9570 if (unformat (i, "%s", &name))
9576 hs = hash_get_mem (vam->help_by_name, name);
9578 print (vam->ofp, "usage: %s %s", name, hs[0]);
9580 print (vam->ofp, "No such msg / command '%s'", name);
9585 print (vam->ofp, "Help is available for the following:");
9588 hash_foreach_pair (p, vam->function_by_name,
9590 vec_add1 (cmds, (u8 *)(p->key));
9594 vec_sort_with_function (cmds, cmd_cmp);
9596 for (j = 0; j < vec_len (cmds); j++)
9597 print (vam->ofp, "%s", cmds[j]);
9604 set (vat_main_t * vam)
9606 u8 *name = 0, *value = 0;
9607 unformat_input_t *i = vam->input;
9609 if (unformat (i, "%s", &name))
9611 /* The input buffer is a vector, not a string. */
9612 value = vec_dup (i->buffer);
9613 vec_delete (value, i->index, 0);
9614 /* Almost certainly has a trailing newline */
9615 if (value[vec_len (value) - 1] == '\n')
9616 value[vec_len (value) - 1] = 0;
9617 /* Make sure it's a proper string, one way or the other */
9618 vec_add1 (value, 0);
9619 (void) clib_macro_set_value (&vam->macro_main,
9620 (char *) name, (char *) value);
9623 errmsg ("usage: set <name> <value>");
9631 unset (vat_main_t * vam)
9635 if (unformat (vam->input, "%s", &name))
9636 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
9637 errmsg ("unset: %s wasn't set", name);
9650 macro_sort_cmp (void *a1, void *a2)
9652 macro_sort_t *s1 = a1;
9653 macro_sort_t *s2 = a2;
9655 return strcmp ((char *) (s1->name), (char *) (s2->name));
9659 dump_macro_table (vat_main_t * vam)
9661 macro_sort_t *sort_me = 0, *sm;
9666 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
9668 vec_add2 (sort_me, sm, 1);
9669 sm->name = (u8 *)(p->key);
9670 sm->value = (u8 *) (p->value[0]);
9674 vec_sort_with_function (sort_me, macro_sort_cmp);
9676 if (vec_len (sort_me))
9677 print (vam->ofp, "%-15s%s", "Name", "Value");
9679 print (vam->ofp, "The macro table is empty...");
9681 for (i = 0; i < vec_len (sort_me); i++)
9682 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
9687 dump_node_table (vat_main_t * vam)
9690 vlib_node_t *node, *next_node;
9692 if (vec_len (vam->graph_nodes) == 0)
9694 print (vam->ofp, "Node table empty, issue get_node_graph...");
9698 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
9700 node = vam->graph_nodes[0][i];
9701 print (vam->ofp, "[%d] %s", i, node->name);
9702 for (j = 0; j < vec_len (node->next_nodes); j++)
9704 if (node->next_nodes[j] != ~0)
9706 next_node = vam->graph_nodes[0][node->next_nodes[j]];
9707 print (vam->ofp, " [%d] %s", j, next_node->name);
9715 value_sort_cmp (void *a1, void *a2)
9717 name_sort_t *n1 = a1;
9718 name_sort_t *n2 = a2;
9720 if (n1->value < n2->value)
9722 if (n1->value > n2->value)
9729 dump_msg_api_table (vat_main_t * vam)
9731 api_main_t *am = vlibapi_get_main ();
9732 name_sort_t *nses = 0, *ns;
9737 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
9739 vec_add2 (nses, ns, 1);
9740 ns->name = (u8 *)(hp->key);
9741 ns->value = (u32) hp->value[0];
9745 vec_sort_with_function (nses, value_sort_cmp);
9747 for (i = 0; i < vec_len (nses); i++)
9748 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
9754 get_msg_id (vat_main_t * vam)
9759 if (unformat (vam->input, "%s", &name_and_crc))
9761 message_index = vl_msg_api_get_msg_index (name_and_crc);
9762 if (message_index == ~0)
9764 print (vam->ofp, " '%s' not found", name_and_crc);
9767 print (vam->ofp, " '%s' has message index %d",
9768 name_and_crc, message_index);
9771 errmsg ("name_and_crc required...");
9776 search_node_table (vat_main_t * vam)
9778 unformat_input_t *line_input = vam->input;
9781 vlib_node_t *node, *next_node;
9784 if (vam->graph_node_index_by_name == 0)
9786 print (vam->ofp, "Node table empty, issue get_node_graph...");
9790 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9792 if (unformat (line_input, "%s", &node_to_find))
9794 vec_add1 (node_to_find, 0);
9795 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
9798 print (vam->ofp, "%s not found...", node_to_find);
9801 node = vam->graph_nodes[0][p[0]];
9802 print (vam->ofp, "[%d] %s", p[0], node->name);
9803 for (j = 0; j < vec_len (node->next_nodes); j++)
9805 if (node->next_nodes[j] != ~0)
9807 next_node = vam->graph_nodes[0][node->next_nodes[j]];
9808 print (vam->ofp, " [%d] %s", j, next_node->name);
9815 clib_warning ("parse error '%U'", format_unformat_error,
9821 vec_free (node_to_find);
9830 script (vat_main_t * vam)
9832 #if (VPP_API_TEST_BUILTIN==0)
9834 char *save_current_file;
9835 unformat_input_t save_input;
9836 jmp_buf save_jump_buf;
9837 u32 save_line_number;
9839 FILE *new_fp, *save_ifp;
9841 if (unformat (vam->input, "%s", &s))
9843 new_fp = fopen ((char *) s, "r");
9846 errmsg ("Couldn't open script file %s", s);
9853 errmsg ("Missing script name");
9857 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
9858 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
9859 save_ifp = vam->ifp;
9860 save_line_number = vam->input_line_number;
9861 save_current_file = (char *) vam->current_file;
9863 vam->input_line_number = 0;
9865 vam->current_file = s;
9868 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
9869 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
9870 vam->ifp = save_ifp;
9871 vam->input_line_number = save_line_number;
9872 vam->current_file = (u8 *) save_current_file;
9877 clib_warning ("use the exec command...");
9883 echo (vat_main_t * vam)
9885 print (vam->ofp, "%v", vam->input->buffer);
9889 /* List of API message constructors, CLI names map to api_xxx */
9890 #define foreach_vpe_api_msg \
9891 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
9892 _(sw_interface_dump,"") \
9893 _(sw_interface_set_flags, \
9894 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
9895 _(sw_interface_add_del_address, \
9896 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
9897 _(sw_interface_set_rx_mode, \
9898 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
9899 _(sw_interface_set_rx_placement, \
9900 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
9901 _(sw_interface_rx_placement_dump, \
9902 "[<intfc> | sw_if_index <id>]") \
9903 _(sw_interface_set_table, \
9904 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
9905 _(sw_interface_set_mpls_enable, \
9906 "<intfc> | sw_if_index [disable | dis]") \
9907 _(sw_interface_set_vpath, \
9908 "<intfc> | sw_if_index <id> enable | disable") \
9909 _(sw_interface_set_l2_xconnect, \
9910 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
9911 "enable | disable") \
9912 _(sw_interface_set_l2_bridge, \
9913 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
9914 "[shg <split-horizon-group>] [bvi]\n" \
9915 "enable | disable") \
9916 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
9917 _(bridge_domain_add_del, \
9918 "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") \
9919 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
9921 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
9922 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
9923 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
9925 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
9927 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
9928 _(virtio_pci_create_v2, \
9929 "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]") \
9930 _(virtio_pci_delete, \
9931 "<vpp-if-name> | sw_if_index <id>") \
9932 _(sw_interface_virtio_pci_dump, "") \
9933 _(ip_table_add_del, \
9934 "table <n> [ipv6] [add | del]\n") \
9935 _(ip_route_add_del, \
9936 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
9937 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
9938 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
9939 "[multipath] [count <n>] [del]") \
9940 _(ip_mroute_add_del, \
9941 "<src> <grp>/<mask> [table-id <n>]\n" \
9942 "[<intfc> | sw_if_index <id>] [local] [del]") \
9943 _(mpls_table_add_del, \
9944 "table <n> [add | del]\n") \
9945 _(mpls_route_add_del, \
9946 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
9947 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
9948 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
9949 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
9950 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
9951 "[count <n>] [del]") \
9952 _(mpls_ip_bind_unbind, \
9953 "<label> <addr/len>") \
9954 _(mpls_tunnel_add_del, \
9955 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
9956 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
9957 "[l2-only] [out-label <n>]") \
9958 _(sw_interface_set_unnumbered, \
9959 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
9960 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
9961 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
9962 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
9963 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
9964 "[outer_vlan_id_any][inner_vlan_id_any]") \
9965 _(ip_table_replace_begin, "table <n> [ipv6]") \
9966 _(ip_table_flush, "table <n> [ipv6]") \
9967 _(ip_table_replace_end, "table <n> [ipv6]") \
9968 _(set_ip_flow_hash, \
9969 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
9970 _(sw_interface_ip6_enable_disable, \
9971 "<intfc> | sw_if_index <id> enable | disable") \
9972 _(l2_patch_add_del, \
9973 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
9974 "enable | disable") \
9975 _(get_node_index, "node <node-name") \
9976 _(add_node_next, "node <node-name> next <next-node-name>") \
9977 _(l2_fib_clear_table, "") \
9978 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
9979 _(l2_interface_vlan_tag_rewrite, \
9980 "<intfc> | sw_if_index <nn> \n" \
9981 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
9982 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
9983 _(create_vhost_user_if, \
9984 "socket <filename> [server] [renumber <dev_instance>] " \
9985 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
9986 "[mac <mac_address>] [packed]") \
9987 _(modify_vhost_user_if, \
9988 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9989 "[server] [renumber <dev_instance>] [gso] [packed]") \
9990 _(create_vhost_user_if_v2, \
9991 "socket <filename> [server] [renumber <dev_instance>] " \
9992 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
9993 "[mac <mac_address>] [packed] [event-idx]") \
9994 _(modify_vhost_user_if_v2, \
9995 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9996 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
9997 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
9998 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
9999 _(show_version, "") \
10000 _(show_threads, "") \
10001 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10002 _(interface_name_renumber, \
10003 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10004 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
10005 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10006 _(ip_dump, "ipv4 | ipv6") \
10007 _(delete_loopback,"sw_if_index <nn>") \
10008 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10009 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
10010 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
10011 _(want_interface_events, "enable|disable") \
10012 _(get_first_msg_id, "client <name>") \
10013 _(get_node_graph, " ") \
10014 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10015 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
10016 _(ioam_disable, "") \
10017 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
10018 _(af_packet_delete, "name <host interface name>") \
10019 _(af_packet_dump, "") \
10020 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
10021 _(mpls_table_dump, "") \
10022 _(mpls_route_dump, "table-id <ID>") \
10023 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
10024 _(sw_interface_span_dump, "[l2]") \
10025 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
10026 _(ip_source_and_port_range_check_add_del, \
10027 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
10028 _(ip_source_and_port_range_check_interface_add_del, \
10029 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
10030 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
10031 _(delete_subif,"<intfc> | sw_if_index <nn>") \
10032 _(l2_interface_pbb_tag_rewrite, \
10033 "<intfc> | sw_if_index <nn> \n" \
10034 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
10035 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
10036 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
10037 _(ip_table_dump, "") \
10038 _(ip_route_dump, "table-id [ip4|ip6]") \
10039 _(ip_mtable_dump, "") \
10040 _(ip_mroute_dump, "table-id [ip4|ip6]") \
10041 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
10043 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
10044 "mac <mac-address> [del]") \
10045 _(l2_xconnect_dump, "") \
10046 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
10047 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
10048 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
10049 _(sock_init_shm, "size <nnn>") \
10050 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
10051 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
10052 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
10053 _(session_rules_dump, "") \
10054 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
10055 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
10057 /* List of command functions, CLI names map directly to functions */
10058 #define foreach_cli_function \
10059 _(comment, "usage: comment <ignore-rest-of-line>") \
10060 _(dump_interface_table, "usage: dump_interface_table") \
10061 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10062 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10063 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10064 _(dump_macro_table, "usage: dump_macro_table ") \
10065 _(dump_node_table, "usage: dump_node_table") \
10066 _(dump_msg_api_table, "usage: dump_msg_api_table") \
10067 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
10068 _(elog_disable, "usage: elog_disable") \
10069 _(elog_enable, "usage: elog_enable") \
10070 _(elog_save, "usage: elog_save <filename>") \
10071 _(get_msg_id, "usage: get_msg_id name_and_crc") \
10072 _(echo, "usage: echo <message>") \
10073 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10074 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
10075 _(help, "usage: help") \
10076 _(q, "usage: quit") \
10077 _(quit, "usage: quit") \
10078 _(search_node_table, "usage: search_node_table <name>...") \
10079 _(set, "usage: set <variable-name> <value>") \
10080 _(script, "usage: script <file-name>") \
10081 _(statseg, "usage: statseg") \
10082 _(unset, "usage: unset <variable-name>")
10085 static void vl_api_##n##_t_handler_uni \
10086 (vl_api_##n##_t * mp) \
10088 vat_main_t * vam = &vat_main; \
10089 if (vam->json_output) { \
10090 vl_api_##n##_t_handler_json(mp); \
10092 vl_api_##n##_t_handler(mp); \
10095 foreach_vpe_api_reply_msg;
10096 #if VPP_API_TEST_BUILTIN == 0
10097 foreach_standalone_reply_msg;
10102 vat_api_hookup (vat_main_t * vam)
10105 vl_msg_api_set_handlers(VL_API_##N, #n, \
10106 vl_api_##n##_t_handler_uni, \
10108 vl_api_##n##_t_endian, \
10109 vl_api_##n##_t_print, \
10110 sizeof(vl_api_##n##_t), 1);
10111 foreach_vpe_api_reply_msg;
10112 #if VPP_API_TEST_BUILTIN == 0
10113 foreach_standalone_reply_msg;
10117 #if (VPP_API_TEST_BUILTIN==0)
10118 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10120 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
10122 vam->function_by_name = hash_create_string (0, sizeof (uword));
10124 vam->help_by_name = hash_create_string (0, sizeof (uword));
10127 /* API messages we can send */
10128 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10129 foreach_vpe_api_msg;
10133 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10134 foreach_vpe_api_msg;
10137 /* CLI functions */
10138 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10139 foreach_cli_function;
10143 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10144 foreach_cli_function;
10148 #if VPP_API_TEST_BUILTIN
10149 static clib_error_t *
10150 vat_api_hookup_shim (vlib_main_t * vm)
10152 vat_api_hookup (&vat_main);
10156 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
10160 * fd.io coding-style-patch-verification: ON
10163 * eval: (c-set-style "gnu")