2 *------------------------------------------------------------------
5 * Copyright (c) 2014-2020 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlib/pci/pci.h>
22 #include <vpp/api/types.h>
23 #include <vppinfra/socket.h>
24 #include <vlibapi/api.h>
25 #include <vlibmemory/api.h>
26 #include <vnet/ip/ip.h>
27 #include <vnet/ip-neighbor/ip_neighbor.h>
28 #include <vnet/ip/ip_types_api.h>
29 #include <vnet/l2/l2_input.h>
30 #include <vnet/udp/udp_local.h>
32 #include <vpp/api/vpe_msg_enum.h>
33 #include <vnet/l2/l2_classify.h>
34 #include <vnet/l2/l2_vtr.h>
35 #include <vnet/classify/in_out_acl.h>
36 #include <vnet/classify/policer_classify.h>
37 #include <vnet/classify/flow_classify.h>
38 #include <vnet/mpls/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
41 #include <vnet/ip/ip6_hop_by_hop.h>
42 #include <vnet/ip/ip_source_and_port_range_check.h>
43 #include <vnet/policer/xlate.h>
44 #include <vnet/span/span.h>
45 #include <vnet/policer/policer.h>
46 #include <vnet/policer/police.h>
47 #include <vnet/mfib/mfib_types.h>
48 #include <vnet/bonding/node.h>
49 #include <vnet/qos/qos_types.h>
50 #include <vnet/ethernet/ethernet_types_api.h>
51 #include <vnet/ip/ip_types_api.h>
52 #include "vat/json_format.h"
53 #include <vnet/ip/ip_types_api.h>
54 #include <vnet/ethernet/ethernet_types_api.h>
59 #define vl_typedefs /* define message structures */
60 #include <vpp/api/vpe_all_api_h.h>
63 /* declare message handlers for each api */
65 #define vl_endianfun /* define message structures */
66 #include <vpp/api/vpe_all_api_h.h>
69 /* instantiate all the print functions we know about */
70 #if VPP_API_TEST_BUILTIN == 0
71 #define vl_print(handle, ...)
73 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
76 #include <vpp/api/vpe_all_api_h.h>
79 #define __plugin_msg_base 0
80 #include <vlibapi/vat_helper_macros.h>
82 void vl_api_set_elog_main (elog_main_t * m);
83 int vl_api_set_elog_trace_api_messages (int enable);
85 #if VPP_API_TEST_BUILTIN == 0
95 vat_socket_connect (vat_main_t * vam)
98 api_main_t *am = vlibapi_get_main ();
99 vam->socket_client_main = &socket_client_main;
100 if ((rv = vl_socket_client_connect ((char *) vam->socket_name,
102 0 /* default socket rx, tx buffer */ )))
105 /* vpp expects the client index in network order */
106 vam->my_client_index = htonl (socket_client_main.client_index);
107 am->my_client_index = vam->my_client_index;
110 #else /* vpp built-in case, we don't do sockets... */
112 vat_socket_connect (vat_main_t * vam)
118 vl_socket_client_read (int wait)
124 vl_socket_client_write ()
130 vl_socket_client_msg_alloc (int nbytes)
138 vat_time_now (vat_main_t * vam)
140 #if VPP_API_TEST_BUILTIN
141 return vlib_time_now (vam->vlib_main);
143 return clib_time_now (&vam->clib_time);
148 errmsg (char *fmt, ...)
150 vat_main_t *vam = &vat_main;
155 s = va_format (0, fmt, &va);
160 #if VPP_API_TEST_BUILTIN
161 vlib_cli_output (vam->vlib_main, (char *) s);
164 if (vam->ifp != stdin)
165 fformat (vam->ofp, "%s(%d): \n", vam->current_file,
166 vam->input_line_number);
168 fformat (vam->ofp, "%s\n", (char *) s);
176 #if VPP_API_TEST_BUILTIN == 0
178 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
180 vat_main_t *vam = va_arg (*args, vat_main_t *);
181 u32 *result = va_arg (*args, u32 *);
185 if (!unformat (input, "%s", &if_name))
188 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
195 /* Parse an IP4 address %d.%d.%d.%d. */
197 unformat_ip4_address (unformat_input_t * input, va_list * args)
199 u8 *result = va_arg (*args, u8 *);
202 if (!unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
205 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
217 unformat_ethernet_address (unformat_input_t * input, va_list * args)
219 u8 *result = va_arg (*args, u8 *);
222 if (!unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
223 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
227 for (i = 0; i < 6; i++)
228 if (a[i] >= (1 << 8))
231 for (i = 0; i < 6; i++)
237 /* Returns ethernet type as an int in host byte order. */
239 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
242 u16 *result = va_arg (*args, u16 *);
246 if (unformat (input, "0x%x", &type) || unformat (input, "%d", &type))
248 if (type >= (1 << 16))
256 /* Parse an IP46 address. */
258 unformat_ip46_address (unformat_input_t * input, va_list * args)
260 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
261 ip46_type_t type = va_arg (*args, ip46_type_t);
262 if ((type != IP46_TYPE_IP6) &&
263 unformat (input, "%U", unformat_ip4_address, &ip46->ip4))
265 ip46_address_mask_ip4 (ip46);
268 else if ((type != IP46_TYPE_IP4) &&
269 unformat (input, "%U", unformat_ip6_address, &ip46->ip6))
276 /* Parse an IP6 address. */
278 unformat_ip6_address (unformat_input_t * input, va_list * args)
280 ip6_address_t *result = va_arg (*args, ip6_address_t *);
282 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
283 uword c, n_colon, double_colon_index;
285 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
286 double_colon_index = ARRAY_LEN (hex_quads);
287 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
290 if (c >= '0' && c <= '9')
292 else if (c >= 'a' && c <= 'f')
293 hex_digit = c + 10 - 'a';
294 else if (c >= 'A' && c <= 'F')
295 hex_digit = c + 10 - 'A';
296 else if (c == ':' && n_colon < 2)
300 unformat_put_input (input);
304 /* Too many hex quads. */
305 if (n_hex_quads >= ARRAY_LEN (hex_quads))
310 hex_quad = (hex_quad << 4) | hex_digit;
312 /* Hex quad must fit in 16 bits. */
313 if (n_hex_digits >= 4)
320 /* Save position of :: */
323 /* More than one :: ? */
324 if (double_colon_index < ARRAY_LEN (hex_quads))
326 double_colon_index = n_hex_quads;
329 if (n_colon > 0 && n_hex_digits > 0)
331 hex_quads[n_hex_quads++] = hex_quad;
337 if (n_hex_digits > 0)
338 hex_quads[n_hex_quads++] = hex_quad;
343 /* Expand :: to appropriate number of zero hex quads. */
344 if (double_colon_index < ARRAY_LEN (hex_quads))
346 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
348 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
349 hex_quads[n_zero + i] = hex_quads[i];
351 for (i = 0; i < n_zero; i++)
352 hex_quads[double_colon_index + i] = 0;
354 n_hex_quads = ARRAY_LEN (hex_quads);
357 /* Too few hex quads given. */
358 if (n_hex_quads < ARRAY_LEN (hex_quads))
361 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
362 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
369 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
371 u32 *r = va_arg (*args, u32 *);
374 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
375 foreach_ipsec_policy_action
383 format_ipsec_crypto_alg (u8 * s, va_list * args)
385 u32 i = va_arg (*args, u32);
390 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
391 foreach_ipsec_crypto_alg
394 return format (s, "unknown");
396 return format (s, "%s", t);
400 format_ipsec_integ_alg (u8 * s, va_list * args)
402 u32 i = va_arg (*args, u32);
407 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
408 foreach_ipsec_integ_alg
411 return format (s, "unknown");
413 return format (s, "%s", t);
416 #else /* VPP_API_TEST_BUILTIN == 1 */
418 api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
420 vat_main_t *vam __clib_unused = va_arg (*args, vat_main_t *);
421 vnet_main_t *vnm = vnet_get_main ();
422 u32 *result = va_arg (*args, u32 *);
424 return unformat (input, "%U", unformat_vnet_sw_interface, vnm, result);
427 #endif /* VPP_API_TEST_BUILTIN */
429 #if (VPP_API_TEST_BUILTIN==0)
431 static const char *mfib_flag_names[] = MFIB_ENTRY_NAMES_SHORT;
432 static const char *mfib_flag_long_names[] = MFIB_ENTRY_NAMES_LONG;
433 static const char *mfib_itf_flag_long_names[] = MFIB_ITF_NAMES_LONG;
434 static const char *mfib_itf_flag_names[] = MFIB_ITF_NAMES_SHORT;
437 unformat_mfib_itf_flags (unformat_input_t * input, va_list * args)
439 mfib_itf_flags_t old, *iflags = va_arg (*args, mfib_itf_flags_t *);
440 mfib_itf_attribute_t attr;
443 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
445 if (unformat (input, mfib_itf_flag_long_names[attr]))
446 *iflags |= (1 << attr);
448 FOR_EACH_MFIB_ITF_ATTRIBUTE (attr)
450 if (unformat (input, mfib_itf_flag_names[attr]))
451 *iflags |= (1 << attr);
454 return (old == *iflags ? 0 : 1);
458 unformat_mfib_entry_flags (unformat_input_t * input, va_list * args)
460 mfib_entry_flags_t old, *eflags = va_arg (*args, mfib_entry_flags_t *);
461 mfib_entry_attribute_t attr;
464 FOR_EACH_MFIB_ATTRIBUTE (attr)
466 if (unformat (input, mfib_flag_long_names[attr]))
467 *eflags |= (1 << attr);
469 FOR_EACH_MFIB_ATTRIBUTE (attr)
471 if (unformat (input, mfib_flag_names[attr]))
472 *eflags |= (1 << attr);
475 return (old == *eflags ? 0 : 1);
479 format_ip4_address (u8 * s, va_list * args)
481 u8 *a = va_arg (*args, u8 *);
482 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
486 format_ip6_address (u8 * s, va_list * args)
488 ip6_address_t *a = va_arg (*args, ip6_address_t *);
489 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
491 i_max_n_zero = ARRAY_LEN (a->as_u16);
493 i_first_zero = i_max_n_zero;
495 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
497 u32 is_zero = a->as_u16[i] == 0;
498 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
504 if ((!is_zero && n_zeros > max_n_zeros)
505 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
507 i_max_n_zero = i_first_zero;
508 max_n_zeros = n_zeros;
509 i_first_zero = ARRAY_LEN (a->as_u16);
514 last_double_colon = 0;
515 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
517 if (i == i_max_n_zero && max_n_zeros > 1)
519 s = format (s, "::");
520 i += max_n_zeros - 1;
521 last_double_colon = 1;
525 s = format (s, "%s%x",
526 (last_double_colon || i == 0) ? "" : ":",
527 clib_net_to_host_u16 (a->as_u16[i]));
528 last_double_colon = 0;
535 /* Format an IP46 address. */
537 format_ip46_address (u8 * s, va_list * args)
539 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
540 ip46_type_t type = va_arg (*args, ip46_type_t);
546 is_ip4 = ip46_address_is_ip4 (ip46);
557 format (s, "%U", format_ip4_address, &ip46->ip4) :
558 format (s, "%U", format_ip6_address, &ip46->ip6);
562 format_ethernet_address (u8 * s, va_list * args)
564 u8 *a = va_arg (*args, u8 *);
566 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
567 a[0], a[1], a[2], a[3], a[4], a[5]);
572 ip_set (ip46_address_t * dst, void *src, u8 is_ip4)
575 dst->ip4.as_u32 = ((ip4_address_t *) src)->as_u32;
577 clib_memcpy_fast (&dst->ip6, (ip6_address_t *) src,
578 sizeof (ip6_address_t));
582 static void vl_api_create_loopback_reply_t_handler
583 (vl_api_create_loopback_reply_t * mp)
585 vat_main_t *vam = &vat_main;
586 i32 retval = ntohl (mp->retval);
588 vam->retval = retval;
589 vam->regenerate_interface_table = 1;
590 vam->sw_if_index = ntohl (mp->sw_if_index);
591 vam->result_ready = 1;
594 static void vl_api_create_loopback_reply_t_handler_json
595 (vl_api_create_loopback_reply_t * mp)
597 vat_main_t *vam = &vat_main;
598 vat_json_node_t node;
600 vat_json_init_object (&node);
601 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
602 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
604 vat_json_print (vam->ofp, &node);
605 vat_json_free (&node);
606 vam->retval = ntohl (mp->retval);
607 vam->result_ready = 1;
610 static void vl_api_create_loopback_instance_reply_t_handler
611 (vl_api_create_loopback_instance_reply_t * mp)
613 vat_main_t *vam = &vat_main;
614 i32 retval = ntohl (mp->retval);
616 vam->retval = retval;
617 vam->regenerate_interface_table = 1;
618 vam->sw_if_index = ntohl (mp->sw_if_index);
619 vam->result_ready = 1;
622 static void vl_api_create_loopback_instance_reply_t_handler_json
623 (vl_api_create_loopback_instance_reply_t * mp)
625 vat_main_t *vam = &vat_main;
626 vat_json_node_t node;
628 vat_json_init_object (&node);
629 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
630 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
632 vat_json_print (vam->ofp, &node);
633 vat_json_free (&node);
634 vam->retval = ntohl (mp->retval);
635 vam->result_ready = 1;
638 static void vl_api_create_vlan_subif_reply_t_handler
639 (vl_api_create_vlan_subif_reply_t * mp)
641 vat_main_t *vam = &vat_main;
642 i32 retval = ntohl (mp->retval);
644 vam->retval = retval;
645 vam->regenerate_interface_table = 1;
646 vam->sw_if_index = ntohl (mp->sw_if_index);
647 vam->result_ready = 1;
650 static void vl_api_create_vlan_subif_reply_t_handler_json
651 (vl_api_create_vlan_subif_reply_t * mp)
653 vat_main_t *vam = &vat_main;
654 vat_json_node_t node;
656 vat_json_init_object (&node);
657 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
658 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
660 vat_json_print (vam->ofp, &node);
661 vat_json_free (&node);
663 vam->retval = ntohl (mp->retval);
664 vam->result_ready = 1;
667 static void vl_api_create_subif_reply_t_handler
668 (vl_api_create_subif_reply_t * mp)
670 vat_main_t *vam = &vat_main;
671 i32 retval = ntohl (mp->retval);
673 vam->retval = retval;
674 vam->regenerate_interface_table = 1;
675 vam->sw_if_index = ntohl (mp->sw_if_index);
676 vam->result_ready = 1;
679 static void vl_api_create_subif_reply_t_handler_json
680 (vl_api_create_subif_reply_t * mp)
682 vat_main_t *vam = &vat_main;
683 vat_json_node_t node;
685 vat_json_init_object (&node);
686 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
687 vat_json_object_add_uint (&node, "sw_if_index", ntohl (mp->sw_if_index));
689 vat_json_print (vam->ofp, &node);
690 vat_json_free (&node);
692 vam->retval = ntohl (mp->retval);
693 vam->result_ready = 1;
696 static void vl_api_interface_name_renumber_reply_t_handler
697 (vl_api_interface_name_renumber_reply_t * mp)
699 vat_main_t *vam = &vat_main;
700 i32 retval = ntohl (mp->retval);
702 vam->retval = retval;
703 vam->regenerate_interface_table = 1;
704 vam->result_ready = 1;
707 static void vl_api_interface_name_renumber_reply_t_handler_json
708 (vl_api_interface_name_renumber_reply_t * mp)
710 vat_main_t *vam = &vat_main;
711 vat_json_node_t node;
713 vat_json_init_object (&node);
714 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
716 vat_json_print (vam->ofp, &node);
717 vat_json_free (&node);
719 vam->retval = ntohl (mp->retval);
720 vam->result_ready = 1;
724 * Special-case: build the interface table, maintain
725 * the next loopback sw_if_index vbl.
727 static void vl_api_sw_interface_details_t_handler
728 (vl_api_sw_interface_details_t * mp)
730 vat_main_t *vam = &vat_main;
731 u8 *s = format (0, "%s%c", mp->interface_name, 0);
733 hash_set_mem (vam->sw_if_index_by_interface_name, s,
734 ntohl (mp->sw_if_index));
736 /* In sub interface case, fill the sub interface table entry */
737 if (mp->sw_if_index != mp->sup_sw_if_index)
739 sw_interface_subif_t *sub = NULL;
741 vec_add2 (vam->sw_if_subif_table, sub, 1);
743 vec_validate (sub->interface_name, strlen ((char *) s) + 1);
744 strncpy ((char *) sub->interface_name, (char *) s,
745 vec_len (sub->interface_name));
746 sub->sw_if_index = ntohl (mp->sw_if_index);
747 sub->sub_id = ntohl (mp->sub_id);
749 sub->raw_flags = ntohl (mp->sub_if_flags & SUB_IF_API_FLAG_MASK_VNET);
751 sub->sub_number_of_tags = mp->sub_number_of_tags;
752 sub->sub_outer_vlan_id = ntohs (mp->sub_outer_vlan_id);
753 sub->sub_inner_vlan_id = ntohs (mp->sub_inner_vlan_id);
755 /* vlan tag rewrite */
756 sub->vtr_op = ntohl (mp->vtr_op);
757 sub->vtr_push_dot1q = ntohl (mp->vtr_push_dot1q);
758 sub->vtr_tag1 = ntohl (mp->vtr_tag1);
759 sub->vtr_tag2 = ntohl (mp->vtr_tag2);
763 static void vl_api_sw_interface_details_t_handler_json
764 (vl_api_sw_interface_details_t * mp)
766 vat_main_t *vam = &vat_main;
767 vat_json_node_t *node = NULL;
769 if (VAT_JSON_ARRAY != vam->json_tree.type)
771 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
772 vat_json_init_array (&vam->json_tree);
774 node = vat_json_array_add (&vam->json_tree);
776 vat_json_init_object (node);
777 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
778 vat_json_object_add_uint (node, "sup_sw_if_index",
779 ntohl (mp->sup_sw_if_index));
780 vat_json_object_add_bytes (node, "l2_address", mp->l2_address,
781 sizeof (mp->l2_address));
782 vat_json_object_add_string_copy (node, "interface_name",
784 vat_json_object_add_string_copy (node, "interface_dev_type",
785 mp->interface_dev_type);
786 vat_json_object_add_uint (node, "flags", mp->flags);
787 vat_json_object_add_uint (node, "link_duplex", mp->link_duplex);
788 vat_json_object_add_uint (node, "link_speed", mp->link_speed);
789 vat_json_object_add_uint (node, "mtu", ntohs (mp->link_mtu));
790 vat_json_object_add_uint (node, "sub_id", ntohl (mp->sub_id));
791 vat_json_object_add_uint (node, "sub_number_of_tags",
792 mp->sub_number_of_tags);
793 vat_json_object_add_uint (node, "sub_outer_vlan_id",
794 ntohs (mp->sub_outer_vlan_id));
795 vat_json_object_add_uint (node, "sub_inner_vlan_id",
796 ntohs (mp->sub_inner_vlan_id));
797 vat_json_object_add_uint (node, "sub_if_flags", ntohl (mp->sub_if_flags));
798 vat_json_object_add_uint (node, "vtr_op", ntohl (mp->vtr_op));
799 vat_json_object_add_uint (node, "vtr_push_dot1q",
800 ntohl (mp->vtr_push_dot1q));
801 vat_json_object_add_uint (node, "vtr_tag1", ntohl (mp->vtr_tag1));
802 vat_json_object_add_uint (node, "vtr_tag2", ntohl (mp->vtr_tag2));
803 if (ntohl (mp->sub_if_flags) & SUB_IF_API_FLAG_DOT1AH)
805 vat_json_object_add_string_copy (node, "pbb_vtr_dmac",
807 format_ethernet_address,
809 vat_json_object_add_string_copy (node, "pbb_vtr_smac",
811 format_ethernet_address,
813 vat_json_object_add_uint (node, "pbb_vtr_b_vlanid", mp->b_vlanid);
814 vat_json_object_add_uint (node, "pbb_vtr_i_sid", mp->i_sid);
818 #if VPP_API_TEST_BUILTIN == 0
819 static void vl_api_sw_interface_event_t_handler
820 (vl_api_sw_interface_event_t * mp)
822 vat_main_t *vam = &vat_main;
823 if (vam->interface_event_display)
824 errmsg ("interface flags: sw_if_index %d %s %s",
825 ntohl (mp->sw_if_index),
826 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_ADMIN_UP) ?
827 "admin-up" : "admin-down",
828 ((ntohl (mp->flags)) & IF_STATUS_API_FLAG_LINK_UP) ?
829 "link-up" : "link-down");
833 __clib_unused static void
834 vl_api_sw_interface_event_t_handler_json (vl_api_sw_interface_event_t * mp)
836 /* JSON output not supported */
840 vl_api_cli_reply_t_handler (vl_api_cli_reply_t * mp)
842 vat_main_t *vam = &vat_main;
843 i32 retval = ntohl (mp->retval);
845 vam->retval = retval;
846 vam->shmem_result = uword_to_pointer (mp->reply_in_shmem, u8 *);
847 vam->result_ready = 1;
851 vl_api_cli_reply_t_handler_json (vl_api_cli_reply_t * mp)
853 vat_main_t *vam = &vat_main;
854 vat_json_node_t node;
858 vat_json_init_object (&node);
859 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
860 vat_json_object_add_uint (&node, "reply_in_shmem",
861 ntohl (mp->reply_in_shmem));
862 /* Toss the shared-memory original... */
863 oldheap = vl_msg_push_heap ();
865 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
868 vl_msg_pop_heap (oldheap);
870 vat_json_print (vam->ofp, &node);
871 vat_json_free (&node);
873 vam->retval = ntohl (mp->retval);
874 vam->result_ready = 1;
878 vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
880 vat_main_t *vam = &vat_main;
881 i32 retval = ntohl (mp->retval);
883 vec_reset_length (vam->cmd_reply);
885 vam->retval = retval;
887 vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
888 vam->result_ready = 1;
892 vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
894 vat_main_t *vam = &vat_main;
895 vat_json_node_t node;
896 u8 *reply = 0; /* reply vector */
898 reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
899 vec_reset_length (vam->cmd_reply);
901 vat_json_init_object (&node);
902 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
903 vat_json_object_add_string_copy (&node, "reply", reply);
905 vat_json_print (vam->ofp, &node);
906 vat_json_free (&node);
909 vam->retval = ntohl (mp->retval);
910 vam->result_ready = 1;
913 static void vl_api_get_node_index_reply_t_handler
914 (vl_api_get_node_index_reply_t * mp)
916 vat_main_t *vam = &vat_main;
917 i32 retval = ntohl (mp->retval);
920 vam->async_errors += (retval < 0);
924 vam->retval = retval;
926 errmsg ("node index %d", ntohl (mp->node_index));
927 vam->result_ready = 1;
931 static void vl_api_get_node_index_reply_t_handler_json
932 (vl_api_get_node_index_reply_t * mp)
934 vat_main_t *vam = &vat_main;
935 vat_json_node_t node;
937 vat_json_init_object (&node);
938 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
939 vat_json_object_add_uint (&node, "node_index", ntohl (mp->node_index));
941 vat_json_print (vam->ofp, &node);
942 vat_json_free (&node);
944 vam->retval = ntohl (mp->retval);
945 vam->result_ready = 1;
948 static void vl_api_get_next_index_reply_t_handler
949 (vl_api_get_next_index_reply_t * mp)
951 vat_main_t *vam = &vat_main;
952 i32 retval = ntohl (mp->retval);
955 vam->async_errors += (retval < 0);
959 vam->retval = retval;
961 errmsg ("next node index %d", ntohl (mp->next_index));
962 vam->result_ready = 1;
966 static void vl_api_get_next_index_reply_t_handler_json
967 (vl_api_get_next_index_reply_t * mp)
969 vat_main_t *vam = &vat_main;
970 vat_json_node_t node;
972 vat_json_init_object (&node);
973 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
974 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
976 vat_json_print (vam->ofp, &node);
977 vat_json_free (&node);
979 vam->retval = ntohl (mp->retval);
980 vam->result_ready = 1;
983 static void vl_api_add_node_next_reply_t_handler
984 (vl_api_add_node_next_reply_t * mp)
986 vat_main_t *vam = &vat_main;
987 i32 retval = ntohl (mp->retval);
990 vam->async_errors += (retval < 0);
994 vam->retval = retval;
996 errmsg ("next index %d", ntohl (mp->next_index));
997 vam->result_ready = 1;
1001 static void vl_api_add_node_next_reply_t_handler_json
1002 (vl_api_add_node_next_reply_t * mp)
1004 vat_main_t *vam = &vat_main;
1005 vat_json_node_t node;
1007 vat_json_init_object (&node);
1008 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1009 vat_json_object_add_uint (&node, "next_index", ntohl (mp->next_index));
1011 vat_json_print (vam->ofp, &node);
1012 vat_json_free (&node);
1014 vam->retval = ntohl (mp->retval);
1015 vam->result_ready = 1;
1018 static void vl_api_show_version_reply_t_handler
1019 (vl_api_show_version_reply_t * mp)
1021 vat_main_t *vam = &vat_main;
1022 i32 retval = ntohl (mp->retval);
1026 errmsg (" program: %s", mp->program);
1027 errmsg (" version: %s", mp->version);
1028 errmsg (" build date: %s", mp->build_date);
1029 errmsg ("build directory: %s", mp->build_directory);
1031 vam->retval = retval;
1032 vam->result_ready = 1;
1035 static void vl_api_show_version_reply_t_handler_json
1036 (vl_api_show_version_reply_t * mp)
1038 vat_main_t *vam = &vat_main;
1039 vat_json_node_t node;
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, "program", mp->program);
1044 vat_json_object_add_string_copy (&node, "version", mp->version);
1045 vat_json_object_add_string_copy (&node, "build_date", mp->build_date);
1046 vat_json_object_add_string_copy (&node, "build_directory",
1047 mp->build_directory);
1049 vat_json_print (vam->ofp, &node);
1050 vat_json_free (&node);
1052 vam->retval = ntohl (mp->retval);
1053 vam->result_ready = 1;
1056 static void vl_api_show_threads_reply_t_handler
1057 (vl_api_show_threads_reply_t * mp)
1059 vat_main_t *vam = &vat_main;
1060 i32 retval = ntohl (mp->retval);
1064 count = ntohl (mp->count);
1066 for (i = 0; i < count; i++)
1068 "\n%-2d %-11s %-11s %-5d %-6d %-4d %-6d",
1069 ntohl (mp->thread_data[i].id), mp->thread_data[i].name,
1070 mp->thread_data[i].type, ntohl (mp->thread_data[i].pid),
1071 ntohl (mp->thread_data[i].cpu_id), ntohl (mp->thread_data[i].core),
1072 ntohl (mp->thread_data[i].cpu_socket));
1074 vam->retval = retval;
1075 vam->result_ready = 1;
1078 static void vl_api_show_threads_reply_t_handler_json
1079 (vl_api_show_threads_reply_t * mp)
1081 vat_main_t *vam = &vat_main;
1082 vat_json_node_t node;
1083 vl_api_thread_data_t *td;
1084 i32 retval = ntohl (mp->retval);
1088 count = ntohl (mp->count);
1090 vat_json_init_object (&node);
1091 vat_json_object_add_int (&node, "retval", retval);
1092 vat_json_object_add_uint (&node, "count", count);
1094 for (i = 0; i < count; i++)
1096 td = &mp->thread_data[i];
1097 vat_json_object_add_uint (&node, "id", ntohl (td->id));
1098 vat_json_object_add_string_copy (&node, "name", td->name);
1099 vat_json_object_add_string_copy (&node, "type", td->type);
1100 vat_json_object_add_uint (&node, "pid", ntohl (td->pid));
1101 vat_json_object_add_int (&node, "cpu_id", ntohl (td->cpu_id));
1102 vat_json_object_add_int (&node, "core", ntohl (td->id));
1103 vat_json_object_add_int (&node, "cpu_socket", ntohl (td->cpu_socket));
1106 vat_json_print (vam->ofp, &node);
1107 vat_json_free (&node);
1109 vam->retval = retval;
1110 vam->result_ready = 1;
1114 api_show_threads (vat_main_t * vam)
1116 vl_api_show_threads_t *mp;
1120 "\n%-2s %-11s %-11s %-5s %-6s %-4s %-6s",
1121 "ID", "Name", "Type", "LWP", "cpu_id", "Core", "Socket");
1123 M (SHOW_THREADS, mp);
1130 #define vl_api_bridge_domain_details_t_endian vl_noop_handler
1131 #define vl_api_bridge_domain_details_t_print vl_noop_handler
1133 static void vl_api_control_ping_reply_t_handler
1134 (vl_api_control_ping_reply_t * mp)
1136 vat_main_t *vam = &vat_main;
1137 i32 retval = ntohl (mp->retval);
1138 if (vam->async_mode)
1140 vam->async_errors += (retval < 0);
1144 vam->retval = retval;
1145 vam->result_ready = 1;
1147 if (vam->socket_client_main)
1148 vam->socket_client_main->control_pings_outstanding--;
1151 static void vl_api_control_ping_reply_t_handler_json
1152 (vl_api_control_ping_reply_t * mp)
1154 vat_main_t *vam = &vat_main;
1155 i32 retval = ntohl (mp->retval);
1157 if (VAT_JSON_NONE != vam->json_tree.type)
1159 vat_json_print (vam->ofp, &vam->json_tree);
1160 vat_json_free (&vam->json_tree);
1161 vam->json_tree.type = VAT_JSON_NONE;
1166 vat_json_init_array (&vam->json_tree);
1167 vat_json_print (vam->ofp, &vam->json_tree);
1168 vam->json_tree.type = VAT_JSON_NONE;
1171 vam->retval = retval;
1172 vam->result_ready = 1;
1176 static void vl_api_get_first_msg_id_reply_t_handler
1177 (vl_api_get_first_msg_id_reply_t * mp)
1179 vat_main_t *vam = &vat_main;
1180 i32 retval = ntohl (mp->retval);
1182 if (vam->async_mode)
1184 vam->async_errors += (retval < 0);
1188 vam->retval = retval;
1189 vam->result_ready = 1;
1193 errmsg ("first message id %d", ntohs (mp->first_msg_id));
1197 static void vl_api_get_first_msg_id_reply_t_handler_json
1198 (vl_api_get_first_msg_id_reply_t * mp)
1200 vat_main_t *vam = &vat_main;
1201 vat_json_node_t node;
1203 vat_json_init_object (&node);
1204 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1205 vat_json_object_add_uint (&node, "first_msg_id",
1206 (uint) ntohs (mp->first_msg_id));
1208 vat_json_print (vam->ofp, &node);
1209 vat_json_free (&node);
1211 vam->retval = ntohl (mp->retval);
1212 vam->result_ready = 1;
1215 static void vl_api_get_node_graph_reply_t_handler
1216 (vl_api_get_node_graph_reply_t * mp)
1218 vat_main_t *vam = &vat_main;
1219 i32 retval = ntohl (mp->retval);
1220 u8 *pvt_copy, *reply;
1225 if (vam->async_mode)
1227 vam->async_errors += (retval < 0);
1231 vam->retval = retval;
1232 vam->result_ready = 1;
1235 /* "Should never happen..." */
1239 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1240 pvt_copy = vec_dup (reply);
1242 /* Toss the shared-memory original... */
1243 oldheap = vl_msg_push_heap ();
1247 vl_msg_pop_heap (oldheap);
1249 if (vam->graph_nodes)
1251 hash_free (vam->graph_node_index_by_name);
1253 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
1255 node = vam->graph_nodes[0][i];
1256 vec_free (node->name);
1257 vec_free (node->next_nodes);
1260 vec_free (vam->graph_nodes[0]);
1261 vec_free (vam->graph_nodes);
1264 vam->graph_node_index_by_name = hash_create_string (0, sizeof (uword));
1265 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1266 vec_free (pvt_copy);
1268 for (i = 0; i < vec_len (vam->graph_nodes[0]); i++)
1270 node = vam->graph_nodes[0][i];
1271 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1275 static void vl_api_get_node_graph_reply_t_handler_json
1276 (vl_api_get_node_graph_reply_t * mp)
1278 vat_main_t *vam = &vat_main;
1280 vat_json_node_t node;
1283 /* $$$$ make this real? */
1284 vat_json_init_object (&node);
1285 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
1286 vat_json_object_add_uint (&node, "reply_in_shmem", mp->reply_in_shmem);
1288 reply = uword_to_pointer (mp->reply_in_shmem, u8 *);
1290 /* Toss the shared-memory original... */
1291 oldheap = vl_msg_push_heap ();
1295 vl_msg_pop_heap (oldheap);
1297 vat_json_print (vam->ofp, &node);
1298 vat_json_free (&node);
1300 vam->retval = ntohl (mp->retval);
1301 vam->result_ready = 1;
1304 /* Format hex dump. */
1306 format_hex_bytes (u8 * s, va_list * va)
1308 u8 *bytes = va_arg (*va, u8 *);
1309 int n_bytes = va_arg (*va, int);
1312 /* Print short or long form depending on byte count. */
1313 uword short_form = n_bytes <= 32;
1314 u32 indent = format_get_indent (s);
1319 for (i = 0; i < n_bytes; i++)
1321 if (!short_form && (i % 32) == 0)
1322 s = format (s, "%08x: ", i);
1323 s = format (s, "%02x", bytes[i]);
1324 if (!short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
1325 s = format (s, "\n%U", format_white_space, indent);
1332 * Generate boilerplate reply handlers, which
1333 * dig the return value out of the xxx_reply_t API message,
1334 * stick it into vam->retval, and set vam->result_ready
1336 * Could also do this by pointing N message decode slots at
1337 * a single function, but that could break in subtle ways.
1340 #define foreach_standard_reply_retval_handler \
1341 _ (sw_interface_set_flags_reply) \
1342 _ (sw_interface_add_del_address_reply) \
1343 _ (sw_interface_set_rx_placement_reply) \
1344 _ (sw_interface_set_unnumbered_reply) \
1345 _ (sw_interface_set_table_reply) \
1346 _ (delete_loopback_reply) \
1347 _ (want_interface_events_reply) \
1348 _ (sw_interface_clear_stats_reply) \
1349 _ (delete_subif_reply) \
1350 _ (sw_interface_tag_add_del_reply) \
1351 _ (sw_interface_add_del_mac_address_reply) \
1352 _ (hw_interface_set_mtu_reply) \
1353 _ (session_rule_add_del_reply)
1356 static void vl_api_##n##_t_handler \
1357 (vl_api_##n##_t * mp) \
1359 vat_main_t * vam = &vat_main; \
1360 i32 retval = ntohl(mp->retval); \
1361 if (vam->async_mode) { \
1362 vam->async_errors += (retval < 0); \
1364 vam->retval = retval; \
1365 vam->result_ready = 1; \
1368 foreach_standard_reply_retval_handler;
1372 static void vl_api_##n##_t_handler_json \
1373 (vl_api_##n##_t * mp) \
1375 vat_main_t * vam = &vat_main; \
1376 vat_json_node_t node; \
1377 vat_json_init_object(&node); \
1378 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1379 vat_json_print(vam->ofp, &node); \
1380 vam->retval = ntohl(mp->retval); \
1381 vam->result_ready = 1; \
1383 foreach_standard_reply_retval_handler;
1387 * Table of message reply handlers, must include boilerplate handlers
1391 #define foreach_vpe_api_reply_msg \
1392 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1393 _(CREATE_LOOPBACK_INSTANCE_REPLY, create_loopback_instance_reply) \
1394 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1395 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1396 _(CONTROL_PING_REPLY, control_ping_reply) \
1397 _(CLI_REPLY, cli_reply) \
1398 _(CLI_INBAND_REPLY, cli_inband_reply) \
1399 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1400 sw_interface_add_del_address_reply) \
1401 _(SW_INTERFACE_SET_RX_PLACEMENT_REPLY, sw_interface_set_rx_placement_reply) \
1402 _(SW_INTERFACE_RX_PLACEMENT_DETAILS, sw_interface_rx_placement_details) \
1403 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1404 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1405 sw_interface_set_unnumbered_reply) \
1406 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1407 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1408 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
1409 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
1410 _(SHOW_VERSION_REPLY, show_version_reply) \
1411 _(SHOW_THREADS_REPLY, show_threads_reply) \
1412 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
1413 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
1414 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
1415 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
1416 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
1417 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
1418 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
1419 _(DELETE_SUBIF_REPLY, delete_subif_reply) \
1420 _(SW_INTERFACE_TAG_ADD_DEL_REPLY, sw_interface_tag_add_del_reply) \
1421 _(SW_INTERFACE_ADD_DEL_MAC_ADDRESS_REPLY, sw_interface_add_del_mac_address_reply) \
1422 _(HW_INTERFACE_SET_MTU_REPLY, hw_interface_set_mtu_reply) \
1423 _(SW_INTERFACE_GET_TABLE_REPLY, sw_interface_get_table_reply) \
1424 _(APP_NAMESPACE_ADD_DEL_REPLY, app_namespace_add_del_reply) \
1425 _(SESSION_RULE_ADD_DEL_REPLY, session_rule_add_del_reply) \
1426 _(SESSION_RULES_DETAILS, session_rules_details) \
1428 #define foreach_standalone_reply_msg \
1429 _(SW_INTERFACE_EVENT, sw_interface_event)
1437 #define STR_VTR_OP_CASE(op) \
1438 case L2_VTR_ ## op: \
1442 str_vtr_op (u32 vtr_op)
1446 STR_VTR_OP_CASE (DISABLED);
1447 STR_VTR_OP_CASE (PUSH_1);
1448 STR_VTR_OP_CASE (PUSH_2);
1449 STR_VTR_OP_CASE (POP_1);
1450 STR_VTR_OP_CASE (POP_2);
1451 STR_VTR_OP_CASE (TRANSLATE_1_1);
1452 STR_VTR_OP_CASE (TRANSLATE_1_2);
1453 STR_VTR_OP_CASE (TRANSLATE_2_1);
1454 STR_VTR_OP_CASE (TRANSLATE_2_2);
1461 dump_sub_interface_table (vat_main_t * vam)
1463 const sw_interface_subif_t *sub = NULL;
1465 if (vam->json_output)
1468 ("JSON output supported only for VPE API calls and dump_stats_table");
1473 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s",
1474 "Interface", "sw_if_index",
1475 "sub id", "dot1ad", "tags", "outer id",
1476 "inner id", "exact", "default", "outer any", "inner any");
1478 vec_foreach (sub, vam->sw_if_subif_table)
1481 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d",
1482 sub->interface_name,
1484 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
1485 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
1486 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
1487 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
1488 if (sub->vtr_op != L2_VTR_DISABLED)
1491 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
1492 "tag1: %d tag2: %d ]",
1493 str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q,
1494 sub->vtr_tag1, sub->vtr_tag2);
1502 name_sort_cmp (void *a1, void *a2)
1504 name_sort_t *n1 = a1;
1505 name_sort_t *n2 = a2;
1507 return strcmp ((char *) n1->name, (char *) n2->name);
1511 dump_interface_table (vat_main_t * vam)
1514 name_sort_t *nses = 0, *ns;
1516 if (vam->json_output)
1519 ("JSON output supported only for VPE API calls and dump_stats_table");
1524 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1526 vec_add2 (nses, ns, 1);
1527 ns->name = (u8 *)(p->key);
1528 ns->value = (u32) p->value[0];
1532 vec_sort_with_function (nses, name_sort_cmp);
1534 print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index");
1535 vec_foreach (ns, nses)
1537 print (vam->ofp, "%-25s%-15d", ns->name, ns->value);
1544 * Pass CLI buffers directly in the CLI_INBAND API message,
1545 * instead of an additional shared memory area.
1548 exec_inband (vat_main_t * vam)
1550 vl_api_cli_inband_t *mp;
1551 unformat_input_t *i = vam->input;
1554 if (vec_len (i->buffer) == 0)
1557 if (vam->exec_mode == 0 && unformat (i, "mode"))
1562 if (vam->exec_mode == 1 && (unformat (i, "exit") || unformat (i, "quit")))
1569 * In order for the CLI command to work, it
1570 * must be a vector ending in \n, not a C-string ending
1573 M2 (CLI_INBAND, mp, vec_len (vam->input->buffer));
1574 vl_api_vec_to_api_string (vam->input->buffer, &mp->cmd);
1578 /* json responses may or may not include a useful reply... */
1579 if (vec_len (vam->cmd_reply))
1580 print (vam->ofp, "%v", (char *) (vam->cmd_reply));
1585 exec (vat_main_t * vam)
1587 return exec_inband (vam);
1591 api_create_loopback (vat_main_t * vam)
1593 unformat_input_t *i = vam->input;
1594 vl_api_create_loopback_t *mp;
1595 vl_api_create_loopback_instance_t *mp_lbi;
1598 u8 is_specified = 0;
1599 u32 user_instance = 0;
1602 clib_memset (mac_address, 0, sizeof (mac_address));
1604 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1606 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
1608 if (unformat (i, "instance %d", &user_instance))
1616 M (CREATE_LOOPBACK_INSTANCE, mp_lbi);
1617 mp_lbi->is_specified = is_specified;
1619 mp_lbi->user_instance = htonl (user_instance);
1621 clib_memcpy (mp_lbi->mac_address, mac_address, sizeof (mac_address));
1626 /* Construct the API message */
1627 M (CREATE_LOOPBACK, mp);
1629 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
1638 api_delete_loopback (vat_main_t * vam)
1640 unformat_input_t *i = vam->input;
1641 vl_api_delete_loopback_t *mp;
1642 u32 sw_if_index = ~0;
1645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1647 if (unformat (i, "sw_if_index %d", &sw_if_index))
1653 if (sw_if_index == ~0)
1655 errmsg ("missing sw_if_index");
1659 /* Construct the API message */
1660 M (DELETE_LOOPBACK, mp);
1661 mp->sw_if_index = ntohl (sw_if_index);
1669 api_want_interface_events (vat_main_t * vam)
1671 unformat_input_t *i = vam->input;
1672 vl_api_want_interface_events_t *mp;
1676 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1678 if (unformat (i, "enable"))
1680 else if (unformat (i, "disable"))
1688 errmsg ("missing enable|disable");
1692 M (WANT_INTERFACE_EVENTS, mp);
1693 mp->enable_disable = enable;
1695 vam->interface_event_display = enable;
1703 /* Note: non-static, called once to set up the initial intfc table */
1705 api_sw_interface_dump (vat_main_t * vam)
1707 vl_api_sw_interface_dump_t *mp;
1708 vl_api_control_ping_t *mp_ping;
1710 name_sort_t *nses = 0, *ns;
1711 sw_interface_subif_t *sub = NULL;
1714 /* Toss the old name table */
1716 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1718 vec_add2 (nses, ns, 1);
1719 ns->name = (u8 *)(p->key);
1720 ns->value = (u32) p->value[0];
1724 hash_free (vam->sw_if_index_by_interface_name);
1726 vec_foreach (ns, nses) vec_free (ns->name);
1730 vec_foreach (sub, vam->sw_if_subif_table)
1732 vec_free (sub->interface_name);
1734 vec_free (vam->sw_if_subif_table);
1736 /* recreate the interface name hash table */
1737 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
1740 * Ask for all interface names. Otherwise, the epic catalog of
1741 * name filters becomes ridiculously long, and vat ends up needing
1742 * to be taught about new interface types.
1744 M (SW_INTERFACE_DUMP, mp);
1747 /* Use a control ping for synchronization */
1748 MPING (CONTROL_PING, mp_ping);
1756 api_sw_interface_set_flags (vat_main_t * vam)
1758 unformat_input_t *i = vam->input;
1759 vl_api_sw_interface_set_flags_t *mp;
1761 u8 sw_if_index_set = 0;
1765 /* Parse args required to build the message */
1766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1768 if (unformat (i, "admin-up"))
1770 else if (unformat (i, "admin-down"))
1773 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1774 sw_if_index_set = 1;
1775 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1776 sw_if_index_set = 1;
1781 if (sw_if_index_set == 0)
1783 errmsg ("missing interface name or sw_if_index");
1787 /* Construct the API message */
1788 M (SW_INTERFACE_SET_FLAGS, mp);
1789 mp->sw_if_index = ntohl (sw_if_index);
1790 mp->flags = ntohl ((admin_up) ? IF_STATUS_API_FLAG_ADMIN_UP : 0);
1795 /* Wait for a reply, return the good/bad news... */
1801 api_sw_interface_set_rx_placement (vat_main_t * vam)
1803 unformat_input_t *i = vam->input;
1804 vl_api_sw_interface_set_rx_placement_t *mp;
1806 u8 sw_if_index_set = 0;
1809 u32 queue_id, thread_index;
1811 /* Parse args required to build the message */
1812 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1814 if (unformat (i, "queue %d", &queue_id))
1816 else if (unformat (i, "main"))
1818 else if (unformat (i, "worker %d", &thread_index))
1821 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1822 sw_if_index_set = 1;
1823 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1824 sw_if_index_set = 1;
1829 if (sw_if_index_set == 0)
1831 errmsg ("missing interface name or sw_if_index");
1837 /* Construct the API message */
1838 M (SW_INTERFACE_SET_RX_PLACEMENT, mp);
1839 mp->sw_if_index = ntohl (sw_if_index);
1840 mp->worker_id = ntohl (thread_index);
1841 mp->queue_id = ntohl (queue_id);
1842 mp->is_main = is_main;
1846 /* Wait for a reply, return the good/bad news... */
1851 static void vl_api_sw_interface_rx_placement_details_t_handler
1852 (vl_api_sw_interface_rx_placement_details_t * mp)
1854 vat_main_t *vam = &vat_main;
1855 u32 worker_id = ntohl (mp->worker_id);
1858 "\n%-11d %-11s %-6d %-5d %-9s",
1859 ntohl (mp->sw_if_index), (worker_id == 0) ? "main" : "worker",
1860 worker_id, ntohl (mp->queue_id),
1862 1) ? "polling" : ((mp->mode == 2) ? "interrupt" : "adaptive"));
1865 static void vl_api_sw_interface_rx_placement_details_t_handler_json
1866 (vl_api_sw_interface_rx_placement_details_t * mp)
1868 vat_main_t *vam = &vat_main;
1869 vat_json_node_t *node = NULL;
1871 if (VAT_JSON_ARRAY != vam->json_tree.type)
1873 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
1874 vat_json_init_array (&vam->json_tree);
1876 node = vat_json_array_add (&vam->json_tree);
1878 vat_json_init_object (node);
1879 vat_json_object_add_uint (node, "sw_if_index", ntohl (mp->sw_if_index));
1880 vat_json_object_add_uint (node, "worker_id", ntohl (mp->worker_id));
1881 vat_json_object_add_uint (node, "queue_id", ntohl (mp->queue_id));
1882 vat_json_object_add_uint (node, "mode", mp->mode);
1886 api_sw_interface_rx_placement_dump (vat_main_t * vam)
1888 unformat_input_t *i = vam->input;
1889 vl_api_sw_interface_rx_placement_dump_t *mp;
1890 vl_api_control_ping_t *mp_ping;
1893 u8 sw_if_index_set = 0;
1895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1897 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1899 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1906 "\n%-11s %-11s %-6s %-5s %-4s",
1907 "sw_if_index", "main/worker", "thread", "queue", "mode");
1909 /* Dump Interface rx placement */
1910 M (SW_INTERFACE_RX_PLACEMENT_DUMP, mp);
1912 if (sw_if_index_set)
1913 mp->sw_if_index = htonl (sw_if_index);
1915 mp->sw_if_index = ~0;
1919 /* Use a control ping for synchronization */
1920 MPING (CONTROL_PING, mp_ping);
1928 api_sw_interface_clear_stats (vat_main_t * vam)
1930 unformat_input_t *i = vam->input;
1931 vl_api_sw_interface_clear_stats_t *mp;
1933 u8 sw_if_index_set = 0;
1936 /* Parse args required to build the message */
1937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1939 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1940 sw_if_index_set = 1;
1941 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1942 sw_if_index_set = 1;
1947 /* Construct the API message */
1948 M (SW_INTERFACE_CLEAR_STATS, mp);
1950 if (sw_if_index_set == 1)
1951 mp->sw_if_index = ntohl (sw_if_index);
1953 mp->sw_if_index = ~0;
1958 /* Wait for a reply, return the good/bad news... */
1964 api_sw_interface_add_del_address (vat_main_t * vam)
1966 unformat_input_t *i = vam->input;
1967 vl_api_sw_interface_add_del_address_t *mp;
1969 u8 sw_if_index_set = 0;
1970 u8 is_add = 1, del_all = 0;
1971 u32 address_length = 0;
1972 u8 v4_address_set = 0;
1973 u8 v6_address_set = 0;
1974 ip4_address_t v4address;
1975 ip6_address_t v6address;
1978 /* Parse args required to build the message */
1979 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
1981 if (unformat (i, "del-all"))
1983 else if (unformat (i, "del"))
1986 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
1987 sw_if_index_set = 1;
1988 else if (unformat (i, "sw_if_index %d", &sw_if_index))
1989 sw_if_index_set = 1;
1990 else if (unformat (i, "%U/%d",
1991 unformat_ip4_address, &v4address, &address_length))
1993 else if (unformat (i, "%U/%d",
1994 unformat_ip6_address, &v6address, &address_length))
2000 if (sw_if_index_set == 0)
2002 errmsg ("missing interface name or sw_if_index");
2005 if (v4_address_set && v6_address_set)
2007 errmsg ("both v4 and v6 addresses set");
2010 if (!v4_address_set && !v6_address_set && !del_all)
2012 errmsg ("no addresses set");
2016 /* Construct the API message */
2017 M (SW_INTERFACE_ADD_DEL_ADDRESS, mp);
2019 mp->sw_if_index = ntohl (sw_if_index);
2020 mp->is_add = is_add;
2021 mp->del_all = del_all;
2024 mp->prefix.address.af = ADDRESS_IP6;
2025 clib_memcpy (mp->prefix.address.un.ip6, &v6address, sizeof (v6address));
2029 mp->prefix.address.af = ADDRESS_IP4;
2030 clib_memcpy (mp->prefix.address.un.ip4, &v4address, sizeof (v4address));
2032 mp->prefix.len = address_length;
2037 /* Wait for a reply, return good/bad news */
2043 api_sw_interface_set_table (vat_main_t * vam)
2045 unformat_input_t *i = vam->input;
2046 vl_api_sw_interface_set_table_t *mp;
2047 u32 sw_if_index, vrf_id = 0;
2048 u8 sw_if_index_set = 0;
2052 /* Parse args required to build the message */
2053 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2055 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2056 sw_if_index_set = 1;
2057 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2058 sw_if_index_set = 1;
2059 else if (unformat (i, "vrf %d", &vrf_id))
2061 else if (unformat (i, "ipv6"))
2067 if (sw_if_index_set == 0)
2069 errmsg ("missing interface name or sw_if_index");
2073 /* Construct the API message */
2074 M (SW_INTERFACE_SET_TABLE, mp);
2076 mp->sw_if_index = ntohl (sw_if_index);
2077 mp->is_ipv6 = is_ipv6;
2078 mp->vrf_id = ntohl (vrf_id);
2083 /* Wait for a reply... */
2088 static void vl_api_sw_interface_get_table_reply_t_handler
2089 (vl_api_sw_interface_get_table_reply_t * mp)
2091 vat_main_t *vam = &vat_main;
2093 print (vam->ofp, "%d", ntohl (mp->vrf_id));
2095 vam->retval = ntohl (mp->retval);
2096 vam->result_ready = 1;
2100 static void vl_api_sw_interface_get_table_reply_t_handler_json
2101 (vl_api_sw_interface_get_table_reply_t * mp)
2103 vat_main_t *vam = &vat_main;
2104 vat_json_node_t node;
2106 vat_json_init_object (&node);
2107 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
2108 vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id));
2110 vat_json_print (vam->ofp, &node);
2111 vat_json_free (&node);
2113 vam->retval = ntohl (mp->retval);
2114 vam->result_ready = 1;
2118 api_sw_interface_get_table (vat_main_t * vam)
2120 unformat_input_t *i = vam->input;
2121 vl_api_sw_interface_get_table_t *mp;
2123 u8 sw_if_index_set = 0;
2127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2129 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2130 sw_if_index_set = 1;
2131 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2132 sw_if_index_set = 1;
2133 else if (unformat (i, "ipv6"))
2139 if (sw_if_index_set == 0)
2141 errmsg ("missing interface name or sw_if_index");
2145 M (SW_INTERFACE_GET_TABLE, mp);
2146 mp->sw_if_index = htonl (sw_if_index);
2147 mp->is_ipv6 = is_ipv6;
2155 unformat_vlib_pci_addr (unformat_input_t *input, va_list *args)
2157 vlib_pci_addr_t *addr = va_arg (*args, vlib_pci_addr_t *);
2160 if (!unformat (input, "%x:%x:%x.%x", &x[0], &x[1], &x[2], &x[3]))
2163 addr->domain = x[0];
2166 addr->function = x[3];
2172 unformat_fib_path (unformat_input_t *input, va_list *args)
2174 vat_main_t *vam = va_arg (*args, vat_main_t *);
2175 vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t *);
2176 u32 weight, preference;
2177 mpls_label_t out_label;
2179 clib_memset (path, 0, sizeof (*path));
2181 path->sw_if_index = ~0;
2185 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2187 if (unformat (input, "%U %U", unformat_vl_api_ip4_address,
2188 &path->nh.address.ip4, api_unformat_sw_if_index, vam,
2189 &path->sw_if_index))
2191 path->proto = FIB_API_PATH_NH_PROTO_IP4;
2193 else if (unformat (input, "%U %U",
2194 unformat_vl_api_ip6_address,
2195 &path->nh.address.ip6,
2196 api_unformat_sw_if_index, vam, &path->sw_if_index))
2198 path->proto = FIB_API_PATH_NH_PROTO_IP6;
2200 else if (unformat (input, "weight %u", &weight))
2202 path->weight = weight;
2204 else if (unformat (input, "preference %u", &preference))
2206 path->preference = preference;
2208 else if (unformat (input, "%U next-hop-table %d",
2209 unformat_vl_api_ip4_address,
2210 &path->nh.address.ip4, &path->table_id))
2212 path->proto = FIB_API_PATH_NH_PROTO_IP4;
2214 else if (unformat (input, "%U next-hop-table %d",
2215 unformat_vl_api_ip6_address,
2216 &path->nh.address.ip6, &path->table_id))
2218 path->proto = FIB_API_PATH_NH_PROTO_IP6;
2220 else if (unformat (input, "%U",
2221 unformat_vl_api_ip4_address, &path->nh.address.ip4))
2224 * the recursive next-hops are by default in the default table
2227 path->sw_if_index = ~0;
2228 path->proto = FIB_API_PATH_NH_PROTO_IP4;
2230 else if (unformat (input, "%U",
2231 unformat_vl_api_ip6_address, &path->nh.address.ip6))
2234 * the recursive next-hops are by default in the default table
2237 path->sw_if_index = ~0;
2238 path->proto = FIB_API_PATH_NH_PROTO_IP6;
2240 else if (unformat (input, "resolve-via-host"))
2242 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
2244 else if (unformat (input, "resolve-via-attached"))
2246 path->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
2248 else if (unformat (input, "ip4-lookup-in-table %d", &path->table_id))
2250 path->type = FIB_API_PATH_TYPE_LOCAL;
2251 path->sw_if_index = ~0;
2252 path->proto = FIB_API_PATH_NH_PROTO_IP4;
2254 else if (unformat (input, "ip6-lookup-in-table %d", &path->table_id))
2256 path->type = FIB_API_PATH_TYPE_LOCAL;
2257 path->sw_if_index = ~0;
2258 path->proto = FIB_API_PATH_NH_PROTO_IP6;
2260 else if (unformat (input, "sw_if_index %d", &path->sw_if_index))
2262 else if (unformat (input, "via-label %d", &path->nh.via_label))
2264 path->proto = FIB_API_PATH_NH_PROTO_MPLS;
2265 path->sw_if_index = ~0;
2267 else if (unformat (input, "l2-input-on %d", &path->sw_if_index))
2269 path->proto = FIB_API_PATH_NH_PROTO_ETHERNET;
2270 path->type = FIB_API_PATH_TYPE_INTERFACE_RX;
2272 else if (unformat (input, "local"))
2274 path->type = FIB_API_PATH_TYPE_LOCAL;
2276 else if (unformat (input, "out-labels"))
2278 while (unformat (input, "%d", &out_label))
2280 path->label_stack[path->n_labels].label = out_label;
2281 path->label_stack[path->n_labels].is_uniform = 0;
2282 path->label_stack[path->n_labels].ttl = 64;
2286 else if (unformat (input, "via"))
2288 /* new path, back up and return */
2289 unformat_put_input (input);
2290 unformat_put_input (input);
2291 unformat_put_input (input);
2292 unformat_put_input (input);
2301 path->proto = ntohl (path->proto);
2302 path->type = ntohl (path->type);
2303 path->flags = ntohl (path->flags);
2304 path->table_id = ntohl (path->table_id);
2305 path->sw_if_index = ntohl (path->sw_if_index);
2311 api_sw_interface_set_unnumbered (vat_main_t *vam)
2313 unformat_input_t *i = vam->input;
2314 vl_api_sw_interface_set_unnumbered_t *mp;
2316 u32 unnum_sw_index = ~0;
2318 u8 sw_if_index_set = 0;
2321 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2323 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2324 sw_if_index_set = 1;
2325 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2326 sw_if_index_set = 1;
2327 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
2329 else if (unformat (i, "del"))
2333 clib_warning ("parse error '%U'", format_unformat_error, i);
2338 if (sw_if_index_set == 0)
2340 errmsg ("missing interface name or sw_if_index");
2344 M (SW_INTERFACE_SET_UNNUMBERED, mp);
2346 mp->sw_if_index = ntohl (sw_if_index);
2347 mp->unnumbered_sw_if_index = ntohl (unnum_sw_index);
2348 mp->is_add = is_add;
2356 api_create_vlan_subif (vat_main_t *vam)
2358 unformat_input_t *i = vam->input;
2359 vl_api_create_vlan_subif_t *mp;
2361 u8 sw_if_index_set = 0;
2366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2368 if (unformat (i, "sw_if_index %d", &sw_if_index))
2369 sw_if_index_set = 1;
2370 else if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2371 sw_if_index_set = 1;
2372 else if (unformat (i, "vlan %d", &vlan_id))
2376 clib_warning ("parse error '%U'", format_unformat_error, i);
2381 if (sw_if_index_set == 0)
2383 errmsg ("missing interface name or sw_if_index");
2387 if (vlan_id_set == 0)
2389 errmsg ("missing vlan_id");
2392 M (CREATE_VLAN_SUBIF, mp);
2394 mp->sw_if_index = ntohl (sw_if_index);
2395 mp->vlan_id = ntohl (vlan_id);
2402 #define foreach_create_subif_bit \
2409 _(outer_vlan_id_any) \
2410 _(inner_vlan_id_any)
2412 #define foreach_create_subif_flag \
2417 _(4, "exact_match") \
2418 _(5, "default_sub") \
2419 _(6, "outer_vlan_id_any") \
2420 _(7, "inner_vlan_id_any")
2423 api_create_subif (vat_main_t * vam)
2425 unformat_input_t *i = vam->input;
2426 vl_api_create_subif_t *mp;
2428 u8 sw_if_index_set = 0;
2431 u32 __attribute__ ((unused)) no_tags = 0;
2432 u32 __attribute__ ((unused)) one_tag = 0;
2433 u32 __attribute__ ((unused)) two_tags = 0;
2434 u32 __attribute__ ((unused)) dot1ad = 0;
2435 u32 __attribute__ ((unused)) exact_match = 0;
2436 u32 __attribute__ ((unused)) default_sub = 0;
2437 u32 __attribute__ ((unused)) outer_vlan_id_any = 0;
2438 u32 __attribute__ ((unused)) inner_vlan_id_any = 0;
2440 u16 outer_vlan_id = 0;
2441 u16 inner_vlan_id = 0;
2444 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2446 if (unformat (i, "sw_if_index %d", &sw_if_index))
2447 sw_if_index_set = 1;
2449 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
2450 sw_if_index_set = 1;
2451 else if (unformat (i, "sub_id %d", &sub_id))
2453 else if (unformat (i, "outer_vlan_id %d", &tmp))
2454 outer_vlan_id = tmp;
2455 else if (unformat (i, "inner_vlan_id %d", &tmp))
2456 inner_vlan_id = tmp;
2458 #define _(a) else if (unformat (i, #a)) a = 1 ;
2459 foreach_create_subif_bit
2463 clib_warning ("parse error '%U'", format_unformat_error, i);
2468 if (sw_if_index_set == 0)
2470 errmsg ("missing interface name or sw_if_index");
2474 if (sub_id_set == 0)
2476 errmsg ("missing sub_id");
2479 M (CREATE_SUBIF, mp);
2481 mp->sw_if_index = ntohl (sw_if_index);
2482 mp->sub_id = ntohl (sub_id);
2484 #define _(a,b) mp->sub_if_flags |= (1 << a);
2485 foreach_create_subif_flag;
2488 mp->outer_vlan_id = ntohs (outer_vlan_id);
2489 mp->inner_vlan_id = ntohs (inner_vlan_id);
2497 u8 localsid_addr[16];
2505 #define foreach_tcp_proto_field \
2509 #define foreach_udp_proto_field \
2513 #define foreach_ip4_proto_field \
2525 u16 src_port, dst_port;
2528 #if VPP_API_TEST_BUILTIN == 0
2530 unformat_tcp_mask (unformat_input_t *input, va_list *args)
2532 u8 **maskp = va_arg (*args, u8 **);
2534 u8 found_something = 0;
2537 #define _(a) u8 a = 0;
2538 foreach_tcp_proto_field;
2541 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2545 #define _(a) else if (unformat (input, #a)) a = 1;
2546 foreach_tcp_proto_field
2551 #define _(a) found_something += a;
2552 foreach_tcp_proto_field;
2555 if (found_something == 0)
2558 vec_validate (mask, sizeof (*tcp) - 1);
2560 tcp = (tcp_header_t *) mask;
2564 clib_memset (&tcp->a, 0xff, sizeof (tcp->a));
2565 foreach_tcp_proto_field;
2573 unformat_udp_mask (unformat_input_t *input, va_list *args)
2575 u8 **maskp = va_arg (*args, u8 **);
2577 u8 found_something = 0;
2580 #define _(a) u8 a = 0;
2581 foreach_udp_proto_field;
2584 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2588 #define _(a) else if (unformat (input, #a)) a = 1;
2589 foreach_udp_proto_field
2594 #define _(a) found_something += a;
2595 foreach_udp_proto_field;
2598 if (found_something == 0)
2601 vec_validate (mask, sizeof (*udp) - 1);
2603 udp = (udp_header_t *) mask;
2607 clib_memset (&udp->a, 0xff, sizeof (udp->a));
2608 foreach_udp_proto_field;
2616 unformat_l4_mask (unformat_input_t *input, va_list *args)
2618 u8 **maskp = va_arg (*args, u8 **);
2619 u16 src_port = 0, dst_port = 0;
2620 tcpudp_header_t *tcpudp;
2622 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2624 if (unformat (input, "tcp %U", unformat_tcp_mask, maskp))
2626 else if (unformat (input, "udp %U", unformat_udp_mask, maskp))
2628 else if (unformat (input, "src_port"))
2630 else if (unformat (input, "dst_port"))
2636 if (!src_port && !dst_port)
2640 vec_validate (mask, sizeof (tcpudp_header_t) - 1);
2642 tcpudp = (tcpudp_header_t *) mask;
2643 tcpudp->src_port = src_port;
2644 tcpudp->dst_port = dst_port;
2652 unformat_ip4_mask (unformat_input_t * input, va_list * args)
2654 u8 **maskp = va_arg (*args, u8 **);
2656 u8 found_something = 0;
2659 #define _(a) u8 a=0;
2660 foreach_ip4_proto_field;
2666 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2668 if (unformat (input, "version"))
2670 else if (unformat (input, "hdr_length"))
2672 else if (unformat (input, "src"))
2674 else if (unformat (input, "dst"))
2676 else if (unformat (input, "proto"))
2679 #define _(a) else if (unformat (input, #a)) a=1;
2680 foreach_ip4_proto_field
2686 #define _(a) found_something += a;
2687 foreach_ip4_proto_field;
2690 if (found_something == 0)
2693 vec_validate (mask, sizeof (*ip) - 1);
2695 ip = (ip4_header_t *) mask;
2697 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
2698 foreach_ip4_proto_field;
2701 ip->ip_version_and_header_length = 0;
2704 ip->ip_version_and_header_length |= 0xF0;
2707 ip->ip_version_and_header_length |= 0x0F;
2713 #define foreach_ip6_proto_field \
2721 unformat_ip6_mask (unformat_input_t * input, va_list * args)
2723 u8 **maskp = va_arg (*args, u8 **);
2725 u8 found_something = 0;
2727 u32 ip_version_traffic_class_and_flow_label;
2729 #define _(a) u8 a=0;
2730 foreach_ip6_proto_field;
2733 u8 traffic_class = 0;
2736 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2738 if (unformat (input, "version"))
2740 else if (unformat (input, "traffic-class"))
2742 else if (unformat (input, "flow-label"))
2744 else if (unformat (input, "src"))
2746 else if (unformat (input, "dst"))
2748 else if (unformat (input, "proto"))
2751 #define _(a) else if (unformat (input, #a)) a=1;
2752 foreach_ip6_proto_field
2758 #define _(a) found_something += a;
2759 foreach_ip6_proto_field;
2762 if (found_something == 0)
2765 vec_validate (mask, sizeof (*ip) - 1);
2767 ip = (ip6_header_t *) mask;
2769 #define _(a) if (a) clib_memset (&ip->a, 0xff, sizeof (ip->a));
2770 foreach_ip6_proto_field;
2773 ip_version_traffic_class_and_flow_label = 0;
2776 ip_version_traffic_class_and_flow_label |= 0xF0000000;
2779 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
2782 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
2784 ip->ip_version_traffic_class_and_flow_label =
2785 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
2792 unformat_l3_mask (unformat_input_t * input, va_list * args)
2794 u8 **maskp = va_arg (*args, u8 **);
2796 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2798 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
2800 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
2809 unformat_l2_mask (unformat_input_t * input, va_list * args)
2811 u8 **maskp = va_arg (*args, u8 **);
2826 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2828 if (unformat (input, "src"))
2830 else if (unformat (input, "dst"))
2832 else if (unformat (input, "proto"))
2834 else if (unformat (input, "tag1"))
2836 else if (unformat (input, "tag2"))
2838 else if (unformat (input, "ignore-tag1"))
2840 else if (unformat (input, "ignore-tag2"))
2842 else if (unformat (input, "cos1"))
2844 else if (unformat (input, "cos2"))
2846 else if (unformat (input, "dot1q"))
2848 else if (unformat (input, "dot1ad"))
2853 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
2854 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
2857 if (tag1 || ignore_tag1 || cos1 || dot1q)
2859 if (tag2 || ignore_tag2 || cos2 || dot1ad)
2862 vec_validate (mask, len - 1);
2865 clib_memset (mask, 0xff, 6);
2868 clib_memset (mask + 6, 0xff, 6);
2872 /* inner vlan tag */
2881 mask[21] = mask[20] = 0xff;
2902 mask[16] = mask[17] = 0xff;
2912 mask[12] = mask[13] = 0xff;
2919 unformat_classify_mask (unformat_input_t * input, va_list * args)
2921 u8 **maskp = va_arg (*args, u8 **);
2922 u32 *skipp = va_arg (*args, u32 *);
2923 u32 *matchp = va_arg (*args, u32 *);
2931 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
2933 if (unformat (input, "hex %U", unformat_hex_string, &mask))
2935 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
2937 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
2939 else if (unformat (input, "l4 %U", unformat_l4_mask, &l4))
2953 if (mask || l2 || l3 || l4)
2957 /* "With a free Ethernet header in every package" */
2959 vec_validate (l2, 13);
2963 vec_append (mask, l3);
2968 vec_append (mask, l4);
2973 /* Scan forward looking for the first significant mask octet */
2974 for (i = 0; i < vec_len (mask); i++)
2978 /* compute (skip, match) params */
2979 *skipp = i / sizeof (u32x4);
2980 vec_delete (mask, *skipp * sizeof (u32x4), 0);
2982 /* Pad mask to an even multiple of the vector size */
2983 while (vec_len (mask) % sizeof (u32x4))
2986 match = vec_len (mask) / sizeof (u32x4);
2988 for (i = match * sizeof (u32x4); i > 0; i -= sizeof (u32x4))
2990 u64 *tmp = (u64 *) (mask + (i - sizeof (u32x4)));
2991 if (*tmp || *(tmp + 1))
2996 clib_warning ("BUG: match 0");
2998 _vec_len (mask) = match * sizeof (u32x4);
3008 #endif /* VPP_API_TEST_BUILTIN */
3010 #define foreach_l2_next \
3012 _(ethernet, ETHERNET_INPUT) \
3017 unformat_l2_next_index (unformat_input_t * input, va_list * args)
3019 u32 *miss_next_indexp = va_arg (*args, u32 *);
3024 if (unformat (input, #n)) { next_index = L2_INPUT_CLASSIFY_NEXT_##N; goto out;}
3028 if (unformat (input, "%d", &tmp))
3037 *miss_next_indexp = next_index;
3041 #define foreach_ip_next \
3047 api_unformat_ip_next_index (unformat_input_t * input, va_list * args)
3049 u32 *miss_next_indexp = va_arg (*args, u32 *);
3054 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
3058 if (unformat (input, "%d", &tmp))
3067 *miss_next_indexp = next_index;
3071 #define foreach_acl_next \
3075 api_unformat_acl_next_index (unformat_input_t * input, va_list * args)
3077 u32 *miss_next_indexp = va_arg (*args, u32 *);
3082 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
3086 if (unformat (input, "permit"))
3091 else if (unformat (input, "%d", &tmp))
3100 *miss_next_indexp = next_index;
3105 unformat_policer_precolor (unformat_input_t * input, va_list * args)
3107 u32 *r = va_arg (*args, u32 *);
3109 if (unformat (input, "conform-color"))
3110 *r = POLICE_CONFORM;
3111 else if (unformat (input, "exceed-color"))
3119 #if VPP_API_TEST_BUILTIN == 0
3121 unformat_l4_match (unformat_input_t * input, va_list * args)
3123 u8 **matchp = va_arg (*args, u8 **);
3125 u8 *proto_header = 0;
3131 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3133 if (unformat (input, "src_port %d", &src_port))
3135 else if (unformat (input, "dst_port %d", &dst_port))
3141 h.src_port = clib_host_to_net_u16 (src_port);
3142 h.dst_port = clib_host_to_net_u16 (dst_port);
3143 vec_validate (proto_header, sizeof (h) - 1);
3144 memcpy (proto_header, &h, sizeof (h));
3146 *matchp = proto_header;
3152 unformat_ip4_match (unformat_input_t * input, va_list * args)
3154 u8 **matchp = va_arg (*args, u8 **);
3161 int src = 0, dst = 0;
3162 ip4_address_t src_val, dst_val;
3169 int fragment_id = 0;
3170 u32 fragment_id_val;
3176 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3178 if (unformat (input, "version %d", &version_val))
3180 else if (unformat (input, "hdr_length %d", &hdr_length_val))
3182 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
3184 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
3186 else if (unformat (input, "proto %d", &proto_val))
3188 else if (unformat (input, "tos %d", &tos_val))
3190 else if (unformat (input, "length %d", &length_val))
3192 else if (unformat (input, "fragment_id %d", &fragment_id_val))
3194 else if (unformat (input, "ttl %d", &ttl_val))
3196 else if (unformat (input, "checksum %d", &checksum_val))
3202 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
3203 + ttl + checksum == 0)
3207 * Aligned because we use the real comparison functions
3209 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
3211 ip = (ip4_header_t *) match;
3213 /* These are realistically matched in practice */
3215 ip->src_address.as_u32 = src_val.as_u32;
3218 ip->dst_address.as_u32 = dst_val.as_u32;
3221 ip->protocol = proto_val;
3224 /* These are not, but they're included for completeness */
3226 ip->ip_version_and_header_length |= (version_val & 0xF) << 4;
3229 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
3235 ip->length = clib_host_to_net_u16 (length_val);
3241 ip->checksum = clib_host_to_net_u16 (checksum_val);
3248 unformat_ip6_match (unformat_input_t * input, va_list * args)
3250 u8 **matchp = va_arg (*args, u8 **);
3255 u8 traffic_class = 0;
3256 u32 traffic_class_val = 0;
3259 int src = 0, dst = 0;
3260 ip6_address_t src_val, dst_val;
3263 int payload_length = 0;
3264 u32 payload_length_val;
3267 u32 ip_version_traffic_class_and_flow_label;
3269 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3271 if (unformat (input, "version %d", &version_val))
3273 else if (unformat (input, "traffic_class %d", &traffic_class_val))
3275 else if (unformat (input, "flow_label %d", &flow_label_val))
3277 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
3279 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
3281 else if (unformat (input, "proto %d", &proto_val))
3283 else if (unformat (input, "payload_length %d", &payload_length_val))
3285 else if (unformat (input, "hop_limit %d", &hop_limit_val))
3291 if (version + traffic_class + flow_label + src + dst + proto +
3292 payload_length + hop_limit == 0)
3296 * Aligned because we use the real comparison functions
3298 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof (u32x4));
3300 ip = (ip6_header_t *) match;
3303 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
3306 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
3309 ip->protocol = proto_val;
3311 ip_version_traffic_class_and_flow_label = 0;
3314 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
3317 ip_version_traffic_class_and_flow_label |=
3318 (traffic_class_val & 0xFF) << 20;
3321 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
3323 ip->ip_version_traffic_class_and_flow_label =
3324 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
3327 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
3330 ip->hop_limit = hop_limit_val;
3337 unformat_l3_match (unformat_input_t * input, va_list * args)
3339 u8 **matchp = va_arg (*args, u8 **);
3341 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3343 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
3345 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
3354 unformat_vlan_tag (unformat_input_t * input, va_list * args)
3356 u8 *tagp = va_arg (*args, u8 *);
3359 if (unformat (input, "%d", &tag))
3361 tagp[0] = (tag >> 8) & 0x0F;
3362 tagp[1] = tag & 0xFF;
3370 unformat_l2_match (unformat_input_t * input, va_list * args)
3372 u8 **matchp = va_arg (*args, u8 **);
3392 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3394 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
3397 if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
3399 else if (unformat (input, "proto %U",
3400 unformat_ethernet_type_host_byte_order, &proto_val))
3402 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
3404 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
3406 else if (unformat (input, "ignore-tag1"))
3408 else if (unformat (input, "ignore-tag2"))
3410 else if (unformat (input, "cos1 %d", &cos1_val))
3412 else if (unformat (input, "cos2 %d", &cos2_val))
3417 if ((src + dst + proto + tag1 + tag2 +
3418 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
3421 if (tag1 || ignore_tag1 || cos1)
3423 if (tag2 || ignore_tag2 || cos2)
3426 vec_validate_aligned (match, len - 1, sizeof (u32x4));
3429 clib_memcpy (match, dst_val, 6);
3432 clib_memcpy (match + 6, src_val, 6);
3436 /* inner vlan tag */
3437 match[19] = tag2_val[1];
3438 match[18] = tag2_val[0];
3440 match[18] |= (cos2_val & 0x7) << 5;
3443 match[21] = proto_val & 0xff;
3444 match[20] = proto_val >> 8;
3448 match[15] = tag1_val[1];
3449 match[14] = tag1_val[0];
3452 match[14] |= (cos1_val & 0x7) << 5;
3458 match[15] = tag1_val[1];
3459 match[14] = tag1_val[0];
3462 match[17] = proto_val & 0xff;
3463 match[16] = proto_val >> 8;
3466 match[14] |= (cos1_val & 0x7) << 5;
3472 match[18] |= (cos2_val & 0x7) << 5;
3474 match[14] |= (cos1_val & 0x7) << 5;
3477 match[13] = proto_val & 0xff;
3478 match[12] = proto_val >> 8;
3486 unformat_qos_source (unformat_input_t * input, va_list * args)
3488 int *qs = va_arg (*args, int *);
3490 if (unformat (input, "ip"))
3491 *qs = QOS_SOURCE_IP;
3492 else if (unformat (input, "mpls"))
3493 *qs = QOS_SOURCE_MPLS;
3494 else if (unformat (input, "ext"))
3495 *qs = QOS_SOURCE_EXT;
3496 else if (unformat (input, "vlan"))
3497 *qs = QOS_SOURCE_VLAN;
3506 api_unformat_classify_match (unformat_input_t * input, va_list * args)
3508 u8 **matchp = va_arg (*args, u8 **);
3509 u32 skip_n_vectors = va_arg (*args, u32);
3510 u32 match_n_vectors = va_arg (*args, u32);
3517 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
3519 if (unformat (input, "hex %U", unformat_hex_string, &match))
3521 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
3523 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
3525 else if (unformat (input, "l4 %U", unformat_l4_match, &l4))
3539 if (match || l2 || l3 || l4)
3543 /* "Win a free Ethernet header in every packet" */
3545 vec_validate_aligned (l2, 13, sizeof (u32x4));
3549 vec_append_aligned (match, l3, sizeof (u32x4));
3554 vec_append_aligned (match, l4, sizeof (u32x4));
3559 /* Make sure the vector is big enough even if key is all 0's */
3560 vec_validate_aligned
3561 (match, ((match_n_vectors + skip_n_vectors) * sizeof (u32x4)) - 1,
3564 /* Set size, include skipped vectors */
3565 _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4);
3576 api_get_node_index (vat_main_t *vam)
3578 unformat_input_t *i = vam->input;
3579 vl_api_get_node_index_t *mp;
3583 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3585 if (unformat (i, "node %s", &name))
3592 errmsg ("node name required");
3595 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
3597 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
3601 M (GET_NODE_INDEX, mp);
3602 clib_memcpy (mp->node_name, name, vec_len (name));
3611 api_get_next_index (vat_main_t *vam)
3613 unformat_input_t *i = vam->input;
3614 vl_api_get_next_index_t *mp;
3615 u8 *node_name = 0, *next_node_name = 0;
3618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3620 if (unformat (i, "node-name %s", &node_name))
3622 else if (unformat (i, "next-node-name %s", &next_node_name))
3628 errmsg ("node name required");
3631 if (vec_len (node_name) >= ARRAY_LEN (mp->node_name))
3633 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
3637 if (next_node_name == 0)
3639 errmsg ("next node name required");
3642 if (vec_len (next_node_name) >= ARRAY_LEN (mp->next_name))
3644 errmsg ("next node name too long, max %d", ARRAY_LEN (mp->next_name));
3648 M (GET_NEXT_INDEX, mp);
3649 clib_memcpy (mp->node_name, node_name, vec_len (node_name));
3650 clib_memcpy (mp->next_name, next_node_name, vec_len (next_node_name));
3651 vec_free (node_name);
3652 vec_free (next_node_name);
3660 api_add_node_next (vat_main_t *vam)
3662 unformat_input_t *i = vam->input;
3663 vl_api_add_node_next_t *mp;
3668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3670 if (unformat (i, "node %s", &name))
3672 else if (unformat (i, "next %s", &next))
3679 errmsg ("node name required");
3682 if (vec_len (name) >= ARRAY_LEN (mp->node_name))
3684 errmsg ("node name too long, max %d", ARRAY_LEN (mp->node_name));
3689 errmsg ("next node required");
3692 if (vec_len (next) >= ARRAY_LEN (mp->next_name))
3694 errmsg ("next name too long, max %d", ARRAY_LEN (mp->next_name));
3698 M (ADD_NODE_NEXT, mp);
3699 clib_memcpy (mp->node_name, name, vec_len (name));
3700 clib_memcpy (mp->next_name, next, vec_len (next));
3709 #define foreach_vtr_op \
3710 _ ("disable", L2_VTR_DISABLED) \
3711 _ ("push-1", L2_VTR_PUSH_1) \
3712 _ ("push-2", L2_VTR_PUSH_2) \
3713 _ ("pop-1", L2_VTR_POP_1) \
3714 _ ("pop-2", L2_VTR_POP_2) \
3715 _ ("translate-1-1", L2_VTR_TRANSLATE_1_1) \
3716 _ ("translate-1-2", L2_VTR_TRANSLATE_1_2) \
3717 _ ("translate-2-1", L2_VTR_TRANSLATE_2_1) \
3718 _ ("translate-2-2", L2_VTR_TRANSLATE_2_2)
3721 api_show_version (vat_main_t *vam)
3723 vl_api_show_version_t *mp;
3726 M (SHOW_VERSION, mp);
3734 api_interface_name_renumber (vat_main_t *vam)
3736 unformat_input_t *line_input = vam->input;
3737 vl_api_interface_name_renumber_t *mp;
3738 u32 sw_if_index = ~0;
3739 u32 new_show_dev_instance = ~0;
3742 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
3744 if (unformat (line_input, "%U", api_unformat_sw_if_index, vam,
3747 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
3749 else if (unformat (line_input, "new_show_dev_instance %d",
3750 &new_show_dev_instance))
3756 if (sw_if_index == ~0)
3758 errmsg ("missing interface name or sw_if_index");
3762 if (new_show_dev_instance == ~0)
3764 errmsg ("missing new_show_dev_instance");
3768 M (INTERFACE_NAME_RENUMBER, mp);
3770 mp->sw_if_index = ntohl (sw_if_index);
3771 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
3779 api_get_first_msg_id (vat_main_t *vam)
3781 vl_api_get_first_msg_id_t *mp;
3782 unformat_input_t *i = vam->input;
3787 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3789 if (unformat (i, "client %s", &name))
3797 errmsg ("missing client name");
3802 if (vec_len (name) > 63)
3804 errmsg ("client name too long");
3808 M (GET_FIRST_MSG_ID, mp);
3809 clib_memcpy (mp->name, name, vec_len (name));
3816 api_get_node_graph (vat_main_t *vam)
3818 vl_api_get_node_graph_t *mp;
3821 M (GET_NODE_GRAPH, mp);
3825 /* Wait for the reply */
3831 api_delete_subif (vat_main_t * vam)
3833 unformat_input_t *i = vam->input;
3834 vl_api_delete_subif_t *mp;
3835 u32 sw_if_index = ~0;
3838 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3840 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3842 if (unformat (i, "sw_if_index %d", &sw_if_index))
3848 if (sw_if_index == ~0)
3850 errmsg ("missing sw_if_index");
3854 /* Construct the API message */
3855 M (DELETE_SUBIF, mp);
3856 mp->sw_if_index = ntohl (sw_if_index);
3863 #define foreach_pbb_vtr_op \
3864 _("disable", L2_VTR_DISABLED) \
3865 _("pop", L2_VTR_POP_2) \
3866 _("push", L2_VTR_PUSH_2)
3870 api_sw_interface_tag_add_del (vat_main_t * vam)
3872 unformat_input_t *i = vam->input;
3873 vl_api_sw_interface_tag_add_del_t *mp;
3874 u32 sw_if_index = ~0;
3879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3881 if (unformat (i, "tag %s", &tag))
3883 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3885 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3887 else if (unformat (i, "del"))
3893 if (sw_if_index == ~0)
3895 errmsg ("missing interface name or sw_if_index");
3899 if (enable && (tag == 0))
3901 errmsg ("no tag specified");
3905 /* Construct the API message */
3906 M (SW_INTERFACE_TAG_ADD_DEL, mp);
3907 mp->sw_if_index = ntohl (sw_if_index);
3908 mp->is_add = enable;
3910 strncpy ((char *) mp->tag, (char *) tag, ARRAY_LEN (mp->tag) - 1);
3919 api_sw_interface_add_del_mac_address (vat_main_t * vam)
3921 unformat_input_t *i = vam->input;
3922 vl_api_mac_address_t mac = { 0 };
3923 vl_api_sw_interface_add_del_mac_address_t *mp;
3924 u32 sw_if_index = ~0;
3929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3931 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3933 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3935 else if (unformat (i, "%U", unformat_vl_api_mac_address, &mac))
3937 else if (unformat (i, "del"))
3943 if (sw_if_index == ~0)
3945 errmsg ("missing interface name or sw_if_index");
3951 errmsg ("missing MAC address");
3955 /* Construct the API message */
3956 M (SW_INTERFACE_ADD_DEL_MAC_ADDRESS, mp);
3957 mp->sw_if_index = ntohl (sw_if_index);
3958 mp->is_add = is_add;
3959 clib_memcpy (&mp->addr, &mac, sizeof (mac));
3967 api_hw_interface_set_mtu (vat_main_t * vam)
3969 unformat_input_t *i = vam->input;
3970 vl_api_hw_interface_set_mtu_t *mp;
3971 u32 sw_if_index = ~0;
3975 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3977 if (unformat (i, "mtu %d", &mtu))
3979 if (unformat (i, "%U", api_unformat_sw_if_index, vam, &sw_if_index))
3981 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3987 if (sw_if_index == ~0)
3989 errmsg ("missing interface name or sw_if_index");
3995 errmsg ("no mtu specified");
3999 /* Construct the API message */
4000 M (HW_INTERFACE_SET_MTU, mp);
4001 mp->sw_if_index = ntohl (sw_if_index);
4002 mp->mtu = ntohs ((u16) mtu);
4009 static void vl_api_app_namespace_add_del_reply_t_handler
4010 (vl_api_app_namespace_add_del_reply_t * mp)
4012 vat_main_t *vam = &vat_main;
4013 i32 retval = ntohl (mp->retval);
4014 if (vam->async_mode)
4016 vam->async_errors += (retval < 0);
4020 vam->retval = retval;
4022 errmsg ("app ns index %d\n", ntohl (mp->appns_index));
4023 vam->result_ready = 1;
4027 static void vl_api_app_namespace_add_del_reply_t_handler_json
4028 (vl_api_app_namespace_add_del_reply_t * mp)
4030 vat_main_t *vam = &vat_main;
4031 vat_json_node_t node;
4033 vat_json_init_object (&node);
4034 vat_json_object_add_int (&node, "retval", ntohl (mp->retval));
4035 vat_json_object_add_uint (&node, "appns_index", ntohl (mp->appns_index));
4037 vat_json_print (vam->ofp, &node);
4038 vat_json_free (&node);
4040 vam->retval = ntohl (mp->retval);
4041 vam->result_ready = 1;
4045 api_app_namespace_add_del (vat_main_t * vam)
4047 vl_api_app_namespace_add_del_t *mp;
4048 unformat_input_t *i = vam->input;
4049 u8 *ns_id = 0, secret_set = 0, sw_if_index_set = 0;
4050 u32 sw_if_index, ip4_fib_id, ip6_fib_id;
4054 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4056 if (unformat (i, "id %_%v%_", &ns_id))
4058 else if (unformat (i, "secret %lu", &secret))
4060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4061 sw_if_index_set = 1;
4062 else if (unformat (i, "ip4_fib_id %d", &ip4_fib_id))
4064 else if (unformat (i, "ip6_fib_id %d", &ip6_fib_id))
4069 if (!ns_id || !secret_set || !sw_if_index_set)
4071 errmsg ("namespace id, secret and sw_if_index must be set");
4074 if (vec_len (ns_id) > 64)
4076 errmsg ("namespace id too long");
4079 M (APP_NAMESPACE_ADD_DEL, mp);
4081 vl_api_vec_to_api_string (ns_id, &mp->namespace_id);
4082 mp->secret = clib_host_to_net_u64 (secret);
4083 mp->sw_if_index = clib_host_to_net_u32 (sw_if_index);
4084 mp->ip4_fib_id = clib_host_to_net_u32 (ip4_fib_id);
4085 mp->ip6_fib_id = clib_host_to_net_u32 (ip6_fib_id);
4093 api_sock_init_shm (vat_main_t * vam)
4095 #if VPP_API_TEST_BUILTIN == 0
4096 unformat_input_t *i = vam->input;
4097 vl_api_shm_elem_config_t *config = 0;
4098 u64 size = 64 << 20;
4101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4103 if (unformat (i, "size %U", unformat_memory_size, &size))
4110 * Canned custom ring allocator config.
4111 * Should probably parse all of this
4113 vec_validate (config, 6);
4114 config[0].type = VL_API_VLIB_RING;
4115 config[0].size = 256;
4116 config[0].count = 32;
4118 config[1].type = VL_API_VLIB_RING;
4119 config[1].size = 1024;
4120 config[1].count = 16;
4122 config[2].type = VL_API_VLIB_RING;
4123 config[2].size = 4096;
4124 config[2].count = 2;
4126 config[3].type = VL_API_CLIENT_RING;
4127 config[3].size = 256;
4128 config[3].count = 32;
4130 config[4].type = VL_API_CLIENT_RING;
4131 config[4].size = 1024;
4132 config[4].count = 16;
4134 config[5].type = VL_API_CLIENT_RING;
4135 config[5].size = 4096;
4136 config[5].count = 2;
4138 config[6].type = VL_API_QUEUE;
4139 config[6].count = 128;
4140 config[6].size = sizeof (uword);
4142 rv = vl_socket_client_init_shm (config, 1 /* want_pthread */ );
4144 vam->client_index_invalid = 1;
4152 vl_api_session_rules_details_t_handler (vl_api_session_rules_details_t * mp)
4154 vat_main_t *vam = &vat_main;
4155 fib_prefix_t lcl, rmt;
4157 ip_prefix_decode (&mp->lcl, &lcl);
4158 ip_prefix_decode (&mp->rmt, &rmt);
4160 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
4163 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
4164 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
4165 mp->scope, format_ip4_address, &lcl.fp_addr.ip4, lcl.fp_len,
4166 clib_net_to_host_u16 (mp->lcl_port), format_ip4_address,
4167 &rmt.fp_addr.ip4, rmt.fp_len,
4168 clib_net_to_host_u16 (mp->rmt_port),
4169 clib_net_to_host_u32 (mp->action_index), mp->tag);
4174 "appns %u tp %u scope %d %U/%d %d %U/%d %d action: %d tag: %s",
4175 clib_net_to_host_u32 (mp->appns_index), mp->transport_proto,
4176 mp->scope, format_ip6_address, &lcl.fp_addr.ip6, lcl.fp_len,
4177 clib_net_to_host_u16 (mp->lcl_port), format_ip6_address,
4178 &rmt.fp_addr.ip6, rmt.fp_len,
4179 clib_net_to_host_u16 (mp->rmt_port),
4180 clib_net_to_host_u32 (mp->action_index), mp->tag);
4185 vl_api_session_rules_details_t_handler_json (vl_api_session_rules_details_t *
4188 vat_main_t *vam = &vat_main;
4189 vat_json_node_t *node = NULL;
4190 struct in6_addr ip6;
4193 fib_prefix_t lcl, rmt;
4195 ip_prefix_decode (&mp->lcl, &lcl);
4196 ip_prefix_decode (&mp->rmt, &rmt);
4198 if (VAT_JSON_ARRAY != vam->json_tree.type)
4200 ASSERT (VAT_JSON_NONE == vam->json_tree.type);
4201 vat_json_init_array (&vam->json_tree);
4203 node = vat_json_array_add (&vam->json_tree);
4204 vat_json_init_object (node);
4206 vat_json_object_add_uint (node, "appns_index",
4207 clib_net_to_host_u32 (mp->appns_index));
4208 vat_json_object_add_uint (node, "transport_proto", mp->transport_proto);
4209 vat_json_object_add_uint (node, "scope", mp->scope);
4210 vat_json_object_add_uint (node, "action_index",
4211 clib_net_to_host_u32 (mp->action_index));
4212 vat_json_object_add_uint (node, "lcl_port",
4213 clib_net_to_host_u16 (mp->lcl_port));
4214 vat_json_object_add_uint (node, "rmt_port",
4215 clib_net_to_host_u16 (mp->rmt_port));
4216 vat_json_object_add_uint (node, "lcl_plen", lcl.fp_len);
4217 vat_json_object_add_uint (node, "rmt_plen", rmt.fp_len);
4218 vat_json_object_add_string_copy (node, "tag", mp->tag);
4219 if (lcl.fp_proto == FIB_PROTOCOL_IP4)
4221 clib_memcpy (&ip4, &lcl.fp_addr.ip4, sizeof (ip4));
4222 vat_json_object_add_ip4 (node, "lcl_ip", ip4);
4223 clib_memcpy (&ip4, &rmt.fp_addr.ip4, sizeof (ip4));
4224 vat_json_object_add_ip4 (node, "rmt_ip", ip4);
4228 clib_memcpy (&ip6, &lcl.fp_addr.ip6, sizeof (ip6));
4229 vat_json_object_add_ip6 (node, "lcl_ip", ip6);
4230 clib_memcpy (&ip6, &rmt.fp_addr.ip6, sizeof (ip6));
4231 vat_json_object_add_ip6 (node, "rmt_ip", ip6);
4236 api_session_rule_add_del (vat_main_t * vam)
4238 vl_api_session_rule_add_del_t *mp;
4239 unformat_input_t *i = vam->input;
4240 u32 proto = ~0, lcl_port, rmt_port, action = 0, lcl_plen, rmt_plen;
4241 u32 appns_index = 0, scope = 0;
4242 ip4_address_t lcl_ip4, rmt_ip4;
4243 ip6_address_t lcl_ip6, rmt_ip6;
4244 u8 is_ip4 = 1, conn_set = 0;
4245 u8 is_add = 1, *tag = 0;
4247 fib_prefix_t lcl, rmt;
4249 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4251 if (unformat (i, "del"))
4253 else if (unformat (i, "add"))
4255 else if (unformat (i, "proto tcp"))
4257 else if (unformat (i, "proto udp"))
4259 else if (unformat (i, "appns %d", &appns_index))
4261 else if (unformat (i, "scope %d", &scope))
4263 else if (unformat (i, "tag %_%v%_", &tag))
4267 (i, "%U/%d %d %U/%d %d", unformat_ip4_address, &lcl_ip4,
4268 &lcl_plen, &lcl_port, unformat_ip4_address, &rmt_ip4, &rmt_plen,
4276 (i, "%U/%d %d %U/%d %d", unformat_ip6_address, &lcl_ip6,
4277 &lcl_plen, &lcl_port, unformat_ip6_address, &rmt_ip6, &rmt_plen,
4283 else if (unformat (i, "action %d", &action))
4288 if (proto == ~0 || !conn_set || action == ~0)
4290 errmsg ("transport proto, connection and action must be set");
4296 errmsg ("scope should be 0-3");
4300 M (SESSION_RULE_ADD_DEL, mp);
4302 clib_memset (&lcl, 0, sizeof (lcl));
4303 clib_memset (&rmt, 0, sizeof (rmt));
4306 ip_set (&lcl.fp_addr, &lcl_ip4, 1);
4307 ip_set (&rmt.fp_addr, &rmt_ip4, 1);
4308 lcl.fp_len = lcl_plen;
4309 rmt.fp_len = rmt_plen;
4313 ip_set (&lcl.fp_addr, &lcl_ip6, 0);
4314 ip_set (&rmt.fp_addr, &rmt_ip6, 0);
4315 lcl.fp_len = lcl_plen;
4316 rmt.fp_len = rmt_plen;
4320 ip_prefix_encode (&lcl, &mp->lcl);
4321 ip_prefix_encode (&rmt, &mp->rmt);
4322 mp->lcl_port = clib_host_to_net_u16 ((u16) lcl_port);
4323 mp->rmt_port = clib_host_to_net_u16 ((u16) rmt_port);
4324 mp->transport_proto =
4325 proto ? TRANSPORT_PROTO_API_UDP : TRANSPORT_PROTO_API_TCP;
4326 mp->action_index = clib_host_to_net_u32 (action);
4327 mp->appns_index = clib_host_to_net_u32 (appns_index);
4329 mp->is_add = is_add;
4332 clib_memcpy (mp->tag, tag, vec_len (tag));
4342 api_session_rules_dump (vat_main_t * vam)
4344 vl_api_session_rules_dump_t *mp;
4345 vl_api_control_ping_t *mp_ping;
4348 if (!vam->json_output)
4350 print (vam->ofp, "%=20s", "Session Rules");
4353 M (SESSION_RULES_DUMP, mp);
4357 /* Use a control ping for synchronization */
4358 MPING (CONTROL_PING, mp_ping);
4361 /* Wait for a reply... */
4367 q_or_quit (vat_main_t * vam)
4369 #if VPP_API_TEST_BUILTIN == 0
4370 longjmp (vam->jump_buf, 1);
4372 return 0; /* not so much */
4376 q (vat_main_t * vam)
4378 return q_or_quit (vam);
4382 quit (vat_main_t * vam)
4384 return q_or_quit (vam);
4388 comment (vat_main_t * vam)
4394 elog_save (vat_main_t * vam)
4396 #if VPP_API_TEST_BUILTIN == 0
4397 elog_main_t *em = &vam->elog_main;
4398 unformat_input_t *i = vam->input;
4399 char *file, *chroot_file;
4400 clib_error_t *error;
4402 if (!unformat (i, "%s", &file))
4404 errmsg ("expected file name, got `%U'", format_unformat_error, i);
4408 /* It's fairly hard to get "../oopsie" through unformat; just in case */
4409 if (strstr (file, "..") || index (file, '/'))
4411 errmsg ("illegal characters in filename '%s'", file);
4415 chroot_file = (char *) format (0, "/tmp/%s%c", file, 0);
4419 errmsg ("Saving %wd of %wd events to %s",
4420 elog_n_events_in_buffer (em),
4421 elog_buffer_capacity (em), chroot_file);
4423 error = elog_write_file (em, chroot_file, 1 /* flush ring */ );
4424 vec_free (chroot_file);
4427 clib_error_report (error);
4429 errmsg ("Use the vpp event loger...");
4436 elog_setup (vat_main_t * vam)
4438 #if VPP_API_TEST_BUILTIN == 0
4439 elog_main_t *em = &vam->elog_main;
4440 unformat_input_t *i = vam->input;
4441 u32 nevents = 128 << 10;
4443 (void) unformat (i, "nevents %d", &nevents);
4445 elog_init (em, nevents);
4446 vl_api_set_elog_main (em);
4447 vl_api_set_elog_trace_api_messages (1);
4448 errmsg ("Event logger initialized with %u events", nevents);
4450 errmsg ("Use the vpp event loger...");
4456 elog_enable (vat_main_t * vam)
4458 #if VPP_API_TEST_BUILTIN == 0
4459 elog_main_t *em = &vam->elog_main;
4461 elog_enable_disable (em, 1 /* enable */ );
4462 vl_api_set_elog_trace_api_messages (1);
4463 errmsg ("Event logger enabled...");
4465 errmsg ("Use the vpp event loger...");
4471 elog_disable (vat_main_t * vam)
4473 #if VPP_API_TEST_BUILTIN == 0
4474 elog_main_t *em = &vam->elog_main;
4476 elog_enable_disable (em, 0 /* enable */ );
4477 vl_api_set_elog_trace_api_messages (1);
4478 errmsg ("Event logger disabled...");
4480 errmsg ("Use the vpp event loger...");
4486 statseg (vat_main_t * vam)
4488 ssvm_private_t *ssvmp = &vam->stat_segment;
4489 ssvm_shared_header_t *shared_header = ssvmp->sh;
4490 vlib_counter_t **counters;
4491 u64 thread0_index1_packets;
4492 u64 thread0_index1_bytes;
4493 f64 vector_rate, input_rate;
4496 uword *counter_vector_by_name;
4497 if (vam->stat_segment_lockp == 0)
4499 errmsg ("Stat segment not mapped...");
4503 /* look up "/if/rx for sw_if_index 1 as a test */
4505 clib_spinlock_lock (vam->stat_segment_lockp);
4507 counter_vector_by_name = (uword *) shared_header->opaque[1];
4509 p = hash_get_mem (counter_vector_by_name, "/if/rx");
4512 clib_spinlock_unlock (vam->stat_segment_lockp);
4513 errmsg ("/if/tx not found?");
4517 /* Fish per-thread vector of combined counters from shared memory */
4518 counters = (vlib_counter_t **) p[0];
4520 if (vec_len (counters[0]) < 2)
4522 clib_spinlock_unlock (vam->stat_segment_lockp);
4523 errmsg ("/if/tx vector length %d", vec_len (counters[0]));
4527 /* Read thread 0 sw_if_index 1 counter */
4528 thread0_index1_packets = counters[0][1].packets;
4529 thread0_index1_bytes = counters[0][1].bytes;
4531 p = hash_get_mem (counter_vector_by_name, "vector_rate");
4534 clib_spinlock_unlock (vam->stat_segment_lockp);
4535 errmsg ("vector_rate not found?");
4539 vector_rate = *(f64 *) (p[0]);
4540 p = hash_get_mem (counter_vector_by_name, "input_rate");
4543 clib_spinlock_unlock (vam->stat_segment_lockp);
4544 errmsg ("input_rate not found?");
4547 input_rate = *(f64 *) (p[0]);
4549 clib_spinlock_unlock (vam->stat_segment_lockp);
4551 print (vam->ofp, "vector_rate %.2f input_rate %.2f",
4552 vector_rate, input_rate);
4553 print (vam->ofp, "thread 0 sw_if_index 1 rx pkts %lld, bytes %lld",
4554 thread0_index1_packets, thread0_index1_bytes);
4560 cmd_cmp (void *a1, void *a2)
4565 return strcmp ((char *) (c1[0]), (char *) (c2[0]));
4569 help (vat_main_t * vam)
4574 unformat_input_t *i = vam->input;
4577 if (unformat (i, "%s", &name))
4583 hs = hash_get_mem (vam->help_by_name, name);
4585 print (vam->ofp, "usage: %s %s", name, hs[0]);
4587 print (vam->ofp, "No such msg / command '%s'", name);
4592 print (vam->ofp, "Help is available for the following:");
4595 hash_foreach_pair (p, vam->function_by_name,
4597 vec_add1 (cmds, (u8 *)(p->key));
4601 vec_sort_with_function (cmds, cmd_cmp);
4603 for (j = 0; j < vec_len (cmds); j++)
4604 print (vam->ofp, "%s", cmds[j]);
4611 set (vat_main_t * vam)
4613 u8 *name = 0, *value = 0;
4614 unformat_input_t *i = vam->input;
4616 if (unformat (i, "%s", &name))
4618 /* The input buffer is a vector, not a string. */
4619 value = vec_dup (i->buffer);
4620 vec_delete (value, i->index, 0);
4621 /* Almost certainly has a trailing newline */
4622 if (value[vec_len (value) - 1] == '\n')
4623 value[vec_len (value) - 1] = 0;
4624 /* Make sure it's a proper string, one way or the other */
4625 vec_add1 (value, 0);
4626 (void) clib_macro_set_value (&vam->macro_main,
4627 (char *) name, (char *) value);
4630 errmsg ("usage: set <name> <value>");
4638 unset (vat_main_t * vam)
4642 if (unformat (vam->input, "%s", &name))
4643 if (clib_macro_unset (&vam->macro_main, (char *) name) == 1)
4644 errmsg ("unset: %s wasn't set", name);
4657 macro_sort_cmp (void *a1, void *a2)
4659 macro_sort_t *s1 = a1;
4660 macro_sort_t *s2 = a2;
4662 return strcmp ((char *) (s1->name), (char *) (s2->name));
4666 dump_macro_table (vat_main_t * vam)
4668 macro_sort_t *sort_me = 0, *sm;
4673 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
4675 vec_add2 (sort_me, sm, 1);
4676 sm->name = (u8 *)(p->key);
4677 sm->value = (u8 *) (p->value[0]);
4681 vec_sort_with_function (sort_me, macro_sort_cmp);
4683 if (vec_len (sort_me))
4684 print (vam->ofp, "%-15s%s", "Name", "Value");
4686 print (vam->ofp, "The macro table is empty...");
4688 for (i = 0; i < vec_len (sort_me); i++)
4689 print (vam->ofp, "%-15s%s", sort_me[i].name, sort_me[i].value);
4694 value_sort_cmp (void *a1, void *a2)
4696 name_sort_t *n1 = a1;
4697 name_sort_t *n2 = a2;
4699 if (n1->value < n2->value)
4701 if (n1->value > n2->value)
4708 dump_msg_api_table (vat_main_t * vam)
4710 api_main_t *am = vlibapi_get_main ();
4711 name_sort_t *nses = 0, *ns;
4716 hash_foreach_pair (hp, am->msg_index_by_name_and_crc,
4718 vec_add2 (nses, ns, 1);
4719 ns->name = (u8 *)(hp->key);
4720 ns->value = (u32) hp->value[0];
4724 vec_sort_with_function (nses, value_sort_cmp);
4726 for (i = 0; i < vec_len (nses); i++)
4727 print (vam->ofp, " [%d]: %s", nses[i].value, nses[i].name);
4733 get_msg_id (vat_main_t * vam)
4738 if (unformat (vam->input, "%s", &name_and_crc))
4740 message_index = vl_msg_api_get_msg_index (name_and_crc);
4741 if (message_index == ~0)
4743 print (vam->ofp, " '%s' not found", name_and_crc);
4746 print (vam->ofp, " '%s' has message index %d",
4747 name_and_crc, message_index);
4750 errmsg ("name_and_crc required...");
4755 search_node_table (vat_main_t * vam)
4757 unformat_input_t *line_input = vam->input;
4760 vlib_node_t *node, *next_node;
4763 if (vam->graph_node_index_by_name == 0)
4765 print (vam->ofp, "Node table empty, issue get_node_graph...");
4769 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
4771 if (unformat (line_input, "%s", &node_to_find))
4773 vec_add1 (node_to_find, 0);
4774 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
4777 print (vam->ofp, "%s not found...", node_to_find);
4780 node = vam->graph_nodes[0][p[0]];
4781 print (vam->ofp, "[%d] %s", p[0], node->name);
4782 for (j = 0; j < vec_len (node->next_nodes); j++)
4784 if (node->next_nodes[j] != ~0)
4786 next_node = vam->graph_nodes[0][node->next_nodes[j]];
4787 print (vam->ofp, " [%d] %s", j, next_node->name);
4794 clib_warning ("parse error '%U'", format_unformat_error,
4800 vec_free (node_to_find);
4809 script (vat_main_t * vam)
4811 #if (VPP_API_TEST_BUILTIN==0)
4813 char *save_current_file;
4814 unformat_input_t save_input;
4815 jmp_buf save_jump_buf;
4816 u32 save_line_number;
4818 FILE *new_fp, *save_ifp;
4820 if (unformat (vam->input, "%s", &s))
4822 new_fp = fopen ((char *) s, "r");
4825 errmsg ("Couldn't open script file %s", s);
4832 errmsg ("Missing script name");
4836 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
4837 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
4838 save_ifp = vam->ifp;
4839 save_line_number = vam->input_line_number;
4840 save_current_file = (char *) vam->current_file;
4842 vam->input_line_number = 0;
4844 vam->current_file = s;
4847 clib_memcpy (&vam->input, &save_input, sizeof (save_input));
4848 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
4849 vam->ifp = save_ifp;
4850 vam->input_line_number = save_line_number;
4851 vam->current_file = (u8 *) save_current_file;
4856 clib_warning ("use the exec command...");
4862 echo (vat_main_t * vam)
4864 print (vam->ofp, "%v", vam->input->buffer);
4868 /* List of API message constructors, CLI names map to api_xxx */
4869 #define foreach_vpe_api_msg \
4870 _(create_loopback,"[mac <mac-addr>] [instance <instance>]") \
4871 _(sw_interface_dump,"") \
4872 _(sw_interface_set_flags, \
4873 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
4874 _(sw_interface_add_del_address, \
4875 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
4876 _(sw_interface_set_rx_placement, \
4877 "<intfc> | sw_if_index <id> [queue <id>] [worker <id> | main]") \
4878 _(sw_interface_rx_placement_dump, \
4879 "[<intfc> | sw_if_index <id>]") \
4880 _(sw_interface_set_table, \
4881 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
4882 _(sw_interface_set_unnumbered, \
4883 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
4884 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
4885 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
4886 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
4887 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
4888 "[outer_vlan_id_any][inner_vlan_id_any]") \
4889 _(get_node_index, "node <node-name") \
4890 _(add_node_next, "node <node-name> next <next-node-name>") \
4891 _(show_version, "") \
4892 _(show_threads, "") \
4893 _(interface_name_renumber, \
4894 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
4895 _(delete_loopback,"sw_if_index <nn>") \
4896 _(want_interface_events, "enable|disable") \
4897 _(get_first_msg_id, "client <name>") \
4898 _(get_node_graph, " ") \
4899 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
4900 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
4901 _(delete_subif,"<intfc> | sw_if_index <nn>") \
4902 _(sw_interface_tag_add_del, "<intfc> | sw_if_index <nn> tag <text>" \
4904 _(sw_interface_add_del_mac_address, "<intfc> | sw_if_index <nn> " \
4905 "mac <mac-address> [del]") \
4906 _(hw_interface_set_mtu, "<intfc> | hw_if_index <nn> mtu <nn>") \
4907 _(sw_interface_get_table, "<intfc> | sw_if_index <id> [ipv6]") \
4908 _(sock_init_shm, "size <nnn>") \
4909 _(app_namespace_add_del, "[add] id <ns-id> secret <nn> sw_if_index <nn>")\
4910 _(session_rule_add_del, "[add|del] proto <tcp/udp> <lcl-ip>/<plen> " \
4911 "<lcl-port> <rmt-ip>/<plen> <rmt-port> action <nn>") \
4912 _(session_rules_dump, "") \
4914 /* List of command functions, CLI names map directly to functions */
4915 #define foreach_cli_function \
4916 _(comment, "usage: comment <ignore-rest-of-line>") \
4917 _(dump_interface_table, "usage: dump_interface_table") \
4918 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
4919 _(dump_macro_table, "usage: dump_macro_table ") \
4920 _(dump_msg_api_table, "usage: dump_msg_api_table") \
4921 _(elog_setup, "usage: elog_setup [nevents, default 128K]") \
4922 _(elog_disable, "usage: elog_disable") \
4923 _(elog_enable, "usage: elog_enable") \
4924 _(elog_save, "usage: elog_save <filename>") \
4925 _(get_msg_id, "usage: get_msg_id name_and_crc") \
4926 _(echo, "usage: echo <message>") \
4927 _(exec, "usage: exec <vpe-debug-CLI-command>") \
4928 _(exec_inband, "usage: exec_inband <vpe-debug-CLI-command>") \
4929 _(help, "usage: help") \
4930 _(q, "usage: quit") \
4931 _(quit, "usage: quit") \
4932 _(search_node_table, "usage: search_node_table <name>...") \
4933 _(set, "usage: set <variable-name> <value>") \
4934 _(script, "usage: script <file-name>") \
4935 _(statseg, "usage: statseg") \
4936 _(unset, "usage: unset <variable-name>")
4939 static void vl_api_##n##_t_handler_uni \
4940 (vl_api_##n##_t * mp) \
4942 vat_main_t * vam = &vat_main; \
4943 if (vam->json_output) { \
4944 vl_api_##n##_t_handler_json(mp); \
4946 vl_api_##n##_t_handler(mp); \
4949 foreach_vpe_api_reply_msg;
4950 #if VPP_API_TEST_BUILTIN == 0
4951 foreach_standalone_reply_msg;
4956 vat_api_hookup (vat_main_t * vam)
4959 vl_msg_api_set_handlers(VL_API_##N, #n, \
4960 vl_api_##n##_t_handler_uni, \
4962 vl_api_##n##_t_endian, \
4963 vl_api_##n##_t_print, \
4964 sizeof(vl_api_##n##_t), 1);
4965 foreach_vpe_api_reply_msg;
4966 #if VPP_API_TEST_BUILTIN == 0
4967 foreach_standalone_reply_msg;
4971 #if (VPP_API_TEST_BUILTIN==0)
4972 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
4974 vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));
4976 vam->function_by_name = hash_create_string (0, sizeof (uword));
4978 vam->help_by_name = hash_create_string (0, sizeof (uword));
4981 /* API messages we can send */
4982 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
4983 foreach_vpe_api_msg;
4987 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
4988 foreach_vpe_api_msg;
4992 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
4993 foreach_cli_function;
4997 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
4998 foreach_cli_function;
5002 #if VPP_API_TEST_BUILTIN
5003 static clib_error_t *
5004 vat_api_hookup_shim (vlib_main_t * vm)
5006 vat_api_hookup (&vat_main);
5010 VLIB_API_INIT_FUNCTION (vat_api_hookup_shim);
5014 * fd.io coding-style-patch-verification: ON
5017 * eval: (c-set-style "gnu")