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) \
2023 static void vl_api_##n##_t_handler \
2024 (vl_api_##n##_t * mp) \
2026 vat_main_t * vam = &vat_main; \
2027 i32 retval = ntohl(mp->retval); \
2028 if (vam->async_mode) { \
2029 vam->async_errors += (retval < 0); \
2031 vam->retval = retval; \
2032 vam->result_ready = 1; \
2035 foreach_standard_reply_retval_handler;
2039 static void vl_api_##n##_t_handler_json \
2040 (vl_api_##n##_t * mp) \
2042 vat_main_t * vam = &vat_main; \
2043 vat_json_node_t node; \
2044 vat_json_init_object(&node); \
2045 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2046 vat_json_print(vam->ofp, &node); \
2047 vam->retval = ntohl(mp->retval); \
2048 vam->result_ready = 1; \
2050 foreach_standard_reply_retval_handler;
2054 * Table of message reply handlers, must include boilerplate handlers
2058 #define foreach_vpe_api_reply_msg \
2059 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2060 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2061 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2062 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2063 _(CONTROL_PING_REPLY, control_ping_reply) \
2064 _(CLI_REPLY, cli_reply) \
2065 _(CLI_INBAND_REPLY, cli_inband_reply) \
2066 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2067 sw_interface_add_del_address_reply) \
2068 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2069 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2070 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2071 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2072 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2073 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2074 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2075 sw_interface_set_l2_xconnect_reply) \
2076 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2077 sw_interface_set_l2_bridge_reply) \
2078 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2079 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2080 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2081 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2082 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2083 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2084 _(L2_FLAGS_REPLY, l2_flags_reply) \
2085 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2086 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2087 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2088 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2089 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2090 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2091 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2092 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2093 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2094 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2095 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2096 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2097 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2098 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2099 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2100 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2101 sw_interface_set_unnumbered_reply) \
2102 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2103 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2104 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2105 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2106 sw_interface_ip6_enable_disable_reply) \
2107 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2108 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2109 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2110 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2111 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2112 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2113 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2114 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2115 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2116 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2117 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2118 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2119 _(SHOW_VERSION_REPLY, show_version_reply) \
2120 _(SHOW_THREADS_REPLY, show_threads_reply) \
2121 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2122 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2123 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2124 _(L2_MACS_EVENT, l2_macs_event) \
2125 _(IP_ADDRESS_DETAILS, ip_address_details) \
2126 _(IP_DETAILS, ip_details) \
2127 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2128 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2129 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
2130 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
2131 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2132 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2133 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2134 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2135 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
2136 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
2137 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2138 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2139 _(AF_PACKET_DETAILS, af_packet_details) \
2140 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
2141 _(MPLS_TABLE_DETAILS, mpls_table_details) \
2142 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
2143 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
2144 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
2145 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
2146 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
2147 ip_source_and_port_range_check_add_del_reply) \
2148 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
2149 ip_source_and_port_range_check_interface_add_del_reply) \
2150 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
2151 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
2152 _(SET_PUNT_REPLY, set_punt_reply) \
2153 _(IP_TABLE_DETAILS, ip_table_details) \
2154 _(IP_ROUTE_DETAILS, ip_route_details) \
2155 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
2156 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
2157 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
2158 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
2159 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
2160 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
2161 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
2162 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
2163 _(SESSION_RULES_DETAILS, session_rules_details) \
2164 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
2166 #define foreach_standalone_reply_msg \
2167 _(SW_INTERFACE_EVENT, sw_interface_event)
2175 #define STR_VTR_OP_CASE(op) \
2176 case L2_VTR_ ## op: \
2180 str_vtr_op (u32 vtr_op)
2184 STR_VTR_OP_CASE (DISABLED);
2185 STR_VTR_OP_CASE (PUSH_1);
2186 STR_VTR_OP_CASE (PUSH_2);
2187 STR_VTR_OP_CASE (POP_1);
2188 STR_VTR_OP_CASE (POP_2);
2189 STR_VTR_OP_CASE (TRANSLATE_1_1);
2190 STR_VTR_OP_CASE (TRANSLATE_1_2);
2191 STR_VTR_OP_CASE (TRANSLATE_2_1);
2192 STR_VTR_OP_CASE (TRANSLATE_2_2);
2199 dump_sub_interface_table (vat_main_t * vam)
2201 const sw_interface_subif_t *sub = NULL;
2203 if (vam->json_output)
2206 ("JSON output supported only for VPE API calls and dump_stats_table");
2211 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
2212 "Interface", "sw_if_index",
2213 "sub id", "dot1ad", "tags", "outer id",
2214 "inner id", "exact", "default", "outer any", "inner any");
2216 vec_foreach (sub, vam->sw_if_subif_table)
2219 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
2220 sub->interface_name,
2222 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2223 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2224 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2225 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2226 if (sub->vtr_op != L2_VTR_DISABLED)
2229 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2230 "tag1: %d tag2: %d ]",
2231 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
2232 sub->vtr_tag1, sub->vtr_tag2);
2240 name_sort_cmp (void *a1, void *a2)
2242 name_sort_t *n1 = a1;
2243 name_sort_t *n2 = a2;
2245 return strcmp ((char *) n1->name, (char *) n2->name);
2249 dump_interface_table (vat_main_t * vam)
2252 name_sort_t *nses = 0, *ns;
2254 if (vam->json_output)
2257 ("JSON output supported only for VPE API calls and dump_stats_table");
2262 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2264 vec_add2 (nses, ns, 1);
2265 ns->name = (u8 *)(p->key);
2266 ns->value = (u32) p->value[0];
2270 vec_sort_with_function (nses, name_sort_cmp);
2272 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
2273 vec_foreach (ns, nses)
2275 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
2282 dump_ip_table (vat_main_t * vam, int is_ipv6)
2284 const ip_details_t *det = NULL;
2285 const ip_address_details_t *address = NULL;
2288 print (vam->ofp, "%-12s", "sw_if_index");
2290 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
2297 print (vam->ofp, "%-12d", i);
2298 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
2303 vec_foreach (address, det->addr)
2307 is_ipv6 ? format_ip6_address : format_ip4_address,
2308 address->ip, address->prefix_length);
2316 dump_ipv4_table (vat_main_t * vam)
2318 if (vam->json_output)
2321 ("JSON output supported only for VPE API calls and dump_stats_table");
2325 return dump_ip_table (vam, 0);
2329 dump_ipv6_table (vat_main_t * vam)
2331 if (vam->json_output)
2334 ("JSON output supported only for VPE API calls and dump_stats_table");
2338 return dump_ip_table (vam, 1);
2342 * Pass CLI buffers directly in the CLI_INBAND API message,
2343 * instead of an additional shared memory area.
2346 exec_inband (vat_main_t * vam)
2348 vl_api_cli_inband_t *mp;
2349 unformat_input_t *i = vam->input;
2352 if (vec_len (i->buffer) == 0)
2355 if (vam->exec_mode == 0 && unformat (i, "mode"))
2360 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
2367 * In order for the CLI command to work, it
2368 * must be a vector ending in \n, not a C-string ending
2371 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
2372 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
2376 /* json responses may or may not include a useful reply... */
2377 if (vec_len (vam->cmd_reply))
2378 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
2383 exec (vat_main_t * vam)
2385 return exec_inband (vam);
2389 api_create_loopback (vat_main_t * vam)
2391 unformat_input_t *i = vam->input;
2392 vl_api_create_loopback_t *mp;
2393 vl_api_create_loopback_instance_t *mp_lbi;
2396 u8 is_specified = 0;
2397 u32 user_instance = 0;
2400 clib_memset (mac_address, 0, sizeof (mac_address));
2402 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2404 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2406 if (unformat (i, "instance %d", &user_instance))
2414 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
2415 mp_lbi->is_specified = is_specified;
2417 mp_lbi->user_instance = htonl (user_instance);
2419 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
2424 /* Construct the API message */
2425 M (CREATE_LOOPBACK, mp);
2427 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2436 api_delete_loopback (vat_main_t * vam)
2438 unformat_input_t *i = vam->input;
2439 vl_api_delete_loopback_t *mp;
2440 u32 sw_if_index = ~0;
2443 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2445 if (unformat (i, "sw_if_index %d", &sw_if_index))
2451 if (sw_if_index == ~0)
2453 errmsg ("missing sw_if_index");
2457 /* Construct the API message */
2458 M (DELETE_LOOPBACK, mp);
2459 mp->sw_if_index = ntohl (sw_if_index);
2467 api_want_interface_events (vat_main_t * vam)
2469 unformat_input_t *i = vam->input;
2470 vl_api_want_interface_events_t *mp;
2474 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2476 if (unformat (i, "enable"))
2478 else if (unformat (i, "disable"))
2486 errmsg ("missing enable|disable");
2490 M (WANT_INTERFACE_EVENTS, mp);
2491 mp->enable_disable = enable;
2493 vam->interface_event_display = enable;
2501 /* Note: non-static, called once to set up the initial intfc table */
2503 api_sw_interface_dump (vat_main_t * vam)
2505 vl_api_sw_interface_dump_t *mp;
2506 vl_api_control_ping_t *mp_ping;
2508 name_sort_t *nses = 0, *ns;
2509 sw_interface_subif_t *sub = NULL;
2512 /* Toss the old name table */
2514 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2516 vec_add2 (nses, ns, 1);
2517 ns->name = (u8 *)(p->key);
2518 ns->value = (u32) p->value[0];
2522 hash_free (vam->sw_if_index_by_interface_name);
2524 vec_foreach (ns, nses) vec_free (ns->name);
2528 vec_foreach (sub, vam->sw_if_subif_table)
2530 vec_free (sub->interface_name);
2532 vec_free (vam->sw_if_subif_table);
2534 /* recreate the interface name hash table */
2535 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
2538 * Ask for all interface names. Otherwise, the epic catalog of
2539 * name filters becomes ridiculously long, and vat ends up needing
2540 * to be taught about new interface types.
2542 M (SW_INTERFACE_DUMP, mp);
2545 /* Use a control ping for synchronization */
2546 MPING (CONTROL_PING, mp_ping);
2554 api_sw_interface_set_flags (vat_main_t * vam)
2556 unformat_input_t *i = vam->input;
2557 vl_api_sw_interface_set_flags_t *mp;
2559 u8 sw_if_index_set = 0;
2563 /* Parse args required to build the message */
2564 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2566 if (unformat (i, "admin-up"))
2568 else if (unformat (i, "admin-down"))
2571 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2572 sw_if_index_set = 1;
2573 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2574 sw_if_index_set = 1;
2579 if (sw_if_index_set == 0)
2581 errmsg ("missing interface name or sw_if_index");
2585 /* Construct the API message */
2586 M (SW_INTERFACE_SET_FLAGS, mp);
2587 mp->sw_if_index = ntohl (sw_if_index);
2588 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
2593 /* Wait for a reply, return the good/bad news... */
2599 api_sw_interface_set_rx_mode (vat_main_t * vam)
2601 unformat_input_t *i = vam->input;
2602 vl_api_sw_interface_set_rx_mode_t *mp;
2604 u8 sw_if_index_set = 0;
2606 u8 queue_id_valid = 0;
2608 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
2610 /* Parse args required to build the message */
2611 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2613 if (unformat (i, "queue %d", &queue_id))
2615 else if (unformat (i, "polling"))
2616 mode = VNET_HW_IF_RX_MODE_POLLING;
2617 else if (unformat (i, "interrupt"))
2618 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
2619 else if (unformat (i, "adaptive"))
2620 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
2622 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2623 sw_if_index_set = 1;
2624 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2625 sw_if_index_set = 1;
2630 if (sw_if_index_set == 0)
2632 errmsg ("missing interface name or sw_if_index");
2635 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
2637 errmsg ("missing rx-mode");
2641 /* Construct the API message */
2642 M (SW_INTERFACE_SET_RX_MODE, mp);
2643 mp->sw_if_index = ntohl (sw_if_index);
2644 mp->mode = (vl_api_rx_mode_t) mode;
2645 mp->queue_id_valid = queue_id_valid;
2646 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
2651 /* Wait for a reply, return the good/bad news... */
2657 api_sw_interface_set_rx_placement (vat_main_t * vam)
2659 unformat_input_t *i = vam->input;
2660 vl_api_sw_interface_set_rx_placement_t *mp;
2662 u8 sw_if_index_set = 0;
2665 u32 queue_id, thread_index;
2667 /* Parse args required to build the message */
2668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2670 if (unformat (i, "queue %d", &queue_id))
2672 else if (unformat (i, "main"))
2674 else if (unformat (i, "worker %d", &thread_index))
2677 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2678 sw_if_index_set = 1;
2679 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2680 sw_if_index_set = 1;
2685 if (sw_if_index_set == 0)
2687 errmsg ("missing interface name or sw_if_index");
2693 /* Construct the API message */
2694 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
2695 mp->sw_if_index = ntohl (sw_if_index);
2696 mp->worker_id = ntohl (thread_index);
2697 mp->queue_id = ntohl (queue_id);
2698 mp->is_main = is_main;
2702 /* Wait for a reply, return the good/bad news... */
2707 static void vl_api_sw_interface_rx_placement_details_t_handler
2708 (vl_api_sw_interface_rx_placement_details_t * mp)
2710 vat_main_t *vam = &vat_main;
2711 u32 worker_id = ntohl (mp->worker_id);
2714 "\n%-11d %-11s %-6d %-5d %-9s",
2715 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
2716 worker_id, ntohl (mp->queue_id),
2718 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
2721 static void vl_api_sw_interface_rx_placement_details_t_handler_json
2722 (vl_api_sw_interface_rx_placement_details_t * mp)
2724 vat_main_t *vam = &vat_main;
2725 vat_json_node_t *node = NULL;
2727 if (VAT_JSON_ARRAY != vam->json_tree.type)
2729 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2730 vat_json_init_array (&vam->json_tree);
2732 node = vat_json_array_add (&vam->json_tree);
2734 vat_json_init_object (node);
2735 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2736 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
2737 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
2738 vat_json_object_add_uint (node, "mode", mp->mode);
2742 api_sw_interface_rx_placement_dump (vat_main_t * vam)
2744 unformat_input_t *i = vam->input;
2745 vl_api_sw_interface_rx_placement_dump_t *mp;
2746 vl_api_control_ping_t *mp_ping;
2749 u8 sw_if_index_set = 0;
2751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2753 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2762 "\n%-11s %-11s %-6s %-5s %-4s",
2763 "sw_if_index", "main/worker", "thread", "queue", "mode");
2765 /* Dump Interface rx placement */
2766 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
2768 if (sw_if_index_set)
2769 mp->sw_if_index = htonl (sw_if_index);
2771 mp->sw_if_index = ~0;
2775 /* Use a control ping for synchronization */
2776 MPING (CONTROL_PING, mp_ping);
2784 api_sw_interface_clear_stats (vat_main_t * vam)
2786 unformat_input_t *i = vam->input;
2787 vl_api_sw_interface_clear_stats_t *mp;
2789 u8 sw_if_index_set = 0;
2792 /* Parse args required to build the message */
2793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2795 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2796 sw_if_index_set = 1;
2797 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2798 sw_if_index_set = 1;
2803 /* Construct the API message */
2804 M (SW_INTERFACE_CLEAR_STATS, mp);
2806 if (sw_if_index_set == 1)
2807 mp->sw_if_index = ntohl (sw_if_index);
2809 mp->sw_if_index = ~0;
2814 /* Wait for a reply, return the good/bad news... */
2820 api_sw_interface_add_del_address (vat_main_t * vam)
2822 unformat_input_t *i = vam->input;
2823 vl_api_sw_interface_add_del_address_t *mp;
2825 u8 sw_if_index_set = 0;
2826 u8 is_add = 1, del_all = 0;
2827 u32 address_length = 0;
2828 u8 v4_address_set = 0;
2829 u8 v6_address_set = 0;
2830 ip4_address_t v4address;
2831 ip6_address_t v6address;
2834 /* Parse args required to build the message */
2835 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2837 if (unformat (i, "del-all"))
2839 else if (unformat (i, "del"))
2842 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2843 sw_if_index_set = 1;
2844 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2845 sw_if_index_set = 1;
2846 else if (unformat (i, "%U/%d",
2847 unformat_ip4_address, &v4address, &address_length))
2849 else if (unformat (i, "%U/%d",
2850 unformat_ip6_address, &v6address, &address_length))
2856 if (sw_if_index_set == 0)
2858 errmsg ("missing interface name or sw_if_index");
2861 if (v4_address_set && v6_address_set)
2863 errmsg ("both v4 and v6 addresses set");
2866 if (!v4_address_set && !v6_address_set && !del_all)
2868 errmsg ("no addresses set");
2872 /* Construct the API message */
2873 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
2875 mp->sw_if_index = ntohl (sw_if_index);
2876 mp->is_add = is_add;
2877 mp->del_all = del_all;
2880 mp->prefix.address.af = ADDRESS_IP6;
2881 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
2885 mp->prefix.address.af = ADDRESS_IP4;
2886 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
2888 mp->prefix.len = address_length;
2893 /* Wait for a reply, return good/bad news */
2899 api_sw_interface_set_mpls_enable (vat_main_t * vam)
2901 unformat_input_t *i = vam->input;
2902 vl_api_sw_interface_set_mpls_enable_t *mp;
2904 u8 sw_if_index_set = 0;
2908 /* Parse args required to build the message */
2909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2911 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2912 sw_if_index_set = 1;
2913 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2914 sw_if_index_set = 1;
2915 else if (unformat (i, "disable"))
2917 else if (unformat (i, "dis"))
2923 if (sw_if_index_set == 0)
2925 errmsg ("missing interface name or sw_if_index");
2929 /* Construct the API message */
2930 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
2932 mp->sw_if_index = ntohl (sw_if_index);
2933 mp->enable = enable;
2938 /* Wait for a reply... */
2944 api_sw_interface_set_table (vat_main_t * vam)
2946 unformat_input_t *i = vam->input;
2947 vl_api_sw_interface_set_table_t *mp;
2948 u32 sw_if_index, vrf_id = 0;
2949 u8 sw_if_index_set = 0;
2953 /* Parse args required to build the message */
2954 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2956 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2957 sw_if_index_set = 1;
2958 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2959 sw_if_index_set = 1;
2960 else if (unformat (i, "vrf %d", &vrf_id))
2962 else if (unformat (i, "ipv6"))
2968 if (sw_if_index_set == 0)
2970 errmsg ("missing interface name or sw_if_index");
2974 /* Construct the API message */
2975 M (SW_INTERFACE_SET_TABLE, mp);
2977 mp->sw_if_index = ntohl (sw_if_index);
2978 mp->is_ipv6 = is_ipv6;
2979 mp->vrf_id = ntohl (vrf_id);
2984 /* Wait for a reply... */
2989 static void vl_api_sw_interface_get_table_reply_t_handler
2990 (vl_api_sw_interface_get_table_reply_t * mp)
2992 vat_main_t *vam = &vat_main;
2994 print (vam->ofp, "%d", ntohl (mp->vrf_id));
2996 vam->retval = ntohl (mp->retval);
2997 vam->result_ready = 1;
3001 static void vl_api_sw_interface_get_table_reply_t_handler_json
3002 (vl_api_sw_interface_get_table_reply_t * mp)
3004 vat_main_t *vam = &vat_main;
3005 vat_json_node_t node;
3007 vat_json_init_object (&node);
3008 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3009 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3011 vat_json_print (vam->ofp, &node);
3012 vat_json_free (&node);
3014 vam->retval = ntohl (mp->retval);
3015 vam->result_ready = 1;
3019 api_sw_interface_get_table (vat_main_t * vam)
3021 unformat_input_t *i = vam->input;
3022 vl_api_sw_interface_get_table_t *mp;
3024 u8 sw_if_index_set = 0;
3028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3030 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3031 sw_if_index_set = 1;
3032 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3033 sw_if_index_set = 1;
3034 else if (unformat (i, "ipv6"))
3040 if (sw_if_index_set == 0)
3042 errmsg ("missing interface name or sw_if_index");
3046 M (SW_INTERFACE_GET_TABLE, mp);
3047 mp->sw_if_index = htonl (sw_if_index);
3048 mp->is_ipv6 = is_ipv6;
3056 api_sw_interface_set_vpath (vat_main_t * vam)
3058 unformat_input_t *i = vam->input;
3059 vl_api_sw_interface_set_vpath_t *mp;
3060 u32 sw_if_index = 0;
3061 u8 sw_if_index_set = 0;
3065 /* Parse args required to build the message */
3066 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3068 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3069 sw_if_index_set = 1;
3070 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3071 sw_if_index_set = 1;
3072 else if (unformat (i, "enable"))
3074 else if (unformat (i, "disable"))
3080 if (sw_if_index_set == 0)
3082 errmsg ("missing interface name or sw_if_index");
3086 /* Construct the API message */
3087 M (SW_INTERFACE_SET_VPATH, mp);
3089 mp->sw_if_index = ntohl (sw_if_index);
3090 mp->enable = is_enable;
3095 /* Wait for a reply... */
3101 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3103 unformat_input_t *i = vam->input;
3104 vl_api_sw_interface_set_l2_xconnect_t *mp;
3106 u8 rx_sw_if_index_set = 0;
3108 u8 tx_sw_if_index_set = 0;
3112 /* Parse args required to build the message */
3113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3115 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3116 rx_sw_if_index_set = 1;
3117 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3118 tx_sw_if_index_set = 1;
3119 else if (unformat (i, "rx"))
3121 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3123 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3125 rx_sw_if_index_set = 1;
3130 else if (unformat (i, "tx"))
3132 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3134 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3136 tx_sw_if_index_set = 1;
3141 else if (unformat (i, "enable"))
3143 else if (unformat (i, "disable"))
3149 if (rx_sw_if_index_set == 0)
3151 errmsg ("missing rx interface name or rx_sw_if_index");
3155 if (enable && (tx_sw_if_index_set == 0))
3157 errmsg ("missing tx interface name or tx_sw_if_index");
3161 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
3163 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3164 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
3165 mp->enable = enable;
3173 api_sw_interface_set_l2_bridge (vat_main_t * vam)
3175 unformat_input_t *i = vam->input;
3176 vl_api_sw_interface_set_l2_bridge_t *mp;
3177 vl_api_l2_port_type_t port_type;
3179 u8 rx_sw_if_index_set = 0;
3186 port_type = L2_API_PORT_TYPE_NORMAL;
3188 /* Parse args required to build the message */
3189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3191 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3192 rx_sw_if_index_set = 1;
3193 else if (unformat (i, "bd_id %d", &bd_id))
3197 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
3198 rx_sw_if_index_set = 1;
3199 else if (unformat (i, "shg %d", &shg))
3201 else if (unformat (i, "bvi"))
3202 port_type = L2_API_PORT_TYPE_BVI;
3203 else if (unformat (i, "uu-fwd"))
3204 port_type = L2_API_PORT_TYPE_UU_FWD;
3205 else if (unformat (i, "enable"))
3207 else if (unformat (i, "disable"))
3213 if (rx_sw_if_index_set == 0)
3215 errmsg ("missing rx interface name or sw_if_index");
3219 if (enable && (bd_id_set == 0))
3221 errmsg ("missing bridge domain");
3225 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
3227 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3228 mp->bd_id = ntohl (bd_id);
3230 mp->port_type = ntohl (port_type);
3231 mp->enable = enable;
3239 api_bridge_domain_dump (vat_main_t * vam)
3241 unformat_input_t *i = vam->input;
3242 vl_api_bridge_domain_dump_t *mp;
3243 vl_api_control_ping_t *mp_ping;
3247 /* Parse args required to build the message */
3248 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3250 if (unformat (i, "bd_id %d", &bd_id))
3256 M (BRIDGE_DOMAIN_DUMP, mp);
3257 mp->bd_id = ntohl (bd_id);
3260 /* Use a control ping for synchronization */
3261 MPING (CONTROL_PING, mp_ping);
3269 api_bridge_domain_add_del (vat_main_t * vam)
3271 unformat_input_t *i = vam->input;
3272 vl_api_bridge_domain_add_del_t *mp;
3275 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3280 /* Parse args required to build the message */
3281 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3283 if (unformat (i, "bd_id %d", &bd_id))
3285 else if (unformat (i, "flood %d", &flood))
3287 else if (unformat (i, "uu-flood %d", &uu_flood))
3289 else if (unformat (i, "forward %d", &forward))
3291 else if (unformat (i, "learn %d", &learn))
3293 else if (unformat (i, "arp-term %d", &arp_term))
3295 else if (unformat (i, "mac-age %d", &mac_age))
3297 else if (unformat (i, "bd-tag %s", &bd_tag))
3299 else if (unformat (i, "del"))
3302 flood = uu_flood = forward = learn = 0;
3310 errmsg ("missing bridge domain");
3317 errmsg ("mac age must be less than 256 ");
3322 if ((bd_tag) && (vec_len (bd_tag) > 63))
3324 errmsg ("bd-tag cannot be longer than 63");
3329 M (BRIDGE_DOMAIN_ADD_DEL, mp);
3331 mp->bd_id = ntohl (bd_id);
3333 mp->uu_flood = uu_flood;
3334 mp->forward = forward;
3336 mp->arp_term = arp_term;
3337 mp->is_add = is_add;
3338 mp->mac_age = (u8) mac_age;
3341 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
3342 mp->bd_tag[vec_len (bd_tag)] = 0;
3353 api_l2fib_flush_bd (vat_main_t * vam)
3355 unformat_input_t *i = vam->input;
3356 vl_api_l2fib_flush_bd_t *mp;
3360 /* Parse args required to build the message */
3361 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3363 if (unformat (i, "bd_id %d", &bd_id));
3370 errmsg ("missing bridge domain");
3374 M (L2FIB_FLUSH_BD, mp);
3376 mp->bd_id = htonl (bd_id);
3384 api_l2fib_flush_int (vat_main_t * vam)
3386 unformat_input_t *i = vam->input;
3387 vl_api_l2fib_flush_int_t *mp;
3388 u32 sw_if_index = ~0;
3391 /* Parse args required to build the message */
3392 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3394 if (unformat (i, "sw_if_index %d", &sw_if_index));
3396 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
3401 if (sw_if_index == ~0)
3403 errmsg ("missing interface name or sw_if_index");
3407 M (L2FIB_FLUSH_INT, mp);
3409 mp->sw_if_index = ntohl (sw_if_index);
3417 api_l2fib_add_del (vat_main_t * vam)
3419 unformat_input_t *i = vam->input;
3420 vl_api_l2fib_add_del_t *mp;
3426 u32 sw_if_index = 0;
3427 u8 sw_if_index_set = 0;
3436 /* Parse args required to build the message */
3437 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3439 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
3441 else if (unformat (i, "bd_id %d", &bd_id))
3443 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3444 sw_if_index_set = 1;
3445 else if (unformat (i, "sw_if"))
3447 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3450 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3451 sw_if_index_set = 1;
3456 else if (unformat (i, "static"))
3458 else if (unformat (i, "filter"))
3463 else if (unformat (i, "bvi"))
3468 else if (unformat (i, "del"))
3470 else if (unformat (i, "count %d", &count))
3478 errmsg ("missing mac address");
3484 errmsg ("missing bridge domain");
3488 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
3490 errmsg ("missing interface name or sw_if_index");
3496 /* Turn on async mode */
3497 vam->async_mode = 1;
3498 vam->async_errors = 0;
3499 before = vat_time_now (vam);
3502 for (j = 0; j < count; j++)
3504 M (L2FIB_ADD_DEL, mp);
3506 clib_memcpy (mp->mac, mac, 6);
3507 mp->bd_id = ntohl (bd_id);
3508 mp->is_add = is_add;
3509 mp->sw_if_index = ntohl (sw_if_index);
3513 mp->static_mac = static_mac;
3514 mp->filter_mac = filter_mac;
3515 mp->bvi_mac = bvi_mac;
3517 increment_mac_address (mac);
3524 vl_api_control_ping_t *mp_ping;
3527 /* Shut off async mode */
3528 vam->async_mode = 0;
3530 MPING (CONTROL_PING, mp_ping);
3533 timeout = vat_time_now (vam) + 1.0;
3534 while (vat_time_now (vam) < timeout)
3535 if (vam->result_ready == 1)
3540 if (vam->retval == -99)
3543 if (vam->async_errors > 0)
3545 errmsg ("%d asynchronous errors", vam->async_errors);
3548 vam->async_errors = 0;
3549 after = vat_time_now (vam);
3551 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
3552 count, after - before, count / (after - before));
3558 /* Wait for a reply... */
3562 /* Return the good/bad news */
3563 return (vam->retval);
3567 api_bridge_domain_set_mac_age (vat_main_t * vam)
3569 unformat_input_t *i = vam->input;
3570 vl_api_bridge_domain_set_mac_age_t *mp;
3575 /* Parse args required to build the message */
3576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3578 if (unformat (i, "bd_id %d", &bd_id));
3579 else if (unformat (i, "mac-age %d", &mac_age));
3586 errmsg ("missing bridge domain");
3592 errmsg ("mac age must be less than 256 ");
3596 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
3598 mp->bd_id = htonl (bd_id);
3599 mp->mac_age = (u8) mac_age;
3607 api_l2_flags (vat_main_t * vam)
3609 unformat_input_t *i = vam->input;
3610 vl_api_l2_flags_t *mp;
3613 u8 sw_if_index_set = 0;
3617 /* Parse args required to build the message */
3618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3620 if (unformat (i, "sw_if_index %d", &sw_if_index))
3621 sw_if_index_set = 1;
3622 else if (unformat (i, "sw_if"))
3624 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3627 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3628 sw_if_index_set = 1;
3633 else if (unformat (i, "learn"))
3635 else if (unformat (i, "forward"))
3637 else if (unformat (i, "flood"))
3639 else if (unformat (i, "uu-flood"))
3640 flags |= L2_UU_FLOOD;
3641 else if (unformat (i, "arp-term"))
3642 flags |= L2_ARP_TERM;
3643 else if (unformat (i, "off"))
3645 else if (unformat (i, "disable"))
3651 if (sw_if_index_set == 0)
3653 errmsg ("missing interface name or sw_if_index");
3659 mp->sw_if_index = ntohl (sw_if_index);
3660 mp->feature_bitmap = ntohl (flags);
3661 mp->is_set = is_set;
3669 api_bridge_flags (vat_main_t * vam)
3671 unformat_input_t *i = vam->input;
3672 vl_api_bridge_flags_t *mp;
3676 bd_flags_t flags = 0;
3679 /* Parse args required to build the message */
3680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3682 if (unformat (i, "bd_id %d", &bd_id))
3684 else if (unformat (i, "learn"))
3685 flags |= BRIDGE_API_FLAG_LEARN;
3686 else if (unformat (i, "forward"))
3687 flags |= BRIDGE_API_FLAG_FWD;
3688 else if (unformat (i, "flood"))
3689 flags |= BRIDGE_API_FLAG_FLOOD;
3690 else if (unformat (i, "uu-flood"))
3691 flags |= BRIDGE_API_FLAG_UU_FLOOD;
3692 else if (unformat (i, "arp-term"))
3693 flags |= BRIDGE_API_FLAG_ARP_TERM;
3694 else if (unformat (i, "off"))
3696 else if (unformat (i, "disable"))
3704 errmsg ("missing bridge domain");
3708 M (BRIDGE_FLAGS, mp);
3710 mp->bd_id = ntohl (bd_id);
3711 mp->flags = ntohl (flags);
3712 mp->is_set = is_set;
3720 api_bd_ip_mac_add_del (vat_main_t * vam)
3722 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
3723 vl_api_mac_address_t mac = { 0 };
3724 unformat_input_t *i = vam->input;
3725 vl_api_bd_ip_mac_add_del_t *mp;
3734 /* Parse args required to build the message */
3735 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3737 if (unformat (i, "bd_id %d", &bd_id))
3741 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
3745 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
3749 else if (unformat (i, "del"))
3757 errmsg ("missing bridge domain");
3760 else if (ip_set == 0)
3762 errmsg ("missing IP address");
3765 else if (mac_set == 0)
3767 errmsg ("missing MAC address");
3771 M (BD_IP_MAC_ADD_DEL, mp);
3773 mp->entry.bd_id = ntohl (bd_id);
3774 mp->is_add = is_add;
3776 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
3777 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
3785 api_bd_ip_mac_flush (vat_main_t * vam)
3787 unformat_input_t *i = vam->input;
3788 vl_api_bd_ip_mac_flush_t *mp;
3793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3795 if (unformat (i, "bd_id %d", &bd_id))
3805 errmsg ("missing bridge domain");
3809 M (BD_IP_MAC_FLUSH, mp);
3811 mp->bd_id = ntohl (bd_id);
3818 static void vl_api_bd_ip_mac_details_t_handler
3819 (vl_api_bd_ip_mac_details_t * mp)
3821 vat_main_t *vam = &vat_main;
3825 ntohl (mp->entry.bd_id),
3826 format_vl_api_mac_address, mp->entry.mac,
3827 format_vl_api_address, &mp->entry.ip);
3830 static void vl_api_bd_ip_mac_details_t_handler_json
3831 (vl_api_bd_ip_mac_details_t * mp)
3833 vat_main_t *vam = &vat_main;
3834 vat_json_node_t *node = NULL;
3836 if (VAT_JSON_ARRAY != vam->json_tree.type)
3838 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3839 vat_json_init_array (&vam->json_tree);
3841 node = vat_json_array_add (&vam->json_tree);
3843 vat_json_init_object (node);
3844 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
3845 vat_json_object_add_string_copy (node, "mac_address",
3846 format (0, "%U", format_vl_api_mac_address,
3850 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
3851 vat_json_object_add_string_copy (node, "ip_address", ip);
3856 api_bd_ip_mac_dump (vat_main_t * vam)
3858 unformat_input_t *i = vam->input;
3859 vl_api_bd_ip_mac_dump_t *mp;
3860 vl_api_control_ping_t *mp_ping;
3865 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3867 if (unformat (i, "bd_id %d", &bd_id))
3876 "\n%-5s %-7s %-20s %-30s",
3877 "bd_id", "is_ipv6", "mac_address", "ip_address");
3879 /* Dump Bridge Domain Ip to Mac entries */
3880 M (BD_IP_MAC_DUMP, mp);
3883 mp->bd_id = htonl (bd_id);
3889 /* Use a control ping for synchronization */
3890 MPING (CONTROL_PING, mp_ping);
3898 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
3900 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
3903 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
3906 addr->domain = x[0];
3909 addr->function = x[3];
3915 api_virtio_pci_create_v2 (vat_main_t * vam)
3917 unformat_input_t *i = vam->input;
3918 vl_api_virtio_pci_create_v2_t *mp;
3922 u64 features = (u64) ~ (0ULL);
3923 u32 virtio_flags = 0;
3926 clib_memset (mac_address, 0, sizeof (mac_address));
3928 /* Parse args required to build the message */
3929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3931 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
3935 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
3937 else if (unformat (i, "features 0x%llx", &features))
3939 else if (unformat (i, "gso-enabled"))
3940 virtio_flags |= VIRTIO_API_FLAG_GSO;
3941 else if (unformat (i, "csum-offload-enabled"))
3942 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
3943 else if (unformat (i, "gro-coalesce"))
3944 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
3945 else if (unformat (i, "packed"))
3946 virtio_flags |= VIRTIO_API_FLAG_PACKED;
3947 else if (unformat (i, "in-order"))
3948 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
3949 else if (unformat (i, "buffering"))
3950 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
3957 errmsg ("pci address must be non zero. ");
3961 /* Construct the API message */
3962 M (VIRTIO_PCI_CREATE_V2, mp);
3964 mp->use_random_mac = random_mac;
3966 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
3967 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
3968 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
3969 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
3971 mp->features = clib_host_to_net_u64 (features);
3972 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
3974 if (random_mac == 0)
3975 clib_memcpy (mp->mac_address, mac_address, 6);
3980 /* Wait for a reply... */
3986 api_virtio_pci_delete (vat_main_t * vam)
3988 unformat_input_t *i = vam->input;
3989 vl_api_virtio_pci_delete_t *mp;
3990 u32 sw_if_index = ~0;
3991 u8 sw_if_index_set = 0;
3994 /* Parse args required to build the message */
3995 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3997 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3998 sw_if_index_set = 1;
3999 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4000 sw_if_index_set = 1;
4005 if (sw_if_index_set == 0)
4007 errmsg ("missing vpp interface name. ");
4011 /* Construct the API message */
4012 M (VIRTIO_PCI_DELETE, mp);
4014 mp->sw_if_index = htonl (sw_if_index);
4019 /* Wait for a reply... */
4025 api_ip_table_add_del (vat_main_t * vam)
4027 unformat_input_t *i = vam->input;
4028 vl_api_ip_table_add_del_t *mp;
4034 /* Parse args required to build the message */
4035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4037 if (unformat (i, "ipv6"))
4039 else if (unformat (i, "del"))
4041 else if (unformat (i, "add"))
4043 else if (unformat (i, "table %d", &table_id))
4047 clib_warning ("parse error '%U'", format_unformat_error, i);
4054 errmsg ("missing table-ID");
4058 /* Construct the API message */
4059 M (IP_TABLE_ADD_DEL, mp);
4061 mp->table.table_id = ntohl (table_id);
4062 mp->table.is_ip6 = is_ipv6;
4063 mp->is_add = is_add;
4068 /* Wait for a reply... */
4075 unformat_fib_path (unformat_input_t * input, va_list * args)
4077 vat_main_t *vam = va_arg (*args, vat_main_t *);
4078 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
4079 u32 weight, preference;
4080 mpls_label_t out_label;
4082 clib_memset (path, 0, sizeof (*path));
4084 path->sw_if_index = ~0;
4088 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
4090 if (unformat (input, "%U %U",
4091 unformat_vl_api_ip4_address,
4092 &path->nh.address.ip4,
4093 api_unformat_sw_if_index, vam, &path->sw_if_index))
4095 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4097 else if (unformat (input, "%U %U",
4098 unformat_vl_api_ip6_address,
4099 &path->nh.address.ip6,
4100 api_unformat_sw_if_index, vam, &path->sw_if_index))
4102 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4104 else if (unformat (input, "weight %u", &weight))
4106 path->weight = weight;
4108 else if (unformat (input, "preference %u", &preference))
4110 path->preference = preference;
4112 else if (unformat (input, "%U next-hop-table %d",
4113 unformat_vl_api_ip4_address,
4114 &path->nh.address.ip4, &path->table_id))
4116 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4118 else if (unformat (input, "%U next-hop-table %d",
4119 unformat_vl_api_ip6_address,
4120 &path->nh.address.ip6, &path->table_id))
4122 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4124 else if (unformat (input, "%U",
4125 unformat_vl_api_ip4_address, &path->nh.address.ip4))
4128 * the recursive next-hops are by default in the default table
4131 path->sw_if_index = ~0;
4132 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4134 else if (unformat (input, "%U",
4135 unformat_vl_api_ip6_address, &path->nh.address.ip6))
4138 * the recursive next-hops are by default in the default table
4141 path->sw_if_index = ~0;
4142 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4144 else if (unformat (input, "resolve-via-host"))
4146 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
4148 else if (unformat (input, "resolve-via-attached"))
4150 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
4152 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
4154 path->type = FIB_API_PATH_TYPE_LOCAL;
4155 path->sw_if_index = ~0;
4156 path->proto = FIB_API_PATH_NH_PROTO_IP4;
4158 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
4160 path->type = FIB_API_PATH_TYPE_LOCAL;
4161 path->sw_if_index = ~0;
4162 path->proto = FIB_API_PATH_NH_PROTO_IP6;
4164 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
4166 else if (unformat (input, "via-label %d", &path->nh.via_label))
4168 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
4169 path->sw_if_index = ~0;
4171 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
4173 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
4174 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
4176 else if (unformat (input, "local"))
4178 path->type = FIB_API_PATH_TYPE_LOCAL;
4180 else if (unformat (input, "out-labels"))
4182 while (unformat (input, "%d", &out_label))
4184 path->label_stack[path->n_labels].label = out_label;
4185 path->label_stack[path->n_labels].is_uniform = 0;
4186 path->label_stack[path->n_labels].ttl = 64;
4190 else if (unformat (input, "via"))
4192 /* new path, back up and return */
4193 unformat_put_input (input);
4194 unformat_put_input (input);
4195 unformat_put_input (input);
4196 unformat_put_input (input);
4205 path->proto = ntohl (path->proto);
4206 path->type = ntohl (path->type);
4207 path->flags = ntohl (path->flags);
4208 path->table_id = ntohl (path->table_id);
4209 path->sw_if_index = ntohl (path->sw_if_index);
4215 api_ip_route_add_del (vat_main_t * vam)
4217 unformat_input_t *i = vam->input;
4218 vl_api_ip_route_add_del_t *mp;
4221 u8 is_multipath = 0;
4224 vl_api_prefix_t pfx = { };
4225 vl_api_fib_path_t paths[8];
4229 u32 random_add_del = 0;
4230 u32 *random_vector = 0;
4231 u32 random_seed = 0xdeaddabe;
4233 /* Parse args required to build the message */
4234 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4236 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
4238 else if (unformat (i, "del"))
4240 else if (unformat (i, "add"))
4242 else if (unformat (i, "vrf %d", &vrf_id))
4244 else if (unformat (i, "count %d", &count))
4246 else if (unformat (i, "random"))
4248 else if (unformat (i, "multipath"))
4250 else if (unformat (i, "seed %d", &random_seed))
4254 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4257 if (8 == path_count)
4259 errmsg ("max 8 paths");
4265 clib_warning ("parse error '%U'", format_unformat_error, i);
4272 errmsg ("specify a path; via ...");
4275 if (prefix_set == 0)
4277 errmsg ("missing prefix");
4281 /* Generate a pile of unique, random routes */
4284 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
4285 u32 this_random_address;
4288 random_hash = hash_create (count, sizeof (uword));
4290 hash_set (random_hash, i->as_u32, 1);
4291 for (j = 0; j <= count; j++)
4295 this_random_address = random_u32 (&random_seed);
4296 this_random_address =
4297 clib_host_to_net_u32 (this_random_address);
4299 while (hash_get (random_hash, this_random_address));
4300 vec_add1 (random_vector, this_random_address);
4301 hash_set (random_hash, this_random_address, 1);
4303 hash_free (random_hash);
4304 set_ip4_address (&pfx.address, random_vector[0]);
4309 /* Turn on async mode */
4310 vam->async_mode = 1;
4311 vam->async_errors = 0;
4312 before = vat_time_now (vam);
4315 for (j = 0; j < count; j++)
4317 /* Construct the API message */
4318 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4320 mp->is_add = is_add;
4321 mp->is_multipath = is_multipath;
4323 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
4324 mp->route.table_id = ntohl (vrf_id);
4325 mp->route.n_paths = path_count;
4327 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
4330 set_ip4_address (&pfx.address, random_vector[j + 1]);
4332 increment_address (&pfx.address);
4335 /* If we receive SIGTERM, stop now... */
4340 /* When testing multiple add/del ops, use a control-ping to sync */
4343 vl_api_control_ping_t *mp_ping;
4347 /* Shut off async mode */
4348 vam->async_mode = 0;
4350 MPING (CONTROL_PING, mp_ping);
4353 timeout = vat_time_now (vam) + 1.0;
4354 while (vat_time_now (vam) < timeout)
4355 if (vam->result_ready == 1)
4360 if (vam->retval == -99)
4363 if (vam->async_errors > 0)
4365 errmsg ("%d asynchronous errors", vam->async_errors);
4368 vam->async_errors = 0;
4369 after = vat_time_now (vam);
4371 /* slim chance, but we might have eaten SIGTERM on the first iteration */
4375 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4376 count, after - before, count / (after - before));
4382 /* Wait for a reply... */
4387 /* Return the good/bad news */
4388 return (vam->retval);
4392 api_ip_mroute_add_del (vat_main_t * vam)
4394 unformat_input_t *i = vam->input;
4395 u8 path_set = 0, prefix_set = 0, is_add = 1;
4396 vl_api_ip_mroute_add_del_t *mp;
4397 mfib_entry_flags_t eflags = 0;
4398 vl_api_mfib_path_t path;
4399 vl_api_mprefix_t pfx = { };
4403 /* Parse args required to build the message */
4404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4406 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
4409 pfx.grp_address_length = htons (pfx.grp_address_length);
4411 else if (unformat (i, "del"))
4413 else if (unformat (i, "add"))
4415 else if (unformat (i, "vrf %d", &vrf_id))
4417 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
4418 path.itf_flags = htonl (path.itf_flags);
4419 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
4421 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
4425 clib_warning ("parse error '%U'", format_unformat_error, i);
4430 if (prefix_set == 0)
4432 errmsg ("missing addresses\n");
4437 errmsg ("missing path\n");
4441 /* Construct the API message */
4442 M (IP_MROUTE_ADD_DEL, mp);
4444 mp->is_add = is_add;
4445 mp->is_multipath = 1;
4447 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
4448 mp->route.table_id = htonl (vrf_id);
4449 mp->route.n_paths = 1;
4450 mp->route.entry_flags = htonl (eflags);
4452 clib_memcpy (&mp->route.paths, &path, sizeof (path));
4456 /* Wait for a reply... */
4462 api_mpls_table_add_del (vat_main_t * vam)
4464 unformat_input_t *i = vam->input;
4465 vl_api_mpls_table_add_del_t *mp;
4470 /* Parse args required to build the message */
4471 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4473 if (unformat (i, "table %d", &table_id))
4475 else if (unformat (i, "del"))
4477 else if (unformat (i, "add"))
4481 clib_warning ("parse error '%U'", format_unformat_error, i);
4488 errmsg ("missing table-ID");
4492 /* Construct the API message */
4493 M (MPLS_TABLE_ADD_DEL, mp);
4495 mp->mt_table.mt_table_id = ntohl (table_id);
4496 mp->mt_is_add = is_add;
4501 /* Wait for a reply... */
4508 api_mpls_route_add_del (vat_main_t * vam)
4510 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
4511 mpls_label_t local_label = MPLS_LABEL_INVALID;
4512 unformat_input_t *i = vam->input;
4513 vl_api_mpls_route_add_del_t *mp;
4514 vl_api_fib_path_t paths[8];
4518 /* Parse args required to build the message */
4519 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4521 if (unformat (i, "%d", &local_label))
4523 else if (unformat (i, "eos"))
4525 else if (unformat (i, "non-eos"))
4527 else if (unformat (i, "del"))
4529 else if (unformat (i, "add"))
4531 else if (unformat (i, "multipath"))
4533 else if (unformat (i, "count %d", &count))
4537 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4540 if (8 == path_count)
4542 errmsg ("max 8 paths");
4548 clib_warning ("parse error '%U'", format_unformat_error, i);
4555 errmsg ("specify a path; via ...");
4559 if (MPLS_LABEL_INVALID == local_label)
4561 errmsg ("missing label");
4567 /* Turn on async mode */
4568 vam->async_mode = 1;
4569 vam->async_errors = 0;
4570 before = vat_time_now (vam);
4573 for (j = 0; j < count; j++)
4575 /* Construct the API message */
4576 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4578 mp->mr_is_add = is_add;
4579 mp->mr_is_multipath = is_multipath;
4581 mp->mr_route.mr_label = local_label;
4582 mp->mr_route.mr_eos = is_eos;
4583 mp->mr_route.mr_table_id = 0;
4584 mp->mr_route.mr_n_paths = path_count;
4586 clib_memcpy (&mp->mr_route.mr_paths, paths,
4587 sizeof (paths[0]) * path_count);
4593 /* If we receive SIGTERM, stop now... */
4598 /* When testing multiple add/del ops, use a control-ping to sync */
4601 vl_api_control_ping_t *mp_ping;
4605 /* Shut off async mode */
4606 vam->async_mode = 0;
4608 MPING (CONTROL_PING, mp_ping);
4611 timeout = vat_time_now (vam) + 1.0;
4612 while (vat_time_now (vam) < timeout)
4613 if (vam->result_ready == 1)
4618 if (vam->retval == -99)
4621 if (vam->async_errors > 0)
4623 errmsg ("%d asynchronous errors", vam->async_errors);
4626 vam->async_errors = 0;
4627 after = vat_time_now (vam);
4629 /* slim chance, but we might have eaten SIGTERM on the first iteration */
4633 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4634 count, after - before, count / (after - before));
4640 /* Wait for a reply... */
4645 /* Return the good/bad news */
4646 return (vam->retval);
4651 api_mpls_ip_bind_unbind (vat_main_t * vam)
4653 unformat_input_t *i = vam->input;
4654 vl_api_mpls_ip_bind_unbind_t *mp;
4655 u32 ip_table_id = 0;
4657 vl_api_prefix_t pfx;
4659 mpls_label_t local_label = MPLS_LABEL_INVALID;
4662 /* Parse args required to build the message */
4663 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4665 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
4667 else if (unformat (i, "%d", &local_label))
4669 else if (unformat (i, "table-id %d", &ip_table_id))
4671 else if (unformat (i, "unbind"))
4673 else if (unformat (i, "bind"))
4677 clib_warning ("parse error '%U'", format_unformat_error, i);
4684 errmsg ("IP prefix not set");
4688 if (MPLS_LABEL_INVALID == local_label)
4690 errmsg ("missing label");
4694 /* Construct the API message */
4695 M (MPLS_IP_BIND_UNBIND, mp);
4697 mp->mb_is_bind = is_bind;
4698 mp->mb_ip_table_id = ntohl (ip_table_id);
4699 mp->mb_mpls_table_id = 0;
4700 mp->mb_label = ntohl (local_label);
4701 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
4706 /* Wait for a reply... */
4713 api_mpls_tunnel_add_del (vat_main_t * vam)
4715 unformat_input_t *i = vam->input;
4716 vl_api_mpls_tunnel_add_del_t *mp;
4718 vl_api_fib_path_t paths[8];
4719 u32 sw_if_index = ~0;
4725 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4727 if (unformat (i, "add"))
4731 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
4733 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
4735 else if (unformat (i, "l2-only"))
4739 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
4742 if (8 == path_count)
4744 errmsg ("max 8 paths");
4750 clib_warning ("parse error '%U'", format_unformat_error, i);
4755 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
4757 mp->mt_is_add = is_add;
4758 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
4759 mp->mt_tunnel.mt_l2_only = l2_only;
4760 mp->mt_tunnel.mt_is_multicast = 0;
4761 mp->mt_tunnel.mt_n_paths = path_count;
4763 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
4764 sizeof (paths[0]) * path_count);
4772 api_sw_interface_set_unnumbered (vat_main_t * vam)
4774 unformat_input_t *i = vam->input;
4775 vl_api_sw_interface_set_unnumbered_t *mp;
4777 u32 unnum_sw_index = ~0;
4779 u8 sw_if_index_set = 0;
4782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4784 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4785 sw_if_index_set = 1;
4786 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4787 sw_if_index_set = 1;
4788 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4790 else if (unformat (i, "del"))
4794 clib_warning ("parse error '%U'", format_unformat_error, i);
4799 if (sw_if_index_set == 0)
4801 errmsg ("missing interface name or sw_if_index");
4805 M (SW_INTERFACE_SET_UNNUMBERED, mp);
4807 mp->sw_if_index = ntohl (sw_if_index);
4808 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
4809 mp->is_add = is_add;
4818 api_create_vlan_subif (vat_main_t * vam)
4820 unformat_input_t *i = vam->input;
4821 vl_api_create_vlan_subif_t *mp;
4823 u8 sw_if_index_set = 0;
4828 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4830 if (unformat (i, "sw_if_index %d", &sw_if_index))
4831 sw_if_index_set = 1;
4833 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4834 sw_if_index_set = 1;
4835 else if (unformat (i, "vlan %d", &vlan_id))
4839 clib_warning ("parse error '%U'", format_unformat_error, i);
4844 if (sw_if_index_set == 0)
4846 errmsg ("missing interface name or sw_if_index");
4850 if (vlan_id_set == 0)
4852 errmsg ("missing vlan_id");
4855 M (CREATE_VLAN_SUBIF, mp);
4857 mp->sw_if_index = ntohl (sw_if_index);
4858 mp->vlan_id = ntohl (vlan_id);
4865 #define foreach_create_subif_bit \
4872 _(outer_vlan_id_any) \
4873 _(inner_vlan_id_any)
4875 #define foreach_create_subif_flag \
4880 _(4, "exact_match") \
4881 _(5, "default_sub") \
4882 _(6, "outer_vlan_id_any") \
4883 _(7, "inner_vlan_id_any")
4886 api_create_subif (vat_main_t * vam)
4888 unformat_input_t *i = vam->input;
4889 vl_api_create_subif_t *mp;
4891 u8 sw_if_index_set = 0;
4894 u32 __attribute__ ((unused)) no_tags = 0;
4895 u32 __attribute__ ((unused)) one_tag = 0;
4896 u32 __attribute__ ((unused)) two_tags = 0;
4897 u32 __attribute__ ((unused)) dot1ad = 0;
4898 u32 __attribute__ ((unused)) exact_match = 0;
4899 u32 __attribute__ ((unused)) default_sub = 0;
4900 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
4901 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
4903 u16 outer_vlan_id = 0;
4904 u16 inner_vlan_id = 0;
4907 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4909 if (unformat (i, "sw_if_index %d", &sw_if_index))
4910 sw_if_index_set = 1;
4912 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4913 sw_if_index_set = 1;
4914 else if (unformat (i, "sub_id %d", &sub_id))
4916 else if (unformat (i, "outer_vlan_id %d", &tmp))
4917 outer_vlan_id = tmp;
4918 else if (unformat (i, "inner_vlan_id %d", &tmp))
4919 inner_vlan_id = tmp;
4921 #define _(a) else if (unformat (i, #a)) a = 1 ;
4922 foreach_create_subif_bit
4926 clib_warning ("parse error '%U'", format_unformat_error, i);
4931 if (sw_if_index_set == 0)
4933 errmsg ("missing interface name or sw_if_index");
4937 if (sub_id_set == 0)
4939 errmsg ("missing sub_id");
4942 M (CREATE_SUBIF, mp);
4944 mp->sw_if_index = ntohl (sw_if_index);
4945 mp->sub_id = ntohl (sub_id);
4947 #define _(a,b) mp->sub_if_flags |= (1 << a);
4948 foreach_create_subif_flag;
4951 mp->outer_vlan_id = ntohs (outer_vlan_id);
4952 mp->inner_vlan_id = ntohs (inner_vlan_id);
4960 api_ip_table_replace_begin (vat_main_t * vam)
4962 unformat_input_t *i = vam->input;
4963 vl_api_ip_table_replace_begin_t *mp;
4968 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4970 if (unformat (i, "table %d", &table_id))
4972 else if (unformat (i, "ipv6"))
4976 clib_warning ("parse error '%U'", format_unformat_error, i);
4981 M (IP_TABLE_REPLACE_BEGIN, mp);
4983 mp->table.table_id = ntohl (table_id);
4984 mp->table.is_ip6 = is_ipv6;
4992 api_ip_table_flush (vat_main_t * vam)
4994 unformat_input_t *i = vam->input;
4995 vl_api_ip_table_flush_t *mp;
5000 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5002 if (unformat (i, "table %d", &table_id))
5004 else if (unformat (i, "ipv6"))
5008 clib_warning ("parse error '%U'", format_unformat_error, i);
5013 M (IP_TABLE_FLUSH, mp);
5015 mp->table.table_id = ntohl (table_id);
5016 mp->table.is_ip6 = is_ipv6;
5024 api_ip_table_replace_end (vat_main_t * vam)
5026 unformat_input_t *i = vam->input;
5027 vl_api_ip_table_replace_end_t *mp;
5032 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5034 if (unformat (i, "table %d", &table_id))
5036 else if (unformat (i, "ipv6"))
5040 clib_warning ("parse error '%U'", format_unformat_error, i);
5045 M (IP_TABLE_REPLACE_END, mp);
5047 mp->table.table_id = ntohl (table_id);
5048 mp->table.is_ip6 = is_ipv6;
5056 api_set_ip_flow_hash (vat_main_t * vam)
5058 unformat_input_t *i = vam->input;
5059 vl_api_set_ip_flow_hash_t *mp;
5071 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5073 if (unformat (i, "vrf %d", &vrf_id))
5075 else if (unformat (i, "ipv6"))
5077 else if (unformat (i, "src"))
5079 else if (unformat (i, "dst"))
5081 else if (unformat (i, "sport"))
5083 else if (unformat (i, "dport"))
5085 else if (unformat (i, "proto"))
5087 else if (unformat (i, "reverse"))
5092 clib_warning ("parse error '%U'", format_unformat_error, i);
5097 if (vrf_id_set == 0)
5099 errmsg ("missing vrf id");
5103 M (SET_IP_FLOW_HASH, mp);
5109 mp->reverse = reverse;
5110 mp->vrf_id = ntohl (vrf_id);
5111 mp->is_ipv6 = is_ipv6;
5119 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5121 unformat_input_t *i = vam->input;
5122 vl_api_sw_interface_ip6_enable_disable_t *mp;
5124 u8 sw_if_index_set = 0;
5128 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5130 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5131 sw_if_index_set = 1;
5132 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5133 sw_if_index_set = 1;
5134 else if (unformat (i, "enable"))
5136 else if (unformat (i, "disable"))
5140 clib_warning ("parse error '%U'", format_unformat_error, i);
5145 if (sw_if_index_set == 0)
5147 errmsg ("missing interface name or sw_if_index");
5151 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
5153 mp->sw_if_index = ntohl (sw_if_index);
5154 mp->enable = enable;
5163 api_l2_patch_add_del (vat_main_t * vam)
5165 unformat_input_t *i = vam->input;
5166 vl_api_l2_patch_add_del_t *mp;
5168 u8 rx_sw_if_index_set = 0;
5170 u8 tx_sw_if_index_set = 0;
5174 /* Parse args required to build the message */
5175 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5177 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5178 rx_sw_if_index_set = 1;
5179 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5180 tx_sw_if_index_set = 1;
5181 else if (unformat (i, "rx"))
5183 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5185 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
5187 rx_sw_if_index_set = 1;
5192 else if (unformat (i, "tx"))
5194 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5196 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
5198 tx_sw_if_index_set = 1;
5203 else if (unformat (i, "del"))
5209 if (rx_sw_if_index_set == 0)
5211 errmsg ("missing rx interface name or rx_sw_if_index");
5215 if (tx_sw_if_index_set == 0)
5217 errmsg ("missing tx interface name or tx_sw_if_index");
5221 M (L2_PATCH_ADD_DEL, mp);
5223 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
5224 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
5225 mp->is_add = is_add;
5233 u8 localsid_addr[16];
5242 api_ioam_enable (vat_main_t * vam)
5244 unformat_input_t *input = vam->input;
5245 vl_api_ioam_enable_t *mp;
5247 int has_trace_option = 0;
5248 int has_pot_option = 0;
5249 int has_seqno_option = 0;
5250 int has_analyse_option = 0;
5253 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5255 if (unformat (input, "trace"))
5256 has_trace_option = 1;
5257 else if (unformat (input, "pot"))
5259 else if (unformat (input, "seqno"))
5260 has_seqno_option = 1;
5261 else if (unformat (input, "analyse"))
5262 has_analyse_option = 1;
5266 M (IOAM_ENABLE, mp);
5267 mp->id = htons (id);
5268 mp->seqno = has_seqno_option;
5269 mp->analyse = has_analyse_option;
5270 mp->pot_enable = has_pot_option;
5271 mp->trace_enable = has_trace_option;
5280 api_ioam_disable (vat_main_t * vam)
5282 vl_api_ioam_disable_t *mp;
5285 M (IOAM_DISABLE, mp);
5291 #define foreach_tcp_proto_field \
5295 #define foreach_udp_proto_field \
5299 #define foreach_ip4_proto_field \
5311 u16 src_port, dst_port;
5314 #if VPP_API_TEST_BUILTIN == 0
5316 unformat_tcp_mask (unformat_input_t * input, va_list * args)
5318 u8 **maskp = va_arg (*args, u8 **);
5320 u8 found_something = 0;
5323 #define _(a) u8 a=0;
5324 foreach_tcp_proto_field;
5327 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5330 #define _(a) else if (unformat (input, #a)) a=1;
5331 foreach_tcp_proto_field
5337 #define _(a) found_something += a;
5338 foreach_tcp_proto_field;
5341 if (found_something == 0)
5344 vec_validate (mask, sizeof (*tcp) - 1);
5346 tcp = (tcp_header_t *) mask;
5348 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
5349 foreach_tcp_proto_field;
5357 unformat_udp_mask (unformat_input_t * input, va_list * args)
5359 u8 **maskp = va_arg (*args, u8 **);
5361 u8 found_something = 0;
5364 #define _(a) u8 a=0;
5365 foreach_udp_proto_field;
5368 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5371 #define _(a) else if (unformat (input, #a)) a=1;
5372 foreach_udp_proto_field
5378 #define _(a) found_something += a;
5379 foreach_udp_proto_field;
5382 if (found_something == 0)
5385 vec_validate (mask, sizeof (*udp) - 1);
5387 udp = (udp_header_t *) mask;
5389 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
5390 foreach_udp_proto_field;
5398 unformat_l4_mask (unformat_input_t * input, va_list * args)
5400 u8 **maskp = va_arg (*args, u8 **);
5401 u16 src_port = 0, dst_port = 0;
5402 tcpudp_header_t *tcpudp;
5404 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5406 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
5408 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
5410 else if (unformat (input, "src_port"))
5412 else if (unformat (input, "dst_port"))
5418 if (!src_port && !dst_port)
5422 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
5424 tcpudp = (tcpudp_header_t *) mask;
5425 tcpudp->src_port = src_port;
5426 tcpudp->dst_port = dst_port;
5434 unformat_ip4_mask (unformat_input_t * input, va_list * args)
5436 u8 **maskp = va_arg (*args, u8 **);
5438 u8 found_something = 0;
5441 #define _(a) u8 a=0;
5442 foreach_ip4_proto_field;
5448 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5450 if (unformat (input, "version"))
5452 else if (unformat (input, "hdr_length"))
5454 else if (unformat (input, "src"))
5456 else if (unformat (input, "dst"))
5458 else if (unformat (input, "proto"))
5461 #define _(a) else if (unformat (input, #a)) a=1;
5462 foreach_ip4_proto_field
5468 #define _(a) found_something += a;
5469 foreach_ip4_proto_field;
5472 if (found_something == 0)
5475 vec_validate (mask, sizeof (*ip) - 1);
5477 ip = (ip4_header_t *) mask;
5479 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
5480 foreach_ip4_proto_field;
5483 ip->ip_version_and_header_length = 0;
5486 ip->ip_version_and_header_length |= 0xF0;
5489 ip->ip_version_and_header_length |= 0x0F;
5495 #define foreach_ip6_proto_field \
5503 unformat_ip6_mask (unformat_input_t * input, va_list * args)
5505 u8 **maskp = va_arg (*args, u8 **);
5507 u8 found_something = 0;
5509 u32 ip_version_traffic_class_and_flow_label;
5511 #define _(a) u8 a=0;
5512 foreach_ip6_proto_field;
5515 u8 traffic_class = 0;
5518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5520 if (unformat (input, "version"))
5522 else if (unformat (input, "traffic-class"))
5524 else if (unformat (input, "flow-label"))
5526 else if (unformat (input, "src"))
5528 else if (unformat (input, "dst"))
5530 else if (unformat (input, "proto"))
5533 #define _(a) else if (unformat (input, #a)) a=1;
5534 foreach_ip6_proto_field
5540 #define _(a) found_something += a;
5541 foreach_ip6_proto_field;
5544 if (found_something == 0)
5547 vec_validate (mask, sizeof (*ip) - 1);
5549 ip = (ip6_header_t *) mask;
5551 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
5552 foreach_ip6_proto_field;
5555 ip_version_traffic_class_and_flow_label = 0;
5558 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5561 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5564 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5566 ip->ip_version_traffic_class_and_flow_label =
5567 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5574 unformat_l3_mask (unformat_input_t * input, va_list * args)
5576 u8 **maskp = va_arg (*args, u8 **);
5578 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5580 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5582 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5591 unformat_l2_mask (unformat_input_t * input, va_list * args)
5593 u8 **maskp = va_arg (*args, u8 **);
5608 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5610 if (unformat (input, "src"))
5612 else if (unformat (input, "dst"))
5614 else if (unformat (input, "proto"))
5616 else if (unformat (input, "tag1"))
5618 else if (unformat (input, "tag2"))
5620 else if (unformat (input, "ignore-tag1"))
5622 else if (unformat (input, "ignore-tag2"))
5624 else if (unformat (input, "cos1"))
5626 else if (unformat (input, "cos2"))
5628 else if (unformat (input, "dot1q"))
5630 else if (unformat (input, "dot1ad"))
5635 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5636 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5639 if (tag1 || ignore_tag1 || cos1 || dot1q)
5641 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5644 vec_validate (mask, len - 1);
5647 clib_memset (mask, 0xff, 6);
5650 clib_memset (mask + 6, 0xff, 6);
5654 /* inner vlan tag */
5663 mask[21] = mask[20] = 0xff;
5684 mask[16] = mask[17] = 0xff;
5694 mask[12] = mask[13] = 0xff;
5701 unformat_classify_mask (unformat_input_t * input, va_list * args)
5703 u8 **maskp = va_arg (*args, u8 **);
5704 u32 *skipp = va_arg (*args, u32 *);
5705 u32 *matchp = va_arg (*args, u32 *);
5713 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5715 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5717 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5719 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5721 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
5735 if (mask || l2 || l3 || l4)
5739 /* "With a free Ethernet header in every package" */
5741 vec_validate (l2, 13);
5745 vec_append (mask, l3);
5750 vec_append (mask, l4);
5755 /* Scan forward looking for the first significant mask octet */
5756 for (i = 0; i < vec_len (mask); i++)
5760 /* compute (skip, match) params */
5761 *skipp = i / sizeof (u32x4);
5762 vec_delete (mask, *skipp * sizeof (u32x4), 0);
5764 /* Pad mask to an even multiple of the vector size */
5765 while (vec_len (mask) % sizeof (u32x4))
5768 match = vec_len (mask) / sizeof (u32x4);
5770 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
5772 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
5773 if (*tmp || *(tmp + 1))
5778 clib_warning ("BUG: match 0");
5780 _vec_len (mask) = match * sizeof (u32x4);
5790 #endif /* VPP_API_TEST_BUILTIN */
5792 #define foreach_l2_next \
5794 _(ethernet, ETHERNET_INPUT) \
5799 unformat_l2_next_index (unformat_input_t * input, va_list * args)
5801 u32 *miss_next_indexp = va_arg (*args, u32 *);
5806 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
5810 if (unformat (input, "%d", &tmp))
5819 *miss_next_indexp = next_index;
5823 #define foreach_ip_next \
5829 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
5831 u32 *miss_next_indexp = va_arg (*args, u32 *);
5836 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5840 if (unformat (input, "%d", &tmp))
5849 *miss_next_indexp = next_index;
5853 #define foreach_acl_next \
5857 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
5859 u32 *miss_next_indexp = va_arg (*args, u32 *);
5864 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5868 if (unformat (input, "permit"))
5873 else if (unformat (input, "%d", &tmp))
5882 *miss_next_indexp = next_index;
5887 unformat_policer_precolor (unformat_input_t * input, va_list * args)
5889 u32 *r = va_arg (*args, u32 *);
5891 if (unformat (input, "conform-color"))
5892 *r = POLICE_CONFORM;
5893 else if (unformat (input, "exceed-color"))
5901 #if VPP_API_TEST_BUILTIN == 0
5903 unformat_l4_match (unformat_input_t * input, va_list * args)
5905 u8 **matchp = va_arg (*args, u8 **);
5907 u8 *proto_header = 0;
5913 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5915 if (unformat (input, "src_port %d", &src_port))
5917 else if (unformat (input, "dst_port %d", &dst_port))
5923 h.src_port = clib_host_to_net_u16 (src_port);
5924 h.dst_port = clib_host_to_net_u16 (dst_port);
5925 vec_validate (proto_header, sizeof (h) - 1);
5926 memcpy (proto_header, &h, sizeof (h));
5928 *matchp = proto_header;
5934 unformat_ip4_match (unformat_input_t * input, va_list * args)
5936 u8 **matchp = va_arg (*args, u8 **);
5943 int src = 0, dst = 0;
5944 ip4_address_t src_val, dst_val;
5951 int fragment_id = 0;
5952 u32 fragment_id_val;
5958 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5960 if (unformat (input, "version %d", &version_val))
5962 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5964 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5966 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5968 else if (unformat (input, "proto %d", &proto_val))
5970 else if (unformat (input, "tos %d", &tos_val))
5972 else if (unformat (input, "length %d", &length_val))
5974 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5976 else if (unformat (input, "ttl %d", &ttl_val))
5978 else if (unformat (input, "checksum %d", &checksum_val))
5984 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5985 + ttl + checksum == 0)
5989 * Aligned because we use the real comparison functions
5991 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
5993 ip = (ip4_header_t *) match;
5995 /* These are realistically matched in practice */
5997 ip->src_address.as_u32 = src_val.as_u32;
6000 ip->dst_address.as_u32 = dst_val.as_u32;
6003 ip->protocol = proto_val;
6006 /* These are not, but they're included for completeness */
6008 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
6011 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6017 ip->length = clib_host_to_net_u16 (length_val);
6023 ip->checksum = clib_host_to_net_u16 (checksum_val);
6030 unformat_ip6_match (unformat_input_t * input, va_list * args)
6032 u8 **matchp = va_arg (*args, u8 **);
6037 u8 traffic_class = 0;
6038 u32 traffic_class_val = 0;
6041 int src = 0, dst = 0;
6042 ip6_address_t src_val, dst_val;
6045 int payload_length = 0;
6046 u32 payload_length_val;
6049 u32 ip_version_traffic_class_and_flow_label;
6051 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6053 if (unformat (input, "version %d", &version_val))
6055 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6057 else if (unformat (input, "flow_label %d", &flow_label_val))
6059 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6061 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6063 else if (unformat (input, "proto %d", &proto_val))
6065 else if (unformat (input, "payload_length %d", &payload_length_val))
6067 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6073 if (version + traffic_class + flow_label + src + dst + proto +
6074 payload_length + hop_limit == 0)
6078 * Aligned because we use the real comparison functions
6080 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
6082 ip = (ip6_header_t *) match;
6085 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6088 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6091 ip->protocol = proto_val;
6093 ip_version_traffic_class_and_flow_label = 0;
6096 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6099 ip_version_traffic_class_and_flow_label |=
6100 (traffic_class_val & 0xFF) << 20;
6103 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6105 ip->ip_version_traffic_class_and_flow_label =
6106 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6109 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6112 ip->hop_limit = hop_limit_val;
6119 unformat_l3_match (unformat_input_t * input, va_list * args)
6121 u8 **matchp = va_arg (*args, u8 **);
6123 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6125 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6127 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6136 unformat_vlan_tag (unformat_input_t * input, va_list * args)
6138 u8 *tagp = va_arg (*args, u8 *);
6141 if (unformat (input, "%d", &tag))
6143 tagp[0] = (tag >> 8) & 0x0F;
6144 tagp[1] = tag & 0xFF;
6152 unformat_l2_match (unformat_input_t * input, va_list * args)
6154 u8 **matchp = va_arg (*args, u8 **);
6174 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6176 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6179 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6181 else if (unformat (input, "proto %U",
6182 unformat_ethernet_type_host_byte_order, &proto_val))
6184 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6186 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6188 else if (unformat (input, "ignore-tag1"))
6190 else if (unformat (input, "ignore-tag2"))
6192 else if (unformat (input, "cos1 %d", &cos1_val))
6194 else if (unformat (input, "cos2 %d", &cos2_val))
6199 if ((src + dst + proto + tag1 + tag2 +
6200 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6203 if (tag1 || ignore_tag1 || cos1)
6205 if (tag2 || ignore_tag2 || cos2)
6208 vec_validate_aligned (match, len - 1, sizeof (u32x4));
6211 clib_memcpy (match, dst_val, 6);
6214 clib_memcpy (match + 6, src_val, 6);
6218 /* inner vlan tag */
6219 match[19] = tag2_val[1];
6220 match[18] = tag2_val[0];
6222 match[18] |= (cos2_val & 0x7) << 5;
6225 match[21] = proto_val & 0xff;
6226 match[20] = proto_val >> 8;
6230 match[15] = tag1_val[1];
6231 match[14] = tag1_val[0];
6234 match[14] |= (cos1_val & 0x7) << 5;
6240 match[15] = tag1_val[1];
6241 match[14] = tag1_val[0];
6244 match[17] = proto_val & 0xff;
6245 match[16] = proto_val >> 8;
6248 match[14] |= (cos1_val & 0x7) << 5;
6254 match[18] |= (cos2_val & 0x7) << 5;
6256 match[14] |= (cos1_val & 0x7) << 5;
6259 match[13] = proto_val & 0xff;
6260 match[12] = proto_val >> 8;
6268 unformat_qos_source (unformat_input_t * input, va_list * args)
6270 int *qs = va_arg (*args, int *);
6272 if (unformat (input, "ip"))
6273 *qs = QOS_SOURCE_IP;
6274 else if (unformat (input, "mpls"))
6275 *qs = QOS_SOURCE_MPLS;
6276 else if (unformat (input, "ext"))
6277 *qs = QOS_SOURCE_EXT;
6278 else if (unformat (input, "vlan"))
6279 *qs = QOS_SOURCE_VLAN;
6288 api_unformat_classify_match (unformat_input_t * input, va_list * args)
6290 u8 **matchp = va_arg (*args, u8 **);
6291 u32 skip_n_vectors = va_arg (*args, u32);
6292 u32 match_n_vectors = va_arg (*args, u32);
6299 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6301 if (unformat (input, "hex %U", unformat_hex_string, &match))
6303 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6305 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6307 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
6321 if (match || l2 || l3 || l4)
6325 /* "Win a free Ethernet header in every packet" */
6327 vec_validate_aligned (l2, 13, sizeof (u32x4));
6331 vec_append_aligned (match, l3, sizeof (u32x4));
6336 vec_append_aligned (match, l4, sizeof (u32x4));
6341 /* Make sure the vector is big enough even if key is all 0's */
6342 vec_validate_aligned
6343 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
6346 /* Set size, include skipped vectors */
6347 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
6358 api_get_node_index (vat_main_t * vam)
6360 unformat_input_t *i = vam->input;
6361 vl_api_get_node_index_t *mp;
6365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6367 if (unformat (i, "node %s", &name))
6374 errmsg ("node name required");
6377 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
6379 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6383 M (GET_NODE_INDEX, mp);
6384 clib_memcpy (mp->node_name, name, vec_len (name));
6393 api_get_next_index (vat_main_t * vam)
6395 unformat_input_t *i = vam->input;
6396 vl_api_get_next_index_t *mp;
6397 u8 *node_name = 0, *next_node_name = 0;
6400 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6402 if (unformat (i, "node-name %s", &node_name))
6404 else if (unformat (i, "next-node-name %s", &next_node_name))
6410 errmsg ("node name required");
6413 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
6415 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6419 if (next_node_name == 0)
6421 errmsg ("next node name required");
6424 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
6426 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
6430 M (GET_NEXT_INDEX, mp);
6431 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
6432 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
6433 vec_free (node_name);
6434 vec_free (next_node_name);
6442 api_add_node_next (vat_main_t * vam)
6444 unformat_input_t *i = vam->input;
6445 vl_api_add_node_next_t *mp;
6450 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6452 if (unformat (i, "node %s", &name))
6454 else if (unformat (i, "next %s", &next))
6461 errmsg ("node name required");
6464 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
6466 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
6471 errmsg ("next node required");
6474 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
6476 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
6480 M (ADD_NODE_NEXT, mp);
6481 clib_memcpy (mp->node_name, name, vec_len (name));
6482 clib_memcpy (mp->next_name, next, vec_len (next));
6491 static void vl_api_sw_interface_virtio_pci_details_t_handler
6492 (vl_api_sw_interface_virtio_pci_details_t * mp)
6494 vat_main_t *vam = &vat_main;
6509 addr.domain = ntohs (mp->pci_addr.domain);
6510 addr.bus = mp->pci_addr.bus;
6511 addr.slot = mp->pci_addr.slot;
6512 addr.function = mp->pci_addr.function;
6514 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
6515 addr.slot, addr.function);
6518 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
6519 pci_addr, ntohl (mp->sw_if_index),
6520 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
6521 format_ethernet_address, mp->mac_addr,
6522 clib_net_to_host_u64 (mp->features));
6523 vec_free (pci_addr);
6526 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
6527 (vl_api_sw_interface_virtio_pci_details_t * mp)
6529 vat_main_t *vam = &vat_main;
6530 vat_json_node_t *node = NULL;
6531 vlib_pci_addr_t pci_addr;
6533 if (VAT_JSON_ARRAY != vam->json_tree.type)
6535 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
6536 vat_json_init_array (&vam->json_tree);
6538 node = vat_json_array_add (&vam->json_tree);
6540 pci_addr.domain = ntohs (mp->pci_addr.domain);
6541 pci_addr.bus = mp->pci_addr.bus;
6542 pci_addr.slot = mp->pci_addr.slot;
6543 pci_addr.function = mp->pci_addr.function;
6545 vat_json_init_object (node);
6546 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
6547 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
6548 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
6549 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
6550 vat_json_object_add_uint (node, "features",
6551 clib_net_to_host_u64 (mp->features));
6552 vat_json_object_add_string_copy (node, "mac_addr",
6553 format (0, "%U", format_ethernet_address,
6558 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
6560 vl_api_sw_interface_virtio_pci_dump_t *mp;
6561 vl_api_control_ping_t *mp_ping;
6565 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
6566 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
6567 "mac_addr", "features");
6569 /* Get list of tap interfaces */
6570 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
6573 /* Use a control ping for synchronization */
6574 MPING (CONTROL_PING, mp_ping);
6582 api_l2_fib_clear_table (vat_main_t * vam)
6584 // unformat_input_t * i = vam->input;
6585 vl_api_l2_fib_clear_table_t *mp;
6588 M (L2_FIB_CLEAR_TABLE, mp);
6596 api_l2_interface_efp_filter (vat_main_t * vam)
6598 unformat_input_t *i = vam->input;
6599 vl_api_l2_interface_efp_filter_t *mp;
6602 u8 sw_if_index_set = 0;
6605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6607 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6608 sw_if_index_set = 1;
6609 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6610 sw_if_index_set = 1;
6611 else if (unformat (i, "enable"))
6613 else if (unformat (i, "disable"))
6617 clib_warning ("parse error '%U'", format_unformat_error, i);
6622 if (sw_if_index_set == 0)
6624 errmsg ("missing sw_if_index");
6628 M (L2_INTERFACE_EFP_FILTER, mp);
6630 mp->sw_if_index = ntohl (sw_if_index);
6631 mp->enable_disable = enable;
6638 #define foreach_vtr_op \
6639 _("disable", L2_VTR_DISABLED) \
6640 _("push-1", L2_VTR_PUSH_1) \
6641 _("push-2", L2_VTR_PUSH_2) \
6642 _("pop-1", L2_VTR_POP_1) \
6643 _("pop-2", L2_VTR_POP_2) \
6644 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6645 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6646 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6647 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6650 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6652 unformat_input_t *i = vam->input;
6653 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6655 u8 sw_if_index_set = 0;
6663 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6665 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6666 sw_if_index_set = 1;
6667 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6668 sw_if_index_set = 1;
6669 else if (unformat (i, "vtr_op %d", &vtr_op))
6671 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6674 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6676 else if (unformat (i, "tag1 %d", &tag1))
6678 else if (unformat (i, "tag2 %d", &tag2))
6682 clib_warning ("parse error '%U'", format_unformat_error, i);
6687 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
6689 errmsg ("missing vtr operation or sw_if_index");
6693 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
6694 mp->sw_if_index = ntohl (sw_if_index);
6695 mp->vtr_op = ntohl (vtr_op);
6696 mp->push_dot1q = ntohl (push_dot1q);
6697 mp->tag1 = ntohl (tag1);
6698 mp->tag2 = ntohl (tag2);
6706 api_create_vhost_user_if (vat_main_t * vam)
6708 unformat_input_t *i = vam->input;
6709 vl_api_create_vhost_user_if_t *mp;
6712 u8 file_name_set = 0;
6713 u32 custom_dev_instance = ~0;
6715 u8 use_custom_mac = 0;
6716 u8 disable_mrg_rxbuf = 0;
6717 u8 disable_indirect_desc = 0;
6720 u8 enable_packed = 0;
6723 /* Shut up coverity */
6724 clib_memset (hwaddr, 0, sizeof (hwaddr));
6726 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6728 if (unformat (i, "socket %s", &file_name))
6732 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6734 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6736 else if (unformat (i, "server"))
6738 else if (unformat (i, "disable_mrg_rxbuf"))
6739 disable_mrg_rxbuf = 1;
6740 else if (unformat (i, "disable_indirect_desc"))
6741 disable_indirect_desc = 1;
6742 else if (unformat (i, "gso"))
6744 else if (unformat (i, "packed"))
6746 else if (unformat (i, "tag %s", &tag))
6752 if (file_name_set == 0)
6754 errmsg ("missing socket file name");
6758 if (vec_len (file_name) > 255)
6760 errmsg ("socket file name too long");
6763 vec_add1 (file_name, 0);
6765 M (CREATE_VHOST_USER_IF, mp);
6767 mp->is_server = is_server;
6768 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
6769 mp->disable_indirect_desc = disable_indirect_desc;
6770 mp->enable_gso = enable_gso;
6771 mp->enable_packed = enable_packed;
6772 mp->custom_dev_instance = ntohl (custom_dev_instance);
6773 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6774 vec_free (file_name);
6775 if (custom_dev_instance != ~0)
6778 mp->use_custom_mac = use_custom_mac;
6779 clib_memcpy (mp->mac_address, hwaddr, 6);
6781 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
6790 api_modify_vhost_user_if (vat_main_t * vam)
6792 unformat_input_t *i = vam->input;
6793 vl_api_modify_vhost_user_if_t *mp;
6796 u8 file_name_set = 0;
6797 u32 custom_dev_instance = ~0;
6798 u8 sw_if_index_set = 0;
6799 u32 sw_if_index = (u32) ~ 0;
6801 u8 enable_packed = 0;
6804 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6806 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6807 sw_if_index_set = 1;
6808 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6809 sw_if_index_set = 1;
6810 else if (unformat (i, "socket %s", &file_name))
6814 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6816 else if (unformat (i, "server"))
6818 else if (unformat (i, "gso"))
6820 else if (unformat (i, "packed"))
6826 if (sw_if_index_set == 0)
6828 errmsg ("missing sw_if_index or interface name");
6832 if (file_name_set == 0)
6834 errmsg ("missing socket file name");
6838 if (vec_len (file_name) > 255)
6840 errmsg ("socket file name too long");
6843 vec_add1 (file_name, 0);
6845 M (MODIFY_VHOST_USER_IF, mp);
6847 mp->sw_if_index = ntohl (sw_if_index);
6848 mp->is_server = is_server;
6849 mp->enable_gso = enable_gso;
6850 mp->enable_packed = enable_packed;
6851 mp->custom_dev_instance = ntohl (custom_dev_instance);
6852 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6853 vec_free (file_name);
6854 if (custom_dev_instance != ~0)
6863 api_create_vhost_user_if_v2 (vat_main_t * vam)
6865 unformat_input_t *i = vam->input;
6866 vl_api_create_vhost_user_if_v2_t *mp;
6869 u8 file_name_set = 0;
6870 u32 custom_dev_instance = ~0;
6872 u8 use_custom_mac = 0;
6873 u8 disable_mrg_rxbuf = 0;
6874 u8 disable_indirect_desc = 0;
6877 u8 enable_packed = 0;
6878 u8 enable_event_idx = 0;
6881 /* Shut up coverity */
6882 clib_memset (hwaddr, 0, sizeof (hwaddr));
6884 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6886 if (unformat (i, "socket %s", &file_name))
6890 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6892 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6894 else if (unformat (i, "server"))
6896 else if (unformat (i, "disable_mrg_rxbuf"))
6897 disable_mrg_rxbuf = 1;
6898 else if (unformat (i, "disable_indirect_desc"))
6899 disable_indirect_desc = 1;
6900 else if (unformat (i, "gso"))
6902 else if (unformat (i, "packed"))
6904 else if (unformat (i, "event-idx"))
6905 enable_event_idx = 1;
6906 else if (unformat (i, "tag %s", &tag))
6912 if (file_name_set == 0)
6914 errmsg ("missing socket file name");
6918 if (vec_len (file_name) > 255)
6920 errmsg ("socket file name too long");
6923 vec_add1 (file_name, 0);
6925 M (CREATE_VHOST_USER_IF_V2, mp);
6927 mp->is_server = is_server;
6928 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
6929 mp->disable_indirect_desc = disable_indirect_desc;
6930 mp->enable_gso = enable_gso;
6931 mp->enable_packed = enable_packed;
6932 mp->enable_event_idx = enable_event_idx;
6933 mp->custom_dev_instance = ntohl (custom_dev_instance);
6934 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
6935 vec_free (file_name);
6936 if (custom_dev_instance != ~0)
6939 mp->use_custom_mac = use_custom_mac;
6940 clib_memcpy (mp->mac_address, hwaddr, 6);
6942 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
6951 api_modify_vhost_user_if_v2 (vat_main_t * vam)
6953 unformat_input_t *i = vam->input;
6954 vl_api_modify_vhost_user_if_v2_t *mp;
6957 u8 file_name_set = 0;
6958 u32 custom_dev_instance = ~0;
6959 u8 sw_if_index_set = 0;
6960 u32 sw_if_index = (u32) ~ 0;
6962 u8 enable_packed = 0;
6963 u8 enable_event_idx = 0;
6966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6968 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6969 sw_if_index_set = 1;
6970 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6971 sw_if_index_set = 1;
6972 else if (unformat (i, "socket %s", &file_name))
6976 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
6978 else if (unformat (i, "server"))
6980 else if (unformat (i, "gso"))
6982 else if (unformat (i, "packed"))
6984 else if (unformat (i, "event-idx"))
6985 enable_event_idx = 1;
6990 if (sw_if_index_set == 0)
6992 errmsg ("missing sw_if_index or interface name");
6996 if (file_name_set == 0)
6998 errmsg ("missing socket file name");
7002 if (vec_len (file_name) > 255)
7004 errmsg ("socket file name too long");
7007 vec_add1 (file_name, 0);
7009 M (MODIFY_VHOST_USER_IF_V2, mp);
7011 mp->sw_if_index = ntohl (sw_if_index);
7012 mp->is_server = is_server;
7013 mp->enable_gso = enable_gso;
7014 mp->enable_packed = enable_packed;
7015 mp->enable_event_idx = enable_event_idx;
7016 mp->custom_dev_instance = ntohl (custom_dev_instance);
7017 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
7018 vec_free (file_name);
7019 if (custom_dev_instance != ~0)
7028 api_delete_vhost_user_if (vat_main_t * vam)
7030 unformat_input_t *i = vam->input;
7031 vl_api_delete_vhost_user_if_t *mp;
7032 u32 sw_if_index = ~0;
7033 u8 sw_if_index_set = 0;
7036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7038 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7039 sw_if_index_set = 1;
7040 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7041 sw_if_index_set = 1;
7046 if (sw_if_index_set == 0)
7048 errmsg ("missing sw_if_index or interface name");
7053 M (DELETE_VHOST_USER_IF, mp);
7055 mp->sw_if_index = ntohl (sw_if_index);
7062 static void vl_api_sw_interface_vhost_user_details_t_handler
7063 (vl_api_sw_interface_vhost_user_details_t * mp)
7065 vat_main_t *vam = &vat_main;
7069 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
7070 clib_net_to_host_u32
7071 (mp->features_last_32) <<
7074 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
7075 (char *) mp->interface_name, ntohl (mp->sw_if_index),
7076 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
7077 ntohl (mp->num_regions), (char *) mp->sock_filename);
7078 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
7081 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7082 (vl_api_sw_interface_vhost_user_details_t * mp)
7084 vat_main_t *vam = &vat_main;
7085 vat_json_node_t *node = NULL;
7087 if (VAT_JSON_ARRAY != vam->json_tree.type)
7089 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7090 vat_json_init_array (&vam->json_tree);
7092 node = vat_json_array_add (&vam->json_tree);
7094 vat_json_init_object (node);
7095 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7096 vat_json_object_add_string_copy (node, "interface_name",
7097 mp->interface_name);
7098 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
7099 ntohl (mp->virtio_net_hdr_sz));
7100 vat_json_object_add_uint (node, "features_first_32",
7101 clib_net_to_host_u32 (mp->features_first_32));
7102 vat_json_object_add_uint (node, "features_last_32",
7103 clib_net_to_host_u32 (mp->features_last_32));
7104 vat_json_object_add_uint (node, "is_server", mp->is_server);
7105 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
7106 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
7107 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
7111 api_sw_interface_vhost_user_dump (vat_main_t * vam)
7113 unformat_input_t *i = vam->input;
7114 vl_api_sw_interface_vhost_user_dump_t *mp;
7115 vl_api_control_ping_t *mp_ping;
7117 u32 sw_if_index = ~0;
7119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7121 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7123 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7129 print (vam->ofp, "Interface name idx hdr_sz features "
7130 "server regions filename");
7132 /* Get list of vhost-user interfaces */
7133 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
7134 mp->sw_if_index = ntohl (sw_if_index);
7137 /* Use a control ping for synchronization */
7138 MPING (CONTROL_PING, mp_ping);
7146 api_show_version (vat_main_t * vam)
7148 vl_api_show_version_t *mp;
7151 M (SHOW_VERSION, mp);
7158 static void vl_api_l2_fib_table_details_t_handler
7159 (vl_api_l2_fib_table_details_t * mp)
7161 vat_main_t *vam = &vat_main;
7163 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7165 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
7166 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
7170 static void vl_api_l2_fib_table_details_t_handler_json
7171 (vl_api_l2_fib_table_details_t * mp)
7173 vat_main_t *vam = &vat_main;
7174 vat_json_node_t *node = NULL;
7176 if (VAT_JSON_ARRAY != vam->json_tree.type)
7178 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7179 vat_json_init_array (&vam->json_tree);
7181 node = vat_json_array_add (&vam->json_tree);
7183 vat_json_init_object (node);
7184 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
7185 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
7186 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7187 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
7188 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
7189 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
7193 api_l2_fib_table_dump (vat_main_t * vam)
7195 unformat_input_t *i = vam->input;
7196 vl_api_l2_fib_table_dump_t *mp;
7197 vl_api_control_ping_t *mp_ping;
7202 /* Parse args required to build the message */
7203 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7205 if (unformat (i, "bd_id %d", &bd_id))
7213 errmsg ("missing bridge domain");
7217 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
7219 /* Get list of l2 fib entries */
7220 M (L2_FIB_TABLE_DUMP, mp);
7222 mp->bd_id = ntohl (bd_id);
7225 /* Use a control ping for synchronization */
7226 MPING (CONTROL_PING, mp_ping);
7235 api_interface_name_renumber (vat_main_t * vam)
7237 unformat_input_t *line_input = vam->input;
7238 vl_api_interface_name_renumber_t *mp;
7239 u32 sw_if_index = ~0;
7240 u32 new_show_dev_instance = ~0;
7243 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
7245 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
7248 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7250 else if (unformat (line_input, "new_show_dev_instance %d",
7251 &new_show_dev_instance))
7257 if (sw_if_index == ~0)
7259 errmsg ("missing interface name or sw_if_index");
7263 if (new_show_dev_instance == ~0)
7265 errmsg ("missing new_show_dev_instance");
7269 M (INTERFACE_NAME_RENUMBER, mp);
7271 mp->sw_if_index = ntohl (sw_if_index);
7272 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7280 api_want_l2_macs_events (vat_main_t * vam)
7282 unformat_input_t *line_input = vam->input;
7283 vl_api_want_l2_macs_events_t *mp;
7284 u8 enable_disable = 1;
7286 u32 max_macs_in_event = 0;
7287 u32 learn_limit = 0;
7290 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
7292 if (unformat (line_input, "learn-limit %d", &learn_limit))
7294 else if (unformat (line_input, "scan-delay %d", &scan_delay))
7296 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
7298 else if (unformat (line_input, "disable"))
7304 M (WANT_L2_MACS_EVENTS, mp);
7305 mp->enable_disable = enable_disable;
7306 mp->pid = htonl (getpid ());
7307 mp->learn_limit = htonl (learn_limit);
7308 mp->scan_delay = (u8) scan_delay;
7309 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
7316 api_ip_address_dump (vat_main_t * vam)
7318 unformat_input_t *i = vam->input;
7319 vl_api_ip_address_dump_t *mp;
7320 vl_api_control_ping_t *mp_ping;
7321 u32 sw_if_index = ~0;
7322 u8 sw_if_index_set = 0;
7327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7329 if (unformat (i, "sw_if_index %d", &sw_if_index))
7330 sw_if_index_set = 1;
7332 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7333 sw_if_index_set = 1;
7334 else if (unformat (i, "ipv4"))
7336 else if (unformat (i, "ipv6"))
7342 if (ipv4_set && ipv6_set)
7344 errmsg ("ipv4 and ipv6 flags cannot be both set");
7348 if ((!ipv4_set) && (!ipv6_set))
7350 errmsg ("no ipv4 nor ipv6 flag set");
7354 if (sw_if_index_set == 0)
7356 errmsg ("missing interface name or sw_if_index");
7360 vam->current_sw_if_index = sw_if_index;
7361 vam->is_ipv6 = ipv6_set;
7363 M (IP_ADDRESS_DUMP, mp);
7364 mp->sw_if_index = ntohl (sw_if_index);
7365 mp->is_ipv6 = ipv6_set;
7368 /* Use a control ping for synchronization */
7369 MPING (CONTROL_PING, mp_ping);
7377 api_ip_dump (vat_main_t * vam)
7379 vl_api_ip_dump_t *mp;
7380 vl_api_control_ping_t *mp_ping;
7381 unformat_input_t *in = vam->input;
7388 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
7390 if (unformat (in, "ipv4"))
7392 else if (unformat (in, "ipv6"))
7398 if (ipv4_set && ipv6_set)
7400 errmsg ("ipv4 and ipv6 flags cannot be both set");
7404 if ((!ipv4_set) && (!ipv6_set))
7406 errmsg ("no ipv4 nor ipv6 flag set");
7411 vam->is_ipv6 = is_ipv6;
7414 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
7416 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7418 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
7421 mp->is_ipv6 = ipv6_set;
7424 /* Use a control ping for synchronization */
7425 MPING (CONTROL_PING, mp_ping);
7433 api_get_first_msg_id (vat_main_t * vam)
7435 vl_api_get_first_msg_id_t *mp;
7436 unformat_input_t *i = vam->input;
7441 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7443 if (unformat (i, "client %s", &name))
7451 errmsg ("missing client name");
7456 if (vec_len (name) > 63)
7458 errmsg ("client name too long");
7462 M (GET_FIRST_MSG_ID, mp);
7463 clib_memcpy (mp->name, name, vec_len (name));
7470 api_get_node_graph (vat_main_t * vam)
7472 vl_api_get_node_graph_t *mp;
7475 M (GET_NODE_GRAPH, mp);
7479 /* Wait for the reply */
7485 api_af_packet_create (vat_main_t * vam)
7487 unformat_input_t *i = vam->input;
7488 vl_api_af_packet_create_t *mp;
7489 u8 *host_if_name = 0;
7491 u8 random_hw_addr = 1;
7494 clib_memset (hw_addr, 0, sizeof (hw_addr));
7496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7498 if (unformat (i, "name %s", &host_if_name))
7499 vec_add1 (host_if_name, 0);
7500 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
7506 if (!vec_len (host_if_name))
7508 errmsg ("host-interface name must be specified");
7512 if (vec_len (host_if_name) > 64)
7514 errmsg ("host-interface name too long");
7518 M (AF_PACKET_CREATE, mp);
7520 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7521 clib_memcpy (mp->hw_addr, hw_addr, 6);
7522 mp->use_random_hw_addr = random_hw_addr;
7523 vec_free (host_if_name);
7531 fprintf (vam->ofp ? vam->ofp : stderr,
7532 " new sw_if_index = %d\n", vam->sw_if_index);
7539 api_af_packet_delete (vat_main_t * vam)
7541 unformat_input_t *i = vam->input;
7542 vl_api_af_packet_delete_t *mp;
7543 u8 *host_if_name = 0;
7546 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7548 if (unformat (i, "name %s", &host_if_name))
7549 vec_add1 (host_if_name, 0);
7554 if (!vec_len (host_if_name))
7556 errmsg ("host-interface name must be specified");
7560 if (vec_len (host_if_name) > 64)
7562 errmsg ("host-interface name too long");
7566 M (AF_PACKET_DELETE, mp);
7568 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
7569 vec_free (host_if_name);
7576 static void vl_api_af_packet_details_t_handler
7577 (vl_api_af_packet_details_t * mp)
7579 vat_main_t *vam = &vat_main;
7581 print (vam->ofp, "%-16s %d",
7582 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
7585 static void vl_api_af_packet_details_t_handler_json
7586 (vl_api_af_packet_details_t * mp)
7588 vat_main_t *vam = &vat_main;
7589 vat_json_node_t *node = NULL;
7591 if (VAT_JSON_ARRAY != vam->json_tree.type)
7593 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7594 vat_json_init_array (&vam->json_tree);
7596 node = vat_json_array_add (&vam->json_tree);
7598 vat_json_init_object (node);
7599 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7600 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
7604 api_af_packet_dump (vat_main_t * vam)
7606 vl_api_af_packet_dump_t *mp;
7607 vl_api_control_ping_t *mp_ping;
7610 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
7611 /* Get list of tap interfaces */
7612 M (AF_PACKET_DUMP, mp);
7615 /* Use a control ping for synchronization */
7616 MPING (CONTROL_PING, mp_ping);
7624 format_fib_api_path_nh_proto (u8 * s, va_list * args)
7626 vl_api_fib_path_nh_proto_t proto =
7627 va_arg (*args, vl_api_fib_path_nh_proto_t);
7631 case FIB_API_PATH_NH_PROTO_IP4:
7632 s = format (s, "ip4");
7634 case FIB_API_PATH_NH_PROTO_IP6:
7635 s = format (s, "ip6");
7637 case FIB_API_PATH_NH_PROTO_MPLS:
7638 s = format (s, "mpls");
7640 case FIB_API_PATH_NH_PROTO_BIER:
7641 s = format (s, "bier");
7643 case FIB_API_PATH_NH_PROTO_ETHERNET:
7644 s = format (s, "ethernet");
7652 format_vl_api_ip_address_union (u8 * s, va_list * args)
7654 vl_api_address_family_t af = va_arg (*args, int);
7655 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
7660 s = format (s, "%U", format_ip4_address, u->ip4);
7663 s = format (s, "%U", format_ip6_address, u->ip6);
7670 format_vl_api_fib_path_type (u8 * s, va_list * args)
7672 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
7676 case FIB_API_PATH_TYPE_NORMAL:
7677 s = format (s, "normal");
7679 case FIB_API_PATH_TYPE_LOCAL:
7680 s = format (s, "local");
7682 case FIB_API_PATH_TYPE_DROP:
7683 s = format (s, "drop");
7685 case FIB_API_PATH_TYPE_UDP_ENCAP:
7686 s = format (s, "udp-encap");
7688 case FIB_API_PATH_TYPE_BIER_IMP:
7689 s = format (s, "bier-imp");
7691 case FIB_API_PATH_TYPE_ICMP_UNREACH:
7692 s = format (s, "unreach");
7694 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
7695 s = format (s, "prohibit");
7697 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
7698 s = format (s, "src-lookup");
7700 case FIB_API_PATH_TYPE_DVR:
7701 s = format (s, "dvr");
7703 case FIB_API_PATH_TYPE_INTERFACE_RX:
7704 s = format (s, "interface-rx");
7706 case FIB_API_PATH_TYPE_CLASSIFY:
7707 s = format (s, "classify");
7715 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
7718 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
7719 ntohl (fp->weight), ntohl (fp->sw_if_index),
7720 format_vl_api_fib_path_type, fp->type,
7721 format_fib_api_path_nh_proto, fp->proto,
7722 format_vl_api_ip_address_union, &fp->nh.address);
7726 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
7727 vl_api_fib_path_t * fp)
7730 struct in6_addr ip6;
7732 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
7733 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
7734 vat_json_object_add_uint (node, "type", fp->type);
7735 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
7736 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
7738 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
7739 vat_json_object_add_ip4 (node, "next_hop", ip4);
7741 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
7743 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
7744 vat_json_object_add_ip6 (node, "next_hop", ip6);
7749 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
7751 vat_main_t *vam = &vat_main;
7752 int count = ntohl (mp->mt_tunnel.mt_n_paths);
7753 vl_api_fib_path_t *fp;
7756 print (vam->ofp, "sw_if_index %d via:",
7757 ntohl (mp->mt_tunnel.mt_sw_if_index));
7758 fp = mp->mt_tunnel.mt_paths;
7759 for (i = 0; i < count; i++)
7761 vl_api_fib_path_print (vam, fp);
7765 print (vam->ofp, "");
7768 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
7769 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
7772 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
7774 vat_main_t *vam = &vat_main;
7775 vat_json_node_t *node = NULL;
7776 int count = ntohl (mp->mt_tunnel.mt_n_paths);
7777 vl_api_fib_path_t *fp;
7780 if (VAT_JSON_ARRAY != vam->json_tree.type)
7782 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7783 vat_json_init_array (&vam->json_tree);
7785 node = vat_json_array_add (&vam->json_tree);
7787 vat_json_init_object (node);
7788 vat_json_object_add_uint (node, "sw_if_index",
7789 ntohl (mp->mt_tunnel.mt_sw_if_index));
7791 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
7793 fp = mp->mt_tunnel.mt_paths;
7794 for (i = 0; i < count; i++)
7796 vl_api_mpls_fib_path_json_print (node, fp);
7802 api_mpls_tunnel_dump (vat_main_t * vam)
7804 vl_api_mpls_tunnel_dump_t *mp;
7805 vl_api_control_ping_t *mp_ping;
7808 M (MPLS_TUNNEL_DUMP, mp);
7812 /* Use a control ping for synchronization */
7813 MPING (CONTROL_PING, mp_ping);
7820 #define vl_api_mpls_table_details_t_endian vl_noop_handler
7821 #define vl_api_mpls_table_details_t_print vl_noop_handler
7825 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
7827 vat_main_t *vam = &vat_main;
7829 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
7832 static void vl_api_mpls_table_details_t_handler_json
7833 (vl_api_mpls_table_details_t * mp)
7835 vat_main_t *vam = &vat_main;
7836 vat_json_node_t *node = NULL;
7838 if (VAT_JSON_ARRAY != vam->json_tree.type)
7840 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7841 vat_json_init_array (&vam->json_tree);
7843 node = vat_json_array_add (&vam->json_tree);
7845 vat_json_init_object (node);
7846 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
7850 api_mpls_table_dump (vat_main_t * vam)
7852 vl_api_mpls_table_dump_t *mp;
7853 vl_api_control_ping_t *mp_ping;
7856 M (MPLS_TABLE_DUMP, mp);
7859 /* Use a control ping for synchronization */
7860 MPING (CONTROL_PING, mp_ping);
7867 #define vl_api_mpls_route_details_t_endian vl_noop_handler
7868 #define vl_api_mpls_route_details_t_print vl_noop_handler
7871 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
7873 vat_main_t *vam = &vat_main;
7874 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
7875 vl_api_fib_path_t *fp;
7879 "table-id %d, label %u, ess_bit %u",
7880 ntohl (mp->mr_route.mr_table_id),
7881 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
7882 fp = mp->mr_route.mr_paths;
7883 for (i = 0; i < count; i++)
7885 vl_api_fib_path_print (vam, fp);
7890 static void vl_api_mpls_route_details_t_handler_json
7891 (vl_api_mpls_route_details_t * mp)
7893 vat_main_t *vam = &vat_main;
7894 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
7895 vat_json_node_t *node = NULL;
7896 vl_api_fib_path_t *fp;
7899 if (VAT_JSON_ARRAY != vam->json_tree.type)
7901 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7902 vat_json_init_array (&vam->json_tree);
7904 node = vat_json_array_add (&vam->json_tree);
7906 vat_json_init_object (node);
7907 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
7908 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
7909 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
7910 vat_json_object_add_uint (node, "path_count", count);
7911 fp = mp->mr_route.mr_paths;
7912 for (i = 0; i < count; i++)
7914 vl_api_mpls_fib_path_json_print (node, fp);
7920 api_mpls_route_dump (vat_main_t * vam)
7922 unformat_input_t *input = vam->input;
7923 vl_api_mpls_route_dump_t *mp;
7924 vl_api_control_ping_t *mp_ping;
7928 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7930 if (unformat (input, "table_id %d", &table_id))
7937 errmsg ("missing table id");
7941 M (MPLS_ROUTE_DUMP, mp);
7943 mp->table.mt_table_id = ntohl (table_id);
7946 /* Use a control ping for synchronization */
7947 MPING (CONTROL_PING, mp_ping);
7954 #define vl_api_ip_table_details_t_endian vl_noop_handler
7955 #define vl_api_ip_table_details_t_print vl_noop_handler
7958 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
7960 vat_main_t *vam = &vat_main;
7963 "%s; table-id %d, prefix %U/%d",
7964 mp->table.name, ntohl (mp->table.table_id));
7968 static void vl_api_ip_table_details_t_handler_json
7969 (vl_api_ip_table_details_t * mp)
7971 vat_main_t *vam = &vat_main;
7972 vat_json_node_t *node = NULL;
7974 if (VAT_JSON_ARRAY != vam->json_tree.type)
7976 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7977 vat_json_init_array (&vam->json_tree);
7979 node = vat_json_array_add (&vam->json_tree);
7981 vat_json_init_object (node);
7982 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
7986 api_ip_table_dump (vat_main_t * vam)
7988 vl_api_ip_table_dump_t *mp;
7989 vl_api_control_ping_t *mp_ping;
7992 M (IP_TABLE_DUMP, mp);
7995 /* Use a control ping for synchronization */
7996 MPING (CONTROL_PING, mp_ping);
8004 api_ip_mtable_dump (vat_main_t * vam)
8006 vl_api_ip_mtable_dump_t *mp;
8007 vl_api_control_ping_t *mp_ping;
8010 M (IP_MTABLE_DUMP, mp);
8013 /* Use a control ping for synchronization */
8014 MPING (CONTROL_PING, mp_ping);
8022 api_ip_mroute_dump (vat_main_t * vam)
8024 unformat_input_t *input = vam->input;
8025 vl_api_control_ping_t *mp_ping;
8026 vl_api_ip_mroute_dump_t *mp;
8031 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8033 if (unformat (input, "table_id %d", &table_id))
8035 else if (unformat (input, "ip6"))
8037 else if (unformat (input, "ip4"))
8044 errmsg ("missing table id");
8048 M (IP_MROUTE_DUMP, mp);
8049 mp->table.table_id = table_id;
8050 mp->table.is_ip6 = is_ip6;
8053 /* Use a control ping for synchronization */
8054 MPING (CONTROL_PING, mp_ping);
8061 #define vl_api_ip_route_details_t_endian vl_noop_handler
8062 #define vl_api_ip_route_details_t_print vl_noop_handler
8065 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
8067 vat_main_t *vam = &vat_main;
8068 u8 count = mp->route.n_paths;
8069 vl_api_fib_path_t *fp;
8073 "table-id %d, prefix %U/%d",
8074 ntohl (mp->route.table_id),
8075 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
8076 for (i = 0; i < count; i++)
8078 fp = &mp->route.paths[i];
8080 vl_api_fib_path_print (vam, fp);
8085 static void vl_api_ip_route_details_t_handler_json
8086 (vl_api_ip_route_details_t * mp)
8088 vat_main_t *vam = &vat_main;
8089 u8 count = mp->route.n_paths;
8090 vat_json_node_t *node = NULL;
8092 struct in6_addr ip6;
8093 vl_api_fib_path_t *fp;
8096 if (VAT_JSON_ARRAY != vam->json_tree.type)
8098 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8099 vat_json_init_array (&vam->json_tree);
8101 node = vat_json_array_add (&vam->json_tree);
8103 vat_json_init_object (node);
8104 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
8105 if (ADDRESS_IP6 == mp->route.prefix.address.af)
8107 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
8108 vat_json_object_add_ip6 (node, "prefix", ip6);
8112 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
8113 vat_json_object_add_ip4 (node, "prefix", ip4);
8115 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
8116 vat_json_object_add_uint (node, "path_count", count);
8117 for (i = 0; i < count; i++)
8119 fp = &mp->route.paths[i];
8120 vl_api_mpls_fib_path_json_print (node, fp);
8125 api_ip_route_dump (vat_main_t * vam)
8127 unformat_input_t *input = vam->input;
8128 vl_api_ip_route_dump_t *mp;
8129 vl_api_control_ping_t *mp_ping;
8135 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8137 if (unformat (input, "table_id %d", &table_id))
8139 else if (unformat (input, "ip6"))
8141 else if (unformat (input, "ip4"))
8148 errmsg ("missing table id");
8152 M (IP_ROUTE_DUMP, mp);
8154 mp->table.table_id = table_id;
8155 mp->table.is_ip6 = is_ip6;
8159 /* Use a control ping for synchronization */
8160 MPING (CONTROL_PING, mp_ping);
8168 api_sw_interface_span_enable_disable (vat_main_t * vam)
8170 unformat_input_t *i = vam->input;
8171 vl_api_sw_interface_span_enable_disable_t *mp;
8172 u32 src_sw_if_index = ~0;
8173 u32 dst_sw_if_index = ~0;
8178 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8181 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
8183 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
8187 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
8189 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
8191 else if (unformat (i, "disable"))
8193 else if (unformat (i, "rx"))
8195 else if (unformat (i, "tx"))
8197 else if (unformat (i, "both"))
8199 else if (unformat (i, "l2"))
8205 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
8207 mp->sw_if_index_from = htonl (src_sw_if_index);
8208 mp->sw_if_index_to = htonl (dst_sw_if_index);
8218 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
8221 vat_main_t *vam = &vat_main;
8222 u8 *sw_if_from_name = 0;
8223 u8 *sw_if_to_name = 0;
8224 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
8225 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
8226 char *states[] = { "none", "rx", "tx", "both" };
8230 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
8232 if ((u32) p->value[0] == sw_if_index_from)
8234 sw_if_from_name = (u8 *)(p->key);
8238 if ((u32) p->value[0] == sw_if_index_to)
8240 sw_if_to_name = (u8 *)(p->key);
8241 if (sw_if_from_name)
8246 print (vam->ofp, "%20s => %20s (%s) %s",
8247 sw_if_from_name, sw_if_to_name, states[mp->state],
8248 mp->is_l2 ? "l2" : "device");
8252 vl_api_sw_interface_span_details_t_handler_json
8253 (vl_api_sw_interface_span_details_t * mp)
8255 vat_main_t *vam = &vat_main;
8256 vat_json_node_t *node = NULL;
8257 u8 *sw_if_from_name = 0;
8258 u8 *sw_if_to_name = 0;
8259 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
8260 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
8264 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
8266 if ((u32) p->value[0] == sw_if_index_from)
8268 sw_if_from_name = (u8 *)(p->key);
8272 if ((u32) p->value[0] == sw_if_index_to)
8274 sw_if_to_name = (u8 *)(p->key);
8275 if (sw_if_from_name)
8281 if (VAT_JSON_ARRAY != vam->json_tree.type)
8283 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8284 vat_json_init_array (&vam->json_tree);
8286 node = vat_json_array_add (&vam->json_tree);
8288 vat_json_init_object (node);
8289 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
8290 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
8291 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
8292 if (0 != sw_if_to_name)
8294 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
8296 vat_json_object_add_uint (node, "state", mp->state);
8297 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
8301 api_sw_interface_span_dump (vat_main_t * vam)
8303 unformat_input_t *input = vam->input;
8304 vl_api_sw_interface_span_dump_t *mp;
8305 vl_api_control_ping_t *mp_ping;
8309 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8311 if (unformat (input, "l2"))
8317 M (SW_INTERFACE_SPAN_DUMP, mp);
8321 /* Use a control ping for synchronization */
8322 MPING (CONTROL_PING, mp_ping);
8330 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
8332 unformat_input_t *input = vam->input;
8333 vl_api_ip_source_and_port_range_check_add_del_t *mp;
8336 u16 *high_ports = 0;
8339 vl_api_prefix_t prefix;
8346 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8348 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
8350 else if (unformat (input, "vrf %d", &vrf_id))
8352 else if (unformat (input, "del"))
8354 else if (unformat (input, "port %d", &tmp))
8356 if (tmp == 0 || tmp > 65535)
8358 errmsg ("port %d out of range", tmp);
8362 this_hi = this_low + 1;
8363 vec_add1 (low_ports, this_low);
8364 vec_add1 (high_ports, this_hi);
8366 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
8368 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
8370 errmsg ("incorrect range parameters");
8374 /* Note: in debug CLI +1 is added to high before
8375 passing to real fn that does "the work"
8376 (ip_source_and_port_range_check_add_del).
8377 This fn is a wrapper around the binary API fn a
8378 control plane will call, which expects this increment
8379 to have occurred. Hence letting the binary API control
8380 plane fn do the increment for consistency between VAT
8381 and other control planes.
8384 vec_add1 (low_ports, this_low);
8385 vec_add1 (high_ports, this_hi);
8391 if (prefix_set == 0)
8393 errmsg ("<address>/<mask> not specified");
8399 errmsg ("VRF ID required, not specified");
8406 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
8410 if (vec_len (low_ports) == 0)
8412 errmsg ("At least one port or port range required");
8416 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
8418 mp->is_add = is_add;
8420 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
8422 mp->number_of_ranges = vec_len (low_ports);
8424 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
8425 vec_free (low_ports);
8427 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
8428 vec_free (high_ports);
8430 mp->vrf_id = ntohl (vrf_id);
8438 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
8440 unformat_input_t *input = vam->input;
8441 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
8442 u32 sw_if_index = ~0;
8444 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
8445 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
8449 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
8451 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8453 else if (unformat (input, "sw_if_index %d", &sw_if_index))
8455 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
8457 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
8459 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
8461 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
8463 else if (unformat (input, "del"))
8469 if (sw_if_index == ~0)
8471 errmsg ("Interface required but not specified");
8477 errmsg ("VRF ID required but not specified");
8481 if (tcp_out_vrf_id == 0
8482 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
8485 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
8489 /* Construct the API message */
8490 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
8492 mp->sw_if_index = ntohl (sw_if_index);
8493 mp->is_add = is_add;
8494 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
8495 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
8496 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
8497 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
8502 /* Wait for a reply... */
8508 api_set_punt (vat_main_t * vam)
8510 unformat_input_t *i = vam->input;
8511 vl_api_address_family_t af;
8512 vl_api_set_punt_t *mp;
8518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8520 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
8522 else if (unformat (i, "protocol %d", &protocol))
8524 else if (unformat (i, "port %d", &port))
8526 else if (unformat (i, "del"))
8530 clib_warning ("parse error '%U'", format_unformat_error, i);
8537 mp->is_add = (u8) is_add;
8538 mp->punt.type = PUNT_API_TYPE_L4;
8539 mp->punt.punt.l4.af = af;
8540 mp->punt.punt.l4.protocol = (u8) protocol;
8541 mp->punt.punt.l4.port = htons ((u16) port);
8549 api_delete_subif (vat_main_t * vam)
8551 unformat_input_t *i = vam->input;
8552 vl_api_delete_subif_t *mp;
8553 u32 sw_if_index = ~0;
8556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8558 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8560 if (unformat (i, "sw_if_index %d", &sw_if_index))
8566 if (sw_if_index == ~0)
8568 errmsg ("missing sw_if_index");
8572 /* Construct the API message */
8573 M (DELETE_SUBIF, mp);
8574 mp->sw_if_index = ntohl (sw_if_index);
8581 #define foreach_pbb_vtr_op \
8582 _("disable", L2_VTR_DISABLED) \
8583 _("pop", L2_VTR_POP_2) \
8584 _("push", L2_VTR_PUSH_2)
8587 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
8589 unformat_input_t *i = vam->input;
8590 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
8591 u32 sw_if_index = ~0, vtr_op = ~0;
8593 u8 dmac[6], smac[6];
8594 u8 dmac_set = 0, smac_set = 0;
8600 /* Shut up coverity */
8601 clib_memset (dmac, 0, sizeof (dmac));
8602 clib_memset (smac, 0, sizeof (smac));
8604 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8606 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8608 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8610 else if (unformat (i, "vtr_op %d", &vtr_op))
8612 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
8615 else if (unformat (i, "translate_pbb_stag"))
8617 if (unformat (i, "%d", &tmp))
8619 vtr_op = L2_VTR_TRANSLATE_2_1;
8625 ("translate_pbb_stag operation requires outer tag definition");
8629 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
8631 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
8633 else if (unformat (i, "sid %d", &sid))
8635 else if (unformat (i, "vlanid %d", &tmp))
8639 clib_warning ("parse error '%U'", format_unformat_error, i);
8644 if ((sw_if_index == ~0) || (vtr_op == ~0))
8646 errmsg ("missing sw_if_index or vtr operation");
8649 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
8650 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
8653 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
8657 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
8658 mp->sw_if_index = ntohl (sw_if_index);
8659 mp->vtr_op = ntohl (vtr_op);
8660 mp->outer_tag = ntohs (outer_tag);
8661 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
8662 clib_memcpy (mp->b_smac, smac, sizeof (smac));
8663 mp->b_vlanid = ntohs (vlanid);
8664 mp->i_sid = ntohl (sid);
8672 api_sw_interface_tag_add_del (vat_main_t * vam)
8674 unformat_input_t *i = vam->input;
8675 vl_api_sw_interface_tag_add_del_t *mp;
8676 u32 sw_if_index = ~0;
8681 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8683 if (unformat (i, "tag %s", &tag))
8685 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8687 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8689 else if (unformat (i, "del"))
8695 if (sw_if_index == ~0)
8697 errmsg ("missing interface name or sw_if_index");
8701 if (enable && (tag == 0))
8703 errmsg ("no tag specified");
8707 /* Construct the API message */
8708 M (SW_INTERFACE_TAG_ADD_DEL, mp);
8709 mp->sw_if_index = ntohl (sw_if_index);
8710 mp->is_add = enable;
8712 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8721 api_sw_interface_add_del_mac_address (vat_main_t * vam)
8723 unformat_input_t *i = vam->input;
8724 vl_api_mac_address_t mac = { 0 };
8725 vl_api_sw_interface_add_del_mac_address_t *mp;
8726 u32 sw_if_index = ~0;
8731 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8733 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8735 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8737 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
8739 else if (unformat (i, "del"))
8745 if (sw_if_index == ~0)
8747 errmsg ("missing interface name or sw_if_index");
8753 errmsg ("missing MAC address");
8757 /* Construct the API message */
8758 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
8759 mp->sw_if_index = ntohl (sw_if_index);
8760 mp->is_add = is_add;
8761 clib_memcpy (&mp->addr, &mac, sizeof (mac));
8768 static void vl_api_l2_xconnect_details_t_handler
8769 (vl_api_l2_xconnect_details_t * mp)
8771 vat_main_t *vam = &vat_main;
8773 print (vam->ofp, "%15d%15d",
8774 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
8777 static void vl_api_l2_xconnect_details_t_handler_json
8778 (vl_api_l2_xconnect_details_t * mp)
8780 vat_main_t *vam = &vat_main;
8781 vat_json_node_t *node = NULL;
8783 if (VAT_JSON_ARRAY != vam->json_tree.type)
8785 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8786 vat_json_init_array (&vam->json_tree);
8788 node = vat_json_array_add (&vam->json_tree);
8790 vat_json_init_object (node);
8791 vat_json_object_add_uint (node, "rx_sw_if_index",
8792 ntohl (mp->rx_sw_if_index));
8793 vat_json_object_add_uint (node, "tx_sw_if_index",
8794 ntohl (mp->tx_sw_if_index));
8798 api_l2_xconnect_dump (vat_main_t * vam)
8800 vl_api_l2_xconnect_dump_t *mp;
8801 vl_api_control_ping_t *mp_ping;
8804 if (!vam->json_output)
8806 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
8809 M (L2_XCONNECT_DUMP, mp);
8813 /* Use a control ping for synchronization */
8814 MPING (CONTROL_PING, mp_ping);
8822 api_hw_interface_set_mtu (vat_main_t * vam)
8824 unformat_input_t *i = vam->input;
8825 vl_api_hw_interface_set_mtu_t *mp;
8826 u32 sw_if_index = ~0;
8830 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8832 if (unformat (i, "mtu %d", &mtu))
8834 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8836 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8842 if (sw_if_index == ~0)
8844 errmsg ("missing interface name or sw_if_index");
8850 errmsg ("no mtu specified");
8854 /* Construct the API message */
8855 M (HW_INTERFACE_SET_MTU, mp);
8856 mp->sw_if_index = ntohl (sw_if_index);
8857 mp->mtu = ntohs ((u16) mtu);
8865 api_tcp_configure_src_addresses (vat_main_t * vam)
8867 vl_api_tcp_configure_src_addresses_t *mp;
8868 unformat_input_t *i = vam->input;
8869 vl_api_address_t first, last;
8874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8876 if (unformat (i, "%U - %U",
8877 unformat_vl_api_address, &first,
8878 unformat_vl_api_address, &last))
8882 errmsg ("one range per message (range already set)");
8887 else if (unformat (i, "vrf %d", &vrf_id))
8895 errmsg ("address range not set");
8899 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
8901 mp->vrf_id = ntohl (vrf_id);
8902 clib_memcpy (&mp->first_address, &first, sizeof (first));
8903 clib_memcpy (&mp->last_address, &last, sizeof (last));
8910 static void vl_api_app_namespace_add_del_reply_t_handler
8911 (vl_api_app_namespace_add_del_reply_t * mp)
8913 vat_main_t *vam = &vat_main;
8914 i32 retval = ntohl (mp->retval);
8915 if (vam->async_mode)
8917 vam->async_errors += (retval < 0);
8921 vam->retval = retval;
8923 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
8924 vam->result_ready = 1;
8928 static void vl_api_app_namespace_add_del_reply_t_handler_json
8929 (vl_api_app_namespace_add_del_reply_t * mp)
8931 vat_main_t *vam = &vat_main;
8932 vat_json_node_t node;
8934 vat_json_init_object (&node);
8935 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
8936 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
8938 vat_json_print (vam->ofp, &node);
8939 vat_json_free (&node);
8941 vam->retval = ntohl (mp->retval);
8942 vam->result_ready = 1;
8946 api_app_namespace_add_del (vat_main_t * vam)
8948 vl_api_app_namespace_add_del_t *mp;
8949 unformat_input_t *i = vam->input;
8950 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
8951 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
8955 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8957 if (unformat (i, "id %_%v%_", &ns_id))
8959 else if (unformat (i, "secret %lu", &secret))
8961 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8962 sw_if_index_set = 1;
8963 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
8965 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
8970 if (!ns_id || !secret_set || !sw_if_index_set)
8972 errmsg ("namespace id, secret and sw_if_index must be set");
8975 if (vec_len (ns_id) > 64)
8977 errmsg ("namespace id too long");
8980 M (APP_NAMESPACE_ADD_DEL, mp);
8982 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
8983 mp->secret = clib_host_to_net_u64 (secret);
8984 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
8985 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
8986 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
8994 api_sock_init_shm (vat_main_t * vam)
8996 #if VPP_API_TEST_BUILTIN == 0
8997 unformat_input_t *i = vam->input;
8998 vl_api_shm_elem_config_t *config = 0;
8999 u64 size = 64 << 20;
9002 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9004 if (unformat (i, "size %U", unformat_memory_size, &size))
9011 * Canned custom ring allocator config.
9012 * Should probably parse all of this
9014 vec_validate (config, 6);
9015 config[0].type = VL_API_VLIB_RING;
9016 config[0].size = 256;
9017 config[0].count = 32;
9019 config[1].type = VL_API_VLIB_RING;
9020 config[1].size = 1024;
9021 config[1].count = 16;
9023 config[2].type = VL_API_VLIB_RING;
9024 config[2].size = 4096;
9025 config[2].count = 2;
9027 config[3].type = VL_API_CLIENT_RING;
9028 config[3].size = 256;
9029 config[3].count = 32;
9031 config[4].type = VL_API_CLIENT_RING;
9032 config[4].size = 1024;
9033 config[4].count = 16;
9035 config[5].type = VL_API_CLIENT_RING;
9036 config[5].size = 4096;
9037 config[5].count = 2;
9039 config[6].type = VL_API_QUEUE;
9040 config[6].count = 128;
9041 config[6].size = sizeof (uword);
9043 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
9045 vam->client_index_invalid = 1;
9053 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
9055 vat_main_t *vam = &vat_main;
9056 fib_prefix_t lcl, rmt;
9058 ip_prefix_decode (&mp->lcl, &lcl);
9059 ip_prefix_decode (&mp->rmt, &rmt);
9061 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
9064 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
9065 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
9066 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
9067 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
9068 &rmt.fp_addr.ip4, rmt.fp_len,
9069 clib_net_to_host_u16 (mp->rmt_port),
9070 clib_net_to_host_u32 (mp->action_index), mp->tag);
9075 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
9076 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
9077 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
9078 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
9079 &rmt.fp_addr.ip6, rmt.fp_len,
9080 clib_net_to_host_u16 (mp->rmt_port),
9081 clib_net_to_host_u32 (mp->action_index), mp->tag);
9086 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
9089 vat_main_t *vam = &vat_main;
9090 vat_json_node_t *node = NULL;
9091 struct in6_addr ip6;
9094 fib_prefix_t lcl, rmt;
9096 ip_prefix_decode (&mp->lcl, &lcl);
9097 ip_prefix_decode (&mp->rmt, &rmt);
9099 if (VAT_JSON_ARRAY != vam->json_tree.type)
9101 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9102 vat_json_init_array (&vam->json_tree);
9104 node = vat_json_array_add (&vam->json_tree);
9105 vat_json_init_object (node);
9107 vat_json_object_add_uint (node, "appns_index",
9108 clib_net_to_host_u32 (mp->appns_index));
9109 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
9110 vat_json_object_add_uint (node, "scope", mp->scope);
9111 vat_json_object_add_uint (node, "action_index",
9112 clib_net_to_host_u32 (mp->action_index));
9113 vat_json_object_add_uint (node, "lcl_port",
9114 clib_net_to_host_u16 (mp->lcl_port));
9115 vat_json_object_add_uint (node, "rmt_port",
9116 clib_net_to_host_u16 (mp->rmt_port));
9117 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
9118 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
9119 vat_json_object_add_string_copy (node, "tag", mp->tag);
9120 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
9122 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
9123 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
9124 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
9125 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
9129 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
9130 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
9131 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
9132 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
9137 api_session_rule_add_del (vat_main_t * vam)
9139 vl_api_session_rule_add_del_t *mp;
9140 unformat_input_t *i = vam->input;
9141 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
9142 u32 appns_index = 0, scope = 0;
9143 ip4_address_t lcl_ip4, rmt_ip4;
9144 ip6_address_t lcl_ip6, rmt_ip6;
9145 u8 is_ip4 = 1, conn_set = 0;
9146 u8 is_add = 1, *tag = 0;
9148 fib_prefix_t lcl, rmt;
9150 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9152 if (unformat (i, "del"))
9154 else if (unformat (i, "add"))
9156 else if (unformat (i, "proto tcp"))
9158 else if (unformat (i, "proto udp"))
9160 else if (unformat (i, "appns %d", &appns_index))
9162 else if (unformat (i, "scope %d", &scope))
9164 else if (unformat (i, "tag %_%v%_", &tag))
9168 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
9169 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
9177 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
9178 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
9184 else if (unformat (i, "action %d", &action))
9189 if (proto == ~0 || !conn_set || action == ~0)
9191 errmsg ("transport proto, connection and action must be set");
9197 errmsg ("scope should be 0-3");
9201 M (SESSION_RULE_ADD_DEL, mp);
9203 clib_memset (&lcl, 0, sizeof (lcl));
9204 clib_memset (&rmt, 0, sizeof (rmt));
9207 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
9208 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
9209 lcl.fp_len = lcl_plen;
9210 rmt.fp_len = rmt_plen;
9214 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
9215 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
9216 lcl.fp_len = lcl_plen;
9217 rmt.fp_len = rmt_plen;
9221 ip_prefix_encode (&lcl, &mp->lcl);
9222 ip_prefix_encode (&rmt, &mp->rmt);
9223 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
9224 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
9225 mp->transport_proto =
9226 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
9227 mp->action_index = clib_host_to_net_u32 (action);
9228 mp->appns_index = clib_host_to_net_u32 (appns_index);
9230 mp->is_add = is_add;
9233 clib_memcpy (mp->tag, tag, vec_len (tag));
9243 api_session_rules_dump (vat_main_t * vam)
9245 vl_api_session_rules_dump_t *mp;
9246 vl_api_control_ping_t *mp_ping;
9249 if (!vam->json_output)
9251 print (vam->ofp, "%=20s", "Session Rules");
9254 M (SESSION_RULES_DUMP, mp);
9258 /* Use a control ping for synchronization */
9259 MPING (CONTROL_PING, mp_ping);
9262 /* Wait for a reply... */
9268 api_ip_container_proxy_add_del (vat_main_t * vam)
9270 vl_api_ip_container_proxy_add_del_t *mp;
9271 unformat_input_t *i = vam->input;
9272 u32 sw_if_index = ~0;
9273 vl_api_prefix_t pfx = { };
9277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9279 if (unformat (i, "del"))
9281 else if (unformat (i, "add"))
9283 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
9285 else if (unformat (i, "sw_if_index %u", &sw_if_index))
9290 if (sw_if_index == ~0 || pfx.len == 0)
9292 errmsg ("address and sw_if_index must be set");
9296 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
9298 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
9299 mp->is_add = is_add;
9300 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
9308 q_or_quit (vat_main_t * vam)
9310 #if VPP_API_TEST_BUILTIN == 0
9311 longjmp (vam->jump_buf, 1);
9313 return 0; /* not so much */
9317 q (vat_main_t * vam)
9319 return q_or_quit (vam);
9323 quit (vat_main_t * vam)
9325 return q_or_quit (vam);
9329 comment (vat_main_t * vam)
9335 elog_save (vat_main_t * vam)
9337 #if VPP_API_TEST_BUILTIN == 0
9338 elog_main_t *em = &vam->elog_main;
9339 unformat_input_t *i = vam->input;
9340 char *file, *chroot_file;
9341 clib_error_t *error;
9343 if (!unformat (i, "%s", &file))
9345 errmsg ("expected file name, got `%U'", format_unformat_error, i);
9349 /* It's fairly hard to get "../oopsie" through unformat; just in case */
9350 if (strstr (file, "..") || index (file, '/'))
9352 errmsg ("illegal characters in filename '%s'", file);
9356 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
9360 errmsg ("Saving %wd of %wd events to %s",
9361 elog_n_events_in_buffer (em),
9362 elog_buffer_capacity (em), chroot_file);
9364 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
9365 vec_free (chroot_file);
9368 clib_error_report (error);
9370 errmsg ("Use the vpp event loger...");
9377 elog_setup (vat_main_t * vam)
9379 #if VPP_API_TEST_BUILTIN == 0
9380 elog_main_t *em = &vam->elog_main;
9381 unformat_input_t *i = vam->input;
9382 u32 nevents = 128 << 10;
9384 (void) unformat (i, "nevents %d", &nevents);
9386 elog_init (em, nevents);
9387 vl_api_set_elog_main (em);
9388 vl_api_set_elog_trace_api_messages (1);
9389 errmsg ("Event logger initialized with %u events", nevents);
9391 errmsg ("Use the vpp event loger...");
9397 elog_enable (vat_main_t * vam)
9399 #if VPP_API_TEST_BUILTIN == 0
9400 elog_main_t *em = &vam->elog_main;
9402 elog_enable_disable (em, 1 /* enable */ );
9403 vl_api_set_elog_trace_api_messages (1);
9404 errmsg ("Event logger enabled...");
9406 errmsg ("Use the vpp event loger...");
9412 elog_disable (vat_main_t * vam)
9414 #if VPP_API_TEST_BUILTIN == 0
9415 elog_main_t *em = &vam->elog_main;
9417 elog_enable_disable (em, 0 /* enable */ );
9418 vl_api_set_elog_trace_api_messages (1);
9419 errmsg ("Event logger disabled...");
9421 errmsg ("Use the vpp event loger...");
9427 statseg (vat_main_t * vam)
9429 ssvm_private_t *ssvmp = &vam->stat_segment;
9430 ssvm_shared_header_t *shared_header = ssvmp->sh;
9431 vlib_counter_t **counters;
9432 u64 thread0_index1_packets;
9433 u64 thread0_index1_bytes;
9434 f64 vector_rate, input_rate;
9437 uword *counter_vector_by_name;
9438 if (vam->stat_segment_lockp == 0)
9440 errmsg ("Stat segment not mapped...");
9444 /* look up "/if/rx for sw_if_index 1 as a test */
9446 clib_spinlock_lock (vam->stat_segment_lockp);
9448 counter_vector_by_name = (uword *) shared_header->opaque[1];
9450 p = hash_get_mem (counter_vector_by_name, "/if/rx");
9453 clib_spinlock_unlock (vam->stat_segment_lockp);
9454 errmsg ("/if/tx not found?");
9458 /* Fish per-thread vector of combined counters from shared memory */
9459 counters = (vlib_counter_t **) p[0];
9461 if (vec_len (counters[0]) < 2)
9463 clib_spinlock_unlock (vam->stat_segment_lockp);
9464 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
9468 /* Read thread 0 sw_if_index 1 counter */
9469 thread0_index1_packets = counters[0][1].packets;
9470 thread0_index1_bytes = counters[0][1].bytes;
9472 p = hash_get_mem (counter_vector_by_name, "vector_rate");
9475 clib_spinlock_unlock (vam->stat_segment_lockp);
9476 errmsg ("vector_rate not found?");
9480 vector_rate = *(f64 *) (p[0]);
9481 p = hash_get_mem (counter_vector_by_name, "input_rate");
9484 clib_spinlock_unlock (vam->stat_segment_lockp);
9485 errmsg ("input_rate not found?");
9488 input_rate = *(f64 *) (p[0]);
9490 clib_spinlock_unlock (vam->stat_segment_lockp);
9492 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
9493 vector_rate, input_rate);
9494 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
9495 thread0_index1_packets, thread0_index1_bytes);
9501 cmd_cmp (void *a1, void *a2)
9506 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
9510 help (vat_main_t * vam)
9515 unformat_input_t *i = vam->input;
9518 if (unformat (i, "%s", &name))
9524 hs = hash_get_mem (vam->help_by_name, name);
9526 print (vam->ofp, "usage: %s %s", name, hs[0]);
9528 print (vam->ofp, "No such msg / command '%s'", name);
9533 print (vam->ofp, "Help is available for the following:");
9536 hash_foreach_pair (p, vam->function_by_name,
9538 vec_add1 (cmds, (u8 *)(p->key));
9542 vec_sort_with_function (cmds, cmd_cmp);
9544 for (j = 0; j < vec_len (cmds); j++)
9545 print (vam->ofp, "%s", cmds[j]);
9552 set (vat_main_t * vam)
9554 u8 *name = 0, *value = 0;
9555 unformat_input_t *i = vam->input;
9557 if (unformat (i, "%s", &name))
9559 /* The input buffer is a vector, not a string. */
9560 value = vec_dup (i->buffer);
9561 vec_delete (value, i->index, 0);
9562 /* Almost certainly has a trailing newline */
9563 if (value[vec_len (value) - 1] == '\n')
9564 value[vec_len (value) - 1] = 0;
9565 /* Make sure it's a proper string, one way or the other */
9566 vec_add1 (value, 0);
9567 (void) clib_macro_set_value (&vam->macro_main,
9568 (char *) name, (char *) value);
9571 errmsg ("usage: set <name> <value>");
9579 unset (vat_main_t * vam)
9583 if (unformat (vam->input, "%s", &name))
9584 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
9585 errmsg ("unset: %s wasn't set", name);
9598 macro_sort_cmp (void *a1, void *a2)
9600 macro_sort_t *s1 = a1;
9601 macro_sort_t *s2 = a2;
9603 return strcmp ((char *) (s1->name), (char *) (s2->name));
9607 dump_macro_table (vat_main_t * vam)
9609 macro_sort_t *sort_me = 0, *sm;
9614 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
9616 vec_add2 (sort_me, sm, 1);
9617 sm->name = (u8 *)(p->key);
9618 sm->value = (u8 *) (p->value[0]);
9622 vec_sort_with_function (sort_me, macro_sort_cmp);
9624 if (vec_len (sort_me))
9625 print (vam->ofp, "%-15s%s", "Name", "Value");
9627 print (vam->ofp, "The macro table is empty...");
9629 for (i = 0; i < vec_len (sort_me); i++)
9630 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
9635 dump_node_table (vat_main_t * vam)
9638 vlib_node_t *node, *next_node;
9640 if (vec_len (vam->graph_nodes) == 0)
9642 print (vam->ofp, "Node table empty, issue get_node_graph...");
9646 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
9648 node = vam->graph_nodes[0][i];
9649 print (vam->ofp, "[%d] %s", i, node->name);
9650 for (j = 0; j < vec_len (node->next_nodes); j++)
9652 if (node->next_nodes[j] != ~0)
9654 next_node = vam->graph_nodes[0][node->next_nodes[j]];
9655 print (vam->ofp, " [%d] %s", j, next_node->name);
9663 value_sort_cmp (void *a1, void *a2)
9665 name_sort_t *n1 = a1;
9666 name_sort_t *n2 = a2;
9668 if (n1->value < n2->value)
9670 if (n1->value > n2->value)
9677 dump_msg_api_table (vat_main_t * vam)
9679 api_main_t *am = vlibapi_get_main ();
9680 name_sort_t *nses = 0, *ns;
9685 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
9687 vec_add2 (nses, ns, 1);
9688 ns->name = (u8 *)(hp->key);
9689 ns->value = (u32) hp->value[0];
9693 vec_sort_with_function (nses, value_sort_cmp);
9695 for (i = 0; i < vec_len (nses); i++)
9696 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
9702 get_msg_id (vat_main_t * vam)
9707 if (unformat (vam->input, "%s", &name_and_crc))
9709 message_index = vl_msg_api_get_msg_index (name_and_crc);
9710 if (message_index == ~0)
9712 print (vam->ofp, " '%s' not found", name_and_crc);
9715 print (vam->ofp, " '%s' has message index %d",
9716 name_and_crc, message_index);
9719 errmsg ("name_and_crc required...");
9724 search_node_table (vat_main_t * vam)
9726 unformat_input_t *line_input = vam->input;
9729 vlib_node_t *node, *next_node;
9732 if (vam->graph_node_index_by_name == 0)
9734 print (vam->ofp, "Node table empty, issue get_node_graph...");
9738 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
9740 if (unformat (line_input, "%s", &node_to_find))
9742 vec_add1 (node_to_find, 0);
9743 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
9746 print (vam->ofp, "%s not found...", node_to_find);
9749 node = vam->graph_nodes[0][p[0]];
9750 print (vam->ofp, "[%d] %s", p[0], node->name);
9751 for (j = 0; j < vec_len (node->next_nodes); j++)
9753 if (node->next_nodes[j] != ~0)
9755 next_node = vam->graph_nodes[0][node->next_nodes[j]];
9756 print (vam->ofp, " [%d] %s", j, next_node->name);
9763 clib_warning ("parse error '%U'", format_unformat_error,
9769 vec_free (node_to_find);
9778 script (vat_main_t * vam)
9780 #if (VPP_API_TEST_BUILTIN==0)
9782 char *save_current_file;
9783 unformat_input_t save_input;
9784 jmp_buf save_jump_buf;
9785 u32 save_line_number;
9787 FILE *new_fp, *save_ifp;
9789 if (unformat (vam->input, "%s", &s))
9791 new_fp = fopen ((char *) s, "r");
9794 errmsg ("Couldn't open script file %s", s);
9801 errmsg ("Missing script name");
9805 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
9806 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
9807 save_ifp = vam->ifp;
9808 save_line_number = vam->input_line_number;
9809 save_current_file = (char *) vam->current_file;
9811 vam->input_line_number = 0;
9813 vam->current_file = s;
9816 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
9817 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
9818 vam->ifp = save_ifp;
9819 vam->input_line_number = save_line_number;
9820 vam->current_file = (u8 *) save_current_file;
9825 clib_warning ("use the exec command...");
9831 echo (vat_main_t * vam)
9833 print (vam->ofp, "%v", vam->input->buffer);
9837 /* List of API message constructors, CLI names map to api_xxx */
9838 #define foreach_vpe_api_msg \
9839 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
9840 _(sw_interface_dump,"") \
9841 _(sw_interface_set_flags, \
9842 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
9843 _(sw_interface_add_del_address, \
9844 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
9845 _(sw_interface_set_rx_mode, \
9846 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
9847 _(sw_interface_set_rx_placement, \
9848 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
9849 _(sw_interface_rx_placement_dump, \
9850 "[<intfc> | sw_if_index <id>]") \
9851 _(sw_interface_set_table, \
9852 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
9853 _(sw_interface_set_mpls_enable, \
9854 "<intfc> | sw_if_index [disable | dis]") \
9855 _(sw_interface_set_vpath, \
9856 "<intfc> | sw_if_index <id> enable | disable") \
9857 _(sw_interface_set_l2_xconnect, \
9858 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
9859 "enable | disable") \
9860 _(sw_interface_set_l2_bridge, \
9861 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
9862 "[shg <split-horizon-group>] [bvi]\n" \
9863 "enable | disable") \
9864 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
9865 _(bridge_domain_add_del, \
9866 "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") \
9867 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
9869 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
9870 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
9871 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
9873 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
9875 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
9876 _(virtio_pci_create_v2, \
9877 "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]") \
9878 _(virtio_pci_delete, \
9879 "<vpp-if-name> | sw_if_index <id>") \
9880 _(sw_interface_virtio_pci_dump, "") \
9881 _(ip_table_add_del, \
9882 "table <n> [ipv6] [add | del]\n") \
9883 _(ip_route_add_del, \
9884 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
9885 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
9886 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
9887 "[multipath] [count <n>] [del]") \
9888 _(ip_mroute_add_del, \
9889 "<src> <grp>/<mask> [table-id <n>]\n" \
9890 "[<intfc> | sw_if_index <id>] [local] [del]") \
9891 _(mpls_table_add_del, \
9892 "table <n> [add | del]\n") \
9893 _(mpls_route_add_del, \
9894 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
9895 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
9896 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
9897 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
9898 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
9899 "[count <n>] [del]") \
9900 _(mpls_ip_bind_unbind, \
9901 "<label> <addr/len>") \
9902 _(mpls_tunnel_add_del, \
9903 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
9904 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
9905 "[l2-only] [out-label <n>]") \
9906 _(sw_interface_set_unnumbered, \
9907 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
9908 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
9909 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
9910 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
9911 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
9912 "[outer_vlan_id_any][inner_vlan_id_any]") \
9913 _(ip_table_replace_begin, "table <n> [ipv6]") \
9914 _(ip_table_flush, "table <n> [ipv6]") \
9915 _(ip_table_replace_end, "table <n> [ipv6]") \
9916 _(set_ip_flow_hash, \
9917 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
9918 _(sw_interface_ip6_enable_disable, \
9919 "<intfc> | sw_if_index <id> enable | disable") \
9920 _(l2_patch_add_del, \
9921 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
9922 "enable | disable") \
9923 _(get_node_index, "node <node-name") \
9924 _(add_node_next, "node <node-name> next <next-node-name>") \
9925 _(l2_fib_clear_table, "") \
9926 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
9927 _(l2_interface_vlan_tag_rewrite, \
9928 "<intfc> | sw_if_index <nn> \n" \
9929 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
9930 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
9931 _(create_vhost_user_if, \
9932 "socket <filename> [server] [renumber <dev_instance>] " \
9933 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
9934 "[mac <mac_address>] [packed]") \
9935 _(modify_vhost_user_if, \
9936 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9937 "[server] [renumber <dev_instance>] [gso] [packed]") \
9938 _(create_vhost_user_if_v2, \
9939 "socket <filename> [server] [renumber <dev_instance>] " \
9940 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
9941 "[mac <mac_address>] [packed] [event-idx]") \
9942 _(modify_vhost_user_if_v2, \
9943 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9944 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
9945 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
9946 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
9947 _(show_version, "") \
9948 _(show_threads, "") \
9949 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
9950 _(interface_name_renumber, \
9951 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
9952 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
9953 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
9954 _(ip_dump, "ipv4 | ipv6") \
9955 _(delete_loopback,"sw_if_index <nn>") \
9956 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
9957 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
9958 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
9959 _(want_interface_events, "enable|disable") \
9960 _(get_first_msg_id, "client <name>") \
9961 _(get_node_graph, " ") \
9962 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
9963 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
9964 _(ioam_disable, "") \
9965 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
9966 _(af_packet_delete, "name <host interface name>") \
9967 _(af_packet_dump, "") \
9968 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
9969 _(mpls_table_dump, "") \
9970 _(mpls_route_dump, "table-id <ID>") \
9971 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
9972 _(sw_interface_span_dump, "[l2]") \
9973 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
9974 _(ip_source_and_port_range_check_add_del, \
9975 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
9976 _(ip_source_and_port_range_check_interface_add_del, \
9977 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
9978 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
9979 _(delete_subif,"<intfc> | sw_if_index <nn>") \
9980 _(l2_interface_pbb_tag_rewrite, \
9981 "<intfc> | sw_if_index <nn> \n" \
9982 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
9983 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
9984 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
9985 _(ip_table_dump, "") \
9986 _(ip_route_dump, "table-id [ip4|ip6]") \
9987 _(ip_mtable_dump, "") \
9988 _(ip_mroute_dump, "table-id [ip4|ip6]") \
9989 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
9991 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
9992 "mac <mac-address> [del]") \
9993 _(l2_xconnect_dump, "") \
9994 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
9995 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
9996 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
9997 _(sock_init_shm, "size <nnn>") \
9998 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
9999 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
10000 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
10001 _(session_rules_dump, "") \
10002 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
10004 /* List of command functions, CLI names map directly to functions */
10005 #define foreach_cli_function \
10006 _(comment, "usage: comment <ignore-rest-of-line>") \
10007 _(dump_interface_table, "usage: dump_interface_table") \
10008 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10009 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10010 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10011 _(dump_macro_table, "usage: dump_macro_table ") \
10012 _(dump_node_table, "usage: dump_node_table") \
10013 _(dump_msg_api_table, "usage: dump_msg_api_table") \
10014 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
10015 _(elog_disable, "usage: elog_disable") \
10016 _(elog_enable, "usage: elog_enable") \
10017 _(elog_save, "usage: elog_save <filename>") \
10018 _(get_msg_id, "usage: get_msg_id name_and_crc") \
10019 _(echo, "usage: echo <message>") \
10020 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10021 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
10022 _(help, "usage: help") \
10023 _(q, "usage: quit") \
10024 _(quit, "usage: quit") \
10025 _(search_node_table, "usage: search_node_table <name>...") \
10026 _(set, "usage: set <variable-name> <value>") \
10027 _(script, "usage: script <file-name>") \
10028 _(statseg, "usage: statseg") \
10029 _(unset, "usage: unset <variable-name>")
10032 static void vl_api_##n##_t_handler_uni \
10033 (vl_api_##n##_t * mp) \
10035 vat_main_t * vam = &vat_main; \
10036 if (vam->json_output) { \
10037 vl_api_##n##_t_handler_json(mp); \
10039 vl_api_##n##_t_handler(mp); \
10042 foreach_vpe_api_reply_msg;
10043 #if VPP_API_TEST_BUILTIN == 0
10044 foreach_standalone_reply_msg;
10049 vat_api_hookup (vat_main_t * vam)
10052 vl_msg_api_set_handlers(VL_API_##N, #n, \
10053 vl_api_##n##_t_handler_uni, \
10055 vl_api_##n##_t_endian, \
10056 vl_api_##n##_t_print, \
10057 sizeof(vl_api_##n##_t), 1);
10058 foreach_vpe_api_reply_msg;
10059 #if VPP_API_TEST_BUILTIN == 0
10060 foreach_standalone_reply_msg;
10064 #if (VPP_API_TEST_BUILTIN==0)
10065 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10067 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
10069 vam->function_by_name = hash_create_string (0, sizeof (uword));
10071 vam->help_by_name = hash_create_string (0, sizeof (uword));
10074 /* API messages we can send */
10075 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10076 foreach_vpe_api_msg;
10080 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10081 foreach_vpe_api_msg;
10084 /* CLI functions */
10085 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10086 foreach_cli_function;
10090 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10091 foreach_cli_function;
10095 #if VPP_API_TEST_BUILTIN
10096 static clib_error_t *
10097 vat_api_hookup_shim (vlib_main_t * vm)
10099 vat_api_hookup (&vat_main);
10103 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
10107 * fd.io coding-style-patch-verification: ON
10110 * eval: (c-set-style "gnu")