2 *------------------------------------------------------------------
5 * Copyright (c) 2014-2020 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlib/pci/pci.h>
22 #include <vpp/api/types.h>
23 #include <vppinfra/socket.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/ip-neighbor/ip_neighbor.h>
28 #include <vnet/ip/ip_types_api.h>
29 #include <vnet/l2/l2_input.h>
30 #include <vnet/udp/udp_local.h>
32 #include <vpp/api/vpe_msg_enum.h>
33 #include <vnet/l2/l2_classify.h>
34 #include <vnet/l2/l2_vtr.h>
35 #include <vnet/classify/in_out_acl.h>
36 #include <vnet/classify/policer_classify.h>
37 #include <vnet/classify/flow_classify.h>
38 #include <vnet/mpls/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
41 #include <vnet/ip/ip6_hop_by_hop.h>
42 #include <vnet/ip/ip_source_and_port_range_check.h>
43 #include <vnet/policer/xlate.h>
44 #include <vnet/span/span.h>
45 #include <vnet/policer/policer.h>
46 #include <vnet/policer/police.h>
47 #include <vnet/mfib/mfib_types.h>
48 #include <vnet/bonding/node.h>
49 #include <vnet/qos/qos_types.h>
50 #include <vnet/ethernet/ethernet_types_api.h>
51 #include <vnet/ip/ip_types_api.h>
52 #include "vat/json_format.h"
53 #include <vnet/ip/ip_types_api.h>
54 #include <vnet/ethernet/ethernet_types_api.h>
59 #define vl_typedefs /* define message structures */
60 #include <vpp/api/vpe_all_api_h.h>
63 /* declare message handlers for each api */
65 #define vl_endianfun /* define message structures */
66 #include <vpp/api/vpe_all_api_h.h>
69 /* instantiate all the print functions we know about */
70 #if VPP_API_TEST_BUILTIN == 0
71 #define vl_print(handle, ...)
73 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
76 #include <vpp/api/vpe_all_api_h.h>
79 #define __plugin_msg_base 0
80 #include <vlibapi/vat_helper_macros.h>
82 void vl_api_set_elog_main (elog_main_t * m);
83 int vl_api_set_elog_trace_api_messages (int enable);
85 #if VPP_API_TEST_BUILTIN == 0
95 vat_socket_connect (vat_main_t * vam)
98 api_main_t *am = vlibapi_get_main ();
99 vam->socket_client_main = &socket_client_main;
100 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
102 0 /* default socket rx, tx buffer */ )))
105 /* vpp expects the client index in network order */
106 vam->my_client_index = htonl (socket_client_main.client_index);
107 am->my_client_index = vam->my_client_index;
110 #else /* vpp built-in case, we don't do sockets... */
112 vat_socket_connect (vat_main_t * vam)
118 vl_socket_client_read (int wait)
124 vl_socket_client_write ()
130 vl_socket_client_msg_alloc (int nbytes)
138 vat_time_now (vat_main_t * vam)
140 #if VPP_API_TEST_BUILTIN
141 return vlib_time_now (vam->vlib_main);
143 return clib_time_now (&vam->clib_time);
148 errmsg (char *fmt, ...)
150 vat_main_t *vam = &vat_main;
155 s = va_format (0, fmt, &va);
160 #if VPP_API_TEST_BUILTIN
161 vlib_cli_output (vam->vlib_main, (char *) s);
164 if (vam->ifp != stdin)
165 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
166 vam->input_line_number);
168 fformat (vam->ofp, "%s\n", (char *) s);
176 #if VPP_API_TEST_BUILTIN == 0
178 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
180 vat_main_t *vam = va_arg (*args, vat_main_t *);
181 u32 *result = va_arg (*args, u32 *);
185 if (!unformat (input, "%s", &if_name))
188 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
195 /* Parse an IP4 address %d.%d.%d.%d. */
197 unformat_ip4_address (unformat_input_t * input, va_list * args)
199 u8 *result = va_arg (*args, u8 *);
202 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
205 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217 unformat_ethernet_address (unformat_input_t * input, va_list * args)
219 u8 *result = va_arg (*args, u8 *);
222 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
223 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
227 for (i = 0; i < 6; i++)
228 if (a[i] >= (1 << 8))
231 for (i = 0; i < 6; i++)
237 /* Returns ethernet type as an int in host byte order. */
239 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
242 u16 *result = va_arg (*args, u16 *);
246 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
248 if (type >= (1 << 16))
256 /* Parse an IP46 address. */
258 unformat_ip46_address (unformat_input_t * input, va_list * args)
260 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
261 ip46_type_t type = va_arg (*args, ip46_type_t);
262 if ((type != IP46_TYPE_IP6) &&
263 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
265 ip46_address_mask_ip4 (ip46);
268 else if ((type != IP46_TYPE_IP4) &&
269 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
276 /* Parse an IP6 address. */
278 unformat_ip6_address (unformat_input_t * input, va_list * args)
280 ip6_address_t *result = va_arg (*args, ip6_address_t *);
282 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
283 uword c, n_colon, double_colon_index;
285 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
286 double_colon_index = ARRAY_LEN (hex_quads);
287 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
290 if (c >= '0' && c <= '9')
292 else if (c >= 'a' && c <= 'f')
293 hex_digit = c + 10 - 'a';
294 else if (c >= 'A' && c <= 'F')
295 hex_digit = c + 10 - 'A';
296 else if (c == ':' && n_colon < 2)
300 unformat_put_input (input);
304 /* Too many hex quads. */
305 if (n_hex_quads >= ARRAY_LEN (hex_quads))
310 hex_quad = (hex_quad << 4) | hex_digit;
312 /* Hex quad must fit in 16 bits. */
313 if (n_hex_digits >= 4)
320 /* Save position of :: */
323 /* More than one :: ? */
324 if (double_colon_index < ARRAY_LEN (hex_quads))
326 double_colon_index = n_hex_quads;
329 if (n_colon > 0 && n_hex_digits > 0)
331 hex_quads[n_hex_quads++] = hex_quad;
337 if (n_hex_digits > 0)
338 hex_quads[n_hex_quads++] = hex_quad;
343 /* Expand :: to appropriate number of zero hex quads. */
344 if (double_colon_index < ARRAY_LEN (hex_quads))
346 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
348 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
349 hex_quads[n_zero + i] = hex_quads[i];
351 for (i = 0; i < n_zero; i++)
352 hex_quads[double_colon_index + i] = 0;
354 n_hex_quads = ARRAY_LEN (hex_quads);
357 /* Too few hex quads given. */
358 if (n_hex_quads < ARRAY_LEN (hex_quads))
361 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
362 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
369 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
371 u32 *r = va_arg (*args, u32 *);
374 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
375 foreach_ipsec_policy_action
383 format_ipsec_crypto_alg (u8 * s, va_list * args)
385 u32 i = va_arg (*args, u32);
390 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
391 foreach_ipsec_crypto_alg
394 return format (s, "unknown");
396 return format (s, "%s", t);
400 format_ipsec_integ_alg (u8 * s, va_list * args)
402 u32 i = va_arg (*args, u32);
407 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
408 foreach_ipsec_integ_alg
411 return format (s, "unknown");
413 return format (s, "%s", t);
416 #else /* VPP_API_TEST_BUILTIN == 1 */
418 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
420 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
421 vnet_main_t *vnm = vnet_get_main ();
422 u32 *result = va_arg (*args, u32 *);
424 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
427 #endif /* VPP_API_TEST_BUILTIN */
430 unformat_ipsec_api_crypto_alg (unformat_input_t * input, va_list * args)
432 u32 *r = va_arg (*args, u32 *);
435 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_CRYPTO_ALG_##f;
436 foreach_ipsec_crypto_alg
444 unformat_ipsec_api_integ_alg (unformat_input_t * input, va_list * args)
446 u32 *r = va_arg (*args, u32 *);
449 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_API_INTEG_ALG_##f;
450 foreach_ipsec_integ_alg
457 #if (VPP_API_TEST_BUILTIN==0)
459 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
460 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
461 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
462 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
465 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
467 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
468 mfib_itf_attribute_t attr;
471 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
473 if (unformat (input, mfib_itf_flag_long_names[attr]))
474 *iflags |= (1 << attr);
476 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
478 if (unformat (input, mfib_itf_flag_names[attr]))
479 *iflags |= (1 << attr);
482 return (old == *iflags ? 0 : 1);
486 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
488 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
489 mfib_entry_attribute_t attr;
492 FOR_EACH_MFIB_ATTRIBUTE (attr)
494 if (unformat (input, mfib_flag_long_names[attr]))
495 *eflags |= (1 << attr);
497 FOR_EACH_MFIB_ATTRIBUTE (attr)
499 if (unformat (input, mfib_flag_names[attr]))
500 *eflags |= (1 << attr);
503 return (old == *eflags ? 0 : 1);
507 format_ip4_address (u8 * s, va_list * args)
509 u8 *a = va_arg (*args, u8 *);
510 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
514 format_ip6_address (u8 * s, va_list * args)
516 ip6_address_t *a = va_arg (*args, ip6_address_t *);
517 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
519 i_max_n_zero = ARRAY_LEN (a->as_u16);
521 i_first_zero = i_max_n_zero;
523 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
525 u32 is_zero = a->as_u16[i] == 0;
526 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
532 if ((!is_zero && n_zeros > max_n_zeros)
533 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
535 i_max_n_zero = i_first_zero;
536 max_n_zeros = n_zeros;
537 i_first_zero = ARRAY_LEN (a->as_u16);
542 last_double_colon = 0;
543 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
545 if (i == i_max_n_zero && max_n_zeros > 1)
547 s = format (s, "::");
548 i += max_n_zeros - 1;
549 last_double_colon = 1;
553 s = format (s, "%s%x",
554 (last_double_colon || i == 0) ? "" : ":",
555 clib_net_to_host_u16 (a->as_u16[i]));
556 last_double_colon = 0;
563 /* Format an IP46 address. */
565 format_ip46_address (u8 * s, va_list * args)
567 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
568 ip46_type_t type = va_arg (*args, ip46_type_t);
574 is_ip4 = ip46_address_is_ip4 (ip46);
585 format (s, "%U", format_ip4_address, &ip46->ip4) :
586 format (s, "%U", format_ip6_address, &ip46->ip6);
590 format_ethernet_address (u8 * s, va_list * args)
592 u8 *a = va_arg (*args, u8 *);
594 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
595 a[0], a[1], a[2], a[3], a[4], a[5]);
600 increment_v4_address (vl_api_ip4_address_t * i)
602 ip4_address_t *a = (ip4_address_t *) i;
605 v = ntohl (a->as_u32) + 1;
606 a->as_u32 = ntohl (v);
610 increment_v6_address (vl_api_ip6_address_t * i)
612 ip6_address_t *a = (ip6_address_t *) i;
615 v0 = clib_net_to_host_u64 (a->as_u64[0]);
616 v1 = clib_net_to_host_u64 (a->as_u64[1]);
621 a->as_u64[0] = clib_net_to_host_u64 (v0);
622 a->as_u64[1] = clib_net_to_host_u64 (v1);
626 increment_address (vl_api_address_t * a)
628 if (a->af == ADDRESS_IP4)
629 increment_v4_address (&a->un.ip4);
630 else if (a->af == ADDRESS_IP6)
631 increment_v6_address (&a->un.ip6);
635 set_ip4_address (vl_api_address_t * a, u32 v)
637 if (a->af == ADDRESS_IP4)
639 ip4_address_t *i = (ip4_address_t *) & a->un.ip4;
645 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
648 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
650 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
651 sizeof (ip6_address_t));
655 increment_mac_address (u8 * mac)
657 u64 tmp = *((u64 *) mac);
658 tmp = clib_net_to_host_u64 (tmp);
659 tmp += 1 << 16; /* skip unused (least significant) octets */
660 tmp = clib_host_to_net_u64 (tmp);
662 clib_memcpy (mac, &tmp, 6);
666 vat_json_object_add_address (vat_json_node_t * node,
667 const char *str, const vl_api_address_t * addr)
669 if (ADDRESS_IP6 == addr->af)
673 clib_memcpy (&ip6, &addr->un.ip6, sizeof (ip6));
674 vat_json_object_add_ip6 (node, str, ip6);
680 clib_memcpy (&ip4, &addr->un.ip4, sizeof (ip4));
681 vat_json_object_add_ip4 (node, str, ip4);
686 vat_json_object_add_prefix (vat_json_node_t * node,
687 const vl_api_prefix_t * prefix)
689 vat_json_object_add_uint (node, "len", prefix->len);
690 vat_json_object_add_address (node, "address", &prefix->address);
693 static void vl_api_create_loopback_reply_t_handler
694 (vl_api_create_loopback_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_reply_t_handler_json
706 (vl_api_create_loopback_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_create_loopback_instance_reply_t_handler
722 (vl_api_create_loopback_instance_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_create_loopback_instance_reply_t_handler_json
734 (vl_api_create_loopback_instance_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);
745 vam->retval = ntohl (mp->retval);
746 vam->result_ready = 1;
749 static void vl_api_af_packet_create_reply_t_handler
750 (vl_api_af_packet_create_reply_t * mp)
752 vat_main_t *vam = &vat_main;
753 i32 retval = ntohl (mp->retval);
755 vam->retval = retval;
756 vam->regenerate_interface_table = 1;
757 vam->sw_if_index = ntohl (mp->sw_if_index);
758 vam->result_ready = 1;
761 static void vl_api_af_packet_create_reply_t_handler_json
762 (vl_api_af_packet_create_reply_t * mp)
764 vat_main_t *vam = &vat_main;
765 vat_json_node_t node;
767 vat_json_init_object (&node);
768 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
769 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
771 vat_json_print (vam->ofp, &node);
772 vat_json_free (&node);
774 vam->retval = ntohl (mp->retval);
775 vam->result_ready = 1;
778 static void vl_api_create_vlan_subif_reply_t_handler
779 (vl_api_create_vlan_subif_reply_t * mp)
781 vat_main_t *vam = &vat_main;
782 i32 retval = ntohl (mp->retval);
784 vam->retval = retval;
785 vam->regenerate_interface_table = 1;
786 vam->sw_if_index = ntohl (mp->sw_if_index);
787 vam->result_ready = 1;
790 static void vl_api_create_vlan_subif_reply_t_handler_json
791 (vl_api_create_vlan_subif_reply_t * mp)
793 vat_main_t *vam = &vat_main;
794 vat_json_node_t node;
796 vat_json_init_object (&node);
797 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
798 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
800 vat_json_print (vam->ofp, &node);
801 vat_json_free (&node);
803 vam->retval = ntohl (mp->retval);
804 vam->result_ready = 1;
807 static void vl_api_create_subif_reply_t_handler
808 (vl_api_create_subif_reply_t * mp)
810 vat_main_t *vam = &vat_main;
811 i32 retval = ntohl (mp->retval);
813 vam->retval = retval;
814 vam->regenerate_interface_table = 1;
815 vam->sw_if_index = ntohl (mp->sw_if_index);
816 vam->result_ready = 1;
819 static void vl_api_create_subif_reply_t_handler_json
820 (vl_api_create_subif_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));
827 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
829 vat_json_print (vam->ofp, &node);
830 vat_json_free (&node);
832 vam->retval = ntohl (mp->retval);
833 vam->result_ready = 1;
836 static void vl_api_interface_name_renumber_reply_t_handler
837 (vl_api_interface_name_renumber_reply_t * mp)
839 vat_main_t *vam = &vat_main;
840 i32 retval = ntohl (mp->retval);
842 vam->retval = retval;
843 vam->regenerate_interface_table = 1;
844 vam->result_ready = 1;
847 static void vl_api_interface_name_renumber_reply_t_handler_json
848 (vl_api_interface_name_renumber_reply_t * mp)
850 vat_main_t *vam = &vat_main;
851 vat_json_node_t node;
853 vat_json_init_object (&node);
854 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
856 vat_json_print (vam->ofp, &node);
857 vat_json_free (&node);
859 vam->retval = ntohl (mp->retval);
860 vam->result_ready = 1;
864 * Special-case: build the interface table, maintain
865 * the next loopback sw_if_index vbl.
867 static void vl_api_sw_interface_details_t_handler
868 (vl_api_sw_interface_details_t * mp)
870 vat_main_t *vam = &vat_main;
871 u8 *s = format (0, "%s%c", mp->interface_name, 0);
873 hash_set_mem (vam->sw_if_index_by_interface_name, s,
874 ntohl (mp->sw_if_index));
876 /* In sub interface case, fill the sub interface table entry */
877 if (mp->sw_if_index != mp->sup_sw_if_index)
879 sw_interface_subif_t *sub = NULL;
881 vec_add2 (vam->sw_if_subif_table, sub, 1);
883 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
884 strncpy ((char *) sub->interface_name, (char *) s,
885 vec_len (sub->interface_name));
886 sub->sw_if_index = ntohl (mp->sw_if_index);
887 sub->sub_id = ntohl (mp->sub_id);
889 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
891 sub->sub_number_of_tags = mp->sub_number_of_tags;
892 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
893 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
895 /* vlan tag rewrite */
896 sub->vtr_op = ntohl (mp->vtr_op);
897 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
898 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
899 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
903 static void vl_api_sw_interface_details_t_handler_json
904 (vl_api_sw_interface_details_t * mp)
906 vat_main_t *vam = &vat_main;
907 vat_json_node_t *node = NULL;
909 if (VAT_JSON_ARRAY != vam->json_tree.type)
911 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
912 vat_json_init_array (&vam->json_tree);
914 node = vat_json_array_add (&vam->json_tree);
916 vat_json_init_object (node);
917 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
918 vat_json_object_add_uint (node, "sup_sw_if_index",
919 ntohl (mp->sup_sw_if_index));
920 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
921 sizeof (mp->l2_address));
922 vat_json_object_add_string_copy (node, "interface_name",
924 vat_json_object_add_string_copy (node, "interface_dev_type",
925 mp->interface_dev_type);
926 vat_json_object_add_uint (node, "flags", mp->flags);
927 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
928 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
929 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
930 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
931 vat_json_object_add_uint (node, "sub_number_of_tags",
932 mp->sub_number_of_tags);
933 vat_json_object_add_uint (node, "sub_outer_vlan_id",
934 ntohs (mp->sub_outer_vlan_id));
935 vat_json_object_add_uint (node, "sub_inner_vlan_id",
936 ntohs (mp->sub_inner_vlan_id));
937 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
938 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
939 vat_json_object_add_uint (node, "vtr_push_dot1q",
940 ntohl (mp->vtr_push_dot1q));
941 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
942 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
943 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
945 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
947 format_ethernet_address,
949 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
951 format_ethernet_address,
953 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
954 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
958 #if VPP_API_TEST_BUILTIN == 0
959 static void vl_api_sw_interface_event_t_handler
960 (vl_api_sw_interface_event_t * mp)
962 vat_main_t *vam = &vat_main;
963 if (vam->interface_event_display)
964 errmsg ("interface flags: sw_if_index %d %s %s",
965 ntohl (mp->sw_if_index),
966 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
967 "admin-up" : "admin-down",
968 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
969 "link-up" : "link-down");
973 __clib_unused static void
974 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
976 /* JSON output not supported */
980 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
982 vat_main_t *vam = &vat_main;
983 i32 retval = ntohl (mp->retval);
985 vam->retval = retval;
986 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
987 vam->result_ready = 1;
991 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
993 vat_main_t *vam = &vat_main;
994 vat_json_node_t node;
998 vat_json_init_object (&node);
999 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1000 vat_json_object_add_uint (&node, "reply_in_shmem",
1001 ntohl (mp->reply_in_shmem));
1002 /* Toss the shared-memory original... */
1003 oldheap = vl_msg_push_heap ();
1005 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1008 vl_msg_pop_heap (oldheap);
1010 vat_json_print (vam->ofp, &node);
1011 vat_json_free (&node);
1013 vam->retval = ntohl (mp->retval);
1014 vam->result_ready = 1;
1018 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
1020 vat_main_t *vam = &vat_main;
1021 i32 retval = ntohl (mp->retval);
1023 vec_reset_length (vam->cmd_reply);
1025 vam->retval = retval;
1027 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1028 vam->result_ready = 1;
1032 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
1034 vat_main_t *vam = &vat_main;
1035 vat_json_node_t node;
1036 u8 *reply = 0; /* reply vector */
1038 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
1039 vec_reset_length (vam->cmd_reply);
1041 vat_json_init_object (&node);
1042 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1043 vat_json_object_add_string_copy (&node, "reply", reply);
1045 vat_json_print (vam->ofp, &node);
1046 vat_json_free (&node);
1049 vam->retval = ntohl (mp->retval);
1050 vam->result_ready = 1;
1053 static void vl_api_get_node_index_reply_t_handler
1054 (vl_api_get_node_index_reply_t * mp)
1056 vat_main_t *vam = &vat_main;
1057 i32 retval = ntohl (mp->retval);
1058 if (vam->async_mode)
1060 vam->async_errors += (retval < 0);
1064 vam->retval = retval;
1066 errmsg ("node index %d", ntohl (mp->node_index));
1067 vam->result_ready = 1;
1071 static void vl_api_get_node_index_reply_t_handler_json
1072 (vl_api_get_node_index_reply_t * mp)
1074 vat_main_t *vam = &vat_main;
1075 vat_json_node_t node;
1077 vat_json_init_object (&node);
1078 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1079 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
1081 vat_json_print (vam->ofp, &node);
1082 vat_json_free (&node);
1084 vam->retval = ntohl (mp->retval);
1085 vam->result_ready = 1;
1088 static void vl_api_get_next_index_reply_t_handler
1089 (vl_api_get_next_index_reply_t * mp)
1091 vat_main_t *vam = &vat_main;
1092 i32 retval = ntohl (mp->retval);
1093 if (vam->async_mode)
1095 vam->async_errors += (retval < 0);
1099 vam->retval = retval;
1101 errmsg ("next node index %d", ntohl (mp->next_index));
1102 vam->result_ready = 1;
1106 static void vl_api_get_next_index_reply_t_handler_json
1107 (vl_api_get_next_index_reply_t * mp)
1109 vat_main_t *vam = &vat_main;
1110 vat_json_node_t node;
1112 vat_json_init_object (&node);
1113 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1114 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1116 vat_json_print (vam->ofp, &node);
1117 vat_json_free (&node);
1119 vam->retval = ntohl (mp->retval);
1120 vam->result_ready = 1;
1123 static void vl_api_add_node_next_reply_t_handler
1124 (vl_api_add_node_next_reply_t * mp)
1126 vat_main_t *vam = &vat_main;
1127 i32 retval = ntohl (mp->retval);
1128 if (vam->async_mode)
1130 vam->async_errors += (retval < 0);
1134 vam->retval = retval;
1136 errmsg ("next index %d", ntohl (mp->next_index));
1137 vam->result_ready = 1;
1141 static void vl_api_add_node_next_reply_t_handler_json
1142 (vl_api_add_node_next_reply_t * mp)
1144 vat_main_t *vam = &vat_main;
1145 vat_json_node_t node;
1147 vat_json_init_object (&node);
1148 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1149 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1151 vat_json_print (vam->ofp, &node);
1152 vat_json_free (&node);
1154 vam->retval = ntohl (mp->retval);
1155 vam->result_ready = 1;
1158 static void vl_api_show_version_reply_t_handler
1159 (vl_api_show_version_reply_t * mp)
1161 vat_main_t *vam = &vat_main;
1162 i32 retval = ntohl (mp->retval);
1166 errmsg (" program: %s", mp->program);
1167 errmsg (" version: %s", mp->version);
1168 errmsg (" build date: %s", mp->build_date);
1169 errmsg ("build directory: %s", mp->build_directory);
1171 vam->retval = retval;
1172 vam->result_ready = 1;
1175 static void vl_api_show_version_reply_t_handler_json
1176 (vl_api_show_version_reply_t * mp)
1178 vat_main_t *vam = &vat_main;
1179 vat_json_node_t node;
1181 vat_json_init_object (&node);
1182 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1183 vat_json_object_add_string_copy (&node, "program", mp->program);
1184 vat_json_object_add_string_copy (&node, "version", mp->version);
1185 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1186 vat_json_object_add_string_copy (&node, "build_directory",
1187 mp->build_directory);
1189 vat_json_print (vam->ofp, &node);
1190 vat_json_free (&node);
1192 vam->retval = ntohl (mp->retval);
1193 vam->result_ready = 1;
1196 static void vl_api_show_threads_reply_t_handler
1197 (vl_api_show_threads_reply_t * mp)
1199 vat_main_t *vam = &vat_main;
1200 i32 retval = ntohl (mp->retval);
1204 count = ntohl (mp->count);
1206 for (i = 0; i < count; i++)
1208 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1209 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1210 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1211 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1212 ntohl (mp->thread_data[i].cpu_socket));
1214 vam->retval = retval;
1215 vam->result_ready = 1;
1218 static void vl_api_show_threads_reply_t_handler_json
1219 (vl_api_show_threads_reply_t * mp)
1221 vat_main_t *vam = &vat_main;
1222 vat_json_node_t node;
1223 vl_api_thread_data_t *td;
1224 i32 retval = ntohl (mp->retval);
1228 count = ntohl (mp->count);
1230 vat_json_init_object (&node);
1231 vat_json_object_add_int (&node, "retval", retval);
1232 vat_json_object_add_uint (&node, "count", count);
1234 for (i = 0; i < count; i++)
1236 td = &mp->thread_data[i];
1237 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1238 vat_json_object_add_string_copy (&node, "name", td->name);
1239 vat_json_object_add_string_copy (&node, "type", td->type);
1240 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1241 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1242 vat_json_object_add_int (&node, "core", ntohl (td->id));
1243 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1246 vat_json_print (vam->ofp, &node);
1247 vat_json_free (&node);
1249 vam->retval = retval;
1250 vam->result_ready = 1;
1254 api_show_threads (vat_main_t * vam)
1256 vl_api_show_threads_t *mp;
1260 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1261 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1263 M (SHOW_THREADS, mp);
1271 vl_api_l2_macs_event_t_handler (vl_api_l2_macs_event_t * mp)
1273 u32 n_macs = ntohl (mp->n_macs);
1274 errmsg ("L2MAC event received with pid %d cl-idx %d for %d macs: \n",
1275 ntohl (mp->pid), mp->client_index, n_macs);
1277 for (i = 0; i < n_macs; i++)
1279 vl_api_mac_entry_t *mac = &mp->mac[i];
1280 errmsg (" [%d] sw_if_index %d mac_addr %U action %d \n",
1281 i + 1, ntohl (mac->sw_if_index),
1282 format_ethernet_address, mac->mac_addr, mac->action);
1289 vl_api_l2_macs_event_t_handler_json (vl_api_l2_macs_event_t * mp)
1291 /* JSON output not supported */
1294 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1295 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1298 * Special-case: build the bridge domain table, maintain
1299 * the next bd id vbl.
1301 static void vl_api_bridge_domain_details_t_handler
1302 (vl_api_bridge_domain_details_t * mp)
1304 vat_main_t *vam = &vat_main;
1305 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1308 print (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-6s %-3s",
1309 " ID", "LRN", "FWD", "FLD", "BVI", "UU-FWD", "#IF");
1311 print (vam->ofp, "%3d %3d %3d %3d %3d %6d %3d",
1312 ntohl (mp->bd_id), mp->learn, mp->forward,
1313 mp->flood, ntohl (mp->bvi_sw_if_index),
1314 ntohl (mp->uu_fwd_sw_if_index), n_sw_ifs);
1318 vl_api_bridge_domain_sw_if_t *sw_ifs;
1319 print (vam->ofp, "\n\n%s %s %s", "sw_if_index", "SHG",
1322 sw_ifs = mp->sw_if_details;
1323 for (i = 0; i < n_sw_ifs; i++)
1329 sw_if_index = ntohl (sw_ifs->sw_if_index);
1332 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1334 if ((u32) p->value[0] == sw_if_index)
1336 sw_if_name = (u8 *)(p->key);
1341 print (vam->ofp, "%7d %3d %s", sw_if_index,
1342 sw_ifs->shg, sw_if_name ? (char *) sw_if_name :
1343 "sw_if_index not found!");
1350 static void vl_api_bridge_domain_details_t_handler_json
1351 (vl_api_bridge_domain_details_t * mp)
1353 vat_main_t *vam = &vat_main;
1354 vat_json_node_t *node, *array = NULL;
1355 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1357 if (VAT_JSON_ARRAY != vam->json_tree.type)
1359 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1360 vat_json_init_array (&vam->json_tree);
1362 node = vat_json_array_add (&vam->json_tree);
1364 vat_json_init_object (node);
1365 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
1366 vat_json_object_add_uint (node, "flood", mp->flood);
1367 vat_json_object_add_uint (node, "forward", mp->forward);
1368 vat_json_object_add_uint (node, "learn", mp->learn);
1369 vat_json_object_add_uint (node, "bvi_sw_if_index",
1370 ntohl (mp->bvi_sw_if_index));
1371 vat_json_object_add_uint (node, "n_sw_ifs", n_sw_ifs);
1372 array = vat_json_object_add (node, "sw_if");
1373 vat_json_init_array (array);
1379 vl_api_bridge_domain_sw_if_t *sw_ifs;
1382 sw_ifs = mp->sw_if_details;
1383 for (i = 0; i < n_sw_ifs; i++)
1385 node = vat_json_array_add (array);
1386 vat_json_init_object (node);
1387 vat_json_object_add_uint (node, "sw_if_index",
1388 ntohl (sw_ifs->sw_if_index));
1389 vat_json_object_add_uint (node, "shg", sw_ifs->shg);
1395 static void vl_api_control_ping_reply_t_handler
1396 (vl_api_control_ping_reply_t * mp)
1398 vat_main_t *vam = &vat_main;
1399 i32 retval = ntohl (mp->retval);
1400 if (vam->async_mode)
1402 vam->async_errors += (retval < 0);
1406 vam->retval = retval;
1407 vam->result_ready = 1;
1409 if (vam->socket_client_main)
1410 vam->socket_client_main->control_pings_outstanding--;
1413 static void vl_api_control_ping_reply_t_handler_json
1414 (vl_api_control_ping_reply_t * mp)
1416 vat_main_t *vam = &vat_main;
1417 i32 retval = ntohl (mp->retval);
1419 if (VAT_JSON_NONE != vam->json_tree.type)
1421 vat_json_print (vam->ofp, &vam->json_tree);
1422 vat_json_free (&vam->json_tree);
1423 vam->json_tree.type = VAT_JSON_NONE;
1428 vat_json_init_array (&vam->json_tree);
1429 vat_json_print (vam->ofp, &vam->json_tree);
1430 vam->json_tree.type = VAT_JSON_NONE;
1433 vam->retval = retval;
1434 vam->result_ready = 1;
1438 vl_api_bridge_domain_set_mac_age_reply_t_handler
1439 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1441 vat_main_t *vam = &vat_main;
1442 i32 retval = ntohl (mp->retval);
1443 if (vam->async_mode)
1445 vam->async_errors += (retval < 0);
1449 vam->retval = retval;
1450 vam->result_ready = 1;
1454 static void vl_api_bridge_domain_set_mac_age_reply_t_handler_json
1455 (vl_api_bridge_domain_set_mac_age_reply_t * mp)
1457 vat_main_t *vam = &vat_main;
1458 vat_json_node_t node;
1460 vat_json_init_object (&node);
1461 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1463 vat_json_print (vam->ofp, &node);
1464 vat_json_free (&node);
1466 vam->retval = ntohl (mp->retval);
1467 vam->result_ready = 1;
1471 vl_api_l2_flags_reply_t_handler (vl_api_l2_flags_reply_t * mp)
1473 vat_main_t *vam = &vat_main;
1474 i32 retval = ntohl (mp->retval);
1475 if (vam->async_mode)
1477 vam->async_errors += (retval < 0);
1481 vam->retval = retval;
1482 vam->result_ready = 1;
1486 static void vl_api_l2_flags_reply_t_handler_json
1487 (vl_api_l2_flags_reply_t * mp)
1489 vat_main_t *vam = &vat_main;
1490 vat_json_node_t node;
1492 vat_json_init_object (&node);
1493 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1494 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1495 ntohl (mp->resulting_feature_bitmap));
1497 vat_json_print (vam->ofp, &node);
1498 vat_json_free (&node);
1500 vam->retval = ntohl (mp->retval);
1501 vam->result_ready = 1;
1504 static void vl_api_bridge_flags_reply_t_handler
1505 (vl_api_bridge_flags_reply_t * mp)
1507 vat_main_t *vam = &vat_main;
1508 i32 retval = ntohl (mp->retval);
1509 if (vam->async_mode)
1511 vam->async_errors += (retval < 0);
1515 vam->retval = retval;
1516 vam->result_ready = 1;
1520 static void vl_api_bridge_flags_reply_t_handler_json
1521 (vl_api_bridge_flags_reply_t * mp)
1523 vat_main_t *vam = &vat_main;
1524 vat_json_node_t node;
1526 vat_json_init_object (&node);
1527 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1528 vat_json_object_add_uint (&node, "resulting_feature_bitmap",
1529 ntohl (mp->resulting_feature_bitmap));
1531 vat_json_print (vam->ofp, &node);
1532 vat_json_free (&node);
1534 vam->retval = ntohl (mp->retval);
1535 vam->result_ready = 1;
1539 vl_api_tap_create_v2_reply_t_handler (vl_api_tap_create_v2_reply_t * mp)
1541 vat_main_t *vam = &vat_main;
1542 i32 retval = ntohl (mp->retval);
1543 if (vam->async_mode)
1545 vam->async_errors += (retval < 0);
1549 vam->retval = retval;
1550 vam->sw_if_index = ntohl (mp->sw_if_index);
1551 vam->result_ready = 1;
1556 static void vl_api_tap_create_v2_reply_t_handler_json
1557 (vl_api_tap_create_v2_reply_t * mp)
1559 vat_main_t *vam = &vat_main;
1560 vat_json_node_t node;
1562 vat_json_init_object (&node);
1563 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1564 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1566 vat_json_print (vam->ofp, &node);
1567 vat_json_free (&node);
1569 vam->retval = ntohl (mp->retval);
1570 vam->result_ready = 1;
1575 vl_api_tap_delete_v2_reply_t_handler (vl_api_tap_delete_v2_reply_t * mp)
1577 vat_main_t *vam = &vat_main;
1578 i32 retval = ntohl (mp->retval);
1579 if (vam->async_mode)
1581 vam->async_errors += (retval < 0);
1585 vam->retval = retval;
1586 vam->result_ready = 1;
1590 static void vl_api_tap_delete_v2_reply_t_handler_json
1591 (vl_api_tap_delete_v2_reply_t * mp)
1593 vat_main_t *vam = &vat_main;
1594 vat_json_node_t node;
1596 vat_json_init_object (&node);
1597 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1599 vat_json_print (vam->ofp, &node);
1600 vat_json_free (&node);
1602 vam->retval = ntohl (mp->retval);
1603 vam->result_ready = 1;
1607 vl_api_virtio_pci_create_reply_t_handler (vl_api_virtio_pci_create_reply_t *
1610 vat_main_t *vam = &vat_main;
1611 i32 retval = ntohl (mp->retval);
1612 if (vam->async_mode)
1614 vam->async_errors += (retval < 0);
1618 vam->retval = retval;
1619 vam->sw_if_index = ntohl (mp->sw_if_index);
1620 vam->result_ready = 1;
1624 static void vl_api_virtio_pci_create_reply_t_handler_json
1625 (vl_api_virtio_pci_create_reply_t * mp)
1627 vat_main_t *vam = &vat_main;
1628 vat_json_node_t node;
1630 vat_json_init_object (&node);
1631 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1632 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1634 vat_json_print (vam->ofp, &node);
1635 vat_json_free (&node);
1637 vam->retval = ntohl (mp->retval);
1638 vam->result_ready = 1;
1643 vl_api_virtio_pci_create_v2_reply_t_handler
1644 (vl_api_virtio_pci_create_v2_reply_t * mp)
1646 vat_main_t *vam = &vat_main;
1647 i32 retval = ntohl (mp->retval);
1648 if (vam->async_mode)
1650 vam->async_errors += (retval < 0);
1654 vam->retval = retval;
1655 vam->sw_if_index = ntohl (mp->sw_if_index);
1656 vam->result_ready = 1;
1660 static void vl_api_virtio_pci_create_v2_reply_t_handler_json
1661 (vl_api_virtio_pci_create_v2_reply_t * mp)
1663 vat_main_t *vam = &vat_main;
1664 vat_json_node_t node;
1666 vat_json_init_object (&node);
1667 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1668 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1670 vat_json_print (vam->ofp, &node);
1671 vat_json_free (&node);
1673 vam->retval = ntohl (mp->retval);
1674 vam->result_ready = 1;
1678 vl_api_virtio_pci_delete_reply_t_handler (vl_api_virtio_pci_delete_reply_t *
1681 vat_main_t *vam = &vat_main;
1682 i32 retval = ntohl (mp->retval);
1683 if (vam->async_mode)
1685 vam->async_errors += (retval < 0);
1689 vam->retval = retval;
1690 vam->result_ready = 1;
1694 static void vl_api_virtio_pci_delete_reply_t_handler_json
1695 (vl_api_virtio_pci_delete_reply_t * mp)
1697 vat_main_t *vam = &vat_main;
1698 vat_json_node_t node;
1700 vat_json_init_object (&node);
1701 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1703 vat_json_print (vam->ofp, &node);
1704 vat_json_free (&node);
1706 vam->retval = ntohl (mp->retval);
1707 vam->result_ready = 1;
1711 vl_api_bond_create_reply_t_handler (vl_api_bond_create_reply_t * mp)
1713 vat_main_t *vam = &vat_main;
1714 i32 retval = ntohl (mp->retval);
1716 if (vam->async_mode)
1718 vam->async_errors += (retval < 0);
1722 vam->retval = retval;
1723 vam->sw_if_index = ntohl (mp->sw_if_index);
1724 vam->result_ready = 1;
1728 static void vl_api_bond_create_reply_t_handler_json
1729 (vl_api_bond_create_reply_t * mp)
1731 vat_main_t *vam = &vat_main;
1732 vat_json_node_t node;
1734 vat_json_init_object (&node);
1735 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1736 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1738 vat_json_print (vam->ofp, &node);
1739 vat_json_free (&node);
1741 vam->retval = ntohl (mp->retval);
1742 vam->result_ready = 1;
1746 vl_api_bond_create2_reply_t_handler (vl_api_bond_create2_reply_t * mp)
1748 vat_main_t *vam = &vat_main;
1749 i32 retval = ntohl (mp->retval);
1751 if (vam->async_mode)
1753 vam->async_errors += (retval < 0);
1757 vam->retval = retval;
1758 vam->sw_if_index = ntohl (mp->sw_if_index);
1759 vam->result_ready = 1;
1763 static void vl_api_bond_create2_reply_t_handler_json
1764 (vl_api_bond_create2_reply_t * mp)
1766 vat_main_t *vam = &vat_main;
1767 vat_json_node_t node;
1769 vat_json_init_object (&node);
1770 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1771 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
1773 vat_json_print (vam->ofp, &node);
1774 vat_json_free (&node);
1776 vam->retval = ntohl (mp->retval);
1777 vam->result_ready = 1;
1781 vl_api_bond_delete_reply_t_handler (vl_api_bond_delete_reply_t * mp)
1783 vat_main_t *vam = &vat_main;
1784 i32 retval = ntohl (mp->retval);
1786 if (vam->async_mode)
1788 vam->async_errors += (retval < 0);
1792 vam->retval = retval;
1793 vam->result_ready = 1;
1797 static void vl_api_bond_delete_reply_t_handler_json
1798 (vl_api_bond_delete_reply_t * mp)
1800 vat_main_t *vam = &vat_main;
1801 vat_json_node_t node;
1803 vat_json_init_object (&node);
1804 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1806 vat_json_print (vam->ofp, &node);
1807 vat_json_free (&node);
1809 vam->retval = ntohl (mp->retval);
1810 vam->result_ready = 1;
1814 vl_api_bond_add_member_reply_t_handler (vl_api_bond_add_member_reply_t * mp)
1816 vat_main_t *vam = &vat_main;
1817 i32 retval = ntohl (mp->retval);
1819 if (vam->async_mode)
1821 vam->async_errors += (retval < 0);
1825 vam->retval = retval;
1826 vam->result_ready = 1;
1830 static void vl_api_bond_add_member_reply_t_handler_json
1831 (vl_api_bond_add_member_reply_t * mp)
1833 vat_main_t *vam = &vat_main;
1834 vat_json_node_t node;
1836 vat_json_init_object (&node);
1837 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1839 vat_json_print (vam->ofp, &node);
1840 vat_json_free (&node);
1842 vam->retval = ntohl (mp->retval);
1843 vam->result_ready = 1;
1847 vl_api_bond_detach_member_reply_t_handler (vl_api_bond_detach_member_reply_t *
1850 vat_main_t *vam = &vat_main;
1851 i32 retval = ntohl (mp->retval);
1853 if (vam->async_mode)
1855 vam->async_errors += (retval < 0);
1859 vam->retval = retval;
1860 vam->result_ready = 1;
1864 static void vl_api_bond_detach_member_reply_t_handler_json
1865 (vl_api_bond_detach_member_reply_t * mp)
1867 vat_main_t *vam = &vat_main;
1868 vat_json_node_t node;
1870 vat_json_init_object (&node);
1871 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1873 vat_json_print (vam->ofp, &node);
1874 vat_json_free (&node);
1876 vam->retval = ntohl (mp->retval);
1877 vam->result_ready = 1;
1881 api_sw_interface_set_bond_weight (vat_main_t * vam)
1883 unformat_input_t *i = vam->input;
1884 vl_api_sw_interface_set_bond_weight_t *mp;
1885 u32 sw_if_index = ~0;
1887 u8 weight_enter = 0;
1890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1892 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1894 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1896 else if (unformat (i, "weight %u", &weight))
1902 if (sw_if_index == ~0)
1904 errmsg ("missing interface name or sw_if_index");
1907 if (weight_enter == 0)
1909 errmsg ("missing valid weight");
1913 /* Construct the API message */
1914 M (SW_INTERFACE_SET_BOND_WEIGHT, mp);
1915 mp->sw_if_index = ntohl (sw_if_index);
1916 mp->weight = ntohl (weight);
1923 static void vl_api_sw_bond_interface_details_t_handler
1924 (vl_api_sw_bond_interface_details_t * mp)
1926 vat_main_t *vam = &vat_main;
1929 "%-16s %-12d %-12U %-13U %-14u %-14u",
1930 mp->interface_name, ntohl (mp->sw_if_index),
1931 format_bond_mode, ntohl (mp->mode), format_bond_load_balance,
1932 ntohl (mp->lb), ntohl (mp->active_members), ntohl (mp->members));
1935 static void vl_api_sw_bond_interface_details_t_handler_json
1936 (vl_api_sw_bond_interface_details_t * mp)
1938 vat_main_t *vam = &vat_main;
1939 vat_json_node_t *node = NULL;
1941 if (VAT_JSON_ARRAY != vam->json_tree.type)
1943 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1944 vat_json_init_array (&vam->json_tree);
1946 node = vat_json_array_add (&vam->json_tree);
1948 vat_json_init_object (node);
1949 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1950 vat_json_object_add_string_copy (node, "interface_name",
1951 mp->interface_name);
1952 vat_json_object_add_uint (node, "mode", ntohl (mp->mode));
1953 vat_json_object_add_uint (node, "load_balance", ntohl (mp->lb));
1954 vat_json_object_add_uint (node, "active_members",
1955 ntohl (mp->active_members));
1956 vat_json_object_add_uint (node, "members", ntohl (mp->members));
1960 api_sw_bond_interface_dump (vat_main_t * vam)
1962 unformat_input_t *i = vam->input;
1963 vl_api_sw_bond_interface_dump_t *mp;
1964 vl_api_control_ping_t *mp_ping;
1966 u32 sw_if_index = ~0;
1968 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1970 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1972 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1979 "\n%-16s %-12s %-12s %-13s %-14s %-14s",
1980 "interface name", "sw_if_index", "mode", "load balance",
1981 "active members", "members");
1983 /* Get list of bond interfaces */
1984 M (SW_BOND_INTERFACE_DUMP, mp);
1985 mp->sw_if_index = ntohl (sw_if_index);
1988 /* Use a control ping for synchronization */
1989 MPING (CONTROL_PING, mp_ping);
1996 static void vl_api_sw_member_interface_details_t_handler
1997 (vl_api_sw_member_interface_details_t * mp)
1999 vat_main_t *vam = &vat_main;
2002 "%-25s %-12d %-7d %-12d %-10d %-10d", mp->interface_name,
2003 ntohl (mp->sw_if_index), mp->is_passive, mp->is_long_timeout,
2004 ntohl (mp->weight), mp->is_local_numa);
2007 static void vl_api_sw_member_interface_details_t_handler_json
2008 (vl_api_sw_member_interface_details_t * mp)
2010 vat_main_t *vam = &vat_main;
2011 vat_json_node_t *node = NULL;
2013 if (VAT_JSON_ARRAY != vam->json_tree.type)
2015 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2016 vat_json_init_array (&vam->json_tree);
2018 node = vat_json_array_add (&vam->json_tree);
2020 vat_json_init_object (node);
2021 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
2022 vat_json_object_add_string_copy (node, "interface_name",
2023 mp->interface_name);
2024 vat_json_object_add_uint (node, "passive", mp->is_passive);
2025 vat_json_object_add_uint (node, "long_timeout", mp->is_long_timeout);
2026 vat_json_object_add_uint (node, "weight", ntohl (mp->weight));
2027 vat_json_object_add_uint (node, "is_local_numa", mp->is_local_numa);
2031 api_sw_member_interface_dump (vat_main_t * vam)
2033 unformat_input_t *i = vam->input;
2034 vl_api_sw_member_interface_dump_t *mp;
2035 vl_api_control_ping_t *mp_ping;
2036 u32 sw_if_index = ~0;
2037 u8 sw_if_index_set = 0;
2040 /* Parse args required to build the message */
2041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2043 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2044 sw_if_index_set = 1;
2045 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2046 sw_if_index_set = 1;
2051 if (sw_if_index_set == 0)
2053 errmsg ("missing vpp interface name. ");
2058 "\n%-25s %-12s %-7s %-12s %-10s %-10s",
2059 "member interface name", "sw_if_index", "passive", "long_timeout",
2060 "weight", "local numa");
2062 /* Get list of bond interfaces */
2063 M (SW_MEMBER_INTERFACE_DUMP, mp);
2064 mp->sw_if_index = ntohl (sw_if_index);
2067 /* Use a control ping for synchronization */
2068 MPING (CONTROL_PING, mp_ping);
2075 static void vl_api_mpls_tunnel_add_del_reply_t_handler
2076 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2078 vat_main_t *vam = &vat_main;
2079 i32 retval = ntohl (mp->retval);
2080 if (vam->async_mode)
2082 vam->async_errors += (retval < 0);
2086 vam->retval = retval;
2087 vam->sw_if_index = ntohl (mp->sw_if_index);
2088 vam->result_ready = 1;
2090 vam->regenerate_interface_table = 1;
2093 static void vl_api_mpls_tunnel_add_del_reply_t_handler_json
2094 (vl_api_mpls_tunnel_add_del_reply_t * mp)
2096 vat_main_t *vam = &vat_main;
2097 vat_json_node_t node;
2099 vat_json_init_object (&node);
2100 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2101 vat_json_object_add_uint (&node, "tunnel_sw_if_index",
2102 ntohl (mp->sw_if_index));
2104 vat_json_print (vam->ofp, &node);
2105 vat_json_free (&node);
2107 vam->retval = ntohl (mp->retval);
2108 vam->result_ready = 1;
2111 static void vl_api_create_vhost_user_if_reply_t_handler
2112 (vl_api_create_vhost_user_if_reply_t * mp)
2114 vat_main_t *vam = &vat_main;
2115 i32 retval = ntohl (mp->retval);
2116 if (vam->async_mode)
2118 vam->async_errors += (retval < 0);
2122 vam->retval = retval;
2123 vam->sw_if_index = ntohl (mp->sw_if_index);
2124 vam->result_ready = 1;
2126 vam->regenerate_interface_table = 1;
2129 static void vl_api_create_vhost_user_if_reply_t_handler_json
2130 (vl_api_create_vhost_user_if_reply_t * mp)
2132 vat_main_t *vam = &vat_main;
2133 vat_json_node_t node;
2135 vat_json_init_object (&node);
2136 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2137 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2139 vat_json_print (vam->ofp, &node);
2140 vat_json_free (&node);
2142 vam->retval = ntohl (mp->retval);
2143 vam->result_ready = 1;
2146 static void vl_api_create_vhost_user_if_v2_reply_t_handler
2147 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2149 vat_main_t *vam = &vat_main;
2150 i32 retval = ntohl (mp->retval);
2151 if (vam->async_mode)
2153 vam->async_errors += (retval < 0);
2157 vam->retval = retval;
2158 vam->sw_if_index = ntohl (mp->sw_if_index);
2159 vam->result_ready = 1;
2161 vam->regenerate_interface_table = 1;
2164 static void vl_api_create_vhost_user_if_v2_reply_t_handler_json
2165 (vl_api_create_vhost_user_if_v2_reply_t * mp)
2167 vat_main_t *vam = &vat_main;
2168 vat_json_node_t node;
2170 vat_json_init_object (&node);
2171 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2172 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
2174 vat_json_print (vam->ofp, &node);
2175 vat_json_free (&node);
2177 vam->retval = ntohl (mp->retval);
2178 vam->result_ready = 1;
2181 static void vl_api_ip_address_details_t_handler
2182 (vl_api_ip_address_details_t * mp)
2184 vat_main_t *vam = &vat_main;
2185 static ip_address_details_t empty_ip_address_details = { {0} };
2186 ip_address_details_t *address = NULL;
2187 ip_details_t *current_ip_details = NULL;
2188 ip_details_t *details = NULL;
2190 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
2192 if (!details || vam->current_sw_if_index >= vec_len (details)
2193 || !details[vam->current_sw_if_index].present)
2195 errmsg ("ip address details arrived but not stored");
2196 errmsg ("ip_dump should be called first");
2200 current_ip_details = vec_elt_at_index (details, vam->current_sw_if_index);
2202 #define addresses (current_ip_details->addr)
2204 vec_validate_init_empty (addresses, vec_len (addresses),
2205 empty_ip_address_details);
2207 address = vec_elt_at_index (addresses, vec_len (addresses) - 1);
2209 clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip));
2210 address->prefix_length = mp->prefix.len;
2214 static void vl_api_ip_address_details_t_handler_json
2215 (vl_api_ip_address_details_t * mp)
2217 vat_main_t *vam = &vat_main;
2218 vat_json_node_t *node = NULL;
2220 if (VAT_JSON_ARRAY != vam->json_tree.type)
2222 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2223 vat_json_init_array (&vam->json_tree);
2225 node = vat_json_array_add (&vam->json_tree);
2227 vat_json_init_object (node);
2228 vat_json_object_add_prefix (node, &mp->prefix);
2232 vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
2234 vat_main_t *vam = &vat_main;
2235 static ip_details_t empty_ip_details = { 0 };
2236 ip_details_t *ip = NULL;
2237 u32 sw_if_index = ~0;
2239 sw_if_index = ntohl (mp->sw_if_index);
2241 vec_validate_init_empty (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2242 sw_if_index, empty_ip_details);
2244 ip = vec_elt_at_index (vam->ip_details_by_sw_if_index[vam->is_ipv6],
2251 vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
2253 vat_main_t *vam = &vat_main;
2255 if (VAT_JSON_ARRAY != vam->json_tree.type)
2257 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
2258 vat_json_init_array (&vam->json_tree);
2260 vat_json_array_add_uint (&vam->json_tree,
2261 clib_net_to_host_u32 (mp->sw_if_index));
2264 static void vl_api_get_first_msg_id_reply_t_handler
2265 (vl_api_get_first_msg_id_reply_t * mp)
2267 vat_main_t *vam = &vat_main;
2268 i32 retval = ntohl (mp->retval);
2270 if (vam->async_mode)
2272 vam->async_errors += (retval < 0);
2276 vam->retval = retval;
2277 vam->result_ready = 1;
2281 errmsg ("first message id %d", ntohs (mp->first_msg_id));
2285 static void vl_api_get_first_msg_id_reply_t_handler_json
2286 (vl_api_get_first_msg_id_reply_t * mp)
2288 vat_main_t *vam = &vat_main;
2289 vat_json_node_t node;
2291 vat_json_init_object (&node);
2292 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2293 vat_json_object_add_uint (&node, "first_msg_id",
2294 (uint) ntohs (mp->first_msg_id));
2296 vat_json_print (vam->ofp, &node);
2297 vat_json_free (&node);
2299 vam->retval = ntohl (mp->retval);
2300 vam->result_ready = 1;
2303 static void vl_api_get_node_graph_reply_t_handler
2304 (vl_api_get_node_graph_reply_t * mp)
2306 vat_main_t *vam = &vat_main;
2307 i32 retval = ntohl (mp->retval);
2308 u8 *pvt_copy, *reply;
2313 if (vam->async_mode)
2315 vam->async_errors += (retval < 0);
2319 vam->retval = retval;
2320 vam->result_ready = 1;
2323 /* "Should never happen..." */
2327 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2328 pvt_copy = vec_dup (reply);
2330 /* Toss the shared-memory original... */
2331 oldheap = vl_msg_push_heap ();
2335 vl_msg_pop_heap (oldheap);
2337 if (vam->graph_nodes)
2339 hash_free (vam->graph_node_index_by_name);
2341 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2343 node = vam->graph_nodes[0][i];
2344 vec_free (node->name);
2345 vec_free (node->next_nodes);
2348 vec_free (vam->graph_nodes[0]);
2349 vec_free (vam->graph_nodes);
2352 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
2353 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2354 vec_free (pvt_copy);
2356 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
2358 node = vam->graph_nodes[0][i];
2359 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2363 static void vl_api_get_node_graph_reply_t_handler_json
2364 (vl_api_get_node_graph_reply_t * mp)
2366 vat_main_t *vam = &vat_main;
2368 vat_json_node_t node;
2371 /* $$$$ make this real? */
2372 vat_json_init_object (&node);
2373 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2374 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
2376 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
2378 /* Toss the shared-memory original... */
2379 oldheap = vl_msg_push_heap ();
2383 vl_msg_pop_heap (oldheap);
2385 vat_json_print (vam->ofp, &node);
2386 vat_json_free (&node);
2388 vam->retval = ntohl (mp->retval);
2389 vam->result_ready = 1;
2392 /* Format hex dump. */
2394 format_hex_bytes (u8 * s, va_list * va)
2396 u8 *bytes = va_arg (*va, u8 *);
2397 int n_bytes = va_arg (*va, int);
2400 /* Print short or long form depending on byte count. */
2401 uword short_form = n_bytes <= 32;
2402 u32 indent = format_get_indent (s);
2407 for (i = 0; i < n_bytes; i++)
2409 if (!short_form && (i % 32) == 0)
2410 s = format (s, "%08x: ", i);
2411 s = format (s, "%02x", bytes[i]);
2412 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2413 s = format (s, "\n%U", format_white_space, indent);
2420 * Generate boilerplate reply handlers, which
2421 * dig the return value out of the xxx_reply_t API message,
2422 * stick it into vam->retval, and set vam->result_ready
2424 * Could also do this by pointing N message decode slots at
2425 * a single function, but that could break in subtle ways.
2428 #define foreach_standard_reply_retval_handler \
2429 _(sw_interface_set_flags_reply) \
2430 _(sw_interface_add_del_address_reply) \
2431 _(sw_interface_set_rx_mode_reply) \
2432 _(sw_interface_set_rx_placement_reply) \
2433 _(sw_interface_set_table_reply) \
2434 _(sw_interface_set_mpls_enable_reply) \
2435 _(sw_interface_set_vpath_reply) \
2436 _(sw_interface_set_l2_bridge_reply) \
2437 _(sw_interface_set_bond_weight_reply) \
2438 _(bridge_domain_add_del_reply) \
2439 _(sw_interface_set_l2_xconnect_reply) \
2440 _(l2fib_add_del_reply) \
2441 _(l2fib_flush_int_reply) \
2442 _(l2fib_flush_bd_reply) \
2443 _(ip_route_add_del_reply) \
2444 _(ip_table_add_del_reply) \
2445 _(ip_table_replace_begin_reply) \
2446 _(ip_table_flush_reply) \
2447 _(ip_table_replace_end_reply) \
2448 _(ip_mroute_add_del_reply) \
2449 _(mpls_route_add_del_reply) \
2450 _(mpls_table_add_del_reply) \
2451 _(mpls_ip_bind_unbind_reply) \
2452 _(sw_interface_set_unnumbered_reply) \
2453 _(set_ip_flow_hash_reply) \
2454 _(sw_interface_ip6_enable_disable_reply) \
2455 _(l2_patch_add_del_reply) \
2456 _(sr_mpls_policy_add_reply) \
2457 _(sr_mpls_policy_mod_reply) \
2458 _(sr_mpls_policy_del_reply) \
2459 _(sr_policy_add_reply) \
2460 _(sr_policy_mod_reply) \
2461 _(sr_policy_del_reply) \
2462 _(sr_localsid_add_del_reply) \
2463 _(sr_steering_add_del_reply) \
2464 _(l2_fib_clear_table_reply) \
2465 _(l2_interface_efp_filter_reply) \
2466 _(l2_interface_vlan_tag_rewrite_reply) \
2467 _(modify_vhost_user_if_reply) \
2468 _(modify_vhost_user_if_v2_reply) \
2469 _(delete_vhost_user_if_reply) \
2470 _(want_l2_macs_events_reply) \
2471 _(ipsec_spd_add_del_reply) \
2472 _(ipsec_interface_add_del_spd_reply) \
2473 _(ipsec_spd_entry_add_del_reply) \
2474 _(ipsec_sad_entry_add_del_reply) \
2475 _(delete_loopback_reply) \
2476 _(bd_ip_mac_add_del_reply) \
2477 _(bd_ip_mac_flush_reply) \
2478 _(want_interface_events_reply) \
2479 _(sw_interface_clear_stats_reply) \
2480 _(ioam_enable_reply) \
2481 _(ioam_disable_reply) \
2482 _(af_packet_delete_reply) \
2483 _(sw_interface_span_enable_disable_reply) \
2484 _(ip_source_and_port_range_check_add_del_reply) \
2485 _(ip_source_and_port_range_check_interface_add_del_reply)\
2486 _(delete_subif_reply) \
2487 _(l2_interface_pbb_tag_rewrite_reply) \
2489 _(sw_interface_tag_add_del_reply) \
2490 _(sw_interface_add_del_mac_address_reply) \
2491 _(hw_interface_set_mtu_reply) \
2492 _(tcp_configure_src_addresses_reply) \
2493 _(session_rule_add_del_reply) \
2494 _(ip_container_proxy_add_del_reply) \
2495 _(qos_record_enable_disable_reply) \
2498 static void vl_api_##n##_t_handler \
2499 (vl_api_##n##_t * mp) \
2501 vat_main_t * vam = &vat_main; \
2502 i32 retval = ntohl(mp->retval); \
2503 if (vam->async_mode) { \
2504 vam->async_errors += (retval < 0); \
2506 vam->retval = retval; \
2507 vam->result_ready = 1; \
2510 foreach_standard_reply_retval_handler;
2514 static void vl_api_##n##_t_handler_json \
2515 (vl_api_##n##_t * mp) \
2517 vat_main_t * vam = &vat_main; \
2518 vat_json_node_t node; \
2519 vat_json_init_object(&node); \
2520 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2521 vat_json_print(vam->ofp, &node); \
2522 vam->retval = ntohl(mp->retval); \
2523 vam->result_ready = 1; \
2525 foreach_standard_reply_retval_handler;
2529 * Table of message reply handlers, must include boilerplate handlers
2533 #define foreach_vpe_api_reply_msg \
2534 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2535 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
2536 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2537 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2538 _(CONTROL_PING_REPLY, control_ping_reply) \
2539 _(CLI_REPLY, cli_reply) \
2540 _(CLI_INBAND_REPLY, cli_inband_reply) \
2541 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2542 sw_interface_add_del_address_reply) \
2543 _(SW_INTERFACE_SET_RX_MODE_REPLY, sw_interface_set_rx_mode_reply) \
2544 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
2545 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
2546 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2547 _(SW_INTERFACE_SET_MPLS_ENABLE_REPLY, sw_interface_set_mpls_enable_reply) \
2548 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2549 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2550 sw_interface_set_l2_xconnect_reply) \
2551 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2552 sw_interface_set_l2_bridge_reply) \
2553 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2554 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2555 _(BRIDGE_DOMAIN_SET_MAC_AGE_REPLY, bridge_domain_set_mac_age_reply) \
2556 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2557 _(L2FIB_FLUSH_INT_REPLY, l2fib_flush_int_reply) \
2558 _(L2FIB_FLUSH_BD_REPLY, l2fib_flush_bd_reply) \
2559 _(L2_FLAGS_REPLY, l2_flags_reply) \
2560 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2561 _(TAP_CREATE_V2_REPLY, tap_create_v2_reply) \
2562 _(TAP_DELETE_V2_REPLY, tap_delete_v2_reply) \
2563 _(SW_INTERFACE_TAP_V2_DETAILS, sw_interface_tap_v2_details) \
2564 _(VIRTIO_PCI_CREATE_REPLY, virtio_pci_create_reply) \
2565 _(VIRTIO_PCI_CREATE_V2_REPLY, virtio_pci_create_v2_reply) \
2566 _(VIRTIO_PCI_DELETE_REPLY, virtio_pci_delete_reply) \
2567 _(SW_INTERFACE_VIRTIO_PCI_DETAILS, sw_interface_virtio_pci_details) \
2568 _(BOND_CREATE_REPLY, bond_create_reply) \
2569 _(BOND_CREATE2_REPLY, bond_create2_reply) \
2570 _(BOND_DELETE_REPLY, bond_delete_reply) \
2571 _(BOND_ADD_MEMBER_REPLY, bond_add_member_reply) \
2572 _(BOND_DETACH_MEMBER_REPLY, bond_detach_member_reply) \
2573 _(SW_INTERFACE_SET_BOND_WEIGHT_REPLY, sw_interface_set_bond_weight_reply) \
2574 _(SW_BOND_INTERFACE_DETAILS, sw_bond_interface_details) \
2575 _(SW_MEMBER_INTERFACE_DETAILS, sw_member_interface_details) \
2576 _(IP_ROUTE_ADD_DEL_REPLY, ip_route_add_del_reply) \
2577 _(IP_TABLE_ADD_DEL_REPLY, ip_table_add_del_reply) \
2578 _(IP_TABLE_REPLACE_BEGIN_REPLY, ip_table_replace_begin_reply) \
2579 _(IP_TABLE_FLUSH_REPLY, ip_table_flush_reply) \
2580 _(IP_TABLE_REPLACE_END_REPLY, ip_table_replace_end_reply) \
2581 _(IP_MROUTE_ADD_DEL_REPLY, ip_mroute_add_del_reply) \
2582 _(MPLS_TABLE_ADD_DEL_REPLY, mpls_table_add_del_reply) \
2583 _(MPLS_ROUTE_ADD_DEL_REPLY, mpls_route_add_del_reply) \
2584 _(MPLS_IP_BIND_UNBIND_REPLY, mpls_ip_bind_unbind_reply) \
2585 _(MPLS_TUNNEL_ADD_DEL_REPLY, mpls_tunnel_add_del_reply) \
2586 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2587 sw_interface_set_unnumbered_reply) \
2588 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2589 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2590 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2591 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2592 sw_interface_ip6_enable_disable_reply) \
2593 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2594 _(SR_MPLS_POLICY_ADD_REPLY, sr_mpls_policy_add_reply) \
2595 _(SR_MPLS_POLICY_MOD_REPLY, sr_mpls_policy_mod_reply) \
2596 _(SR_MPLS_POLICY_DEL_REPLY, sr_mpls_policy_del_reply) \
2597 _(SR_POLICY_ADD_REPLY, sr_policy_add_reply) \
2598 _(SR_POLICY_MOD_REPLY, sr_policy_mod_reply) \
2599 _(SR_POLICY_DEL_REPLY, sr_policy_del_reply) \
2600 _(SR_LOCALSID_ADD_DEL_REPLY, sr_localsid_add_del_reply) \
2601 _(SR_STEERING_ADD_DEL_REPLY, sr_steering_add_del_reply) \
2602 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2603 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2604 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2605 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2606 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2607 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2608 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2609 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2610 _(CREATE_VHOST_USER_IF_V2_REPLY, create_vhost_user_if_v2_reply) \
2611 _(MODIFY_VHOST_USER_IF_V2_REPLY, modify_vhost_user_if_v2_reply) \
2612 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2613 _(SHOW_VERSION_REPLY, show_version_reply) \
2614 _(SHOW_THREADS_REPLY, show_threads_reply) \
2615 _(L2_FIB_TABLE_DETAILS, l2_fib_table_details) \
2616 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2617 _(WANT_L2_MACS_EVENTS_REPLY, want_l2_macs_events_reply) \
2618 _(L2_MACS_EVENT, l2_macs_event) \
2619 _(IP_ADDRESS_DETAILS, ip_address_details) \
2620 _(IP_DETAILS, ip_details) \
2621 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2622 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2623 _(IPSEC_SPD_ENTRY_ADD_DEL_REPLY, ipsec_spd_entry_add_del_reply) \
2624 _(IPSEC_SAD_ENTRY_ADD_DEL_REPLY, ipsec_sad_entry_add_del_reply) \
2625 _(IPSEC_SA_DETAILS, ipsec_sa_details) \
2626 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2627 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2628 _(BD_IP_MAC_FLUSH_REPLY, bd_ip_mac_flush_reply) \
2629 _(BD_IP_MAC_DETAILS, bd_ip_mac_details) \
2630 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2631 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2632 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2633 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2634 _(IOAM_ENABLE_REPLY, ioam_enable_reply) \
2635 _(IOAM_DISABLE_REPLY, ioam_disable_reply) \
2636 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2637 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2638 _(AF_PACKET_DETAILS, af_packet_details) \
2639 _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \
2640 _(MPLS_TABLE_DETAILS, mpls_table_details) \
2641 _(MPLS_ROUTE_DETAILS, mpls_route_details) \
2642 _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \
2643 _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \
2644 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
2645 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
2646 ip_source_and_port_range_check_add_del_reply) \
2647 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
2648 ip_source_and_port_range_check_interface_add_del_reply) \
2649 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
2650 _(L2_INTERFACE_PBB_TAG_REWRITE_REPLY, l2_interface_pbb_tag_rewrite_reply) \
2651 _(SET_PUNT_REPLY, set_punt_reply) \
2652 _(IP_TABLE_DETAILS, ip_table_details) \
2653 _(IP_ROUTE_DETAILS, ip_route_details) \
2654 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
2655 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
2656 _(L2_XCONNECT_DETAILS, l2_xconnect_details) \
2657 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
2658 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
2659 _(TCP_CONFIGURE_SRC_ADDRESSES_REPLY, tcp_configure_src_addresses_reply) \
2660 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
2661 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
2662 _(SESSION_RULES_DETAILS, session_rules_details) \
2663 _(IP_CONTAINER_PROXY_ADD_DEL_REPLY, ip_container_proxy_add_del_reply) \
2664 _(QOS_RECORD_ENABLE_DISABLE_REPLY, qos_record_enable_disable_reply) \
2666 #define foreach_standalone_reply_msg \
2667 _(SW_INTERFACE_EVENT, sw_interface_event)
2675 #define STR_VTR_OP_CASE(op) \
2676 case L2_VTR_ ## op: \
2680 str_vtr_op (u32 vtr_op)
2684 STR_VTR_OP_CASE (DISABLED);
2685 STR_VTR_OP_CASE (PUSH_1);
2686 STR_VTR_OP_CASE (PUSH_2);
2687 STR_VTR_OP_CASE (POP_1);
2688 STR_VTR_OP_CASE (POP_2);
2689 STR_VTR_OP_CASE (TRANSLATE_1_1);
2690 STR_VTR_OP_CASE (TRANSLATE_1_2);
2691 STR_VTR_OP_CASE (TRANSLATE_2_1);
2692 STR_VTR_OP_CASE (TRANSLATE_2_2);
2699 dump_sub_interface_table (vat_main_t * vam)
2701 const sw_interface_subif_t *sub = NULL;
2703 if (vam->json_output)
2706 ("JSON output supported only for VPE API calls and dump_stats_table");
2711 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
2712 "Interface", "sw_if_index",
2713 "sub id", "dot1ad", "tags", "outer id",
2714 "inner id", "exact", "default", "outer any", "inner any");
2716 vec_foreach (sub, vam->sw_if_subif_table)
2719 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
2720 sub->interface_name,
2722 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2723 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2724 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2725 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2726 if (sub->vtr_op != L2_VTR_DISABLED)
2729 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2730 "tag1: %d tag2: %d ]",
2731 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
2732 sub->vtr_tag1, sub->vtr_tag2);
2740 name_sort_cmp (void *a1, void *a2)
2742 name_sort_t *n1 = a1;
2743 name_sort_t *n2 = a2;
2745 return strcmp ((char *) n1->name, (char *) n2->name);
2749 dump_interface_table (vat_main_t * vam)
2752 name_sort_t *nses = 0, *ns;
2754 if (vam->json_output)
2757 ("JSON output supported only for VPE API calls and dump_stats_table");
2762 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2764 vec_add2 (nses, ns, 1);
2765 ns->name = (u8 *)(p->key);
2766 ns->value = (u32) p->value[0];
2770 vec_sort_with_function (nses, name_sort_cmp);
2772 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
2773 vec_foreach (ns, nses)
2775 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
2782 dump_ip_table (vat_main_t * vam, int is_ipv6)
2784 const ip_details_t *det = NULL;
2785 const ip_address_details_t *address = NULL;
2788 print (vam->ofp, "%-12s", "sw_if_index");
2790 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6])
2797 print (vam->ofp, "%-12d", i);
2798 print (vam->ofp, " %-30s%-13s", "Address", "Prefix length");
2803 vec_foreach (address, det->addr)
2807 is_ipv6 ? format_ip6_address : format_ip4_address,
2808 address->ip, address->prefix_length);
2816 dump_ipv4_table (vat_main_t * vam)
2818 if (vam->json_output)
2821 ("JSON output supported only for VPE API calls and dump_stats_table");
2825 return dump_ip_table (vam, 0);
2829 dump_ipv6_table (vat_main_t * vam)
2831 if (vam->json_output)
2834 ("JSON output supported only for VPE API calls and dump_stats_table");
2838 return dump_ip_table (vam, 1);
2842 * Pass CLI buffers directly in the CLI_INBAND API message,
2843 * instead of an additional shared memory area.
2846 exec_inband (vat_main_t * vam)
2848 vl_api_cli_inband_t *mp;
2849 unformat_input_t *i = vam->input;
2852 if (vec_len (i->buffer) == 0)
2855 if (vam->exec_mode == 0 && unformat (i, "mode"))
2860 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
2867 * In order for the CLI command to work, it
2868 * must be a vector ending in \n, not a C-string ending
2871 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
2872 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
2876 /* json responses may or may not include a useful reply... */
2877 if (vec_len (vam->cmd_reply))
2878 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
2883 exec (vat_main_t * vam)
2885 return exec_inband (vam);
2889 api_create_loopback (vat_main_t * vam)
2891 unformat_input_t *i = vam->input;
2892 vl_api_create_loopback_t *mp;
2893 vl_api_create_loopback_instance_t *mp_lbi;
2896 u8 is_specified = 0;
2897 u32 user_instance = 0;
2900 clib_memset (mac_address, 0, sizeof (mac_address));
2902 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2904 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2906 if (unformat (i, "instance %d", &user_instance))
2914 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
2915 mp_lbi->is_specified = is_specified;
2917 mp_lbi->user_instance = htonl (user_instance);
2919 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
2924 /* Construct the API message */
2925 M (CREATE_LOOPBACK, mp);
2927 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2936 api_delete_loopback (vat_main_t * vam)
2938 unformat_input_t *i = vam->input;
2939 vl_api_delete_loopback_t *mp;
2940 u32 sw_if_index = ~0;
2943 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2945 if (unformat (i, "sw_if_index %d", &sw_if_index))
2951 if (sw_if_index == ~0)
2953 errmsg ("missing sw_if_index");
2957 /* Construct the API message */
2958 M (DELETE_LOOPBACK, mp);
2959 mp->sw_if_index = ntohl (sw_if_index);
2967 api_want_interface_events (vat_main_t * vam)
2969 unformat_input_t *i = vam->input;
2970 vl_api_want_interface_events_t *mp;
2974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2976 if (unformat (i, "enable"))
2978 else if (unformat (i, "disable"))
2986 errmsg ("missing enable|disable");
2990 M (WANT_INTERFACE_EVENTS, mp);
2991 mp->enable_disable = enable;
2993 vam->interface_event_display = enable;
3001 /* Note: non-static, called once to set up the initial intfc table */
3003 api_sw_interface_dump (vat_main_t * vam)
3005 vl_api_sw_interface_dump_t *mp;
3006 vl_api_control_ping_t *mp_ping;
3008 name_sort_t *nses = 0, *ns;
3009 sw_interface_subif_t *sub = NULL;
3012 /* Toss the old name table */
3014 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3016 vec_add2 (nses, ns, 1);
3017 ns->name = (u8 *)(p->key);
3018 ns->value = (u32) p->value[0];
3022 hash_free (vam->sw_if_index_by_interface_name);
3024 vec_foreach (ns, nses) vec_free (ns->name);
3028 vec_foreach (sub, vam->sw_if_subif_table)
3030 vec_free (sub->interface_name);
3032 vec_free (vam->sw_if_subif_table);
3034 /* recreate the interface name hash table */
3035 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
3038 * Ask for all interface names. Otherwise, the epic catalog of
3039 * name filters becomes ridiculously long, and vat ends up needing
3040 * to be taught about new interface types.
3042 M (SW_INTERFACE_DUMP, mp);
3045 /* Use a control ping for synchronization */
3046 MPING (CONTROL_PING, mp_ping);
3054 api_sw_interface_set_flags (vat_main_t * vam)
3056 unformat_input_t *i = vam->input;
3057 vl_api_sw_interface_set_flags_t *mp;
3059 u8 sw_if_index_set = 0;
3063 /* Parse args required to build the message */
3064 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3066 if (unformat (i, "admin-up"))
3068 else if (unformat (i, "admin-down"))
3071 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3072 sw_if_index_set = 1;
3073 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3074 sw_if_index_set = 1;
3079 if (sw_if_index_set == 0)
3081 errmsg ("missing interface name or sw_if_index");
3085 /* Construct the API message */
3086 M (SW_INTERFACE_SET_FLAGS, mp);
3087 mp->sw_if_index = ntohl (sw_if_index);
3088 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
3093 /* Wait for a reply, return the good/bad news... */
3099 api_sw_interface_set_rx_mode (vat_main_t * vam)
3101 unformat_input_t *i = vam->input;
3102 vl_api_sw_interface_set_rx_mode_t *mp;
3104 u8 sw_if_index_set = 0;
3106 u8 queue_id_valid = 0;
3108 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
3110 /* Parse args required to build the message */
3111 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3113 if (unformat (i, "queue %d", &queue_id))
3115 else if (unformat (i, "polling"))
3116 mode = VNET_HW_IF_RX_MODE_POLLING;
3117 else if (unformat (i, "interrupt"))
3118 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
3119 else if (unformat (i, "adaptive"))
3120 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
3122 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3123 sw_if_index_set = 1;
3124 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3125 sw_if_index_set = 1;
3130 if (sw_if_index_set == 0)
3132 errmsg ("missing interface name or sw_if_index");
3135 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
3137 errmsg ("missing rx-mode");
3141 /* Construct the API message */
3142 M (SW_INTERFACE_SET_RX_MODE, mp);
3143 mp->sw_if_index = ntohl (sw_if_index);
3144 mp->mode = (vl_api_rx_mode_t) mode;
3145 mp->queue_id_valid = queue_id_valid;
3146 mp->queue_id = queue_id_valid ? ntohl (queue_id) : ~0;
3151 /* Wait for a reply, return the good/bad news... */
3157 api_sw_interface_set_rx_placement (vat_main_t * vam)
3159 unformat_input_t *i = vam->input;
3160 vl_api_sw_interface_set_rx_placement_t *mp;
3162 u8 sw_if_index_set = 0;
3165 u32 queue_id, thread_index;
3167 /* Parse args required to build the message */
3168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3170 if (unformat (i, "queue %d", &queue_id))
3172 else if (unformat (i, "main"))
3174 else if (unformat (i, "worker %d", &thread_index))
3177 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3178 sw_if_index_set = 1;
3179 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3180 sw_if_index_set = 1;
3185 if (sw_if_index_set == 0)
3187 errmsg ("missing interface name or sw_if_index");
3193 /* Construct the API message */
3194 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
3195 mp->sw_if_index = ntohl (sw_if_index);
3196 mp->worker_id = ntohl (thread_index);
3197 mp->queue_id = ntohl (queue_id);
3198 mp->is_main = is_main;
3202 /* Wait for a reply, return the good/bad news... */
3207 static void vl_api_sw_interface_rx_placement_details_t_handler
3208 (vl_api_sw_interface_rx_placement_details_t * mp)
3210 vat_main_t *vam = &vat_main;
3211 u32 worker_id = ntohl (mp->worker_id);
3214 "\n%-11d %-11s %-6d %-5d %-9s",
3215 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
3216 worker_id, ntohl (mp->queue_id),
3218 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
3221 static void vl_api_sw_interface_rx_placement_details_t_handler_json
3222 (vl_api_sw_interface_rx_placement_details_t * mp)
3224 vat_main_t *vam = &vat_main;
3225 vat_json_node_t *node = NULL;
3227 if (VAT_JSON_ARRAY != vam->json_tree.type)
3229 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
3230 vat_json_init_array (&vam->json_tree);
3232 node = vat_json_array_add (&vam->json_tree);
3234 vat_json_init_object (node);
3235 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
3236 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
3237 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
3238 vat_json_object_add_uint (node, "mode", mp->mode);
3242 api_sw_interface_rx_placement_dump (vat_main_t * vam)
3244 unformat_input_t *i = vam->input;
3245 vl_api_sw_interface_rx_placement_dump_t *mp;
3246 vl_api_control_ping_t *mp_ping;
3249 u8 sw_if_index_set = 0;
3251 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3253 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3255 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3262 "\n%-11s %-11s %-6s %-5s %-4s",
3263 "sw_if_index", "main/worker", "thread", "queue", "mode");
3265 /* Dump Interface rx placement */
3266 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
3268 if (sw_if_index_set)
3269 mp->sw_if_index = htonl (sw_if_index);
3271 mp->sw_if_index = ~0;
3275 /* Use a control ping for synchronization */
3276 MPING (CONTROL_PING, mp_ping);
3284 api_sw_interface_clear_stats (vat_main_t * vam)
3286 unformat_input_t *i = vam->input;
3287 vl_api_sw_interface_clear_stats_t *mp;
3289 u8 sw_if_index_set = 0;
3292 /* Parse args required to build the message */
3293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3295 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3296 sw_if_index_set = 1;
3297 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3298 sw_if_index_set = 1;
3303 /* Construct the API message */
3304 M (SW_INTERFACE_CLEAR_STATS, mp);
3306 if (sw_if_index_set == 1)
3307 mp->sw_if_index = ntohl (sw_if_index);
3309 mp->sw_if_index = ~0;
3314 /* Wait for a reply, return the good/bad news... */
3320 api_sw_interface_add_del_address (vat_main_t * vam)
3322 unformat_input_t *i = vam->input;
3323 vl_api_sw_interface_add_del_address_t *mp;
3325 u8 sw_if_index_set = 0;
3326 u8 is_add = 1, del_all = 0;
3327 u32 address_length = 0;
3328 u8 v4_address_set = 0;
3329 u8 v6_address_set = 0;
3330 ip4_address_t v4address;
3331 ip6_address_t v6address;
3334 /* Parse args required to build the message */
3335 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3337 if (unformat (i, "del-all"))
3339 else if (unformat (i, "del"))
3342 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3343 sw_if_index_set = 1;
3344 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3345 sw_if_index_set = 1;
3346 else if (unformat (i, "%U/%d",
3347 unformat_ip4_address, &v4address, &address_length))
3349 else if (unformat (i, "%U/%d",
3350 unformat_ip6_address, &v6address, &address_length))
3356 if (sw_if_index_set == 0)
3358 errmsg ("missing interface name or sw_if_index");
3361 if (v4_address_set && v6_address_set)
3363 errmsg ("both v4 and v6 addresses set");
3366 if (!v4_address_set && !v6_address_set && !del_all)
3368 errmsg ("no addresses set");
3372 /* Construct the API message */
3373 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
3375 mp->sw_if_index = ntohl (sw_if_index);
3376 mp->is_add = is_add;
3377 mp->del_all = del_all;
3380 mp->prefix.address.af = ADDRESS_IP6;
3381 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
3385 mp->prefix.address.af = ADDRESS_IP4;
3386 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
3388 mp->prefix.len = address_length;
3393 /* Wait for a reply, return good/bad news */
3399 api_sw_interface_set_mpls_enable (vat_main_t * vam)
3401 unformat_input_t *i = vam->input;
3402 vl_api_sw_interface_set_mpls_enable_t *mp;
3404 u8 sw_if_index_set = 0;
3408 /* Parse args required to build the message */
3409 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3411 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3412 sw_if_index_set = 1;
3413 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3414 sw_if_index_set = 1;
3415 else if (unformat (i, "disable"))
3417 else if (unformat (i, "dis"))
3423 if (sw_if_index_set == 0)
3425 errmsg ("missing interface name or sw_if_index");
3429 /* Construct the API message */
3430 M (SW_INTERFACE_SET_MPLS_ENABLE, mp);
3432 mp->sw_if_index = ntohl (sw_if_index);
3433 mp->enable = enable;
3438 /* Wait for a reply... */
3444 api_sw_interface_set_table (vat_main_t * vam)
3446 unformat_input_t *i = vam->input;
3447 vl_api_sw_interface_set_table_t *mp;
3448 u32 sw_if_index, vrf_id = 0;
3449 u8 sw_if_index_set = 0;
3453 /* Parse args required to build the message */
3454 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3456 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3457 sw_if_index_set = 1;
3458 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3459 sw_if_index_set = 1;
3460 else if (unformat (i, "vrf %d", &vrf_id))
3462 else if (unformat (i, "ipv6"))
3468 if (sw_if_index_set == 0)
3470 errmsg ("missing interface name or sw_if_index");
3474 /* Construct the API message */
3475 M (SW_INTERFACE_SET_TABLE, mp);
3477 mp->sw_if_index = ntohl (sw_if_index);
3478 mp->is_ipv6 = is_ipv6;
3479 mp->vrf_id = ntohl (vrf_id);
3484 /* Wait for a reply... */
3489 static void vl_api_sw_interface_get_table_reply_t_handler
3490 (vl_api_sw_interface_get_table_reply_t * mp)
3492 vat_main_t *vam = &vat_main;
3494 print (vam->ofp, "%d", ntohl (mp->vrf_id));
3496 vam->retval = ntohl (mp->retval);
3497 vam->result_ready = 1;
3501 static void vl_api_sw_interface_get_table_reply_t_handler_json
3502 (vl_api_sw_interface_get_table_reply_t * mp)
3504 vat_main_t *vam = &vat_main;
3505 vat_json_node_t node;
3507 vat_json_init_object (&node);
3508 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
3509 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
3511 vat_json_print (vam->ofp, &node);
3512 vat_json_free (&node);
3514 vam->retval = ntohl (mp->retval);
3515 vam->result_ready = 1;
3519 api_sw_interface_get_table (vat_main_t * vam)
3521 unformat_input_t *i = vam->input;
3522 vl_api_sw_interface_get_table_t *mp;
3524 u8 sw_if_index_set = 0;
3528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3530 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3531 sw_if_index_set = 1;
3532 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3533 sw_if_index_set = 1;
3534 else if (unformat (i, "ipv6"))
3540 if (sw_if_index_set == 0)
3542 errmsg ("missing interface name or sw_if_index");
3546 M (SW_INTERFACE_GET_TABLE, mp);
3547 mp->sw_if_index = htonl (sw_if_index);
3548 mp->is_ipv6 = is_ipv6;
3556 api_sw_interface_set_vpath (vat_main_t * vam)
3558 unformat_input_t *i = vam->input;
3559 vl_api_sw_interface_set_vpath_t *mp;
3560 u32 sw_if_index = 0;
3561 u8 sw_if_index_set = 0;
3565 /* Parse args required to build the message */
3566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3568 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3569 sw_if_index_set = 1;
3570 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3571 sw_if_index_set = 1;
3572 else if (unformat (i, "enable"))
3574 else if (unformat (i, "disable"))
3580 if (sw_if_index_set == 0)
3582 errmsg ("missing interface name or sw_if_index");
3586 /* Construct the API message */
3587 M (SW_INTERFACE_SET_VPATH, mp);
3589 mp->sw_if_index = ntohl (sw_if_index);
3590 mp->enable = is_enable;
3595 /* Wait for a reply... */
3601 api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3603 unformat_input_t *i = vam->input;
3604 vl_api_sw_interface_set_l2_xconnect_t *mp;
3606 u8 rx_sw_if_index_set = 0;
3608 u8 tx_sw_if_index_set = 0;
3612 /* Parse args required to build the message */
3613 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3615 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3616 rx_sw_if_index_set = 1;
3617 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3618 tx_sw_if_index_set = 1;
3619 else if (unformat (i, "rx"))
3621 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3623 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3625 rx_sw_if_index_set = 1;
3630 else if (unformat (i, "tx"))
3632 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3634 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
3636 tx_sw_if_index_set = 1;
3641 else if (unformat (i, "enable"))
3643 else if (unformat (i, "disable"))
3649 if (rx_sw_if_index_set == 0)
3651 errmsg ("missing rx interface name or rx_sw_if_index");
3655 if (enable && (tx_sw_if_index_set == 0))
3657 errmsg ("missing tx interface name or tx_sw_if_index");
3661 M (SW_INTERFACE_SET_L2_XCONNECT, mp);
3663 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3664 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
3665 mp->enable = enable;
3673 api_sw_interface_set_l2_bridge (vat_main_t * vam)
3675 unformat_input_t *i = vam->input;
3676 vl_api_sw_interface_set_l2_bridge_t *mp;
3677 vl_api_l2_port_type_t port_type;
3679 u8 rx_sw_if_index_set = 0;
3686 port_type = L2_API_PORT_TYPE_NORMAL;
3688 /* Parse args required to build the message */
3689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3691 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3692 rx_sw_if_index_set = 1;
3693 else if (unformat (i, "bd_id %d", &bd_id))
3697 (i, "%U", api_unformat_sw_if_index, vam, &rx_sw_if_index))
3698 rx_sw_if_index_set = 1;
3699 else if (unformat (i, "shg %d", &shg))
3701 else if (unformat (i, "bvi"))
3702 port_type = L2_API_PORT_TYPE_BVI;
3703 else if (unformat (i, "uu-fwd"))
3704 port_type = L2_API_PORT_TYPE_UU_FWD;
3705 else if (unformat (i, "enable"))
3707 else if (unformat (i, "disable"))
3713 if (rx_sw_if_index_set == 0)
3715 errmsg ("missing rx interface name or sw_if_index");
3719 if (enable && (bd_id_set == 0))
3721 errmsg ("missing bridge domain");
3725 M (SW_INTERFACE_SET_L2_BRIDGE, mp);
3727 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
3728 mp->bd_id = ntohl (bd_id);
3730 mp->port_type = ntohl (port_type);
3731 mp->enable = enable;
3739 api_bridge_domain_dump (vat_main_t * vam)
3741 unformat_input_t *i = vam->input;
3742 vl_api_bridge_domain_dump_t *mp;
3743 vl_api_control_ping_t *mp_ping;
3747 /* Parse args required to build the message */
3748 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3750 if (unformat (i, "bd_id %d", &bd_id))
3756 M (BRIDGE_DOMAIN_DUMP, mp);
3757 mp->bd_id = ntohl (bd_id);
3760 /* Use a control ping for synchronization */
3761 MPING (CONTROL_PING, mp_ping);
3769 api_bridge_domain_add_del (vat_main_t * vam)
3771 unformat_input_t *i = vam->input;
3772 vl_api_bridge_domain_add_del_t *mp;
3775 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3780 /* Parse args required to build the message */
3781 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3783 if (unformat (i, "bd_id %d", &bd_id))
3785 else if (unformat (i, "flood %d", &flood))
3787 else if (unformat (i, "uu-flood %d", &uu_flood))
3789 else if (unformat (i, "forward %d", &forward))
3791 else if (unformat (i, "learn %d", &learn))
3793 else if (unformat (i, "arp-term %d", &arp_term))
3795 else if (unformat (i, "mac-age %d", &mac_age))
3797 else if (unformat (i, "bd-tag %s", &bd_tag))
3799 else if (unformat (i, "del"))
3802 flood = uu_flood = forward = learn = 0;
3810 errmsg ("missing bridge domain");
3817 errmsg ("mac age must be less than 256 ");
3822 if ((bd_tag) && (vec_len (bd_tag) > 63))
3824 errmsg ("bd-tag cannot be longer than 63");
3829 M (BRIDGE_DOMAIN_ADD_DEL, mp);
3831 mp->bd_id = ntohl (bd_id);
3833 mp->uu_flood = uu_flood;
3834 mp->forward = forward;
3836 mp->arp_term = arp_term;
3837 mp->is_add = is_add;
3838 mp->mac_age = (u8) mac_age;
3841 clib_memcpy (mp->bd_tag, bd_tag, vec_len (bd_tag));
3842 mp->bd_tag[vec_len (bd_tag)] = 0;
3853 api_l2fib_flush_bd (vat_main_t * vam)
3855 unformat_input_t *i = vam->input;
3856 vl_api_l2fib_flush_bd_t *mp;
3860 /* Parse args required to build the message */
3861 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3863 if (unformat (i, "bd_id %d", &bd_id));
3870 errmsg ("missing bridge domain");
3874 M (L2FIB_FLUSH_BD, mp);
3876 mp->bd_id = htonl (bd_id);
3884 api_l2fib_flush_int (vat_main_t * vam)
3886 unformat_input_t *i = vam->input;
3887 vl_api_l2fib_flush_int_t *mp;
3888 u32 sw_if_index = ~0;
3891 /* Parse args required to build the message */
3892 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3894 if (unformat (i, "sw_if_index %d", &sw_if_index));
3896 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index));
3901 if (sw_if_index == ~0)
3903 errmsg ("missing interface name or sw_if_index");
3907 M (L2FIB_FLUSH_INT, mp);
3909 mp->sw_if_index = ntohl (sw_if_index);
3917 api_l2fib_add_del (vat_main_t * vam)
3919 unformat_input_t *i = vam->input;
3920 vl_api_l2fib_add_del_t *mp;
3926 u32 sw_if_index = 0;
3927 u8 sw_if_index_set = 0;
3936 /* Parse args required to build the message */
3937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3939 if (unformat (i, "mac %U", unformat_ethernet_address, mac))
3941 else if (unformat (i, "bd_id %d", &bd_id))
3943 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3944 sw_if_index_set = 1;
3945 else if (unformat (i, "sw_if"))
3947 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3950 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3951 sw_if_index_set = 1;
3956 else if (unformat (i, "static"))
3958 else if (unformat (i, "filter"))
3963 else if (unformat (i, "bvi"))
3968 else if (unformat (i, "del"))
3970 else if (unformat (i, "count %d", &count))
3978 errmsg ("missing mac address");
3984 errmsg ("missing bridge domain");
3988 if (is_add && sw_if_index_set == 0 && filter_mac == 0)
3990 errmsg ("missing interface name or sw_if_index");
3996 /* Turn on async mode */
3997 vam->async_mode = 1;
3998 vam->async_errors = 0;
3999 before = vat_time_now (vam);
4002 for (j = 0; j < count; j++)
4004 M (L2FIB_ADD_DEL, mp);
4006 clib_memcpy (mp->mac, mac, 6);
4007 mp->bd_id = ntohl (bd_id);
4008 mp->is_add = is_add;
4009 mp->sw_if_index = ntohl (sw_if_index);
4013 mp->static_mac = static_mac;
4014 mp->filter_mac = filter_mac;
4015 mp->bvi_mac = bvi_mac;
4017 increment_mac_address (mac);
4024 vl_api_control_ping_t *mp_ping;
4027 /* Shut off async mode */
4028 vam->async_mode = 0;
4030 MPING (CONTROL_PING, mp_ping);
4033 timeout = vat_time_now (vam) + 1.0;
4034 while (vat_time_now (vam) < timeout)
4035 if (vam->result_ready == 1)
4040 if (vam->retval == -99)
4043 if (vam->async_errors > 0)
4045 errmsg ("%d asynchronous errors", vam->async_errors);
4048 vam->async_errors = 0;
4049 after = vat_time_now (vam);
4051 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
4052 count, after - before, count / (after - before));
4058 /* Wait for a reply... */
4062 /* Return the good/bad news */
4063 return (vam->retval);
4067 api_bridge_domain_set_mac_age (vat_main_t * vam)
4069 unformat_input_t *i = vam->input;
4070 vl_api_bridge_domain_set_mac_age_t *mp;
4075 /* Parse args required to build the message */
4076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4078 if (unformat (i, "bd_id %d", &bd_id));
4079 else if (unformat (i, "mac-age %d", &mac_age));
4086 errmsg ("missing bridge domain");
4092 errmsg ("mac age must be less than 256 ");
4096 M (BRIDGE_DOMAIN_SET_MAC_AGE, mp);
4098 mp->bd_id = htonl (bd_id);
4099 mp->mac_age = (u8) mac_age;
4107 api_l2_flags (vat_main_t * vam)
4109 unformat_input_t *i = vam->input;
4110 vl_api_l2_flags_t *mp;
4113 u8 sw_if_index_set = 0;
4117 /* Parse args required to build the message */
4118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4120 if (unformat (i, "sw_if_index %d", &sw_if_index))
4121 sw_if_index_set = 1;
4122 else if (unformat (i, "sw_if"))
4124 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4127 (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4128 sw_if_index_set = 1;
4133 else if (unformat (i, "learn"))
4135 else if (unformat (i, "forward"))
4137 else if (unformat (i, "flood"))
4139 else if (unformat (i, "uu-flood"))
4140 flags |= L2_UU_FLOOD;
4141 else if (unformat (i, "arp-term"))
4142 flags |= L2_ARP_TERM;
4143 else if (unformat (i, "off"))
4145 else if (unformat (i, "disable"))
4151 if (sw_if_index_set == 0)
4153 errmsg ("missing interface name or sw_if_index");
4159 mp->sw_if_index = ntohl (sw_if_index);
4160 mp->feature_bitmap = ntohl (flags);
4161 mp->is_set = is_set;
4169 api_bridge_flags (vat_main_t * vam)
4171 unformat_input_t *i = vam->input;
4172 vl_api_bridge_flags_t *mp;
4176 bd_flags_t flags = 0;
4179 /* Parse args required to build the message */
4180 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4182 if (unformat (i, "bd_id %d", &bd_id))
4184 else if (unformat (i, "learn"))
4185 flags |= BRIDGE_API_FLAG_LEARN;
4186 else if (unformat (i, "forward"))
4187 flags |= BRIDGE_API_FLAG_FWD;
4188 else if (unformat (i, "flood"))
4189 flags |= BRIDGE_API_FLAG_FLOOD;
4190 else if (unformat (i, "uu-flood"))
4191 flags |= BRIDGE_API_FLAG_UU_FLOOD;
4192 else if (unformat (i, "arp-term"))
4193 flags |= BRIDGE_API_FLAG_ARP_TERM;
4194 else if (unformat (i, "off"))
4196 else if (unformat (i, "disable"))
4204 errmsg ("missing bridge domain");
4208 M (BRIDGE_FLAGS, mp);
4210 mp->bd_id = ntohl (bd_id);
4211 mp->flags = ntohl (flags);
4212 mp->is_set = is_set;
4220 api_bd_ip_mac_add_del (vat_main_t * vam)
4222 vl_api_address_t ip = VL_API_ZERO_ADDRESS;
4223 vl_api_mac_address_t mac = { 0 };
4224 unformat_input_t *i = vam->input;
4225 vl_api_bd_ip_mac_add_del_t *mp;
4234 /* Parse args required to build the message */
4235 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4237 if (unformat (i, "bd_id %d", &bd_id))
4241 else if (unformat (i, "%U", unformat_vl_api_address, &ip))
4245 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
4249 else if (unformat (i, "del"))
4257 errmsg ("missing bridge domain");
4260 else if (ip_set == 0)
4262 errmsg ("missing IP address");
4265 else if (mac_set == 0)
4267 errmsg ("missing MAC address");
4271 M (BD_IP_MAC_ADD_DEL, mp);
4273 mp->entry.bd_id = ntohl (bd_id);
4274 mp->is_add = is_add;
4276 clib_memcpy (&mp->entry.ip, &ip, sizeof (ip));
4277 clib_memcpy (&mp->entry.mac, &mac, sizeof (mac));
4285 api_bd_ip_mac_flush (vat_main_t * vam)
4287 unformat_input_t *i = vam->input;
4288 vl_api_bd_ip_mac_flush_t *mp;
4293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4295 if (unformat (i, "bd_id %d", &bd_id))
4305 errmsg ("missing bridge domain");
4309 M (BD_IP_MAC_FLUSH, mp);
4311 mp->bd_id = ntohl (bd_id);
4318 static void vl_api_bd_ip_mac_details_t_handler
4319 (vl_api_bd_ip_mac_details_t * mp)
4321 vat_main_t *vam = &vat_main;
4325 ntohl (mp->entry.bd_id),
4326 format_vl_api_mac_address, mp->entry.mac,
4327 format_vl_api_address, &mp->entry.ip);
4330 static void vl_api_bd_ip_mac_details_t_handler_json
4331 (vl_api_bd_ip_mac_details_t * mp)
4333 vat_main_t *vam = &vat_main;
4334 vat_json_node_t *node = NULL;
4336 if (VAT_JSON_ARRAY != vam->json_tree.type)
4338 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4339 vat_json_init_array (&vam->json_tree);
4341 node = vat_json_array_add (&vam->json_tree);
4343 vat_json_init_object (node);
4344 vat_json_object_add_uint (node, "bd_id", ntohl (mp->entry.bd_id));
4345 vat_json_object_add_string_copy (node, "mac_address",
4346 format (0, "%U", format_vl_api_mac_address,
4350 ip = format (0, "%U", format_vl_api_address, &mp->entry.ip);
4351 vat_json_object_add_string_copy (node, "ip_address", ip);
4356 api_bd_ip_mac_dump (vat_main_t * vam)
4358 unformat_input_t *i = vam->input;
4359 vl_api_bd_ip_mac_dump_t *mp;
4360 vl_api_control_ping_t *mp_ping;
4365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4367 if (unformat (i, "bd_id %d", &bd_id))
4376 "\n%-5s %-7s %-20s %-30s",
4377 "bd_id", "is_ipv6", "mac_address", "ip_address");
4379 /* Dump Bridge Domain Ip to Mac entries */
4380 M (BD_IP_MAC_DUMP, mp);
4383 mp->bd_id = htonl (bd_id);
4389 /* Use a control ping for synchronization */
4390 MPING (CONTROL_PING, mp_ping);
4398 api_tap_create_v2 (vat_main_t * vam)
4400 unformat_input_t *i = vam->input;
4401 vl_api_tap_create_v2_t *mp;
4405 u32 num_rx_queues = 0;
4406 u8 *host_if_name = 0;
4407 u8 host_if_name_set = 0;
4410 u8 host_mac_addr[6];
4411 u8 host_mac_addr_set = 0;
4412 u8 *host_bridge = 0;
4413 u8 host_bridge_set = 0;
4414 u8 host_ip4_prefix_set = 0;
4415 u8 host_ip6_prefix_set = 0;
4416 ip4_address_t host_ip4_addr;
4417 ip4_address_t host_ip4_gw;
4418 u8 host_ip4_gw_set = 0;
4419 u32 host_ip4_prefix_len = 0;
4420 ip6_address_t host_ip6_addr;
4421 ip6_address_t host_ip6_gw;
4422 u8 host_ip6_gw_set = 0;
4423 u32 host_ip6_prefix_len = 0;
4424 u32 host_mtu_size = 0;
4425 u8 host_mtu_set = 0;
4428 u32 rx_ring_sz = 0, tx_ring_sz = 0;
4430 clib_memset (mac_address, 0, sizeof (mac_address));
4432 /* Parse args required to build the message */
4433 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4435 if (unformat (i, "id %u", &id))
4439 (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4441 else if (unformat (i, "host-if-name %s", &host_if_name))
4442 host_if_name_set = 1;
4443 else if (unformat (i, "num-rx-queues %u", &num_rx_queues))
4445 else if (unformat (i, "host-ns %s", &host_ns))
4447 else if (unformat (i, "host-mac-addr %U", unformat_ethernet_address,
4449 host_mac_addr_set = 1;
4450 else if (unformat (i, "host-bridge %s", &host_bridge))
4451 host_bridge_set = 1;
4452 else if (unformat (i, "host-ip4-addr %U/%u", unformat_ip4_address,
4453 &host_ip4_addr, &host_ip4_prefix_len))
4454 host_ip4_prefix_set = 1;
4455 else if (unformat (i, "host-ip6-addr %U/%u", unformat_ip6_address,
4456 &host_ip6_addr, &host_ip6_prefix_len))
4457 host_ip6_prefix_set = 1;
4458 else if (unformat (i, "host-ip4-gw %U", unformat_ip4_address,
4460 host_ip4_gw_set = 1;
4461 else if (unformat (i, "host-ip6-gw %U", unformat_ip6_address,
4463 host_ip6_gw_set = 1;
4464 else if (unformat (i, "rx-ring-size %u", &rx_ring_sz))
4466 else if (unformat (i, "tx-ring-size %u", &tx_ring_sz))
4468 else if (unformat (i, "host-mtu-size %u", &host_mtu_size))
4470 else if (unformat (i, "no-gso"))
4471 tap_flags &= ~TAP_API_FLAG_GSO;
4472 else if (unformat (i, "gso"))
4473 tap_flags |= TAP_API_FLAG_GSO;
4474 else if (unformat (i, "csum-offload"))
4475 tap_flags |= TAP_API_FLAG_CSUM_OFFLOAD;
4476 else if (unformat (i, "persist"))
4477 tap_flags |= TAP_API_FLAG_PERSIST;
4478 else if (unformat (i, "attach"))
4479 tap_flags |= TAP_API_FLAG_ATTACH;
4480 else if (unformat (i, "tun"))
4481 tap_flags |= TAP_API_FLAG_TUN;
4482 else if (unformat (i, "gro-coalesce"))
4483 tap_flags |= TAP_API_FLAG_GRO_COALESCE;
4484 else if (unformat (i, "packed"))
4485 tap_flags |= TAP_API_FLAG_PACKED;
4486 else if (unformat (i, "in-order"))
4487 tap_flags |= TAP_API_FLAG_IN_ORDER;
4492 if (vec_len (host_if_name) > 63)
4494 errmsg ("tap name too long. ");
4497 if (vec_len (host_ns) > 63)
4499 errmsg ("host name space too long. ");
4502 if (vec_len (host_bridge) > 63)
4504 errmsg ("host bridge name too long. ");
4507 if (host_ip4_prefix_len > 32)
4509 errmsg ("host ip4 prefix length not valid. ");
4512 if (host_ip6_prefix_len > 128)
4514 errmsg ("host ip6 prefix length not valid. ");
4517 if (!is_pow2 (rx_ring_sz))
4519 errmsg ("rx ring size must be power of 2. ");
4522 if (rx_ring_sz > 32768)
4524 errmsg ("rx ring size must be 32768 or lower. ");
4527 if (!is_pow2 (tx_ring_sz))
4529 errmsg ("tx ring size must be power of 2. ");
4532 if (tx_ring_sz > 32768)
4534 errmsg ("tx ring size must be 32768 or lower. ");
4537 if (host_mtu_set && (host_mtu_size < 64 || host_mtu_size > 65355))
4539 errmsg ("host MTU size must be in between 64 and 65355. ");
4543 /* Construct the API message */
4544 M (TAP_CREATE_V2, mp);
4546 mp->id = ntohl (id);
4547 mp->use_random_mac = random_mac;
4548 mp->num_rx_queues = (u8) num_rx_queues;
4549 mp->tx_ring_sz = ntohs (tx_ring_sz);
4550 mp->rx_ring_sz = ntohs (rx_ring_sz);
4551 mp->host_mtu_set = host_mtu_set;
4552 mp->host_mtu_size = ntohl (host_mtu_size);
4553 mp->host_mac_addr_set = host_mac_addr_set;
4554 mp->host_ip4_prefix_set = host_ip4_prefix_set;
4555 mp->host_ip6_prefix_set = host_ip6_prefix_set;
4556 mp->host_ip4_gw_set = host_ip4_gw_set;
4557 mp->host_ip6_gw_set = host_ip6_gw_set;
4558 mp->tap_flags = ntohl (tap_flags);
4559 mp->host_namespace_set = host_ns_set;
4560 mp->host_if_name_set = host_if_name_set;
4561 mp->host_bridge_set = host_bridge_set;
4563 if (random_mac == 0)
4564 clib_memcpy (mp->mac_address, mac_address, 6);
4565 if (host_mac_addr_set)
4566 clib_memcpy (mp->host_mac_addr, host_mac_addr, 6);
4567 if (host_if_name_set)
4568 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
4570 clib_memcpy (mp->host_namespace, host_ns, vec_len (host_ns));
4571 if (host_bridge_set)
4572 clib_memcpy (mp->host_bridge, host_bridge, vec_len (host_bridge));
4573 if (host_ip4_prefix_set)
4575 clib_memcpy (mp->host_ip4_prefix.address, &host_ip4_addr, 4);
4576 mp->host_ip4_prefix.len = (u8) host_ip4_prefix_len;
4578 if (host_ip6_prefix_set)
4580 clib_memcpy (mp->host_ip6_prefix.address, &host_ip6_addr, 16);
4581 mp->host_ip6_prefix.len = (u8) host_ip6_prefix_len;
4583 if (host_ip4_gw_set)
4584 clib_memcpy (mp->host_ip4_gw, &host_ip4_gw, 4);
4585 if (host_ip6_gw_set)
4586 clib_memcpy (mp->host_ip6_gw, &host_ip6_gw, 16);
4589 vec_free (host_if_name);
4590 vec_free (host_bridge);
4595 /* Wait for a reply... */
4601 api_tap_delete_v2 (vat_main_t * vam)
4603 unformat_input_t *i = vam->input;
4604 vl_api_tap_delete_v2_t *mp;
4605 u32 sw_if_index = ~0;
4606 u8 sw_if_index_set = 0;
4609 /* Parse args required to build the message */
4610 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4612 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4613 sw_if_index_set = 1;
4614 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4615 sw_if_index_set = 1;
4620 if (sw_if_index_set == 0)
4622 errmsg ("missing vpp interface name. ");
4626 /* Construct the API message */
4627 M (TAP_DELETE_V2, mp);
4629 mp->sw_if_index = ntohl (sw_if_index);
4634 /* Wait for a reply... */
4640 unformat_vlib_pci_addr (unformat_input_t * input, va_list * args)
4642 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
4645 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
4648 addr->domain = x[0];
4651 addr->function = x[3];
4657 api_virtio_pci_create_v2 (vat_main_t * vam)
4659 unformat_input_t *i = vam->input;
4660 vl_api_virtio_pci_create_v2_t *mp;
4664 u64 features = (u64) ~ (0ULL);
4665 u32 virtio_flags = 0;
4668 clib_memset (mac_address, 0, sizeof (mac_address));
4670 /* Parse args required to build the message */
4671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4673 if (unformat (i, "hw-addr %U", unformat_ethernet_address, mac_address))
4677 else if (unformat (i, "pci-addr %U", unformat_vlib_pci_addr, &pci_addr))
4679 else if (unformat (i, "features 0x%llx", &features))
4681 else if (unformat (i, "gso-enabled"))
4682 virtio_flags |= VIRTIO_API_FLAG_GSO;
4683 else if (unformat (i, "csum-offload-enabled"))
4684 virtio_flags |= VIRTIO_API_FLAG_CSUM_OFFLOAD;
4685 else if (unformat (i, "gro-coalesce"))
4686 virtio_flags |= VIRTIO_API_FLAG_GRO_COALESCE;
4687 else if (unformat (i, "packed"))
4688 virtio_flags |= VIRTIO_API_FLAG_PACKED;
4689 else if (unformat (i, "in-order"))
4690 virtio_flags |= VIRTIO_API_FLAG_IN_ORDER;
4691 else if (unformat (i, "buffering"))
4692 virtio_flags |= VIRTIO_API_FLAG_BUFFERING;
4699 errmsg ("pci address must be non zero. ");
4703 /* Construct the API message */
4704 M (VIRTIO_PCI_CREATE_V2, mp);
4706 mp->use_random_mac = random_mac;
4708 mp->pci_addr.domain = htons (((vlib_pci_addr_t) pci_addr).domain);
4709 mp->pci_addr.bus = ((vlib_pci_addr_t) pci_addr).bus;
4710 mp->pci_addr.slot = ((vlib_pci_addr_t) pci_addr).slot;
4711 mp->pci_addr.function = ((vlib_pci_addr_t) pci_addr).function;
4713 mp->features = clib_host_to_net_u64 (features);
4714 mp->virtio_flags = clib_host_to_net_u32 (virtio_flags);
4716 if (random_mac == 0)
4717 clib_memcpy (mp->mac_address, mac_address, 6);
4722 /* Wait for a reply... */
4728 api_virtio_pci_delete (vat_main_t * vam)
4730 unformat_input_t *i = vam->input;
4731 vl_api_virtio_pci_delete_t *mp;
4732 u32 sw_if_index = ~0;
4733 u8 sw_if_index_set = 0;
4736 /* Parse args required to build the message */
4737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4739 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4740 sw_if_index_set = 1;
4741 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4742 sw_if_index_set = 1;
4747 if (sw_if_index_set == 0)
4749 errmsg ("missing vpp interface name. ");
4753 /* Construct the API message */
4754 M (VIRTIO_PCI_DELETE, mp);
4756 mp->sw_if_index = htonl (sw_if_index);
4761 /* Wait for a reply... */
4767 api_bond_create (vat_main_t * vam)
4769 unformat_input_t *i = vam->input;
4770 vl_api_bond_create_t *mp;
4780 clib_memset (mac_address, 0, sizeof (mac_address));
4783 /* Parse args required to build the message */
4784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4786 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
4788 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
4789 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
4791 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
4794 else if (unformat (i, "numa-only"))
4796 else if (unformat (i, "id %u", &id))
4802 if (mode_is_set == 0)
4804 errmsg ("Missing bond mode. ");
4808 /* Construct the API message */
4809 M (BOND_CREATE, mp);
4811 mp->use_custom_mac = custom_mac;
4813 mp->mode = htonl (mode);
4814 mp->lb = htonl (lb);
4815 mp->id = htonl (id);
4816 mp->numa_only = numa_only;
4819 clib_memcpy (mp->mac_address, mac_address, 6);
4824 /* Wait for a reply... */
4830 api_bond_create2 (vat_main_t * vam)
4832 unformat_input_t *i = vam->input;
4833 vl_api_bond_create2_t *mp;
4844 clib_memset (mac_address, 0, sizeof (mac_address));
4847 /* Parse args required to build the message */
4848 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4850 if (unformat (i, "mode %U", unformat_bond_mode, &mode))
4852 else if (((mode == BOND_MODE_LACP) || (mode == BOND_MODE_XOR))
4853 && unformat (i, "lb %U", unformat_bond_load_balance, &lb))
4855 else if (unformat (i, "hw-addr %U", unformat_ethernet_address,
4858 else if (unformat (i, "numa-only"))
4860 else if (unformat (i, "gso"))
4862 else if (unformat (i, "id %u", &id))
4868 if (mode_is_set == 0)
4870 errmsg ("Missing bond mode. ");
4874 /* Construct the API message */
4875 M (BOND_CREATE2, mp);
4877 mp->use_custom_mac = custom_mac;
4879 mp->mode = htonl (mode);
4880 mp->lb = htonl (lb);
4881 mp->id = htonl (id);
4882 mp->numa_only = numa_only;
4883 mp->enable_gso = gso;
4886 clib_memcpy (mp->mac_address, mac_address, 6);
4891 /* Wait for a reply... */
4897 api_bond_delete (vat_main_t * vam)
4899 unformat_input_t *i = vam->input;
4900 vl_api_bond_delete_t *mp;
4901 u32 sw_if_index = ~0;
4902 u8 sw_if_index_set = 0;
4905 /* Parse args required to build the message */
4906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4908 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
4909 sw_if_index_set = 1;
4910 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4911 sw_if_index_set = 1;
4916 if (sw_if_index_set == 0)
4918 errmsg ("missing vpp interface name. ");
4922 /* Construct the API message */
4923 M (BOND_DELETE, mp);
4925 mp->sw_if_index = ntohl (sw_if_index);
4930 /* Wait for a reply... */
4936 api_bond_add_member (vat_main_t * vam)
4938 unformat_input_t *i = vam->input;
4939 vl_api_bond_add_member_t *mp;
4940 u32 bond_sw_if_index;
4944 u32 bond_sw_if_index_is_set = 0;
4946 u8 sw_if_index_is_set = 0;
4948 /* Parse args required to build the message */
4949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4951 if (unformat (i, "sw_if_index %d", &sw_if_index))
4952 sw_if_index_is_set = 1;
4953 else if (unformat (i, "bond %u", &bond_sw_if_index))
4954 bond_sw_if_index_is_set = 1;
4955 else if (unformat (i, "passive %d", &is_passive))
4957 else if (unformat (i, "long-timeout %d", &is_long_timeout))
4963 if (bond_sw_if_index_is_set == 0)
4965 errmsg ("Missing bond sw_if_index. ");
4968 if (sw_if_index_is_set == 0)
4970 errmsg ("Missing member sw_if_index. ");
4974 /* Construct the API message */
4975 M (BOND_ADD_MEMBER, mp);
4977 mp->bond_sw_if_index = ntohl (bond_sw_if_index);
4978 mp->sw_if_index = ntohl (sw_if_index);
4979 mp->is_long_timeout = is_long_timeout;
4980 mp->is_passive = is_passive;
4985 /* Wait for a reply... */
4991 api_bond_detach_member (vat_main_t * vam)
4993 unformat_input_t *i = vam->input;
4994 vl_api_bond_detach_member_t *mp;
4995 u32 sw_if_index = ~0;
4996 u8 sw_if_index_set = 0;
4999 /* Parse args required to build the message */
5000 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5002 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5003 sw_if_index_set = 1;
5004 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5005 sw_if_index_set = 1;
5010 if (sw_if_index_set == 0)
5012 errmsg ("missing vpp interface name. ");
5016 /* Construct the API message */
5017 M (BOND_DETACH_MEMBER, mp);
5019 mp->sw_if_index = ntohl (sw_if_index);
5024 /* Wait for a reply... */
5030 api_ip_table_add_del (vat_main_t * vam)
5032 unformat_input_t *i = vam->input;
5033 vl_api_ip_table_add_del_t *mp;
5039 /* Parse args required to build the message */
5040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5042 if (unformat (i, "ipv6"))
5044 else if (unformat (i, "del"))
5046 else if (unformat (i, "add"))
5048 else if (unformat (i, "table %d", &table_id))
5052 clib_warning ("parse error '%U'", format_unformat_error, i);
5059 errmsg ("missing table-ID");
5063 /* Construct the API message */
5064 M (IP_TABLE_ADD_DEL, mp);
5066 mp->table.table_id = ntohl (table_id);
5067 mp->table.is_ip6 = is_ipv6;
5068 mp->is_add = is_add;
5073 /* Wait for a reply... */
5080 unformat_fib_path (unformat_input_t * input, va_list * args)
5082 vat_main_t *vam = va_arg (*args, vat_main_t *);
5083 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
5084 u32 weight, preference;
5085 mpls_label_t out_label;
5087 clib_memset (path, 0, sizeof (*path));
5089 path->sw_if_index = ~0;
5093 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5095 if (unformat (input, "%U %U",
5096 unformat_vl_api_ip4_address,
5097 &path->nh.address.ip4,
5098 api_unformat_sw_if_index, vam, &path->sw_if_index))
5100 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5102 else if (unformat (input, "%U %U",
5103 unformat_vl_api_ip6_address,
5104 &path->nh.address.ip6,
5105 api_unformat_sw_if_index, vam, &path->sw_if_index))
5107 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5109 else if (unformat (input, "weight %u", &weight))
5111 path->weight = weight;
5113 else if (unformat (input, "preference %u", &preference))
5115 path->preference = preference;
5117 else if (unformat (input, "%U next-hop-table %d",
5118 unformat_vl_api_ip4_address,
5119 &path->nh.address.ip4, &path->table_id))
5121 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5123 else if (unformat (input, "%U next-hop-table %d",
5124 unformat_vl_api_ip6_address,
5125 &path->nh.address.ip6, &path->table_id))
5127 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5129 else if (unformat (input, "%U",
5130 unformat_vl_api_ip4_address, &path->nh.address.ip4))
5133 * the recursive next-hops are by default in the default table
5136 path->sw_if_index = ~0;
5137 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5139 else if (unformat (input, "%U",
5140 unformat_vl_api_ip6_address, &path->nh.address.ip6))
5143 * the recursive next-hops are by default in the default table
5146 path->sw_if_index = ~0;
5147 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5149 else if (unformat (input, "resolve-via-host"))
5151 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
5153 else if (unformat (input, "resolve-via-attached"))
5155 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
5157 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
5159 path->type = FIB_API_PATH_TYPE_LOCAL;
5160 path->sw_if_index = ~0;
5161 path->proto = FIB_API_PATH_NH_PROTO_IP4;
5163 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
5165 path->type = FIB_API_PATH_TYPE_LOCAL;
5166 path->sw_if_index = ~0;
5167 path->proto = FIB_API_PATH_NH_PROTO_IP6;
5169 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
5171 else if (unformat (input, "via-label %d", &path->nh.via_label))
5173 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
5174 path->sw_if_index = ~0;
5176 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
5178 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
5179 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
5181 else if (unformat (input, "local"))
5183 path->type = FIB_API_PATH_TYPE_LOCAL;
5185 else if (unformat (input, "out-labels"))
5187 while (unformat (input, "%d", &out_label))
5189 path->label_stack[path->n_labels].label = out_label;
5190 path->label_stack[path->n_labels].is_uniform = 0;
5191 path->label_stack[path->n_labels].ttl = 64;
5195 else if (unformat (input, "via"))
5197 /* new path, back up and return */
5198 unformat_put_input (input);
5199 unformat_put_input (input);
5200 unformat_put_input (input);
5201 unformat_put_input (input);
5210 path->proto = ntohl (path->proto);
5211 path->type = ntohl (path->type);
5212 path->flags = ntohl (path->flags);
5213 path->table_id = ntohl (path->table_id);
5214 path->sw_if_index = ntohl (path->sw_if_index);
5220 api_ip_route_add_del (vat_main_t * vam)
5222 unformat_input_t *i = vam->input;
5223 vl_api_ip_route_add_del_t *mp;
5226 u8 is_multipath = 0;
5229 vl_api_prefix_t pfx = { };
5230 vl_api_fib_path_t paths[8];
5234 u32 random_add_del = 0;
5235 u32 *random_vector = 0;
5236 u32 random_seed = 0xdeaddabe;
5238 /* Parse args required to build the message */
5239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5241 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5243 else if (unformat (i, "del"))
5245 else if (unformat (i, "add"))
5247 else if (unformat (i, "vrf %d", &vrf_id))
5249 else if (unformat (i, "count %d", &count))
5251 else if (unformat (i, "random"))
5253 else if (unformat (i, "multipath"))
5255 else if (unformat (i, "seed %d", &random_seed))
5259 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5262 if (8 == path_count)
5264 errmsg ("max 8 paths");
5270 clib_warning ("parse error '%U'", format_unformat_error, i);
5277 errmsg ("specify a path; via ...");
5280 if (prefix_set == 0)
5282 errmsg ("missing prefix");
5286 /* Generate a pile of unique, random routes */
5289 ip4_address_t *i = (ip4_address_t *) & paths[0].nh.address.ip4;
5290 u32 this_random_address;
5293 random_hash = hash_create (count, sizeof (uword));
5295 hash_set (random_hash, i->as_u32, 1);
5296 for (j = 0; j <= count; j++)
5300 this_random_address = random_u32 (&random_seed);
5301 this_random_address =
5302 clib_host_to_net_u32 (this_random_address);
5304 while (hash_get (random_hash, this_random_address));
5305 vec_add1 (random_vector, this_random_address);
5306 hash_set (random_hash, this_random_address, 1);
5308 hash_free (random_hash);
5309 set_ip4_address (&pfx.address, random_vector[0]);
5314 /* Turn on async mode */
5315 vam->async_mode = 1;
5316 vam->async_errors = 0;
5317 before = vat_time_now (vam);
5320 for (j = 0; j < count; j++)
5322 /* Construct the API message */
5323 M2 (IP_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5325 mp->is_add = is_add;
5326 mp->is_multipath = is_multipath;
5328 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5329 mp->route.table_id = ntohl (vrf_id);
5330 mp->route.n_paths = path_count;
5332 clib_memcpy (&mp->route.paths, &paths, sizeof (paths[0]) * path_count);
5335 set_ip4_address (&pfx.address, random_vector[j + 1]);
5337 increment_address (&pfx.address);
5340 /* If we receive SIGTERM, stop now... */
5345 /* When testing multiple add/del ops, use a control-ping to sync */
5348 vl_api_control_ping_t *mp_ping;
5352 /* Shut off async mode */
5353 vam->async_mode = 0;
5355 MPING (CONTROL_PING, mp_ping);
5358 timeout = vat_time_now (vam) + 1.0;
5359 while (vat_time_now (vam) < timeout)
5360 if (vam->result_ready == 1)
5365 if (vam->retval == -99)
5368 if (vam->async_errors > 0)
5370 errmsg ("%d asynchronous errors", vam->async_errors);
5373 vam->async_errors = 0;
5374 after = vat_time_now (vam);
5376 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5380 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5381 count, after - before, count / (after - before));
5387 /* Wait for a reply... */
5392 /* Return the good/bad news */
5393 return (vam->retval);
5397 api_ip_mroute_add_del (vat_main_t * vam)
5399 unformat_input_t *i = vam->input;
5400 u8 path_set = 0, prefix_set = 0, is_add = 1;
5401 vl_api_ip_mroute_add_del_t *mp;
5402 mfib_entry_flags_t eflags = 0;
5403 vl_api_mfib_path_t path;
5404 vl_api_mprefix_t pfx = { };
5408 /* Parse args required to build the message */
5409 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5411 if (unformat (i, "%U", unformat_vl_api_mprefix, &pfx))
5414 pfx.grp_address_length = htons (pfx.grp_address_length);
5416 else if (unformat (i, "del"))
5418 else if (unformat (i, "add"))
5420 else if (unformat (i, "vrf %d", &vrf_id))
5422 else if (unformat (i, "%U", unformat_mfib_itf_flags, &path.itf_flags))
5423 path.itf_flags = htonl (path.itf_flags);
5424 else if (unformat (i, "%U", unformat_mfib_entry_flags, &eflags))
5426 else if (unformat (i, "via %U", unformat_fib_path, vam, &path.path))
5430 clib_warning ("parse error '%U'", format_unformat_error, i);
5435 if (prefix_set == 0)
5437 errmsg ("missing addresses\n");
5442 errmsg ("missing path\n");
5446 /* Construct the API message */
5447 M (IP_MROUTE_ADD_DEL, mp);
5449 mp->is_add = is_add;
5450 mp->is_multipath = 1;
5452 clib_memcpy (&mp->route.prefix, &pfx, sizeof (pfx));
5453 mp->route.table_id = htonl (vrf_id);
5454 mp->route.n_paths = 1;
5455 mp->route.entry_flags = htonl (eflags);
5457 clib_memcpy (&mp->route.paths, &path, sizeof (path));
5461 /* Wait for a reply... */
5467 api_mpls_table_add_del (vat_main_t * vam)
5469 unformat_input_t *i = vam->input;
5470 vl_api_mpls_table_add_del_t *mp;
5475 /* Parse args required to build the message */
5476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5478 if (unformat (i, "table %d", &table_id))
5480 else if (unformat (i, "del"))
5482 else if (unformat (i, "add"))
5486 clib_warning ("parse error '%U'", format_unformat_error, i);
5493 errmsg ("missing table-ID");
5497 /* Construct the API message */
5498 M (MPLS_TABLE_ADD_DEL, mp);
5500 mp->mt_table.mt_table_id = ntohl (table_id);
5501 mp->mt_is_add = is_add;
5506 /* Wait for a reply... */
5513 api_mpls_route_add_del (vat_main_t * vam)
5515 u8 is_add = 1, path_count = 0, is_multipath = 0, is_eos = 0;
5516 mpls_label_t local_label = MPLS_LABEL_INVALID;
5517 unformat_input_t *i = vam->input;
5518 vl_api_mpls_route_add_del_t *mp;
5519 vl_api_fib_path_t paths[8];
5523 /* Parse args required to build the message */
5524 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5526 if (unformat (i, "%d", &local_label))
5528 else if (unformat (i, "eos"))
5530 else if (unformat (i, "non-eos"))
5532 else if (unformat (i, "del"))
5534 else if (unformat (i, "add"))
5536 else if (unformat (i, "multipath"))
5538 else if (unformat (i, "count %d", &count))
5542 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5545 if (8 == path_count)
5547 errmsg ("max 8 paths");
5553 clib_warning ("parse error '%U'", format_unformat_error, i);
5560 errmsg ("specify a path; via ...");
5564 if (MPLS_LABEL_INVALID == local_label)
5566 errmsg ("missing label");
5572 /* Turn on async mode */
5573 vam->async_mode = 1;
5574 vam->async_errors = 0;
5575 before = vat_time_now (vam);
5578 for (j = 0; j < count; j++)
5580 /* Construct the API message */
5581 M2 (MPLS_ROUTE_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5583 mp->mr_is_add = is_add;
5584 mp->mr_is_multipath = is_multipath;
5586 mp->mr_route.mr_label = local_label;
5587 mp->mr_route.mr_eos = is_eos;
5588 mp->mr_route.mr_table_id = 0;
5589 mp->mr_route.mr_n_paths = path_count;
5591 clib_memcpy (&mp->mr_route.mr_paths, paths,
5592 sizeof (paths[0]) * path_count);
5598 /* If we receive SIGTERM, stop now... */
5603 /* When testing multiple add/del ops, use a control-ping to sync */
5606 vl_api_control_ping_t *mp_ping;
5610 /* Shut off async mode */
5611 vam->async_mode = 0;
5613 MPING (CONTROL_PING, mp_ping);
5616 timeout = vat_time_now (vam) + 1.0;
5617 while (vat_time_now (vam) < timeout)
5618 if (vam->result_ready == 1)
5623 if (vam->retval == -99)
5626 if (vam->async_errors > 0)
5628 errmsg ("%d asynchronous errors", vam->async_errors);
5631 vam->async_errors = 0;
5632 after = vat_time_now (vam);
5634 /* slim chance, but we might have eaten SIGTERM on the first iteration */
5638 print (vam->ofp, "%d routes in %.6f secs, %.2f routes/sec",
5639 count, after - before, count / (after - before));
5645 /* Wait for a reply... */
5650 /* Return the good/bad news */
5651 return (vam->retval);
5656 api_mpls_ip_bind_unbind (vat_main_t * vam)
5658 unformat_input_t *i = vam->input;
5659 vl_api_mpls_ip_bind_unbind_t *mp;
5660 u32 ip_table_id = 0;
5662 vl_api_prefix_t pfx;
5664 mpls_label_t local_label = MPLS_LABEL_INVALID;
5667 /* Parse args required to build the message */
5668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5670 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
5672 else if (unformat (i, "%d", &local_label))
5674 else if (unformat (i, "table-id %d", &ip_table_id))
5676 else if (unformat (i, "unbind"))
5678 else if (unformat (i, "bind"))
5682 clib_warning ("parse error '%U'", format_unformat_error, i);
5689 errmsg ("IP prefix not set");
5693 if (MPLS_LABEL_INVALID == local_label)
5695 errmsg ("missing label");
5699 /* Construct the API message */
5700 M (MPLS_IP_BIND_UNBIND, mp);
5702 mp->mb_is_bind = is_bind;
5703 mp->mb_ip_table_id = ntohl (ip_table_id);
5704 mp->mb_mpls_table_id = 0;
5705 mp->mb_label = ntohl (local_label);
5706 clib_memcpy (&mp->mb_prefix, &pfx, sizeof (pfx));
5711 /* Wait for a reply... */
5718 api_sr_mpls_policy_add (vat_main_t * vam)
5720 unformat_input_t *i = vam->input;
5721 vl_api_sr_mpls_policy_add_t *mp;
5727 u32 *segments = NULL;
5730 /* Parse args required to build the message */
5731 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5733 if (unformat (i, "bsid %d", &bsid))
5735 else if (unformat (i, "weight %d", &weight))
5737 else if (unformat (i, "spray"))
5739 else if (unformat (i, "next %d", &sid))
5742 vec_add1 (segments, htonl (sid));
5746 clib_warning ("parse error '%U'", format_unformat_error, i);
5753 errmsg ("bsid not set");
5757 if (n_segments == 0)
5759 errmsg ("no sid in segment stack");
5763 /* Construct the API message */
5764 M2 (SR_MPLS_POLICY_ADD, mp, sizeof (u32) * n_segments);
5766 mp->bsid = htonl (bsid);
5767 mp->weight = htonl (weight);
5768 mp->is_spray = type;
5769 mp->n_segments = n_segments;
5770 memcpy (mp->segments, segments, sizeof (u32) * n_segments);
5771 vec_free (segments);
5776 /* Wait for a reply... */
5782 api_sr_mpls_policy_del (vat_main_t * vam)
5784 unformat_input_t *i = vam->input;
5785 vl_api_sr_mpls_policy_del_t *mp;
5789 /* Parse args required to build the message */
5790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5792 if (unformat (i, "bsid %d", &bsid))
5796 clib_warning ("parse error '%U'", format_unformat_error, i);
5803 errmsg ("bsid not set");
5807 /* Construct the API message */
5808 M (SR_MPLS_POLICY_DEL, mp);
5810 mp->bsid = htonl (bsid);
5815 /* Wait for a reply... */
5821 api_mpls_tunnel_add_del (vat_main_t * vam)
5823 unformat_input_t *i = vam->input;
5824 vl_api_mpls_tunnel_add_del_t *mp;
5826 vl_api_fib_path_t paths[8];
5827 u32 sw_if_index = ~0;
5833 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5835 if (unformat (i, "add"))
5839 (i, "del %U", api_unformat_sw_if_index, vam, &sw_if_index))
5841 else if (unformat (i, "del sw_if_index %d", &sw_if_index))
5843 else if (unformat (i, "l2-only"))
5847 (i, "via %U", unformat_fib_path, vam, &paths[path_count]))
5850 if (8 == path_count)
5852 errmsg ("max 8 paths");
5858 clib_warning ("parse error '%U'", format_unformat_error, i);
5863 M2 (MPLS_TUNNEL_ADD_DEL, mp, sizeof (vl_api_fib_path_t) * path_count);
5865 mp->mt_is_add = is_add;
5866 mp->mt_tunnel.mt_sw_if_index = ntohl (sw_if_index);
5867 mp->mt_tunnel.mt_l2_only = l2_only;
5868 mp->mt_tunnel.mt_is_multicast = 0;
5869 mp->mt_tunnel.mt_n_paths = path_count;
5871 clib_memcpy (&mp->mt_tunnel.mt_paths, &paths,
5872 sizeof (paths[0]) * path_count);
5880 api_sw_interface_set_unnumbered (vat_main_t * vam)
5882 unformat_input_t *i = vam->input;
5883 vl_api_sw_interface_set_unnumbered_t *mp;
5885 u32 unnum_sw_index = ~0;
5887 u8 sw_if_index_set = 0;
5890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5892 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5893 sw_if_index_set = 1;
5894 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5895 sw_if_index_set = 1;
5896 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5898 else if (unformat (i, "del"))
5902 clib_warning ("parse error '%U'", format_unformat_error, i);
5907 if (sw_if_index_set == 0)
5909 errmsg ("missing interface name or sw_if_index");
5913 M (SW_INTERFACE_SET_UNNUMBERED, mp);
5915 mp->sw_if_index = ntohl (sw_if_index);
5916 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
5917 mp->is_add = is_add;
5926 api_create_vlan_subif (vat_main_t * vam)
5928 unformat_input_t *i = vam->input;
5929 vl_api_create_vlan_subif_t *mp;
5931 u8 sw_if_index_set = 0;
5936 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5938 if (unformat (i, "sw_if_index %d", &sw_if_index))
5939 sw_if_index_set = 1;
5941 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
5942 sw_if_index_set = 1;
5943 else if (unformat (i, "vlan %d", &vlan_id))
5947 clib_warning ("parse error '%U'", format_unformat_error, i);
5952 if (sw_if_index_set == 0)
5954 errmsg ("missing interface name or sw_if_index");
5958 if (vlan_id_set == 0)
5960 errmsg ("missing vlan_id");
5963 M (CREATE_VLAN_SUBIF, mp);
5965 mp->sw_if_index = ntohl (sw_if_index);
5966 mp->vlan_id = ntohl (vlan_id);
5973 #define foreach_create_subif_bit \
5980 _(outer_vlan_id_any) \
5981 _(inner_vlan_id_any)
5983 #define foreach_create_subif_flag \
5988 _(4, "exact_match") \
5989 _(5, "default_sub") \
5990 _(6, "outer_vlan_id_any") \
5991 _(7, "inner_vlan_id_any")
5994 api_create_subif (vat_main_t * vam)
5996 unformat_input_t *i = vam->input;
5997 vl_api_create_subif_t *mp;
5999 u8 sw_if_index_set = 0;
6002 u32 __attribute__ ((unused)) no_tags = 0;
6003 u32 __attribute__ ((unused)) one_tag = 0;
6004 u32 __attribute__ ((unused)) two_tags = 0;
6005 u32 __attribute__ ((unused)) dot1ad = 0;
6006 u32 __attribute__ ((unused)) exact_match = 0;
6007 u32 __attribute__ ((unused)) default_sub = 0;
6008 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
6009 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
6011 u16 outer_vlan_id = 0;
6012 u16 inner_vlan_id = 0;
6015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6017 if (unformat (i, "sw_if_index %d", &sw_if_index))
6018 sw_if_index_set = 1;
6020 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6021 sw_if_index_set = 1;
6022 else if (unformat (i, "sub_id %d", &sub_id))
6024 else if (unformat (i, "outer_vlan_id %d", &tmp))
6025 outer_vlan_id = tmp;
6026 else if (unformat (i, "inner_vlan_id %d", &tmp))
6027 inner_vlan_id = tmp;
6029 #define _(a) else if (unformat (i, #a)) a = 1 ;
6030 foreach_create_subif_bit
6034 clib_warning ("parse error '%U'", format_unformat_error, i);
6039 if (sw_if_index_set == 0)
6041 errmsg ("missing interface name or sw_if_index");
6045 if (sub_id_set == 0)
6047 errmsg ("missing sub_id");
6050 M (CREATE_SUBIF, mp);
6052 mp->sw_if_index = ntohl (sw_if_index);
6053 mp->sub_id = ntohl (sub_id);
6055 #define _(a,b) mp->sub_if_flags |= (1 << a);
6056 foreach_create_subif_flag;
6059 mp->outer_vlan_id = ntohs (outer_vlan_id);
6060 mp->inner_vlan_id = ntohs (inner_vlan_id);
6068 api_ip_table_replace_begin (vat_main_t * vam)
6070 unformat_input_t *i = vam->input;
6071 vl_api_ip_table_replace_begin_t *mp;
6076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6078 if (unformat (i, "table %d", &table_id))
6080 else if (unformat (i, "ipv6"))
6084 clib_warning ("parse error '%U'", format_unformat_error, i);
6089 M (IP_TABLE_REPLACE_BEGIN, mp);
6091 mp->table.table_id = ntohl (table_id);
6092 mp->table.is_ip6 = is_ipv6;
6100 api_ip_table_flush (vat_main_t * vam)
6102 unformat_input_t *i = vam->input;
6103 vl_api_ip_table_flush_t *mp;
6108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6110 if (unformat (i, "table %d", &table_id))
6112 else if (unformat (i, "ipv6"))
6116 clib_warning ("parse error '%U'", format_unformat_error, i);
6121 M (IP_TABLE_FLUSH, mp);
6123 mp->table.table_id = ntohl (table_id);
6124 mp->table.is_ip6 = is_ipv6;
6132 api_ip_table_replace_end (vat_main_t * vam)
6134 unformat_input_t *i = vam->input;
6135 vl_api_ip_table_replace_end_t *mp;
6140 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6142 if (unformat (i, "table %d", &table_id))
6144 else if (unformat (i, "ipv6"))
6148 clib_warning ("parse error '%U'", format_unformat_error, i);
6153 M (IP_TABLE_REPLACE_END, mp);
6155 mp->table.table_id = ntohl (table_id);
6156 mp->table.is_ip6 = is_ipv6;
6164 api_set_ip_flow_hash (vat_main_t * vam)
6166 unformat_input_t *i = vam->input;
6167 vl_api_set_ip_flow_hash_t *mp;
6179 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6181 if (unformat (i, "vrf %d", &vrf_id))
6183 else if (unformat (i, "ipv6"))
6185 else if (unformat (i, "src"))
6187 else if (unformat (i, "dst"))
6189 else if (unformat (i, "sport"))
6191 else if (unformat (i, "dport"))
6193 else if (unformat (i, "proto"))
6195 else if (unformat (i, "reverse"))
6200 clib_warning ("parse error '%U'", format_unformat_error, i);
6205 if (vrf_id_set == 0)
6207 errmsg ("missing vrf id");
6211 M (SET_IP_FLOW_HASH, mp);
6217 mp->reverse = reverse;
6218 mp->vrf_id = ntohl (vrf_id);
6219 mp->is_ipv6 = is_ipv6;
6227 api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6229 unformat_input_t *i = vam->input;
6230 vl_api_sw_interface_ip6_enable_disable_t *mp;
6232 u8 sw_if_index_set = 0;
6236 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6238 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
6239 sw_if_index_set = 1;
6240 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6241 sw_if_index_set = 1;
6242 else if (unformat (i, "enable"))
6244 else if (unformat (i, "disable"))
6248 clib_warning ("parse error '%U'", format_unformat_error, i);
6253 if (sw_if_index_set == 0)
6255 errmsg ("missing interface name or sw_if_index");
6259 M (SW_INTERFACE_IP6_ENABLE_DISABLE, mp);
6261 mp->sw_if_index = ntohl (sw_if_index);
6262 mp->enable = enable;
6271 api_l2_patch_add_del (vat_main_t * vam)
6273 unformat_input_t *i = vam->input;
6274 vl_api_l2_patch_add_del_t *mp;
6276 u8 rx_sw_if_index_set = 0;
6278 u8 tx_sw_if_index_set = 0;
6282 /* Parse args required to build the message */
6283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6285 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6286 rx_sw_if_index_set = 1;
6287 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6288 tx_sw_if_index_set = 1;
6289 else if (unformat (i, "rx"))
6291 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6293 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6295 rx_sw_if_index_set = 1;
6300 else if (unformat (i, "tx"))
6302 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6304 if (unformat (i, "%U", api_unformat_sw_if_index, vam,
6306 tx_sw_if_index_set = 1;
6311 else if (unformat (i, "del"))
6317 if (rx_sw_if_index_set == 0)
6319 errmsg ("missing rx interface name or rx_sw_if_index");
6323 if (tx_sw_if_index_set == 0)
6325 errmsg ("missing tx interface name or tx_sw_if_index");
6329 M (L2_PATCH_ADD_DEL, mp);
6331 mp->rx_sw_if_index = ntohl (rx_sw_if_index);
6332 mp->tx_sw_if_index = ntohl (tx_sw_if_index);
6333 mp->is_add = is_add;
6341 u8 localsid_addr[16];
6350 api_sr_localsid_add_del (vat_main_t * vam)
6352 unformat_input_t *i = vam->input;
6353 vl_api_sr_localsid_add_del_t *mp;
6356 ip6_address_t localsid;
6360 u32 fib_table = ~(u32) 0;
6361 ip46_address_t nh_addr;
6362 clib_memset (&nh_addr, 0, sizeof (ip46_address_t));
6364 bool nexthop_set = 0;
6368 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6370 if (unformat (i, "del"))
6372 else if (unformat (i, "address %U", unformat_ip6_address, &localsid));
6373 else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr))
6375 else if (unformat (i, "behavior %u", &behavior));
6376 else if (unformat (i, "sw_if_index %u", &sw_if_index));
6377 else if (unformat (i, "fib-table %u", &fib_table));
6378 else if (unformat (i, "end.psp %u", &behavior));
6383 M (SR_LOCALSID_ADD_DEL, mp);
6385 clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid));
6389 clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un));
6391 mp->behavior = behavior;
6392 mp->sw_if_index = ntohl (sw_if_index);
6393 mp->fib_table = ntohl (fib_table);
6394 mp->end_psp = end_psp;
6395 mp->is_del = is_del;
6403 api_ioam_enable (vat_main_t * vam)
6405 unformat_input_t *input = vam->input;
6406 vl_api_ioam_enable_t *mp;
6408 int has_trace_option = 0;
6409 int has_pot_option = 0;
6410 int has_seqno_option = 0;
6411 int has_analyse_option = 0;
6414 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6416 if (unformat (input, "trace"))
6417 has_trace_option = 1;
6418 else if (unformat (input, "pot"))
6420 else if (unformat (input, "seqno"))
6421 has_seqno_option = 1;
6422 else if (unformat (input, "analyse"))
6423 has_analyse_option = 1;
6427 M (IOAM_ENABLE, mp);
6428 mp->id = htons (id);
6429 mp->seqno = has_seqno_option;
6430 mp->analyse = has_analyse_option;
6431 mp->pot_enable = has_pot_option;
6432 mp->trace_enable = has_trace_option;
6441 api_ioam_disable (vat_main_t * vam)
6443 vl_api_ioam_disable_t *mp;
6446 M (IOAM_DISABLE, mp);
6452 #define foreach_tcp_proto_field \
6456 #define foreach_udp_proto_field \
6460 #define foreach_ip4_proto_field \
6472 u16 src_port, dst_port;
6475 #if VPP_API_TEST_BUILTIN == 0
6477 unformat_tcp_mask (unformat_input_t * input, va_list * args)
6479 u8 **maskp = va_arg (*args, u8 **);
6481 u8 found_something = 0;
6484 #define _(a) u8 a=0;
6485 foreach_tcp_proto_field;
6488 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6491 #define _(a) else if (unformat (input, #a)) a=1;
6492 foreach_tcp_proto_field
6498 #define _(a) found_something += a;
6499 foreach_tcp_proto_field;
6502 if (found_something == 0)
6505 vec_validate (mask, sizeof (*tcp) - 1);
6507 tcp = (tcp_header_t *) mask;
6509 #define _(a) if (a) clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
6510 foreach_tcp_proto_field;
6518 unformat_udp_mask (unformat_input_t * input, va_list * args)
6520 u8 **maskp = va_arg (*args, u8 **);
6522 u8 found_something = 0;
6525 #define _(a) u8 a=0;
6526 foreach_udp_proto_field;
6529 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6532 #define _(a) else if (unformat (input, #a)) a=1;
6533 foreach_udp_proto_field
6539 #define _(a) found_something += a;
6540 foreach_udp_proto_field;
6543 if (found_something == 0)
6546 vec_validate (mask, sizeof (*udp) - 1);
6548 udp = (udp_header_t *) mask;
6550 #define _(a) if (a) clib_memset (&udp->a, 0xff, sizeof (udp->a));
6551 foreach_udp_proto_field;
6559 unformat_l4_mask (unformat_input_t * input, va_list * args)
6561 u8 **maskp = va_arg (*args, u8 **);
6562 u16 src_port = 0, dst_port = 0;
6563 tcpudp_header_t *tcpudp;
6565 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6567 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
6569 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
6571 else if (unformat (input, "src_port"))
6573 else if (unformat (input, "dst_port"))
6579 if (!src_port && !dst_port)
6583 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
6585 tcpudp = (tcpudp_header_t *) mask;
6586 tcpudp->src_port = src_port;
6587 tcpudp->dst_port = dst_port;
6595 unformat_ip4_mask (unformat_input_t * input, va_list * args)
6597 u8 **maskp = va_arg (*args, u8 **);
6599 u8 found_something = 0;
6602 #define _(a) u8 a=0;
6603 foreach_ip4_proto_field;
6609 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6611 if (unformat (input, "version"))
6613 else if (unformat (input, "hdr_length"))
6615 else if (unformat (input, "src"))
6617 else if (unformat (input, "dst"))
6619 else if (unformat (input, "proto"))
6622 #define _(a) else if (unformat (input, #a)) a=1;
6623 foreach_ip4_proto_field
6629 #define _(a) found_something += a;
6630 foreach_ip4_proto_field;
6633 if (found_something == 0)
6636 vec_validate (mask, sizeof (*ip) - 1);
6638 ip = (ip4_header_t *) mask;
6640 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
6641 foreach_ip4_proto_field;
6644 ip->ip_version_and_header_length = 0;
6647 ip->ip_version_and_header_length |= 0xF0;
6650 ip->ip_version_and_header_length |= 0x0F;
6656 #define foreach_ip6_proto_field \
6664 unformat_ip6_mask (unformat_input_t * input, va_list * args)
6666 u8 **maskp = va_arg (*args, u8 **);
6668 u8 found_something = 0;
6670 u32 ip_version_traffic_class_and_flow_label;
6672 #define _(a) u8 a=0;
6673 foreach_ip6_proto_field;
6676 u8 traffic_class = 0;
6679 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6681 if (unformat (input, "version"))
6683 else if (unformat (input, "traffic-class"))
6685 else if (unformat (input, "flow-label"))
6687 else if (unformat (input, "src"))
6689 else if (unformat (input, "dst"))
6691 else if (unformat (input, "proto"))
6694 #define _(a) else if (unformat (input, #a)) a=1;
6695 foreach_ip6_proto_field
6701 #define _(a) found_something += a;
6702 foreach_ip6_proto_field;
6705 if (found_something == 0)
6708 vec_validate (mask, sizeof (*ip) - 1);
6710 ip = (ip6_header_t *) mask;
6712 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
6713 foreach_ip6_proto_field;
6716 ip_version_traffic_class_and_flow_label = 0;
6719 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6722 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6725 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6727 ip->ip_version_traffic_class_and_flow_label =
6728 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6735 unformat_l3_mask (unformat_input_t * input, va_list * args)
6737 u8 **maskp = va_arg (*args, u8 **);
6739 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6741 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6743 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6752 unformat_l2_mask (unformat_input_t * input, va_list * args)
6754 u8 **maskp = va_arg (*args, u8 **);
6769 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6771 if (unformat (input, "src"))
6773 else if (unformat (input, "dst"))
6775 else if (unformat (input, "proto"))
6777 else if (unformat (input, "tag1"))
6779 else if (unformat (input, "tag2"))
6781 else if (unformat (input, "ignore-tag1"))
6783 else if (unformat (input, "ignore-tag2"))
6785 else if (unformat (input, "cos1"))
6787 else if (unformat (input, "cos2"))
6789 else if (unformat (input, "dot1q"))
6791 else if (unformat (input, "dot1ad"))
6796 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6797 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6800 if (tag1 || ignore_tag1 || cos1 || dot1q)
6802 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6805 vec_validate (mask, len - 1);
6808 clib_memset (mask, 0xff, 6);
6811 clib_memset (mask + 6, 0xff, 6);
6815 /* inner vlan tag */
6824 mask[21] = mask[20] = 0xff;
6845 mask[16] = mask[17] = 0xff;
6855 mask[12] = mask[13] = 0xff;
6862 unformat_classify_mask (unformat_input_t * input, va_list * args)
6864 u8 **maskp = va_arg (*args, u8 **);
6865 u32 *skipp = va_arg (*args, u32 *);
6866 u32 *matchp = va_arg (*args, u32 *);
6874 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6876 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6878 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6880 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6882 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
6896 if (mask || l2 || l3 || l4)
6900 /* "With a free Ethernet header in every package" */
6902 vec_validate (l2, 13);
6906 vec_append (mask, l3);
6911 vec_append (mask, l4);
6916 /* Scan forward looking for the first significant mask octet */
6917 for (i = 0; i < vec_len (mask); i++)
6921 /* compute (skip, match) params */
6922 *skipp = i / sizeof (u32x4);
6923 vec_delete (mask, *skipp * sizeof (u32x4), 0);
6925 /* Pad mask to an even multiple of the vector size */
6926 while (vec_len (mask) % sizeof (u32x4))
6929 match = vec_len (mask) / sizeof (u32x4);
6931 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
6933 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
6934 if (*tmp || *(tmp + 1))
6939 clib_warning ("BUG: match 0");
6941 _vec_len (mask) = match * sizeof (u32x4);
6951 #endif /* VPP_API_TEST_BUILTIN */
6953 #define foreach_l2_next \
6955 _(ethernet, ETHERNET_INPUT) \
6960 unformat_l2_next_index (unformat_input_t * input, va_list * args)
6962 u32 *miss_next_indexp = va_arg (*args, u32 *);
6967 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
6971 if (unformat (input, "%d", &tmp))
6980 *miss_next_indexp = next_index;
6984 #define foreach_ip_next \
6990 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
6992 u32 *miss_next_indexp = va_arg (*args, u32 *);
6997 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7001 if (unformat (input, "%d", &tmp))
7010 *miss_next_indexp = next_index;
7014 #define foreach_acl_next \
7018 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
7020 u32 *miss_next_indexp = va_arg (*args, u32 *);
7025 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7029 if (unformat (input, "permit"))
7034 else if (unformat (input, "%d", &tmp))
7043 *miss_next_indexp = next_index;
7048 unformat_policer_precolor (unformat_input_t * input, va_list * args)
7050 u32 *r = va_arg (*args, u32 *);
7052 if (unformat (input, "conform-color"))
7053 *r = POLICE_CONFORM;
7054 else if (unformat (input, "exceed-color"))
7062 #if VPP_API_TEST_BUILTIN == 0
7064 unformat_l4_match (unformat_input_t * input, va_list * args)
7066 u8 **matchp = va_arg (*args, u8 **);
7068 u8 *proto_header = 0;
7074 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7076 if (unformat (input, "src_port %d", &src_port))
7078 else if (unformat (input, "dst_port %d", &dst_port))
7084 h.src_port = clib_host_to_net_u16 (src_port);
7085 h.dst_port = clib_host_to_net_u16 (dst_port);
7086 vec_validate (proto_header, sizeof (h) - 1);
7087 memcpy (proto_header, &h, sizeof (h));
7089 *matchp = proto_header;
7095 unformat_ip4_match (unformat_input_t * input, va_list * args)
7097 u8 **matchp = va_arg (*args, u8 **);
7104 int src = 0, dst = 0;
7105 ip4_address_t src_val, dst_val;
7112 int fragment_id = 0;
7113 u32 fragment_id_val;
7119 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7121 if (unformat (input, "version %d", &version_val))
7123 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7125 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7127 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7129 else if (unformat (input, "proto %d", &proto_val))
7131 else if (unformat (input, "tos %d", &tos_val))
7133 else if (unformat (input, "length %d", &length_val))
7135 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7137 else if (unformat (input, "ttl %d", &ttl_val))
7139 else if (unformat (input, "checksum %d", &checksum_val))
7145 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7146 + ttl + checksum == 0)
7150 * Aligned because we use the real comparison functions
7152 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7154 ip = (ip4_header_t *) match;
7156 /* These are realistically matched in practice */
7158 ip->src_address.as_u32 = src_val.as_u32;
7161 ip->dst_address.as_u32 = dst_val.as_u32;
7164 ip->protocol = proto_val;
7167 /* These are not, but they're included for completeness */
7169 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
7172 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7178 ip->length = clib_host_to_net_u16 (length_val);
7184 ip->checksum = clib_host_to_net_u16 (checksum_val);
7191 unformat_ip6_match (unformat_input_t * input, va_list * args)
7193 u8 **matchp = va_arg (*args, u8 **);
7198 u8 traffic_class = 0;
7199 u32 traffic_class_val = 0;
7202 int src = 0, dst = 0;
7203 ip6_address_t src_val, dst_val;
7206 int payload_length = 0;
7207 u32 payload_length_val;
7210 u32 ip_version_traffic_class_and_flow_label;
7212 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7214 if (unformat (input, "version %d", &version_val))
7216 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7218 else if (unformat (input, "flow_label %d", &flow_label_val))
7220 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7222 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7224 else if (unformat (input, "proto %d", &proto_val))
7226 else if (unformat (input, "payload_length %d", &payload_length_val))
7228 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7234 if (version + traffic_class + flow_label + src + dst + proto +
7235 payload_length + hop_limit == 0)
7239 * Aligned because we use the real comparison functions
7241 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
7243 ip = (ip6_header_t *) match;
7246 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7249 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7252 ip->protocol = proto_val;
7254 ip_version_traffic_class_and_flow_label = 0;
7257 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7260 ip_version_traffic_class_and_flow_label |=
7261 (traffic_class_val & 0xFF) << 20;
7264 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7266 ip->ip_version_traffic_class_and_flow_label =
7267 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7270 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7273 ip->hop_limit = hop_limit_val;
7280 unformat_l3_match (unformat_input_t * input, va_list * args)
7282 u8 **matchp = va_arg (*args, u8 **);
7284 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7286 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7288 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7297 unformat_vlan_tag (unformat_input_t * input, va_list * args)
7299 u8 *tagp = va_arg (*args, u8 *);
7302 if (unformat (input, "%d", &tag))
7304 tagp[0] = (tag >> 8) & 0x0F;
7305 tagp[1] = tag & 0xFF;
7313 unformat_l2_match (unformat_input_t * input, va_list * args)
7315 u8 **matchp = va_arg (*args, u8 **);
7335 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7337 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7340 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7342 else if (unformat (input, "proto %U",
7343 unformat_ethernet_type_host_byte_order, &proto_val))
7345 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7347 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7349 else if (unformat (input, "ignore-tag1"))
7351 else if (unformat (input, "ignore-tag2"))
7353 else if (unformat (input, "cos1 %d", &cos1_val))
7355 else if (unformat (input, "cos2 %d", &cos2_val))
7360 if ((src + dst + proto + tag1 + tag2 +
7361 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7364 if (tag1 || ignore_tag1 || cos1)
7366 if (tag2 || ignore_tag2 || cos2)
7369 vec_validate_aligned (match, len - 1, sizeof (u32x4));
7372 clib_memcpy (match, dst_val, 6);
7375 clib_memcpy (match + 6, src_val, 6);
7379 /* inner vlan tag */
7380 match[19] = tag2_val[1];
7381 match[18] = tag2_val[0];
7383 match[18] |= (cos2_val & 0x7) << 5;
7386 match[21] = proto_val & 0xff;
7387 match[20] = proto_val >> 8;
7391 match[15] = tag1_val[1];
7392 match[14] = tag1_val[0];
7395 match[14] |= (cos1_val & 0x7) << 5;
7401 match[15] = tag1_val[1];
7402 match[14] = tag1_val[0];
7405 match[17] = proto_val & 0xff;
7406 match[16] = proto_val >> 8;
7409 match[14] |= (cos1_val & 0x7) << 5;
7415 match[18] |= (cos2_val & 0x7) << 5;
7417 match[14] |= (cos1_val & 0x7) << 5;
7420 match[13] = proto_val & 0xff;
7421 match[12] = proto_val >> 8;
7429 unformat_qos_source (unformat_input_t * input, va_list * args)
7431 int *qs = va_arg (*args, int *);
7433 if (unformat (input, "ip"))
7434 *qs = QOS_SOURCE_IP;
7435 else if (unformat (input, "mpls"))
7436 *qs = QOS_SOURCE_MPLS;
7437 else if (unformat (input, "ext"))
7438 *qs = QOS_SOURCE_EXT;
7439 else if (unformat (input, "vlan"))
7440 *qs = QOS_SOURCE_VLAN;
7449 api_unformat_classify_match (unformat_input_t * input, va_list * args)
7451 u8 **matchp = va_arg (*args, u8 **);
7452 u32 skip_n_vectors = va_arg (*args, u32);
7453 u32 match_n_vectors = va_arg (*args, u32);
7460 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7462 if (unformat (input, "hex %U", unformat_hex_string, &match))
7464 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7466 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7468 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
7482 if (match || l2 || l3 || l4)
7486 /* "Win a free Ethernet header in every packet" */
7488 vec_validate_aligned (l2, 13, sizeof (u32x4));
7492 vec_append_aligned (match, l3, sizeof (u32x4));
7497 vec_append_aligned (match, l4, sizeof (u32x4));
7502 /* Make sure the vector is big enough even if key is all 0's */
7503 vec_validate_aligned
7504 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
7507 /* Set size, include skipped vectors */
7508 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
7519 api_get_node_index (vat_main_t * vam)
7521 unformat_input_t *i = vam->input;
7522 vl_api_get_node_index_t *mp;
7526 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7528 if (unformat (i, "node %s", &name))
7535 errmsg ("node name required");
7538 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7540 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7544 M (GET_NODE_INDEX, mp);
7545 clib_memcpy (mp->node_name, name, vec_len (name));
7554 api_get_next_index (vat_main_t * vam)
7556 unformat_input_t *i = vam->input;
7557 vl_api_get_next_index_t *mp;
7558 u8 *node_name = 0, *next_node_name = 0;
7561 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7563 if (unformat (i, "node-name %s", &node_name))
7565 else if (unformat (i, "next-node-name %s", &next_node_name))
7571 errmsg ("node name required");
7574 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
7576 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7580 if (next_node_name == 0)
7582 errmsg ("next node name required");
7585 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
7587 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
7591 M (GET_NEXT_INDEX, mp);
7592 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
7593 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
7594 vec_free (node_name);
7595 vec_free (next_node_name);
7603 api_add_node_next (vat_main_t * vam)
7605 unformat_input_t *i = vam->input;
7606 vl_api_add_node_next_t *mp;
7611 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7613 if (unformat (i, "node %s", &name))
7615 else if (unformat (i, "next %s", &next))
7622 errmsg ("node name required");
7625 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
7627 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
7632 errmsg ("next node required");
7635 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
7637 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
7641 M (ADD_NODE_NEXT, mp);
7642 clib_memcpy (mp->node_name, name, vec_len (name));
7643 clib_memcpy (mp->next_name, next, vec_len (next));
7652 static void vl_api_sw_interface_tap_v2_details_t_handler
7653 (vl_api_sw_interface_tap_v2_details_t * mp)
7655 vat_main_t *vam = &vat_main;
7658 format (0, "%U/%d", format_ip4_address, mp->host_ip4_prefix.address,
7659 mp->host_ip4_prefix.len);
7661 format (0, "%U/%d", format_ip6_address, mp->host_ip6_prefix.address,
7662 mp->host_ip6_prefix.len);
7665 "\n%-16s %-12d %-5d %-12d %-12d %-14U %-30s %-20s %-20s %-30s 0x%-08x",
7666 mp->dev_name, ntohl (mp->sw_if_index), ntohl (mp->id),
7667 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
7668 format_ethernet_address, mp->host_mac_addr, mp->host_namespace,
7669 mp->host_bridge, ip4, ip6, ntohl (mp->tap_flags));
7675 static void vl_api_sw_interface_tap_v2_details_t_handler_json
7676 (vl_api_sw_interface_tap_v2_details_t * mp)
7678 vat_main_t *vam = &vat_main;
7679 vat_json_node_t *node = NULL;
7681 if (VAT_JSON_ARRAY != vam->json_tree.type)
7683 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7684 vat_json_init_array (&vam->json_tree);
7686 node = vat_json_array_add (&vam->json_tree);
7688 vat_json_init_object (node);
7689 vat_json_object_add_uint (node, "id", ntohl (mp->id));
7690 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7691 vat_json_object_add_uint (node, "tap_flags", ntohl (mp->tap_flags));
7692 vat_json_object_add_string_copy (node, "dev_name", mp->dev_name);
7693 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
7694 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
7695 vat_json_object_add_string_copy (node, "host_mac_addr",
7696 format (0, "%U", format_ethernet_address,
7697 &mp->host_mac_addr));
7698 vat_json_object_add_string_copy (node, "host_namespace",
7699 mp->host_namespace);
7700 vat_json_object_add_string_copy (node, "host_bridge", mp->host_bridge);
7701 vat_json_object_add_string_copy (node, "host_ip4_addr",
7702 format (0, "%U/%d", format_ip4_address,
7703 mp->host_ip4_prefix.address,
7704 mp->host_ip4_prefix.len));
7705 vat_json_object_add_string_copy (node, "host_ip6_prefix",
7706 format (0, "%U/%d", format_ip6_address,
7707 mp->host_ip6_prefix.address,
7708 mp->host_ip6_prefix.len));
7713 api_sw_interface_tap_v2_dump (vat_main_t * vam)
7715 vl_api_sw_interface_tap_v2_dump_t *mp;
7716 vl_api_control_ping_t *mp_ping;
7720 "\n%-16s %-12s %-5s %-12s %-12s %-14s %-30s %-20s %-20s %-30s",
7721 "dev_name", "sw_if_index", "id", "rx_ring_sz", "tx_ring_sz",
7722 "host_mac_addr", "host_namespace", "host_bridge", "host_ip4_addr",
7725 /* Get list of tap interfaces */
7726 M (SW_INTERFACE_TAP_V2_DUMP, mp);
7729 /* Use a control ping for synchronization */
7730 MPING (CONTROL_PING, mp_ping);
7737 static void vl_api_sw_interface_virtio_pci_details_t_handler
7738 (vl_api_sw_interface_virtio_pci_details_t * mp)
7740 vat_main_t *vam = &vat_main;
7755 addr.domain = ntohs (mp->pci_addr.domain);
7756 addr.bus = mp->pci_addr.bus;
7757 addr.slot = mp->pci_addr.slot;
7758 addr.function = mp->pci_addr.function;
7760 u8 *pci_addr = format (0, "%04x:%02x:%02x.%x", addr.domain, addr.bus,
7761 addr.slot, addr.function);
7764 "\n%-12s %-12d %-12d %-12d %-17U 0x%-08llx",
7765 pci_addr, ntohl (mp->sw_if_index),
7766 ntohs (mp->rx_ring_sz), ntohs (mp->tx_ring_sz),
7767 format_ethernet_address, mp->mac_addr,
7768 clib_net_to_host_u64 (mp->features));
7769 vec_free (pci_addr);
7772 static void vl_api_sw_interface_virtio_pci_details_t_handler_json
7773 (vl_api_sw_interface_virtio_pci_details_t * mp)
7775 vat_main_t *vam = &vat_main;
7776 vat_json_node_t *node = NULL;
7777 vlib_pci_addr_t pci_addr;
7779 if (VAT_JSON_ARRAY != vam->json_tree.type)
7781 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
7782 vat_json_init_array (&vam->json_tree);
7784 node = vat_json_array_add (&vam->json_tree);
7786 pci_addr.domain = ntohs (mp->pci_addr.domain);
7787 pci_addr.bus = mp->pci_addr.bus;
7788 pci_addr.slot = mp->pci_addr.slot;
7789 pci_addr.function = mp->pci_addr.function;
7791 vat_json_init_object (node);
7792 vat_json_object_add_uint (node, "pci-addr", pci_addr.as_u32);
7793 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
7794 vat_json_object_add_uint (node, "rx_ring_sz", ntohs (mp->rx_ring_sz));
7795 vat_json_object_add_uint (node, "tx_ring_sz", ntohs (mp->tx_ring_sz));
7796 vat_json_object_add_uint (node, "features",
7797 clib_net_to_host_u64 (mp->features));
7798 vat_json_object_add_string_copy (node, "mac_addr",
7799 format (0, "%U", format_ethernet_address,
7804 api_sw_interface_virtio_pci_dump (vat_main_t * vam)
7806 vl_api_sw_interface_virtio_pci_dump_t *mp;
7807 vl_api_control_ping_t *mp_ping;
7811 "\n%-12s %-12s %-12s %-12s %-17s %-08s",
7812 "pci_addr", "sw_if_index", "rx_ring_sz", "tx_ring_sz",
7813 "mac_addr", "features");
7815 /* Get list of tap interfaces */
7816 M (SW_INTERFACE_VIRTIO_PCI_DUMP, mp);
7819 /* Use a control ping for synchronization */
7820 MPING (CONTROL_PING, mp_ping);
7828 api_l2_fib_clear_table (vat_main_t * vam)
7830 // unformat_input_t * i = vam->input;
7831 vl_api_l2_fib_clear_table_t *mp;
7834 M (L2_FIB_CLEAR_TABLE, mp);
7842 api_l2_interface_efp_filter (vat_main_t * vam)
7844 unformat_input_t *i = vam->input;
7845 vl_api_l2_interface_efp_filter_t *mp;
7848 u8 sw_if_index_set = 0;
7851 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7853 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7854 sw_if_index_set = 1;
7855 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7856 sw_if_index_set = 1;
7857 else if (unformat (i, "enable"))
7859 else if (unformat (i, "disable"))
7863 clib_warning ("parse error '%U'", format_unformat_error, i);
7868 if (sw_if_index_set == 0)
7870 errmsg ("missing sw_if_index");
7874 M (L2_INTERFACE_EFP_FILTER, mp);
7876 mp->sw_if_index = ntohl (sw_if_index);
7877 mp->enable_disable = enable;
7884 #define foreach_vtr_op \
7885 _("disable", L2_VTR_DISABLED) \
7886 _("push-1", L2_VTR_PUSH_1) \
7887 _("push-2", L2_VTR_PUSH_2) \
7888 _("pop-1", L2_VTR_POP_1) \
7889 _("pop-2", L2_VTR_POP_2) \
7890 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7891 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7892 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7893 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7896 api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7898 unformat_input_t *i = vam->input;
7899 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7901 u8 sw_if_index_set = 0;
7909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7911 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
7912 sw_if_index_set = 1;
7913 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7914 sw_if_index_set = 1;
7915 else if (unformat (i, "vtr_op %d", &vtr_op))
7917 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7920 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7922 else if (unformat (i, "tag1 %d", &tag1))
7924 else if (unformat (i, "tag2 %d", &tag2))
7928 clib_warning ("parse error '%U'", format_unformat_error, i);
7933 if ((sw_if_index_set == 0) || (vtr_op_set == 0))
7935 errmsg ("missing vtr operation or sw_if_index");
7939 M (L2_INTERFACE_VLAN_TAG_REWRITE, mp);
7940 mp->sw_if_index = ntohl (sw_if_index);
7941 mp->vtr_op = ntohl (vtr_op);
7942 mp->push_dot1q = ntohl (push_dot1q);
7943 mp->tag1 = ntohl (tag1);
7944 mp->tag2 = ntohl (tag2);
7952 api_create_vhost_user_if (vat_main_t * vam)
7954 unformat_input_t *i = vam->input;
7955 vl_api_create_vhost_user_if_t *mp;
7958 u8 file_name_set = 0;
7959 u32 custom_dev_instance = ~0;
7961 u8 use_custom_mac = 0;
7962 u8 disable_mrg_rxbuf = 0;
7963 u8 disable_indirect_desc = 0;
7966 u8 enable_packed = 0;
7969 /* Shut up coverity */
7970 clib_memset (hwaddr, 0, sizeof (hwaddr));
7972 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
7974 if (unformat (i, "socket %s", &file_name))
7978 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
7980 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7982 else if (unformat (i, "server"))
7984 else if (unformat (i, "disable_mrg_rxbuf"))
7985 disable_mrg_rxbuf = 1;
7986 else if (unformat (i, "disable_indirect_desc"))
7987 disable_indirect_desc = 1;
7988 else if (unformat (i, "gso"))
7990 else if (unformat (i, "packed"))
7992 else if (unformat (i, "tag %s", &tag))
7998 if (file_name_set == 0)
8000 errmsg ("missing socket file name");
8004 if (vec_len (file_name) > 255)
8006 errmsg ("socket file name too long");
8009 vec_add1 (file_name, 0);
8011 M (CREATE_VHOST_USER_IF, mp);
8013 mp->is_server = is_server;
8014 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8015 mp->disable_indirect_desc = disable_indirect_desc;
8016 mp->enable_gso = enable_gso;
8017 mp->enable_packed = enable_packed;
8018 mp->custom_dev_instance = ntohl (custom_dev_instance);
8019 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8020 vec_free (file_name);
8021 if (custom_dev_instance != ~0)
8024 mp->use_custom_mac = use_custom_mac;
8025 clib_memcpy (mp->mac_address, hwaddr, 6);
8027 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8036 api_modify_vhost_user_if (vat_main_t * vam)
8038 unformat_input_t *i = vam->input;
8039 vl_api_modify_vhost_user_if_t *mp;
8042 u8 file_name_set = 0;
8043 u32 custom_dev_instance = ~0;
8044 u8 sw_if_index_set = 0;
8045 u32 sw_if_index = (u32) ~ 0;
8047 u8 enable_packed = 0;
8050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8052 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8053 sw_if_index_set = 1;
8054 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8055 sw_if_index_set = 1;
8056 else if (unformat (i, "socket %s", &file_name))
8060 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8062 else if (unformat (i, "server"))
8064 else if (unformat (i, "gso"))
8066 else if (unformat (i, "packed"))
8072 if (sw_if_index_set == 0)
8074 errmsg ("missing sw_if_index or interface name");
8078 if (file_name_set == 0)
8080 errmsg ("missing socket file name");
8084 if (vec_len (file_name) > 255)
8086 errmsg ("socket file name too long");
8089 vec_add1 (file_name, 0);
8091 M (MODIFY_VHOST_USER_IF, mp);
8093 mp->sw_if_index = ntohl (sw_if_index);
8094 mp->is_server = is_server;
8095 mp->enable_gso = enable_gso;
8096 mp->enable_packed = enable_packed;
8097 mp->custom_dev_instance = ntohl (custom_dev_instance);
8098 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8099 vec_free (file_name);
8100 if (custom_dev_instance != ~0)
8109 api_create_vhost_user_if_v2 (vat_main_t * vam)
8111 unformat_input_t *i = vam->input;
8112 vl_api_create_vhost_user_if_v2_t *mp;
8115 u8 file_name_set = 0;
8116 u32 custom_dev_instance = ~0;
8118 u8 use_custom_mac = 0;
8119 u8 disable_mrg_rxbuf = 0;
8120 u8 disable_indirect_desc = 0;
8123 u8 enable_packed = 0;
8124 u8 enable_event_idx = 0;
8127 /* Shut up coverity */
8128 clib_memset (hwaddr, 0, sizeof (hwaddr));
8130 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8132 if (unformat (i, "socket %s", &file_name))
8136 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8138 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8140 else if (unformat (i, "server"))
8142 else if (unformat (i, "disable_mrg_rxbuf"))
8143 disable_mrg_rxbuf = 1;
8144 else if (unformat (i, "disable_indirect_desc"))
8145 disable_indirect_desc = 1;
8146 else if (unformat (i, "gso"))
8148 else if (unformat (i, "packed"))
8150 else if (unformat (i, "event-idx"))
8151 enable_event_idx = 1;
8152 else if (unformat (i, "tag %s", &tag))
8158 if (file_name_set == 0)
8160 errmsg ("missing socket file name");
8164 if (vec_len (file_name) > 255)
8166 errmsg ("socket file name too long");
8169 vec_add1 (file_name, 0);
8171 M (CREATE_VHOST_USER_IF_V2, mp);
8173 mp->is_server = is_server;
8174 mp->disable_mrg_rxbuf = disable_mrg_rxbuf;
8175 mp->disable_indirect_desc = disable_indirect_desc;
8176 mp->enable_gso = enable_gso;
8177 mp->enable_packed = enable_packed;
8178 mp->enable_event_idx = enable_event_idx;
8179 mp->custom_dev_instance = ntohl (custom_dev_instance);
8180 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8181 vec_free (file_name);
8182 if (custom_dev_instance != ~0)
8185 mp->use_custom_mac = use_custom_mac;
8186 clib_memcpy (mp->mac_address, hwaddr, 6);
8188 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
8197 api_modify_vhost_user_if_v2 (vat_main_t * vam)
8199 unformat_input_t *i = vam->input;
8200 vl_api_modify_vhost_user_if_v2_t *mp;
8203 u8 file_name_set = 0;
8204 u32 custom_dev_instance = ~0;
8205 u8 sw_if_index_set = 0;
8206 u32 sw_if_index = (u32) ~ 0;
8208 u8 enable_packed = 0;
8209 u8 enable_event_idx = 0;
8212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8214 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8215 sw_if_index_set = 1;
8216 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8217 sw_if_index_set = 1;
8218 else if (unformat (i, "socket %s", &file_name))
8222 else if (unformat (i, "renumber %" PRIu32, &custom_dev_instance))
8224 else if (unformat (i, "server"))
8226 else if (unformat (i, "gso"))
8228 else if (unformat (i, "packed"))
8230 else if (unformat (i, "event-idx"))
8231 enable_event_idx = 1;
8236 if (sw_if_index_set == 0)
8238 errmsg ("missing sw_if_index or interface name");
8242 if (file_name_set == 0)
8244 errmsg ("missing socket file name");
8248 if (vec_len (file_name) > 255)
8250 errmsg ("socket file name too long");
8253 vec_add1 (file_name, 0);
8255 M (MODIFY_VHOST_USER_IF_V2, mp);
8257 mp->sw_if_index = ntohl (sw_if_index);
8258 mp->is_server = is_server;
8259 mp->enable_gso = enable_gso;
8260 mp->enable_packed = enable_packed;
8261 mp->enable_event_idx = enable_event_idx;
8262 mp->custom_dev_instance = ntohl (custom_dev_instance);
8263 clib_memcpy (mp->sock_filename, file_name, vec_len (file_name));
8264 vec_free (file_name);
8265 if (custom_dev_instance != ~0)
8274 api_delete_vhost_user_if (vat_main_t * vam)
8276 unformat_input_t *i = vam->input;
8277 vl_api_delete_vhost_user_if_t *mp;
8278 u32 sw_if_index = ~0;
8279 u8 sw_if_index_set = 0;
8282 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8284 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8285 sw_if_index_set = 1;
8286 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8287 sw_if_index_set = 1;
8292 if (sw_if_index_set == 0)
8294 errmsg ("missing sw_if_index or interface name");
8299 M (DELETE_VHOST_USER_IF, mp);
8301 mp->sw_if_index = ntohl (sw_if_index);
8308 static void vl_api_sw_interface_vhost_user_details_t_handler
8309 (vl_api_sw_interface_vhost_user_details_t * mp)
8311 vat_main_t *vam = &vat_main;
8315 clib_net_to_host_u32 (mp->features_first_32) | ((u64)
8316 clib_net_to_host_u32
8317 (mp->features_last_32) <<
8320 print (vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %16llx %6d %7d %s",
8321 (char *) mp->interface_name, ntohl (mp->sw_if_index),
8322 ntohl (mp->virtio_net_hdr_sz), features, mp->is_server,
8323 ntohl (mp->num_regions), (char *) mp->sock_filename);
8324 print (vam->ofp, " Status: '%s'", strerror (ntohl (mp->sock_errno)));
8327 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8328 (vl_api_sw_interface_vhost_user_details_t * mp)
8330 vat_main_t *vam = &vat_main;
8331 vat_json_node_t *node = NULL;
8333 if (VAT_JSON_ARRAY != vam->json_tree.type)
8335 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8336 vat_json_init_array (&vam->json_tree);
8338 node = vat_json_array_add (&vam->json_tree);
8340 vat_json_init_object (node);
8341 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8342 vat_json_object_add_string_copy (node, "interface_name",
8343 mp->interface_name);
8344 vat_json_object_add_uint (node, "virtio_net_hdr_sz",
8345 ntohl (mp->virtio_net_hdr_sz));
8346 vat_json_object_add_uint (node, "features_first_32",
8347 clib_net_to_host_u32 (mp->features_first_32));
8348 vat_json_object_add_uint (node, "features_last_32",
8349 clib_net_to_host_u32 (mp->features_last_32));
8350 vat_json_object_add_uint (node, "is_server", mp->is_server);
8351 vat_json_object_add_string_copy (node, "sock_filename", mp->sock_filename);
8352 vat_json_object_add_uint (node, "num_regions", ntohl (mp->num_regions));
8353 vat_json_object_add_uint (node, "sock_errno", ntohl (mp->sock_errno));
8357 api_sw_interface_vhost_user_dump (vat_main_t * vam)
8359 unformat_input_t *i = vam->input;
8360 vl_api_sw_interface_vhost_user_dump_t *mp;
8361 vl_api_control_ping_t *mp_ping;
8363 u32 sw_if_index = ~0;
8365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8367 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8369 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8375 print (vam->ofp, "Interface name idx hdr_sz features "
8376 "server regions filename");
8378 /* Get list of vhost-user interfaces */
8379 M (SW_INTERFACE_VHOST_USER_DUMP, mp);
8380 mp->sw_if_index = ntohl (sw_if_index);
8383 /* Use a control ping for synchronization */
8384 MPING (CONTROL_PING, mp_ping);
8392 api_show_version (vat_main_t * vam)
8394 vl_api_show_version_t *mp;
8397 M (SHOW_VERSION, mp);
8404 static void vl_api_l2_fib_table_details_t_handler
8405 (vl_api_l2_fib_table_details_t * mp)
8407 vat_main_t *vam = &vat_main;
8409 print (vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8411 ntohl (mp->bd_id), format_ethernet_address, mp->mac,
8412 ntohl (mp->sw_if_index), mp->static_mac, mp->filter_mac,
8416 static void vl_api_l2_fib_table_details_t_handler_json
8417 (vl_api_l2_fib_table_details_t * mp)
8419 vat_main_t *vam = &vat_main;
8420 vat_json_node_t *node = NULL;
8422 if (VAT_JSON_ARRAY != vam->json_tree.type)
8424 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
8425 vat_json_init_array (&vam->json_tree);
8427 node = vat_json_array_add (&vam->json_tree);
8429 vat_json_init_object (node);
8430 vat_json_object_add_uint (node, "bd_id", ntohl (mp->bd_id));
8431 vat_json_object_add_bytes (node, "mac", mp->mac, 6);
8432 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
8433 vat_json_object_add_uint (node, "static_mac", mp->static_mac);
8434 vat_json_object_add_uint (node, "filter_mac", mp->filter_mac);
8435 vat_json_object_add_uint (node, "bvi_mac", mp->bvi_mac);
8439 api_l2_fib_table_dump (vat_main_t * vam)
8441 unformat_input_t *i = vam->input;
8442 vl_api_l2_fib_table_dump_t *mp;
8443 vl_api_control_ping_t *mp_ping;
8448 /* Parse args required to build the message */
8449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8451 if (unformat (i, "bd_id %d", &bd_id))
8459 errmsg ("missing bridge domain");
8463 print (vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI");
8465 /* Get list of l2 fib entries */
8466 M (L2_FIB_TABLE_DUMP, mp);
8468 mp->bd_id = ntohl (bd_id);
8471 /* Use a control ping for synchronization */
8472 MPING (CONTROL_PING, mp_ping);
8481 api_interface_name_renumber (vat_main_t * vam)
8483 unformat_input_t *line_input = vam->input;
8484 vl_api_interface_name_renumber_t *mp;
8485 u32 sw_if_index = ~0;
8486 u32 new_show_dev_instance = ~0;
8489 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8491 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
8494 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8496 else if (unformat (line_input, "new_show_dev_instance %d",
8497 &new_show_dev_instance))
8503 if (sw_if_index == ~0)
8505 errmsg ("missing interface name or sw_if_index");
8509 if (new_show_dev_instance == ~0)
8511 errmsg ("missing new_show_dev_instance");
8515 M (INTERFACE_NAME_RENUMBER, mp);
8517 mp->sw_if_index = ntohl (sw_if_index);
8518 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8526 api_want_l2_macs_events (vat_main_t * vam)
8528 unformat_input_t *line_input = vam->input;
8529 vl_api_want_l2_macs_events_t *mp;
8530 u8 enable_disable = 1;
8532 u32 max_macs_in_event = 0;
8533 u32 learn_limit = 0;
8536 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
8538 if (unformat (line_input, "learn-limit %d", &learn_limit))
8540 else if (unformat (line_input, "scan-delay %d", &scan_delay))
8542 else if (unformat (line_input, "max-entries %d", &max_macs_in_event))
8544 else if (unformat (line_input, "disable"))
8550 M (WANT_L2_MACS_EVENTS, mp);
8551 mp->enable_disable = enable_disable;
8552 mp->pid = htonl (getpid ());
8553 mp->learn_limit = htonl (learn_limit);
8554 mp->scan_delay = (u8) scan_delay;
8555 mp->max_macs_in_event = (u8) (max_macs_in_event / 10);
8562 api_ip_address_dump (vat_main_t * vam)
8564 unformat_input_t *i = vam->input;
8565 vl_api_ip_address_dump_t *mp;
8566 vl_api_control_ping_t *mp_ping;
8567 u32 sw_if_index = ~0;
8568 u8 sw_if_index_set = 0;
8573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8575 if (unformat (i, "sw_if_index %d", &sw_if_index))
8576 sw_if_index_set = 1;
8578 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8579 sw_if_index_set = 1;
8580 else if (unformat (i, "ipv4"))
8582 else if (unformat (i, "ipv6"))
8588 if (ipv4_set && ipv6_set)
8590 errmsg ("ipv4 and ipv6 flags cannot be both set");
8594 if ((!ipv4_set) && (!ipv6_set))
8596 errmsg ("no ipv4 nor ipv6 flag set");
8600 if (sw_if_index_set == 0)
8602 errmsg ("missing interface name or sw_if_index");
8606 vam->current_sw_if_index = sw_if_index;
8607 vam->is_ipv6 = ipv6_set;
8609 M (IP_ADDRESS_DUMP, mp);
8610 mp->sw_if_index = ntohl (sw_if_index);
8611 mp->is_ipv6 = ipv6_set;
8614 /* Use a control ping for synchronization */
8615 MPING (CONTROL_PING, mp_ping);
8623 api_ip_dump (vat_main_t * vam)
8625 vl_api_ip_dump_t *mp;
8626 vl_api_control_ping_t *mp_ping;
8627 unformat_input_t *in = vam->input;
8634 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT)
8636 if (unformat (in, "ipv4"))
8638 else if (unformat (in, "ipv6"))
8644 if (ipv4_set && ipv6_set)
8646 errmsg ("ipv4 and ipv6 flags cannot be both set");
8650 if ((!ipv4_set) && (!ipv6_set))
8652 errmsg ("no ipv4 nor ipv6 flag set");
8657 vam->is_ipv6 = is_ipv6;
8660 for (i = 0; i < vec_len (vam->ip_details_by_sw_if_index[is_ipv6]); i++)
8662 vec_free (vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8664 vec_free (vam->ip_details_by_sw_if_index[is_ipv6]);
8667 mp->is_ipv6 = ipv6_set;
8670 /* Use a control ping for synchronization */
8671 MPING (CONTROL_PING, mp_ping);
8679 api_ipsec_spd_add_del (vat_main_t * vam)
8681 unformat_input_t *i = vam->input;
8682 vl_api_ipsec_spd_add_del_t *mp;
8687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8689 if (unformat (i, "spd_id %d", &spd_id))
8691 else if (unformat (i, "del"))
8695 clib_warning ("parse error '%U'", format_unformat_error, i);
8701 errmsg ("spd_id must be set");
8705 M (IPSEC_SPD_ADD_DEL, mp);
8707 mp->spd_id = ntohl (spd_id);
8708 mp->is_add = is_add;
8716 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8718 unformat_input_t *i = vam->input;
8719 vl_api_ipsec_interface_add_del_spd_t *mp;
8721 u8 sw_if_index_set = 0;
8722 u32 spd_id = (u32) ~ 0;
8726 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8728 if (unformat (i, "del"))
8730 else if (unformat (i, "spd_id %d", &spd_id))
8733 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
8734 sw_if_index_set = 1;
8735 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8736 sw_if_index_set = 1;
8739 clib_warning ("parse error '%U'", format_unformat_error, i);
8745 if (spd_id == (u32) ~ 0)
8747 errmsg ("spd_id must be set");
8751 if (sw_if_index_set == 0)
8753 errmsg ("missing interface name or sw_if_index");
8757 M (IPSEC_INTERFACE_ADD_DEL_SPD, mp);
8759 mp->spd_id = ntohl (spd_id);
8760 mp->sw_if_index = ntohl (sw_if_index);
8761 mp->is_add = is_add;
8769 api_ipsec_spd_entry_add_del (vat_main_t * vam)
8771 unformat_input_t *i = vam->input;
8772 vl_api_ipsec_spd_entry_add_del_t *mp;
8773 u8 is_add = 1, is_outbound = 0;
8774 u32 spd_id = 0, sa_id = 0, protocol = 0, policy = 0;
8776 u32 rport_start = 0, rport_stop = (u32) ~ 0;
8777 u32 lport_start = 0, lport_stop = (u32) ~ 0;
8778 vl_api_address_t laddr_start = { }, laddr_stop =
8787 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8789 if (unformat (i, "del"))
8791 if (unformat (i, "outbound"))
8793 if (unformat (i, "inbound"))
8795 else if (unformat (i, "spd_id %d", &spd_id))
8797 else if (unformat (i, "sa_id %d", &sa_id))
8799 else if (unformat (i, "priority %d", &priority))
8801 else if (unformat (i, "protocol %d", &protocol))
8803 else if (unformat (i, "lport_start %d", &lport_start))
8805 else if (unformat (i, "lport_stop %d", &lport_stop))
8807 else if (unformat (i, "rport_start %d", &rport_start))
8809 else if (unformat (i, "rport_stop %d", &rport_stop))
8811 else if (unformat (i, "laddr_start %U",
8812 unformat_vl_api_address, &laddr_start))
8814 else if (unformat (i, "laddr_stop %U", unformat_vl_api_address,
8817 else if (unformat (i, "raddr_start %U", unformat_vl_api_address,
8820 else if (unformat (i, "raddr_stop %U", unformat_vl_api_address,
8824 if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8826 if (policy == IPSEC_POLICY_ACTION_RESOLVE)
8828 clib_warning ("unsupported action: 'resolve'");
8834 clib_warning ("parse error '%U'", format_unformat_error, i);
8840 M (IPSEC_SPD_ENTRY_ADD_DEL, mp);
8842 mp->is_add = is_add;
8844 mp->entry.spd_id = ntohl (spd_id);
8845 mp->entry.priority = ntohl (priority);
8846 mp->entry.is_outbound = is_outbound;
8848 clib_memcpy (&mp->entry.remote_address_start, &raddr_start,
8849 sizeof (vl_api_address_t));
8850 clib_memcpy (&mp->entry.remote_address_stop, &raddr_stop,
8851 sizeof (vl_api_address_t));
8852 clib_memcpy (&mp->entry.local_address_start, &laddr_start,
8853 sizeof (vl_api_address_t));
8854 clib_memcpy (&mp->entry.local_address_stop, &laddr_stop,
8855 sizeof (vl_api_address_t));
8857 mp->entry.protocol = (u8) protocol;
8858 mp->entry.local_port_start = ntohs ((u16) lport_start);
8859 mp->entry.local_port_stop = ntohs ((u16) lport_stop);
8860 mp->entry.remote_port_start = ntohs ((u16) rport_start);
8861 mp->entry.remote_port_stop = ntohs ((u16) rport_stop);
8862 mp->entry.policy = (u8) policy;
8863 mp->entry.sa_id = ntohl (sa_id);
8871 api_ipsec_sad_entry_add_del (vat_main_t * vam)
8873 unformat_input_t *i = vam->input;
8874 vl_api_ipsec_sad_entry_add_del_t *mp;
8875 u32 sad_id = 0, spi = 0;
8876 u8 *ck = 0, *ik = 0;
8879 vl_api_ipsec_crypto_alg_t crypto_alg = IPSEC_API_CRYPTO_ALG_NONE;
8880 vl_api_ipsec_integ_alg_t integ_alg = IPSEC_API_INTEG_ALG_NONE;
8881 vl_api_ipsec_sad_flags_t flags = IPSEC_API_SAD_FLAG_NONE;
8882 vl_api_ipsec_proto_t protocol = IPSEC_API_PROTO_AH;
8883 vl_api_address_t tun_src, tun_dst;
8886 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
8888 if (unformat (i, "del"))
8890 else if (unformat (i, "sad_id %d", &sad_id))
8892 else if (unformat (i, "spi %d", &spi))
8894 else if (unformat (i, "esp"))
8895 protocol = IPSEC_API_PROTO_ESP;
8897 if (unformat (i, "tunnel_src %U", unformat_vl_api_address, &tun_src))
8899 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
8900 if (ADDRESS_IP6 == tun_src.af)
8901 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
8904 if (unformat (i, "tunnel_dst %U", unformat_vl_api_address, &tun_dst))
8906 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
8907 if (ADDRESS_IP6 == tun_src.af)
8908 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
8911 if (unformat (i, "crypto_alg %U",
8912 unformat_ipsec_api_crypto_alg, &crypto_alg))
8914 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8916 else if (unformat (i, "integ_alg %U",
8917 unformat_ipsec_api_integ_alg, &integ_alg))
8919 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8923 clib_warning ("parse error '%U'", format_unformat_error, i);
8929 M (IPSEC_SAD_ENTRY_ADD_DEL, mp);
8931 mp->is_add = is_add;
8932 mp->entry.sad_id = ntohl (sad_id);
8933 mp->entry.protocol = protocol;
8934 mp->entry.spi = ntohl (spi);
8935 mp->entry.flags = flags;
8937 mp->entry.crypto_algorithm = crypto_alg;
8938 mp->entry.integrity_algorithm = integ_alg;
8939 mp->entry.crypto_key.length = vec_len (ck);
8940 mp->entry.integrity_key.length = vec_len (ik);
8942 if (mp->entry.crypto_key.length > sizeof (mp->entry.crypto_key.data))
8943 mp->entry.crypto_key.length = sizeof (mp->entry.crypto_key.data);
8945 if (mp->entry.integrity_key.length > sizeof (mp->entry.integrity_key.data))
8946 mp->entry.integrity_key.length = sizeof (mp->entry.integrity_key.data);
8949 clib_memcpy (mp->entry.crypto_key.data, ck, mp->entry.crypto_key.length);
8951 clib_memcpy (mp->entry.integrity_key.data, ik,
8952 mp->entry.integrity_key.length);
8954 if (flags & IPSEC_API_SAD_FLAG_IS_TUNNEL)
8956 clib_memcpy (&mp->entry.tunnel_src, &tun_src,
8957 sizeof (mp->entry.tunnel_src));
8958 clib_memcpy (&mp->entry.tunnel_dst, &tun_dst,
8959 sizeof (mp->entry.tunnel_dst));
8968 vl_api_ipsec_sa_details_t_handler (vl_api_ipsec_sa_details_t * mp)
8970 vat_main_t *vam = &vat_main;
8972 print (vam->ofp, "sa_id %u sw_if_index %u spi %u proto %u crypto_alg %u "
8973 "crypto_key %U integ_alg %u integ_key %U flags %x "
8974 "tunnel_src_addr %U tunnel_dst_addr %U "
8975 "salt %u seq_outbound %lu last_seq_inbound %lu "
8976 "replay_window %lu stat_index %u\n",
8977 ntohl (mp->entry.sad_id),
8978 ntohl (mp->sw_if_index),
8979 ntohl (mp->entry.spi),
8980 ntohl (mp->entry.protocol),
8981 ntohl (mp->entry.crypto_algorithm),
8982 format_hex_bytes, mp->entry.crypto_key.data,
8983 mp->entry.crypto_key.length, ntohl (mp->entry.integrity_algorithm),
8984 format_hex_bytes, mp->entry.integrity_key.data,
8985 mp->entry.integrity_key.length, ntohl (mp->entry.flags),
8986 format_vl_api_address, &mp->entry.tunnel_src, format_vl_api_address,
8987 &mp->entry.tunnel_dst, ntohl (mp->salt),
8988 clib_net_to_host_u64 (mp->seq_outbound),
8989 clib_net_to_host_u64 (mp->last_seq_inbound),
8990 clib_net_to_host_u64 (mp->replay_window), ntohl (mp->stat_index));
8993 #define vl_api_ipsec_sa_details_t_endian vl_noop_handler
8994 #define vl_api_ipsec_sa_details_t_print vl_noop_handler
8996 static void vl_api_ipsec_sa_details_t_handler_json
8997 (vl_api_ipsec_sa_details_t * mp)
8999 vat_main_t *vam = &vat_main;
9000 vat_json_node_t *node = NULL;
9001 vl_api_ipsec_sad_flags_t flags;
9003 if (VAT_JSON_ARRAY != vam->json_tree.type)
9005 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9006 vat_json_init_array (&vam->json_tree);
9008 node = vat_json_array_add (&vam->json_tree);
9010 vat_json_init_object (node);
9011 vat_json_object_add_uint (node, "sa_id", ntohl (mp->entry.sad_id));
9012 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9013 vat_json_object_add_uint (node, "spi", ntohl (mp->entry.spi));
9014 vat_json_object_add_uint (node, "proto", ntohl (mp->entry.protocol));
9015 vat_json_object_add_uint (node, "crypto_alg",
9016 ntohl (mp->entry.crypto_algorithm));
9017 vat_json_object_add_uint (node, "integ_alg",
9018 ntohl (mp->entry.integrity_algorithm));
9019 flags = ntohl (mp->entry.flags);
9020 vat_json_object_add_uint (node, "use_esn",
9021 ! !(flags & IPSEC_API_SAD_FLAG_USE_ESN));
9022 vat_json_object_add_uint (node, "use_anti_replay",
9023 ! !(flags & IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY));
9024 vat_json_object_add_uint (node, "is_tunnel",
9025 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL));
9026 vat_json_object_add_uint (node, "is_tunnel_ip6",
9027 ! !(flags & IPSEC_API_SAD_FLAG_IS_TUNNEL_V6));
9028 vat_json_object_add_uint (node, "udp_encap",
9029 ! !(flags & IPSEC_API_SAD_FLAG_UDP_ENCAP));
9030 vat_json_object_add_bytes (node, "crypto_key", mp->entry.crypto_key.data,
9031 mp->entry.crypto_key.length);
9032 vat_json_object_add_bytes (node, "integ_key", mp->entry.integrity_key.data,
9033 mp->entry.integrity_key.length);
9034 vat_json_object_add_address (node, "src", &mp->entry.tunnel_src);
9035 vat_json_object_add_address (node, "dst", &mp->entry.tunnel_dst);
9036 vat_json_object_add_uint (node, "replay_window",
9037 clib_net_to_host_u64 (mp->replay_window));
9038 vat_json_object_add_uint (node, "stat_index", ntohl (mp->stat_index));
9042 api_ipsec_sa_dump (vat_main_t * vam)
9044 unformat_input_t *i = vam->input;
9045 vl_api_ipsec_sa_dump_t *mp;
9046 vl_api_control_ping_t *mp_ping;
9050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9052 if (unformat (i, "sa_id %d", &sa_id))
9056 clib_warning ("parse error '%U'", format_unformat_error, i);
9061 M (IPSEC_SA_DUMP, mp);
9063 mp->sa_id = ntohl (sa_id);
9067 /* Use a control ping for synchronization */
9068 M (CONTROL_PING, mp_ping);
9076 api_get_first_msg_id (vat_main_t * vam)
9078 vl_api_get_first_msg_id_t *mp;
9079 unformat_input_t *i = vam->input;
9084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9086 if (unformat (i, "client %s", &name))
9094 errmsg ("missing client name");
9099 if (vec_len (name) > 63)
9101 errmsg ("client name too long");
9105 M (GET_FIRST_MSG_ID, mp);
9106 clib_memcpy (mp->name, name, vec_len (name));
9113 api_get_node_graph (vat_main_t * vam)
9115 vl_api_get_node_graph_t *mp;
9118 M (GET_NODE_GRAPH, mp);
9122 /* Wait for the reply */
9128 api_af_packet_create (vat_main_t * vam)
9130 unformat_input_t *i = vam->input;
9131 vl_api_af_packet_create_t *mp;
9132 u8 *host_if_name = 0;
9134 u8 random_hw_addr = 1;
9137 clib_memset (hw_addr, 0, sizeof (hw_addr));
9139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9141 if (unformat (i, "name %s", &host_if_name))
9142 vec_add1 (host_if_name, 0);
9143 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
9149 if (!vec_len (host_if_name))
9151 errmsg ("host-interface name must be specified");
9155 if (vec_len (host_if_name) > 64)
9157 errmsg ("host-interface name too long");
9161 M (AF_PACKET_CREATE, mp);
9163 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9164 clib_memcpy (mp->hw_addr, hw_addr, 6);
9165 mp->use_random_hw_addr = random_hw_addr;
9166 vec_free (host_if_name);
9174 fprintf (vam->ofp ? vam->ofp : stderr,
9175 " new sw_if_index = %d\n", vam->sw_if_index);
9182 api_af_packet_delete (vat_main_t * vam)
9184 unformat_input_t *i = vam->input;
9185 vl_api_af_packet_delete_t *mp;
9186 u8 *host_if_name = 0;
9189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9191 if (unformat (i, "name %s", &host_if_name))
9192 vec_add1 (host_if_name, 0);
9197 if (!vec_len (host_if_name))
9199 errmsg ("host-interface name must be specified");
9203 if (vec_len (host_if_name) > 64)
9205 errmsg ("host-interface name too long");
9209 M (AF_PACKET_DELETE, mp);
9211 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
9212 vec_free (host_if_name);
9219 static void vl_api_af_packet_details_t_handler
9220 (vl_api_af_packet_details_t * mp)
9222 vat_main_t *vam = &vat_main;
9224 print (vam->ofp, "%-16s %d",
9225 mp->host_if_name, clib_net_to_host_u32 (mp->sw_if_index));
9228 static void vl_api_af_packet_details_t_handler_json
9229 (vl_api_af_packet_details_t * mp)
9231 vat_main_t *vam = &vat_main;
9232 vat_json_node_t *node = NULL;
9234 if (VAT_JSON_ARRAY != vam->json_tree.type)
9236 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9237 vat_json_init_array (&vam->json_tree);
9239 node = vat_json_array_add (&vam->json_tree);
9241 vat_json_init_object (node);
9242 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
9243 vat_json_object_add_string_copy (node, "dev_name", mp->host_if_name);
9247 api_af_packet_dump (vat_main_t * vam)
9249 vl_api_af_packet_dump_t *mp;
9250 vl_api_control_ping_t *mp_ping;
9253 print (vam->ofp, "\n%-16s %s", "dev_name", "sw_if_index");
9254 /* Get list of tap interfaces */
9255 M (AF_PACKET_DUMP, mp);
9258 /* Use a control ping for synchronization */
9259 MPING (CONTROL_PING, mp_ping);
9267 format_fib_api_path_nh_proto (u8 * s, va_list * args)
9269 vl_api_fib_path_nh_proto_t proto =
9270 va_arg (*args, vl_api_fib_path_nh_proto_t);
9274 case FIB_API_PATH_NH_PROTO_IP4:
9275 s = format (s, "ip4");
9277 case FIB_API_PATH_NH_PROTO_IP6:
9278 s = format (s, "ip6");
9280 case FIB_API_PATH_NH_PROTO_MPLS:
9281 s = format (s, "mpls");
9283 case FIB_API_PATH_NH_PROTO_BIER:
9284 s = format (s, "bier");
9286 case FIB_API_PATH_NH_PROTO_ETHERNET:
9287 s = format (s, "ethernet");
9295 format_vl_api_ip_address_union (u8 * s, va_list * args)
9297 vl_api_address_family_t af = va_arg (*args, int);
9298 const vl_api_address_union_t *u = va_arg (*args, vl_api_address_union_t *);
9303 s = format (s, "%U", format_ip4_address, u->ip4);
9306 s = format (s, "%U", format_ip6_address, u->ip6);
9313 format_vl_api_fib_path_type (u8 * s, va_list * args)
9315 vl_api_fib_path_type_t t = va_arg (*args, vl_api_fib_path_type_t);
9319 case FIB_API_PATH_TYPE_NORMAL:
9320 s = format (s, "normal");
9322 case FIB_API_PATH_TYPE_LOCAL:
9323 s = format (s, "local");
9325 case FIB_API_PATH_TYPE_DROP:
9326 s = format (s, "drop");
9328 case FIB_API_PATH_TYPE_UDP_ENCAP:
9329 s = format (s, "udp-encap");
9331 case FIB_API_PATH_TYPE_BIER_IMP:
9332 s = format (s, "bier-imp");
9334 case FIB_API_PATH_TYPE_ICMP_UNREACH:
9335 s = format (s, "unreach");
9337 case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
9338 s = format (s, "prohibit");
9340 case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
9341 s = format (s, "src-lookup");
9343 case FIB_API_PATH_TYPE_DVR:
9344 s = format (s, "dvr");
9346 case FIB_API_PATH_TYPE_INTERFACE_RX:
9347 s = format (s, "interface-rx");
9349 case FIB_API_PATH_TYPE_CLASSIFY:
9350 s = format (s, "classify");
9358 vl_api_fib_path_print (vat_main_t * vam, vl_api_fib_path_t * fp)
9361 " weight %d, sw_if_index %d, type %U, afi %U, next_hop %U",
9362 ntohl (fp->weight), ntohl (fp->sw_if_index),
9363 format_vl_api_fib_path_type, fp->type,
9364 format_fib_api_path_nh_proto, fp->proto,
9365 format_vl_api_ip_address_union, &fp->nh.address);
9369 vl_api_mpls_fib_path_json_print (vat_json_node_t * node,
9370 vl_api_fib_path_t * fp)
9373 struct in6_addr ip6;
9375 vat_json_object_add_uint (node, "weight", ntohl (fp->weight));
9376 vat_json_object_add_uint (node, "sw_if_index", ntohl (fp->sw_if_index));
9377 vat_json_object_add_uint (node, "type", fp->type);
9378 vat_json_object_add_uint (node, "next_hop_proto", fp->proto);
9379 if (fp->proto == FIB_API_PATH_NH_PROTO_IP4)
9381 clib_memcpy (&ip4, &fp->nh.address.ip4, sizeof (ip4));
9382 vat_json_object_add_ip4 (node, "next_hop", ip4);
9384 else if (fp->proto == FIB_API_PATH_NH_PROTO_IP6)
9386 clib_memcpy (&ip6, &fp->nh.address.ip6, sizeof (ip6));
9387 vat_json_object_add_ip6 (node, "next_hop", ip6);
9392 vl_api_mpls_tunnel_details_t_handler (vl_api_mpls_tunnel_details_t * mp)
9394 vat_main_t *vam = &vat_main;
9395 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9396 vl_api_fib_path_t *fp;
9399 print (vam->ofp, "sw_if_index %d via:",
9400 ntohl (mp->mt_tunnel.mt_sw_if_index));
9401 fp = mp->mt_tunnel.mt_paths;
9402 for (i = 0; i < count; i++)
9404 vl_api_fib_path_print (vam, fp);
9408 print (vam->ofp, "");
9411 #define vl_api_mpls_tunnel_details_t_endian vl_noop_handler
9412 #define vl_api_mpls_tunnel_details_t_print vl_noop_handler
9415 vl_api_mpls_tunnel_details_t_handler_json (vl_api_mpls_tunnel_details_t * mp)
9417 vat_main_t *vam = &vat_main;
9418 vat_json_node_t *node = NULL;
9419 int count = ntohl (mp->mt_tunnel.mt_n_paths);
9420 vl_api_fib_path_t *fp;
9423 if (VAT_JSON_ARRAY != vam->json_tree.type)
9425 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9426 vat_json_init_array (&vam->json_tree);
9428 node = vat_json_array_add (&vam->json_tree);
9430 vat_json_init_object (node);
9431 vat_json_object_add_uint (node, "sw_if_index",
9432 ntohl (mp->mt_tunnel.mt_sw_if_index));
9434 vat_json_object_add_uint (node, "l2_only", mp->mt_tunnel.mt_l2_only);
9436 fp = mp->mt_tunnel.mt_paths;
9437 for (i = 0; i < count; i++)
9439 vl_api_mpls_fib_path_json_print (node, fp);
9445 api_mpls_tunnel_dump (vat_main_t * vam)
9447 vl_api_mpls_tunnel_dump_t *mp;
9448 vl_api_control_ping_t *mp_ping;
9451 M (MPLS_TUNNEL_DUMP, mp);
9455 /* Use a control ping for synchronization */
9456 MPING (CONTROL_PING, mp_ping);
9463 #define vl_api_mpls_table_details_t_endian vl_noop_handler
9464 #define vl_api_mpls_table_details_t_print vl_noop_handler
9468 vl_api_mpls_table_details_t_handler (vl_api_mpls_table_details_t * mp)
9470 vat_main_t *vam = &vat_main;
9472 print (vam->ofp, "table-id %d,", ntohl (mp->mt_table.mt_table_id));
9475 static void vl_api_mpls_table_details_t_handler_json
9476 (vl_api_mpls_table_details_t * mp)
9478 vat_main_t *vam = &vat_main;
9479 vat_json_node_t *node = NULL;
9481 if (VAT_JSON_ARRAY != vam->json_tree.type)
9483 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9484 vat_json_init_array (&vam->json_tree);
9486 node = vat_json_array_add (&vam->json_tree);
9488 vat_json_init_object (node);
9489 vat_json_object_add_uint (node, "table", ntohl (mp->mt_table.mt_table_id));
9493 api_mpls_table_dump (vat_main_t * vam)
9495 vl_api_mpls_table_dump_t *mp;
9496 vl_api_control_ping_t *mp_ping;
9499 M (MPLS_TABLE_DUMP, mp);
9502 /* Use a control ping for synchronization */
9503 MPING (CONTROL_PING, mp_ping);
9510 #define vl_api_mpls_route_details_t_endian vl_noop_handler
9511 #define vl_api_mpls_route_details_t_print vl_noop_handler
9514 vl_api_mpls_route_details_t_handler (vl_api_mpls_route_details_t * mp)
9516 vat_main_t *vam = &vat_main;
9517 int count = (int) clib_net_to_host_u32 (mp->mr_route.mr_n_paths);
9518 vl_api_fib_path_t *fp;
9522 "table-id %d, label %u, ess_bit %u",
9523 ntohl (mp->mr_route.mr_table_id),
9524 ntohl (mp->mr_route.mr_label), mp->mr_route.mr_eos);
9525 fp = mp->mr_route.mr_paths;
9526 for (i = 0; i < count; i++)
9528 vl_api_fib_path_print (vam, fp);
9533 static void vl_api_mpls_route_details_t_handler_json
9534 (vl_api_mpls_route_details_t * mp)
9536 vat_main_t *vam = &vat_main;
9537 int count = (int) clib_host_to_net_u32 (mp->mr_route.mr_n_paths);
9538 vat_json_node_t *node = NULL;
9539 vl_api_fib_path_t *fp;
9542 if (VAT_JSON_ARRAY != vam->json_tree.type)
9544 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9545 vat_json_init_array (&vam->json_tree);
9547 node = vat_json_array_add (&vam->json_tree);
9549 vat_json_init_object (node);
9550 vat_json_object_add_uint (node, "table", ntohl (mp->mr_route.mr_table_id));
9551 vat_json_object_add_uint (node, "s_bit", mp->mr_route.mr_eos);
9552 vat_json_object_add_uint (node, "label", ntohl (mp->mr_route.mr_label));
9553 vat_json_object_add_uint (node, "path_count", count);
9554 fp = mp->mr_route.mr_paths;
9555 for (i = 0; i < count; i++)
9557 vl_api_mpls_fib_path_json_print (node, fp);
9563 api_mpls_route_dump (vat_main_t * vam)
9565 unformat_input_t *input = vam->input;
9566 vl_api_mpls_route_dump_t *mp;
9567 vl_api_control_ping_t *mp_ping;
9571 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9573 if (unformat (input, "table_id %d", &table_id))
9580 errmsg ("missing table id");
9584 M (MPLS_ROUTE_DUMP, mp);
9586 mp->table.mt_table_id = ntohl (table_id);
9589 /* Use a control ping for synchronization */
9590 MPING (CONTROL_PING, mp_ping);
9597 #define vl_api_ip_table_details_t_endian vl_noop_handler
9598 #define vl_api_ip_table_details_t_print vl_noop_handler
9601 vl_api_ip_table_details_t_handler (vl_api_ip_table_details_t * mp)
9603 vat_main_t *vam = &vat_main;
9606 "%s; table-id %d, prefix %U/%d",
9607 mp->table.name, ntohl (mp->table.table_id));
9611 static void vl_api_ip_table_details_t_handler_json
9612 (vl_api_ip_table_details_t * mp)
9614 vat_main_t *vam = &vat_main;
9615 vat_json_node_t *node = NULL;
9617 if (VAT_JSON_ARRAY != vam->json_tree.type)
9619 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9620 vat_json_init_array (&vam->json_tree);
9622 node = vat_json_array_add (&vam->json_tree);
9624 vat_json_init_object (node);
9625 vat_json_object_add_uint (node, "table", ntohl (mp->table.table_id));
9629 api_ip_table_dump (vat_main_t * vam)
9631 vl_api_ip_table_dump_t *mp;
9632 vl_api_control_ping_t *mp_ping;
9635 M (IP_TABLE_DUMP, mp);
9638 /* Use a control ping for synchronization */
9639 MPING (CONTROL_PING, mp_ping);
9647 api_ip_mtable_dump (vat_main_t * vam)
9649 vl_api_ip_mtable_dump_t *mp;
9650 vl_api_control_ping_t *mp_ping;
9653 M (IP_MTABLE_DUMP, mp);
9656 /* Use a control ping for synchronization */
9657 MPING (CONTROL_PING, mp_ping);
9665 api_ip_mroute_dump (vat_main_t * vam)
9667 unformat_input_t *input = vam->input;
9668 vl_api_control_ping_t *mp_ping;
9669 vl_api_ip_mroute_dump_t *mp;
9674 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9676 if (unformat (input, "table_id %d", &table_id))
9678 else if (unformat (input, "ip6"))
9680 else if (unformat (input, "ip4"))
9687 errmsg ("missing table id");
9691 M (IP_MROUTE_DUMP, mp);
9692 mp->table.table_id = table_id;
9693 mp->table.is_ip6 = is_ip6;
9696 /* Use a control ping for synchronization */
9697 MPING (CONTROL_PING, mp_ping);
9704 #define vl_api_ip_route_details_t_endian vl_noop_handler
9705 #define vl_api_ip_route_details_t_print vl_noop_handler
9708 vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp)
9710 vat_main_t *vam = &vat_main;
9711 u8 count = mp->route.n_paths;
9712 vl_api_fib_path_t *fp;
9716 "table-id %d, prefix %U/%d",
9717 ntohl (mp->route.table_id),
9718 format_ip46_address, mp->route.prefix.address, mp->route.prefix.len);
9719 for (i = 0; i < count; i++)
9721 fp = &mp->route.paths[i];
9723 vl_api_fib_path_print (vam, fp);
9728 static void vl_api_ip_route_details_t_handler_json
9729 (vl_api_ip_route_details_t * mp)
9731 vat_main_t *vam = &vat_main;
9732 u8 count = mp->route.n_paths;
9733 vat_json_node_t *node = NULL;
9735 struct in6_addr ip6;
9736 vl_api_fib_path_t *fp;
9739 if (VAT_JSON_ARRAY != vam->json_tree.type)
9741 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9742 vat_json_init_array (&vam->json_tree);
9744 node = vat_json_array_add (&vam->json_tree);
9746 vat_json_init_object (node);
9747 vat_json_object_add_uint (node, "table", ntohl (mp->route.table_id));
9748 if (ADDRESS_IP6 == mp->route.prefix.address.af)
9750 clib_memcpy (&ip6, &mp->route.prefix.address.un.ip6, sizeof (ip6));
9751 vat_json_object_add_ip6 (node, "prefix", ip6);
9755 clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4));
9756 vat_json_object_add_ip4 (node, "prefix", ip4);
9758 vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len);
9759 vat_json_object_add_uint (node, "path_count", count);
9760 for (i = 0; i < count; i++)
9762 fp = &mp->route.paths[i];
9763 vl_api_mpls_fib_path_json_print (node, fp);
9768 api_ip_route_dump (vat_main_t * vam)
9770 unformat_input_t *input = vam->input;
9771 vl_api_ip_route_dump_t *mp;
9772 vl_api_control_ping_t *mp_ping;
9778 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9780 if (unformat (input, "table_id %d", &table_id))
9782 else if (unformat (input, "ip6"))
9784 else if (unformat (input, "ip4"))
9791 errmsg ("missing table id");
9795 M (IP_ROUTE_DUMP, mp);
9797 mp->table.table_id = table_id;
9798 mp->table.is_ip6 = is_ip6;
9802 /* Use a control ping for synchronization */
9803 MPING (CONTROL_PING, mp_ping);
9811 api_sw_interface_span_enable_disable (vat_main_t * vam)
9813 unformat_input_t *i = vam->input;
9814 vl_api_sw_interface_span_enable_disable_t *mp;
9815 u32 src_sw_if_index = ~0;
9816 u32 dst_sw_if_index = ~0;
9821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
9824 (i, "src %U", api_unformat_sw_if_index, vam, &src_sw_if_index))
9826 else if (unformat (i, "src_sw_if_index %d", &src_sw_if_index))
9830 (i, "dst %U", api_unformat_sw_if_index, vam, &dst_sw_if_index))
9832 else if (unformat (i, "dst_sw_if_index %d", &dst_sw_if_index))
9834 else if (unformat (i, "disable"))
9836 else if (unformat (i, "rx"))
9838 else if (unformat (i, "tx"))
9840 else if (unformat (i, "both"))
9842 else if (unformat (i, "l2"))
9848 M (SW_INTERFACE_SPAN_ENABLE_DISABLE, mp);
9850 mp->sw_if_index_from = htonl (src_sw_if_index);
9851 mp->sw_if_index_to = htonl (dst_sw_if_index);
9861 vl_api_sw_interface_span_details_t_handler (vl_api_sw_interface_span_details_t
9864 vat_main_t *vam = &vat_main;
9865 u8 *sw_if_from_name = 0;
9866 u8 *sw_if_to_name = 0;
9867 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
9868 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
9869 char *states[] = { "none", "rx", "tx", "both" };
9873 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
9875 if ((u32) p->value[0] == sw_if_index_from)
9877 sw_if_from_name = (u8 *)(p->key);
9881 if ((u32) p->value[0] == sw_if_index_to)
9883 sw_if_to_name = (u8 *)(p->key);
9884 if (sw_if_from_name)
9889 print (vam->ofp, "%20s => %20s (%s) %s",
9890 sw_if_from_name, sw_if_to_name, states[mp->state],
9891 mp->is_l2 ? "l2" : "device");
9895 vl_api_sw_interface_span_details_t_handler_json
9896 (vl_api_sw_interface_span_details_t * mp)
9898 vat_main_t *vam = &vat_main;
9899 vat_json_node_t *node = NULL;
9900 u8 *sw_if_from_name = 0;
9901 u8 *sw_if_to_name = 0;
9902 u32 sw_if_index_from = ntohl (mp->sw_if_index_from);
9903 u32 sw_if_index_to = ntohl (mp->sw_if_index_to);
9907 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
9909 if ((u32) p->value[0] == sw_if_index_from)
9911 sw_if_from_name = (u8 *)(p->key);
9915 if ((u32) p->value[0] == sw_if_index_to)
9917 sw_if_to_name = (u8 *)(p->key);
9918 if (sw_if_from_name)
9924 if (VAT_JSON_ARRAY != vam->json_tree.type)
9926 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
9927 vat_json_init_array (&vam->json_tree);
9929 node = vat_json_array_add (&vam->json_tree);
9931 vat_json_init_object (node);
9932 vat_json_object_add_uint (node, "src-if-index", sw_if_index_from);
9933 vat_json_object_add_string_copy (node, "src-if-name", sw_if_from_name);
9934 vat_json_object_add_uint (node, "dst-if-index", sw_if_index_to);
9935 if (0 != sw_if_to_name)
9937 vat_json_object_add_string_copy (node, "dst-if-name", sw_if_to_name);
9939 vat_json_object_add_uint (node, "state", mp->state);
9940 vat_json_object_add_uint (node, "is-l2", mp->is_l2);
9944 api_sw_interface_span_dump (vat_main_t * vam)
9946 unformat_input_t *input = vam->input;
9947 vl_api_sw_interface_span_dump_t *mp;
9948 vl_api_control_ping_t *mp_ping;
9952 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9954 if (unformat (input, "l2"))
9960 M (SW_INTERFACE_SPAN_DUMP, mp);
9964 /* Use a control ping for synchronization */
9965 MPING (CONTROL_PING, mp_ping);
9973 api_ip_source_and_port_range_check_add_del (vat_main_t * vam)
9975 unformat_input_t *input = vam->input;
9976 vl_api_ip_source_and_port_range_check_add_del_t *mp;
9979 u16 *high_ports = 0;
9982 vl_api_prefix_t prefix;
9989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9991 if (unformat (input, "%U", unformat_vl_api_prefix, &prefix))
9993 else if (unformat (input, "vrf %d", &vrf_id))
9995 else if (unformat (input, "del"))
9997 else if (unformat (input, "port %d", &tmp))
9999 if (tmp == 0 || tmp > 65535)
10001 errmsg ("port %d out of range", tmp);
10005 this_hi = this_low + 1;
10006 vec_add1 (low_ports, this_low);
10007 vec_add1 (high_ports, this_hi);
10009 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
10011 if ((tmp > tmp2) || (tmp == 0) || (tmp2 > 65535))
10013 errmsg ("incorrect range parameters");
10017 /* Note: in debug CLI +1 is added to high before
10018 passing to real fn that does "the work"
10019 (ip_source_and_port_range_check_add_del).
10020 This fn is a wrapper around the binary API fn a
10021 control plane will call, which expects this increment
10022 to have occurred. Hence letting the binary API control
10023 plane fn do the increment for consistency between VAT
10024 and other control planes.
10027 vec_add1 (low_ports, this_low);
10028 vec_add1 (high_ports, this_hi);
10034 if (prefix_set == 0)
10036 errmsg ("<address>/<mask> not specified");
10042 errmsg ("VRF ID required, not specified");
10049 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10053 if (vec_len (low_ports) == 0)
10055 errmsg ("At least one port or port range required");
10059 M (IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, mp);
10061 mp->is_add = is_add;
10063 clib_memcpy (&mp->prefix, &prefix, sizeof (prefix));
10065 mp->number_of_ranges = vec_len (low_ports);
10067 clib_memcpy (mp->low_ports, low_ports, vec_len (low_ports));
10068 vec_free (low_ports);
10070 clib_memcpy (mp->high_ports, high_ports, vec_len (high_ports));
10071 vec_free (high_ports);
10073 mp->vrf_id = ntohl (vrf_id);
10081 api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
10083 unformat_input_t *input = vam->input;
10084 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
10085 u32 sw_if_index = ~0;
10087 u32 tcp_out_vrf_id = ~0, udp_out_vrf_id = ~0;
10088 u32 tcp_in_vrf_id = ~0, udp_in_vrf_id = ~0;
10092 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10094 if (unformat (input, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10096 else if (unformat (input, "sw_if_index %d", &sw_if_index))
10098 else if (unformat (input, "tcp-out-vrf %d", &tcp_out_vrf_id))
10100 else if (unformat (input, "udp-out-vrf %d", &udp_out_vrf_id))
10102 else if (unformat (input, "tcp-in-vrf %d", &tcp_in_vrf_id))
10104 else if (unformat (input, "udp-in-vrf %d", &udp_in_vrf_id))
10106 else if (unformat (input, "del"))
10112 if (sw_if_index == ~0)
10114 errmsg ("Interface required but not specified");
10120 errmsg ("VRF ID required but not specified");
10124 if (tcp_out_vrf_id == 0
10125 || udp_out_vrf_id == 0 || tcp_in_vrf_id == 0 || udp_in_vrf_id == 0)
10128 ("VRF ID should not be default. Should be distinct VRF for this purpose.");
10132 /* Construct the API message */
10133 M (IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, mp);
10135 mp->sw_if_index = ntohl (sw_if_index);
10136 mp->is_add = is_add;
10137 mp->tcp_out_vrf_id = ntohl (tcp_out_vrf_id);
10138 mp->udp_out_vrf_id = ntohl (udp_out_vrf_id);
10139 mp->tcp_in_vrf_id = ntohl (tcp_in_vrf_id);
10140 mp->udp_in_vrf_id = ntohl (udp_in_vrf_id);
10145 /* Wait for a reply... */
10151 api_set_punt (vat_main_t * vam)
10153 unformat_input_t *i = vam->input;
10154 vl_api_address_family_t af;
10155 vl_api_set_punt_t *mp;
10161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10163 if (unformat (i, "%U", unformat_vl_api_address_family, &af))
10165 else if (unformat (i, "protocol %d", &protocol))
10167 else if (unformat (i, "port %d", &port))
10169 else if (unformat (i, "del"))
10173 clib_warning ("parse error '%U'", format_unformat_error, i);
10180 mp->is_add = (u8) is_add;
10181 mp->punt.type = PUNT_API_TYPE_L4;
10182 mp->punt.punt.l4.af = af;
10183 mp->punt.punt.l4.protocol = (u8) protocol;
10184 mp->punt.punt.l4.port = htons ((u16) port);
10192 api_delete_subif (vat_main_t * vam)
10194 unformat_input_t *i = vam->input;
10195 vl_api_delete_subif_t *mp;
10196 u32 sw_if_index = ~0;
10199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10201 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10203 if (unformat (i, "sw_if_index %d", &sw_if_index))
10209 if (sw_if_index == ~0)
10211 errmsg ("missing sw_if_index");
10215 /* Construct the API message */
10216 M (DELETE_SUBIF, mp);
10217 mp->sw_if_index = ntohl (sw_if_index);
10224 #define foreach_pbb_vtr_op \
10225 _("disable", L2_VTR_DISABLED) \
10226 _("pop", L2_VTR_POP_2) \
10227 _("push", L2_VTR_PUSH_2)
10230 api_l2_interface_pbb_tag_rewrite (vat_main_t * vam)
10232 unformat_input_t *i = vam->input;
10233 vl_api_l2_interface_pbb_tag_rewrite_t *mp;
10234 u32 sw_if_index = ~0, vtr_op = ~0;
10235 u16 outer_tag = ~0;
10236 u8 dmac[6], smac[6];
10237 u8 dmac_set = 0, smac_set = 0;
10243 /* Shut up coverity */
10244 clib_memset (dmac, 0, sizeof (dmac));
10245 clib_memset (smac, 0, sizeof (smac));
10247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10249 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10251 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10253 else if (unformat (i, "vtr_op %d", &vtr_op))
10255 #define _(n,v) else if (unformat(i, n)) {vtr_op = v;}
10258 else if (unformat (i, "translate_pbb_stag"))
10260 if (unformat (i, "%d", &tmp))
10262 vtr_op = L2_VTR_TRANSLATE_2_1;
10268 ("translate_pbb_stag operation requires outer tag definition");
10272 else if (unformat (i, "dmac %U", unformat_ethernet_address, dmac))
10274 else if (unformat (i, "smac %U", unformat_ethernet_address, smac))
10276 else if (unformat (i, "sid %d", &sid))
10278 else if (unformat (i, "vlanid %d", &tmp))
10282 clib_warning ("parse error '%U'", format_unformat_error, i);
10287 if ((sw_if_index == ~0) || (vtr_op == ~0))
10289 errmsg ("missing sw_if_index or vtr operation");
10292 if (((vtr_op == L2_VTR_PUSH_2) || (vtr_op == L2_VTR_TRANSLATE_2_2))
10293 && ((dmac_set == 0) || (smac_set == 0) || (sid == ~0)))
10296 ("push and translate_qinq operations require dmac, smac, sid and optionally vlanid");
10300 M (L2_INTERFACE_PBB_TAG_REWRITE, mp);
10301 mp->sw_if_index = ntohl (sw_if_index);
10302 mp->vtr_op = ntohl (vtr_op);
10303 mp->outer_tag = ntohs (outer_tag);
10304 clib_memcpy (mp->b_dmac, dmac, sizeof (dmac));
10305 clib_memcpy (mp->b_smac, smac, sizeof (smac));
10306 mp->b_vlanid = ntohs (vlanid);
10307 mp->i_sid = ntohl (sid);
10315 api_sw_interface_tag_add_del (vat_main_t * vam)
10317 unformat_input_t *i = vam->input;
10318 vl_api_sw_interface_tag_add_del_t *mp;
10319 u32 sw_if_index = ~0;
10324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10326 if (unformat (i, "tag %s", &tag))
10328 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10330 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10332 else if (unformat (i, "del"))
10338 if (sw_if_index == ~0)
10340 errmsg ("missing interface name or sw_if_index");
10344 if (enable && (tag == 0))
10346 errmsg ("no tag specified");
10350 /* Construct the API message */
10351 M (SW_INTERFACE_TAG_ADD_DEL, mp);
10352 mp->sw_if_index = ntohl (sw_if_index);
10353 mp->is_add = enable;
10355 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
10364 api_sw_interface_add_del_mac_address (vat_main_t * vam)
10366 unformat_input_t *i = vam->input;
10367 vl_api_mac_address_t mac = { 0 };
10368 vl_api_sw_interface_add_del_mac_address_t *mp;
10369 u32 sw_if_index = ~0;
10374 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10376 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10378 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10380 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
10382 else if (unformat (i, "del"))
10388 if (sw_if_index == ~0)
10390 errmsg ("missing interface name or sw_if_index");
10396 errmsg ("missing MAC address");
10400 /* Construct the API message */
10401 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
10402 mp->sw_if_index = ntohl (sw_if_index);
10403 mp->is_add = is_add;
10404 clib_memcpy (&mp->addr, &mac, sizeof (mac));
10411 static void vl_api_l2_xconnect_details_t_handler
10412 (vl_api_l2_xconnect_details_t * mp)
10414 vat_main_t *vam = &vat_main;
10416 print (vam->ofp, "%15d%15d",
10417 ntohl (mp->rx_sw_if_index), ntohl (mp->tx_sw_if_index));
10420 static void vl_api_l2_xconnect_details_t_handler_json
10421 (vl_api_l2_xconnect_details_t * mp)
10423 vat_main_t *vam = &vat_main;
10424 vat_json_node_t *node = NULL;
10426 if (VAT_JSON_ARRAY != vam->json_tree.type)
10428 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10429 vat_json_init_array (&vam->json_tree);
10431 node = vat_json_array_add (&vam->json_tree);
10433 vat_json_init_object (node);
10434 vat_json_object_add_uint (node, "rx_sw_if_index",
10435 ntohl (mp->rx_sw_if_index));
10436 vat_json_object_add_uint (node, "tx_sw_if_index",
10437 ntohl (mp->tx_sw_if_index));
10441 api_l2_xconnect_dump (vat_main_t * vam)
10443 vl_api_l2_xconnect_dump_t *mp;
10444 vl_api_control_ping_t *mp_ping;
10447 if (!vam->json_output)
10449 print (vam->ofp, "%15s%15s", "rx_sw_if_index", "tx_sw_if_index");
10452 M (L2_XCONNECT_DUMP, mp);
10456 /* Use a control ping for synchronization */
10457 MPING (CONTROL_PING, mp_ping);
10465 api_hw_interface_set_mtu (vat_main_t * vam)
10467 unformat_input_t *i = vam->input;
10468 vl_api_hw_interface_set_mtu_t *mp;
10469 u32 sw_if_index = ~0;
10473 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10475 if (unformat (i, "mtu %d", &mtu))
10477 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10479 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10485 if (sw_if_index == ~0)
10487 errmsg ("missing interface name or sw_if_index");
10493 errmsg ("no mtu specified");
10497 /* Construct the API message */
10498 M (HW_INTERFACE_SET_MTU, mp);
10499 mp->sw_if_index = ntohl (sw_if_index);
10500 mp->mtu = ntohs ((u16) mtu);
10508 api_tcp_configure_src_addresses (vat_main_t * vam)
10510 vl_api_tcp_configure_src_addresses_t *mp;
10511 unformat_input_t *i = vam->input;
10512 vl_api_address_t first, last;
10517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10519 if (unformat (i, "%U - %U",
10520 unformat_vl_api_address, &first,
10521 unformat_vl_api_address, &last))
10525 errmsg ("one range per message (range already set)");
10530 else if (unformat (i, "vrf %d", &vrf_id))
10536 if (range_set == 0)
10538 errmsg ("address range not set");
10542 M (TCP_CONFIGURE_SRC_ADDRESSES, mp);
10544 mp->vrf_id = ntohl (vrf_id);
10545 clib_memcpy (&mp->first_address, &first, sizeof (first));
10546 clib_memcpy (&mp->last_address, &last, sizeof (last));
10553 static void vl_api_app_namespace_add_del_reply_t_handler
10554 (vl_api_app_namespace_add_del_reply_t * mp)
10556 vat_main_t *vam = &vat_main;
10557 i32 retval = ntohl (mp->retval);
10558 if (vam->async_mode)
10560 vam->async_errors += (retval < 0);
10564 vam->retval = retval;
10566 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
10567 vam->result_ready = 1;
10571 static void vl_api_app_namespace_add_del_reply_t_handler_json
10572 (vl_api_app_namespace_add_del_reply_t * mp)
10574 vat_main_t *vam = &vat_main;
10575 vat_json_node_t node;
10577 vat_json_init_object (&node);
10578 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
10579 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
10581 vat_json_print (vam->ofp, &node);
10582 vat_json_free (&node);
10584 vam->retval = ntohl (mp->retval);
10585 vam->result_ready = 1;
10589 api_app_namespace_add_del (vat_main_t * vam)
10591 vl_api_app_namespace_add_del_t *mp;
10592 unformat_input_t *i = vam->input;
10593 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
10594 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
10598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10600 if (unformat (i, "id %_%v%_", &ns_id))
10602 else if (unformat (i, "secret %lu", &secret))
10604 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10605 sw_if_index_set = 1;
10606 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
10608 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
10613 if (!ns_id || !secret_set || !sw_if_index_set)
10615 errmsg ("namespace id, secret and sw_if_index must be set");
10618 if (vec_len (ns_id) > 64)
10620 errmsg ("namespace id too long");
10623 M (APP_NAMESPACE_ADD_DEL, mp);
10625 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
10626 mp->secret = clib_host_to_net_u64 (secret);
10627 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
10628 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
10629 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
10637 api_sock_init_shm (vat_main_t * vam)
10639 #if VPP_API_TEST_BUILTIN == 0
10640 unformat_input_t *i = vam->input;
10641 vl_api_shm_elem_config_t *config = 0;
10642 u64 size = 64 << 20;
10645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10647 if (unformat (i, "size %U", unformat_memory_size, &size))
10654 * Canned custom ring allocator config.
10655 * Should probably parse all of this
10657 vec_validate (config, 6);
10658 config[0].type = VL_API_VLIB_RING;
10659 config[0].size = 256;
10660 config[0].count = 32;
10662 config[1].type = VL_API_VLIB_RING;
10663 config[1].size = 1024;
10664 config[1].count = 16;
10666 config[2].type = VL_API_VLIB_RING;
10667 config[2].size = 4096;
10668 config[2].count = 2;
10670 config[3].type = VL_API_CLIENT_RING;
10671 config[3].size = 256;
10672 config[3].count = 32;
10674 config[4].type = VL_API_CLIENT_RING;
10675 config[4].size = 1024;
10676 config[4].count = 16;
10678 config[5].type = VL_API_CLIENT_RING;
10679 config[5].size = 4096;
10680 config[5].count = 2;
10682 config[6].type = VL_API_QUEUE;
10683 config[6].count = 128;
10684 config[6].size = sizeof (uword);
10686 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
10688 vam->client_index_invalid = 1;
10696 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
10698 vat_main_t *vam = &vat_main;
10699 fib_prefix_t lcl, rmt;
10701 ip_prefix_decode (&mp->lcl, &lcl);
10702 ip_prefix_decode (&mp->rmt, &rmt);
10704 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
10707 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
10708 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
10709 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
10710 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
10711 &rmt.fp_addr.ip4, rmt.fp_len,
10712 clib_net_to_host_u16 (mp->rmt_port),
10713 clib_net_to_host_u32 (mp->action_index), mp->tag);
10718 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
10719 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
10720 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
10721 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
10722 &rmt.fp_addr.ip6, rmt.fp_len,
10723 clib_net_to_host_u16 (mp->rmt_port),
10724 clib_net_to_host_u32 (mp->action_index), mp->tag);
10729 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
10732 vat_main_t *vam = &vat_main;
10733 vat_json_node_t *node = NULL;
10734 struct in6_addr ip6;
10735 struct in_addr ip4;
10737 fib_prefix_t lcl, rmt;
10739 ip_prefix_decode (&mp->lcl, &lcl);
10740 ip_prefix_decode (&mp->rmt, &rmt);
10742 if (VAT_JSON_ARRAY != vam->json_tree.type)
10744 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
10745 vat_json_init_array (&vam->json_tree);
10747 node = vat_json_array_add (&vam->json_tree);
10748 vat_json_init_object (node);
10750 vat_json_object_add_uint (node, "appns_index",
10751 clib_net_to_host_u32 (mp->appns_index));
10752 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
10753 vat_json_object_add_uint (node, "scope", mp->scope);
10754 vat_json_object_add_uint (node, "action_index",
10755 clib_net_to_host_u32 (mp->action_index));
10756 vat_json_object_add_uint (node, "lcl_port",
10757 clib_net_to_host_u16 (mp->lcl_port));
10758 vat_json_object_add_uint (node, "rmt_port",
10759 clib_net_to_host_u16 (mp->rmt_port));
10760 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
10761 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
10762 vat_json_object_add_string_copy (node, "tag", mp->tag);
10763 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
10765 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
10766 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
10767 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
10768 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
10772 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
10773 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
10774 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
10775 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
10780 api_session_rule_add_del (vat_main_t * vam)
10782 vl_api_session_rule_add_del_t *mp;
10783 unformat_input_t *i = vam->input;
10784 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
10785 u32 appns_index = 0, scope = 0;
10786 ip4_address_t lcl_ip4, rmt_ip4;
10787 ip6_address_t lcl_ip6, rmt_ip6;
10788 u8 is_ip4 = 1, conn_set = 0;
10789 u8 is_add = 1, *tag = 0;
10791 fib_prefix_t lcl, rmt;
10793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10795 if (unformat (i, "del"))
10797 else if (unformat (i, "add"))
10799 else if (unformat (i, "proto tcp"))
10801 else if (unformat (i, "proto udp"))
10803 else if (unformat (i, "appns %d", &appns_index))
10805 else if (unformat (i, "scope %d", &scope))
10807 else if (unformat (i, "tag %_%v%_", &tag))
10811 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
10812 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
10820 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
10821 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
10827 else if (unformat (i, "action %d", &action))
10832 if (proto == ~0 || !conn_set || action == ~0)
10834 errmsg ("transport proto, connection and action must be set");
10840 errmsg ("scope should be 0-3");
10844 M (SESSION_RULE_ADD_DEL, mp);
10846 clib_memset (&lcl, 0, sizeof (lcl));
10847 clib_memset (&rmt, 0, sizeof (rmt));
10850 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
10851 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
10852 lcl.fp_len = lcl_plen;
10853 rmt.fp_len = rmt_plen;
10857 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
10858 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
10859 lcl.fp_len = lcl_plen;
10860 rmt.fp_len = rmt_plen;
10864 ip_prefix_encode (&lcl, &mp->lcl);
10865 ip_prefix_encode (&rmt, &mp->rmt);
10866 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
10867 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
10868 mp->transport_proto =
10869 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
10870 mp->action_index = clib_host_to_net_u32 (action);
10871 mp->appns_index = clib_host_to_net_u32 (appns_index);
10873 mp->is_add = is_add;
10876 clib_memcpy (mp->tag, tag, vec_len (tag));
10886 api_session_rules_dump (vat_main_t * vam)
10888 vl_api_session_rules_dump_t *mp;
10889 vl_api_control_ping_t *mp_ping;
10892 if (!vam->json_output)
10894 print (vam->ofp, "%=20s", "Session Rules");
10897 M (SESSION_RULES_DUMP, mp);
10901 /* Use a control ping for synchronization */
10902 MPING (CONTROL_PING, mp_ping);
10905 /* Wait for a reply... */
10911 api_ip_container_proxy_add_del (vat_main_t * vam)
10913 vl_api_ip_container_proxy_add_del_t *mp;
10914 unformat_input_t *i = vam->input;
10915 u32 sw_if_index = ~0;
10916 vl_api_prefix_t pfx = { };
10920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10922 if (unformat (i, "del"))
10924 else if (unformat (i, "add"))
10926 if (unformat (i, "%U", unformat_vl_api_prefix, &pfx))
10928 else if (unformat (i, "sw_if_index %u", &sw_if_index))
10933 if (sw_if_index == ~0 || pfx.len == 0)
10935 errmsg ("address and sw_if_index must be set");
10939 M (IP_CONTAINER_PROXY_ADD_DEL, mp);
10941 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
10942 mp->is_add = is_add;
10943 clib_memcpy (&mp->pfx, &pfx, sizeof (pfx));
10951 api_qos_record_enable_disable (vat_main_t * vam)
10953 unformat_input_t *i = vam->input;
10954 vl_api_qos_record_enable_disable_t *mp;
10955 u32 sw_if_index, qs = 0xff;
10956 u8 sw_if_index_set = 0;
10960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
10962 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
10963 sw_if_index_set = 1;
10964 else if (unformat (i, "sw_if_index %d", &sw_if_index))
10965 sw_if_index_set = 1;
10966 else if (unformat (i, "%U", unformat_qos_source, &qs))
10968 else if (unformat (i, "disable"))
10972 clib_warning ("parse error '%U'", format_unformat_error, i);
10977 if (sw_if_index_set == 0)
10979 errmsg ("missing interface name or sw_if_index");
10984 errmsg ("input location must be specified");
10988 M (QOS_RECORD_ENABLE_DISABLE, mp);
10990 mp->record.sw_if_index = ntohl (sw_if_index);
10991 mp->record.input_source = qs;
10992 mp->enable = enable;
11001 q_or_quit (vat_main_t * vam)
11003 #if VPP_API_TEST_BUILTIN == 0
11004 longjmp (vam->jump_buf, 1);
11006 return 0; /* not so much */
11010 q (vat_main_t * vam)
11012 return q_or_quit (vam);
11016 quit (vat_main_t * vam)
11018 return q_or_quit (vam);
11022 comment (vat_main_t * vam)
11028 elog_save (vat_main_t * vam)
11030 #if VPP_API_TEST_BUILTIN == 0
11031 elog_main_t *em = &vam->elog_main;
11032 unformat_input_t *i = vam->input;
11033 char *file, *chroot_file;
11034 clib_error_t *error;
11036 if (!unformat (i, "%s", &file))
11038 errmsg ("expected file name, got `%U'", format_unformat_error, i);
11042 /* It's fairly hard to get "../oopsie" through unformat; just in case */
11043 if (strstr (file, "..") || index (file, '/'))
11045 errmsg ("illegal characters in filename '%s'", file);
11049 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
11053 errmsg ("Saving %wd of %wd events to %s",
11054 elog_n_events_in_buffer (em),
11055 elog_buffer_capacity (em), chroot_file);
11057 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
11058 vec_free (chroot_file);
11061 clib_error_report (error);
11063 errmsg ("Use the vpp event loger...");
11070 elog_setup (vat_main_t * vam)
11072 #if VPP_API_TEST_BUILTIN == 0
11073 elog_main_t *em = &vam->elog_main;
11074 unformat_input_t *i = vam->input;
11075 u32 nevents = 128 << 10;
11077 (void) unformat (i, "nevents %d", &nevents);
11079 elog_init (em, nevents);
11080 vl_api_set_elog_main (em);
11081 vl_api_set_elog_trace_api_messages (1);
11082 errmsg ("Event logger initialized with %u events", nevents);
11084 errmsg ("Use the vpp event loger...");
11090 elog_enable (vat_main_t * vam)
11092 #if VPP_API_TEST_BUILTIN == 0
11093 elog_main_t *em = &vam->elog_main;
11095 elog_enable_disable (em, 1 /* enable */ );
11096 vl_api_set_elog_trace_api_messages (1);
11097 errmsg ("Event logger enabled...");
11099 errmsg ("Use the vpp event loger...");
11105 elog_disable (vat_main_t * vam)
11107 #if VPP_API_TEST_BUILTIN == 0
11108 elog_main_t *em = &vam->elog_main;
11110 elog_enable_disable (em, 0 /* enable */ );
11111 vl_api_set_elog_trace_api_messages (1);
11112 errmsg ("Event logger disabled...");
11114 errmsg ("Use the vpp event loger...");
11120 statseg (vat_main_t * vam)
11122 ssvm_private_t *ssvmp = &vam->stat_segment;
11123 ssvm_shared_header_t *shared_header = ssvmp->sh;
11124 vlib_counter_t **counters;
11125 u64 thread0_index1_packets;
11126 u64 thread0_index1_bytes;
11127 f64 vector_rate, input_rate;
11130 uword *counter_vector_by_name;
11131 if (vam->stat_segment_lockp == 0)
11133 errmsg ("Stat segment not mapped...");
11137 /* look up "/if/rx for sw_if_index 1 as a test */
11139 clib_spinlock_lock (vam->stat_segment_lockp);
11141 counter_vector_by_name = (uword *) shared_header->opaque[1];
11143 p = hash_get_mem (counter_vector_by_name, "/if/rx");
11146 clib_spinlock_unlock (vam->stat_segment_lockp);
11147 errmsg ("/if/tx not found?");
11151 /* Fish per-thread vector of combined counters from shared memory */
11152 counters = (vlib_counter_t **) p[0];
11154 if (vec_len (counters[0]) < 2)
11156 clib_spinlock_unlock (vam->stat_segment_lockp);
11157 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
11161 /* Read thread 0 sw_if_index 1 counter */
11162 thread0_index1_packets = counters[0][1].packets;
11163 thread0_index1_bytes = counters[0][1].bytes;
11165 p = hash_get_mem (counter_vector_by_name, "vector_rate");
11168 clib_spinlock_unlock (vam->stat_segment_lockp);
11169 errmsg ("vector_rate not found?");
11173 vector_rate = *(f64 *) (p[0]);
11174 p = hash_get_mem (counter_vector_by_name, "input_rate");
11177 clib_spinlock_unlock (vam->stat_segment_lockp);
11178 errmsg ("input_rate not found?");
11181 input_rate = *(f64 *) (p[0]);
11183 clib_spinlock_unlock (vam->stat_segment_lockp);
11185 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
11186 vector_rate, input_rate);
11187 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
11188 thread0_index1_packets, thread0_index1_bytes);
11194 cmd_cmp (void *a1, void *a2)
11199 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
11203 help (vat_main_t * vam)
11208 unformat_input_t *i = vam->input;
11211 if (unformat (i, "%s", &name))
11215 vec_add1 (name, 0);
11217 hs = hash_get_mem (vam->help_by_name, name);
11219 print (vam->ofp, "usage: %s %s", name, hs[0]);
11221 print (vam->ofp, "No such msg / command '%s'", name);
11226 print (vam->ofp, "Help is available for the following:");
11229 hash_foreach_pair (p, vam->function_by_name,
11231 vec_add1 (cmds, (u8 *)(p->key));
11235 vec_sort_with_function (cmds, cmd_cmp);
11237 for (j = 0; j < vec_len (cmds); j++)
11238 print (vam->ofp, "%s", cmds[j]);
11245 set (vat_main_t * vam)
11247 u8 *name = 0, *value = 0;
11248 unformat_input_t *i = vam->input;
11250 if (unformat (i, "%s", &name))
11252 /* The input buffer is a vector, not a string. */
11253 value = vec_dup (i->buffer);
11254 vec_delete (value, i->index, 0);
11255 /* Almost certainly has a trailing newline */
11256 if (value[vec_len (value) - 1] == '\n')
11257 value[vec_len (value) - 1] = 0;
11258 /* Make sure it's a proper string, one way or the other */
11259 vec_add1 (value, 0);
11260 (void) clib_macro_set_value (&vam->macro_main,
11261 (char *) name, (char *) value);
11264 errmsg ("usage: set <name> <value>");
11272 unset (vat_main_t * vam)
11276 if (unformat (vam->input, "%s", &name))
11277 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
11278 errmsg ("unset: %s wasn't set", name);
11291 macro_sort_cmp (void *a1, void *a2)
11293 macro_sort_t *s1 = a1;
11294 macro_sort_t *s2 = a2;
11296 return strcmp ((char *) (s1->name), (char *) (s2->name));
11300 dump_macro_table (vat_main_t * vam)
11302 macro_sort_t *sort_me = 0, *sm;
11307 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
11309 vec_add2 (sort_me, sm, 1);
11310 sm->name = (u8 *)(p->key);
11311 sm->value = (u8 *) (p->value[0]);
11315 vec_sort_with_function (sort_me, macro_sort_cmp);
11317 if (vec_len (sort_me))
11318 print (vam->ofp, "%-15s%s", "Name", "Value");
11320 print (vam->ofp, "The macro table is empty...");
11322 for (i = 0; i < vec_len (sort_me); i++)
11323 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
11328 dump_node_table (vat_main_t * vam)
11331 vlib_node_t *node, *next_node;
11333 if (vec_len (vam->graph_nodes) == 0)
11335 print (vam->ofp, "Node table empty, issue get_node_graph...");
11339 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
11341 node = vam->graph_nodes[0][i];
11342 print (vam->ofp, "[%d] %s", i, node->name);
11343 for (j = 0; j < vec_len (node->next_nodes); j++)
11345 if (node->next_nodes[j] != ~0)
11347 next_node = vam->graph_nodes[0][node->next_nodes[j]];
11348 print (vam->ofp, " [%d] %s", j, next_node->name);
11356 value_sort_cmp (void *a1, void *a2)
11358 name_sort_t *n1 = a1;
11359 name_sort_t *n2 = a2;
11361 if (n1->value < n2->value)
11363 if (n1->value > n2->value)
11370 dump_msg_api_table (vat_main_t * vam)
11372 api_main_t *am = vlibapi_get_main ();
11373 name_sort_t *nses = 0, *ns;
11378 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
11380 vec_add2 (nses, ns, 1);
11381 ns->name = (u8 *)(hp->key);
11382 ns->value = (u32) hp->value[0];
11386 vec_sort_with_function (nses, value_sort_cmp);
11388 for (i = 0; i < vec_len (nses); i++)
11389 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
11395 get_msg_id (vat_main_t * vam)
11400 if (unformat (vam->input, "%s", &name_and_crc))
11402 message_index = vl_msg_api_get_msg_index (name_and_crc);
11403 if (message_index == ~0)
11405 print (vam->ofp, " '%s' not found", name_and_crc);
11408 print (vam->ofp, " '%s' has message index %d",
11409 name_and_crc, message_index);
11412 errmsg ("name_and_crc required...");
11417 search_node_table (vat_main_t * vam)
11419 unformat_input_t *line_input = vam->input;
11422 vlib_node_t *node, *next_node;
11425 if (vam->graph_node_index_by_name == 0)
11427 print (vam->ofp, "Node table empty, issue get_node_graph...");
11431 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
11433 if (unformat (line_input, "%s", &node_to_find))
11435 vec_add1 (node_to_find, 0);
11436 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
11439 print (vam->ofp, "%s not found...", node_to_find);
11442 node = vam->graph_nodes[0][p[0]];
11443 print (vam->ofp, "[%d] %s", p[0], node->name);
11444 for (j = 0; j < vec_len (node->next_nodes); j++)
11446 if (node->next_nodes[j] != ~0)
11448 next_node = vam->graph_nodes[0][node->next_nodes[j]];
11449 print (vam->ofp, " [%d] %s", j, next_node->name);
11456 clib_warning ("parse error '%U'", format_unformat_error,
11462 vec_free (node_to_find);
11471 script (vat_main_t * vam)
11473 #if (VPP_API_TEST_BUILTIN==0)
11475 char *save_current_file;
11476 unformat_input_t save_input;
11477 jmp_buf save_jump_buf;
11478 u32 save_line_number;
11480 FILE *new_fp, *save_ifp;
11482 if (unformat (vam->input, "%s", &s))
11484 new_fp = fopen ((char *) s, "r");
11487 errmsg ("Couldn't open script file %s", s);
11494 errmsg ("Missing script name");
11498 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
11499 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
11500 save_ifp = vam->ifp;
11501 save_line_number = vam->input_line_number;
11502 save_current_file = (char *) vam->current_file;
11504 vam->input_line_number = 0;
11506 vam->current_file = s;
11509 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
11510 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
11511 vam->ifp = save_ifp;
11512 vam->input_line_number = save_line_number;
11513 vam->current_file = (u8 *) save_current_file;
11518 clib_warning ("use the exec command...");
11524 echo (vat_main_t * vam)
11526 print (vam->ofp, "%v", vam->input->buffer);
11530 /* List of API message constructors, CLI names map to api_xxx */
11531 #define foreach_vpe_api_msg \
11532 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
11533 _(sw_interface_dump,"") \
11534 _(sw_interface_set_flags, \
11535 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
11536 _(sw_interface_add_del_address, \
11537 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
11538 _(sw_interface_set_rx_mode, \
11539 "<intfc> | sw_if_index <id> [queue <id>] <polling | interrupt | adaptive>") \
11540 _(sw_interface_set_rx_placement, \
11541 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
11542 _(sw_interface_rx_placement_dump, \
11543 "[<intfc> | sw_if_index <id>]") \
11544 _(sw_interface_set_table, \
11545 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
11546 _(sw_interface_set_mpls_enable, \
11547 "<intfc> | sw_if_index [disable | dis]") \
11548 _(sw_interface_set_vpath, \
11549 "<intfc> | sw_if_index <id> enable | disable") \
11550 _(sw_interface_set_l2_xconnect, \
11551 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11552 "enable | disable") \
11553 _(sw_interface_set_l2_bridge, \
11554 "{<intfc> | sw_if_index <id>} bd_id <bridge-domain-id>\n" \
11555 "[shg <split-horizon-group>] [bvi]\n" \
11556 "enable | disable") \
11557 _(bridge_domain_set_mac_age, "bd_id <bridge-domain-id> mac-age 0-255") \
11558 _(bridge_domain_add_del, \
11559 "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") \
11560 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
11562 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
11563 _(l2fib_flush_bd, "bd_id <bridge-domain-id>") \
11564 _(l2fib_flush_int, "<intfc> | sw_if_index <id>") \
11566 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11568 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11570 "id <num> [hw-addr <mac-addr>] [host-if-name <name>] [host-ns <name>] [num-rx-queues <num>] [rx-ring-size <num>] [tx-ring-size <num>] [host-bridge <name>] [host-mac-addr <mac-addr>] [host-ip4-addr <ip4addr/mask>] [host-ip6-addr <ip6addr/mask>] [host-mtu-size <mtu>] [gso | no-gso | csum-offload | gro-coalesce] [persist] [attach] [tun] [packed] [in-order]") \
11572 "<vpp-if-name> | sw_if_index <id>") \
11573 _(sw_interface_tap_v2_dump, "") \
11574 _(virtio_pci_create_v2, \
11575 "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]") \
11576 _(virtio_pci_delete, \
11577 "<vpp-if-name> | sw_if_index <id>") \
11578 _(sw_interface_virtio_pci_dump, "") \
11580 "[hw-addr <mac-addr>] {round-robin | active-backup | " \
11581 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
11584 "[hw-addr <mac-addr>] {mode round-robin | active-backup | " \
11585 "broadcast | {lacp | xor} [load-balance { l2 | l23 | l34 }]} " \
11586 "[id <if-id>] [gso]") \
11588 "<vpp-if-name> | sw_if_index <id>") \
11589 _(bond_add_member, \
11590 "sw_if_index <n> bond <sw_if_index> [is_passive] [is_long_timeout]") \
11591 _(bond_detach_member, \
11592 "sw_if_index <n>") \
11593 _(sw_interface_set_bond_weight, "<intfc> | sw_if_index <nn> weight <value>") \
11594 _(sw_bond_interface_dump, "<intfc> | sw_if_index <nn>") \
11595 _(sw_member_interface_dump, \
11596 "<vpp-if-name> | sw_if_index <id>") \
11597 _(ip_table_add_del, \
11598 "table <n> [ipv6] [add | del]\n") \
11599 _(ip_route_add_del, \
11600 "<addr>/<mask> via <<addr>|<intfc>|sw_if_index <id>|via-label <n>>\n" \
11601 "[table-id <n>] [<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n"\
11602 "[weight <n>] [drop] [local] [classify <n>] [out-label <n>]\n" \
11603 "[multipath] [count <n>] [del]") \
11604 _(ip_mroute_add_del, \
11605 "<src> <grp>/<mask> [table-id <n>]\n" \
11606 "[<intfc> | sw_if_index <id>] [local] [del]") \
11607 _(mpls_table_add_del, \
11608 "table <n> [add | del]\n") \
11609 _(mpls_route_add_del, \
11610 "<label> <eos> via <addr | next-hop-table <n> | via-label <n> |\n" \
11611 "lookup-ip4-table <n> | lookup-in-ip6-table <n> |\n" \
11612 "l2-input-on <intfc> | l2-input-on sw_if_index <id>>\n" \
11613 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>] [weight <n>]\n" \
11614 "[drop] [local] [classify <n>] [out-label <n>] [multipath]\n" \
11615 "[count <n>] [del]") \
11616 _(mpls_ip_bind_unbind, \
11617 "<label> <addr/len>") \
11618 _(mpls_tunnel_add_del, \
11619 "[add | del <intfc | sw_if_index <id>>] via <addr | via-label <n>>\n" \
11620 "[<intfc> | sw_if_index <id> | next-hop-table <id>]\n" \
11621 "[l2-only] [out-label <n>]") \
11622 _(sr_mpls_policy_add, \
11623 "bsid <id> [weight <n>] [spray] next <sid> [next <sid>]") \
11624 _(sr_mpls_policy_del, \
11626 _(sw_interface_set_unnumbered, \
11627 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
11628 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
11629 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
11630 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
11631 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
11632 "[outer_vlan_id_any][inner_vlan_id_any]") \
11633 _(ip_table_replace_begin, "table <n> [ipv6]") \
11634 _(ip_table_flush, "table <n> [ipv6]") \
11635 _(ip_table_replace_end, "table <n> [ipv6]") \
11636 _(set_ip_flow_hash, \
11637 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
11638 _(sw_interface_ip6_enable_disable, \
11639 "<intfc> | sw_if_index <id> enable | disable") \
11640 _(l2_patch_add_del, \
11641 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11642 "enable | disable") \
11643 _(sr_localsid_add_del, \
11644 "(del) address <addr> next_hop <addr> behavior <beh>\n" \
11645 "fib-table <num> (end.psp) sw_if_index <num>") \
11646 _(get_node_index, "node <node-name") \
11647 _(add_node_next, "node <node-name> next <next-node-name>") \
11648 _(l2_fib_clear_table, "") \
11649 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
11650 _(l2_interface_vlan_tag_rewrite, \
11651 "<intfc> | sw_if_index <nn> \n" \
11652 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
11653 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
11654 _(create_vhost_user_if, \
11655 "socket <filename> [server] [renumber <dev_instance>] " \
11656 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
11657 "[mac <mac_address>] [packed]") \
11658 _(modify_vhost_user_if, \
11659 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11660 "[server] [renumber <dev_instance>] [gso] [packed]") \
11661 _(create_vhost_user_if_v2, \
11662 "socket <filename> [server] [renumber <dev_instance>] " \
11663 "[disable_mrg_rxbuf] [disable_indirect_desc] [gso] " \
11664 "[mac <mac_address>] [packed] [event-idx]") \
11665 _(modify_vhost_user_if_v2, \
11666 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11667 "[server] [renumber <dev_instance>] [gso] [packed] [event-idx]")\
11668 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
11669 _(sw_interface_vhost_user_dump, "<intfc> | sw_if_index <nn>") \
11670 _(show_version, "") \
11671 _(show_threads, "") \
11672 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
11673 _(interface_name_renumber, \
11674 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
11675 _(want_l2_macs_events, "[disable] [learn-limit <n>] [scan-delay <n>] [max-entries <n>]") \
11676 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
11677 _(ip_dump, "ipv4 | ipv6") \
11678 _(ipsec_spd_add_del, "spd_id <n> [del]") \
11679 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
11681 _(ipsec_sad_entry_add_del, "sad_id <n> spi <n> crypto_alg <alg>\n" \
11682 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
11683 " integ_alg <alg> integ_key <hex>") \
11684 _(ipsec_spd_entry_add_del, "spd_id <n> priority <n> action <action>\n" \
11685 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
11686 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
11687 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" ) \
11688 _(ipsec_sa_dump, "[sa_id <n>]") \
11689 _(delete_loopback,"sw_if_index <nn>") \
11690 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
11691 _(bd_ip_mac_flush, "bd_id <bridge-domain-id>") \
11692 _(bd_ip_mac_dump, "[bd_id] <bridge-domain-id>") \
11693 _(want_interface_events, "enable|disable") \
11694 _(get_first_msg_id, "client <name>") \
11695 _(get_node_graph, " ") \
11696 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
11697 _(ioam_enable, "[trace] [pow] [ppc <encap|decap>]") \
11698 _(ioam_disable, "") \
11699 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
11700 _(af_packet_delete, "name <host interface name>") \
11701 _(af_packet_dump, "") \
11702 _(mpls_tunnel_dump, "tunnel_index <tunnel-id>") \
11703 _(mpls_table_dump, "") \
11704 _(mpls_route_dump, "table-id <ID>") \
11705 _(sw_interface_span_enable_disable, "[l2] [src <intfc> | src_sw_if_index <id>] [disable | [[dst <intfc> | dst_sw_if_index <id>] [both|rx|tx]]]") \
11706 _(sw_interface_span_dump, "[l2]") \
11707 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
11708 _(ip_source_and_port_range_check_add_del, \
11709 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
11710 _(ip_source_and_port_range_check_interface_add_del, \
11711 "<intf> | sw_if_index <nn> [tcp-out-vrf <id>] [tcp-in-vrf <id>]" \
11712 "[udp-in-vrf <id>] [udp-out-vrf <id>]") \
11713 _(delete_subif,"<intfc> | sw_if_index <nn>") \
11714 _(l2_interface_pbb_tag_rewrite, \
11715 "<intfc> | sw_if_index <nn> \n" \
11716 "[disable | push | pop | translate_pbb_stag <outer_tag>] \n" \
11717 "dmac <mac> smac <mac> sid <nn> [vlanid <nn>]") \
11718 _(set_punt, "protocol <l4-protocol> [ip <ver>] [port <l4-port>] [del]") \
11719 _(ip_table_dump, "") \
11720 _(ip_route_dump, "table-id [ip4|ip6]") \
11721 _(ip_mtable_dump, "") \
11722 _(ip_mroute_dump, "table-id [ip4|ip6]") \
11723 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
11725 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
11726 "mac <mac-address> [del]") \
11727 _(l2_xconnect_dump, "") \
11728 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
11729 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
11730 _(tcp_configure_src_addresses, "<ip4|6>first-<ip4|6>last [vrf <id>]") \
11731 _(sock_init_shm, "size <nnn>") \
11732 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
11733 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
11734 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
11735 _(session_rules_dump, "") \
11736 _(ip_container_proxy_add_del, "[add|del] <address> <sw_if_index>") \
11737 _(qos_record_enable_disable, "<record-source> <intfc> | sw_if_index <id> [disable]")
11739 /* List of command functions, CLI names map directly to functions */
11740 #define foreach_cli_function \
11741 _(comment, "usage: comment <ignore-rest-of-line>") \
11742 _(dump_interface_table, "usage: dump_interface_table") \
11743 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
11744 _(dump_ipv4_table, "usage: dump_ipv4_table") \
11745 _(dump_ipv6_table, "usage: dump_ipv6_table") \
11746 _(dump_macro_table, "usage: dump_macro_table ") \
11747 _(dump_node_table, "usage: dump_node_table") \
11748 _(dump_msg_api_table, "usage: dump_msg_api_table") \
11749 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
11750 _(elog_disable, "usage: elog_disable") \
11751 _(elog_enable, "usage: elog_enable") \
11752 _(elog_save, "usage: elog_save <filename>") \
11753 _(get_msg_id, "usage: get_msg_id name_and_crc") \
11754 _(echo, "usage: echo <message>") \
11755 _(exec, "usage: exec <vpe-debug-CLI-command>") \
11756 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
11757 _(help, "usage: help") \
11758 _(q, "usage: quit") \
11759 _(quit, "usage: quit") \
11760 _(search_node_table, "usage: search_node_table <name>...") \
11761 _(set, "usage: set <variable-name> <value>") \
11762 _(script, "usage: script <file-name>") \
11763 _(statseg, "usage: statseg") \
11764 _(unset, "usage: unset <variable-name>")
11767 static void vl_api_##n##_t_handler_uni \
11768 (vl_api_##n##_t * mp) \
11770 vat_main_t * vam = &vat_main; \
11771 if (vam->json_output) { \
11772 vl_api_##n##_t_handler_json(mp); \
11774 vl_api_##n##_t_handler(mp); \
11777 foreach_vpe_api_reply_msg;
11778 #if VPP_API_TEST_BUILTIN == 0
11779 foreach_standalone_reply_msg;
11784 vat_api_hookup (vat_main_t * vam)
11787 vl_msg_api_set_handlers(VL_API_##N, #n, \
11788 vl_api_##n##_t_handler_uni, \
11790 vl_api_##n##_t_endian, \
11791 vl_api_##n##_t_print, \
11792 sizeof(vl_api_##n##_t), 1);
11793 foreach_vpe_api_reply_msg;
11794 #if VPP_API_TEST_BUILTIN == 0
11795 foreach_standalone_reply_msg;
11799 #if (VPP_API_TEST_BUILTIN==0)
11800 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
11802 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
11804 vam->function_by_name = hash_create_string (0, sizeof (uword));
11806 vam->help_by_name = hash_create_string (0, sizeof (uword));
11809 /* API messages we can send */
11810 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
11811 foreach_vpe_api_msg;
11815 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11816 foreach_vpe_api_msg;
11819 /* CLI functions */
11820 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
11821 foreach_cli_function;
11825 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11826 foreach_cli_function;
11830 #if VPP_API_TEST_BUILTIN
11831 static clib_error_t *
11832 vat_api_hookup_shim (vlib_main_t * vm)
11834 vat_api_hookup (&vat_main);
11838 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
11842 * fd.io coding-style-patch-verification: ON
11845 * eval: (c-set-style "gnu")