2 *------------------------------------------------------------------
5 * Copyright (c) 2014 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 <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vlibsocket/api.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2tp/l2tp.h>
28 #include <vnet/vxlan/vxlan.h>
29 #include <vnet/gre/gre.h>
30 #include <vnet/vxlan-gpe/vxlan_gpe.h>
31 #include <vnet/lisp-gpe/lisp_gpe.h>
33 #include <vpp-api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
37 #include <vnet/mpls-gre/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
40 #include <vnet/ipsec/ikev2.h>
44 #include <vnet/map/map.h>
45 #include <vnet/cop/cop.h>
46 #include <vnet/ip/ip6_hop_by_hop.h>
47 #include <vnet/policer/xlate.h>
48 #include <vnet/policer/policer.h>
50 #include "vat/json_format.h"
52 #define vl_typedefs /* define message structures */
53 #include <vpp-api/vpe_all_api_h.h>
56 /* declare message handlers for each api */
58 #define vl_endianfun /* define message structures */
59 #include <vpp-api/vpe_all_api_h.h>
62 /* instantiate all the print functions we know about */
63 #define vl_print(handle, ...)
65 #include <vpp-api/vpe_all_api_h.h>
68 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
70 vat_main_t * vam = va_arg (*args, vat_main_t *);
71 u32 * result = va_arg (*args, u32 *);
75 if (!unformat (input, "%s", &if_name))
78 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
85 /* Parse an IP4 address %d.%d.%d.%d. */
86 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
88 u8 * result = va_arg (*args, u8 *);
91 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
94 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
107 unformat_ethernet_address (unformat_input_t * input, va_list * args)
109 u8 * result = va_arg (*args, u8 *);
112 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
113 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
117 for (i = 0; i < 6; i++)
118 if (a[i] >= (1 << 8))
121 for (i = 0; i < 6; i++)
127 /* Returns ethernet type as an int in host byte order. */
129 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
132 u16 * result = va_arg (*args, u16 *);
136 if (unformat (input, "0x%x", &type)
137 || unformat (input, "%d", &type))
139 if (type >= (1 << 16))
147 /* Parse an IP6 address. */
148 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
150 ip6_address_t * result = va_arg (*args, ip6_address_t *);
152 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
153 uword c, n_colon, double_colon_index;
155 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
156 double_colon_index = ARRAY_LEN (hex_quads);
157 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
160 if (c >= '0' && c <= '9')
162 else if (c >= 'a' && c <= 'f')
163 hex_digit = c + 10 - 'a';
164 else if (c >= 'A' && c <= 'F')
165 hex_digit = c + 10 - 'A';
166 else if (c == ':' && n_colon < 2)
170 unformat_put_input (input);
174 /* Too many hex quads. */
175 if (n_hex_quads >= ARRAY_LEN (hex_quads))
180 hex_quad = (hex_quad << 4) | hex_digit;
182 /* Hex quad must fit in 16 bits. */
183 if (n_hex_digits >= 4)
190 /* Save position of :: */
193 /* More than one :: ? */
194 if (double_colon_index < ARRAY_LEN (hex_quads))
196 double_colon_index = n_hex_quads;
199 if (n_colon > 0 && n_hex_digits > 0)
201 hex_quads[n_hex_quads++] = hex_quad;
207 if (n_hex_digits > 0)
208 hex_quads[n_hex_quads++] = hex_quad;
213 /* Expand :: to appropriate number of zero hex quads. */
214 if (double_colon_index < ARRAY_LEN (hex_quads))
216 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
218 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
219 hex_quads[n_zero + i] = hex_quads[i];
221 for (i = 0; i < n_zero; i++)
222 hex_quads[double_colon_index + i] = 0;
224 n_hex_quads = ARRAY_LEN (hex_quads);
227 /* Too few hex quads given. */
228 if (n_hex_quads < ARRAY_LEN (hex_quads))
231 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
232 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
239 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
242 u32 * r = va_arg (*args, u32 *);
245 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
246 foreach_ipsec_policy_action
257 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
260 u32 * r = va_arg (*args, u32 *);
263 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
264 foreach_ipsec_crypto_alg
275 format_ipsec_crypto_alg (u8 * s, va_list * args)
278 u32 i = va_arg (*args, u32);
283 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
284 foreach_ipsec_crypto_alg
287 return format (s, "unknown");
289 return format (s, "%s", t);
291 return format (s, "Unimplemented");
296 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
299 u32 * r = va_arg (*args, u32 *);
302 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
303 foreach_ipsec_integ_alg
314 format_ipsec_integ_alg (u8 * s, va_list * args)
317 u32 i = va_arg (*args, u32);
322 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
323 foreach_ipsec_integ_alg
326 return format (s, "unknown");
328 return format (s, "%s", t);
330 return format (s, "Unsupported");
335 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
338 u32 * r = va_arg (*args, u32 *);
341 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
342 foreach_ikev2_auth_method
353 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
356 u32 * r = va_arg (*args, u32 *);
359 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
360 foreach_ikev2_id_type
371 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
373 u8 * r = va_arg (*args, u8 *);
375 if (unformat (input, "kbps"))
376 *r = SSE2_QOS_RATE_KBPS;
377 else if (unformat(input, "pps"))
378 *r = SSE2_QOS_RATE_PPS;
385 unformat_policer_round_type (unformat_input_t * input, va_list * args)
387 u8 * r = va_arg (*args, u8 *);
389 if (unformat(input, "closest"))
390 *r = SSE2_QOS_ROUND_TO_CLOSEST;
391 else if (unformat (input, "up"))
392 *r = SSE2_QOS_ROUND_TO_UP;
393 else if (unformat (input, "down"))
394 *r = SSE2_QOS_ROUND_TO_DOWN;
401 unformat_policer_type (unformat_input_t * input, va_list * args)
403 u8 * r = va_arg (*args, u8 *);
405 if (unformat (input, "1r2c"))
406 *r = SSE2_QOS_POLICER_TYPE_1R2C;
407 else if (unformat (input, "1r3c"))
408 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
409 else if (unformat (input, "2r3c-2698"))
410 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
411 else if (unformat (input, "2r3c-4115"))
412 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
413 else if (unformat (input, "2r3c-mef5cf1"))
414 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
421 unformat_dscp (unformat_input_t * input, va_list * va)
423 u8 * r = va_arg (*va, u8 *);
426 #define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
435 unformat_policer_action_type (unformat_input_t * input, va_list * va)
437 sse2_qos_pol_action_params_st * a
438 = va_arg (*va, sse2_qos_pol_action_params_st *);
440 if (unformat (input, "drop"))
441 a->action_type = SSE2_QOS_ACTION_DROP;
442 else if (unformat (input, "transmit"))
443 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
444 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
445 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
451 u8 * format_ip4_address (u8 * s, va_list * args)
453 u8 * a = va_arg (*args, u8 *);
454 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
457 u8 * format_ip6_address (u8 * s, va_list * args)
459 ip6_address_t * a = va_arg (*args, ip6_address_t *);
460 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
462 i_max_n_zero = ARRAY_LEN (a->as_u16);
464 i_first_zero = i_max_n_zero;
466 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
468 u32 is_zero = a->as_u16[i] == 0;
469 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
475 if ((! is_zero && n_zeros > max_n_zeros)
476 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
478 i_max_n_zero = i_first_zero;
479 max_n_zeros = n_zeros;
480 i_first_zero = ARRAY_LEN (a->as_u16);
485 last_double_colon = 0;
486 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
488 if (i == i_max_n_zero && max_n_zeros > 1)
490 s = format (s, "::");
491 i += max_n_zeros - 1;
492 last_double_colon = 1;
496 s = format (s, "%s%x",
497 (last_double_colon || i == 0) ? "" : ":",
498 clib_net_to_host_u16 (a->as_u16[i]));
499 last_double_colon = 0;
506 /* Format an IP46 address. */
507 u8 * format_ip46_address (u8 * s, va_list * args)
509 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
510 ip46_type_t type = va_arg (*args, ip46_type_t);
516 is_ip4 = ip46_address_is_ip4(ip46);
527 format(s, "%U", format_ip4_address, &ip46->ip4):
528 format(s, "%U", format_ip6_address, &ip46->ip6);
531 u8 * format_ethernet_address (u8 * s, va_list * args)
533 u8 * a = va_arg (*args, u8 *);
535 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
536 a[0], a[1], a[2], a[3], a[4], a[5]);
539 void increment_v4_address (ip4_address_t * a)
543 v = ntohl(a->as_u32) + 1;
544 a->as_u32 = ntohl(v);
547 void increment_v6_address (ip6_address_t * a)
551 v0 = clib_net_to_host_u64 (a->as_u64[0]);
552 v1 = clib_net_to_host_u64 (a->as_u64[1]);
557 a->as_u64[0] = clib_net_to_host_u64 (v0);
558 a->as_u64[1] = clib_net_to_host_u64 (v1);
561 void increment_mac_address (u64 *mac)
565 tmp = clib_net_to_host_u64(tmp);
566 tmp += 1<<16; /* skip unused (least significant) octets */
567 tmp = clib_host_to_net_u64 (tmp);
571 static void vl_api_create_loopback_reply_t_handler
572 (vl_api_create_loopback_reply_t * mp)
574 vat_main_t * vam = &vat_main;
575 i32 retval = ntohl(mp->retval);
577 vam->retval = retval;
578 vam->regenerate_interface_table = 1;
579 vam->sw_if_index = ntohl (mp->sw_if_index);
580 vam->result_ready = 1;
583 static void vl_api_create_loopback_reply_t_handler_json
584 (vl_api_create_loopback_reply_t * mp)
586 vat_main_t * vam = &vat_main;
587 vat_json_node_t node;
589 vat_json_init_object(&node);
590 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
591 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
593 vat_json_print(vam->ofp, &node);
594 vat_json_free(&node);
595 vam->retval = ntohl(mp->retval);
596 vam->result_ready = 1;
599 static void vl_api_af_packet_create_reply_t_handler
600 (vl_api_af_packet_create_reply_t * mp)
602 vat_main_t * vam = &vat_main;
603 i32 retval = ntohl(mp->retval);
605 vam->retval = retval;
606 vam->regenerate_interface_table = 1;
607 vam->sw_if_index = ntohl (mp->sw_if_index);
608 vam->result_ready = 1;
611 static void vl_api_af_packet_create_reply_t_handler_json
612 (vl_api_af_packet_create_reply_t * mp)
614 vat_main_t * vam = &vat_main;
615 vat_json_node_t node;
617 vat_json_init_object(&node);
618 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
619 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
621 vat_json_print(vam->ofp, &node);
622 vat_json_free(&node);
624 vam->retval = ntohl(mp->retval);
625 vam->result_ready = 1;
628 static void vl_api_create_vlan_subif_reply_t_handler
629 (vl_api_create_vlan_subif_reply_t * mp)
631 vat_main_t * vam = &vat_main;
632 i32 retval = ntohl(mp->retval);
634 vam->retval = retval;
635 vam->regenerate_interface_table = 1;
636 vam->sw_if_index = ntohl (mp->sw_if_index);
637 vam->result_ready = 1;
640 static void vl_api_create_vlan_subif_reply_t_handler_json
641 (vl_api_create_vlan_subif_reply_t * mp)
643 vat_main_t * vam = &vat_main;
644 vat_json_node_t node;
646 vat_json_init_object(&node);
647 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
648 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
650 vat_json_print(vam->ofp, &node);
651 vat_json_free(&node);
653 vam->retval = ntohl(mp->retval);
654 vam->result_ready = 1;
657 static void vl_api_create_subif_reply_t_handler
658 (vl_api_create_subif_reply_t * mp)
660 vat_main_t * vam = &vat_main;
661 i32 retval = ntohl(mp->retval);
663 vam->retval = retval;
664 vam->regenerate_interface_table = 1;
665 vam->sw_if_index = ntohl (mp->sw_if_index);
666 vam->result_ready = 1;
669 static void vl_api_create_subif_reply_t_handler_json
670 (vl_api_create_subif_reply_t * mp)
672 vat_main_t * vam = &vat_main;
673 vat_json_node_t node;
675 vat_json_init_object(&node);
676 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
677 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
679 vat_json_print(vam->ofp, &node);
680 vat_json_free(&node);
682 vam->retval = ntohl(mp->retval);
683 vam->result_ready = 1;
686 static void vl_api_interface_name_renumber_reply_t_handler
687 (vl_api_interface_name_renumber_reply_t * mp)
689 vat_main_t * vam = &vat_main;
690 i32 retval = ntohl(mp->retval);
692 vam->retval = retval;
693 vam->regenerate_interface_table = 1;
694 vam->result_ready = 1;
697 static void vl_api_interface_name_renumber_reply_t_handler_json
698 (vl_api_interface_name_renumber_reply_t * mp)
700 vat_main_t * vam = &vat_main;
701 vat_json_node_t node;
703 vat_json_init_object(&node);
704 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
706 vat_json_print(vam->ofp, &node);
707 vat_json_free(&node);
709 vam->retval = ntohl(mp->retval);
710 vam->result_ready = 1;
714 * Special-case: build the interface table, maintain
715 * the next loopback sw_if_index vbl.
717 static void vl_api_sw_interface_details_t_handler
718 (vl_api_sw_interface_details_t * mp)
720 vat_main_t * vam = &vat_main;
721 u8 * s = format (0, "%s%c", mp->interface_name, 0);
723 hash_set_mem (vam->sw_if_index_by_interface_name, s,
724 ntohl(mp->sw_if_index));
726 /* In sub interface case, fill the sub interface table entry */
727 if (mp->sw_if_index != mp->sup_sw_if_index) {
728 sw_interface_subif_t * sub = NULL;
730 vec_add2(vam->sw_if_subif_table, sub, 1);
732 vec_validate(sub->interface_name, strlen((char *)s) + 1);
733 strncpy((char *)sub->interface_name, (char *)s,
734 vec_len(sub->interface_name));
735 sub->sw_if_index = ntohl(mp->sw_if_index);
736 sub->sub_id = ntohl(mp->sub_id);
738 sub->sub_dot1ad = mp->sub_dot1ad;
739 sub->sub_number_of_tags = mp->sub_number_of_tags;
740 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
741 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
742 sub->sub_exact_match = mp->sub_exact_match;
743 sub->sub_default = mp->sub_default;
744 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
745 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
747 /* vlan tag rewrite */
748 sub->vtr_op = ntohl(mp->vtr_op);
749 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
750 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
751 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
755 static void vl_api_sw_interface_details_t_handler_json
756 (vl_api_sw_interface_details_t * mp)
758 vat_main_t * vam = &vat_main;
759 vat_json_node_t *node = NULL;
761 if (VAT_JSON_ARRAY != vam->json_tree.type) {
762 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
763 vat_json_init_array(&vam->json_tree);
765 node = vat_json_array_add(&vam->json_tree);
767 vat_json_init_object(node);
768 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
769 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
770 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
771 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
772 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
773 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
774 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
775 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
776 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
777 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
778 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
779 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
780 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
781 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
782 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
783 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
784 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
785 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
786 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
787 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
788 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
789 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
790 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
793 static void vl_api_sw_interface_set_flags_t_handler
794 (vl_api_sw_interface_set_flags_t * mp)
796 vat_main_t * vam = &vat_main;
797 if (vam->interface_event_display)
798 errmsg ("interface flags: sw_if_index %d %s %s\n",
799 ntohl(mp->sw_if_index),
800 mp->admin_up_down ? "admin-up" : "admin-down",
801 mp->link_up_down ? "link-up" : "link-down");
804 static void vl_api_sw_interface_set_flags_t_handler_json
805 (vl_api_sw_interface_set_flags_t * mp)
807 /* JSON output not supported */
810 static void vl_api_cli_reply_t_handler
811 (vl_api_cli_reply_t * mp)
813 vat_main_t * vam = &vat_main;
814 i32 retval = ntohl(mp->retval);
816 vam->retval = retval;
817 vam->shmem_result = (u8 *) mp->reply_in_shmem;
818 vam->result_ready = 1;
821 static void vl_api_cli_reply_t_handler_json
822 (vl_api_cli_reply_t * mp)
824 vat_main_t * vam = &vat_main;
825 vat_json_node_t node;
826 api_main_t * am = &api_main;
830 vat_json_init_object(&node);
831 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
832 vat_json_object_add_uint(&node, "reply_in_shmem",
833 ntohl(mp->reply_in_shmem));
834 /* Toss the shared-memory original... */
835 pthread_mutex_lock (&am->vlib_rp->mutex);
836 oldheap = svm_push_data_heap (am->vlib_rp);
838 reply = (u8 *)(mp->reply_in_shmem);
841 svm_pop_heap (oldheap);
842 pthread_mutex_unlock (&am->vlib_rp->mutex);
844 vat_json_print(vam->ofp, &node);
845 vat_json_free(&node);
847 vam->retval = ntohl(mp->retval);
848 vam->result_ready = 1;
851 static void vl_api_classify_add_del_table_reply_t_handler
852 (vl_api_classify_add_del_table_reply_t * mp)
854 vat_main_t * vam = &vat_main;
855 i32 retval = ntohl(mp->retval);
856 if (vam->async_mode) {
857 vam->async_errors += (retval < 0);
859 vam->retval = retval;
861 ((mp->new_table_index != 0xFFFFFFFF) ||
862 (mp->skip_n_vectors != 0xFFFFFFFF) ||
863 (mp->match_n_vectors != 0xFFFFFFFF)))
865 * Note: this is just barely thread-safe, depends on
866 * the main thread spinning waiting for an answer...
868 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
869 ntohl(mp->new_table_index),
870 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
871 vam->result_ready = 1;
875 static void vl_api_classify_add_del_table_reply_t_handler_json
876 (vl_api_classify_add_del_table_reply_t * mp)
878 vat_main_t * vam = &vat_main;
879 vat_json_node_t node;
881 vat_json_init_object(&node);
882 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
883 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
884 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
885 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
887 vat_json_print(vam->ofp, &node);
888 vat_json_free(&node);
890 vam->retval = ntohl(mp->retval);
891 vam->result_ready = 1;
894 static void vl_api_get_node_index_reply_t_handler
895 (vl_api_get_node_index_reply_t * mp)
897 vat_main_t * vam = &vat_main;
898 i32 retval = ntohl(mp->retval);
899 if (vam->async_mode) {
900 vam->async_errors += (retval < 0);
902 vam->retval = retval;
904 errmsg ("node index %d\n", ntohl(mp->node_index));
905 vam->result_ready = 1;
909 static void vl_api_get_node_index_reply_t_handler_json
910 (vl_api_get_node_index_reply_t * mp)
912 vat_main_t * vam = &vat_main;
913 vat_json_node_t node;
915 vat_json_init_object(&node);
916 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
917 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
919 vat_json_print(vam->ofp, &node);
920 vat_json_free(&node);
922 vam->retval = ntohl(mp->retval);
923 vam->result_ready = 1;
926 static void vl_api_add_node_next_reply_t_handler
927 (vl_api_add_node_next_reply_t * mp)
929 vat_main_t * vam = &vat_main;
930 i32 retval = ntohl(mp->retval);
931 if (vam->async_mode) {
932 vam->async_errors += (retval < 0);
934 vam->retval = retval;
936 errmsg ("next index %d\n", ntohl(mp->next_index));
937 vam->result_ready = 1;
941 static void vl_api_add_node_next_reply_t_handler_json
942 (vl_api_add_node_next_reply_t * mp)
944 vat_main_t * vam = &vat_main;
945 vat_json_node_t node;
947 vat_json_init_object(&node);
948 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
949 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
951 vat_json_print(vam->ofp, &node);
952 vat_json_free(&node);
954 vam->retval = ntohl(mp->retval);
955 vam->result_ready = 1;
958 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
959 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
961 vat_main_t * vam = &vat_main;
962 i32 retval = ntohl(mp->retval);
963 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
965 if (retval >= 0 && sw_if_index != (u32)~0) {
966 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
968 vam->retval = retval;
969 vam->result_ready = 1;
972 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
973 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
975 vat_main_t * vam = &vat_main;
976 vat_json_node_t node;
978 vat_json_init_object(&node);
979 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
980 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
982 vat_json_print(vam->ofp, &node);
983 vat_json_free(&node);
985 vam->retval = ntohl(mp->retval);
986 vam->result_ready = 1;
990 static void vl_api_show_version_reply_t_handler
991 (vl_api_show_version_reply_t * mp)
993 vat_main_t * vam = &vat_main;
994 i32 retval = ntohl(mp->retval);
997 errmsg (" program: %s\n", mp->program);
998 errmsg (" version: %s\n", mp->version);
999 errmsg (" build date: %s\n", mp->build_date);
1000 errmsg ("build directory: %s\n", mp->build_directory);
1002 vam->retval = retval;
1003 vam->result_ready = 1;
1006 static void vl_api_show_version_reply_t_handler_json
1007 (vl_api_show_version_reply_t * mp)
1009 vat_main_t * vam = &vat_main;
1010 vat_json_node_t node;
1012 vat_json_init_object(&node);
1013 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1014 vat_json_object_add_string_copy(&node, "program", mp->program);
1015 vat_json_object_add_string_copy(&node, "version", mp->version);
1016 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
1017 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
1019 vat_json_print(vam->ofp, &node);
1020 vat_json_free(&node);
1022 vam->retval = ntohl(mp->retval);
1023 vam->result_ready = 1;
1026 static void vl_api_ip4_arp_event_t_handler
1027 (vl_api_ip4_arp_event_t * mp)
1029 vat_main_t * vam = &vat_main;
1030 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
1031 format_ip4_address, &mp->address,
1032 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1035 static void vl_api_ip4_arp_event_t_handler_json
1036 (vl_api_ip4_arp_event_t * mp)
1038 /* JSON output not supported */
1042 * Special-case: build the bridge domain table, maintain
1043 * the next bd id vbl.
1045 static void vl_api_bridge_domain_details_t_handler
1046 (vl_api_bridge_domain_details_t * mp)
1048 vat_main_t * vam = &vat_main;
1049 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1051 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1052 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1054 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1055 ntohl (mp->bd_id), mp->learn, mp->forward,
1056 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1059 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1063 static void vl_api_bridge_domain_details_t_handler_json
1064 (vl_api_bridge_domain_details_t * mp)
1066 vat_main_t * vam = &vat_main;
1067 vat_json_node_t *node, *array = NULL;
1069 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1070 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1071 vat_json_init_array(&vam->json_tree);
1073 node = vat_json_array_add(&vam->json_tree);
1075 vat_json_init_object(node);
1076 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1077 vat_json_object_add_uint(node, "flood", mp->flood);
1078 vat_json_object_add_uint(node, "forward", mp->forward);
1079 vat_json_object_add_uint(node, "learn", mp->learn);
1080 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1081 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1082 array = vat_json_object_add(node, "sw_if");
1083 vat_json_init_array(array);
1087 * Special-case: build the bridge domain sw if table.
1089 static void vl_api_bridge_domain_sw_if_details_t_handler
1090 (vl_api_bridge_domain_sw_if_details_t * mp)
1092 vat_main_t * vam = &vat_main;
1094 u8 * sw_if_name = 0;
1097 sw_if_index = ntohl (mp->sw_if_index);
1098 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1100 if ((u32) p->value[0] == sw_if_index) {
1101 sw_if_name = (u8 *)(p->key);
1106 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1107 mp->shg, sw_if_name ? (char *)sw_if_name :
1108 "sw_if_index not found!");
1111 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1112 (vl_api_bridge_domain_sw_if_details_t * mp)
1114 vat_main_t * vam = &vat_main;
1115 vat_json_node_t *node = NULL;
1116 uword last_index = 0;
1118 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1119 ASSERT(vec_len(vam->json_tree.array) >= 1);
1120 last_index = vec_len(vam->json_tree.array) - 1;
1121 node = &vam->json_tree.array[last_index];
1122 node = vat_json_object_get_element(node, "sw_if");
1123 ASSERT(NULL != node);
1124 node = vat_json_array_add(node);
1126 vat_json_init_object(node);
1127 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1128 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1129 vat_json_object_add_uint(node, "shg", mp->shg);
1132 static void vl_api_control_ping_reply_t_handler
1133 (vl_api_control_ping_reply_t * mp)
1135 vat_main_t * vam = &vat_main;
1136 i32 retval = ntohl(mp->retval);
1137 if (vam->async_mode) {
1138 vam->async_errors += (retval < 0);
1140 vam->retval = retval;
1141 vam->result_ready = 1;
1145 static void vl_api_control_ping_reply_t_handler_json
1146 (vl_api_control_ping_reply_t * mp)
1148 vat_main_t * vam = &vat_main;
1149 i32 retval = ntohl(mp->retval);
1151 if (VAT_JSON_NONE != vam->json_tree.type) {
1152 vat_json_print(vam->ofp, &vam->json_tree);
1153 vat_json_free(&vam->json_tree);
1154 vam->json_tree.type = VAT_JSON_NONE;
1157 vat_json_init_array(&vam->json_tree);
1158 vat_json_print(vam->ofp, &vam->json_tree);
1159 vam->json_tree.type = VAT_JSON_NONE;
1162 vam->retval = retval;
1163 vam->result_ready = 1;
1166 static void vl_api_l2_flags_reply_t_handler
1167 (vl_api_l2_flags_reply_t * mp)
1169 vat_main_t * vam = &vat_main;
1170 i32 retval = ntohl(mp->retval);
1171 if (vam->async_mode) {
1172 vam->async_errors += (retval < 0);
1174 vam->retval = retval;
1175 vam->result_ready = 1;
1179 static void vl_api_l2_flags_reply_t_handler_json
1180 (vl_api_l2_flags_reply_t * mp)
1182 vat_main_t * vam = &vat_main;
1183 vat_json_node_t node;
1185 vat_json_init_object(&node);
1186 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1187 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1189 vat_json_print(vam->ofp, &node);
1190 vat_json_free(&node);
1192 vam->retval = ntohl(mp->retval);
1193 vam->result_ready = 1;
1196 static void vl_api_bridge_flags_reply_t_handler
1197 (vl_api_bridge_flags_reply_t * mp)
1199 vat_main_t * vam = &vat_main;
1200 i32 retval = ntohl(mp->retval);
1201 if (vam->async_mode) {
1202 vam->async_errors += (retval < 0);
1204 vam->retval = retval;
1205 vam->result_ready = 1;
1209 static void vl_api_bridge_flags_reply_t_handler_json
1210 (vl_api_bridge_flags_reply_t * mp)
1212 vat_main_t * vam = &vat_main;
1213 vat_json_node_t node;
1215 vat_json_init_object(&node);
1216 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1217 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1219 vat_json_print(vam->ofp, &node);
1220 vat_json_free(&node);
1222 vam->retval = ntohl(mp->retval);
1223 vam->result_ready = 1;
1226 static void vl_api_tap_connect_reply_t_handler
1227 (vl_api_tap_connect_reply_t * mp)
1229 vat_main_t * vam = &vat_main;
1230 i32 retval = ntohl(mp->retval);
1231 if (vam->async_mode) {
1232 vam->async_errors += (retval < 0);
1234 vam->retval = retval;
1235 vam->sw_if_index = ntohl (mp->sw_if_index);
1236 vam->result_ready = 1;
1241 static void vl_api_tap_connect_reply_t_handler_json
1242 (vl_api_tap_connect_reply_t * mp)
1244 vat_main_t * vam = &vat_main;
1245 vat_json_node_t node;
1247 vat_json_init_object(&node);
1248 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1249 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1251 vat_json_print(vam->ofp, &node);
1252 vat_json_free(&node);
1254 vam->retval = ntohl(mp->retval);
1255 vam->result_ready = 1;
1259 static void vl_api_tap_modify_reply_t_handler
1260 (vl_api_tap_modify_reply_t * mp)
1262 vat_main_t * vam = &vat_main;
1263 i32 retval = ntohl(mp->retval);
1264 if (vam->async_mode) {
1265 vam->async_errors += (retval < 0);
1267 vam->retval = retval;
1268 vam->sw_if_index = ntohl (mp->sw_if_index);
1269 vam->result_ready = 1;
1273 static void vl_api_tap_modify_reply_t_handler_json
1274 (vl_api_tap_modify_reply_t * mp)
1276 vat_main_t * vam = &vat_main;
1277 vat_json_node_t node;
1279 vat_json_init_object(&node);
1280 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1281 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1283 vat_json_print(vam->ofp, &node);
1284 vat_json_free(&node);
1286 vam->retval = ntohl(mp->retval);
1287 vam->result_ready = 1;
1290 static void vl_api_tap_delete_reply_t_handler
1291 (vl_api_tap_delete_reply_t * mp)
1293 vat_main_t * vam = &vat_main;
1294 i32 retval = ntohl(mp->retval);
1295 if (vam->async_mode) {
1296 vam->async_errors += (retval < 0);
1298 vam->retval = retval;
1299 vam->result_ready = 1;
1303 static void vl_api_tap_delete_reply_t_handler_json
1304 (vl_api_tap_delete_reply_t * mp)
1306 vat_main_t * vam = &vat_main;
1307 vat_json_node_t node;
1309 vat_json_init_object(&node);
1310 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1312 vat_json_print(vam->ofp, &node);
1313 vat_json_free(&node);
1315 vam->retval = ntohl(mp->retval);
1316 vam->result_ready = 1;
1319 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1320 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1322 vat_main_t * vam = &vat_main;
1323 i32 retval = ntohl(mp->retval);
1324 if (vam->async_mode) {
1325 vam->async_errors += (retval < 0);
1327 vam->retval = retval;
1328 vam->result_ready = 1;
1332 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1333 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1335 vat_main_t * vam = &vat_main;
1336 vat_json_node_t node;
1338 vat_json_init_object(&node);
1339 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1340 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1342 vat_json_print(vam->ofp, &node);
1343 vat_json_free(&node);
1345 vam->retval = ntohl(mp->retval);
1346 vam->result_ready = 1;
1349 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1350 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1352 vat_main_t * vam = &vat_main;
1353 i32 retval = ntohl(mp->retval);
1354 if (vam->async_mode) {
1355 vam->async_errors += (retval < 0);
1357 vam->retval = retval;
1358 vam->sw_if_index = ntohl (mp->sw_if_index);
1359 vam->result_ready = 1;
1363 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1364 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1366 vat_main_t * vam = &vat_main;
1367 vat_json_node_t node;
1369 vat_json_init_object(&node);
1370 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1371 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1373 vat_json_print(vam->ofp, &node);
1374 vat_json_free(&node);
1376 vam->retval = ntohl(mp->retval);
1377 vam->result_ready = 1;
1380 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1381 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1383 vat_main_t * vam = &vat_main;
1384 i32 retval = ntohl(mp->retval);
1385 if (vam->async_mode) {
1386 vam->async_errors += (retval < 0);
1388 vam->retval = retval;
1389 vam->sw_if_index = ntohl (mp->sw_if_index);
1390 vam->result_ready = 1;
1394 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1395 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1397 vat_main_t * vam = &vat_main;
1398 vat_json_node_t node;
1400 vat_json_init_object(&node);
1401 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1402 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1404 vat_json_print(vam->ofp, &node);
1405 vat_json_free(&node);
1407 vam->retval = ntohl(mp->retval);
1408 vam->result_ready = 1;
1411 static void vl_api_gre_add_del_tunnel_reply_t_handler
1412 (vl_api_gre_add_del_tunnel_reply_t * mp)
1414 vat_main_t * vam = &vat_main;
1415 i32 retval = ntohl(mp->retval);
1416 if (vam->async_mode) {
1417 vam->async_errors += (retval < 0);
1419 vam->retval = retval;
1420 vam->sw_if_index = ntohl (mp->sw_if_index);
1421 vam->result_ready = 1;
1425 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1426 (vl_api_gre_add_del_tunnel_reply_t * mp)
1428 vat_main_t * vam = &vat_main;
1429 vat_json_node_t node;
1431 vat_json_init_object(&node);
1432 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1433 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1435 vat_json_print(vam->ofp, &node);
1436 vat_json_free(&node);
1438 vam->retval = ntohl(mp->retval);
1439 vam->result_ready = 1;
1442 static void vl_api_create_vhost_user_if_reply_t_handler
1443 (vl_api_create_vhost_user_if_reply_t * mp)
1445 vat_main_t * vam = &vat_main;
1446 i32 retval = ntohl(mp->retval);
1447 if (vam->async_mode) {
1448 vam->async_errors += (retval < 0);
1450 vam->retval = retval;
1451 vam->sw_if_index = ntohl (mp->sw_if_index);
1452 vam->result_ready = 1;
1456 static void vl_api_create_vhost_user_if_reply_t_handler_json
1457 (vl_api_create_vhost_user_if_reply_t * mp)
1459 vat_main_t * vam = &vat_main;
1460 vat_json_node_t node;
1462 vat_json_init_object(&node);
1463 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1464 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1466 vat_json_print(vam->ofp, &node);
1467 vat_json_free(&node);
1469 vam->retval = ntohl(mp->retval);
1470 vam->result_ready = 1;
1473 static void vl_api_ip_address_details_t_handler
1474 (vl_api_ip_address_details_t * mp)
1476 vat_main_t * vam = &vat_main;
1477 static ip_address_details_t empty_ip_address_details = {{0}};
1478 ip_address_details_t * address = NULL;
1479 ip_details_t * current_ip_details = NULL;
1480 ip_details_t * details = NULL;
1482 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1484 if (!details || vam->current_sw_if_index >= vec_len(details)
1485 || !details[vam->current_sw_if_index].present) {
1486 errmsg ("ip address details arrived but not stored\n");
1487 errmsg ("ip_dump should be called first\n");
1491 current_ip_details = vec_elt_at_index(details,
1492 vam->current_sw_if_index);
1494 #define addresses (current_ip_details->addr)
1496 vec_validate_init_empty(addresses, vec_len(addresses),
1497 empty_ip_address_details);
1499 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1501 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1502 address->prefix_length = mp->prefix_length;
1506 static void vl_api_ip_address_details_t_handler_json
1507 (vl_api_ip_address_details_t * mp)
1509 vat_main_t * vam = &vat_main;
1510 vat_json_node_t *node = NULL;
1511 struct in6_addr ip6;
1514 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1515 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1516 vat_json_init_array(&vam->json_tree);
1518 node = vat_json_array_add(&vam->json_tree);
1520 vat_json_init_object(node);
1522 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1523 vat_json_object_add_ip6(node, "ip", ip6);
1525 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1526 vat_json_object_add_ip4(node, "ip", ip4);
1528 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1531 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1533 vat_main_t * vam = &vat_main;
1534 static ip_details_t empty_ip_details = {0};
1535 ip_details_t * ip = NULL;
1536 u32 sw_if_index = ~0;
1538 sw_if_index = ntohl(mp->sw_if_index);
1540 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1541 sw_if_index, empty_ip_details);
1543 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1549 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1551 vat_main_t * vam = &vat_main;
1553 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1554 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1555 vat_json_init_array(&vam->json_tree);
1557 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1560 static void vl_api_map_domain_details_t_handler_json
1561 (vl_api_map_domain_details_t * mp)
1563 vat_json_node_t * node = NULL;
1564 vat_main_t * vam = &vat_main;
1565 struct in6_addr ip6;
1568 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1569 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1570 vat_json_init_array(&vam->json_tree);
1573 node = vat_json_array_add(&vam->json_tree);
1574 vat_json_init_object(node);
1576 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1577 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1578 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1579 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1580 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1581 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1582 vat_json_object_add_ip6(node, "ip6_src", ip6);
1583 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1584 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1585 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1586 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1587 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1588 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1589 vat_json_object_add_uint(node, "flags", mp->flags);
1590 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1591 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1594 static void vl_api_map_domain_details_t_handler
1595 (vl_api_map_domain_details_t * mp)
1597 vat_main_t * vam = &vat_main;
1599 if (mp->is_translation) {
1600 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1601 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1602 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1603 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1605 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1606 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1607 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1608 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1610 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1611 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1614 static void vl_api_map_rule_details_t_handler_json
1615 (vl_api_map_rule_details_t * mp)
1617 struct in6_addr ip6;
1618 vat_json_node_t * node = NULL;
1619 vat_main_t * vam = &vat_main;
1621 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1622 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1623 vat_json_init_array(&vam->json_tree);
1626 node = vat_json_array_add(&vam->json_tree);
1627 vat_json_init_object(node);
1629 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1630 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1631 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1634 static void vl_api_map_rule_details_t_handler
1635 (vl_api_map_rule_details_t * mp)
1637 vat_main_t * vam = &vat_main;
1638 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1639 format_ip6_address, mp->ip6_dst);
1642 static void vl_api_dhcp_compl_event_t_handler
1643 (vl_api_dhcp_compl_event_t * mp)
1645 vat_main_t * vam = &vat_main;
1646 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1647 "router_addr %U host_mac %U\n",
1648 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1649 format_ip4_address, &mp->host_address,
1650 format_ip4_address, &mp->router_address,
1651 format_ethernet_address, mp->host_mac);
1654 static void vl_api_dhcp_compl_event_t_handler_json
1655 (vl_api_dhcp_compl_event_t * mp)
1657 /* JSON output not supported */
1660 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1663 vat_main_t * vam = &vat_main;
1664 static u64 default_counter = 0;
1666 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1667 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1668 sw_if_index, default_counter);
1669 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1672 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1673 interface_counter_t counter)
1675 vat_main_t * vam = &vat_main;
1676 static interface_counter_t default_counter = {0, };
1678 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1679 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1680 sw_if_index, default_counter);
1681 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1684 static void vl_api_vnet_interface_counters_t_handler
1685 (vl_api_vnet_interface_counters_t *mp)
1690 static void vl_api_vnet_interface_counters_t_handler_json
1691 (vl_api_vnet_interface_counters_t *mp)
1693 interface_counter_t counter;
1698 u32 first_sw_if_index;
1701 count = ntohl(mp->count);
1702 first_sw_if_index = ntohl(mp->first_sw_if_index);
1704 if (!mp->is_combined) {
1705 v_packets = (u64*)&mp->data;
1706 for (i = 0; i < count; i++) {
1707 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1708 set_simple_interface_counter(mp->vnet_counter_type,
1709 first_sw_if_index + i, packets);
1713 v = (vlib_counter_t*)&mp->data;
1714 for (i = 0; i < count; i++) {
1715 counter.packets = clib_net_to_host_u64(
1716 clib_mem_unaligned(&v->packets, u64));
1717 counter.bytes = clib_net_to_host_u64(
1718 clib_mem_unaligned(&v->bytes, u64));
1719 set_combined_interface_counter(mp->vnet_counter_type,
1720 first_sw_if_index + i, counter);
1726 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1728 vat_main_t * vam = &vat_main;
1731 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1732 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1739 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1741 vat_main_t * vam = &vat_main;
1744 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1745 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1752 static void vl_api_vnet_ip4_fib_counters_t_handler
1753 (vl_api_vnet_ip4_fib_counters_t *mp)
1758 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1759 (vl_api_vnet_ip4_fib_counters_t *mp)
1761 vat_main_t * vam = &vat_main;
1762 vl_api_ip4_fib_counter_t *v;
1763 ip4_fib_counter_t *counter;
1770 vrf_id = ntohl(mp->vrf_id);
1771 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1772 if (~0 == vrf_index) {
1773 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1774 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1775 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1776 vec_validate(vam->ip4_fib_counters, vrf_index);
1777 vam->ip4_fib_counters[vrf_index] = NULL;
1780 vec_free(vam->ip4_fib_counters[vrf_index]);
1781 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1782 count = ntohl(mp->count);
1783 for (i = 0; i < count; i++) {
1784 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1785 counter = &vam->ip4_fib_counters[vrf_index][i];
1786 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1787 counter->address = ip4;
1788 counter->address_length = v->address_length;
1789 counter->packets = clib_net_to_host_u64(v->packets);
1790 counter->bytes = clib_net_to_host_u64(v->bytes);
1795 static void vl_api_vnet_ip6_fib_counters_t_handler
1796 (vl_api_vnet_ip6_fib_counters_t *mp)
1801 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1802 (vl_api_vnet_ip6_fib_counters_t *mp)
1804 vat_main_t * vam = &vat_main;
1805 vl_api_ip6_fib_counter_t *v;
1806 ip6_fib_counter_t *counter;
1807 struct in6_addr ip6;
1813 vrf_id = ntohl(mp->vrf_id);
1814 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1815 if (~0 == vrf_index) {
1816 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1817 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1818 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1819 vec_validate(vam->ip6_fib_counters, vrf_index);
1820 vam->ip6_fib_counters[vrf_index] = NULL;
1823 vec_free(vam->ip6_fib_counters[vrf_index]);
1824 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1825 count = ntohl(mp->count);
1826 for (i = 0; i < count; i++) {
1827 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1828 counter = &vam->ip6_fib_counters[vrf_index][i];
1829 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1830 counter->address = ip6;
1831 counter->address_length = v->address_length;
1832 counter->packets = clib_net_to_host_u64(v->packets);
1833 counter->bytes = clib_net_to_host_u64(v->bytes);
1838 static void vl_api_get_first_msg_id_reply_t_handler
1839 (vl_api_get_first_msg_id_reply_t * mp)
1841 vat_main_t * vam = &vat_main;
1842 i32 retval = ntohl(mp->retval);
1844 if (vam->async_mode) {
1845 vam->async_errors += (retval < 0);
1847 vam->retval = retval;
1848 vam->result_ready = 1;
1851 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1855 static void vl_api_get_first_msg_id_reply_t_handler_json
1856 (vl_api_get_first_msg_id_reply_t * mp)
1858 vat_main_t * vam = &vat_main;
1859 vat_json_node_t node;
1861 vat_json_init_object(&node);
1862 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1863 vat_json_object_add_uint(&node, "first_msg_id",
1864 (uint) ntohs(mp->first_msg_id));
1866 vat_json_print(vam->ofp, &node);
1867 vat_json_free(&node);
1869 vam->retval = ntohl(mp->retval);
1870 vam->result_ready = 1;
1873 static void vl_api_get_node_graph_reply_t_handler
1874 (vl_api_get_node_graph_reply_t * mp)
1876 vat_main_t * vam = &vat_main;
1877 api_main_t * am = &api_main;
1878 i32 retval = ntohl(mp->retval);
1879 u8 * pvt_copy, * reply;
1884 if (vam->async_mode) {
1885 vam->async_errors += (retval < 0);
1887 vam->retval = retval;
1888 vam->result_ready = 1;
1891 /* "Should never happen..." */
1895 reply = (u8 *)(mp->reply_in_shmem);
1896 pvt_copy = vec_dup (reply);
1898 /* Toss the shared-memory original... */
1899 pthread_mutex_lock (&am->vlib_rp->mutex);
1900 oldheap = svm_push_data_heap (am->vlib_rp);
1904 svm_pop_heap (oldheap);
1905 pthread_mutex_unlock (&am->vlib_rp->mutex);
1907 if (vam->graph_nodes) {
1908 hash_free (vam->graph_node_index_by_name);
1910 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1911 node = vam->graph_nodes[i];
1912 vec_free (node->name);
1913 vec_free (node->next_nodes);
1916 vec_free(vam->graph_nodes);
1919 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1920 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1921 vec_free (pvt_copy);
1923 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1924 node = vam->graph_nodes[i];
1925 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1929 static void vl_api_get_node_graph_reply_t_handler_json
1930 (vl_api_get_node_graph_reply_t * mp)
1932 vat_main_t * vam = &vat_main;
1933 api_main_t * am = &api_main;
1935 vat_json_node_t node;
1938 /* $$$$ make this real? */
1939 vat_json_init_object(&node);
1940 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1941 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1943 reply = (u8 *)(mp->reply_in_shmem);
1945 /* Toss the shared-memory original... */
1946 pthread_mutex_lock (&am->vlib_rp->mutex);
1947 oldheap = svm_push_data_heap (am->vlib_rp);
1951 svm_pop_heap (oldheap);
1952 pthread_mutex_unlock (&am->vlib_rp->mutex);
1954 vat_json_print(vam->ofp, &node);
1955 vat_json_free(&node);
1957 vam->retval = ntohl(mp->retval);
1958 vam->result_ready = 1;
1962 vl_api_lisp_locator_set_details_t_handler (
1963 vl_api_lisp_locator_set_details_t *mp)
1965 vat_main_t *vam = &vat_main;
1966 u8 * tmp_str = NULL;
1969 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1970 mp->locator_set_name,
1971 ntohl(mp->sw_if_index),
1975 tmp_str = format(0,"%U/%d",
1976 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1980 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1981 mp->locator_set_name,
1990 vl_api_lisp_locator_set_details_t_handler_json (
1991 vl_api_lisp_locator_set_details_t *mp)
1993 vat_main_t *vam = &vat_main;
1994 vat_json_node_t *node = NULL;
1995 struct in6_addr ip6;
1998 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1999 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2000 vat_json_init_array(&vam->json_tree);
2002 node = vat_json_array_add(&vam->json_tree);
2004 vat_json_init_object(node);
2005 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
2007 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
2010 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2011 vat_json_object_add_ip6(node, "locator", ip6);
2013 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2014 vat_json_object_add_ip4(node, "locator", ip4);
2016 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
2018 vat_json_object_add_uint(node, "priority", mp->priority);
2019 vat_json_object_add_uint(node, "weight", mp->weight);
2023 vl_api_lisp_local_eid_table_details_t_handler (
2024 vl_api_lisp_local_eid_table_details_t *mp)
2026 vat_main_t *vam = &vat_main;
2028 u8 * (*format_eid)(u8 *, va_list *) = 0;
2030 switch (mp->eid_type)
2032 case 0: format_eid = format_ip4_address; break;
2033 case 1: format_eid = format_ip6_address; break;
2034 case 2: format_eid = format_ethernet_address; break;
2036 errmsg ("unknown EID type %d!", mp->eid_type);
2040 prefix = format(0, "[%d] %U/%d",
2041 clib_net_to_host_u32 (mp->vni),
2042 format_eid, mp->eid, mp->eid_prefix_len);
2044 fformat(vam->ofp, "%=20s%=30s\n",
2045 mp->locator_set_name, prefix);
2051 vl_api_lisp_local_eid_table_details_t_handler_json (
2052 vl_api_lisp_local_eid_table_details_t *mp)
2054 vat_main_t *vam = &vat_main;
2055 vat_json_node_t *node = NULL;
2056 struct in6_addr ip6;
2060 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2061 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2062 vat_json_init_array(&vam->json_tree);
2064 node = vat_json_array_add(&vam->json_tree);
2066 vat_json_init_object(node);
2067 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
2068 switch (mp->eid_type)
2071 clib_memcpy(&ip4, mp->eid, sizeof(ip4));
2072 vat_json_object_add_ip4(node, "eid-address", ip4);
2075 clib_memcpy(&ip6, mp->eid, sizeof(ip6));
2076 vat_json_object_add_ip6(node, "eid-address", ip6);
2079 s = format (0, "%U", format_ethernet_address, mp->eid);
2081 vat_json_object_add_string_copy(node, "eid-address", s);
2085 errmsg ("unknown EID type %d!", mp->eid_type);
2088 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2089 vat_json_object_add_uint(node, "eid-prefix-len", mp->eid_prefix_len);
2093 format_decap_next (u8 * s, va_list * args)
2095 u32 next_index = va_arg (*args, u32);
2099 case LISP_GPE_INPUT_NEXT_DROP:
2100 return format (s, "drop");
2101 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2102 return format (s, "ip4");
2103 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2104 return format (s, "ip6");
2106 return format (s, "unknown %d", next_index);
2112 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2114 vat_main_t *vam = &vat_main;
2116 u8 *flag_str = NULL;
2118 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2120 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2121 foreach_lisp_gpe_flag_bit;
2124 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2125 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2127 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2129 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2131 ntohl(mp->encap_fib_id),
2132 ntohl(mp->decap_fib_id),
2133 format_decap_next, ntohl(mp->dcap_next),
2145 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2146 vl_api_lisp_gpe_tunnel_details_t *mp)
2148 vat_main_t *vam = &vat_main;
2149 vat_json_node_t *node = NULL;
2150 struct in6_addr ip6;
2154 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2156 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2157 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2158 vat_json_init_array(&vam->json_tree);
2160 node = vat_json_array_add(&vam->json_tree);
2162 vat_json_init_object(node);
2163 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2165 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2166 vat_json_object_add_ip6(node, "source address", ip6);
2167 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2168 vat_json_object_add_ip6(node, "destination address", ip6);
2170 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2171 vat_json_object_add_ip4(node, "source address", ip4);
2172 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2173 vat_json_object_add_ip4(node, "destination address", ip4);
2175 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2176 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2177 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2178 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2179 vat_json_object_add_uint(node, "flags", mp->flags);
2180 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2181 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2182 vat_json_object_add_uint(node, "res", mp->res);
2183 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2185 vec_free(next_decap_str);
2189 vl_api_lisp_map_resolver_details_t_handler (
2190 vl_api_lisp_map_resolver_details_t *mp)
2192 vat_main_t *vam = &vat_main;
2194 fformat(vam->ofp, "%=20U\n",
2195 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2200 vl_api_lisp_map_resolver_details_t_handler_json (
2201 vl_api_lisp_map_resolver_details_t *mp)
2203 vat_main_t *vam = &vat_main;
2204 vat_json_node_t *node = NULL;
2205 struct in6_addr ip6;
2208 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2209 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2210 vat_json_init_array(&vam->json_tree);
2212 node = vat_json_array_add(&vam->json_tree);
2214 vat_json_init_object(node);
2216 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2217 vat_json_object_add_ip6(node, "map resolver", ip6);
2219 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2220 vat_json_object_add_ip4(node, "map resolver", ip4);
2225 vl_api_lisp_enable_disable_status_details_t_handler
2226 (vl_api_lisp_enable_disable_status_details_t *mp)
2228 vat_main_t *vam = &vat_main;
2230 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2231 mp->feature_status ? "enabled" : "disabled",
2232 mp->gpe_status ? "enabled" : "disabled");
2236 vl_api_lisp_enable_disable_status_details_t_handler_json
2237 (vl_api_lisp_enable_disable_status_details_t *mp)
2239 vat_main_t *vam = &vat_main;
2240 vat_json_node_t *node = NULL;
2241 u8 * gpe_status = NULL;
2242 u8 * feature_status = NULL;
2244 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2245 feature_status = format (0, "%s",
2246 mp->feature_status ? "enabled" : "disabled");
2247 vec_add1 (gpe_status, 0);
2248 vec_add1 (feature_status, 0);
2250 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2251 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2252 vat_json_init_array(&vam->json_tree);
2254 node = vat_json_array_add(&vam->json_tree);
2256 vat_json_init_object(node);
2257 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2258 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2260 vec_free (gpe_status);
2261 vec_free (feature_status);
2265 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2266 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2268 vat_main_t * vam = &vat_main;
2269 i32 retval = ntohl(mp->retval);
2272 fformat(vam->ofp, "%=20s\n",
2273 mp->locator_set_name);
2276 vam->retval = retval;
2277 vam->result_ready = 1;
2281 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2282 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2284 vat_main_t * vam = &vat_main;
2285 vat_json_node_t * node = NULL;
2287 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2288 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2289 vat_json_init_array(&vam->json_tree);
2291 node = vat_json_array_add(&vam->json_tree);
2293 vat_json_init_object(node);
2294 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2296 vat_json_print(vam->ofp, node);
2297 vat_json_free(node);
2299 vam->retval = ntohl(mp->retval);
2300 vam->result_ready = 1;
2303 static u8 * format_policer_type (u8 * s, va_list * va)
2305 u32 i = va_arg (*va, u32);
2307 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2308 s = format (s, "1r2c");
2309 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2310 s = format (s, "1r3c");
2311 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2312 s = format (s, "2r3c-2698");
2313 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2314 s = format (s, "2r3c-4115");
2315 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2316 s = format (s, "2r3c-mef5cf1");
2318 s = format (s, "ILLEGAL");
2322 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2324 u32 i = va_arg (*va, u32);
2326 if (i == SSE2_QOS_RATE_KBPS)
2327 s = format (s, "kbps");
2328 else if (i == SSE2_QOS_RATE_PPS)
2329 s = format(s, "pps");
2331 s = format (s, "ILLEGAL");
2335 static u8 * format_policer_round_type (u8 * s, va_list * va)
2337 u32 i = va_arg (*va, u32);
2339 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2340 s = format(s, "closest");
2341 else if (i == SSE2_QOS_ROUND_TO_UP)
2342 s = format (s, "up");
2343 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2344 s = format (s, "down");
2346 s = format (s, "ILLEGAL");
2350 static u8 * format_policer_action_type (u8 * s, va_list * va)
2352 u32 i = va_arg (*va, u32);
2354 if (i == SSE2_QOS_ACTION_DROP)
2355 s = format (s, "drop");
2356 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2357 s = format (s, "transmit");
2358 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2359 s = format (s, "mark-and-transmit");
2361 s = format (s, "ILLEGAL");
2365 static u8 * format_dscp (u8 * s, va_list * va)
2367 u32 i = va_arg (*va, u32);
2371 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2375 return format (s, "ILLEGAL");
2377 s = format (s, "%s", t);
2381 static void vl_api_policer_details_t_handler
2382 (vl_api_policer_details_t * mp)
2384 vat_main_t * vam = &vat_main;
2385 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2387 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2388 conform_dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2390 conform_dscp_str = format(0, "");
2392 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2393 exceed_dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2395 exceed_dscp_str = format(0, "");
2397 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2398 violate_dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2400 violate_dscp_str = format(0, "");
2402 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2403 "rate type %U, round type %U, %s rate, %s color-aware, "
2404 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2405 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2406 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2408 format_policer_type, mp->type,
2413 format_policer_rate_type, mp->rate_type,
2414 format_policer_round_type, mp->round_type,
2415 mp->single_rate ? "single" : "dual",
2416 mp->color_aware ? "is" : "not",
2417 ntohl(mp->cir_tokens_per_period),
2418 ntohl(mp->pir_tokens_per_period),
2420 ntohl(mp->current_limit),
2421 ntohl(mp->current_bucket),
2422 ntohl(mp->extended_limit),
2423 ntohl(mp->extended_bucket),
2424 clib_net_to_host_u64(mp->last_update_time),
2425 format_policer_action_type, mp->conform_action_type,
2427 format_policer_action_type, mp->exceed_action_type,
2429 format_policer_action_type, mp->violate_action_type,
2432 vec_free(conform_dscp_str);
2433 vec_free(exceed_dscp_str);
2434 vec_free(violate_dscp_str);
2437 static void vl_api_policer_details_t_handler_json
2438 (vl_api_policer_details_t * mp)
2440 vat_main_t * vam = &vat_main;
2441 vat_json_node_t *node;
2442 u8 *rate_type_str, *round_type_str, *type_str;
2443 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2445 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2446 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2447 type_str = format(0, "%U", format_policer_type, mp->type);
2448 conform_action_str = format(0, "%U", format_policer_action_type,
2449 mp->conform_action_type);
2450 exceed_action_str = format(0, "%U", format_policer_action_type,
2451 mp->exceed_action_type);
2452 violate_action_str = format(0, "%U", format_policer_action_type,
2453 mp->violate_action_type);
2455 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2456 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2457 vat_json_init_array(&vam->json_tree);
2459 node = vat_json_array_add(&vam->json_tree);
2461 vat_json_init_object(node);
2462 vat_json_object_add_string_copy(node, "name", mp->name);
2463 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2464 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2465 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2466 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2467 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2468 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2469 vat_json_object_add_string_copy(node, "type", type_str);
2470 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2471 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2472 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2473 vat_json_object_add_uint(node, "cir_tokens_per_period",
2474 ntohl(mp->cir_tokens_per_period));
2475 vat_json_object_add_uint(node, "eir_tokens_per_period",
2476 ntohl(mp->pir_tokens_per_period));
2477 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2478 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2479 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2480 vat_json_object_add_uint(node, "extended_bucket",
2481 ntohl(mp->extended_bucket));
2482 vat_json_object_add_uint(node, "last_update_time",
2483 ntohl(mp->last_update_time));
2484 vat_json_object_add_string_copy(node, "conform_action", conform_action_str);
2485 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2486 u8 *dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2487 vat_json_object_add_string_copy(node, "conform_dscp", dscp_str);
2490 vat_json_object_add_string_copy(node, "exceed_action", exceed_action_str);
2491 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2492 u8 *dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2493 vat_json_object_add_string_copy(node, "exceed_dscp", dscp_str);
2496 vat_json_object_add_string_copy(node, "violate_action", violate_action_str);
2497 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2498 u8 *dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2499 vat_json_object_add_string_copy(node, "violate_dscp", dscp_str);
2503 vec_free(rate_type_str);
2504 vec_free(round_type_str);
2506 vec_free(conform_action_str);
2507 vec_free(exceed_action_str);
2508 vec_free(violate_action_str);
2511 static void vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * mp)
2513 vat_main_t * vam = &vat_main;
2514 int i, count = ntohl(mp->count);
2517 fformat (vam->ofp, "classify table ids (%d) : ", count);
2518 for (i = 0; i < count; i++)
2520 fformat (vam->ofp, "%d", ntohl(mp->ids[i]));
2521 fformat (vam->ofp, (i<count-1)?",":"\n");
2523 vam->retval = ntohl(mp->retval);
2524 vam->result_ready = 1;
2527 static void vl_api_classify_table_ids_reply_t_handler_json (vl_api_classify_table_ids_reply_t * mp)
2529 vat_main_t * vam = &vat_main;
2530 int i, count = ntohl(mp->count);
2533 vat_json_node_t node;
2535 vat_json_init_object(&node);
2536 for (i = 0; i < count; i++)
2538 vat_json_object_add_uint(&node, "table_id", ntohl(mp->ids[i]));
2540 vat_json_print(vam->ofp, &node);
2541 vat_json_free(&node);
2543 vam->retval = ntohl(mp->retval);
2544 vam->result_ready = 1;
2547 static void vl_api_classify_table_by_interface_reply_t_handler (vl_api_classify_table_by_interface_reply_t * mp)
2549 vat_main_t * vam = &vat_main;
2552 table_id = ntohl(mp->l2_table_id);
2554 fformat (vam->ofp, "l2 table id : %d\n", table_id);
2556 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
2557 table_id = ntohl(mp->ip4_table_id);
2559 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
2561 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
2562 table_id = ntohl(mp->ip6_table_id);
2564 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
2566 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
2567 vam->retval = ntohl(mp->retval);
2568 vam->result_ready = 1;
2571 static void vl_api_classify_table_by_interface_reply_t_handler_json (vl_api_classify_table_by_interface_reply_t * mp)
2573 vat_main_t * vam = &vat_main;
2574 vat_json_node_t node;
2576 vat_json_init_object(&node);
2578 vat_json_object_add_int(&node, "l2_table_id", ntohl(mp->l2_table_id));
2579 vat_json_object_add_int(&node, "ip4_table_id", ntohl(mp->ip4_table_id));
2580 vat_json_object_add_int(&node, "ip6_table_id", ntohl(mp->ip6_table_id));
2582 vat_json_print(vam->ofp, &node);
2583 vat_json_free(&node);
2585 vam->retval = ntohl(mp->retval);
2586 vam->result_ready = 1;
2589 /* Format hex dump. */
2590 u8 * format_hex_bytes (u8 * s, va_list * va)
2592 u8 * bytes = va_arg (*va, u8 *);
2593 int n_bytes = va_arg (*va, int);
2596 /* Print short or long form depending on byte count. */
2597 uword short_form = n_bytes <= 32;
2598 uword indent = format_get_indent (s);
2603 for (i = 0; i < n_bytes; i++)
2605 if (! short_form && (i % 32) == 0)
2606 s = format (s, "%08x: ", i);
2607 s = format (s, "%02x", bytes[i]);
2608 if (! short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2609 s = format (s, "\n%U", format_white_space, indent);
2615 static void vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t * mp)
2617 vat_main_t * vam = &vat_main;
2618 i32 retval = ntohl(mp->retval);
2620 fformat (vam->ofp, "classify table info :\n");
2621 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n", ntohl(mp->active_sessions), ntohl(mp->next_table_index), ntohl(mp->miss_next_index));
2622 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n", ntohl(mp->nbuckets), ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
2623 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask, ntohl(mp->mask_length));
2625 vam->retval = retval;
2626 vam->result_ready = 1;
2629 static void vl_api_classify_table_info_reply_t_handler_json (vl_api_classify_table_info_reply_t * mp)
2631 vat_main_t * vam = &vat_main;
2632 vat_json_node_t node;
2634 i32 retval = ntohl(mp->retval);
2636 vat_json_init_object(&node);
2638 vat_json_object_add_int(&node, "sessions", ntohl(mp->active_sessions));
2639 vat_json_object_add_int(&node, "nexttbl", ntohl(mp->next_table_index));
2640 vat_json_object_add_int(&node, "nextnode", ntohl(mp->miss_next_index));
2641 vat_json_object_add_int(&node, "nbuckets", ntohl(mp->nbuckets));
2642 vat_json_object_add_int(&node, "skip", ntohl(mp->skip_n_vectors));
2643 vat_json_object_add_int(&node, "match", ntohl(mp->match_n_vectors));
2644 u8 * s = format (0, "%U%c",format_hex_bytes, mp->mask, ntohl(mp->mask_length), 0);
2645 vat_json_object_add_string_copy(&node, "mask", s);
2647 vat_json_print(vam->ofp, &node);
2648 vat_json_free(&node);
2650 vam->retval = ntohl(mp->retval);
2651 vam->result_ready = 1;
2654 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
2656 vat_main_t * vam = &vat_main;
2658 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ", ntohl(mp->hit_next_index), ntohl(mp->advance), ntohl(mp->opaque_index));
2659 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match, ntohl(mp->match_length));
2662 static void vl_api_classify_session_details_t_handler_json (vl_api_classify_session_details_t * mp)
2664 vat_main_t * vam = &vat_main;
2665 vat_json_node_t *node = NULL;
2667 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2668 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2669 vat_json_init_array(&vam->json_tree);
2671 node = vat_json_array_add(&vam->json_tree);
2673 vat_json_init_object(node);
2674 vat_json_object_add_int(node, "next_index", ntohl(mp->hit_next_index));
2675 vat_json_object_add_int(node, "advance", ntohl(mp->advance));
2676 vat_json_object_add_int(node, "opaque", ntohl(mp->opaque_index));
2677 u8 * s = format (0, "%U%c",format_hex_bytes, mp->match, ntohl(mp->match_length), 0);
2678 vat_json_object_add_string_copy(node, "match", s);
2681 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2682 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2683 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2684 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2687 * Generate boilerplate reply handlers, which
2688 * dig the return value out of the xxx_reply_t API message,
2689 * stick it into vam->retval, and set vam->result_ready
2691 * Could also do this by pointing N message decode slots at
2692 * a single function, but that could break in subtle ways.
2695 #define foreach_standard_reply_retval_handler \
2696 _(sw_interface_set_flags_reply) \
2697 _(sw_interface_add_del_address_reply) \
2698 _(sw_interface_set_table_reply) \
2699 _(sw_interface_set_vpath_reply) \
2700 _(sw_interface_set_l2_bridge_reply) \
2701 _(bridge_domain_add_del_reply) \
2702 _(sw_interface_set_l2_xconnect_reply) \
2703 _(l2fib_add_del_reply) \
2704 _(ip_add_del_route_reply) \
2705 _(proxy_arp_add_del_reply) \
2706 _(proxy_arp_intfc_enable_disable_reply) \
2707 _(mpls_add_del_encap_reply) \
2708 _(mpls_add_del_decap_reply) \
2709 _(mpls_ethernet_add_del_tunnel_2_reply) \
2710 _(sw_interface_set_unnumbered_reply) \
2711 _(ip_neighbor_add_del_reply) \
2712 _(reset_vrf_reply) \
2713 _(oam_add_del_reply) \
2714 _(reset_fib_reply) \
2715 _(dhcp_proxy_config_reply) \
2716 _(dhcp_proxy_config_2_reply) \
2717 _(dhcp_proxy_set_vss_reply) \
2718 _(dhcp_client_config_reply) \
2719 _(set_ip_flow_hash_reply) \
2720 _(sw_interface_ip6_enable_disable_reply) \
2721 _(sw_interface_ip6_set_link_local_address_reply) \
2722 _(sw_interface_ip6nd_ra_prefix_reply) \
2723 _(sw_interface_ip6nd_ra_config_reply) \
2724 _(set_arp_neighbor_limit_reply) \
2725 _(l2_patch_add_del_reply) \
2726 _(sr_tunnel_add_del_reply) \
2727 _(sr_policy_add_del_reply) \
2728 _(sr_multicast_map_add_del_reply) \
2729 _(classify_add_del_session_reply) \
2730 _(classify_set_interface_ip_table_reply) \
2731 _(classify_set_interface_l2_tables_reply) \
2732 _(l2tpv3_set_tunnel_cookies_reply) \
2733 _(l2tpv3_interface_enable_disable_reply) \
2734 _(l2tpv3_set_lookup_key_reply) \
2735 _(l2_fib_clear_table_reply) \
2736 _(l2_interface_efp_filter_reply) \
2737 _(l2_interface_vlan_tag_rewrite_reply) \
2738 _(modify_vhost_user_if_reply) \
2739 _(delete_vhost_user_if_reply) \
2740 _(want_ip4_arp_events_reply) \
2741 _(input_acl_set_interface_reply) \
2742 _(ipsec_spd_add_del_reply) \
2743 _(ipsec_interface_add_del_spd_reply) \
2744 _(ipsec_spd_add_del_entry_reply) \
2745 _(ipsec_sad_add_del_entry_reply) \
2746 _(ipsec_sa_set_key_reply) \
2747 _(ikev2_profile_add_del_reply) \
2748 _(ikev2_profile_set_auth_reply) \
2749 _(ikev2_profile_set_id_reply) \
2750 _(ikev2_profile_set_ts_reply) \
2751 _(ikev2_set_local_key_reply) \
2752 _(delete_loopback_reply) \
2753 _(bd_ip_mac_add_del_reply) \
2754 _(map_del_domain_reply) \
2755 _(map_add_del_rule_reply) \
2756 _(want_interface_events_reply) \
2757 _(want_stats_reply) \
2758 _(cop_interface_enable_disable_reply) \
2759 _(cop_whitelist_enable_disable_reply) \
2760 _(sw_interface_clear_stats_reply) \
2761 _(trace_profile_add_reply) \
2762 _(trace_profile_apply_reply) \
2763 _(trace_profile_del_reply) \
2764 _(lisp_add_del_locator_set_reply) \
2765 _(lisp_add_del_locator_reply) \
2766 _(lisp_add_del_local_eid_reply) \
2767 _(lisp_add_del_remote_mapping_reply) \
2768 _(lisp_add_del_adjacency_reply) \
2769 _(lisp_gpe_add_del_fwd_entry_reply) \
2770 _(lisp_add_del_map_resolver_reply) \
2771 _(lisp_gpe_enable_disable_reply) \
2772 _(lisp_gpe_add_del_iface_reply) \
2773 _(lisp_enable_disable_reply) \
2774 _(lisp_pitr_set_locator_set_reply) \
2775 _(lisp_add_del_map_request_itr_rlocs_reply) \
2776 _(lisp_eid_table_add_del_map_reply) \
2777 _(vxlan_gpe_add_del_tunnel_reply) \
2778 _(af_packet_delete_reply) \
2779 _(policer_add_del_reply) \
2780 _(netmap_create_reply) \
2781 _(netmap_delete_reply) \
2782 _(ipfix_enable_reply)
2785 static void vl_api_##n##_t_handler \
2786 (vl_api_##n##_t * mp) \
2788 vat_main_t * vam = &vat_main; \
2789 i32 retval = ntohl(mp->retval); \
2790 if (vam->async_mode) { \
2791 vam->async_errors += (retval < 0); \
2793 vam->retval = retval; \
2794 vam->result_ready = 1; \
2797 foreach_standard_reply_retval_handler;
2801 static void vl_api_##n##_t_handler_json \
2802 (vl_api_##n##_t * mp) \
2804 vat_main_t * vam = &vat_main; \
2805 vat_json_node_t node; \
2806 vat_json_init_object(&node); \
2807 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2808 vat_json_print(vam->ofp, &node); \
2809 vam->retval = ntohl(mp->retval); \
2810 vam->result_ready = 1; \
2812 foreach_standard_reply_retval_handler;
2816 * Table of message reply handlers, must include boilerplate handlers
2820 #define foreach_vpe_api_reply_msg \
2821 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2822 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2823 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2824 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2825 _(CONTROL_PING_REPLY, control_ping_reply) \
2826 _(CLI_REPLY, cli_reply) \
2827 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2828 sw_interface_add_del_address_reply) \
2829 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2830 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2831 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2832 sw_interface_set_l2_xconnect_reply) \
2833 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2834 sw_interface_set_l2_bridge_reply) \
2835 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2836 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2837 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2838 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2839 _(L2_FLAGS_REPLY, l2_flags_reply) \
2840 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2841 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2842 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2843 _(TAP_DELETE_REPLY, tap_delete_reply) \
2844 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2845 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2846 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2847 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2848 proxy_arp_intfc_enable_disable_reply) \
2849 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2850 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2851 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2852 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2853 mpls_ethernet_add_del_tunnel_reply) \
2854 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2855 mpls_ethernet_add_del_tunnel_2_reply) \
2856 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2857 sw_interface_set_unnumbered_reply) \
2858 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2859 _(RESET_VRF_REPLY, reset_vrf_reply) \
2860 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2861 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2862 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2863 _(RESET_FIB_REPLY, reset_fib_reply) \
2864 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2865 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2866 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2867 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2868 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2869 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2870 sw_interface_ip6_enable_disable_reply) \
2871 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2872 sw_interface_ip6_set_link_local_address_reply) \
2873 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2874 sw_interface_ip6nd_ra_prefix_reply) \
2875 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2876 sw_interface_ip6nd_ra_config_reply) \
2877 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2878 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2879 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2880 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2881 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2882 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2883 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2884 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2885 classify_set_interface_ip_table_reply) \
2886 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2887 classify_set_interface_l2_tables_reply) \
2888 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2889 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2890 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2891 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2892 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2893 l2tpv3_interface_enable_disable_reply) \
2894 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2895 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2896 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2897 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2898 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2899 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2900 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2901 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2902 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2903 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2904 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2905 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2906 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2907 _(SHOW_VERSION_REPLY, show_version_reply) \
2908 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2909 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2910 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
2911 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2912 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2913 _(IP4_ARP_EVENT, ip4_arp_event) \
2914 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2915 _(IP_ADDRESS_DETAILS, ip_address_details) \
2916 _(IP_DETAILS, ip_details) \
2917 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2918 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2919 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2920 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2921 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2922 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2923 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2924 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2925 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2926 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2927 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2928 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2929 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2930 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2931 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2932 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2933 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2934 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2935 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2936 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2937 _(MAP_RULE_DETAILS, map_rule_details) \
2938 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2939 _(WANT_STATS_REPLY, want_stats_reply) \
2940 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2941 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2942 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2943 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2944 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2945 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2946 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2947 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2948 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2949 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2950 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2951 _(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
2952 _(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
2953 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2954 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2955 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2956 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2957 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
2958 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
2959 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2960 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2961 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2962 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2963 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2964 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2965 lisp_enable_disable_status_details) \
2966 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
2967 lisp_add_del_map_request_itr_rlocs_reply) \
2968 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
2969 lisp_get_map_request_itr_rlocs_reply) \
2970 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2971 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2972 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
2973 _(POLICER_DETAILS, policer_details) \
2974 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
2975 _(NETMAP_DELETE_REPLY, netmap_delete_reply) \
2976 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
2977 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
2978 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
2979 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
2980 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
2981 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
2982 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
2983 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
2984 _(IPFIX_ENABLE_REPLY, ipfix_enable_reply) \
2985 _(IPFIX_DETAILS, ipfix_details)
2987 /* M: construct, but don't yet send a message */
2991 vam->result_ready = 0; \
2992 mp = vl_msg_api_alloc(sizeof(*mp)); \
2993 memset (mp, 0, sizeof (*mp)); \
2994 mp->_vl_msg_id = ntohs (VL_API_##T); \
2995 mp->client_index = vam->my_client_index; \
3000 vam->result_ready = 0; \
3001 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3002 memset (mp, 0, sizeof (*mp)); \
3003 mp->_vl_msg_id = ntohs (VL_API_##T); \
3004 mp->client_index = vam->my_client_index; \
3008 /* S: send a message */
3009 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3011 /* W: wait for results, with timeout */
3014 timeout = vat_time_now (vam) + 1.0; \
3016 while (vat_time_now (vam) < timeout) { \
3017 if (vam->result_ready == 1) { \
3018 return (vam->retval); \
3024 /* W2: wait for results, with timeout */
3027 timeout = vat_time_now (vam) + 1.0; \
3029 while (vat_time_now (vam) < timeout) { \
3030 if (vam->result_ready == 1) { \
3032 return (vam->retval); \
3044 #define STR_VTR_OP_CASE(op) \
3045 case L2_VTR_ ## op: \
3048 static const char *str_vtr_op(u32 vtr_op)
3051 STR_VTR_OP_CASE(DISABLED);
3052 STR_VTR_OP_CASE(PUSH_1);
3053 STR_VTR_OP_CASE(PUSH_2);
3054 STR_VTR_OP_CASE(POP_1);
3055 STR_VTR_OP_CASE(POP_2);
3056 STR_VTR_OP_CASE(TRANSLATE_1_1);
3057 STR_VTR_OP_CASE(TRANSLATE_1_2);
3058 STR_VTR_OP_CASE(TRANSLATE_2_1);
3059 STR_VTR_OP_CASE(TRANSLATE_2_2);
3065 static int dump_sub_interface_table (vat_main_t * vam)
3067 const sw_interface_subif_t * sub = NULL;
3069 if (vam->json_output) {
3070 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3075 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3076 "Interface", "sw_if_index",
3077 "sub id", "dot1ad", "tags", "outer id",
3078 "inner id", "exact", "default",
3079 "outer any", "inner any");
3081 vec_foreach (sub, vam->sw_if_subif_table) {
3083 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3084 sub->interface_name,
3086 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3087 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3088 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3089 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3090 if (sub->vtr_op != L2_VTR_DISABLED) {
3092 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3093 "tag1: %d tag2: %d ]\n",
3094 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
3095 sub->vtr_tag1, sub->vtr_tag2);
3102 static int name_sort_cmp (void * a1, void * a2)
3104 name_sort_t * n1 = a1;
3105 name_sort_t * n2 = a2;
3107 return strcmp ((char *)n1->name, (char *)n2->name);
3110 static int dump_interface_table (vat_main_t * vam)
3113 name_sort_t * nses = 0, * ns;
3115 if (vam->json_output) {
3116 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3120 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3122 vec_add2 (nses, ns, 1);
3123 ns->name = (u8 *)(p->key);
3124 ns->value = (u32) p->value[0];
3127 vec_sort_with_function (nses, name_sort_cmp);
3129 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3130 vec_foreach (ns, nses) {
3131 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3137 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
3139 const ip_details_t * det = NULL;
3140 const ip_address_details_t * address = NULL;
3151 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
3153 if (!det->present) {
3161 "Address", "Prefix length");
3165 vec_foreach (address, det->addr) {
3168 is_ipv6 ? format_ip6_address : format_ip4_address,
3170 address->prefix_length);
3177 static int dump_ipv4_table (vat_main_t * vam)
3179 if (vam->json_output) {
3180 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3184 return dump_ip_table (vam, 0);
3187 static int dump_ipv6_table (vat_main_t * vam)
3189 if (vam->json_output) {
3190 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3194 return dump_ip_table (vam, 1);
3197 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
3200 switch(counter_type) {
3201 case VNET_INTERFACE_COUNTER_DROP:
3203 case VNET_INTERFACE_COUNTER_PUNT:
3205 case VNET_INTERFACE_COUNTER_IP4:
3207 case VNET_INTERFACE_COUNTER_IP6:
3209 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3211 case VNET_INTERFACE_COUNTER_RX_MISS:
3213 case VNET_INTERFACE_COUNTER_RX_ERROR:
3215 case VNET_INTERFACE_COUNTER_TX_ERROR:
3218 return "INVALID-COUNTER-TYPE";
3221 switch(counter_type) {
3222 case VNET_INTERFACE_COUNTER_RX:
3224 case VNET_INTERFACE_COUNTER_TX:
3227 return "INVALID-COUNTER-TYPE";
3232 static int dump_stats_table (vat_main_t * vam)
3234 vat_json_node_t node;
3235 vat_json_node_t *msg_array;
3236 vat_json_node_t *msg;
3237 vat_json_node_t *counter_array;
3238 vat_json_node_t *counter;
3239 interface_counter_t c;
3241 ip4_fib_counter_t *c4;
3242 ip6_fib_counter_t *c6;
3245 if (!vam->json_output) {
3246 clib_warning ("dump_stats_table supported only in JSON format");
3250 vat_json_init_object(&node);
3252 /* interface counters */
3253 msg_array = vat_json_object_add(&node, "interface_counters");
3254 vat_json_init_array(msg_array);
3255 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
3256 msg = vat_json_array_add(msg_array);
3257 vat_json_init_object(msg);
3258 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3259 (u8*)counter_type_to_str(i, 0));
3260 vat_json_object_add_int(msg, "is_combined", 0);
3261 counter_array = vat_json_object_add(msg, "data");
3262 vat_json_init_array(counter_array);
3263 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
3264 packets = vam->simple_interface_counters[i][j];
3265 vat_json_array_add_uint(counter_array, packets);
3268 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
3269 msg = vat_json_array_add(msg_array);
3270 vat_json_init_object(msg);
3271 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3272 (u8*)counter_type_to_str(i, 1));
3273 vat_json_object_add_int(msg, "is_combined", 1);
3274 counter_array = vat_json_object_add(msg, "data");
3275 vat_json_init_array(counter_array);
3276 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
3277 c = vam->combined_interface_counters[i][j];
3278 counter = vat_json_array_add(counter_array);
3279 vat_json_init_object(counter);
3280 vat_json_object_add_uint(counter, "packets", c.packets);
3281 vat_json_object_add_uint(counter, "bytes", c.bytes);
3285 /* ip4 fib counters */
3286 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
3287 vat_json_init_array(msg_array);
3288 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
3289 msg = vat_json_array_add(msg_array);
3290 vat_json_init_object(msg);
3291 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
3292 counter_array = vat_json_object_add(msg, "c");
3293 vat_json_init_array(counter_array);
3294 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
3295 counter = vat_json_array_add(counter_array);
3296 vat_json_init_object(counter);
3297 c4 = &vam->ip4_fib_counters[i][j];
3298 vat_json_object_add_ip4(counter, "address", c4->address);
3299 vat_json_object_add_uint(counter, "address_length", c4->address_length);
3300 vat_json_object_add_uint(counter, "packets", c4->packets);
3301 vat_json_object_add_uint(counter, "bytes", c4->bytes);
3305 /* ip6 fib counters */
3306 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
3307 vat_json_init_array(msg_array);
3308 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
3309 msg = vat_json_array_add(msg_array);
3310 vat_json_init_object(msg);
3311 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
3312 counter_array = vat_json_object_add(msg, "c");
3313 vat_json_init_array(counter_array);
3314 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
3315 counter = vat_json_array_add(counter_array);
3316 vat_json_init_object(counter);
3317 c6 = &vam->ip6_fib_counters[i][j];
3318 vat_json_object_add_ip6(counter, "address", c6->address);
3319 vat_json_object_add_uint(counter, "address_length", c6->address_length);
3320 vat_json_object_add_uint(counter, "packets", c6->packets);
3321 vat_json_object_add_uint(counter, "bytes", c6->bytes);
3325 vat_json_print(vam->ofp, &node);
3326 vat_json_free(&node);
3331 int exec (vat_main_t * vam)
3333 api_main_t * am = &api_main;
3334 vl_api_cli_request_t *mp;
3338 unformat_input_t * i = vam->input;
3340 if (vec_len(i->buffer) == 0)
3343 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3347 if (vam->exec_mode == 1 &&
3348 (unformat (i, "exit") || unformat (i, "quit"))) {
3354 M(CLI_REQUEST, cli_request);
3357 * Copy cmd into shared memory.
3358 * In order for the CLI command to work, it
3359 * must be a vector ending in \n, not a C-string ending
3362 pthread_mutex_lock (&am->vlib_rp->mutex);
3363 oldheap = svm_push_data_heap (am->vlib_rp);
3365 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3366 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3368 svm_pop_heap (oldheap);
3369 pthread_mutex_unlock (&am->vlib_rp->mutex);
3371 mp->cmd_in_shmem = (u64) cmd;
3373 timeout = vat_time_now (vam) + 10.0;
3375 while (vat_time_now (vam) < timeout) {
3376 if (vam->result_ready == 1) {
3378 if (vam->shmem_result != NULL)
3379 fformat (vam->ofp, "%s", vam->shmem_result);
3380 pthread_mutex_lock (&am->vlib_rp->mutex);
3381 oldheap = svm_push_data_heap (am->vlib_rp);
3383 free_me = (u8 *)vam->shmem_result;
3386 svm_pop_heap (oldheap);
3387 pthread_mutex_unlock (&am->vlib_rp->mutex);
3394 static int api_create_loopback (vat_main_t * vam)
3396 unformat_input_t * i = vam->input;
3397 vl_api_create_loopback_t *mp;
3402 memset (mac_address, 0, sizeof (mac_address));
3404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3406 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3412 /* Construct the API message */
3413 M(CREATE_LOOPBACK, create_loopback);
3415 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3420 static int api_delete_loopback (vat_main_t * vam)
3422 unformat_input_t * i = vam->input;
3423 vl_api_delete_loopback_t *mp;
3425 u32 sw_if_index = ~0;
3427 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3429 if (unformat (i, "sw_if_index %d", &sw_if_index))
3435 if (sw_if_index == ~0)
3437 errmsg ("missing sw_if_index\n");
3441 /* Construct the API message */
3442 M(DELETE_LOOPBACK, delete_loopback);
3443 mp->sw_if_index = ntohl (sw_if_index);
3448 static int api_want_stats (vat_main_t * vam)
3450 unformat_input_t * i = vam->input;
3451 vl_api_want_stats_t * mp;
3455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3457 if (unformat (i, "enable"))
3459 else if (unformat (i, "disable"))
3467 errmsg ("missing enable|disable\n");
3471 M(WANT_STATS, want_stats);
3472 mp->enable_disable = enable;
3477 static int api_want_interface_events (vat_main_t * vam)
3479 unformat_input_t * i = vam->input;
3480 vl_api_want_interface_events_t * mp;
3484 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3486 if (unformat (i, "enable"))
3488 else if (unformat (i, "disable"))
3496 errmsg ("missing enable|disable\n");
3500 M(WANT_INTERFACE_EVENTS, want_interface_events);
3501 mp->enable_disable = enable;
3503 vam->interface_event_display = enable;
3509 /* Note: non-static, called once to set up the initial intfc table */
3510 int api_sw_interface_dump (vat_main_t * vam)
3512 vl_api_sw_interface_dump_t *mp;
3515 name_sort_t * nses = 0, * ns;
3516 sw_interface_subif_t * sub = NULL;
3518 /* Toss the old name table */
3519 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3521 vec_add2 (nses, ns, 1);
3522 ns->name = (u8 *)(p->key);
3523 ns->value = (u32) p->value[0];
3526 hash_free (vam->sw_if_index_by_interface_name);
3528 vec_foreach (ns, nses)
3529 vec_free (ns->name);
3533 vec_foreach (sub, vam->sw_if_subif_table) {
3534 vec_free (sub->interface_name);
3536 vec_free (vam->sw_if_subif_table);
3538 /* recreate the interface name hash table */
3539 vam->sw_if_index_by_interface_name
3540 = hash_create_string (0, sizeof(uword));
3542 /* Get list of ethernets */
3543 M(SW_INTERFACE_DUMP, sw_interface_dump);
3544 mp->name_filter_valid = 1;
3545 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3548 /* and local / loopback interfaces */
3549 M(SW_INTERFACE_DUMP, sw_interface_dump);
3550 mp->name_filter_valid = 1;
3551 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3555 /* and vxlan-gpe tunnel interfaces */
3556 M(SW_INTERFACE_DUMP, sw_interface_dump);
3557 mp->name_filter_valid = 1;
3558 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3561 /* and vxlan tunnel interfaces */
3562 M(SW_INTERFACE_DUMP, sw_interface_dump);
3563 mp->name_filter_valid = 1;
3564 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3567 /* and host (af_packet) interfaces */
3568 M(SW_INTERFACE_DUMP, sw_interface_dump);
3569 mp->name_filter_valid = 1;
3570 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3573 /* and l2tpv3 tunnel interfaces */
3574 M(SW_INTERFACE_DUMP, sw_interface_dump);
3575 mp->name_filter_valid = 1;
3576 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3579 /* and GRE tunnel interfaces */
3580 M(SW_INTERFACE_DUMP, sw_interface_dump);
3581 mp->name_filter_valid = 1;
3582 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3585 /* Use a control ping for synchronization */
3587 vl_api_control_ping_t * mp;
3588 M(CONTROL_PING, control_ping);
3594 static int api_sw_interface_set_flags (vat_main_t * vam)
3596 unformat_input_t * i = vam->input;
3597 vl_api_sw_interface_set_flags_t *mp;
3600 u8 sw_if_index_set = 0;
3601 u8 admin_up = 0, link_up = 0;
3603 /* Parse args required to build the message */
3604 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3605 if (unformat (i, "admin-up"))
3607 else if (unformat (i, "admin-down"))
3609 else if (unformat (i, "link-up"))
3611 else if (unformat (i, "link-down"))
3613 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3614 sw_if_index_set = 1;
3615 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3616 sw_if_index_set = 1;
3621 if (sw_if_index_set == 0) {
3622 errmsg ("missing interface name or sw_if_index\n");
3626 /* Construct the API message */
3627 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3628 mp->sw_if_index = ntohl (sw_if_index);
3629 mp->admin_up_down = admin_up;
3630 mp->link_up_down = link_up;
3635 /* Wait for a reply, return the good/bad news... */
3639 static int api_sw_interface_clear_stats (vat_main_t * vam)
3641 unformat_input_t * i = vam->input;
3642 vl_api_sw_interface_clear_stats_t *mp;
3645 u8 sw_if_index_set = 0;
3647 /* Parse args required to build the message */
3648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3650 sw_if_index_set = 1;
3651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3652 sw_if_index_set = 1;
3657 /* Construct the API message */
3658 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3660 if (sw_if_index_set == 1)
3661 mp->sw_if_index = ntohl (sw_if_index);
3663 mp->sw_if_index = ~0;
3668 /* Wait for a reply, return the good/bad news... */
3672 static int api_sw_interface_add_del_address (vat_main_t * vam)
3674 unformat_input_t * i = vam->input;
3675 vl_api_sw_interface_add_del_address_t *mp;
3678 u8 sw_if_index_set = 0;
3679 u8 is_add = 1, del_all = 0;
3680 u32 address_length = 0;
3681 u8 v4_address_set = 0;
3682 u8 v6_address_set = 0;
3683 ip4_address_t v4address;
3684 ip6_address_t v6address;
3686 /* Parse args required to build the message */
3687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3688 if (unformat (i, "del-all"))
3690 else if (unformat (i, "del"))
3692 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3693 sw_if_index_set = 1;
3694 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3695 sw_if_index_set = 1;
3696 else if (unformat (i, "%U/%d",
3697 unformat_ip4_address, &v4address,
3700 else if (unformat (i, "%U/%d",
3701 unformat_ip6_address, &v6address,
3708 if (sw_if_index_set == 0) {
3709 errmsg ("missing interface name or sw_if_index\n");
3712 if (v4_address_set && v6_address_set) {
3713 errmsg ("both v4 and v6 addresses set\n");
3716 if (!v4_address_set && !v6_address_set && !del_all) {
3717 errmsg ("no addresses set\n");
3721 /* Construct the API message */
3722 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3724 mp->sw_if_index = ntohl (sw_if_index);
3725 mp->is_add = is_add;
3726 mp->del_all = del_all;
3727 if (v6_address_set) {
3729 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3731 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3733 mp->address_length = address_length;
3738 /* Wait for a reply, return good/bad news */
3742 static int api_sw_interface_set_table (vat_main_t * vam)
3744 unformat_input_t * i = vam->input;
3745 vl_api_sw_interface_set_table_t *mp;
3747 u32 sw_if_index, vrf_id = 0;
3748 u8 sw_if_index_set = 0;
3751 /* Parse args required to build the message */
3752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3753 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3754 sw_if_index_set = 1;
3755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3756 sw_if_index_set = 1;
3757 else if (unformat (i, "vrf %d", &vrf_id))
3759 else if (unformat (i, "ipv6"))
3765 if (sw_if_index_set == 0) {
3766 errmsg ("missing interface name or sw_if_index\n");
3770 /* Construct the API message */
3771 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3773 mp->sw_if_index = ntohl (sw_if_index);
3774 mp->is_ipv6 = is_ipv6;
3775 mp->vrf_id = ntohl (vrf_id);
3780 /* Wait for a reply... */
3784 static int api_sw_interface_set_vpath (vat_main_t * vam)
3786 unformat_input_t * i = vam->input;
3787 vl_api_sw_interface_set_vpath_t *mp;
3789 u32 sw_if_index = 0;
3790 u8 sw_if_index_set = 0;
3793 /* Parse args required to build the message */
3794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3795 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3796 sw_if_index_set = 1;
3797 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3798 sw_if_index_set = 1;
3799 else if (unformat (i, "enable"))
3801 else if (unformat (i, "disable"))
3807 if (sw_if_index_set == 0) {
3808 errmsg ("missing interface name or sw_if_index\n");
3812 /* Construct the API message */
3813 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3815 mp->sw_if_index = ntohl (sw_if_index);
3816 mp->enable = is_enable;
3821 /* Wait for a reply... */
3825 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3827 unformat_input_t * i = vam->input;
3828 vl_api_sw_interface_set_l2_xconnect_t *mp;
3831 u8 rx_sw_if_index_set = 0;
3833 u8 tx_sw_if_index_set = 0;
3836 /* Parse args required to build the message */
3837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3838 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3839 rx_sw_if_index_set = 1;
3840 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3841 tx_sw_if_index_set = 1;
3842 else if (unformat (i, "rx")) {
3843 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3844 if (unformat (i, "%U", unformat_sw_if_index, vam,
3846 rx_sw_if_index_set = 1;
3849 } else if (unformat (i, "tx")) {
3850 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3851 if (unformat (i, "%U", unformat_sw_if_index, vam,
3853 tx_sw_if_index_set = 1;
3856 } else if (unformat (i, "enable"))
3858 else if (unformat (i, "disable"))
3864 if (rx_sw_if_index_set == 0) {
3865 errmsg ("missing rx interface name or rx_sw_if_index\n");
3869 if (enable && (tx_sw_if_index_set == 0)) {
3870 errmsg ("missing tx interface name or tx_sw_if_index\n");
3874 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3876 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3877 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3878 mp->enable = enable;
3885 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3887 unformat_input_t * i = vam->input;
3888 vl_api_sw_interface_set_l2_bridge_t *mp;
3891 u8 rx_sw_if_index_set = 0;
3898 /* Parse args required to build the message */
3899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3900 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3901 rx_sw_if_index_set = 1;
3902 else if (unformat (i, "bd_id %d", &bd_id))
3904 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3906 rx_sw_if_index_set = 1;
3907 else if (unformat (i, "shg %d", &shg))
3909 else if (unformat (i, "bvi"))
3911 else if (unformat (i, "enable"))
3913 else if (unformat (i, "disable"))
3919 if (rx_sw_if_index_set == 0) {
3920 errmsg ("missing rx interface name or sw_if_index\n");
3924 if (enable && (bd_id_set == 0)) {
3925 errmsg ("missing bridge domain\n");
3929 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3931 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3932 mp->bd_id = ntohl(bd_id);
3935 mp->enable = enable;
3942 static int api_bridge_domain_dump (vat_main_t * vam)
3944 unformat_input_t * i = vam->input;
3945 vl_api_bridge_domain_dump_t *mp;
3949 /* Parse args required to build the message */
3950 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3951 if (unformat (i, "bd_id %d", &bd_id))
3957 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3958 mp->bd_id = ntohl(bd_id);
3961 /* Use a control ping for synchronization */
3963 vl_api_control_ping_t * mp;
3964 M(CONTROL_PING, control_ping);
3973 static int api_bridge_domain_add_del (vat_main_t * vam)
3975 unformat_input_t * i = vam->input;
3976 vl_api_bridge_domain_add_del_t *mp;
3980 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3982 /* Parse args required to build the message */
3983 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3984 if (unformat (i, "bd_id %d", &bd_id))
3986 else if (unformat (i, "flood %d", &flood))
3988 else if (unformat (i, "uu-flood %d", &uu_flood))
3990 else if (unformat (i, "forward %d", &forward))
3992 else if (unformat (i, "learn %d", &learn))
3994 else if (unformat (i, "arp-term %d", &arp_term))
3996 else if (unformat (i, "del")) {
3998 flood = uu_flood = forward = learn = 0;
4005 errmsg ("missing bridge domain\n");
4009 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
4011 mp->bd_id = ntohl(bd_id);
4013 mp->uu_flood = uu_flood;
4014 mp->forward = forward;
4016 mp->arp_term = arp_term;
4017 mp->is_add = is_add;
4024 static int api_l2fib_add_del (vat_main_t * vam)
4026 unformat_input_t * i = vam->input;
4027 vl_api_l2fib_add_del_t *mp;
4034 u8 sw_if_index_set = 0;
4043 /* Parse args required to build the message */
4044 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4045 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
4047 else if (unformat (i, "bd_id %d", &bd_id))
4049 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4050 sw_if_index_set = 1;
4051 else if (unformat (i, "sw_if")) {
4052 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4053 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4054 sw_if_index_set = 1;
4057 } else if (unformat (i, "static"))
4059 else if (unformat (i, "filter")) {
4062 } else if (unformat (i, "bvi")) {
4065 } else if (unformat (i, "del"))
4067 else if (unformat (i, "count %d", &count))
4074 errmsg ("missing mac address\n");
4078 if (bd_id_set == 0) {
4079 errmsg ("missing bridge domain\n");
4083 if (is_add && (sw_if_index_set == 0)) {
4084 errmsg ("missing interface name or sw_if_index\n");
4089 /* Turn on async mode */
4090 vam->async_mode = 1;
4091 vam->async_errors = 0;
4092 before = vat_time_now(vam);
4095 for (j = 0; j < count; j++) {
4096 M(L2FIB_ADD_DEL, l2fib_add_del);
4099 mp->bd_id = ntohl(bd_id);
4100 mp->is_add = is_add;
4103 mp->sw_if_index = ntohl(sw_if_index);
4104 mp->static_mac = static_mac;
4105 mp->filter_mac = filter_mac;
4106 mp->bvi_mac = bvi_mac;
4108 increment_mac_address (&mac);
4114 vl_api_control_ping_t * mp;
4117 /* Shut off async mode */
4118 vam->async_mode = 0;
4120 M(CONTROL_PING, control_ping);
4123 timeout = vat_time_now(vam) + 1.0;
4124 while (vat_time_now (vam) < timeout)
4125 if (vam->result_ready == 1)
4130 if (vam->retval == -99)
4131 errmsg ("timeout\n");
4133 if (vam->async_errors > 0) {
4134 errmsg ("%d asynchronous errors\n", vam->async_errors);
4137 vam->async_errors = 0;
4138 after = vat_time_now(vam);
4140 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4141 count, after - before, count / (after - before));
4143 /* Wait for a reply... */
4146 /* Return the good/bad news */
4147 return (vam->retval);
4150 static int api_l2_flags (vat_main_t * vam)
4152 unformat_input_t * i = vam->input;
4153 vl_api_l2_flags_t *mp;
4156 u32 feature_bitmap = 0;
4157 u8 sw_if_index_set = 0;
4159 /* Parse args required to build the message */
4160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4161 if (unformat (i, "sw_if_index %d", &sw_if_index))
4162 sw_if_index_set = 1;
4163 else if (unformat (i, "sw_if")) {
4164 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4165 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4166 sw_if_index_set = 1;
4169 } else if (unformat (i, "learn"))
4170 feature_bitmap |= L2INPUT_FEAT_LEARN;
4171 else if (unformat (i, "forward"))
4172 feature_bitmap |= L2INPUT_FEAT_FWD;
4173 else if (unformat (i, "flood"))
4174 feature_bitmap |= L2INPUT_FEAT_FLOOD;
4175 else if (unformat (i, "uu-flood"))
4176 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
4181 if (sw_if_index_set == 0) {
4182 errmsg ("missing interface name or sw_if_index\n");
4186 M(L2_FLAGS, l2_flags);
4188 mp->sw_if_index = ntohl(sw_if_index);
4189 mp->feature_bitmap = ntohl(feature_bitmap);
4196 static int api_bridge_flags (vat_main_t * vam)
4198 unformat_input_t * i = vam->input;
4199 vl_api_bridge_flags_t *mp;
4206 /* Parse args required to build the message */
4207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4208 if (unformat (i, "bd_id %d", &bd_id))
4210 else if (unformat (i, "learn"))
4212 else if (unformat (i, "forward"))
4214 else if (unformat (i, "flood"))
4216 else if (unformat (i, "uu-flood"))
4217 flags |= L2_UU_FLOOD;
4218 else if (unformat (i, "arp-term"))
4219 flags |= L2_ARP_TERM;
4220 else if (unformat (i, "off"))
4222 else if (unformat (i, "disable"))
4228 if (bd_id_set == 0) {
4229 errmsg ("missing bridge domain\n");
4233 M(BRIDGE_FLAGS, bridge_flags);
4235 mp->bd_id = ntohl(bd_id);
4236 mp->feature_bitmap = ntohl(flags);
4237 mp->is_set = is_set;
4244 static int api_bd_ip_mac_add_del (vat_main_t * vam)
4246 unformat_input_t * i = vam->input;
4247 vl_api_bd_ip_mac_add_del_t *mp;
4255 ip4_address_t v4addr;
4256 ip6_address_t v6addr;
4260 /* Parse args required to build the message */
4261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4262 if (unformat (i, "bd_id %d", &bd_id)) {
4264 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
4266 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
4269 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
4271 } else if (unformat (i, "del"))
4277 if (bd_id_set == 0) {
4278 errmsg ("missing bridge domain\n");
4280 } else if (ip_set == 0) {
4281 errmsg ("missing IP address\n");
4283 } else if (mac_set == 0) {
4284 errmsg ("missing MAC address\n");
4288 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
4290 mp->bd_id = ntohl(bd_id);
4291 mp->is_ipv6 = is_ipv6;
4292 mp->is_add = is_add;
4294 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
4295 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
4296 clib_memcpy (mp->mac_address, macaddr, 6);
4302 static int api_tap_connect (vat_main_t * vam)
4304 unformat_input_t * i = vam->input;
4305 vl_api_tap_connect_t *mp;
4312 memset (mac_address, 0, sizeof (mac_address));
4314 /* Parse args required to build the message */
4315 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4316 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4319 else if (unformat (i, "random-mac"))
4321 else if (unformat (i, "tapname %s", &tap_name))
4327 if (name_set == 0) {
4328 errmsg ("missing tap name\n");
4331 if (vec_len (tap_name) > 63) {
4332 errmsg ("tap name too long\n");
4334 vec_add1 (tap_name, 0);
4336 /* Construct the API message */
4337 M(TAP_CONNECT, tap_connect);
4339 mp->use_random_mac = random_mac;
4340 clib_memcpy (mp->mac_address, mac_address, 6);
4341 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4342 vec_free (tap_name);
4347 /* Wait for a reply... */
4351 static int api_tap_modify (vat_main_t * vam)
4353 unformat_input_t * i = vam->input;
4354 vl_api_tap_modify_t *mp;
4360 u32 sw_if_index = ~0;
4361 u8 sw_if_index_set = 0;
4363 memset (mac_address, 0, sizeof (mac_address));
4365 /* Parse args required to build the message */
4366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4367 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4368 sw_if_index_set = 1;
4369 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4370 sw_if_index_set = 1;
4371 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4374 else if (unformat (i, "random-mac"))
4376 else if (unformat (i, "tapname %s", &tap_name))
4382 if (sw_if_index_set == 0) {
4383 errmsg ("missing vpp interface name");
4386 if (name_set == 0) {
4387 errmsg ("missing tap name\n");
4390 if (vec_len (tap_name) > 63) {
4391 errmsg ("tap name too long\n");
4393 vec_add1 (tap_name, 0);
4395 /* Construct the API message */
4396 M(TAP_MODIFY, tap_modify);
4398 mp->use_random_mac = random_mac;
4399 mp->sw_if_index = ntohl(sw_if_index);
4400 clib_memcpy (mp->mac_address, mac_address, 6);
4401 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4402 vec_free (tap_name);
4407 /* Wait for a reply... */
4411 static int api_tap_delete (vat_main_t * vam)
4413 unformat_input_t * i = vam->input;
4414 vl_api_tap_delete_t *mp;
4416 u32 sw_if_index = ~0;
4417 u8 sw_if_index_set = 0;
4419 /* Parse args required to build the message */
4420 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4421 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4422 sw_if_index_set = 1;
4423 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4424 sw_if_index_set = 1;
4429 if (sw_if_index_set == 0) {
4430 errmsg ("missing vpp interface name");
4434 /* Construct the API message */
4435 M(TAP_DELETE, tap_delete);
4437 mp->sw_if_index = ntohl(sw_if_index);
4442 /* Wait for a reply... */
4446 static int api_ip_add_del_route (vat_main_t * vam)
4448 unformat_input_t * i = vam->input;
4449 vl_api_ip_add_del_route_t *mp;
4451 u32 sw_if_index = ~0, vrf_id = 0;
4452 u8 sw_if_index_set = 0;
4454 u8 is_local = 0, is_drop = 0;
4455 u8 create_vrf_if_needed = 0;
4457 u8 next_hop_weight = 1;
4459 u8 is_multipath = 0;
4461 u8 address_length_set = 0;
4462 u32 lookup_in_vrf = 0;
4463 u32 resolve_attempts = 0;
4464 u32 dst_address_length = 0;
4465 u8 next_hop_set = 0;
4466 ip4_address_t v4_dst_address, v4_next_hop_address;
4467 ip6_address_t v6_dst_address, v6_next_hop_address;
4471 u32 random_add_del = 0;
4472 u32 * random_vector = 0;
4473 uword * random_hash;
4474 u32 random_seed = 0xdeaddabe;
4475 u32 classify_table_index = ~0;
4478 /* Parse args required to build the message */
4479 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4480 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4481 sw_if_index_set = 1;
4482 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4483 sw_if_index_set = 1;
4484 else if (unformat (i, "%U", unformat_ip4_address,
4489 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4493 else if (unformat (i, "/%d", &dst_address_length)) {
4494 address_length_set = 1;
4497 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4498 &v4_next_hop_address)) {
4501 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4502 &v6_next_hop_address)) {
4505 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4507 else if (unformat (i, "weight %d", &next_hop_weight))
4509 else if (unformat (i, "drop")) {
4511 } else if (unformat (i, "local")) {
4513 } else if (unformat (i, "classify %d", &classify_table_index)) {
4515 } else if (unformat (i, "del"))
4517 else if (unformat (i, "add"))
4519 else if (unformat (i, "not-last"))
4521 else if (unformat (i, "multipath"))
4523 else if (unformat (i, "vrf %d", &vrf_id))
4525 else if (unformat (i, "create-vrf"))
4526 create_vrf_if_needed = 1;
4527 else if (unformat (i, "count %d", &count))
4529 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4531 else if (unformat (i, "random"))
4533 else if (unformat (i, "seed %d", &random_seed))
4536 clib_warning ("parse error '%U'", format_unformat_error, i);
4541 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4542 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4546 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4547 errmsg ("next hop / local / drop / classify not set\n");
4551 if (address_set == 0) {
4552 errmsg ("missing addresses\n");
4556 if (address_length_set == 0) {
4557 errmsg ("missing address length\n");
4561 /* Generate a pile of unique, random routes */
4562 if (random_add_del) {
4563 u32 this_random_address;
4564 random_hash = hash_create (count, sizeof(uword));
4566 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4567 for (j = 0; j <= count; j++) {
4569 this_random_address = random_u32 (&random_seed);
4570 this_random_address =
4571 clib_host_to_net_u32 (this_random_address);
4572 } while (hash_get (random_hash, this_random_address));
4573 vec_add1 (random_vector, this_random_address);
4574 hash_set (random_hash, this_random_address, 1);
4576 hash_free (random_hash);
4577 v4_dst_address.as_u32 = random_vector[0];
4581 /* Turn on async mode */
4582 vam->async_mode = 1;
4583 vam->async_errors = 0;
4584 before = vat_time_now(vam);
4587 for (j = 0; j < count; j++) {
4588 /* Construct the API message */
4589 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4591 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4592 mp->vrf_id = ntohl (vrf_id);
4593 if (resolve_attempts > 0) {
4594 mp->resolve_attempts = ntohl (resolve_attempts);
4595 mp->resolve_if_needed = 1;
4597 mp->create_vrf_if_needed = create_vrf_if_needed;
4599 mp->is_add = is_add;
4600 mp->is_drop = is_drop;
4601 mp->is_ipv6 = is_ipv6;
4602 mp->is_local = is_local;
4603 mp->is_classify = is_classify;
4604 mp->is_multipath = is_multipath;
4605 mp->not_last = not_last;
4606 mp->next_hop_weight = next_hop_weight;
4607 mp->dst_address_length = dst_address_length;
4608 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4609 mp->classify_table_index = ntohl(classify_table_index);
4612 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4614 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4615 sizeof (v6_next_hop_address));
4616 increment_v6_address (&v6_dst_address);
4618 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4620 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4621 sizeof (v4_next_hop_address));
4623 v4_dst_address.as_u32 = random_vector[j+1];
4625 increment_v4_address (&v4_dst_address);
4631 /* When testing multiple add/del ops, use a control-ping to sync */
4633 vl_api_control_ping_t * mp;
4636 /* Shut off async mode */
4637 vam->async_mode = 0;
4639 M(CONTROL_PING, control_ping);
4642 timeout = vat_time_now(vam) + 1.0;
4643 while (vat_time_now (vam) < timeout)
4644 if (vam->result_ready == 1)
4649 if (vam->retval == -99)
4650 errmsg ("timeout\n");
4652 if (vam->async_errors > 0) {
4653 errmsg ("%d asynchronous errors\n", vam->async_errors);
4656 vam->async_errors = 0;
4657 after = vat_time_now(vam);
4659 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4660 count, after - before, count / (after - before));
4662 /* Wait for a reply... */
4666 /* Return the good/bad news */
4667 return (vam->retval);
4670 static int api_proxy_arp_add_del (vat_main_t * vam)
4672 unformat_input_t * i = vam->input;
4673 vl_api_proxy_arp_add_del_t *mp;
4677 ip4_address_t lo, hi;
4680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4681 if (unformat (i, "vrf %d", &vrf_id))
4683 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4684 unformat_ip4_address, &hi))
4686 else if (unformat (i, "del"))
4689 clib_warning ("parse error '%U'", format_unformat_error, i);
4694 if (range_set == 0) {
4695 errmsg ("address range not set\n");
4699 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4701 mp->vrf_id = ntohl(vrf_id);
4702 mp->is_add = is_add;
4703 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4704 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4711 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4713 unformat_input_t * i = vam->input;
4714 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4718 u8 sw_if_index_set = 0;
4720 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4721 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4722 sw_if_index_set = 1;
4723 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4724 sw_if_index_set = 1;
4725 else if (unformat (i, "enable"))
4727 else if (unformat (i, "disable"))
4730 clib_warning ("parse error '%U'", format_unformat_error, i);
4735 if (sw_if_index_set == 0) {
4736 errmsg ("missing interface name or sw_if_index\n");
4740 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4742 mp->sw_if_index = ntohl(sw_if_index);
4743 mp->enable_disable = enable;
4750 static int api_mpls_add_del_decap (vat_main_t * vam)
4752 unformat_input_t * i = vam->input;
4753 vl_api_mpls_add_del_decap_t *mp;
4762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4763 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4765 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4767 else if (unformat (i, "label %d", &label))
4769 else if (unformat (i, "next-index %d", &next_index))
4771 else if (unformat (i, "del"))
4773 else if (unformat (i, "s-bit-clear"))
4776 clib_warning ("parse error '%U'", format_unformat_error, i);
4781 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4783 mp->rx_vrf_id = ntohl(rx_vrf_id);
4784 mp->tx_vrf_id = ntohl(tx_vrf_id);
4785 mp->label = ntohl(label);
4786 mp->next_index = ntohl(next_index);
4788 mp->is_add = is_add;
4795 static int api_mpls_add_del_encap (vat_main_t * vam)
4797 unformat_input_t * i = vam->input;
4798 vl_api_mpls_add_del_encap_t *mp;
4803 ip4_address_t dst_address;
4806 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4807 if (unformat (i, "vrf %d", &vrf_id))
4809 else if (unformat (i, "label %d", &label))
4810 vec_add1 (labels, ntohl(label));
4811 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4813 else if (unformat (i, "del"))
4816 clib_warning ("parse error '%U'", format_unformat_error, i);
4821 if (vec_len (labels) == 0) {
4822 errmsg ("missing encap label stack\n");
4826 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4827 sizeof (u32) * vec_len (labels));
4829 mp->vrf_id = ntohl(vrf_id);
4830 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4831 mp->is_add = is_add;
4832 mp->nlabels = vec_len (labels);
4833 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4842 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4844 unformat_input_t * i = vam->input;
4845 vl_api_mpls_gre_add_del_tunnel_t *mp;
4847 u32 inner_vrf_id = 0;
4848 u32 outer_vrf_id = 0;
4849 ip4_address_t src_address;
4850 ip4_address_t dst_address;
4851 ip4_address_t intfc_address;
4853 u8 intfc_address_length = 0;
4857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4858 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4860 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4862 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4864 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4866 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4867 &intfc_address, &tmp))
4868 intfc_address_length = tmp;
4869 else if (unformat (i, "l2-only"))
4871 else if (unformat (i, "del"))
4874 clib_warning ("parse error '%U'", format_unformat_error, i);
4879 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4881 mp->inner_vrf_id = ntohl(inner_vrf_id);
4882 mp->outer_vrf_id = ntohl(outer_vrf_id);
4883 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4884 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4885 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4886 mp->intfc_address_length = intfc_address_length;
4887 mp->l2_only = l2_only;
4888 mp->is_add = is_add;
4895 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4897 unformat_input_t * i = vam->input;
4898 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4900 u32 inner_vrf_id = 0;
4901 ip4_address_t intfc_address;
4902 u8 dst_mac_address[6];
4905 u8 intfc_address_length = 0;
4909 int tx_sw_if_index_set = 0;
4911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4912 if (unformat (i, "vrf %d", &inner_vrf_id))
4914 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4915 &intfc_address, &tmp))
4916 intfc_address_length = tmp;
4917 else if (unformat (i, "%U",
4918 unformat_sw_if_index, vam, &tx_sw_if_index))
4919 tx_sw_if_index_set = 1;
4920 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4921 tx_sw_if_index_set = 1;
4922 else if (unformat (i, "dst %U", unformat_ethernet_address,
4925 else if (unformat (i, "l2-only"))
4927 else if (unformat (i, "del"))
4930 clib_warning ("parse error '%U'", format_unformat_error, i);
4936 errmsg ("dst (mac address) not set\n");
4939 if (!tx_sw_if_index_set) {
4940 errmsg ("tx-intfc not set\n");
4944 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4946 mp->vrf_id = ntohl(inner_vrf_id);
4947 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4948 mp->adj_address_length = intfc_address_length;
4949 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4950 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4951 mp->l2_only = l2_only;
4952 mp->is_add = is_add;
4959 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4961 unformat_input_t * i = vam->input;
4962 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4964 u32 inner_vrf_id = 0;
4965 u32 outer_vrf_id = 0;
4966 ip4_address_t adj_address;
4967 int adj_address_set = 0;
4968 ip4_address_t next_hop_address;
4969 int next_hop_address_set = 0;
4971 u8 adj_address_length = 0;
4974 u32 resolve_attempts = 5;
4975 u8 resolve_if_needed = 1;
4977 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4978 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4980 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4982 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4983 &adj_address, &tmp)) {
4984 adj_address_length = tmp;
4985 adj_address_set = 1;
4987 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4989 next_hop_address_set = 1;
4990 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4992 else if (unformat (i, "resolve-if-needed %d", &tmp))
4993 resolve_if_needed = tmp;
4994 else if (unformat (i, "l2-only"))
4996 else if (unformat (i, "del"))
4999 clib_warning ("parse error '%U'", format_unformat_error, i);
5004 if (!adj_address_set) {
5005 errmsg ("adjacency address/mask not set\n");
5008 if (!next_hop_address_set) {
5009 errmsg ("ip4 next hop address (in outer fib) not set\n");
5013 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
5015 mp->inner_vrf_id = ntohl(inner_vrf_id);
5016 mp->outer_vrf_id = ntohl(outer_vrf_id);
5017 mp->resolve_attempts = ntohl(resolve_attempts);
5018 mp->resolve_if_needed = resolve_if_needed;
5019 mp->is_add = is_add;
5020 mp->l2_only = l2_only;
5021 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
5022 mp->adj_address_length = adj_address_length;
5023 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
5024 sizeof (next_hop_address));
5031 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
5033 unformat_input_t * i = vam->input;
5034 vl_api_sw_interface_set_unnumbered_t *mp;
5039 u8 sw_if_index_set = 0;
5041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5042 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5043 sw_if_index_set = 1;
5044 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5045 sw_if_index_set = 1;
5046 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5048 else if (unformat (i, "del"))
5051 clib_warning ("parse error '%U'", format_unformat_error, i);
5056 if (sw_if_index_set == 0) {
5057 errmsg ("missing interface name or sw_if_index\n");
5061 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
5063 mp->sw_if_index = ntohl(sw_if_index);
5064 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
5065 mp->is_add = is_add;
5072 static int api_ip_neighbor_add_del (vat_main_t * vam)
5074 unformat_input_t * i = vam->input;
5075 vl_api_ip_neighbor_add_del_t *mp;
5078 u8 sw_if_index_set = 0;
5084 u8 v4_address_set = 0;
5085 u8 v6_address_set = 0;
5086 ip4_address_t v4address;
5087 ip6_address_t v6address;
5089 memset (mac_address, 0, sizeof (mac_address));
5091 /* Parse args required to build the message */
5092 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5093 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
5096 else if (unformat (i, "del"))
5098 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5099 sw_if_index_set = 1;
5100 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5101 sw_if_index_set = 1;
5102 else if (unformat (i, "is_static"))
5104 else if (unformat (i, "vrf %d", &vrf_id))
5106 else if (unformat (i, "dst %U",
5107 unformat_ip4_address, &v4address))
5109 else if (unformat (i, "dst %U",
5110 unformat_ip6_address, &v6address))
5113 clib_warning ("parse error '%U'", format_unformat_error, i);
5118 if (sw_if_index_set == 0) {
5119 errmsg ("missing interface name or sw_if_index\n");
5122 if (v4_address_set && v6_address_set) {
5123 errmsg ("both v4 and v6 addresses set\n");
5126 if (!v4_address_set && !v6_address_set) {
5127 errmsg ("no address set\n");
5131 /* Construct the API message */
5132 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
5134 mp->sw_if_index = ntohl (sw_if_index);
5135 mp->is_add = is_add;
5136 mp->vrf_id = ntohl (vrf_id);
5137 mp->is_static = is_static;
5139 clib_memcpy (mp->mac_address, mac_address, 6);
5140 if (v6_address_set) {
5142 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
5144 /* mp->is_ipv6 = 0; via memset in M macro above */
5145 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
5151 /* Wait for a reply, return good/bad news */
5158 static int api_reset_vrf (vat_main_t * vam)
5160 unformat_input_t * i = vam->input;
5161 vl_api_reset_vrf_t *mp;
5167 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5168 if (unformat (i, "vrf %d", &vrf_id))
5170 else if (unformat (i, "ipv6"))
5173 clib_warning ("parse error '%U'", format_unformat_error, i);
5178 if (vrf_id_set == 0) {
5179 errmsg ("missing vrf id\n");
5183 M(RESET_VRF, reset_vrf);
5185 mp->vrf_id = ntohl(vrf_id);
5186 mp->is_ipv6 = is_ipv6;
5193 static int api_create_vlan_subif (vat_main_t * vam)
5195 unformat_input_t * i = vam->input;
5196 vl_api_create_vlan_subif_t *mp;
5199 u8 sw_if_index_set = 0;
5203 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5204 if (unformat (i, "sw_if_index %d", &sw_if_index))
5205 sw_if_index_set = 1;
5206 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5207 sw_if_index_set = 1;
5208 else if (unformat (i, "vlan %d", &vlan_id))
5211 clib_warning ("parse error '%U'", format_unformat_error, i);
5216 if (sw_if_index_set == 0) {
5217 errmsg ("missing interface name or sw_if_index\n");
5221 if (vlan_id_set == 0) {
5222 errmsg ("missing vlan_id\n");
5225 M(CREATE_VLAN_SUBIF, create_vlan_subif);
5227 mp->sw_if_index = ntohl(sw_if_index);
5228 mp->vlan_id = ntohl(vlan_id);
5235 #define foreach_create_subif_bit \
5242 _(outer_vlan_id_any) \
5243 _(inner_vlan_id_any)
5245 static int api_create_subif (vat_main_t * vam)
5247 unformat_input_t * i = vam->input;
5248 vl_api_create_subif_t *mp;
5251 u8 sw_if_index_set = 0;
5258 u32 exact_match = 0;
5259 u32 default_sub = 0;
5260 u32 outer_vlan_id_any = 0;
5261 u32 inner_vlan_id_any = 0;
5263 u16 outer_vlan_id = 0;
5264 u16 inner_vlan_id = 0;
5266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5267 if (unformat (i, "sw_if_index %d", &sw_if_index))
5268 sw_if_index_set = 1;
5269 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5270 sw_if_index_set = 1;
5271 else if (unformat (i, "sub_id %d", &sub_id))
5273 else if (unformat (i, "outer_vlan_id %d", &tmp))
5274 outer_vlan_id = tmp;
5275 else if (unformat (i, "inner_vlan_id %d", &tmp))
5276 inner_vlan_id = tmp;
5278 #define _(a) else if (unformat (i, #a)) a = 1 ;
5279 foreach_create_subif_bit
5283 clib_warning ("parse error '%U'", format_unformat_error, i);
5288 if (sw_if_index_set == 0) {
5289 errmsg ("missing interface name or sw_if_index\n");
5293 if (sub_id_set == 0) {
5294 errmsg ("missing sub_id\n");
5297 M(CREATE_SUBIF, create_subif);
5299 mp->sw_if_index = ntohl(sw_if_index);
5300 mp->sub_id = ntohl(sub_id);
5302 #define _(a) mp->a = a;
5303 foreach_create_subif_bit;
5306 mp->outer_vlan_id = ntohs (outer_vlan_id);
5307 mp->inner_vlan_id = ntohs (inner_vlan_id);
5314 static int api_oam_add_del (vat_main_t * vam)
5316 unformat_input_t * i = vam->input;
5317 vl_api_oam_add_del_t *mp;
5321 ip4_address_t src, dst;
5325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5326 if (unformat (i, "vrf %d", &vrf_id))
5328 else if (unformat (i, "src %U", unformat_ip4_address, &src))
5330 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
5332 else if (unformat (i, "del"))
5335 clib_warning ("parse error '%U'", format_unformat_error, i);
5341 errmsg ("missing src addr\n");
5346 errmsg ("missing dst addr\n");
5350 M(OAM_ADD_DEL, oam_add_del);
5352 mp->vrf_id = ntohl(vrf_id);
5353 mp->is_add = is_add;
5354 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
5355 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
5362 static int api_reset_fib (vat_main_t * vam)
5364 unformat_input_t * i = vam->input;
5365 vl_api_reset_fib_t *mp;
5371 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5372 if (unformat (i, "vrf %d", &vrf_id))
5374 else if (unformat (i, "ipv6"))
5377 clib_warning ("parse error '%U'", format_unformat_error, i);
5382 if (vrf_id_set == 0) {
5383 errmsg ("missing vrf id\n");
5387 M(RESET_FIB, reset_fib);
5389 mp->vrf_id = ntohl(vrf_id);
5390 mp->is_ipv6 = is_ipv6;
5397 static int api_dhcp_proxy_config (vat_main_t * vam)
5399 unformat_input_t * i = vam->input;
5400 vl_api_dhcp_proxy_config_t *mp;
5405 u8 v4_address_set = 0;
5406 u8 v6_address_set = 0;
5407 ip4_address_t v4address;
5408 ip6_address_t v6address;
5409 u8 v4_src_address_set = 0;
5410 u8 v6_src_address_set = 0;
5411 ip4_address_t v4srcaddress;
5412 ip6_address_t v6srcaddress;
5414 /* Parse args required to build the message */
5415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5416 if (unformat (i, "del"))
5418 else if (unformat (i, "vrf %d", &vrf_id))
5420 else if (unformat (i, "insert-cid %d", &insert_cid))
5422 else if (unformat (i, "svr %U",
5423 unformat_ip4_address, &v4address))
5425 else if (unformat (i, "svr %U",
5426 unformat_ip6_address, &v6address))
5428 else if (unformat (i, "src %U",
5429 unformat_ip4_address, &v4srcaddress))
5430 v4_src_address_set = 1;
5431 else if (unformat (i, "src %U",
5432 unformat_ip6_address, &v6srcaddress))
5433 v6_src_address_set = 1;
5438 if (v4_address_set && v6_address_set) {
5439 errmsg ("both v4 and v6 server addresses set\n");
5442 if (!v4_address_set && !v6_address_set) {
5443 errmsg ("no server addresses set\n");
5447 if (v4_src_address_set && v6_src_address_set) {
5448 errmsg ("both v4 and v6 src addresses set\n");
5451 if (!v4_src_address_set && !v6_src_address_set) {
5452 errmsg ("no src addresses set\n");
5456 if (!(v4_src_address_set && v4_address_set) &&
5457 !(v6_src_address_set && v6_address_set)) {
5458 errmsg ("no matching server and src addresses set\n");
5462 /* Construct the API message */
5463 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5465 mp->insert_circuit_id = insert_cid;
5466 mp->is_add = is_add;
5467 mp->vrf_id = ntohl (vrf_id);
5468 if (v6_address_set) {
5470 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5471 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5473 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5474 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5480 /* Wait for a reply, return good/bad news */
5486 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5488 unformat_input_t * i = vam->input;
5489 vl_api_dhcp_proxy_config_2_t *mp;
5492 u32 server_vrf_id = 0;
5495 u8 v4_address_set = 0;
5496 u8 v6_address_set = 0;
5497 ip4_address_t v4address;
5498 ip6_address_t v6address;
5499 u8 v4_src_address_set = 0;
5500 u8 v6_src_address_set = 0;
5501 ip4_address_t v4srcaddress;
5502 ip6_address_t v6srcaddress;
5504 /* Parse args required to build the message */
5505 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5506 if (unformat (i, "del"))
5508 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5510 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5512 else if (unformat (i, "insert-cid %d", &insert_cid))
5514 else if (unformat (i, "svr %U",
5515 unformat_ip4_address, &v4address))
5517 else if (unformat (i, "svr %U",
5518 unformat_ip6_address, &v6address))
5520 else if (unformat (i, "src %U",
5521 unformat_ip4_address, &v4srcaddress))
5522 v4_src_address_set = 1;
5523 else if (unformat (i, "src %U",
5524 unformat_ip6_address, &v6srcaddress))
5525 v6_src_address_set = 1;
5530 if (v4_address_set && v6_address_set) {
5531 errmsg ("both v4 and v6 server addresses set\n");
5534 if (!v4_address_set && !v6_address_set) {
5535 errmsg ("no server addresses set\n");
5539 if (v4_src_address_set && v6_src_address_set) {
5540 errmsg ("both v4 and v6 src addresses set\n");
5543 if (!v4_src_address_set && !v6_src_address_set) {
5544 errmsg ("no src addresses set\n");
5548 if (!(v4_src_address_set && v4_address_set) &&
5549 !(v6_src_address_set && v6_address_set)) {
5550 errmsg ("no matching server and src addresses set\n");
5554 /* Construct the API message */
5555 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5557 mp->insert_circuit_id = insert_cid;
5558 mp->is_add = is_add;
5559 mp->rx_vrf_id = ntohl (rx_vrf_id);
5560 mp->server_vrf_id = ntohl (server_vrf_id);
5561 if (v6_address_set) {
5563 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5564 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5566 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5567 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5573 /* Wait for a reply, return good/bad news */
5579 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5581 unformat_input_t * i = vam->input;
5582 vl_api_dhcp_proxy_set_vss_t *mp;
5593 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5594 if (unformat (i, "tbl_id %d", &tbl_id))
5596 if (unformat (i, "fib_id %d", &fib_id))
5598 if (unformat (i, "oui %d", &oui))
5600 else if (unformat (i, "ipv6"))
5602 else if (unformat (i, "del"))
5605 clib_warning ("parse error '%U'", format_unformat_error, i);
5610 if (tbl_id_set == 0) {
5611 errmsg ("missing tbl id\n");
5615 if (fib_id_set == 0) {
5616 errmsg ("missing fib id\n");
5620 errmsg ("missing oui\n");
5624 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5625 mp->tbl_id = ntohl(tbl_id);
5626 mp->fib_id = ntohl(fib_id);
5627 mp->oui = ntohl(oui);
5628 mp->is_ipv6 = is_ipv6;
5629 mp->is_add = is_add;
5636 static int api_dhcp_client_config (vat_main_t * vam)
5638 unformat_input_t * i = vam->input;
5639 vl_api_dhcp_client_config_t *mp;
5642 u8 sw_if_index_set = 0;
5645 u8 disable_event = 0;
5647 /* Parse args required to build the message */
5648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5649 if (unformat (i, "del"))
5651 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5652 sw_if_index_set = 1;
5653 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5654 sw_if_index_set = 1;
5655 else if (unformat (i, "hostname %s", &hostname))
5657 else if (unformat (i, "disable_event"))
5663 if (sw_if_index_set == 0) {
5664 errmsg ("missing interface name or sw_if_index\n");
5668 if (vec_len (hostname) > 63) {
5669 errmsg ("hostname too long\n");
5671 vec_add1 (hostname, 0);
5673 /* Construct the API message */
5674 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5676 mp->sw_if_index = ntohl (sw_if_index);
5677 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5678 vec_free (hostname);
5679 mp->is_add = is_add;
5680 mp->want_dhcp_event = disable_event ? 0 : 1;
5686 /* Wait for a reply, return good/bad news */
5692 static int api_set_ip_flow_hash (vat_main_t * vam)
5694 unformat_input_t * i = vam->input;
5695 vl_api_set_ip_flow_hash_t *mp;
5707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5708 if (unformat (i, "vrf %d", &vrf_id))
5710 else if (unformat (i, "ipv6"))
5712 else if (unformat (i, "src"))
5714 else if (unformat (i, "dst"))
5716 else if (unformat (i, "sport"))
5718 else if (unformat (i, "dport"))
5720 else if (unformat (i, "proto"))
5722 else if (unformat (i, "reverse"))
5726 clib_warning ("parse error '%U'", format_unformat_error, i);
5731 if (vrf_id_set == 0) {
5732 errmsg ("missing vrf id\n");
5736 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5742 mp->reverse = reverse;
5743 mp->vrf_id = ntohl(vrf_id);
5744 mp->is_ipv6 = is_ipv6;
5751 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5753 unformat_input_t * i = vam->input;
5754 vl_api_sw_interface_ip6_enable_disable_t *mp;
5757 u8 sw_if_index_set = 0;
5760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5761 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5762 sw_if_index_set = 1;
5763 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5764 sw_if_index_set = 1;
5765 else if (unformat (i, "enable"))
5767 else if (unformat (i, "disable"))
5770 clib_warning ("parse error '%U'", format_unformat_error, i);
5775 if (sw_if_index_set == 0) {
5776 errmsg ("missing interface name or sw_if_index\n");
5780 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5782 mp->sw_if_index = ntohl(sw_if_index);
5783 mp->enable = enable;
5790 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5792 unformat_input_t * i = vam->input;
5793 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5796 u8 sw_if_index_set = 0;
5797 u32 address_length = 0;
5798 u8 v6_address_set = 0;
5799 ip6_address_t v6address;
5801 /* Parse args required to build the message */
5802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5803 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5804 sw_if_index_set = 1;
5805 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5806 sw_if_index_set = 1;
5807 else if (unformat (i, "%U/%d",
5808 unformat_ip6_address, &v6address,
5815 if (sw_if_index_set == 0) {
5816 errmsg ("missing interface name or sw_if_index\n");
5819 if (!v6_address_set) {
5820 errmsg ("no address set\n");
5824 /* Construct the API message */
5825 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5826 sw_interface_ip6_set_link_local_address);
5828 mp->sw_if_index = ntohl (sw_if_index);
5829 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5830 mp->address_length = address_length;
5835 /* Wait for a reply, return good/bad news */
5843 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5845 unformat_input_t * i = vam->input;
5846 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5849 u8 sw_if_index_set = 0;
5850 u32 address_length = 0;
5851 u8 v6_address_set = 0;
5852 ip6_address_t v6address;
5854 u8 no_advertise = 0;
5856 u8 no_autoconfig = 0;
5859 u32 val_lifetime = 0;
5860 u32 pref_lifetime = 0;
5862 /* Parse args required to build the message */
5863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5864 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5865 sw_if_index_set = 1;
5866 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5867 sw_if_index_set = 1;
5868 else if (unformat (i, "%U/%d",
5869 unformat_ip6_address, &v6address,
5872 else if (unformat (i, "val_life %d", &val_lifetime))
5874 else if (unformat (i, "pref_life %d", &pref_lifetime))
5876 else if (unformat (i, "def"))
5878 else if (unformat (i, "noadv"))
5880 else if (unformat (i, "offl"))
5882 else if (unformat (i, "noauto"))
5884 else if (unformat (i, "nolink"))
5886 else if (unformat (i, "isno"))
5889 clib_warning ("parse error '%U'", format_unformat_error, i);
5894 if (sw_if_index_set == 0) {
5895 errmsg ("missing interface name or sw_if_index\n");
5898 if (!v6_address_set) {
5899 errmsg ("no address set\n");
5903 /* Construct the API message */
5904 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5906 mp->sw_if_index = ntohl (sw_if_index);
5907 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5908 mp->address_length = address_length;
5909 mp->use_default = use_default;
5910 mp->no_advertise = no_advertise;
5911 mp->off_link = off_link;
5912 mp->no_autoconfig = no_autoconfig;
5913 mp->no_onlink = no_onlink;
5915 mp->val_lifetime = ntohl(val_lifetime);
5916 mp->pref_lifetime = ntohl(pref_lifetime);
5921 /* Wait for a reply, return good/bad news */
5928 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5930 unformat_input_t * i = vam->input;
5931 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5934 u8 sw_if_index_set = 0;
5939 u8 send_unicast = 0;
5942 u8 default_router = 0;
5943 u32 max_interval = 0;
5944 u32 min_interval = 0;
5946 u32 initial_count = 0;
5947 u32 initial_interval = 0;
5950 /* Parse args required to build the message */
5951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5952 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5953 sw_if_index_set = 1;
5954 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5955 sw_if_index_set = 1;
5956 else if (unformat (i, "maxint %d", &max_interval))
5958 else if (unformat (i, "minint %d", &min_interval))
5960 else if (unformat (i, "life %d", &lifetime))
5962 else if (unformat (i, "count %d", &initial_count))
5964 else if (unformat (i, "interval %d", &initial_interval))
5966 else if (unformat (i, "suppress") || unformat (i, "surpress"))
5968 else if (unformat (i, "managed"))
5970 else if (unformat (i, "other"))
5972 else if (unformat (i, "ll"))
5974 else if (unformat (i, "send"))
5976 else if (unformat (i, "cease"))
5978 else if (unformat (i, "isno"))
5980 else if (unformat (i, "def"))
5983 clib_warning ("parse error '%U'", format_unformat_error, i);
5988 if (sw_if_index_set == 0) {
5989 errmsg ("missing interface name or sw_if_index\n");
5993 /* Construct the API message */
5994 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5996 mp->sw_if_index = ntohl (sw_if_index);
5997 mp->max_interval = ntohl(max_interval);
5998 mp->min_interval = ntohl(min_interval);
5999 mp->lifetime = ntohl(lifetime);
6000 mp->initial_count = ntohl(initial_count);
6001 mp->initial_interval = ntohl(initial_interval);
6002 mp->suppress = suppress;
6003 mp->managed = managed;
6005 mp->ll_option = ll_option;
6006 mp->send_unicast = send_unicast;
6009 mp->default_router = default_router;
6014 /* Wait for a reply, return good/bad news */
6021 static int api_set_arp_neighbor_limit (vat_main_t * vam)
6023 unformat_input_t * i = vam->input;
6024 vl_api_set_arp_neighbor_limit_t *mp;
6030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6031 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
6033 else if (unformat (i, "ipv6"))
6036 clib_warning ("parse error '%U'", format_unformat_error, i);
6041 if (limit_set == 0) {
6042 errmsg ("missing limit value\n");
6046 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
6048 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
6049 mp->is_ipv6 = is_ipv6;
6056 static int api_l2_patch_add_del (vat_main_t * vam)
6058 unformat_input_t * i = vam->input;
6059 vl_api_l2_patch_add_del_t *mp;
6062 u8 rx_sw_if_index_set = 0;
6064 u8 tx_sw_if_index_set = 0;
6067 /* Parse args required to build the message */
6068 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6069 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6070 rx_sw_if_index_set = 1;
6071 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6072 tx_sw_if_index_set = 1;
6073 else if (unformat (i, "rx")) {
6074 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6075 if (unformat (i, "%U", unformat_sw_if_index, vam,
6077 rx_sw_if_index_set = 1;
6080 } else if (unformat (i, "tx")) {
6081 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6082 if (unformat (i, "%U", unformat_sw_if_index, vam,
6084 tx_sw_if_index_set = 1;
6087 } else if (unformat (i, "del"))
6093 if (rx_sw_if_index_set == 0) {
6094 errmsg ("missing rx interface name or rx_sw_if_index\n");
6098 if (tx_sw_if_index_set == 0) {
6099 errmsg ("missing tx interface name or tx_sw_if_index\n");
6103 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
6105 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
6106 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
6107 mp->is_add = is_add;
6113 static int api_trace_profile_add (vat_main_t *vam)
6115 unformat_input_t * input = vam->input;
6116 vl_api_trace_profile_add_t *mp;
6119 u32 trace_option_elts = 0;
6120 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
6121 int has_pow_option = 0;
6122 int has_ppc_option = 0;
6124 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6126 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
6127 "trace-tsp %d node-id 0x%x app-data 0x%x",
6128 &id, &trace_type, &trace_option_elts, &trace_tsp,
6129 &node_id, &app_data))
6131 else if (unformat (input, "pow"))
6133 else if (unformat (input, "ppc encap"))
6134 has_ppc_option = PPC_ENCAP;
6135 else if (unformat (input, "ppc decap"))
6136 has_ppc_option = PPC_DECAP;
6137 else if (unformat (input, "ppc none"))
6138 has_ppc_option = PPC_NONE;
6142 M(TRACE_PROFILE_ADD, trace_profile_add);
6144 mp->trace_type = trace_type;
6145 mp->trace_num_elt = trace_option_elts;
6146 mp->trace_ppc = has_ppc_option;
6147 mp->trace_app_data = htonl(app_data);
6148 mp->pow_enable = has_pow_option;
6149 mp->trace_tsp = trace_tsp;
6150 mp->node_id = htonl(node_id);
6157 static int api_trace_profile_apply (vat_main_t *vam)
6159 unformat_input_t * input = vam->input;
6160 vl_api_trace_profile_apply_t *mp;
6163 u32 mask_width = ~0;
6170 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6172 if (unformat (input, "%U/%d",
6173 unformat_ip6_address, &addr, &mask_width))
6175 else if (unformat (input, "id %d", &id))
6177 else if (unformat (input, "vrf-id %d", &vrf_id))
6179 else if (unformat (input, "add"))
6181 else if (unformat (input, "pop"))
6183 else if (unformat (input, "none"))
6189 if ((is_add + is_pop + is_none) != 1) {
6190 errmsg("One of (add, pop, none) required");
6193 if (mask_width == ~0) {
6194 errmsg("<address>/<mask-width> required");
6197 M(TRACE_PROFILE_APPLY, trace_profile_apply);
6198 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
6200 mp->prefix_length = htonl(mask_width);
6201 mp->vrf_id = htonl(vrf_id);
6203 mp->trace_op = IOAM_HBYH_ADD;
6205 mp->trace_op = IOAM_HBYH_POP;
6207 mp->trace_op = IOAM_HBYH_MOD;
6219 static int api_trace_profile_del (vat_main_t *vam)
6221 vl_api_trace_profile_del_t *mp;
6224 M(TRACE_PROFILE_DEL, trace_profile_del);
6229 static int api_sr_tunnel_add_del (vat_main_t * vam)
6231 unformat_input_t * i = vam->input;
6232 vl_api_sr_tunnel_add_del_t *mp;
6236 ip6_address_t src_address;
6237 int src_address_set = 0;
6238 ip6_address_t dst_address;
6240 int dst_address_set = 0;
6242 u32 rx_table_id = 0;
6243 u32 tx_table_id = 0;
6244 ip6_address_t * segments = 0;
6245 ip6_address_t * this_seg;
6246 ip6_address_t * tags = 0;
6247 ip6_address_t * this_tag;
6248 ip6_address_t next_address, tag;
6250 u8 * policy_name = 0;
6252 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6254 if (unformat (i, "del"))
6256 else if (unformat (i, "name %s", &name))
6258 else if (unformat (i, "policy %s", &policy_name))
6260 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
6262 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
6264 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
6265 src_address_set = 1;
6266 else if (unformat (i, "dst %U/%d",
6267 unformat_ip6_address, &dst_address,
6269 dst_address_set = 1;
6270 else if (unformat (i, "next %U", unformat_ip6_address,
6273 vec_add2 (segments, this_seg, 1);
6274 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
6276 else if (unformat (i, "tag %U", unformat_ip6_address,
6279 vec_add2 (tags, this_tag, 1);
6280 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
6282 else if (unformat (i, "clean"))
6283 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
6284 else if (unformat (i, "protected"))
6285 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
6286 else if (unformat (i, "InPE %d", &pl_index))
6288 if (pl_index <= 0 || pl_index > 4)
6290 pl_index_range_error:
6291 errmsg ("pl index %d out of range\n", pl_index);
6294 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
6296 else if (unformat (i, "EgPE %d", &pl_index))
6298 if (pl_index <= 0 || pl_index > 4)
6299 goto pl_index_range_error;
6300 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
6302 else if (unformat (i, "OrgSrc %d", &pl_index))
6304 if (pl_index <= 0 || pl_index > 4)
6305 goto pl_index_range_error;
6306 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
6312 if (!src_address_set)
6314 errmsg ("src address required\n");
6318 if (!dst_address_set)
6320 errmsg ("dst address required\n");
6326 errmsg ("at least one sr segment required\n");
6330 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
6331 vec_len(segments) * sizeof (ip6_address_t)
6332 + vec_len(tags) * sizeof (ip6_address_t));
6334 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
6335 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
6336 mp->dst_mask_width = dst_mask_width;
6337 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
6338 mp->n_segments = vec_len (segments);
6339 mp->n_tags = vec_len (tags);
6340 mp->is_add = is_del == 0;
6341 clib_memcpy (mp->segs_and_tags, segments,
6342 vec_len(segments)* sizeof (ip6_address_t));
6343 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
6344 tags, vec_len(tags)* sizeof (ip6_address_t));
6346 mp->outer_vrf_id = ntohl (rx_table_id);
6347 mp->inner_vrf_id = ntohl (tx_table_id);
6348 memcpy (mp->name, name, vec_len(name));
6349 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6351 vec_free (segments);
6358 static int api_sr_policy_add_del (vat_main_t * vam)
6360 unformat_input_t * input = vam->input;
6361 vl_api_sr_policy_add_del_t *mp;
6365 u8 * tunnel_name = 0;
6366 u8 ** tunnel_names = 0;
6371 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
6372 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
6374 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6376 if (unformat (input, "del"))
6378 else if (unformat (input, "name %s", &name))
6380 else if (unformat (input, "tunnel %s", &tunnel_name))
6384 vec_add1 (tunnel_names, tunnel_name);
6386 - length = #bytes to store in serial vector
6387 - +1 = byte to store that length
6389 tunnel_names_length += (vec_len (tunnel_name) + 1);
6400 errmsg ("policy name required\n");
6404 if ((!tunnel_set) && (!is_del))
6406 errmsg ("tunnel name required\n");
6410 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6414 mp->is_add = !is_del;
6416 memcpy (mp->name, name, vec_len(name));
6417 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6418 u8 * serial_orig = 0;
6419 vec_validate (serial_orig, tunnel_names_length);
6420 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6421 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6423 for (j=0; j < vec_len(tunnel_names); j++)
6425 tun_name_len = vec_len (tunnel_names[j]);
6426 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6427 serial_orig += 1; // Move along one byte to store the actual tunnel name
6428 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6429 serial_orig += tun_name_len; // Advance past the copy
6431 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6433 vec_free (tunnel_names);
6434 vec_free (tunnel_name);
6440 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6442 unformat_input_t * input = vam->input;
6443 vl_api_sr_multicast_map_add_del_t *mp;
6446 ip6_address_t multicast_address;
6447 u8 * policy_name = 0;
6448 int multicast_address_set = 0;
6450 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6452 if (unformat (input, "del"))
6454 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6455 multicast_address_set = 1;
6456 else if (unformat (input, "sr-policy %s", &policy_name))
6462 if (!is_del && !policy_name)
6464 errmsg ("sr-policy name required\n");
6469 if (!multicast_address_set)
6471 errmsg ("address required\n");
6475 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6477 mp->is_add = !is_del;
6478 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6479 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6482 vec_free (policy_name);
6489 #define foreach_ip4_proto_field \
6499 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6501 u8 ** maskp = va_arg (*args, u8 **);
6503 u8 found_something = 0;
6506 #define _(a) u8 a=0;
6507 foreach_ip4_proto_field;
6513 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6515 if (unformat (input, "version"))
6517 else if (unformat (input, "hdr_length"))
6519 else if (unformat (input, "src"))
6521 else if (unformat (input, "dst"))
6523 else if (unformat (input, "proto"))
6526 #define _(a) else if (unformat (input, #a)) a=1;
6527 foreach_ip4_proto_field
6533 #define _(a) found_something += a;
6534 foreach_ip4_proto_field;
6537 if (found_something == 0)
6540 vec_validate (mask, sizeof (*ip) - 1);
6542 ip = (ip4_header_t *) mask;
6544 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6545 foreach_ip4_proto_field;
6548 ip->ip_version_and_header_length = 0;
6551 ip->ip_version_and_header_length |= 0xF0;
6554 ip->ip_version_and_header_length |= 0x0F;
6560 #define foreach_ip6_proto_field \
6567 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6569 u8 ** maskp = va_arg (*args, u8 **);
6571 u8 found_something = 0;
6573 u32 ip_version_traffic_class_and_flow_label;
6575 #define _(a) u8 a=0;
6576 foreach_ip6_proto_field;
6579 u8 traffic_class = 0;
6582 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6584 if (unformat (input, "version"))
6586 else if (unformat (input, "traffic-class"))
6588 else if (unformat (input, "flow-label"))
6590 else if (unformat (input, "src"))
6592 else if (unformat (input, "dst"))
6594 else if (unformat (input, "proto"))
6597 #define _(a) else if (unformat (input, #a)) a=1;
6598 foreach_ip6_proto_field
6604 #define _(a) found_something += a;
6605 foreach_ip6_proto_field;
6608 if (found_something == 0)
6611 vec_validate (mask, sizeof (*ip) - 1);
6613 ip = (ip6_header_t *) mask;
6615 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6616 foreach_ip6_proto_field;
6619 ip_version_traffic_class_and_flow_label = 0;
6622 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6625 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6628 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6630 ip->ip_version_traffic_class_and_flow_label =
6631 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6637 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6639 u8 ** maskp = va_arg (*args, u8 **);
6641 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6642 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6644 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6652 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6654 u8 ** maskp = va_arg (*args, u8 **);
6669 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6670 if (unformat (input, "src"))
6672 else if (unformat (input, "dst"))
6674 else if (unformat (input, "proto"))
6676 else if (unformat (input, "tag1"))
6678 else if (unformat (input, "tag2"))
6680 else if (unformat (input, "ignore-tag1"))
6682 else if (unformat (input, "ignore-tag2"))
6684 else if (unformat (input, "cos1"))
6686 else if (unformat (input, "cos2"))
6688 else if (unformat (input, "dot1q"))
6690 else if (unformat (input, "dot1ad"))
6695 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6696 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6699 if (tag1 || ignore_tag1 || cos1 || dot1q)
6701 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6704 vec_validate (mask, len-1);
6707 memset (mask, 0xff, 6);
6710 memset (mask + 6, 0xff, 6);
6714 /* inner vlan tag */
6723 mask[21] = mask [20] = 0xff;
6744 mask[16] = mask [17] = 0xff;
6754 mask[12] = mask [13] = 0xff;
6760 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6762 u8 ** maskp = va_arg (*args, u8 **);
6763 u32 * skipp = va_arg (*args, u32 *);
6764 u32 * matchp = va_arg (*args, u32 *);
6771 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6772 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6774 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6776 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6782 if (mask || l2 || l3)
6786 /* "With a free Ethernet header in every package" */
6788 vec_validate (l2, 13);
6790 vec_append (mask, l3);
6794 /* Scan forward looking for the first significant mask octet */
6795 for (i = 0; i < vec_len (mask); i++)
6799 /* compute (skip, match) params */
6800 *skipp = i / sizeof(u32x4);
6801 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6803 /* Pad mask to an even multiple of the vector size */
6804 while (vec_len (mask) % sizeof (u32x4))
6807 match = vec_len (mask) / sizeof (u32x4);
6809 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6811 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6812 if (*tmp || *(tmp+1))
6817 clib_warning ("BUG: match 0");
6819 _vec_len (mask) = match * sizeof(u32x4);
6830 #define foreach_l2_next \
6832 _(ethernet, ETHERNET_INPUT) \
6836 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6838 u32 * miss_next_indexp = va_arg (*args, u32 *);
6843 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6847 if (unformat (input, "%d", &tmp))
6856 *miss_next_indexp = next_index;
6860 #define foreach_ip_next \
6866 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6868 u32 * miss_next_indexp = va_arg (*args, u32 *);
6873 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6877 if (unformat (input, "%d", &tmp))
6886 *miss_next_indexp = next_index;
6890 #define foreach_acl_next \
6893 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6895 u32 * miss_next_indexp = va_arg (*args, u32 *);
6900 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6904 if (unformat (input, "permit"))
6909 else if (unformat (input, "%d", &tmp))
6918 *miss_next_indexp = next_index;
6922 static int api_classify_add_del_table (vat_main_t * vam)
6924 unformat_input_t * i = vam->input;
6925 vl_api_classify_add_del_table_t *mp;
6931 u32 table_index = ~0;
6932 u32 next_table_index = ~0;
6933 u32 miss_next_index = ~0;
6934 u32 memory_size = 32<<20;
6938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6939 if (unformat (i, "del"))
6941 else if (unformat (i, "buckets %d", &nbuckets))
6943 else if (unformat (i, "memory_size %d", &memory_size))
6945 else if (unformat (i, "skip %d", &skip))
6947 else if (unformat (i, "match %d", &match))
6949 else if (unformat (i, "table %d", &table_index))
6951 else if (unformat (i, "mask %U", unformat_classify_mask,
6952 &mask, &skip, &match))
6954 else if (unformat (i, "next-table %d", &next_table_index))
6956 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6959 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6962 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6969 if (is_add && mask == 0) {
6970 errmsg ("Mask required\n");
6974 if (is_add && skip == ~0) {
6975 errmsg ("skip count required\n");
6979 if (is_add && match == ~0) {
6980 errmsg ("match count required\n");
6984 if (!is_add && table_index == ~0) {
6985 errmsg ("table index required for delete\n");
6989 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6992 mp->is_add = is_add;
6993 mp->table_index = ntohl(table_index);
6994 mp->nbuckets = ntohl(nbuckets);
6995 mp->memory_size = ntohl(memory_size);
6996 mp->skip_n_vectors = ntohl(skip);
6997 mp->match_n_vectors = ntohl(match);
6998 mp->next_table_index = ntohl(next_table_index);
6999 mp->miss_next_index = ntohl(miss_next_index);
7000 clib_memcpy (mp->mask, mask, vec_len(mask));
7008 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
7010 u8 ** matchp = va_arg (*args, u8 **);
7017 int src = 0, dst = 0;
7018 ip4_address_t src_val, dst_val;
7025 int fragment_id = 0;
7026 u32 fragment_id_val;
7032 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7034 if (unformat (input, "version %d", &version_val))
7036 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7038 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7040 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7042 else if (unformat (input, "proto %d", &proto_val))
7044 else if (unformat (input, "tos %d", &tos_val))
7046 else if (unformat (input, "length %d", &length_val))
7048 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7050 else if (unformat (input, "ttl %d", &ttl_val))
7052 else if (unformat (input, "checksum %d", &checksum_val))
7058 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7059 + ttl + checksum == 0)
7063 * Aligned because we use the real comparison functions
7065 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7067 ip = (ip4_header_t *) match;
7069 /* These are realistically matched in practice */
7071 ip->src_address.as_u32 = src_val.as_u32;
7074 ip->dst_address.as_u32 = dst_val.as_u32;
7077 ip->protocol = proto_val;
7080 /* These are not, but they're included for completeness */
7082 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
7085 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7091 ip->length = length_val;
7097 ip->checksum = checksum_val;
7103 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
7105 u8 ** matchp = va_arg (*args, u8 **);
7111 u32 traffic_class_val;
7114 int src = 0, dst = 0;
7115 ip6_address_t src_val, dst_val;
7118 int payload_length = 0;
7119 u32 payload_length_val;
7122 u32 ip_version_traffic_class_and_flow_label;
7124 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7126 if (unformat (input, "version %d", &version_val))
7128 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7130 else if (unformat (input, "flow_label %d", &flow_label_val))
7132 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7134 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7136 else if (unformat (input, "proto %d", &proto_val))
7138 else if (unformat (input, "payload_length %d", &payload_length_val))
7140 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7146 if (version + traffic_class + flow_label + src + dst + proto +
7147 payload_length + hop_limit == 0)
7151 * Aligned because we use the real comparison functions
7153 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7155 ip = (ip6_header_t *) match;
7158 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7161 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7164 ip->protocol = proto_val;
7166 ip_version_traffic_class_and_flow_label = 0;
7169 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7172 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
7175 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7177 ip->ip_version_traffic_class_and_flow_label =
7178 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7181 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7184 ip->hop_limit = hop_limit_val;
7190 uword unformat_l3_match (unformat_input_t * input, va_list * args)
7192 u8 ** matchp = va_arg (*args, u8 **);
7194 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7195 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7197 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7205 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
7207 u8 * tagp = va_arg (*args, u8 *);
7210 if (unformat(input, "%d", &tag))
7212 tagp[0] = (tag>>8) & 0x0F;
7213 tagp[1] = tag & 0xFF;
7220 uword unformat_l2_match (unformat_input_t * input, va_list * args)
7222 u8 ** matchp = va_arg (*args, u8 **);
7242 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7243 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7245 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7247 else if (unformat (input, "proto %U",
7248 unformat_ethernet_type_host_byte_order, &proto_val))
7250 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7252 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7254 else if (unformat (input, "ignore-tag1"))
7256 else if (unformat (input, "ignore-tag2"))
7258 else if (unformat (input, "cos1 %d", &cos1_val))
7260 else if (unformat (input, "cos2 %d", &cos2_val))
7265 if ((src + dst + proto + tag1 + tag2 +
7266 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7269 if (tag1 || ignore_tag1 || cos1)
7271 if (tag2 || ignore_tag2 || cos2)
7274 vec_validate_aligned (match, len-1, sizeof(u32x4));
7277 clib_memcpy (match, dst_val, 6);
7280 clib_memcpy (match + 6, src_val, 6);
7284 /* inner vlan tag */
7285 match[19] = tag2_val[1];
7286 match[18] = tag2_val[0];
7288 match [18] |= (cos2_val & 0x7) << 5;
7291 match[21] = proto_val & 0xff;
7292 match[20] = proto_val >> 8;
7296 match [15] = tag1_val[1];
7297 match [14] = tag1_val[0];
7300 match [14] |= (cos1_val & 0x7) << 5;
7306 match [15] = tag1_val[1];
7307 match [14] = tag1_val[0];
7310 match[17] = proto_val & 0xff;
7311 match[16] = proto_val >> 8;
7314 match [14] |= (cos1_val & 0x7) << 5;
7320 match [18] |= (cos2_val & 0x7) << 5;
7322 match [14] |= (cos1_val & 0x7) << 5;
7325 match[13] = proto_val & 0xff;
7326 match[12] = proto_val >> 8;
7334 uword unformat_classify_match (unformat_input_t * input, va_list * args)
7336 u8 ** matchp = va_arg (*args, u8 **);
7337 u32 skip_n_vectors = va_arg (*args, u32);
7338 u32 match_n_vectors = va_arg (*args, u32);
7344 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7345 if (unformat (input, "hex %U", unformat_hex_string, &match))
7347 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7349 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7355 if (match || l2 || l3)
7359 /* "Win a free Ethernet header in every packet" */
7361 vec_validate_aligned (l2, 13, sizeof(u32x4));
7363 vec_append_aligned (match, l3, sizeof(u32x4));
7367 /* Make sure the vector is big enough even if key is all 0's */
7368 vec_validate_aligned
7369 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
7372 /* Set size, include skipped vectors*/
7373 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
7383 static int api_classify_add_del_session (vat_main_t * vam)
7385 unformat_input_t * i = vam->input;
7386 vl_api_classify_add_del_session_t *mp;
7388 u32 table_index = ~0;
7389 u32 hit_next_index = ~0;
7390 u32 opaque_index = ~0;
7394 u32 skip_n_vectors = 0;
7395 u32 match_n_vectors = 0;
7398 * Warning: you have to supply skip_n and match_n
7399 * because the API client cant simply look at the classify
7403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7404 if (unformat (i, "del"))
7406 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7409 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7412 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7415 else if (unformat (i, "opaque-index %d", &opaque_index))
7417 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7419 else if (unformat (i, "match_n %d", &match_n_vectors))
7421 else if (unformat (i, "match %U", unformat_classify_match,
7422 &match, skip_n_vectors, match_n_vectors))
7424 else if (unformat (i, "advance %d", &advance))
7426 else if (unformat (i, "table-index %d", &table_index))
7432 if (table_index == ~0) {
7433 errmsg ("Table index required\n");
7437 if (is_add && match == 0) {
7438 errmsg ("Match value required\n");
7442 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7445 mp->is_add = is_add;
7446 mp->table_index = ntohl(table_index);
7447 mp->hit_next_index = ntohl(hit_next_index);
7448 mp->opaque_index = ntohl(opaque_index);
7449 mp->advance = ntohl(advance);
7450 clib_memcpy (mp->match, match, vec_len(match));
7457 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7459 unformat_input_t * i = vam->input;
7460 vl_api_classify_set_interface_ip_table_t *mp;
7463 int sw_if_index_set;
7464 u32 table_index = ~0;
7467 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7468 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7469 sw_if_index_set = 1;
7470 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7471 sw_if_index_set = 1;
7472 else if (unformat (i, "table %d", &table_index))
7475 clib_warning ("parse error '%U'", format_unformat_error, i);
7480 if (sw_if_index_set == 0) {
7481 errmsg ("missing interface name or sw_if_index\n");
7486 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7488 mp->sw_if_index = ntohl(sw_if_index);
7489 mp->table_index = ntohl(table_index);
7490 mp->is_ipv6 = is_ipv6;
7497 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7499 unformat_input_t * i = vam->input;
7500 vl_api_classify_set_interface_l2_tables_t *mp;
7503 int sw_if_index_set;
7504 u32 ip4_table_index = ~0;
7505 u32 ip6_table_index = ~0;
7506 u32 other_table_index = ~0;
7508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7509 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7510 sw_if_index_set = 1;
7511 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7512 sw_if_index_set = 1;
7513 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7515 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7517 else if (unformat (i, "other-table %d", &other_table_index))
7520 clib_warning ("parse error '%U'", format_unformat_error, i);
7525 if (sw_if_index_set == 0) {
7526 errmsg ("missing interface name or sw_if_index\n");
7531 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7533 mp->sw_if_index = ntohl(sw_if_index);
7534 mp->ip4_table_index = ntohl(ip4_table_index);
7535 mp->ip6_table_index = ntohl(ip6_table_index);
7536 mp->other_table_index = ntohl(other_table_index);
7544 static int api_ipfix_enable (vat_main_t * vam)
7546 unformat_input_t * i = vam->input;
7547 vl_api_ipfix_enable_t *mp;
7548 ip4_address_t collector_address;
7549 u8 collector_address_set = 0;
7550 u32 collector_port = ~0;
7551 ip4_address_t src_address;
7552 u8 src_address_set = 0;
7555 u32 template_interval = ~0;
7558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7559 if (unformat (i, "collector_address %U", unformat_ip4_address,
7560 &collector_address))
7561 collector_address_set = 1;
7562 else if (unformat (i, "collector_port %d", &collector_port))
7564 else if (unformat (i, "src_address %U", unformat_ip4_address,
7566 src_address_set = 1;
7567 else if (unformat (i, "vrf_id %d", &vrf_id))
7569 else if (unformat (i, "path_mtu %d", &path_mtu))
7571 else if (unformat (i, "template_interval %d", &template_interval))
7577 if (collector_address_set == 0) {
7578 errmsg ("collector_address required\n");
7582 if (src_address_set == 0) {
7583 errmsg ("src_address required\n");
7587 M (IPFIX_ENABLE, ipfix_enable);
7589 memcpy(mp->collector_address, collector_address.data,
7590 sizeof(collector_address.data));
7591 mp->collector_port = htons((u16)collector_port);
7592 memcpy(mp->src_address, src_address.data,
7593 sizeof(src_address.data));
7594 mp->vrf_id = htonl(vrf_id);
7595 mp->path_mtu = htonl(path_mtu);
7596 mp->template_interval = htonl(template_interval);
7602 static int api_get_node_index (vat_main_t * vam)
7604 unformat_input_t * i = vam->input;
7605 vl_api_get_node_index_t * mp;
7609 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7610 if (unformat (i, "node %s", &name))
7616 errmsg ("node name required\n");
7619 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7620 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7624 M(GET_NODE_INDEX, get_node_index);
7625 clib_memcpy (mp->node_name, name, vec_len(name));
7633 static int api_add_node_next (vat_main_t * vam)
7635 unformat_input_t * i = vam->input;
7636 vl_api_add_node_next_t * mp;
7641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7642 if (unformat (i, "node %s", &name))
7644 else if (unformat (i, "next %s", &next))
7650 errmsg ("node name required\n");
7653 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7654 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7658 errmsg ("next node required\n");
7661 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
7662 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
7666 M(ADD_NODE_NEXT, add_node_next);
7667 clib_memcpy (mp->node_name, name, vec_len(name));
7668 clib_memcpy (mp->next_name, next, vec_len(next));
7677 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
7679 unformat_input_t * i = vam->input;
7680 ip6_address_t client_address, our_address;
7681 int client_address_set = 0;
7682 int our_address_set = 0;
7683 u32 local_session_id = 0;
7684 u32 remote_session_id = 0;
7685 u64 local_cookie = 0;
7686 u64 remote_cookie = 0;
7687 u8 l2_sublayer_present = 0;
7688 vl_api_l2tpv3_create_tunnel_t * mp;
7691 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7692 if (unformat (i, "client_address %U", unformat_ip6_address,
7694 client_address_set = 1;
7695 else if (unformat (i, "our_address %U", unformat_ip6_address,
7697 our_address_set = 1;
7698 else if (unformat (i, "local_session_id %d", &local_session_id))
7700 else if (unformat (i, "remote_session_id %d", &remote_session_id))
7702 else if (unformat (i, "local_cookie %lld", &local_cookie))
7704 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7706 else if (unformat (i, "l2-sublayer-present"))
7707 l2_sublayer_present = 1;
7712 if (client_address_set == 0) {
7713 errmsg ("client_address required\n");
7717 if (our_address_set == 0) {
7718 errmsg ("our_address required\n");
7722 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7724 clib_memcpy (mp->client_address, client_address.as_u8,
7725 sizeof (mp->client_address));
7727 clib_memcpy (mp->our_address, our_address.as_u8,
7728 sizeof (mp->our_address));
7730 mp->local_session_id = ntohl (local_session_id);
7731 mp->remote_session_id = ntohl (remote_session_id);
7732 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7733 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7734 mp->l2_sublayer_present = l2_sublayer_present;
7742 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7744 unformat_input_t * i = vam->input;
7746 u8 sw_if_index_set = 0;
7747 u64 new_local_cookie = 0;
7748 u64 new_remote_cookie = 0;
7749 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7753 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7754 sw_if_index_set = 1;
7755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7756 sw_if_index_set = 1;
7757 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7759 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7765 if (sw_if_index_set == 0) {
7766 errmsg ("missing interface name or sw_if_index\n");
7770 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7772 mp->sw_if_index = ntohl(sw_if_index);
7773 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7774 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7781 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7783 unformat_input_t * i = vam->input;
7784 vl_api_l2tpv3_interface_enable_disable_t *mp;
7787 u8 sw_if_index_set = 0;
7788 u8 enable_disable = 1;
7790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7791 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7792 sw_if_index_set = 1;
7793 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7794 sw_if_index_set = 1;
7795 else if (unformat (i, "enable"))
7797 else if (unformat (i, "disable"))
7803 if (sw_if_index_set == 0) {
7804 errmsg ("missing interface name or sw_if_index\n");
7808 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7810 mp->sw_if_index = ntohl(sw_if_index);
7811 mp->enable_disable = enable_disable;
7818 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7820 unformat_input_t * i = vam->input;
7821 vl_api_l2tpv3_set_lookup_key_t * mp;
7825 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7826 if (unformat (i, "lookup_v6_src"))
7827 key = L2T_LOOKUP_SRC_ADDRESS;
7828 else if (unformat (i, "lookup_v6_dst"))
7829 key = L2T_LOOKUP_DST_ADDRESS;
7830 else if (unformat (i, "lookup_session_id"))
7831 key = L2T_LOOKUP_SESSION_ID;
7836 if (key == (u8) ~0) {
7837 errmsg ("l2tp session lookup key unset\n");
7841 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7850 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7851 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7853 vat_main_t * vam = &vat_main;
7855 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7856 format_ip6_address, mp->our_address,
7857 format_ip6_address, mp->client_address,
7858 clib_net_to_host_u32(mp->sw_if_index));
7860 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7861 clib_net_to_host_u64 (mp->local_cookie[0]),
7862 clib_net_to_host_u64 (mp->local_cookie[1]),
7863 clib_net_to_host_u64 (mp->remote_cookie));
7865 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7866 clib_net_to_host_u32 (mp->local_session_id),
7867 clib_net_to_host_u32 (mp->remote_session_id));
7869 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7870 mp->l2_sublayer_present ? "preset" : "absent");
7874 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7875 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7877 vat_main_t * vam = &vat_main;
7878 vat_json_node_t *node = NULL;
7879 struct in6_addr addr;
7881 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7882 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7883 vat_json_init_array(&vam->json_tree);
7885 node = vat_json_array_add(&vam->json_tree);
7887 vat_json_init_object(node);
7889 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7890 vat_json_object_add_ip6(node, "our_address", addr);
7891 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7892 vat_json_object_add_ip6(node, "client_address", addr);
7894 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7895 vat_json_init_array(lc);
7896 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7897 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7898 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7900 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7901 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7902 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7903 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7904 (u8*)"present" : (u8*)"absent");
7907 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7909 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7912 /* Get list of l2tpv3-tunnel interfaces */
7913 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7916 /* Use a control ping for synchronization */
7918 vl_api_control_ping_t * mp;
7919 M(CONTROL_PING, control_ping);
7926 static void vl_api_sw_interface_tap_details_t_handler
7927 (vl_api_sw_interface_tap_details_t * mp)
7929 vat_main_t * vam = &vat_main;
7931 fformat(vam->ofp, "%-16s %d\n",
7933 clib_net_to_host_u32(mp->sw_if_index));
7936 static void vl_api_sw_interface_tap_details_t_handler_json
7937 (vl_api_sw_interface_tap_details_t * mp)
7939 vat_main_t * vam = &vat_main;
7940 vat_json_node_t *node = NULL;
7942 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7943 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7944 vat_json_init_array(&vam->json_tree);
7946 node = vat_json_array_add(&vam->json_tree);
7948 vat_json_init_object(node);
7949 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7950 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7953 static int api_sw_interface_tap_dump (vat_main_t * vam)
7955 vl_api_sw_interface_tap_dump_t *mp;
7958 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7959 /* Get list of tap interfaces */
7960 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7963 /* Use a control ping for synchronization */
7965 vl_api_control_ping_t * mp;
7966 M(CONTROL_PING, control_ping);
7972 static uword unformat_vxlan_decap_next
7973 (unformat_input_t * input, va_list * args)
7975 u32 * result = va_arg (*args, u32 *);
7978 if (unformat (input, "drop"))
7979 *result = VXLAN_INPUT_NEXT_DROP;
7980 else if (unformat (input, "ip4"))
7981 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7982 else if (unformat (input, "ip6"))
7983 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7984 else if (unformat (input, "l2"))
7985 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7986 else if (unformat (input, "%d", &tmp))
7993 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7995 unformat_input_t * line_input = vam->input;
7996 vl_api_vxlan_add_del_tunnel_t *mp;
7998 ip4_address_t src4, dst4;
7999 ip6_address_t src6, dst6;
8001 u8 ipv4_set = 0, ipv6_set = 0;
8004 u32 encap_vrf_id = 0;
8005 u32 decap_next_index = ~0;
8008 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8009 if (unformat (line_input, "del"))
8011 else if (unformat (line_input, "src %U",
8012 unformat_ip4_address, &src4))
8017 else if (unformat (line_input, "dst %U",
8018 unformat_ip4_address, &dst4))
8023 else if (unformat (line_input, "src %U",
8024 unformat_ip6_address, &src6))
8029 else if (unformat (line_input, "dst %U",
8030 unformat_ip6_address, &dst6))
8035 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8037 else if (unformat (line_input, "decap-next %U",
8038 unformat_vxlan_decap_next, &decap_next_index))
8040 else if (unformat (line_input, "vni %d", &vni))
8043 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8049 errmsg ("tunnel src address not specified\n");
8053 errmsg ("tunnel dst address not specified\n");
8057 if (ipv4_set && ipv6_set) {
8058 errmsg ("both IPv4 and IPv6 addresses specified");
8062 if ((vni == 0) || (vni>>24)) {
8063 errmsg ("vni not specified or out of range\n");
8067 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
8070 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
8071 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
8073 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8074 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8076 mp->encap_vrf_id = ntohl(encap_vrf_id);
8077 mp->decap_next_index = ntohl(decap_next_index);
8078 mp->vni = ntohl(vni);
8079 mp->is_add = is_add;
8080 mp->is_ipv6 = ipv6_set;
8087 static void vl_api_vxlan_tunnel_details_t_handler
8088 (vl_api_vxlan_tunnel_details_t * mp)
8090 vat_main_t * vam = &vat_main;
8092 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
8093 ntohl(mp->sw_if_index),
8094 format_ip46_address, &(mp->src_address[0]),
8096 format_ip46_address, &(mp->dst_address[0]),
8098 ntohl(mp->encap_vrf_id),
8099 ntohl(mp->decap_next_index),
8103 static void vl_api_vxlan_tunnel_details_t_handler_json
8104 (vl_api_vxlan_tunnel_details_t * mp)
8106 vat_main_t * vam = &vat_main;
8107 vat_json_node_t *node = NULL;
8109 struct in6_addr ip6;
8111 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8112 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8113 vat_json_init_array(&vam->json_tree);
8115 node = vat_json_array_add(&vam->json_tree);
8117 vat_json_init_object(node);
8118 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8120 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
8121 vat_json_object_add_ip6(node, "src_address", ip6);
8122 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
8123 vat_json_object_add_ip6(node, "dst_address", ip6);
8125 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
8126 vat_json_object_add_ip4(node, "src_address", ip4);
8127 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
8128 vat_json_object_add_ip4(node, "dst_address", ip4);
8130 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8131 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
8132 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8133 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8136 static int api_vxlan_tunnel_dump (vat_main_t * vam)
8138 unformat_input_t * i = vam->input;
8139 vl_api_vxlan_tunnel_dump_t *mp;
8142 u8 sw_if_index_set = 0;
8144 /* Parse args required to build the message */
8145 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8146 if (unformat (i, "sw_if_index %d", &sw_if_index))
8147 sw_if_index_set = 1;
8152 if (sw_if_index_set == 0) {
8156 if (!vam->json_output) {
8157 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
8158 "sw_if_index", "src_address", "dst_address",
8159 "encap_vrf_id", "decap_next_index", "vni");
8162 /* Get list of vxlan-tunnel interfaces */
8163 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
8165 mp->sw_if_index = htonl(sw_if_index);
8169 /* Use a control ping for synchronization */
8171 vl_api_control_ping_t * mp;
8172 M(CONTROL_PING, control_ping);
8178 static int api_gre_add_del_tunnel (vat_main_t * vam)
8180 unformat_input_t * line_input = vam->input;
8181 vl_api_gre_add_del_tunnel_t *mp;
8183 ip4_address_t src4, dst4;
8187 u32 outer_fib_id = 0;
8189 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8190 if (unformat (line_input, "del"))
8192 else if (unformat (line_input, "src %U",
8193 unformat_ip4_address, &src4))
8195 else if (unformat (line_input, "dst %U",
8196 unformat_ip4_address, &dst4))
8198 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
8201 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8207 errmsg ("tunnel src address not specified\n");
8211 errmsg ("tunnel dst address not specified\n");
8216 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
8218 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8219 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8220 mp->outer_table_id = ntohl(outer_fib_id);
8221 mp->is_add = is_add;
8228 static void vl_api_gre_tunnel_details_t_handler
8229 (vl_api_gre_tunnel_details_t * mp)
8231 vat_main_t * vam = &vat_main;
8233 fformat(vam->ofp, "%11d%15U%15U%14d\n",
8234 ntohl(mp->sw_if_index),
8235 format_ip4_address, &mp->src_address,
8236 format_ip4_address, &mp->dst_address,
8237 ntohl(mp->outer_table_id));
8240 static void vl_api_gre_tunnel_details_t_handler_json
8241 (vl_api_gre_tunnel_details_t * mp)
8243 vat_main_t * vam = &vat_main;
8244 vat_json_node_t *node = NULL;
8247 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8248 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8249 vat_json_init_array(&vam->json_tree);
8251 node = vat_json_array_add(&vam->json_tree);
8253 vat_json_init_object(node);
8254 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8255 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
8256 vat_json_object_add_ip4(node, "src_address", ip4);
8257 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
8258 vat_json_object_add_ip4(node, "dst_address", ip4);
8259 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
8262 static int api_gre_tunnel_dump (vat_main_t * vam)
8264 unformat_input_t * i = vam->input;
8265 vl_api_gre_tunnel_dump_t *mp;
8268 u8 sw_if_index_set = 0;
8270 /* Parse args required to build the message */
8271 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8272 if (unformat (i, "sw_if_index %d", &sw_if_index))
8273 sw_if_index_set = 1;
8278 if (sw_if_index_set == 0) {
8282 if (!vam->json_output) {
8283 fformat(vam->ofp, "%11s%15s%15s%14s\n",
8284 "sw_if_index", "src_address", "dst_address",
8288 /* Get list of gre-tunnel interfaces */
8289 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
8291 mp->sw_if_index = htonl(sw_if_index);
8295 /* Use a control ping for synchronization */
8297 vl_api_control_ping_t * mp;
8298 M(CONTROL_PING, control_ping);
8304 static int api_l2_fib_clear_table (vat_main_t * vam)
8306 // unformat_input_t * i = vam->input;
8307 vl_api_l2_fib_clear_table_t *mp;
8310 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
8317 static int api_l2_interface_efp_filter (vat_main_t * vam)
8319 unformat_input_t * i = vam->input;
8320 vl_api_l2_interface_efp_filter_t *mp;
8324 u8 sw_if_index_set = 0;
8326 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8327 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8328 sw_if_index_set = 1;
8329 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8330 sw_if_index_set = 1;
8331 else if (unformat (i, "enable"))
8333 else if (unformat (i, "disable"))
8336 clib_warning ("parse error '%U'", format_unformat_error, i);
8341 if (sw_if_index_set == 0) {
8342 errmsg ("missing sw_if_index\n");
8346 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
8348 mp->sw_if_index = ntohl(sw_if_index);
8349 mp->enable_disable = enable;
8356 #define foreach_vtr_op \
8357 _("disable", L2_VTR_DISABLED) \
8358 _("push-1", L2_VTR_PUSH_1) \
8359 _("push-2", L2_VTR_PUSH_2) \
8360 _("pop-1", L2_VTR_POP_1) \
8361 _("pop-2", L2_VTR_POP_2) \
8362 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8363 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8364 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8365 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8367 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8369 unformat_input_t * i = vam->input;
8370 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8373 u8 sw_if_index_set = 0;
8380 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8381 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8382 sw_if_index_set = 1;
8383 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8384 sw_if_index_set = 1;
8385 else if (unformat (i, "vtr_op %d", &vtr_op))
8387 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8391 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8393 else if (unformat (i, "tag1 %d", &tag1))
8395 else if (unformat (i, "tag2 %d", &tag2))
8398 clib_warning ("parse error '%U'", format_unformat_error, i);
8403 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
8404 errmsg ("missing vtr operation or sw_if_index\n");
8408 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
8410 mp->sw_if_index = ntohl(sw_if_index);
8411 mp->vtr_op = ntohl(vtr_op);
8412 mp->push_dot1q = ntohl(push_dot1q);
8413 mp->tag1 = ntohl(tag1);
8414 mp->tag2 = ntohl(tag2);
8421 static int api_create_vhost_user_if (vat_main_t * vam)
8423 unformat_input_t * i = vam->input;
8424 vl_api_create_vhost_user_if_t *mp;
8428 u8 file_name_set = 0;
8429 u32 custom_dev_instance = ~0;
8431 u8 use_custom_mac = 0;
8433 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8434 if (unformat (i, "socket %s", &file_name)) {
8437 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8439 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8441 else if (unformat (i, "server"))
8447 if (file_name_set == 0) {
8448 errmsg ("missing socket file name\n");
8452 if (vec_len (file_name) > 255) {
8453 errmsg ("socket file name too long\n");
8456 vec_add1 (file_name, 0);
8458 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8460 mp->is_server = is_server;
8461 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8462 vec_free(file_name);
8463 if (custom_dev_instance != ~0) {
8465 mp->custom_dev_instance = ntohl(custom_dev_instance);
8467 mp->use_custom_mac = use_custom_mac;
8468 clib_memcpy(mp->mac_address, hwaddr, 6);
8475 static int api_modify_vhost_user_if (vat_main_t * vam)
8477 unformat_input_t * i = vam->input;
8478 vl_api_modify_vhost_user_if_t *mp;
8482 u8 file_name_set = 0;
8483 u32 custom_dev_instance = ~0;
8484 u8 sw_if_index_set = 0;
8485 u32 sw_if_index = (u32)~0;
8487 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8488 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8489 sw_if_index_set = 1;
8490 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8491 sw_if_index_set = 1;
8492 else if (unformat (i, "socket %s", &file_name)) {
8495 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8497 else if (unformat (i, "server"))
8503 if (sw_if_index_set == 0) {
8504 errmsg ("missing sw_if_index or interface name\n");
8508 if (file_name_set == 0) {
8509 errmsg ("missing socket file name\n");
8513 if (vec_len (file_name) > 255) {
8514 errmsg ("socket file name too long\n");
8517 vec_add1 (file_name, 0);
8519 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8521 mp->sw_if_index = ntohl(sw_if_index);
8522 mp->is_server = is_server;
8523 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8524 vec_free(file_name);
8525 if (custom_dev_instance != ~0) {
8527 mp->custom_dev_instance = ntohl(custom_dev_instance);
8535 static int api_delete_vhost_user_if (vat_main_t * vam)
8537 unformat_input_t * i = vam->input;
8538 vl_api_delete_vhost_user_if_t *mp;
8540 u32 sw_if_index = ~0;
8541 u8 sw_if_index_set = 0;
8543 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8544 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8545 sw_if_index_set = 1;
8546 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8547 sw_if_index_set = 1;
8552 if (sw_if_index_set == 0) {
8553 errmsg ("missing sw_if_index or interface name\n");
8558 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8560 mp->sw_if_index = ntohl(sw_if_index);
8567 static void vl_api_sw_interface_vhost_user_details_t_handler
8568 (vl_api_sw_interface_vhost_user_details_t * mp)
8570 vat_main_t * vam = &vat_main;
8572 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8573 (char *)mp->interface_name,
8574 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8575 clib_net_to_host_u64(mp->features), mp->is_server,
8576 ntohl(mp->num_regions), (char *)mp->sock_filename);
8577 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8580 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8581 (vl_api_sw_interface_vhost_user_details_t * mp)
8583 vat_main_t * vam = &vat_main;
8584 vat_json_node_t *node = NULL;
8586 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8587 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8588 vat_json_init_array(&vam->json_tree);
8590 node = vat_json_array_add(&vam->json_tree);
8592 vat_json_init_object(node);
8593 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8594 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8595 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8596 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8597 vat_json_object_add_uint(node, "is_server", mp->is_server);
8598 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8599 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8600 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8603 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8605 vl_api_sw_interface_vhost_user_dump_t *mp;
8607 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8609 /* Get list of vhost-user interfaces */
8610 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8613 /* Use a control ping for synchronization */
8615 vl_api_control_ping_t * mp;
8616 M(CONTROL_PING, control_ping);
8622 static int api_show_version (vat_main_t * vam)
8624 vl_api_show_version_t *mp;
8627 M(SHOW_VERSION, show_version);
8635 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8637 unformat_input_t * line_input = vam->input;
8638 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
8640 ip4_address_t local4, remote4;
8641 ip6_address_t local6, remote6;
8643 u8 ipv4_set = 0, ipv6_set = 0;
8646 u32 encap_vrf_id = 0;
8647 u32 decap_vrf_id = 0;
8652 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8653 if (unformat (line_input, "del"))
8655 else if (unformat (line_input, "local %U",
8656 unformat_ip4_address, &local4))
8661 else if (unformat (line_input, "remote %U",
8662 unformat_ip4_address, &remote4))
8667 else if (unformat (line_input, "local %U",
8668 unformat_ip6_address, &local6))
8673 else if (unformat (line_input, "remote %U",
8674 unformat_ip6_address, &remote6))
8679 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8681 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8683 else if (unformat (line_input, "vni %d", &vni))
8685 else if (unformat(line_input, "next-ip4"))
8687 else if (unformat(line_input, "next-ip6"))
8689 else if (unformat(line_input, "next-ethernet"))
8691 else if (unformat(line_input, "next-nsh"))
8694 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8699 if (local_set == 0) {
8700 errmsg ("tunnel local address not specified\n");
8703 if (remote_set == 0) {
8704 errmsg ("tunnel remote address not specified\n");
8707 if (ipv4_set && ipv6_set) {
8708 errmsg ("both IPv4 and IPv6 addresses specified");
8713 errmsg ("vni not specified\n");
8717 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
8721 clib_memcpy(&mp->local, &local6, sizeof(local6));
8722 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
8724 clib_memcpy(&mp->local, &local4, sizeof(local4));
8725 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
8728 mp->encap_vrf_id = ntohl(encap_vrf_id);
8729 mp->decap_vrf_id = ntohl(decap_vrf_id);
8730 mp->protocol = ntohl(protocol);
8731 mp->vni = ntohl(vni);
8732 mp->is_add = is_add;
8733 mp->is_ipv6 = ipv6_set;
8740 static void vl_api_vxlan_gpe_tunnel_details_t_handler
8741 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8743 vat_main_t * vam = &vat_main;
8745 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
8746 ntohl(mp->sw_if_index),
8747 format_ip46_address, &(mp->local[0]),
8748 format_ip46_address, &(mp->remote[0]),
8750 ntohl(mp->protocol),
8751 ntohl(mp->encap_vrf_id),
8752 ntohl(mp->decap_vrf_id));
8755 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
8756 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8758 vat_main_t * vam = &vat_main;
8759 vat_json_node_t *node = NULL;
8761 struct in6_addr ip6;
8763 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8764 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8765 vat_json_init_array(&vam->json_tree);
8767 node = vat_json_array_add(&vam->json_tree);
8769 vat_json_init_object(node);
8770 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8772 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
8773 vat_json_object_add_ip6(node, "local", ip6);
8774 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
8775 vat_json_object_add_ip6(node, "remote", ip6);
8777 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
8778 vat_json_object_add_ip4(node, "local", ip4);
8779 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
8780 vat_json_object_add_ip4(node, "remote", ip4);
8782 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8783 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
8784 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8785 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
8786 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8789 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
8791 unformat_input_t * i = vam->input;
8792 vl_api_vxlan_gpe_tunnel_dump_t *mp;
8795 u8 sw_if_index_set = 0;
8797 /* Parse args required to build the message */
8798 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8799 if (unformat (i, "sw_if_index %d", &sw_if_index))
8800 sw_if_index_set = 1;
8805 if (sw_if_index_set == 0) {
8809 if (!vam->json_output) {
8810 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
8811 "sw_if_index", "local", "remote", "vni",
8812 "protocol","encap_vrf_id", "decap_vrf_id");
8815 /* Get list of vxlan-tunnel interfaces */
8816 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
8818 mp->sw_if_index = htonl(sw_if_index);
8822 /* Use a control ping for synchronization */
8824 vl_api_control_ping_t * mp;
8825 M(CONTROL_PING, control_ping);
8831 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8833 u8 * a = va_arg (*args, u8 *);
8835 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8836 a[2], a[3], a[4], a[5], a[6], a[7]);
8839 static void vl_api_l2_fib_table_entry_t_handler
8840 (vl_api_l2_fib_table_entry_t * mp)
8842 vat_main_t * vam = &vat_main;
8844 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8846 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8847 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8851 static void vl_api_l2_fib_table_entry_t_handler_json
8852 (vl_api_l2_fib_table_entry_t * mp)
8854 vat_main_t * vam = &vat_main;
8855 vat_json_node_t *node = NULL;
8857 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8858 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8859 vat_json_init_array(&vam->json_tree);
8861 node = vat_json_array_add(&vam->json_tree);
8863 vat_json_init_object(node);
8864 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8865 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8866 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8867 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8868 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8869 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8872 static int api_l2_fib_table_dump (vat_main_t * vam)
8874 unformat_input_t * i = vam->input;
8875 vl_api_l2_fib_table_dump_t *mp;
8880 /* Parse args required to build the message */
8881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8882 if (unformat (i, "bd_id %d", &bd_id))
8888 if (bd_id_set == 0) {
8889 errmsg ("missing bridge domain\n");
8893 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8895 /* Get list of l2 fib entries */
8896 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8898 mp->bd_id = ntohl(bd_id);
8901 /* Use a control ping for synchronization */
8903 vl_api_control_ping_t * mp;
8904 M(CONTROL_PING, control_ping);
8912 api_interface_name_renumber (vat_main_t * vam)
8914 unformat_input_t * line_input = vam->input;
8915 vl_api_interface_name_renumber_t *mp;
8916 u32 sw_if_index = ~0;
8918 u32 new_show_dev_instance = ~0;
8920 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8921 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8924 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8926 else if (unformat (line_input, "new_show_dev_instance %d",
8927 &new_show_dev_instance))
8933 if (sw_if_index == ~0) {
8934 errmsg ("missing interface name or sw_if_index\n");
8938 if (new_show_dev_instance == ~0) {
8939 errmsg ("missing new_show_dev_instance\n");
8943 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8945 mp->sw_if_index = ntohl (sw_if_index);
8946 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8952 api_want_ip4_arp_events (vat_main_t * vam)
8954 unformat_input_t * line_input = vam->input;
8955 vl_api_want_ip4_arp_events_t * mp;
8957 ip4_address_t address;
8958 int address_set = 0;
8959 u32 enable_disable = 1;
8961 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8962 if (unformat (line_input, "address %U",
8963 unformat_ip4_address, &address))
8965 else if (unformat (line_input, "del"))
8971 if (address_set == 0) {
8972 errmsg ("missing addresses\n");
8976 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8977 mp->enable_disable = enable_disable;
8979 mp->address = address.as_u32;
8984 static int api_input_acl_set_interface (vat_main_t * vam)
8986 unformat_input_t * i = vam->input;
8987 vl_api_input_acl_set_interface_t *mp;
8990 int sw_if_index_set;
8991 u32 ip4_table_index = ~0;
8992 u32 ip6_table_index = ~0;
8993 u32 l2_table_index = ~0;
8996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8997 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8998 sw_if_index_set = 1;
8999 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9000 sw_if_index_set = 1;
9001 else if (unformat (i, "del"))
9003 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9005 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9007 else if (unformat (i, "l2-table %d", &l2_table_index))
9010 clib_warning ("parse error '%U'", format_unformat_error, i);
9015 if (sw_if_index_set == 0) {
9016 errmsg ("missing interface name or sw_if_index\n");
9020 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
9022 mp->sw_if_index = ntohl(sw_if_index);
9023 mp->ip4_table_index = ntohl(ip4_table_index);
9024 mp->ip6_table_index = ntohl(ip6_table_index);
9025 mp->l2_table_index = ntohl(l2_table_index);
9026 mp->is_add = is_add;
9034 api_ip_address_dump (vat_main_t * vam)
9036 unformat_input_t * i = vam->input;
9037 vl_api_ip_address_dump_t * mp;
9038 u32 sw_if_index = ~0;
9039 u8 sw_if_index_set = 0;
9044 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9045 if (unformat (i, "sw_if_index %d", &sw_if_index))
9046 sw_if_index_set = 1;
9047 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9048 sw_if_index_set = 1;
9049 else if (unformat (i, "ipv4"))
9051 else if (unformat (i, "ipv6"))
9057 if (ipv4_set && ipv6_set) {
9058 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9062 if ((!ipv4_set) && (!ipv6_set)) {
9063 errmsg ("no ipv4 nor ipv6 flag set\n");
9067 if (sw_if_index_set == 0) {
9068 errmsg ("missing interface name or sw_if_index\n");
9072 vam->current_sw_if_index = sw_if_index;
9073 vam->is_ipv6 = ipv6_set;
9075 M(IP_ADDRESS_DUMP, ip_address_dump);
9076 mp->sw_if_index = ntohl(sw_if_index);
9077 mp->is_ipv6 = ipv6_set;
9080 /* Use a control ping for synchronization */
9082 vl_api_control_ping_t * mp;
9083 M(CONTROL_PING, control_ping);
9090 api_ip_dump (vat_main_t * vam)
9092 vl_api_ip_dump_t * mp;
9093 unformat_input_t * in = vam->input;
9100 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
9101 if (unformat (in, "ipv4"))
9103 else if (unformat (in, "ipv6"))
9109 if (ipv4_set && ipv6_set) {
9110 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9114 if ((!ipv4_set) && (!ipv6_set)) {
9115 errmsg ("no ipv4 nor ipv6 flag set\n");
9120 vam->is_ipv6 = is_ipv6;
9123 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
9124 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9126 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
9128 M(IP_DUMP, ip_dump);
9129 mp->is_ipv6 = ipv6_set;
9132 /* Use a control ping for synchronization */
9134 vl_api_control_ping_t * mp;
9135 M(CONTROL_PING, control_ping);
9142 api_ipsec_spd_add_del (vat_main_t * vam)
9145 unformat_input_t * i = vam->input;
9146 vl_api_ipsec_spd_add_del_t *mp;
9151 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9152 if (unformat (i, "spd_id %d", &spd_id))
9154 else if (unformat (i, "del"))
9157 clib_warning ("parse error '%U'", format_unformat_error, i);
9162 errmsg ("spd_id must be set\n");
9166 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
9168 mp->spd_id = ntohl(spd_id);
9169 mp->is_add = is_add;
9175 clib_warning ("unsupported (no dpdk)");
9181 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9184 unformat_input_t * i = vam->input;
9185 vl_api_ipsec_interface_add_del_spd_t *mp;
9188 u8 sw_if_index_set = 0;
9189 u32 spd_id = (u32) ~0;
9192 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9193 if (unformat (i, "del"))
9195 else if (unformat (i, "spd_id %d", &spd_id))
9197 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9198 sw_if_index_set = 1;
9199 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9200 sw_if_index_set = 1;
9202 clib_warning ("parse error '%U'", format_unformat_error, i);
9208 if (spd_id == (u32) ~0) {
9209 errmsg ("spd_id must be set\n");
9213 if (sw_if_index_set == 0) {
9214 errmsg ("missing interface name or sw_if_index\n");
9218 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
9220 mp->spd_id = ntohl(spd_id);
9221 mp->sw_if_index = ntohl (sw_if_index);
9222 mp->is_add = is_add;
9228 clib_warning ("unsupported (no dpdk)");
9234 api_ipsec_spd_add_del_entry (vat_main_t * vam)
9237 unformat_input_t * i = vam->input;
9238 vl_api_ipsec_spd_add_del_entry_t *mp;
9240 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
9241 u32 spd_id, sa_id, protocol = 0, policy = 0;
9243 u32 rport_start = 0, rport_stop = (u32) ~0;
9244 u32 lport_start = 0, lport_stop = (u32) ~0;
9245 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
9246 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
9248 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
9249 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
9250 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
9251 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
9252 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
9253 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
9255 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9256 if (unformat (i, "del"))
9258 if (unformat (i, "outbound"))
9260 if (unformat (i, "inbound"))
9262 else if (unformat (i, "spd_id %d", &spd_id))
9264 else if (unformat (i, "sa_id %d", &sa_id))
9266 else if (unformat (i, "priority %d", &priority))
9268 else if (unformat (i, "protocol %d", &protocol))
9270 else if (unformat (i, "lport_start %d", &lport_start))
9272 else if (unformat (i, "lport_stop %d", &lport_stop))
9274 else if (unformat (i, "rport_start %d", &rport_start))
9276 else if (unformat (i, "rport_stop %d", &rport_stop))
9278 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
9283 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
9288 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
9293 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
9298 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
9303 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
9308 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
9313 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
9318 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9320 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
9321 clib_warning ("unsupported action: 'resolve'");
9326 clib_warning ("parse error '%U'", format_unformat_error, i);
9332 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
9334 mp->spd_id = ntohl(spd_id);
9335 mp->priority = ntohl(priority);
9336 mp->is_outbound = is_outbound;
9338 mp->is_ipv6 = is_ipv6;
9339 if (is_ipv6 || is_ip_any) {
9340 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
9341 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
9342 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
9343 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
9345 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
9346 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
9347 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
9348 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
9350 mp->protocol = (u8) protocol;
9351 mp->local_port_start = ntohs((u16) lport_start);
9352 mp->local_port_stop = ntohs((u16) lport_stop);
9353 mp->remote_port_start = ntohs((u16) rport_start);
9354 mp->remote_port_stop = ntohs((u16) rport_stop);
9355 mp->policy = (u8) policy;
9356 mp->sa_id = ntohl(sa_id);
9357 mp->is_add = is_add;
9358 mp->is_ip_any = is_ip_any;
9363 clib_warning ("unsupported (no dpdk)");
9369 api_ipsec_sad_add_del_entry (vat_main_t * vam)
9372 unformat_input_t * i = vam->input;
9373 vl_api_ipsec_sad_add_del_entry_t *mp;
9379 u8 protocol = IPSEC_PROTOCOL_AH;
9380 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
9381 u32 crypto_alg = 0, integ_alg = 0;
9382 ip4_address_t tun_src4;
9383 ip4_address_t tun_dst4;
9384 ip6_address_t tun_src6;
9385 ip6_address_t tun_dst6;
9387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9388 if (unformat (i, "del"))
9390 else if (unformat (i, "sad_id %d", &sad_id))
9392 else if (unformat (i, "spi %d", &spi))
9394 else if (unformat (i, "esp"))
9395 protocol = IPSEC_PROTOCOL_ESP;
9396 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
9400 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
9404 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
9408 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
9412 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
9413 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
9414 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9415 clib_warning ("unsupported crypto-alg: '%U'",
9416 format_ipsec_crypto_alg, crypto_alg);
9420 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9422 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
9423 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
9424 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9425 clib_warning ("unsupported integ-alg: '%U'",
9426 format_ipsec_integ_alg, integ_alg);
9430 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9433 clib_warning ("parse error '%U'", format_unformat_error, i);
9439 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
9441 mp->sad_id = ntohl(sad_id);
9442 mp->is_add = is_add;
9443 mp->protocol = protocol;
9444 mp->spi = ntohl(spi);
9445 mp->is_tunnel = is_tunnel;
9446 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
9447 mp->crypto_algorithm = crypto_alg;
9448 mp->integrity_algorithm = integ_alg;
9449 mp->crypto_key_length = vec_len(ck);
9450 mp->integrity_key_length = vec_len(ik);
9452 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9453 mp->crypto_key_length = sizeof(mp->crypto_key);
9455 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9456 mp->integrity_key_length = sizeof(mp->integrity_key);
9458 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9459 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9462 if (is_tunnel_ipv6) {
9463 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9464 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9466 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9467 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9475 clib_warning ("unsupported (no dpdk)");
9481 api_ipsec_sa_set_key (vat_main_t * vam)
9484 unformat_input_t * i = vam->input;
9485 vl_api_ipsec_sa_set_key_t *mp;
9490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9491 if (unformat (i, "sa_id %d", &sa_id))
9493 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9495 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9498 clib_warning ("parse error '%U'", format_unformat_error, i);
9503 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9505 mp->sa_id = ntohl(sa_id);
9506 mp->crypto_key_length = vec_len(ck);
9507 mp->integrity_key_length = vec_len(ik);
9509 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9510 mp->crypto_key_length = sizeof(mp->crypto_key);
9512 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9513 mp->integrity_key_length = sizeof(mp->integrity_key);
9515 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9516 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9522 clib_warning ("unsupported (no dpdk)");
9528 api_ikev2_profile_add_del (vat_main_t * vam)
9531 unformat_input_t * i = vam->input;
9532 vl_api_ikev2_profile_add_del_t * mp;
9537 const char * valid_chars = "a-zA-Z0-9_";
9539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9540 if (unformat (i, "del"))
9542 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9545 errmsg ("parse error '%U'", format_unformat_error, i);
9550 if (!vec_len (name)) {
9551 errmsg ("profile name must be specified");
9555 if (vec_len (name) > 64) {
9556 errmsg ("profile name too long");
9560 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9562 clib_memcpy(mp->name, name, vec_len (name));
9563 mp->is_add = is_add;
9570 clib_warning ("unsupported (no dpdk)");
9576 api_ikev2_profile_set_auth (vat_main_t * vam)
9579 unformat_input_t * i = vam->input;
9580 vl_api_ikev2_profile_set_auth_t * mp;
9584 u32 auth_method = 0;
9587 const char * valid_chars = "a-zA-Z0-9_";
9589 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9590 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9592 else if (unformat (i, "auth_method %U",
9593 unformat_ikev2_auth_method, &auth_method))
9595 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9597 else if (unformat (i, "auth_data %v", &data))
9600 errmsg ("parse error '%U'", format_unformat_error, i);
9605 if (!vec_len (name)) {
9606 errmsg ("profile name must be specified");
9610 if (vec_len (name) > 64) {
9611 errmsg ("profile name too long");
9615 if (!vec_len(data)) {
9616 errmsg ("auth_data must be specified");
9621 errmsg ("auth_method must be specified");
9625 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9627 mp->is_hex = is_hex;
9628 mp->auth_method = (u8) auth_method;
9629 mp->data_len = vec_len (data);
9630 clib_memcpy (mp->name, name, vec_len (name));
9631 clib_memcpy (mp->data, data, vec_len (data));
9639 clib_warning ("unsupported (no dpdk)");
9645 api_ikev2_profile_set_id (vat_main_t * vam)
9648 unformat_input_t * i = vam->input;
9649 vl_api_ikev2_profile_set_id_t * mp;
9657 const char * valid_chars = "a-zA-Z0-9_";
9659 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9660 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9662 else if (unformat (i, "id_type %U",
9663 unformat_ikev2_id_type, &id_type))
9665 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9667 data = vec_new(u8, 4);
9668 clib_memcpy(data, ip4.as_u8, 4);
9670 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9672 else if (unformat (i, "id_data %v", &data))
9674 else if (unformat (i, "local"))
9676 else if (unformat (i, "remote"))
9679 errmsg ("parse error '%U'", format_unformat_error, i);
9684 if (!vec_len (name)) {
9685 errmsg ("profile name must be specified");
9689 if (vec_len (name) > 64) {
9690 errmsg ("profile name too long");
9694 if (!vec_len(data)) {
9695 errmsg ("id_data must be specified");
9700 errmsg ("id_type must be specified");
9704 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9706 mp->is_local = is_local;
9707 mp->id_type = (u8) id_type;
9708 mp->data_len = vec_len (data);
9709 clib_memcpy (mp->name, name, vec_len (name));
9710 clib_memcpy (mp->data, data, vec_len (data));
9718 clib_warning ("unsupported (no dpdk)");
9724 api_ikev2_profile_set_ts (vat_main_t * vam)
9727 unformat_input_t * i = vam->input;
9728 vl_api_ikev2_profile_set_ts_t * mp;
9732 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9733 ip4_address_t start_addr, end_addr;
9735 const char * valid_chars = "a-zA-Z0-9_";
9737 start_addr.as_u32 = 0;
9738 end_addr.as_u32 = (u32) ~0;
9740 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9741 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9743 else if (unformat (i, "protocol %d", &proto))
9745 else if (unformat (i, "start_port %d", &start_port))
9747 else if (unformat (i, "end_port %d", &end_port))
9749 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9751 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9753 else if (unformat (i, "local"))
9755 else if (unformat (i, "remote"))
9758 errmsg ("parse error '%U'", format_unformat_error, i);
9763 if (!vec_len (name)) {
9764 errmsg ("profile name must be specified");
9768 if (vec_len (name) > 64) {
9769 errmsg ("profile name too long");
9773 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9775 mp->is_local = is_local;
9776 mp->proto = (u8) proto;
9777 mp->start_port = (u16) start_port;
9778 mp->end_port = (u16) end_port;
9779 mp->start_addr = start_addr.as_u32;
9780 mp->end_addr = end_addr.as_u32;
9781 clib_memcpy (mp->name, name, vec_len (name));
9788 clib_warning ("unsupported (no dpdk)");
9794 api_ikev2_set_local_key (vat_main_t * vam)
9797 unformat_input_t * i = vam->input;
9798 vl_api_ikev2_set_local_key_t * mp;
9802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9803 if (unformat (i, "file %v", &file))
9806 errmsg ("parse error '%U'", format_unformat_error, i);
9811 if (!vec_len (file)) {
9812 errmsg ("RSA key file must be specified");
9816 if (vec_len (file) > 256) {
9817 errmsg ("file name too long");
9821 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9823 clib_memcpy (mp->key_file, file, vec_len (file));
9830 clib_warning ("unsupported (no dpdk)");
9838 static int api_map_add_domain (vat_main_t * vam)
9840 unformat_input_t *i = vam->input;
9841 vl_api_map_add_domain_t *mp;
9844 ip4_address_t ip4_prefix;
9845 ip6_address_t ip6_prefix;
9846 ip6_address_t ip6_src;
9848 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9850 u8 is_translation = 0;
9852 u8 ip6_src_len = 128;
9854 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9855 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9856 &ip4_prefix, &ip4_prefix_len))
9858 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9859 &ip6_prefix, &ip6_prefix_len))
9861 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9863 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9865 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9867 else if (unformat (i, "psid-offset %d", &psid_offset))
9869 else if (unformat (i, "psid-len %d", &psid_length))
9871 else if (unformat (i, "mtu %d", &mtu))
9873 else if (unformat (i, "map-t"))
9876 clib_warning ("parse error '%U'", format_unformat_error, i);
9881 if (num_m_args != 6) {
9882 errmsg("mandatory argument(s) missing\n");
9886 /* Construct the API message */
9887 M(MAP_ADD_DOMAIN, map_add_domain);
9889 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9890 mp->ip4_prefix_len = ip4_prefix_len;
9892 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9893 mp->ip6_prefix_len = ip6_prefix_len;
9895 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9896 mp->ip6_src_prefix_len = ip6_src_len;
9898 mp->ea_bits_len = ea_bits_len;
9899 mp->psid_offset = psid_offset;
9900 mp->psid_length = psid_length;
9901 mp->is_translation = is_translation;
9902 mp->mtu = htons(mtu);
9907 /* Wait for a reply, return good/bad news */
9911 static int api_map_del_domain (vat_main_t * vam)
9913 unformat_input_t *i = vam->input;
9914 vl_api_map_del_domain_t *mp;
9920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9921 if (unformat (i, "index %d", &index))
9924 clib_warning ("parse error '%U'", format_unformat_error, i);
9929 if (num_m_args != 1) {
9930 errmsg("mandatory argument(s) missing\n");
9934 /* Construct the API message */
9935 M(MAP_DEL_DOMAIN, map_del_domain);
9937 mp->index = ntohl(index);
9942 /* Wait for a reply, return good/bad news */
9946 static int api_map_add_del_rule (vat_main_t * vam)
9948 unformat_input_t *i = vam->input;
9949 vl_api_map_add_del_rule_t *mp;
9952 ip6_address_t ip6_dst;
9953 u32 num_m_args = 0, index, psid;
9955 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9956 if (unformat (i, "index %d", &index))
9958 else if (unformat (i, "psid %d", &psid))
9960 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9962 else if (unformat (i, "del")) {
9965 clib_warning ("parse error '%U'", format_unformat_error, i);
9970 /* Construct the API message */
9971 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9973 mp->index = ntohl(index);
9974 mp->is_add = is_add;
9975 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9976 mp->psid = ntohs(psid);
9981 /* Wait for a reply, return good/bad news */
9985 static int api_map_domain_dump (vat_main_t * vam)
9987 vl_api_map_domain_dump_t *mp;
9990 /* Construct the API message */
9991 M(MAP_DOMAIN_DUMP, map_domain_dump);
9996 /* Use a control ping for synchronization */
9998 vl_api_control_ping_t * mp;
9999 M(CONTROL_PING, control_ping);
10005 static int api_map_rule_dump (vat_main_t * vam)
10007 unformat_input_t *i = vam->input;
10008 vl_api_map_rule_dump_t *mp;
10010 u32 domain_index = ~0;
10012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10013 if (unformat (i, "index %u", &domain_index))
10019 if (domain_index == ~0) {
10020 clib_warning("parse error: domain index expected");
10024 /* Construct the API message */
10025 M(MAP_RULE_DUMP, map_rule_dump);
10027 mp->domain_index = htonl(domain_index);
10032 /* Use a control ping for synchronization */
10034 vl_api_control_ping_t * mp;
10035 M(CONTROL_PING, control_ping);
10041 static void vl_api_map_add_domain_reply_t_handler
10042 (vl_api_map_add_domain_reply_t * mp)
10044 vat_main_t * vam = &vat_main;
10045 i32 retval = ntohl(mp->retval);
10047 if (vam->async_mode) {
10048 vam->async_errors += (retval < 0);
10050 vam->retval = retval;
10051 vam->result_ready = 1;
10055 static void vl_api_map_add_domain_reply_t_handler_json
10056 (vl_api_map_add_domain_reply_t * mp)
10058 vat_main_t * vam = &vat_main;
10059 vat_json_node_t node;
10061 vat_json_init_object(&node);
10062 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
10063 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
10065 vat_json_print(vam->ofp, &node);
10066 vat_json_free(&node);
10068 vam->retval = ntohl(mp->retval);
10069 vam->result_ready = 1;
10073 api_get_first_msg_id (vat_main_t * vam)
10075 vl_api_get_first_msg_id_t * mp;
10077 unformat_input_t * i = vam->input;
10081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10082 if (unformat (i, "client %s", &name))
10088 if (name_set == 0) {
10089 errmsg ("missing client name\n");
10092 vec_add1 (name, 0);
10094 if (vec_len (name) > 63) {
10095 errmsg ("client name too long\n");
10099 M(GET_FIRST_MSG_ID, get_first_msg_id);
10100 clib_memcpy (mp->name, name, vec_len(name));
10106 static int api_cop_interface_enable_disable (vat_main_t * vam)
10108 unformat_input_t * line_input = vam->input;
10109 vl_api_cop_interface_enable_disable_t * mp;
10111 u32 sw_if_index = ~0;
10112 u8 enable_disable = 1;
10114 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10115 if (unformat (line_input, "disable"))
10116 enable_disable = 0;
10117 if (unformat (line_input, "enable"))
10118 enable_disable = 1;
10119 else if (unformat (line_input, "%U", unformat_sw_if_index,
10120 vam, &sw_if_index))
10122 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10128 if (sw_if_index == ~0) {
10129 errmsg ("missing interface name or sw_if_index\n");
10133 /* Construct the API message */
10134 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
10135 mp->sw_if_index = ntohl(sw_if_index);
10136 mp->enable_disable = enable_disable;
10140 /* Wait for the reply */
10144 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
10146 unformat_input_t * line_input = vam->input;
10147 vl_api_cop_whitelist_enable_disable_t * mp;
10149 u32 sw_if_index = ~0;
10150 u8 ip4=0, ip6=0, default_cop=0;
10153 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10154 if (unformat (line_input, "ip4"))
10156 else if (unformat (line_input, "ip6"))
10158 else if (unformat (line_input, "default"))
10160 else if (unformat (line_input, "%U", unformat_sw_if_index,
10161 vam, &sw_if_index))
10163 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10165 else if (unformat (line_input, "fib-id %d", &fib_id))
10171 if (sw_if_index == ~0) {
10172 errmsg ("missing interface name or sw_if_index\n");
10176 /* Construct the API message */
10177 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
10178 mp->sw_if_index = ntohl(sw_if_index);
10179 mp->fib_id = ntohl(fib_id);
10182 mp->default_cop = default_cop;
10186 /* Wait for the reply */
10190 static int api_get_node_graph (vat_main_t * vam)
10192 vl_api_get_node_graph_t * mp;
10195 M(GET_NODE_GRAPH, get_node_graph);
10199 /* Wait for the reply */
10204 api_lisp_add_del_locator_set(vat_main_t * vam)
10206 unformat_input_t * input = vam->input;
10207 vl_api_lisp_add_del_locator_set_t *mp;
10210 u8 *locator_set_name = NULL;
10211 u8 locator_set_name_set = 0;
10213 /* Parse args required to build the message */
10214 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10215 if (unformat(input, "del")) {
10217 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10218 locator_set_name_set = 1;
10223 if (locator_set_name_set == 0) {
10224 errmsg ("missing locator-set name");
10228 if (vec_len(locator_set_name) > 64) {
10229 errmsg ("locator-set name too long\n");
10230 vec_free(locator_set_name);
10233 vec_add1(locator_set_name, 0);
10235 /* Construct the API message */
10236 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
10238 mp->is_add = is_add;
10239 clib_memcpy(mp->locator_set_name, locator_set_name,
10240 vec_len(locator_set_name));
10241 vec_free(locator_set_name);
10246 /* Wait for a reply... */
10254 api_lisp_add_del_locator(vat_main_t * vam)
10256 unformat_input_t * input = vam->input;
10257 vl_api_lisp_add_del_locator_t *mp;
10259 u32 tmp_if_index = ~0;
10260 u32 sw_if_index = ~0;
10261 u8 sw_if_index_set = 0;
10262 u8 sw_if_index_if_name_set = 0;
10264 u8 priority_set = 0;
10268 u8 *locator_set_name = NULL;
10269 u8 locator_set_name_set = 0;
10271 /* Parse args required to build the message */
10272 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10273 if (unformat(input, "del")) {
10275 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10276 locator_set_name_set = 1;
10277 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
10279 sw_if_index_if_name_set = 1;
10280 sw_if_index = tmp_if_index;
10281 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
10282 sw_if_index_set = 1;
10283 sw_if_index = tmp_if_index;
10284 } else if (unformat(input, "p %d", &priority)) {
10286 } else if (unformat(input, "w %d", &weight)) {
10292 if (locator_set_name_set == 0) {
10293 errmsg ("missing locator-set name");
10297 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
10298 errmsg ("missing sw_if_index");
10299 vec_free(locator_set_name);
10303 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
10304 errmsg ("cannot use both params interface name and sw_if_index");
10305 vec_free(locator_set_name);
10309 if (priority_set == 0) {
10310 errmsg ("missing locator-set priority\n");
10311 vec_free(locator_set_name);
10315 if (weight_set == 0) {
10316 errmsg ("missing locator-set weight\n");
10317 vec_free(locator_set_name);
10321 if (vec_len(locator_set_name) > 64) {
10322 errmsg ("locator-set name too long\n");
10323 vec_free(locator_set_name);
10326 vec_add1(locator_set_name, 0);
10328 /* Construct the API message */
10329 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
10331 mp->is_add = is_add;
10332 mp->sw_if_index = ntohl(sw_if_index);
10333 mp->priority = priority;
10334 mp->weight = weight;
10335 clib_memcpy(mp->locator_set_name, locator_set_name,
10336 vec_len(locator_set_name));
10337 vec_free(locator_set_name);
10342 /* Wait for a reply... */
10350 api_lisp_add_del_local_eid(vat_main_t * vam)
10352 unformat_input_t * input = vam->input;
10353 vl_api_lisp_add_del_local_eid_t *mp;
10358 u8 eid_type = (u8)~0;
10359 ip4_address_t eidv4;
10360 ip6_address_t eidv6;
10362 u32 tmp_eid_lenght = ~0;
10363 u8 eid_lenght = ~0;
10364 u8 *locator_set_name = NULL;
10365 u8 locator_set_name_set = 0;
10368 /* Parse args required to build the message */
10369 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10370 if (unformat(input, "del")) {
10372 } else if (unformat(input, "vni &d", &vni)) {
10374 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10375 &eidv4, &tmp_eid_lenght)) {
10376 eid_lenght = tmp_eid_lenght;
10378 eid_type = 0; /* ipv4 type */
10379 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10380 &eidv6, &tmp_eid_lenght)) {
10381 eid_lenght = tmp_eid_lenght;
10383 eid_type = 1; /* ipv6 type */
10384 } else if (unformat(input, "eid %U", unformat_ethernet_address, mac)) {
10385 eid_type = 2; /* mac type */
10386 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10387 locator_set_name_set = 1;
10392 if (locator_set_name_set == 0) {
10393 errmsg ("missing locator-set name\n");
10397 if ((u8)~0 == eid_type) {
10398 errmsg ("EID address not set!");
10399 vec_free(locator_set_name);
10403 if (vec_len(locator_set_name) > 64) {
10404 errmsg ("locator-set name too long\n");
10405 vec_free(locator_set_name);
10408 vec_add1(locator_set_name, 0);
10410 if (eidv4_set && eidv6_set) {
10411 errmsg ("both eid v4 and v6 addresses set\n");
10412 vec_free(locator_set_name);
10416 if (eidv4_set && eid_lenght > 32) {
10417 errmsg ("eid prefix to big\n");
10418 vec_free(locator_set_name);
10422 if (eidv6_set && eid_lenght > 128) {
10423 errmsg ("eid prefix to big\n");
10424 vec_free(locator_set_name);
10428 /* Construct the API message */
10429 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
10431 mp->is_add = is_add;
10432 switch (eid_type) {
10434 clib_memcpy (mp->eid, &eidv4, sizeof(eidv4));
10437 clib_memcpy (mp->eid, &eidv6, sizeof(eidv6));
10440 clib_memcpy (mp->eid, mac, 6);
10443 mp->eid_type = eid_type;
10444 mp->prefix_len = eid_lenght;
10445 mp->vni = clib_host_to_net_u32(vni);
10446 clib_memcpy(mp->locator_set_name, locator_set_name,
10447 vec_len(locator_set_name));
10448 vec_free(locator_set_name);
10453 /* Wait for a reply... */
10461 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
10463 unformat_input_t * input = vam->input;
10464 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10467 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
10468 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
10469 ip4_address_t eidv4, slocv4, dlocv4;
10470 ip6_address_t eidv6, slocv6, dlocv6;
10471 u32 tmp_eid_lenght = ~0;
10472 u8 eid_lenght = ~0;
10474 /* Parse args required to build the message */
10475 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10476 if (unformat(input, "del")) {
10478 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10479 &eidv4, &tmp_eid_lenght)) {
10480 eid_lenght = tmp_eid_lenght;
10482 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10483 &eidv6, &tmp_eid_lenght)) {
10484 eid_lenght = tmp_eid_lenght;
10486 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10488 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10490 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10492 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10498 if (eidv4_set && eidv6_set) {
10499 errmsg ("both eid v4 and v6 addresses set\n");
10503 if (!eidv4_set && !eidv6_set) {
10504 errmsg ("eid addresses not set\n");
10508 if (slocv4_set && slocv6_set) {
10509 errmsg ("both source v4 and v6 addresses set\n");
10513 if (!slocv4_set && !slocv6_set) {
10514 errmsg ("source addresses not set\n");
10518 if (dlocv4_set && dlocv6_set) {
10519 errmsg ("both destination v4 and v6 addresses set\n");
10523 if (dlocv4_set && dlocv6_set) {
10524 errmsg ("destination addresses not set\n");
10528 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10529 errmsg ("mixing type of source and destination address\n");
10533 /* Construct the API message */
10534 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10536 mp->is_add = is_add;
10538 mp->eid_is_ipv6 = 1;
10539 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10541 mp->eid_is_ipv6 = 0;
10542 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10544 mp->eid_prefix_len = eid_lenght;
10546 mp->address_is_ipv6 = 1;
10547 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10548 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10550 mp->address_is_ipv6 = 0;
10551 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10552 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10558 /* Wait for a reply... */
10566 api_lisp_add_del_map_resolver(vat_main_t * vam)
10568 unformat_input_t * input = vam->input;
10569 vl_api_lisp_add_del_map_resolver_t *mp;
10574 ip4_address_t ipv4;
10575 ip6_address_t ipv6;
10577 /* Parse args required to build the message */
10578 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10579 if (unformat(input, "del")) {
10581 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10583 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10589 if (ipv4_set && ipv6_set) {
10590 errmsg ("both eid v4 and v6 addresses set\n");
10594 if (!ipv4_set && !ipv6_set) {
10595 errmsg ("eid addresses not set\n");
10599 /* Construct the API message */
10600 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10602 mp->is_add = is_add;
10605 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10608 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10614 /* Wait for a reply... */
10622 api_lisp_gpe_enable_disable (vat_main_t * vam)
10624 unformat_input_t * input = vam->input;
10625 vl_api_lisp_gpe_enable_disable_t *mp;
10630 /* Parse args required to build the message */
10631 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10632 if (unformat(input, "enable")) {
10635 } else if (unformat(input, "disable")) {
10643 errmsg("Value not set\n");
10647 /* Construct the API message */
10648 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10655 /* Wait for a reply... */
10663 api_lisp_enable_disable (vat_main_t * vam)
10665 unformat_input_t * input = vam->input;
10666 vl_api_lisp_enable_disable_t *mp;
10671 /* Parse args required to build the message */
10672 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10674 if (unformat (input, "enable"))
10679 else if (unformat (input, "disable"))
10689 errmsg ("Value not set\n");
10693 /* Construct the API message */
10694 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
10701 /* Wait for a reply... */
10708 /** Used for transferring locators via VPP API */
10709 typedef CLIB_PACKED(struct
10711 u8 is_ip4; /**< is locator an IPv4 address? */
10712 u8 priority; /**< locator priority */
10713 u8 weight; /**< locator weight */
10714 u8 addr[16]; /**< IPv4/IPv6 address */
10718 * Enable/disable LISP proxy ITR.
10720 * @param vam vpp API test context
10721 * @return return code
10724 api_lisp_pitr_set_locator_set (vat_main_t * vam)
10727 u8 ls_name_set = 0;
10728 unformat_input_t * input = vam->input;
10729 vl_api_lisp_pitr_set_locator_set_t * mp;
10733 /* Parse args required to build the message */
10734 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10736 if (unformat (input, "del"))
10738 else if (unformat (input, "locator-set %s", &ls_name))
10742 errmsg ("parse error '%U'", format_unformat_error, input);
10749 errmsg ("locator-set name not set!");
10753 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
10755 mp->is_add = is_add;
10756 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
10757 vec_free (ls_name);
10762 /* wait for reply */
10770 * Add/delete mapping between vni and vrf
10773 api_lisp_eid_table_add_del_map (vat_main_t * vam)
10776 unformat_input_t * input = vam->input;
10777 vl_api_lisp_eid_table_add_del_map_t *mp;
10778 u8 is_add = 1, vni_set = 0, vrf_set = 0;
10781 /* Parse args required to build the message */
10782 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10784 if (unformat (input, "del"))
10786 else if (unformat(input, "vrf %d", &vrf))
10788 else if (unformat(input, "vni %d", &vni))
10794 if (!vni_set || !vrf_set)
10796 errmsg ("missing arguments!");
10800 M(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
10802 mp->is_add = is_add;
10803 mp->vni = htonl (vni);
10804 mp->vrf = htonl (vrf);
10809 /* wait for reply */
10817 * Add/del remote mapping to/from LISP control plane
10819 * @param vam vpp API test context
10820 * @return return code
10823 api_lisp_add_del_remote_mapping (vat_main_t * vam)
10825 unformat_input_t * input = vam->input;
10826 vl_api_lisp_add_del_remote_mapping_t *mp;
10829 ip4_address_t seid4, deid4, rloc4;
10830 ip6_address_t seid6, deid6, rloc6;
10831 u8 deid_mac[6] = {0};
10832 u8 seid_mac[6] = {0};
10833 u8 deid_type, seid_type;
10834 u32 seid_len = 0, deid_len = 0, len;
10835 u8 is_add = 1, del_all = 0;
10836 u32 action = ~0, p, w;
10837 rloc_t * rlocs = 0, rloc, * curr_rloc = 0;
10839 seid_type = deid_type = (u8)~0;
10841 /* Parse args required to build the message */
10842 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10843 if (unformat(input, "del-all")) {
10845 } else if (unformat(input, "del")) {
10847 } else if (unformat(input, "add")) {
10849 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
10851 deid_type = 0; /* ipv4 */
10853 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
10855 deid_type = 1; /* ipv6 */
10857 } else if (unformat(input, "deid %U", unformat_ethernet_address,
10859 deid_type = 2; /* mac */
10860 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
10862 seid_type = 0; /* ipv4 */
10864 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
10866 seid_type = 1; /* ipv6 */
10868 } else if (unformat(input, "seid %U", unformat_ethernet_address,
10870 seid_type = 2; /* mac */
10871 } else if (unformat(input, "vni %d", &vni)) {
10873 } else if (unformat(input, "p %d w %d", &p, &w)) {
10875 errmsg ("No RLOC configured for setting priority/weight!");
10878 curr_rloc->priority = p;
10879 curr_rloc->weight = w;
10880 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
10882 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
10883 vec_add1 (rlocs, rloc);
10884 curr_rloc = &rlocs[vec_len (rlocs) - 1];
10885 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
10887 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
10888 vec_add1 (rlocs, rloc);
10889 curr_rloc = &rlocs[vec_len (rlocs) - 1];
10890 } else if (unformat(input, "action %d", &action)) {
10893 clib_warning ("parse error '%U'", format_unformat_error, input);
10898 if ((u8)~0 == deid_type) {
10899 errmsg ("missing params!");
10903 if (seid_type != deid_type) {
10904 errmsg ("source and destination EIDs are of different types!");
10908 if (is_add && (~0 == action)
10909 && 0 == vec_len (rlocs)) {
10910 errmsg ("no action set for negative map-reply!");
10914 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
10915 mp->is_add = is_add;
10916 mp->vni = htonl (vni);
10917 mp->seid_len = seid_len;
10918 mp->action = (u8) action;
10919 mp->deid_len = deid_len;
10920 mp->del_all = del_all;
10921 mp->eid_type = deid_type;
10923 switch (mp->eid_type) {
10925 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
10926 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
10929 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
10930 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
10933 clib_memcpy (mp->seid, seid_mac, 6);
10934 clib_memcpy (mp->deid, deid_mac, 6);
10937 errmsg ("unknown EID type %d!", mp->eid_type);
10941 mp->rloc_num = vec_len (rlocs);
10942 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
10948 /* Wait for a reply... */
10956 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
10957 * forwarding entries in data-plane accordingly.
10959 * @param vam vpp API test context
10960 * @return return code
10963 api_lisp_add_del_adjacency (vat_main_t * vam)
10965 unformat_input_t * input = vam->input;
10966 vl_api_lisp_add_del_adjacency_t *mp;
10969 ip4_address_t seid4, deid4;
10970 ip6_address_t seid6, deid6;
10971 u8 deid_mac[6] = {0};
10972 u8 seid_mac[6] = {0};
10973 u8 deid_type, seid_type;
10974 u32 seid_len = 0, deid_len = 0, len;
10977 seid_type = deid_type = (u8)~0;
10979 /* Parse args required to build the message */
10980 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10981 if (unformat(input, "del")) {
10983 } else if (unformat(input, "add")) {
10985 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
10987 deid_type = 0; /* ipv4 */
10989 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
10991 deid_type = 1; /* ipv6 */
10993 } else if (unformat(input, "deid %U", unformat_ethernet_address,
10995 deid_type = 2; /* mac */
10996 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
10998 seid_type = 0; /* ipv4 */
11000 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11002 seid_type = 1; /* ipv6 */
11004 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11006 seid_type = 2; /* mac */
11007 } else if (unformat(input, "vni %d", &vni)) {
11010 errmsg ("parse error '%U'", format_unformat_error, input);
11015 if ((u8)~0 == deid_type) {
11016 errmsg ("missing params!");
11020 if (seid_type != deid_type) {
11021 errmsg ("source and destination EIDs are of different types!");
11025 M(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
11026 mp->is_add = is_add;
11027 mp->vni = htonl (vni);
11028 mp->seid_len = seid_len;
11029 mp->deid_len = deid_len;
11030 mp->eid_type = deid_type;
11032 switch (mp->eid_type) {
11034 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
11035 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
11038 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
11039 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
11042 clib_memcpy (mp->seid, seid_mac, 6);
11043 clib_memcpy (mp->deid, deid_mac, 6);
11046 errmsg ("unknown EID type %d!", mp->eid_type);
11053 /* Wait for a reply... */
11061 api_lisp_gpe_add_del_iface(vat_main_t * vam)
11063 unformat_input_t * input = vam->input;
11064 vl_api_lisp_gpe_add_del_iface_t *mp;
11070 /* Parse args required to build the message */
11071 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11072 if (unformat(input, "up")) {
11075 } else if (unformat(input, "down")) {
11078 } else if (unformat(input, "table_id %d", &table_id)) {
11080 } else if (unformat(input, "vni %d", &vni)) {
11087 errmsg("Value not set\n");
11091 /* Construct the API message */
11092 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
11094 mp->is_add = is_add;
11095 mp->table_id = table_id;
11101 /* Wait for a reply... */
11109 * Add/del map request itr rlocs from LISP control plane and updates
11111 * @param vam vpp API test context
11112 * @return return code
11115 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
11117 unformat_input_t * input = vam->input;
11118 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
11120 u8 *locator_set_name = 0;
11121 u8 locator_set_name_set = 0;
11124 /* Parse args required to build the message */
11125 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11126 if (unformat(input, "del")) {
11128 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
11129 locator_set_name_set = 1;
11131 clib_warning ("parse error '%U'", format_unformat_error, input);
11136 if (is_add && !locator_set_name_set) {
11137 errmsg ("itr-rloc is not set!");
11141 if (is_add && vec_len(locator_set_name) > 64) {
11142 errmsg ("itr-rloc locator-set name too long\n");
11143 vec_free(locator_set_name);
11147 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
11148 mp->is_add = is_add;
11150 clib_memcpy (mp->locator_set_name , locator_set_name,
11151 vec_len(locator_set_name));
11153 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
11155 vec_free (locator_set_name);
11160 /* Wait for a reply... */
11168 api_lisp_locator_set_dump(vat_main_t *vam)
11170 vl_api_lisp_locator_set_dump_t *mp;
11173 if (!vam->json_output) {
11174 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
11175 "Locator-set", "Locator", "Priority", "Weight");
11178 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11182 /* Use a control ping for synchronization */
11184 vl_api_control_ping_t * mp;
11185 M(CONTROL_PING, control_ping);
11188 /* Wait for a reply... */
11196 api_lisp_local_eid_table_dump(vat_main_t *vam)
11198 unformat_input_t * i = vam->input;
11199 vl_api_lisp_local_eid_table_dump_t *mp;
11201 struct in_addr ip4;
11202 struct in6_addr ip6;
11204 u8 eid_type = ~0, eid_set;
11205 u32 prefix_length = ~0, t, vni = 0;
11207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11208 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t)) {
11212 } else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t)) {
11216 } else if (unformat (i, "eid %U", unformat_ethernet_address, mac)) {
11219 } else if (unformat (i, "vni %d", &t))
11222 errmsg ("parse error '%U'", format_unformat_error, i);
11227 if (!vam->json_output) {
11228 fformat(vam->ofp, "%=20s%=30s\n",
11229 "Locator-set", "Eid");
11232 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
11236 mp->vni = htonl (vni);
11237 mp->eid_type = eid_type;
11238 switch (eid_type) {
11240 mp->prefix_length = prefix_length;
11241 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
11244 mp->prefix_length = prefix_length;
11245 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
11248 clib_memcpy (mp->eid, mac, sizeof (mac));
11251 errmsg ("unknown EID type %d!", eid_type);
11259 /* Use a control ping for synchronization */
11261 vl_api_control_ping_t * mp;
11262 M(CONTROL_PING, control_ping);
11265 /* Wait for a reply... */
11273 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
11275 vl_api_lisp_gpe_tunnel_dump_t *mp;
11278 if (!vam->json_output) {
11279 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
11280 "%=16s%=16s%=16s%=16s%=16s\n",
11281 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
11282 "Decap next", "Lisp version", "Flags", "Next protocol",
11283 "ver_res", "res", "iid");
11286 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
11290 /* Use a control ping for synchronization */
11292 vl_api_control_ping_t * mp;
11293 M(CONTROL_PING, control_ping);
11296 /* Wait for a reply... */
11304 api_lisp_map_resolver_dump(vat_main_t *vam)
11306 vl_api_lisp_map_resolver_dump_t *mp;
11309 if (!vam->json_output) {
11310 fformat(vam->ofp, "%=20s\n",
11314 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
11318 /* Use a control ping for synchronization */
11320 vl_api_control_ping_t * mp;
11321 M(CONTROL_PING, control_ping);
11324 /* Wait for a reply... */
11332 api_lisp_enable_disable_status_dump(vat_main_t *vam)
11334 vl_api_lisp_enable_disable_status_dump_t *mp;
11337 if (!vam->json_output) {
11338 fformat(vam->ofp, "%=20s\n",
11342 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
11343 lisp_enable_disable_status_dump);
11347 /* Use a control ping for synchronization */
11349 vl_api_control_ping_t * mp;
11350 M(CONTROL_PING, control_ping);
11353 /* Wait for a reply... */
11361 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
11363 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
11366 if (!vam->json_output) {
11367 fformat(vam->ofp, "%=20s\n",
11371 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
11374 /* Wait for a reply... */
11382 api_af_packet_create (vat_main_t * vam)
11384 unformat_input_t * i = vam->input;
11385 vl_api_af_packet_create_t * mp;
11387 u8 * host_if_name = 0;
11389 u8 random_hw_addr = 1;
11391 memset (hw_addr, 0, sizeof (hw_addr));
11393 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11394 if (unformat (i, "name %s", &host_if_name))
11395 vec_add1 (host_if_name, 0);
11396 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11397 random_hw_addr = 0;
11402 if (!vec_len (host_if_name)) {
11403 errmsg ("host-interface name must be specified");
11407 if (vec_len (host_if_name) > 64) {
11408 errmsg ("host-interface name too long");
11412 M(AF_PACKET_CREATE, af_packet_create);
11414 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11415 clib_memcpy (mp->hw_addr, hw_addr, 6);
11416 mp->use_random_hw_addr = random_hw_addr;
11417 vec_free (host_if_name);
11419 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
11425 api_af_packet_delete (vat_main_t * vam)
11427 unformat_input_t * i = vam->input;
11428 vl_api_af_packet_delete_t * mp;
11430 u8 * host_if_name = 0;
11432 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11433 if (unformat (i, "name %s", &host_if_name))
11434 vec_add1 (host_if_name, 0);
11439 if (!vec_len (host_if_name)) {
11440 errmsg ("host-interface name must be specified");
11444 if (vec_len (host_if_name) > 64) {
11445 errmsg ("host-interface name too long");
11449 M(AF_PACKET_DELETE, af_packet_delete);
11451 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
11452 vec_free (host_if_name);
11460 api_policer_add_del (vat_main_t * vam)
11462 unformat_input_t * i = vam->input;
11463 vl_api_policer_add_del_t * mp;
11474 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
11476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11477 if (unformat (i, "del"))
11479 else if (unformat (i, "name %s", &name))
11480 vec_add1 (name, 0);
11481 else if (unformat (i, "cir %u", &cir))
11483 else if (unformat (i, "eir %u", &eir))
11485 else if (unformat (i, "cb %u", &cb))
11487 else if (unformat (i, "eb %u", &eb))
11489 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11492 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11495 else if (unformat (i, "type %U", unformat_policer_type, &type))
11497 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
11500 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
11503 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
11510 if (!vec_len (name)) {
11511 errmsg ("policer name must be specified");
11515 if (vec_len (name) > 64) {
11516 errmsg ("policer name too long");
11520 M(POLICER_ADD_DEL, policer_add_del);
11522 clib_memcpy (mp->name, name, vec_len (name));
11524 mp->is_add = is_add;
11529 mp->rate_type = rate_type;
11530 mp->round_type = round_type;
11532 mp->conform_action_type = conform_action.action_type;
11533 mp->conform_dscp = conform_action.dscp;
11534 mp->exceed_action_type = exceed_action.action_type;
11535 mp->exceed_dscp = exceed_action.dscp;
11536 mp->violate_action_type = violate_action.action_type;
11537 mp->violate_dscp = violate_action.dscp;
11545 api_policer_dump(vat_main_t *vam)
11547 unformat_input_t * i = vam->input;
11548 vl_api_policer_dump_t *mp;
11550 u8 *match_name = 0;
11551 u8 match_name_valid = 0;
11553 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11554 if (unformat (i, "name %s", &match_name)) {
11555 vec_add1 (match_name, 0);
11556 match_name_valid = 1;
11561 M(POLICER_DUMP, policer_dump);
11562 mp->match_name_valid = match_name_valid;
11563 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11564 vec_free (match_name);
11568 /* Use a control ping for synchronization */
11570 vl_api_control_ping_t * mp;
11571 M(CONTROL_PING, control_ping);
11574 /* Wait for a reply... */
11582 api_netmap_create (vat_main_t * vam)
11584 unformat_input_t * i = vam->input;
11585 vl_api_netmap_create_t * mp;
11589 u8 random_hw_addr = 1;
11593 memset (hw_addr, 0, sizeof (hw_addr));
11595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11596 if (unformat (i, "name %s", &if_name))
11597 vec_add1 (if_name, 0);
11598 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11599 random_hw_addr = 0;
11600 else if (unformat (i, "pipe"))
11602 else if (unformat (i, "master"))
11604 else if (unformat (i, "slave"))
11610 if (!vec_len (if_name)) {
11611 errmsg ("interface name must be specified");
11615 if (vec_len (if_name) > 64) {
11616 errmsg ("interface name too long");
11620 M(NETMAP_CREATE, netmap_create);
11622 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
11623 clib_memcpy (mp->hw_addr, hw_addr, 6);
11624 mp->use_random_hw_addr = random_hw_addr;
11625 mp->is_pipe = is_pipe;
11626 mp->is_master = is_master;
11627 vec_free (if_name);
11635 api_netmap_delete (vat_main_t * vam)
11637 unformat_input_t * i = vam->input;
11638 vl_api_netmap_delete_t * mp;
11642 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11643 if (unformat (i, "name %s", &if_name))
11644 vec_add1 (if_name, 0);
11649 if (!vec_len (if_name)) {
11650 errmsg ("interface name must be specified");
11654 if (vec_len (if_name) > 64) {
11655 errmsg ("interface name too long");
11659 M(NETMAP_DELETE, netmap_delete);
11661 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
11662 vec_free (if_name);
11669 static void vl_api_mpls_gre_tunnel_details_t_handler
11670 (vl_api_mpls_gre_tunnel_details_t * mp)
11672 vat_main_t * vam = &vat_main;
11674 i32 len = ntohl(mp->nlabels);
11676 if (mp->l2_only == 0) {
11677 fformat(vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
11678 ntohl(mp->tunnel_index),
11679 format_ip4_address, &mp->tunnel_src,
11680 format_ip4_address, &mp->tunnel_dst,
11681 format_ip4_address, &mp->intfc_address,
11682 ntohl(mp->mask_width));
11683 for (i = 0; i < len; i++) {
11684 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11686 fformat(vam->ofp, "\n");
11687 fformat(vam->ofp, " inner fib index %d, outer fib index %d\n",
11688 ntohl(mp->inner_fib_index), ntohl(mp->outer_fib_index));
11690 fformat(vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
11691 ntohl(mp->tunnel_index),
11692 format_ip4_address, &mp->tunnel_src,
11693 format_ip4_address, &mp->tunnel_dst,
11694 format_ip4_address, &mp->intfc_address);
11695 for (i = 0; i < len; i++) {
11696 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11698 fformat(vam->ofp, "\n");
11699 fformat(vam->ofp, " l2 interface %d, outer fib index %d\n",
11700 ntohl(mp->hw_if_index), ntohl(mp->outer_fib_index));
11704 static void vl_api_mpls_gre_tunnel_details_t_handler_json
11705 (vl_api_mpls_gre_tunnel_details_t * mp)
11707 vat_main_t * vam = &vat_main;
11708 vat_json_node_t *node = NULL;
11709 struct in_addr ip4;
11711 i32 len = ntohl(mp->nlabels);
11713 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11714 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11715 vat_json_init_array(&vam->json_tree);
11717 node = vat_json_array_add(&vam->json_tree);
11719 vat_json_init_object(node);
11720 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
11721 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
11722 vat_json_object_add_ip4(node, "intfc_address", ip4);
11723 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
11724 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
11725 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
11726 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
11727 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
11728 clib_memcpy(&ip4, &(mp->tunnel_src), sizeof(ip4));
11729 vat_json_object_add_ip4(node, "tunnel_src", ip4);
11730 clib_memcpy(&ip4, &(mp->tunnel_dst), sizeof(ip4));
11731 vat_json_object_add_ip4(node, "tunnel_dst", ip4);
11732 vat_json_object_add_uint(node, "outer_fib_index", ntohl(mp->outer_fib_index));
11733 vat_json_object_add_uint(node, "label_count", len);
11734 for (i = 0; i < len; i++) {
11735 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11739 static int api_mpls_gre_tunnel_dump (vat_main_t * vam)
11741 vl_api_mpls_gre_tunnel_dump_t *mp;
11745 /* Parse args required to build the message */
11746 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
11747 if (!unformat (vam->input, "tunnel_index %d", &index)) {
11753 fformat(vam->ofp, " tunnel_index %d\n", index);
11755 M(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
11756 mp->tunnel_index = htonl(index);
11759 /* Use a control ping for synchronization */
11761 vl_api_control_ping_t * mp;
11762 M(CONTROL_PING, control_ping);
11768 static void vl_api_mpls_eth_tunnel_details_t_handler
11769 (vl_api_mpls_eth_tunnel_details_t * mp)
11771 vat_main_t * vam = &vat_main;
11773 i32 len = ntohl(mp->nlabels);
11775 fformat(vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
11776 ntohl(mp->tunnel_index),
11777 format_ethernet_address, &mp->tunnel_dst_mac,
11778 format_ip4_address, &mp->intfc_address,
11779 ntohl(mp->mask_width));
11780 for (i = 0; i < len; i++) {
11781 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11783 fformat(vam->ofp, "\n");
11784 fformat(vam->ofp, " tx on %d, rx fib index %d\n",
11785 ntohl(mp->tx_sw_if_index),
11786 ntohl(mp->inner_fib_index));
11789 static void vl_api_mpls_eth_tunnel_details_t_handler_json
11790 (vl_api_mpls_eth_tunnel_details_t * mp)
11792 vat_main_t * vam = &vat_main;
11793 vat_json_node_t *node = NULL;
11794 struct in_addr ip4;
11796 i32 len = ntohl(mp->nlabels);
11798 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11799 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11800 vat_json_init_array(&vam->json_tree);
11802 node = vat_json_array_add(&vam->json_tree);
11804 vat_json_init_object(node);
11805 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
11806 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
11807 vat_json_object_add_ip4(node, "intfc_address", ip4);
11808 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
11809 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
11810 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
11811 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
11812 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
11813 vat_json_object_add_string_copy(node, "tunnel_dst_mac",
11814 format(0, "%U", format_ethernet_address, &mp->tunnel_dst_mac));
11815 vat_json_object_add_uint(node, "tx_sw_if_index", ntohl(mp->tx_sw_if_index));
11816 vat_json_object_add_uint(node, "label_count", len);
11817 for (i = 0; i < len; i++) {
11818 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11822 static int api_mpls_eth_tunnel_dump (vat_main_t * vam)
11824 vl_api_mpls_eth_tunnel_dump_t *mp;
11828 /* Parse args required to build the message */
11829 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
11830 if (!unformat (vam->input, "tunnel_index %d", &index)) {
11836 fformat(vam->ofp, " tunnel_index %d\n", index);
11838 M(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
11839 mp->tunnel_index = htonl(index);
11842 /* Use a control ping for synchronization */
11844 vl_api_control_ping_t * mp;
11845 M(CONTROL_PING, control_ping);
11851 static void vl_api_mpls_fib_encap_details_t_handler
11852 (vl_api_mpls_fib_encap_details_t * mp)
11854 vat_main_t * vam = &vat_main;
11856 i32 len = ntohl(mp->nlabels);
11858 fformat(vam->ofp, "table %d, dest %U, label ",
11859 ntohl(mp->fib_index),
11860 format_ip4_address, &mp->dest,
11862 for (i = 0; i < len; i++) {
11863 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11865 fformat(vam->ofp, "\n");
11868 static void vl_api_mpls_fib_encap_details_t_handler_json
11869 (vl_api_mpls_fib_encap_details_t * mp)
11871 vat_main_t * vam = &vat_main;
11872 vat_json_node_t *node = NULL;
11874 i32 len = ntohl(mp->nlabels);
11875 struct in_addr ip4;
11877 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11878 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11879 vat_json_init_array(&vam->json_tree);
11881 node = vat_json_array_add(&vam->json_tree);
11883 vat_json_init_object(node);
11884 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
11885 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
11886 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
11887 vat_json_object_add_ip4(node, "dest", ip4);
11888 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
11889 vat_json_object_add_uint(node, "label_count", len);
11890 for (i = 0; i < len; i++) {
11891 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11895 static int api_mpls_fib_encap_dump (vat_main_t * vam)
11897 vl_api_mpls_fib_encap_dump_t *mp;
11900 M(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
11903 /* Use a control ping for synchronization */
11905 vl_api_control_ping_t * mp;
11906 M(CONTROL_PING, control_ping);
11912 static void vl_api_mpls_fib_decap_details_t_handler
11913 (vl_api_mpls_fib_decap_details_t * mp)
11915 vat_main_t * vam = &vat_main;
11917 fformat(vam->ofp, "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
11918 ntohl(mp->rx_table_id),
11919 ntohl(mp->tx_table_id),
11925 static void vl_api_mpls_fib_decap_details_t_handler_json
11926 (vl_api_mpls_fib_decap_details_t * mp)
11928 vat_main_t * vam = &vat_main;
11929 vat_json_node_t *node = NULL;
11930 struct in_addr ip4;
11932 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11933 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11934 vat_json_init_array(&vam->json_tree);
11936 node = vat_json_array_add(&vam->json_tree);
11938 vat_json_init_object(node);
11939 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
11940 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
11941 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
11942 vat_json_object_add_ip4(node, "dest", ip4);
11943 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
11944 vat_json_object_add_uint(node, "label", ntohl(mp->label));
11945 vat_json_object_add_uint(node, "rx_table_id", ntohl(mp->rx_table_id));
11946 vat_json_object_add_uint(node, "tx_table_id", ntohl(mp->tx_table_id));
11947 vat_json_object_add_string_copy(node, "swif_tag", mp->swif_tag);
11950 static int api_mpls_fib_decap_dump (vat_main_t * vam)
11952 vl_api_mpls_fib_decap_dump_t *mp;
11955 M(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
11958 /* Use a control ping for synchronization */
11960 vl_api_control_ping_t * mp;
11961 M(CONTROL_PING, control_ping);
11967 int api_classify_table_ids (vat_main_t *vam)
11969 vl_api_classify_table_ids_t *mp;
11972 /* Construct the API message */
11973 M(CLASSIFY_TABLE_IDS, classify_table_ids);
11981 int api_classify_table_by_interface (vat_main_t *vam)
11983 unformat_input_t * input = vam->input;
11984 vl_api_classify_table_by_interface_t *mp;
11987 u32 sw_if_index = ~0;
11988 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11989 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
11991 else if (unformat (input, "sw_if_index %d", &sw_if_index))
11996 if (sw_if_index == ~0) {
11997 errmsg ("missing interface name or sw_if_index\n");
12001 /* Construct the API message */
12002 M(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
12004 mp->sw_if_index = ntohl(sw_if_index);
12011 int api_classify_table_info (vat_main_t *vam)
12013 unformat_input_t * input = vam->input;
12014 vl_api_classify_table_info_t *mp;
12018 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12019 if (unformat (input, "table_id %d", &table_id))
12024 if (table_id == ~0) {
12025 errmsg ("missing table id\n");
12029 /* Construct the API message */
12030 M(CLASSIFY_TABLE_INFO, classify_table_info);
12032 mp->table_id = ntohl(table_id);
12039 int api_classify_session_dump (vat_main_t *vam)
12041 unformat_input_t * input = vam->input;
12042 vl_api_classify_session_dump_t *mp;
12046 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12047 if (unformat (input, "table_id %d", &table_id))
12052 if (table_id == ~0) {
12053 errmsg ("missing table id\n");
12057 /* Construct the API message */
12058 M(CLASSIFY_SESSION_DUMP, classify_session_dump);
12060 mp->table_id = ntohl(table_id);
12063 /* Use a control ping for synchronization */
12065 vl_api_control_ping_t * mp;
12066 M(CONTROL_PING, control_ping);
12074 static void vl_api_ipfix_details_t_handler (vl_api_ipfix_details_t * mp)
12076 vat_main_t * vam = &vat_main;
12078 fformat(vam->ofp, "collector_address %U, collector_port %d, "
12079 "src_address %U, fib_index %u, path_mtu %u, "
12080 "template_interval %u\n",
12081 format_ip4_address, mp->collector_address,
12082 ntohs(mp->collector_port),
12083 format_ip4_address, mp->src_address,
12084 ntohl(mp->fib_index),
12085 ntohl(mp->path_mtu),
12086 ntohl(mp->template_interval));
12089 vam->result_ready = 1;
12092 static void vl_api_ipfix_details_t_handler_json
12093 (vl_api_ipfix_details_t * mp)
12095 vat_main_t * vam = &vat_main;
12096 vat_json_node_t node;
12097 struct in_addr collector_address;
12098 struct in_addr src_address;
12100 vat_json_init_object(&node);
12101 clib_memcpy(&collector_address, &mp->collector_address,
12102 sizeof(collector_address));
12103 vat_json_object_add_ip4(&node, "collector_address", collector_address);
12104 vat_json_object_add_uint(&node, "collector_port",
12105 ntohs(mp->collector_port));
12106 clib_memcpy(&src_address, &mp->src_address, sizeof(src_address));
12107 vat_json_object_add_ip4(&node, "src_address", src_address);
12108 vat_json_object_add_uint(&node, "fib_index", ntohl(mp->fib_index));
12109 vat_json_object_add_uint(&node, "path_mtu", ntohl(mp->path_mtu));
12110 vat_json_object_add_uint(&node, "template_interval",
12111 ntohl(mp->template_interval));
12113 vat_json_print(vam->ofp, &node);
12114 vat_json_free(&node);
12116 vam->result_ready = 1;
12119 int api_ipfix_dump (vat_main_t *vam)
12121 vl_api_ipfix_dump_t *mp;
12124 /* Construct the API message */
12125 M(IPFIX_DUMP, ipfix_dump);
12133 static int q_or_quit (vat_main_t * vam)
12135 longjmp (vam->jump_buf, 1);
12136 return 0; /* not so much */
12138 static int q (vat_main_t * vam) {return q_or_quit (vam);}
12139 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
12141 static int comment (vat_main_t * vam)
12146 static int cmd_cmp (void * a1, void * a2)
12151 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
12154 static int help (vat_main_t * vam)
12159 unformat_input_t * i = vam->input;
12162 if (unformat (i, "%s", &name)) {
12167 hs = hash_get_mem (vam->help_by_name, name);
12169 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
12171 fformat (vam->ofp, "No such msg / command '%s'\n", name);
12176 fformat(vam->ofp, "Help is available for the following:\n");
12178 hash_foreach_pair (p, vam->function_by_name,
12180 vec_add1 (cmds, (u8 *)(p->key));
12183 vec_sort_with_function (cmds, cmd_cmp);
12185 for (j = 0; j < vec_len(cmds); j++)
12186 fformat (vam->ofp, "%s\n", cmds[j]);
12192 static int set (vat_main_t * vam)
12194 u8 * name = 0, * value = 0;
12195 unformat_input_t * i = vam->input;
12197 if (unformat (i, "%s", &name)) {
12198 /* The input buffer is a vector, not a string. */
12199 value = vec_dup (i->buffer);
12200 vec_delete (value, i->index, 0);
12201 /* Almost certainly has a trailing newline */
12202 if (value[vec_len(value)-1] == '\n')
12203 value[vec_len(value)-1] = 0;
12204 /* Make sure it's a proper string, one way or the other */
12205 vec_add1 (value, 0);
12206 (void) clib_macro_set_value (&vam->macro_main,
12207 (char *)name, (char *)value);
12210 errmsg ("usage: set <name> <value>\n");
12217 static int unset (vat_main_t * vam)
12221 if (unformat (vam->input, "%s", &name))
12222 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
12223 errmsg ("unset: %s wasn't set\n", name);
12234 static int macro_sort_cmp (void * a1, void * a2)
12236 macro_sort_t * s1 = a1;
12237 macro_sort_t * s2 = a2;
12239 return strcmp ((char *)(s1->name), (char *)(s2->name));
12242 static int dump_macro_table (vat_main_t * vam)
12244 macro_sort_t * sort_me = 0, * sm;
12248 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
12250 vec_add2 (sort_me, sm, 1);
12251 sm->name = (u8 *)(p->key);
12252 sm->value = (u8 *) (p->value[0]);
12255 vec_sort_with_function (sort_me, macro_sort_cmp);
12257 if (vec_len(sort_me))
12258 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
12260 fformat (vam->ofp, "The macro table is empty...\n");
12262 for (i = 0; i < vec_len (sort_me); i++)
12263 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
12268 static int dump_node_table (vat_main_t * vam)
12271 vlib_node_t * node, * next_node;
12273 if (vec_len (vam->graph_nodes) == 0) {
12274 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
12278 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
12279 node = vam->graph_nodes[i];
12280 fformat (vam->ofp, "[%d] %s\n", i, node->name);
12281 for (j = 0; j < vec_len (node->next_nodes); j++) {
12282 if (node->next_nodes[j] != ~0) {
12283 next_node = vam->graph_nodes[node->next_nodes[j]];
12284 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
12291 static int search_node_table (vat_main_t * vam)
12293 unformat_input_t * line_input = vam->input;
12296 vlib_node_t * node, * next_node;
12299 if (vam->graph_node_index_by_name == 0) {
12300 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
12304 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
12305 if (unformat (line_input, "%s", &node_to_find)) {
12306 vec_add1 (node_to_find, 0);
12307 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
12309 fformat (vam->ofp, "%s not found...\n", node_to_find);
12312 node = vam->graph_nodes[p[0]];
12313 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
12314 for (j = 0; j < vec_len (node->next_nodes); j++) {
12315 if (node->next_nodes[j] != ~0) {
12316 next_node = vam->graph_nodes[node->next_nodes[j]];
12317 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
12323 clib_warning ("parse error '%U'", format_unformat_error,
12329 vec_free(node_to_find);
12337 static int script (vat_main_t * vam)
12340 char * save_current_file;
12341 unformat_input_t save_input;
12342 jmp_buf save_jump_buf;
12343 u32 save_line_number;
12345 FILE * new_fp, * save_ifp;
12347 if (unformat (vam->input, "%s", &s)) {
12348 new_fp = fopen ((char *)s, "r");
12350 errmsg ("Couldn't open script file %s\n", s);
12355 errmsg ("Missing script name\n");
12359 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
12360 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
12361 save_ifp = vam->ifp;
12362 save_line_number = vam->input_line_number;
12363 save_current_file = (char *) vam->current_file;
12365 vam->input_line_number = 0;
12367 vam->current_file = s;
12370 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
12371 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
12372 vam->ifp = save_ifp;
12373 vam->input_line_number = save_line_number;
12374 vam->current_file = (u8 *) save_current_file;
12380 static int echo (vat_main_t * vam)
12382 fformat (vam->ofp, "%v", vam->input->buffer);
12386 /* List of API message constructors, CLI names map to api_xxx */
12387 #define foreach_vpe_api_msg \
12388 _(create_loopback,"[mac <mac-addr>]") \
12389 _(sw_interface_dump,"") \
12390 _(sw_interface_set_flags, \
12391 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
12392 _(sw_interface_add_del_address, \
12393 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
12394 _(sw_interface_set_table, \
12395 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
12396 _(sw_interface_set_vpath, \
12397 "<intfc> | sw_if_index <id> enable | disable") \
12398 _(sw_interface_set_l2_xconnect, \
12399 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12400 "enable | disable") \
12401 _(sw_interface_set_l2_bridge, \
12402 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
12403 "[shg <split-horizon-group>] [bvi]\n" \
12404 "enable | disable") \
12405 _(bridge_domain_add_del, \
12406 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
12407 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
12409 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
12411 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
12413 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
12415 "tapname <name> mac <mac-addr> | random-mac") \
12417 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
12419 "<vpp-if-name> | sw_if_index <id>") \
12420 _(sw_interface_tap_dump, "") \
12421 _(ip_add_del_route, \
12422 "<addr>/<mask> via <addr> [vrf <n>]\n" \
12423 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
12424 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
12425 "[multipath] [count <n>]") \
12426 _(proxy_arp_add_del, \
12427 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
12428 _(proxy_arp_intfc_enable_disable, \
12429 "<intfc> | sw_if_index <id> enable | disable") \
12430 _(mpls_add_del_encap, \
12431 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
12432 _(mpls_add_del_decap, \
12433 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
12434 _(mpls_gre_add_del_tunnel, \
12435 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
12436 "adj <ip4-address>/<mask-width> [del]") \
12437 _(sw_interface_set_unnumbered, \
12438 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
12439 _(ip_neighbor_add_del, \
12440 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
12441 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
12442 _(reset_vrf, "vrf <id> [ipv6]") \
12443 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
12444 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
12445 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
12446 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
12447 "[outer_vlan_id_any][inner_vlan_id_any]") \
12448 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
12449 _(reset_fib, "vrf <n> [ipv6]") \
12450 _(dhcp_proxy_config, \
12451 "svr <v46-address> src <v46-address>\n" \
12452 "insert-cid <n> [del]") \
12453 _(dhcp_proxy_config_2, \
12454 "svr <v46-address> src <v46-address>\n" \
12455 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
12456 _(dhcp_proxy_set_vss, \
12457 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
12458 _(dhcp_client_config, \
12459 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
12460 _(set_ip_flow_hash, \
12461 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
12462 _(sw_interface_ip6_enable_disable, \
12463 "<intfc> | sw_if_index <id> enable | disable") \
12464 _(sw_interface_ip6_set_link_local_address, \
12465 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
12466 _(sw_interface_ip6nd_ra_prefix, \
12467 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
12468 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
12469 "[nolink] [isno]") \
12470 _(sw_interface_ip6nd_ra_config, \
12471 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
12472 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
12473 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
12474 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
12475 _(l2_patch_add_del, \
12476 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
12477 "enable | disable") \
12478 _(mpls_ethernet_add_del_tunnel, \
12479 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
12480 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
12481 _(mpls_ethernet_add_del_tunnel_2, \
12482 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
12483 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
12484 _(sr_tunnel_add_del, \
12485 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
12486 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
12487 "[policy <policy_name>]") \
12488 _(sr_policy_add_del, \
12489 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
12490 _(sr_multicast_map_add_del, \
12491 "address [ip6 multicast address] sr-policy [policy name] [del]") \
12492 _(classify_add_del_table, \
12493 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
12494 "[del] mask <mask-value>\n" \
12495 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
12496 _(classify_add_del_session, \
12497 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
12498 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
12499 _(classify_set_interface_ip_table, \
12500 "<intfc> | sw_if_index <nn> table <nn>") \
12501 _(classify_set_interface_l2_tables, \
12502 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
12503 " [other-table <nn>]") \
12504 _(get_node_index, "node <node-name") \
12505 _(add_node_next, "node <node-name> next <next-node-name>") \
12506 _(l2tpv3_create_tunnel, \
12507 "client_address <ip6-addr> our_address <ip6-addr>\n" \
12508 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
12509 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
12510 _(l2tpv3_set_tunnel_cookies, \
12511 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
12512 "[new_remote_cookie <nn>]\n") \
12513 _(l2tpv3_interface_enable_disable, \
12514 "<intfc> | sw_if_index <nn> enable | disable") \
12515 _(l2tpv3_set_lookup_key, \
12516 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
12517 _(sw_if_l2tpv3_tunnel_dump, "") \
12518 _(vxlan_add_del_tunnel, \
12519 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
12520 " [decap-next l2|ip4|ip6] [del]") \
12521 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
12522 _(gre_add_del_tunnel, \
12523 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
12524 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
12525 _(l2_fib_clear_table, "") \
12526 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
12527 _(l2_interface_vlan_tag_rewrite, \
12528 "<intfc> | sw_if_index <nn> \n" \
12529 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
12530 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
12531 _(create_vhost_user_if, \
12532 "socket <filename> [server] [renumber <dev_instance>] " \
12533 "[mac <mac_address>]") \
12534 _(modify_vhost_user_if, \
12535 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12536 "[server] [renumber <dev_instance>]") \
12537 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
12538 _(sw_interface_vhost_user_dump, "") \
12539 _(show_version, "") \
12540 _(vxlan_gpe_add_del_tunnel, \
12541 "local <addr> remote <addr> vni <nn>\n" \
12542 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
12543 "[next-ethernet] [next-nsh]\n") \
12544 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
12545 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
12546 _(interface_name_renumber, \
12547 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
12548 _(input_acl_set_interface, \
12549 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
12550 " [l2-table <nn>] [del]") \
12551 _(want_ip4_arp_events, "address <ip4-address> [del]") \
12552 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
12553 _(ip_dump, "ipv4 | ipv6") \
12554 _(ipsec_spd_add_del, "spd_id <n> [del]") \
12555 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
12557 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
12558 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
12559 " integ_alg <alg> integ_key <hex>") \
12560 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
12561 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
12562 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
12563 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
12564 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
12565 _(ikev2_profile_add_del, "name <profile_name> [del]") \
12566 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
12567 "(auth_data 0x<data> | auth_data <data>)") \
12568 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
12569 "(id_data 0x<data> | id_data <data>) (local|remote)") \
12570 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
12571 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
12572 "(local|remote)") \
12573 _(ikev2_set_local_key, "file <absolute_file_path>") \
12574 _(delete_loopback,"sw_if_index <nn>") \
12575 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
12576 _(map_add_domain, \
12577 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
12578 "ip6-src <ip6addr> " \
12579 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
12580 _(map_del_domain, "index <n>") \
12581 _(map_add_del_rule, \
12582 "index <n> psid <n> dst <ip6addr> [del]") \
12583 _(map_domain_dump, "") \
12584 _(map_rule_dump, "index <map-domain>") \
12585 _(want_interface_events, "enable|disable") \
12586 _(want_stats,"enable|disable") \
12587 _(get_first_msg_id, "client <name>") \
12588 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
12589 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
12590 "fib-id <nn> [ip4][ip6][default]") \
12591 _(get_node_graph, " ") \
12592 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
12593 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
12594 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
12595 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
12596 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
12597 " vrf_id <nn> add | pop | none") \
12598 _(trace_profile_del, "") \
12599 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
12600 _(lisp_add_del_locator, "locator-set <locator_name> " \
12601 "iface <intf> | sw_if_index <sw_if_index> " \
12602 "p <priority> w <weight> [del]") \
12603 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
12604 "locator-set <locator_name> [del]") \
12605 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
12606 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
12607 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
12608 _(lisp_gpe_enable_disable, "enable|disable") \
12609 _(lisp_enable_disable, "enable|disable") \
12610 _(lisp_gpe_add_del_iface, "up|down") \
12611 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> seid" \
12612 " <src-eid> rloc <locator> p <prio> " \
12613 "w <weight> [rloc <loc> ... ] " \
12614 "action <action>") \
12615 _(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid " \
12616 "<src-eid> rloc <locator> p <prio> w <weight>"\
12617 "[rloc <loc> ... ] action <action>") \
12618 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
12619 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
12620 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
12621 _(lisp_locator_set_dump, "") \
12622 _(lisp_local_eid_table_dump, "") \
12623 _(lisp_gpe_tunnel_dump, "") \
12624 _(lisp_map_resolver_dump, "") \
12625 _(lisp_enable_disable_status_dump, "") \
12626 _(lisp_get_map_request_itr_rlocs, "") \
12627 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
12628 _(af_packet_delete, "name <host interface name>") \
12629 _(policer_add_del, "name <policer name> <params> [del]") \
12630 _(policer_dump, "[name <policer name>]") \
12631 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
12632 "[master|slave]") \
12633 _(netmap_delete, "name <interface name>") \
12634 _(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
12635 _(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
12636 _(mpls_fib_encap_dump, "") \
12637 _(mpls_fib_decap_dump, "") \
12638 _(classify_table_ids, "") \
12639 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
12640 _(classify_table_info, "table_id <nn>") \
12641 _(classify_session_dump, "table_id <nn>") \
12642 _(ipfix_enable, "collector_address <ip4> [collector_port <nn>] " \
12643 "src_address <ip4> [fib_id <nn>] [path_mtu <nn>] " \
12644 "[template_interval <nn>]") \
12647 /* List of command functions, CLI names map directly to functions */
12648 #define foreach_cli_function \
12649 _(comment, "usage: comment <ignore-rest-of-line>") \
12650 _(dump_interface_table, "usage: dump_interface_table") \
12651 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
12652 _(dump_ipv4_table, "usage: dump_ipv4_table") \
12653 _(dump_ipv6_table, "usage: dump_ipv6_table") \
12654 _(dump_stats_table, "usage: dump_stats_table") \
12655 _(dump_macro_table, "usage: dump_macro_table ") \
12656 _(dump_node_table, "usage: dump_node_table") \
12657 _(echo, "usage: echo <message>") \
12658 _(exec, "usage: exec <vpe-debug-CLI-command>") \
12659 _(help, "usage: help") \
12660 _(q, "usage: quit") \
12661 _(quit, "usage: quit") \
12662 _(search_node_table, "usage: search_node_table <name>...") \
12663 _(set, "usage: set <variable-name> <value>") \
12664 _(script, "usage: script <file-name>") \
12665 _(unset, "usage: unset <variable-name>")
12668 static void vl_api_##n##_t_handler_uni \
12669 (vl_api_##n##_t * mp) \
12671 vat_main_t * vam = &vat_main; \
12672 if (vam->json_output) { \
12673 vl_api_##n##_t_handler_json(mp); \
12675 vl_api_##n##_t_handler(mp); \
12678 foreach_vpe_api_reply_msg;
12681 void vat_api_hookup (vat_main_t *vam)
12684 vl_msg_api_set_handlers(VL_API_##N, #n, \
12685 vl_api_##n##_t_handler_uni, \
12687 vl_api_##n##_t_endian, \
12688 vl_api_##n##_t_print, \
12689 sizeof(vl_api_##n##_t), 1);
12690 foreach_vpe_api_reply_msg;
12693 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
12695 vam->sw_if_index_by_interface_name =
12696 hash_create_string (0, sizeof (uword));
12698 vam->function_by_name =
12699 hash_create_string (0, sizeof(uword));
12701 vam->help_by_name =
12702 hash_create_string (0, sizeof(uword));
12704 /* API messages we can send */
12705 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
12706 foreach_vpe_api_msg;
12710 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12711 foreach_vpe_api_msg;
12714 /* CLI functions */
12715 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
12716 foreach_cli_function;
12720 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12721 foreach_cli_function;
12725 #undef vl_api_version
12726 #define vl_api_version(n,v) static u32 vpe_api_version = v;
12727 #include <vpp-api/vpe.api.h>
12728 #undef vl_api_version
12730 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
12733 * Send the main API signature in slot 0. This bit of code must
12734 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
12736 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);