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/classify/policer_classify.h>
38 #include <vnet/mpls-gre/mpls.h>
40 #include <vnet/ipsec/ipsec.h>
41 #include <vnet/ipsec/ikev2.h>
45 #include <vnet/map/map.h>
46 #include <vnet/cop/cop.h>
47 #include <vnet/ip/ip6_hop_by_hop.h>
48 #include <vnet/policer/xlate.h>
49 #include <vnet/policer/policer.h>
50 #include <vnet/policer/police.h>
52 #include "vat/json_format.h"
56 #define vl_typedefs /* define message structures */
57 #include <vpp-api/vpe_all_api_h.h>
60 /* declare message handlers for each api */
62 #define vl_endianfun /* define message structures */
63 #include <vpp-api/vpe_all_api_h.h>
66 /* instantiate all the print functions we know about */
67 #define vl_print(handle, ...)
69 #include <vpp-api/vpe_all_api_h.h>
72 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
74 vat_main_t * vam = va_arg (*args, vat_main_t *);
75 u32 * result = va_arg (*args, u32 *);
79 if (!unformat (input, "%s", &if_name))
82 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
89 /* Parse an IP4 address %d.%d.%d.%d. */
90 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
92 u8 * result = va_arg (*args, u8 *);
95 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
98 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
111 unformat_ethernet_address (unformat_input_t * input, va_list * args)
113 u8 * result = va_arg (*args, u8 *);
116 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
117 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
121 for (i = 0; i < 6; i++)
122 if (a[i] >= (1 << 8))
125 for (i = 0; i < 6; i++)
131 /* Returns ethernet type as an int in host byte order. */
133 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
136 u16 * result = va_arg (*args, u16 *);
140 if (unformat (input, "0x%x", &type)
141 || unformat (input, "%d", &type))
143 if (type >= (1 << 16))
151 /* Parse an IP6 address. */
152 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
154 ip6_address_t * result = va_arg (*args, ip6_address_t *);
156 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
157 uword c, n_colon, double_colon_index;
159 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
160 double_colon_index = ARRAY_LEN (hex_quads);
161 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
164 if (c >= '0' && c <= '9')
166 else if (c >= 'a' && c <= 'f')
167 hex_digit = c + 10 - 'a';
168 else if (c >= 'A' && c <= 'F')
169 hex_digit = c + 10 - 'A';
170 else if (c == ':' && n_colon < 2)
174 unformat_put_input (input);
178 /* Too many hex quads. */
179 if (n_hex_quads >= ARRAY_LEN (hex_quads))
184 hex_quad = (hex_quad << 4) | hex_digit;
186 /* Hex quad must fit in 16 bits. */
187 if (n_hex_digits >= 4)
194 /* Save position of :: */
197 /* More than one :: ? */
198 if (double_colon_index < ARRAY_LEN (hex_quads))
200 double_colon_index = n_hex_quads;
203 if (n_colon > 0 && n_hex_digits > 0)
205 hex_quads[n_hex_quads++] = hex_quad;
211 if (n_hex_digits > 0)
212 hex_quads[n_hex_quads++] = hex_quad;
217 /* Expand :: to appropriate number of zero hex quads. */
218 if (double_colon_index < ARRAY_LEN (hex_quads))
220 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
222 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
223 hex_quads[n_zero + i] = hex_quads[i];
225 for (i = 0; i < n_zero; i++)
226 hex_quads[double_colon_index + i] = 0;
228 n_hex_quads = ARRAY_LEN (hex_quads);
231 /* Too few hex quads given. */
232 if (n_hex_quads < ARRAY_LEN (hex_quads))
235 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
236 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
243 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
246 u32 * r = va_arg (*args, u32 *);
249 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
250 foreach_ipsec_policy_action
261 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
264 u32 * r = va_arg (*args, u32 *);
267 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
268 foreach_ipsec_crypto_alg
279 format_ipsec_crypto_alg (u8 * s, va_list * args)
282 u32 i = va_arg (*args, u32);
287 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
288 foreach_ipsec_crypto_alg
291 return format (s, "unknown");
293 return format (s, "%s", t);
295 return format (s, "Unimplemented");
300 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
303 u32 * r = va_arg (*args, u32 *);
306 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
307 foreach_ipsec_integ_alg
318 format_ipsec_integ_alg (u8 * s, va_list * args)
321 u32 i = va_arg (*args, u32);
326 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
327 foreach_ipsec_integ_alg
330 return format (s, "unknown");
332 return format (s, "%s", t);
334 return format (s, "Unsupported");
339 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
342 u32 * r = va_arg (*args, u32 *);
345 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
346 foreach_ikev2_auth_method
357 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
360 u32 * r = va_arg (*args, u32 *);
363 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
364 foreach_ikev2_id_type
375 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
377 u8 * r = va_arg (*args, u8 *);
379 if (unformat (input, "kbps"))
380 *r = SSE2_QOS_RATE_KBPS;
381 else if (unformat(input, "pps"))
382 *r = SSE2_QOS_RATE_PPS;
389 unformat_policer_round_type (unformat_input_t * input, va_list * args)
391 u8 * r = va_arg (*args, u8 *);
393 if (unformat(input, "closest"))
394 *r = SSE2_QOS_ROUND_TO_CLOSEST;
395 else if (unformat (input, "up"))
396 *r = SSE2_QOS_ROUND_TO_UP;
397 else if (unformat (input, "down"))
398 *r = SSE2_QOS_ROUND_TO_DOWN;
405 unformat_policer_type (unformat_input_t * input, va_list * args)
407 u8 * r = va_arg (*args, u8 *);
409 if (unformat (input, "1r2c"))
410 *r = SSE2_QOS_POLICER_TYPE_1R2C;
411 else if (unformat (input, "1r3c"))
412 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
413 else if (unformat (input, "2r3c-2698"))
414 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
415 else if (unformat (input, "2r3c-4115"))
416 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
417 else if (unformat (input, "2r3c-mef5cf1"))
418 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
425 unformat_dscp (unformat_input_t * input, va_list * va)
427 u8 * r = va_arg (*va, u8 *);
430 #define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
439 unformat_policer_action_type (unformat_input_t * input, va_list * va)
441 sse2_qos_pol_action_params_st * a
442 = va_arg (*va, sse2_qos_pol_action_params_st *);
444 if (unformat (input, "drop"))
445 a->action_type = SSE2_QOS_ACTION_DROP;
446 else if (unformat (input, "transmit"))
447 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
448 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
449 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
456 unformat_classify_table_type (unformat_input_t * input, va_list * va)
458 u32 * r = va_arg (*va, u32 *);
461 if (unformat (input, "ip4"))
462 tid = POLICER_CLASSIFY_TABLE_IP4;
463 else if (unformat (input, "ip6"))
464 tid = POLICER_CLASSIFY_TABLE_IP6;
465 else if (unformat (input, "l2"))
466 tid = POLICER_CLASSIFY_TABLE_L2;
474 u8 * format_ip4_address (u8 * s, va_list * args)
476 u8 * a = va_arg (*args, u8 *);
477 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
480 u8 * format_ip6_address (u8 * s, va_list * args)
482 ip6_address_t * a = va_arg (*args, ip6_address_t *);
483 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
485 i_max_n_zero = ARRAY_LEN (a->as_u16);
487 i_first_zero = i_max_n_zero;
489 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
491 u32 is_zero = a->as_u16[i] == 0;
492 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
498 if ((! is_zero && n_zeros > max_n_zeros)
499 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
501 i_max_n_zero = i_first_zero;
502 max_n_zeros = n_zeros;
503 i_first_zero = ARRAY_LEN (a->as_u16);
508 last_double_colon = 0;
509 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
511 if (i == i_max_n_zero && max_n_zeros > 1)
513 s = format (s, "::");
514 i += max_n_zeros - 1;
515 last_double_colon = 1;
519 s = format (s, "%s%x",
520 (last_double_colon || i == 0) ? "" : ":",
521 clib_net_to_host_u16 (a->as_u16[i]));
522 last_double_colon = 0;
529 /* Format an IP46 address. */
530 u8 * format_ip46_address (u8 * s, va_list * args)
532 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
533 ip46_type_t type = va_arg (*args, ip46_type_t);
539 is_ip4 = ip46_address_is_ip4(ip46);
550 format(s, "%U", format_ip4_address, &ip46->ip4):
551 format(s, "%U", format_ip6_address, &ip46->ip6);
554 u8 * format_ethernet_address (u8 * s, va_list * args)
556 u8 * a = va_arg (*args, u8 *);
558 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
559 a[0], a[1], a[2], a[3], a[4], a[5]);
562 void increment_v4_address (ip4_address_t * a)
566 v = ntohl(a->as_u32) + 1;
567 a->as_u32 = ntohl(v);
570 void increment_v6_address (ip6_address_t * a)
574 v0 = clib_net_to_host_u64 (a->as_u64[0]);
575 v1 = clib_net_to_host_u64 (a->as_u64[1]);
580 a->as_u64[0] = clib_net_to_host_u64 (v0);
581 a->as_u64[1] = clib_net_to_host_u64 (v1);
584 void increment_mac_address (u64 *mac)
588 tmp = clib_net_to_host_u64(tmp);
589 tmp += 1<<16; /* skip unused (least significant) octets */
590 tmp = clib_host_to_net_u64 (tmp);
594 static void vl_api_create_loopback_reply_t_handler
595 (vl_api_create_loopback_reply_t * mp)
597 vat_main_t * vam = &vat_main;
598 i32 retval = ntohl(mp->retval);
600 vam->retval = retval;
601 vam->regenerate_interface_table = 1;
602 vam->sw_if_index = ntohl (mp->sw_if_index);
603 vam->result_ready = 1;
606 static void vl_api_create_loopback_reply_t_handler_json
607 (vl_api_create_loopback_reply_t * mp)
609 vat_main_t * vam = &vat_main;
610 vat_json_node_t node;
612 vat_json_init_object(&node);
613 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
614 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
616 vat_json_print(vam->ofp, &node);
617 vat_json_free(&node);
618 vam->retval = ntohl(mp->retval);
619 vam->result_ready = 1;
622 static void vl_api_af_packet_create_reply_t_handler
623 (vl_api_af_packet_create_reply_t * mp)
625 vat_main_t * vam = &vat_main;
626 i32 retval = ntohl(mp->retval);
628 vam->retval = retval;
629 vam->regenerate_interface_table = 1;
630 vam->sw_if_index = ntohl (mp->sw_if_index);
631 vam->result_ready = 1;
634 static void vl_api_af_packet_create_reply_t_handler_json
635 (vl_api_af_packet_create_reply_t * mp)
637 vat_main_t * vam = &vat_main;
638 vat_json_node_t node;
640 vat_json_init_object(&node);
641 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
642 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
644 vat_json_print(vam->ofp, &node);
645 vat_json_free(&node);
647 vam->retval = ntohl(mp->retval);
648 vam->result_ready = 1;
651 static void vl_api_create_vlan_subif_reply_t_handler
652 (vl_api_create_vlan_subif_reply_t * mp)
654 vat_main_t * vam = &vat_main;
655 i32 retval = ntohl(mp->retval);
657 vam->retval = retval;
658 vam->regenerate_interface_table = 1;
659 vam->sw_if_index = ntohl (mp->sw_if_index);
660 vam->result_ready = 1;
663 static void vl_api_create_vlan_subif_reply_t_handler_json
664 (vl_api_create_vlan_subif_reply_t * mp)
666 vat_main_t * vam = &vat_main;
667 vat_json_node_t node;
669 vat_json_init_object(&node);
670 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
671 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
673 vat_json_print(vam->ofp, &node);
674 vat_json_free(&node);
676 vam->retval = ntohl(mp->retval);
677 vam->result_ready = 1;
680 static void vl_api_create_subif_reply_t_handler
681 (vl_api_create_subif_reply_t * mp)
683 vat_main_t * vam = &vat_main;
684 i32 retval = ntohl(mp->retval);
686 vam->retval = retval;
687 vam->regenerate_interface_table = 1;
688 vam->sw_if_index = ntohl (mp->sw_if_index);
689 vam->result_ready = 1;
692 static void vl_api_create_subif_reply_t_handler_json
693 (vl_api_create_subif_reply_t * mp)
695 vat_main_t * vam = &vat_main;
696 vat_json_node_t node;
698 vat_json_init_object(&node);
699 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
700 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
702 vat_json_print(vam->ofp, &node);
703 vat_json_free(&node);
705 vam->retval = ntohl(mp->retval);
706 vam->result_ready = 1;
709 static void vl_api_interface_name_renumber_reply_t_handler
710 (vl_api_interface_name_renumber_reply_t * mp)
712 vat_main_t * vam = &vat_main;
713 i32 retval = ntohl(mp->retval);
715 vam->retval = retval;
716 vam->regenerate_interface_table = 1;
717 vam->result_ready = 1;
720 static void vl_api_interface_name_renumber_reply_t_handler_json
721 (vl_api_interface_name_renumber_reply_t * mp)
723 vat_main_t * vam = &vat_main;
724 vat_json_node_t node;
726 vat_json_init_object(&node);
727 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
729 vat_json_print(vam->ofp, &node);
730 vat_json_free(&node);
732 vam->retval = ntohl(mp->retval);
733 vam->result_ready = 1;
737 * Special-case: build the interface table, maintain
738 * the next loopback sw_if_index vbl.
740 static void vl_api_sw_interface_details_t_handler
741 (vl_api_sw_interface_details_t * mp)
743 vat_main_t * vam = &vat_main;
744 u8 * s = format (0, "%s%c", mp->interface_name, 0);
746 hash_set_mem (vam->sw_if_index_by_interface_name, s,
747 ntohl(mp->sw_if_index));
749 /* In sub interface case, fill the sub interface table entry */
750 if (mp->sw_if_index != mp->sup_sw_if_index) {
751 sw_interface_subif_t * sub = NULL;
753 vec_add2(vam->sw_if_subif_table, sub, 1);
755 vec_validate(sub->interface_name, strlen((char *)s) + 1);
756 strncpy((char *)sub->interface_name, (char *)s,
757 vec_len(sub->interface_name));
758 sub->sw_if_index = ntohl(mp->sw_if_index);
759 sub->sub_id = ntohl(mp->sub_id);
761 sub->sub_dot1ad = mp->sub_dot1ad;
762 sub->sub_number_of_tags = mp->sub_number_of_tags;
763 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
764 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
765 sub->sub_exact_match = mp->sub_exact_match;
766 sub->sub_default = mp->sub_default;
767 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
768 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
770 /* vlan tag rewrite */
771 sub->vtr_op = ntohl(mp->vtr_op);
772 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
773 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
774 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
778 static void vl_api_sw_interface_details_t_handler_json
779 (vl_api_sw_interface_details_t * mp)
781 vat_main_t * vam = &vat_main;
782 vat_json_node_t *node = NULL;
784 if (VAT_JSON_ARRAY != vam->json_tree.type) {
785 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
786 vat_json_init_array(&vam->json_tree);
788 node = vat_json_array_add(&vam->json_tree);
790 vat_json_init_object(node);
791 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
792 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
793 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
794 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
795 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
796 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
797 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
798 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
799 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
800 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
801 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
802 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
803 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
804 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
805 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
806 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
807 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
808 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
809 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
810 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
811 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
812 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
813 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
816 static void vl_api_sw_interface_set_flags_t_handler
817 (vl_api_sw_interface_set_flags_t * mp)
819 vat_main_t * vam = &vat_main;
820 if (vam->interface_event_display)
821 errmsg ("interface flags: sw_if_index %d %s %s\n",
822 ntohl(mp->sw_if_index),
823 mp->admin_up_down ? "admin-up" : "admin-down",
824 mp->link_up_down ? "link-up" : "link-down");
827 static void vl_api_sw_interface_set_flags_t_handler_json
828 (vl_api_sw_interface_set_flags_t * mp)
830 /* JSON output not supported */
833 static void vl_api_cli_reply_t_handler
834 (vl_api_cli_reply_t * mp)
836 vat_main_t * vam = &vat_main;
837 i32 retval = ntohl(mp->retval);
839 vam->retval = retval;
840 vam->shmem_result = (u8 *) mp->reply_in_shmem;
841 vam->result_ready = 1;
844 static void vl_api_cli_reply_t_handler_json
845 (vl_api_cli_reply_t * mp)
847 vat_main_t * vam = &vat_main;
848 vat_json_node_t node;
849 api_main_t * am = &api_main;
853 vat_json_init_object(&node);
854 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
855 vat_json_object_add_uint(&node, "reply_in_shmem",
856 ntohl(mp->reply_in_shmem));
857 /* Toss the shared-memory original... */
858 pthread_mutex_lock (&am->vlib_rp->mutex);
859 oldheap = svm_push_data_heap (am->vlib_rp);
861 reply = (u8 *)(mp->reply_in_shmem);
864 svm_pop_heap (oldheap);
865 pthread_mutex_unlock (&am->vlib_rp->mutex);
867 vat_json_print(vam->ofp, &node);
868 vat_json_free(&node);
870 vam->retval = ntohl(mp->retval);
871 vam->result_ready = 1;
874 static void vl_api_classify_add_del_table_reply_t_handler
875 (vl_api_classify_add_del_table_reply_t * mp)
877 vat_main_t * vam = &vat_main;
878 i32 retval = ntohl(mp->retval);
879 if (vam->async_mode) {
880 vam->async_errors += (retval < 0);
882 vam->retval = retval;
884 ((mp->new_table_index != 0xFFFFFFFF) ||
885 (mp->skip_n_vectors != 0xFFFFFFFF) ||
886 (mp->match_n_vectors != 0xFFFFFFFF)))
888 * Note: this is just barely thread-safe, depends on
889 * the main thread spinning waiting for an answer...
891 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
892 ntohl(mp->new_table_index),
893 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
894 vam->result_ready = 1;
898 static void vl_api_classify_add_del_table_reply_t_handler_json
899 (vl_api_classify_add_del_table_reply_t * mp)
901 vat_main_t * vam = &vat_main;
902 vat_json_node_t node;
904 vat_json_init_object(&node);
905 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
906 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
907 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
908 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
910 vat_json_print(vam->ofp, &node);
911 vat_json_free(&node);
913 vam->retval = ntohl(mp->retval);
914 vam->result_ready = 1;
917 static void vl_api_get_node_index_reply_t_handler
918 (vl_api_get_node_index_reply_t * mp)
920 vat_main_t * vam = &vat_main;
921 i32 retval = ntohl(mp->retval);
922 if (vam->async_mode) {
923 vam->async_errors += (retval < 0);
925 vam->retval = retval;
927 errmsg ("node index %d\n", ntohl(mp->node_index));
928 vam->result_ready = 1;
932 static void vl_api_get_node_index_reply_t_handler_json
933 (vl_api_get_node_index_reply_t * mp)
935 vat_main_t * vam = &vat_main;
936 vat_json_node_t node;
938 vat_json_init_object(&node);
939 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
940 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
942 vat_json_print(vam->ofp, &node);
943 vat_json_free(&node);
945 vam->retval = ntohl(mp->retval);
946 vam->result_ready = 1;
949 static void vl_api_get_next_index_reply_t_handler
950 (vl_api_get_next_index_reply_t * mp)
952 vat_main_t * vam = &vat_main;
953 i32 retval = ntohl(mp->retval);
954 if (vam->async_mode) {
955 vam->async_errors += (retval < 0);
957 vam->retval = retval;
959 errmsg ("next node index %d\n", ntohl(mp->next_index));
960 vam->result_ready = 1;
964 static void vl_api_get_next_index_reply_t_handler_json
965 (vl_api_get_next_index_reply_t * mp)
967 vat_main_t * vam = &vat_main;
968 vat_json_node_t node;
970 vat_json_init_object(&node);
971 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
972 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
974 vat_json_print(vam->ofp, &node);
975 vat_json_free(&node);
977 vam->retval = ntohl(mp->retval);
978 vam->result_ready = 1;
981 static void vl_api_add_node_next_reply_t_handler
982 (vl_api_add_node_next_reply_t * mp)
984 vat_main_t * vam = &vat_main;
985 i32 retval = ntohl(mp->retval);
986 if (vam->async_mode) {
987 vam->async_errors += (retval < 0);
989 vam->retval = retval;
991 errmsg ("next index %d\n", ntohl(mp->next_index));
992 vam->result_ready = 1;
996 static void vl_api_add_node_next_reply_t_handler_json
997 (vl_api_add_node_next_reply_t * mp)
999 vat_main_t * vam = &vat_main;
1000 vat_json_node_t node;
1002 vat_json_init_object(&node);
1003 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1004 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
1006 vat_json_print(vam->ofp, &node);
1007 vat_json_free(&node);
1009 vam->retval = ntohl(mp->retval);
1010 vam->result_ready = 1;
1013 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
1014 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
1016 vat_main_t * vam = &vat_main;
1017 i32 retval = ntohl(mp->retval);
1018 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
1020 if (retval >= 0 && sw_if_index != (u32)~0) {
1021 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
1023 vam->retval = retval;
1024 vam->result_ready = 1;
1027 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
1028 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
1030 vat_main_t * vam = &vat_main;
1031 vat_json_node_t node;
1033 vat_json_init_object(&node);
1034 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1035 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1037 vat_json_print(vam->ofp, &node);
1038 vat_json_free(&node);
1040 vam->retval = ntohl(mp->retval);
1041 vam->result_ready = 1;
1045 static void vl_api_show_version_reply_t_handler
1046 (vl_api_show_version_reply_t * mp)
1048 vat_main_t * vam = &vat_main;
1049 i32 retval = ntohl(mp->retval);
1052 errmsg (" program: %s\n", mp->program);
1053 errmsg (" version: %s\n", mp->version);
1054 errmsg (" build date: %s\n", mp->build_date);
1055 errmsg ("build directory: %s\n", mp->build_directory);
1057 vam->retval = retval;
1058 vam->result_ready = 1;
1061 static void vl_api_show_version_reply_t_handler_json
1062 (vl_api_show_version_reply_t * mp)
1064 vat_main_t * vam = &vat_main;
1065 vat_json_node_t node;
1067 vat_json_init_object(&node);
1068 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1069 vat_json_object_add_string_copy(&node, "program", mp->program);
1070 vat_json_object_add_string_copy(&node, "version", mp->version);
1071 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
1072 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
1074 vat_json_print(vam->ofp, &node);
1075 vat_json_free(&node);
1077 vam->retval = ntohl(mp->retval);
1078 vam->result_ready = 1;
1081 static void vl_api_ip4_arp_event_t_handler
1082 (vl_api_ip4_arp_event_t * mp)
1084 vat_main_t * vam = &vat_main;
1085 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
1086 format_ip4_address, &mp->address,
1087 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1090 static void vl_api_ip4_arp_event_t_handler_json
1091 (vl_api_ip4_arp_event_t * mp)
1093 /* JSON output not supported */
1097 * Special-case: build the bridge domain table, maintain
1098 * the next bd id vbl.
1100 static void vl_api_bridge_domain_details_t_handler
1101 (vl_api_bridge_domain_details_t * mp)
1103 vat_main_t * vam = &vat_main;
1104 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1106 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1107 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1109 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1110 ntohl (mp->bd_id), mp->learn, mp->forward,
1111 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1114 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1118 static void vl_api_bridge_domain_details_t_handler_json
1119 (vl_api_bridge_domain_details_t * mp)
1121 vat_main_t * vam = &vat_main;
1122 vat_json_node_t *node, *array = NULL;
1124 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1125 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1126 vat_json_init_array(&vam->json_tree);
1128 node = vat_json_array_add(&vam->json_tree);
1130 vat_json_init_object(node);
1131 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1132 vat_json_object_add_uint(node, "flood", mp->flood);
1133 vat_json_object_add_uint(node, "forward", mp->forward);
1134 vat_json_object_add_uint(node, "learn", mp->learn);
1135 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1136 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1137 array = vat_json_object_add(node, "sw_if");
1138 vat_json_init_array(array);
1142 * Special-case: build the bridge domain sw if table.
1144 static void vl_api_bridge_domain_sw_if_details_t_handler
1145 (vl_api_bridge_domain_sw_if_details_t * mp)
1147 vat_main_t * vam = &vat_main;
1149 u8 * sw_if_name = 0;
1152 sw_if_index = ntohl (mp->sw_if_index);
1153 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1155 if ((u32) p->value[0] == sw_if_index) {
1156 sw_if_name = (u8 *)(p->key);
1161 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1162 mp->shg, sw_if_name ? (char *)sw_if_name :
1163 "sw_if_index not found!");
1166 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1167 (vl_api_bridge_domain_sw_if_details_t * mp)
1169 vat_main_t * vam = &vat_main;
1170 vat_json_node_t *node = NULL;
1171 uword last_index = 0;
1173 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1174 ASSERT(vec_len(vam->json_tree.array) >= 1);
1175 last_index = vec_len(vam->json_tree.array) - 1;
1176 node = &vam->json_tree.array[last_index];
1177 node = vat_json_object_get_element(node, "sw_if");
1178 ASSERT(NULL != node);
1179 node = vat_json_array_add(node);
1181 vat_json_init_object(node);
1182 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1183 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1184 vat_json_object_add_uint(node, "shg", mp->shg);
1187 static void vl_api_control_ping_reply_t_handler
1188 (vl_api_control_ping_reply_t * mp)
1190 vat_main_t * vam = &vat_main;
1191 i32 retval = ntohl(mp->retval);
1192 if (vam->async_mode) {
1193 vam->async_errors += (retval < 0);
1195 vam->retval = retval;
1196 vam->result_ready = 1;
1200 static void vl_api_control_ping_reply_t_handler_json
1201 (vl_api_control_ping_reply_t * mp)
1203 vat_main_t * vam = &vat_main;
1204 i32 retval = ntohl(mp->retval);
1206 if (VAT_JSON_NONE != vam->json_tree.type) {
1207 vat_json_print(vam->ofp, &vam->json_tree);
1208 vat_json_free(&vam->json_tree);
1209 vam->json_tree.type = VAT_JSON_NONE;
1212 vat_json_init_array(&vam->json_tree);
1213 vat_json_print(vam->ofp, &vam->json_tree);
1214 vam->json_tree.type = VAT_JSON_NONE;
1217 vam->retval = retval;
1218 vam->result_ready = 1;
1221 static void vl_api_noprint_control_ping_reply_t_handler
1222 (vl_api_noprint_control_ping_reply_t * mp)
1224 vat_main_t * vam = &vat_main;
1225 i32 retval = ntohl(mp->retval);
1226 if (vam->async_mode) {
1227 vam->async_errors += (retval < 0);
1229 vam->retval = retval;
1230 vam->result_ready = 1;
1234 static void vl_api_noprint_control_ping_reply_t_handler_json
1235 (vl_api_noprint_control_ping_reply_t * mp)
1237 vat_main_t * vam = &vat_main;
1238 i32 retval = ntohl(mp->retval);
1240 if (vam->noprint_msg) {
1241 vam->retval = retval;
1242 vam->result_ready = 1;
1246 if (VAT_JSON_NONE != vam->json_tree.type) {
1247 vat_json_print(vam->ofp, &vam->json_tree);
1248 vat_json_free(&vam->json_tree);
1249 vam->json_tree.type = VAT_JSON_NONE;
1252 vat_json_init_array(&vam->json_tree);
1253 vat_json_print(vam->ofp, &vam->json_tree);
1254 vam->json_tree.type = VAT_JSON_NONE;
1257 vam->retval = retval;
1258 vam->result_ready = 1;
1261 static void vl_api_l2_flags_reply_t_handler
1262 (vl_api_l2_flags_reply_t * mp)
1264 vat_main_t * vam = &vat_main;
1265 i32 retval = ntohl(mp->retval);
1266 if (vam->async_mode) {
1267 vam->async_errors += (retval < 0);
1269 vam->retval = retval;
1270 vam->result_ready = 1;
1274 static void vl_api_l2_flags_reply_t_handler_json
1275 (vl_api_l2_flags_reply_t * mp)
1277 vat_main_t * vam = &vat_main;
1278 vat_json_node_t node;
1280 vat_json_init_object(&node);
1281 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1282 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1284 vat_json_print(vam->ofp, &node);
1285 vat_json_free(&node);
1287 vam->retval = ntohl(mp->retval);
1288 vam->result_ready = 1;
1291 static void vl_api_bridge_flags_reply_t_handler
1292 (vl_api_bridge_flags_reply_t * mp)
1294 vat_main_t * vam = &vat_main;
1295 i32 retval = ntohl(mp->retval);
1296 if (vam->async_mode) {
1297 vam->async_errors += (retval < 0);
1299 vam->retval = retval;
1300 vam->result_ready = 1;
1304 static void vl_api_bridge_flags_reply_t_handler_json
1305 (vl_api_bridge_flags_reply_t * mp)
1307 vat_main_t * vam = &vat_main;
1308 vat_json_node_t node;
1310 vat_json_init_object(&node);
1311 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1312 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1314 vat_json_print(vam->ofp, &node);
1315 vat_json_free(&node);
1317 vam->retval = ntohl(mp->retval);
1318 vam->result_ready = 1;
1321 static void vl_api_tap_connect_reply_t_handler
1322 (vl_api_tap_connect_reply_t * mp)
1324 vat_main_t * vam = &vat_main;
1325 i32 retval = ntohl(mp->retval);
1326 if (vam->async_mode) {
1327 vam->async_errors += (retval < 0);
1329 vam->retval = retval;
1330 vam->sw_if_index = ntohl (mp->sw_if_index);
1331 vam->result_ready = 1;
1336 static void vl_api_tap_connect_reply_t_handler_json
1337 (vl_api_tap_connect_reply_t * mp)
1339 vat_main_t * vam = &vat_main;
1340 vat_json_node_t node;
1342 vat_json_init_object(&node);
1343 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1344 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1346 vat_json_print(vam->ofp, &node);
1347 vat_json_free(&node);
1349 vam->retval = ntohl(mp->retval);
1350 vam->result_ready = 1;
1354 static void vl_api_tap_modify_reply_t_handler
1355 (vl_api_tap_modify_reply_t * mp)
1357 vat_main_t * vam = &vat_main;
1358 i32 retval = ntohl(mp->retval);
1359 if (vam->async_mode) {
1360 vam->async_errors += (retval < 0);
1362 vam->retval = retval;
1363 vam->sw_if_index = ntohl (mp->sw_if_index);
1364 vam->result_ready = 1;
1368 static void vl_api_tap_modify_reply_t_handler_json
1369 (vl_api_tap_modify_reply_t * mp)
1371 vat_main_t * vam = &vat_main;
1372 vat_json_node_t node;
1374 vat_json_init_object(&node);
1375 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1376 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1378 vat_json_print(vam->ofp, &node);
1379 vat_json_free(&node);
1381 vam->retval = ntohl(mp->retval);
1382 vam->result_ready = 1;
1385 static void vl_api_tap_delete_reply_t_handler
1386 (vl_api_tap_delete_reply_t * mp)
1388 vat_main_t * vam = &vat_main;
1389 i32 retval = ntohl(mp->retval);
1390 if (vam->async_mode) {
1391 vam->async_errors += (retval < 0);
1393 vam->retval = retval;
1394 vam->result_ready = 1;
1398 static void vl_api_tap_delete_reply_t_handler_json
1399 (vl_api_tap_delete_reply_t * mp)
1401 vat_main_t * vam = &vat_main;
1402 vat_json_node_t node;
1404 vat_json_init_object(&node);
1405 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1407 vat_json_print(vam->ofp, &node);
1408 vat_json_free(&node);
1410 vam->retval = ntohl(mp->retval);
1411 vam->result_ready = 1;
1414 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1415 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1417 vat_main_t * vam = &vat_main;
1418 i32 retval = ntohl(mp->retval);
1419 if (vam->async_mode) {
1420 vam->async_errors += (retval < 0);
1422 vam->retval = retval;
1423 vam->result_ready = 1;
1427 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1428 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1430 vat_main_t * vam = &vat_main;
1431 vat_json_node_t node;
1433 vat_json_init_object(&node);
1434 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1435 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1437 vat_json_print(vam->ofp, &node);
1438 vat_json_free(&node);
1440 vam->retval = ntohl(mp->retval);
1441 vam->result_ready = 1;
1444 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1445 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1447 vat_main_t * vam = &vat_main;
1448 i32 retval = ntohl(mp->retval);
1449 if (vam->async_mode) {
1450 vam->async_errors += (retval < 0);
1452 vam->retval = retval;
1453 vam->sw_if_index = ntohl (mp->sw_if_index);
1454 vam->result_ready = 1;
1458 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1459 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1461 vat_main_t * vam = &vat_main;
1462 vat_json_node_t node;
1464 vat_json_init_object(&node);
1465 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1466 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1468 vat_json_print(vam->ofp, &node);
1469 vat_json_free(&node);
1471 vam->retval = ntohl(mp->retval);
1472 vam->result_ready = 1;
1475 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1476 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1478 vat_main_t * vam = &vat_main;
1479 i32 retval = ntohl(mp->retval);
1480 if (vam->async_mode) {
1481 vam->async_errors += (retval < 0);
1483 vam->retval = retval;
1484 vam->sw_if_index = ntohl (mp->sw_if_index);
1485 vam->result_ready = 1;
1489 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1490 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1492 vat_main_t * vam = &vat_main;
1493 vat_json_node_t node;
1495 vat_json_init_object(&node);
1496 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1497 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1499 vat_json_print(vam->ofp, &node);
1500 vat_json_free(&node);
1502 vam->retval = ntohl(mp->retval);
1503 vam->result_ready = 1;
1506 static void vl_api_gre_add_del_tunnel_reply_t_handler
1507 (vl_api_gre_add_del_tunnel_reply_t * mp)
1509 vat_main_t * vam = &vat_main;
1510 i32 retval = ntohl(mp->retval);
1511 if (vam->async_mode) {
1512 vam->async_errors += (retval < 0);
1514 vam->retval = retval;
1515 vam->sw_if_index = ntohl (mp->sw_if_index);
1516 vam->result_ready = 1;
1520 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1521 (vl_api_gre_add_del_tunnel_reply_t * mp)
1523 vat_main_t * vam = &vat_main;
1524 vat_json_node_t node;
1526 vat_json_init_object(&node);
1527 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1528 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1530 vat_json_print(vam->ofp, &node);
1531 vat_json_free(&node);
1533 vam->retval = ntohl(mp->retval);
1534 vam->result_ready = 1;
1537 static void vl_api_create_vhost_user_if_reply_t_handler
1538 (vl_api_create_vhost_user_if_reply_t * mp)
1540 vat_main_t * vam = &vat_main;
1541 i32 retval = ntohl(mp->retval);
1542 if (vam->async_mode) {
1543 vam->async_errors += (retval < 0);
1545 vam->retval = retval;
1546 vam->sw_if_index = ntohl (mp->sw_if_index);
1547 vam->result_ready = 1;
1551 static void vl_api_create_vhost_user_if_reply_t_handler_json
1552 (vl_api_create_vhost_user_if_reply_t * mp)
1554 vat_main_t * vam = &vat_main;
1555 vat_json_node_t node;
1557 vat_json_init_object(&node);
1558 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1559 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1561 vat_json_print(vam->ofp, &node);
1562 vat_json_free(&node);
1564 vam->retval = ntohl(mp->retval);
1565 vam->result_ready = 1;
1568 static void vl_api_ip_address_details_t_handler
1569 (vl_api_ip_address_details_t * mp)
1571 vat_main_t * vam = &vat_main;
1572 static ip_address_details_t empty_ip_address_details = {{0}};
1573 ip_address_details_t * address = NULL;
1574 ip_details_t * current_ip_details = NULL;
1575 ip_details_t * details = NULL;
1577 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1579 if (!details || vam->current_sw_if_index >= vec_len(details)
1580 || !details[vam->current_sw_if_index].present) {
1581 errmsg ("ip address details arrived but not stored\n");
1582 errmsg ("ip_dump should be called first\n");
1586 current_ip_details = vec_elt_at_index(details,
1587 vam->current_sw_if_index);
1589 #define addresses (current_ip_details->addr)
1591 vec_validate_init_empty(addresses, vec_len(addresses),
1592 empty_ip_address_details);
1594 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1596 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1597 address->prefix_length = mp->prefix_length;
1601 static void vl_api_ip_address_details_t_handler_json
1602 (vl_api_ip_address_details_t * mp)
1604 vat_main_t * vam = &vat_main;
1605 vat_json_node_t *node = NULL;
1606 struct in6_addr ip6;
1609 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1610 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1611 vat_json_init_array(&vam->json_tree);
1613 node = vat_json_array_add(&vam->json_tree);
1615 vat_json_init_object(node);
1617 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1618 vat_json_object_add_ip6(node, "ip", ip6);
1620 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1621 vat_json_object_add_ip4(node, "ip", ip4);
1623 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1626 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1628 vat_main_t * vam = &vat_main;
1629 static ip_details_t empty_ip_details = {0};
1630 ip_details_t * ip = NULL;
1631 u32 sw_if_index = ~0;
1633 sw_if_index = ntohl(mp->sw_if_index);
1635 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1636 sw_if_index, empty_ip_details);
1638 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1644 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1646 vat_main_t * vam = &vat_main;
1648 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1649 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1650 vat_json_init_array(&vam->json_tree);
1652 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1655 static void vl_api_map_domain_details_t_handler_json
1656 (vl_api_map_domain_details_t * mp)
1658 vat_json_node_t * node = NULL;
1659 vat_main_t * vam = &vat_main;
1660 struct in6_addr ip6;
1663 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1664 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1665 vat_json_init_array(&vam->json_tree);
1668 node = vat_json_array_add(&vam->json_tree);
1669 vat_json_init_object(node);
1671 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1672 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1673 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1674 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1675 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1676 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1677 vat_json_object_add_ip6(node, "ip6_src", ip6);
1678 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1679 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1680 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1681 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1682 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1683 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1684 vat_json_object_add_uint(node, "flags", mp->flags);
1685 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1686 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1689 static void vl_api_map_domain_details_t_handler
1690 (vl_api_map_domain_details_t * mp)
1692 vat_main_t * vam = &vat_main;
1694 if (mp->is_translation) {
1695 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1696 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1697 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1698 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1700 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1701 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1702 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1703 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1705 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1706 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1709 static void vl_api_map_rule_details_t_handler_json
1710 (vl_api_map_rule_details_t * mp)
1712 struct in6_addr ip6;
1713 vat_json_node_t * node = NULL;
1714 vat_main_t * vam = &vat_main;
1716 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1717 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1718 vat_json_init_array(&vam->json_tree);
1721 node = vat_json_array_add(&vam->json_tree);
1722 vat_json_init_object(node);
1724 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1725 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1726 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1729 static void vl_api_map_rule_details_t_handler
1730 (vl_api_map_rule_details_t * mp)
1732 vat_main_t * vam = &vat_main;
1733 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1734 format_ip6_address, mp->ip6_dst);
1737 static void vl_api_dhcp_compl_event_t_handler
1738 (vl_api_dhcp_compl_event_t * mp)
1740 vat_main_t * vam = &vat_main;
1741 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1742 "router_addr %U host_mac %U\n",
1743 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1744 format_ip4_address, &mp->host_address,
1745 format_ip4_address, &mp->router_address,
1746 format_ethernet_address, mp->host_mac);
1749 static void vl_api_dhcp_compl_event_t_handler_json
1750 (vl_api_dhcp_compl_event_t * mp)
1752 /* JSON output not supported */
1755 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1758 vat_main_t * vam = &vat_main;
1759 static u64 default_counter = 0;
1761 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1762 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1763 sw_if_index, default_counter);
1764 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1767 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1768 interface_counter_t counter)
1770 vat_main_t * vam = &vat_main;
1771 static interface_counter_t default_counter = {0, };
1773 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1774 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1775 sw_if_index, default_counter);
1776 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1779 static void vl_api_vnet_interface_counters_t_handler
1780 (vl_api_vnet_interface_counters_t *mp)
1785 static void vl_api_vnet_interface_counters_t_handler_json
1786 (vl_api_vnet_interface_counters_t *mp)
1788 interface_counter_t counter;
1793 u32 first_sw_if_index;
1796 count = ntohl(mp->count);
1797 first_sw_if_index = ntohl(mp->first_sw_if_index);
1799 if (!mp->is_combined) {
1800 v_packets = (u64*)&mp->data;
1801 for (i = 0; i < count; i++) {
1802 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1803 set_simple_interface_counter(mp->vnet_counter_type,
1804 first_sw_if_index + i, packets);
1808 v = (vlib_counter_t*)&mp->data;
1809 for (i = 0; i < count; i++) {
1810 counter.packets = clib_net_to_host_u64(
1811 clib_mem_unaligned(&v->packets, u64));
1812 counter.bytes = clib_net_to_host_u64(
1813 clib_mem_unaligned(&v->bytes, u64));
1814 set_combined_interface_counter(mp->vnet_counter_type,
1815 first_sw_if_index + i, counter);
1821 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1823 vat_main_t * vam = &vat_main;
1826 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1827 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1834 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1836 vat_main_t * vam = &vat_main;
1839 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1840 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1847 static void vl_api_vnet_ip4_fib_counters_t_handler
1848 (vl_api_vnet_ip4_fib_counters_t *mp)
1853 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1854 (vl_api_vnet_ip4_fib_counters_t *mp)
1856 vat_main_t * vam = &vat_main;
1857 vl_api_ip4_fib_counter_t *v;
1858 ip4_fib_counter_t *counter;
1865 vrf_id = ntohl(mp->vrf_id);
1866 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1867 if (~0 == vrf_index) {
1868 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1869 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1870 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1871 vec_validate(vam->ip4_fib_counters, vrf_index);
1872 vam->ip4_fib_counters[vrf_index] = NULL;
1875 vec_free(vam->ip4_fib_counters[vrf_index]);
1876 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1877 count = ntohl(mp->count);
1878 for (i = 0; i < count; i++) {
1879 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1880 counter = &vam->ip4_fib_counters[vrf_index][i];
1881 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1882 counter->address = ip4;
1883 counter->address_length = v->address_length;
1884 counter->packets = clib_net_to_host_u64(v->packets);
1885 counter->bytes = clib_net_to_host_u64(v->bytes);
1890 static void vl_api_vnet_ip6_fib_counters_t_handler
1891 (vl_api_vnet_ip6_fib_counters_t *mp)
1896 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1897 (vl_api_vnet_ip6_fib_counters_t *mp)
1899 vat_main_t * vam = &vat_main;
1900 vl_api_ip6_fib_counter_t *v;
1901 ip6_fib_counter_t *counter;
1902 struct in6_addr ip6;
1908 vrf_id = ntohl(mp->vrf_id);
1909 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1910 if (~0 == vrf_index) {
1911 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1912 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1913 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1914 vec_validate(vam->ip6_fib_counters, vrf_index);
1915 vam->ip6_fib_counters[vrf_index] = NULL;
1918 vec_free(vam->ip6_fib_counters[vrf_index]);
1919 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1920 count = ntohl(mp->count);
1921 for (i = 0; i < count; i++) {
1922 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1923 counter = &vam->ip6_fib_counters[vrf_index][i];
1924 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1925 counter->address = ip6;
1926 counter->address_length = v->address_length;
1927 counter->packets = clib_net_to_host_u64(v->packets);
1928 counter->bytes = clib_net_to_host_u64(v->bytes);
1933 static void vl_api_get_first_msg_id_reply_t_handler
1934 (vl_api_get_first_msg_id_reply_t * mp)
1936 vat_main_t * vam = &vat_main;
1937 i32 retval = ntohl(mp->retval);
1939 if (vam->async_mode) {
1940 vam->async_errors += (retval < 0);
1942 vam->retval = retval;
1943 vam->result_ready = 1;
1946 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1950 static void vl_api_get_first_msg_id_reply_t_handler_json
1951 (vl_api_get_first_msg_id_reply_t * mp)
1953 vat_main_t * vam = &vat_main;
1954 vat_json_node_t node;
1956 vat_json_init_object(&node);
1957 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1958 vat_json_object_add_uint(&node, "first_msg_id",
1959 (uint) ntohs(mp->first_msg_id));
1961 vat_json_print(vam->ofp, &node);
1962 vat_json_free(&node);
1964 vam->retval = ntohl(mp->retval);
1965 vam->result_ready = 1;
1968 static void vl_api_get_node_graph_reply_t_handler
1969 (vl_api_get_node_graph_reply_t * mp)
1971 vat_main_t * vam = &vat_main;
1972 api_main_t * am = &api_main;
1973 i32 retval = ntohl(mp->retval);
1974 u8 * pvt_copy, * reply;
1979 if (vam->async_mode) {
1980 vam->async_errors += (retval < 0);
1982 vam->retval = retval;
1983 vam->result_ready = 1;
1986 /* "Should never happen..." */
1990 reply = (u8 *)(mp->reply_in_shmem);
1991 pvt_copy = vec_dup (reply);
1993 /* Toss the shared-memory original... */
1994 pthread_mutex_lock (&am->vlib_rp->mutex);
1995 oldheap = svm_push_data_heap (am->vlib_rp);
1999 svm_pop_heap (oldheap);
2000 pthread_mutex_unlock (&am->vlib_rp->mutex);
2002 if (vam->graph_nodes) {
2003 hash_free (vam->graph_node_index_by_name);
2005 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
2006 node = vam->graph_nodes[i];
2007 vec_free (node->name);
2008 vec_free (node->next_nodes);
2011 vec_free(vam->graph_nodes);
2014 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
2015 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2016 vec_free (pvt_copy);
2018 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
2019 node = vam->graph_nodes[i];
2020 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2024 static void vl_api_get_node_graph_reply_t_handler_json
2025 (vl_api_get_node_graph_reply_t * mp)
2027 vat_main_t * vam = &vat_main;
2028 api_main_t * am = &api_main;
2030 vat_json_node_t node;
2033 /* $$$$ make this real? */
2034 vat_json_init_object(&node);
2035 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
2036 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
2038 reply = (u8 *)(mp->reply_in_shmem);
2040 /* Toss the shared-memory original... */
2041 pthread_mutex_lock (&am->vlib_rp->mutex);
2042 oldheap = svm_push_data_heap (am->vlib_rp);
2046 svm_pop_heap (oldheap);
2047 pthread_mutex_unlock (&am->vlib_rp->mutex);
2049 vat_json_print(vam->ofp, &node);
2050 vat_json_free(&node);
2052 vam->retval = ntohl(mp->retval);
2053 vam->result_ready = 1;
2057 vl_api_lisp_locator_details_t_handler (
2058 vl_api_lisp_locator_details_t *mp)
2060 vat_main_t *vam = &vat_main;
2064 memset(&loc, 0, sizeof(loc));
2065 if (vam->noprint_msg) {
2066 loc.local = mp->local;
2067 loc.priority = mp->priority;
2068 loc.weight = mp->weight;
2070 loc.sw_if_index = ntohl(mp->sw_if_index);
2072 loc.is_ipv6 = mp->is_ipv6;
2073 clib_memcpy(loc.ip_address, mp->ip_address, sizeof(loc.ip_address));
2075 vec_add1(vam->locator_msg, loc);
2078 tmp_str = format(tmp_str, "%=16d%=16d%=16d\n",
2079 ntohl(mp->sw_if_index),
2083 tmp_str = format(tmp_str, "%=16U%=16d%=16d\n",
2084 mp->is_ipv6 ? format_ip6_address :
2091 fformat(vam->ofp, "%s", tmp_str);
2098 vl_api_lisp_locator_details_t_handler_json (
2099 vl_api_lisp_locator_details_t *mp)
2101 vat_main_t *vam = &vat_main;
2102 vat_json_node_t *node = NULL;
2104 struct in6_addr ip6;
2107 memset(&loc, 0, sizeof(loc));
2108 if (vam->noprint_msg) {
2109 loc.local = mp->local;
2110 loc.priority = mp->priority;
2111 loc.weight = mp->weight;
2113 loc.sw_if_index = ntohl(mp->sw_if_index);
2115 loc.is_ipv6 = mp->is_ipv6;
2116 clib_memcpy(loc.ip_address, mp->ip_address, sizeof(loc.ip_address));
2118 vec_add1(vam->locator_msg, loc);
2122 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2123 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2124 vat_json_init_array(&vam->json_tree);
2126 node = vat_json_array_add(&vam->json_tree);
2128 vat_json_init_object(node);
2131 vat_json_object_add_uint(node, "locator_index", ntohl(mp->sw_if_index));
2134 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2135 vat_json_object_add_ip6(node, "locator", ip6);
2137 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2138 vat_json_object_add_ip4(node, "locator", ip4);
2141 vat_json_object_add_uint(node, "priority", mp->priority);
2142 vat_json_object_add_uint(node, "weight", mp->weight);
2146 vl_api_lisp_locator_set_details_t_handler (
2147 vl_api_lisp_locator_set_details_t *mp)
2149 vat_main_t *vam = &vat_main;
2150 locator_set_msg_t ls;
2152 ls.locator_set_index = ntohl(mp->locator_set_index);
2153 ls.locator_set_name = format(0, "%s", mp->locator_set_name);
2154 vec_add1(vam->locator_set_msg, ls);
2158 vl_api_lisp_locator_set_details_t_handler_json (
2159 vl_api_lisp_locator_set_details_t *mp)
2161 vat_main_t *vam = &vat_main;
2162 locator_set_msg_t ls;
2164 ls.locator_set_index = ntohl(mp->locator_set_index);
2165 ls.locator_set_name = format(0, "%s", mp->locator_set_name);
2166 vec_add1(vam->locator_set_msg, ls);
2170 vl_api_lisp_local_eid_table_details_t_handler (
2171 vl_api_lisp_local_eid_table_details_t *mp)
2173 vat_main_t *vam = &vat_main;
2175 u8 * (*format_eid)(u8 *, va_list *) = 0;
2177 switch (mp->eid_type)
2179 case 0: format_eid = format_ip4_address; break;
2180 case 1: format_eid = format_ip6_address; break;
2181 case 2: format_eid = format_ethernet_address; break;
2183 errmsg ("unknown EID type %d!", mp->eid_type);
2187 prefix = format(0, "[%d] %U/%d",
2188 clib_net_to_host_u32 (mp->vni),
2189 format_eid, mp->eid, mp->eid_prefix_len);
2191 fformat(vam->ofp, "%=20s%=30s\n",
2192 mp->locator_set_name, prefix);
2198 vl_api_lisp_eid_table_map_details_t_handler (
2199 vl_api_lisp_eid_table_map_details_t *mp)
2201 vat_main_t *vam = &vat_main;
2203 u8 * line = format(0, "%=10d%=10d",
2204 clib_net_to_host_u32 (mp->vni),
2205 clib_net_to_host_u32 (mp->vrf));
2206 fformat(vam->ofp, "%v\n", line);
2211 vl_api_lisp_eid_table_map_details_t_handler_json (
2212 vl_api_lisp_eid_table_map_details_t *mp)
2214 vat_main_t *vam = &vat_main;
2215 vat_json_node_t *node = NULL;
2217 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2218 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2219 vat_json_init_array(&vam->json_tree);
2221 node = vat_json_array_add(&vam->json_tree);
2222 vat_json_init_object(node);
2223 vat_json_object_add_uint(node, "vrf", clib_net_to_host_u32 (mp->vrf));
2224 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2228 vl_api_lisp_local_eid_table_details_t_handler_json (
2229 vl_api_lisp_local_eid_table_details_t *mp)
2231 vat_main_t *vam = &vat_main;
2232 vat_json_node_t *node = NULL;
2233 struct in6_addr ip6;
2237 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2238 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2239 vat_json_init_array(&vam->json_tree);
2241 node = vat_json_array_add(&vam->json_tree);
2243 vat_json_init_object(node);
2244 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
2245 switch (mp->eid_type)
2248 clib_memcpy(&ip4, mp->eid, sizeof(ip4));
2249 vat_json_object_add_ip4(node, "eid", ip4);
2250 vat_json_object_add_uint(node, "eid-prefix-len", mp->eid_prefix_len);
2253 clib_memcpy(&ip6, mp->eid, sizeof(ip6));
2254 vat_json_object_add_ip6(node, "eid", ip6);
2255 vat_json_object_add_uint(node, "eid-prefix-len", mp->eid_prefix_len);
2258 s = format (0, "%U", format_ethernet_address, mp->eid);
2260 vat_json_object_add_string_copy(node, "eid", s);
2264 errmsg ("unknown EID type %d!", mp->eid_type);
2267 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2271 format_decap_next (u8 * s, va_list * args)
2273 u32 next_index = va_arg (*args, u32);
2277 case LISP_GPE_INPUT_NEXT_DROP:
2278 return format (s, "drop");
2279 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2280 return format (s, "ip4");
2281 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2282 return format (s, "ip6");
2284 return format (s, "unknown %d", next_index);
2290 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2292 vat_main_t *vam = &vat_main;
2294 u8 *flag_str = NULL;
2296 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2298 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2299 foreach_lisp_gpe_flag_bit;
2302 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2303 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2305 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2307 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2309 ntohl(mp->encap_fib_id),
2310 ntohl(mp->decap_fib_id),
2311 format_decap_next, ntohl(mp->dcap_next),
2323 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2324 vl_api_lisp_gpe_tunnel_details_t *mp)
2326 vat_main_t *vam = &vat_main;
2327 vat_json_node_t *node = NULL;
2328 struct in6_addr ip6;
2332 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2334 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2335 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2336 vat_json_init_array(&vam->json_tree);
2338 node = vat_json_array_add(&vam->json_tree);
2340 vat_json_init_object(node);
2341 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2343 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2344 vat_json_object_add_ip6(node, "source address", ip6);
2345 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2346 vat_json_object_add_ip6(node, "destination address", ip6);
2348 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2349 vat_json_object_add_ip4(node, "source address", ip4);
2350 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2351 vat_json_object_add_ip4(node, "destination address", ip4);
2353 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2354 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2355 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2356 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2357 vat_json_object_add_uint(node, "flags", mp->flags);
2358 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2359 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2360 vat_json_object_add_uint(node, "res", mp->res);
2361 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2363 vec_free(next_decap_str);
2367 vl_api_lisp_map_resolver_details_t_handler (
2368 vl_api_lisp_map_resolver_details_t *mp)
2370 vat_main_t *vam = &vat_main;
2372 fformat(vam->ofp, "%=20U\n",
2373 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2378 vl_api_lisp_map_resolver_details_t_handler_json (
2379 vl_api_lisp_map_resolver_details_t *mp)
2381 vat_main_t *vam = &vat_main;
2382 vat_json_node_t *node = NULL;
2383 struct in6_addr ip6;
2386 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2387 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2388 vat_json_init_array(&vam->json_tree);
2390 node = vat_json_array_add(&vam->json_tree);
2392 vat_json_init_object(node);
2394 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2395 vat_json_object_add_ip6(node, "map resolver", ip6);
2397 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2398 vat_json_object_add_ip4(node, "map resolver", ip4);
2403 vl_api_show_lisp_status_reply_t_handler
2404 (vl_api_show_lisp_status_reply_t * mp)
2406 vat_main_t *vam = &vat_main;
2407 i32 retval = ntohl(mp->retval);
2410 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2411 mp->feature_status ? "enabled" : "disabled",
2412 mp->gpe_status ? "enabled" : "disabled");
2415 vam->retval = retval;
2416 vam->result_ready = 1;
2420 vl_api_show_lisp_status_reply_t_handler_json
2421 (vl_api_show_lisp_status_reply_t *mp)
2423 vat_main_t *vam = &vat_main;
2424 vat_json_node_t node;
2425 u8 * gpe_status = NULL;
2426 u8 * feature_status = NULL;
2428 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2429 feature_status = format (0, "%s",
2430 mp->feature_status ? "enabled" : "disabled");
2431 vec_add1 (gpe_status, 0);
2432 vec_add1 (feature_status, 0);
2434 vat_json_init_object(&node);
2435 vat_json_object_add_string_copy(&node, "gpe_status", gpe_status);
2436 vat_json_object_add_string_copy(&node, "feature_status", feature_status);
2438 vec_free (gpe_status);
2439 vec_free (feature_status);
2441 vat_json_print(vam->ofp, &node);
2442 vat_json_free(&node);
2444 vam->retval = ntohl(mp->retval);
2445 vam->result_ready = 1;
2449 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2450 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2452 vat_main_t * vam = &vat_main;
2453 i32 retval = ntohl(mp->retval);
2456 fformat(vam->ofp, "%=20s\n",
2457 mp->locator_set_name);
2460 vam->retval = retval;
2461 vam->result_ready = 1;
2465 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2466 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2468 vat_main_t * vam = &vat_main;
2469 vat_json_node_t * node = NULL;
2471 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2472 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2473 vat_json_init_array(&vam->json_tree);
2475 node = vat_json_array_add(&vam->json_tree);
2477 vat_json_init_object(node);
2478 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2480 vat_json_print(vam->ofp, node);
2481 vat_json_free(node);
2483 vam->retval = ntohl(mp->retval);
2484 vam->result_ready = 1;
2488 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2490 vat_main_t *vam = &vat_main;
2491 i32 retval = ntohl(mp->retval);
2494 fformat(vam->ofp, "%-20s%-16s\n",
2495 mp->status ? "enabled" : "disabled",
2496 mp->status ? (char *) mp->locator_set_name : "");
2499 vam->retval = retval;
2500 vam->result_ready = 1;
2504 vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t * mp)
2506 vat_main_t *vam = &vat_main;
2507 vat_json_node_t node;
2510 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2511 vec_add1 (status, 0);
2513 vat_json_init_object(&node);
2514 vat_json_object_add_string_copy(&node, "status", status);
2516 vat_json_object_add_string_copy(&node, "locator_set", mp->locator_set_name);
2521 vat_json_print(vam->ofp, &node);
2522 vat_json_free(&node);
2524 vam->retval = ntohl(mp->retval);
2525 vam->result_ready = 1;
2528 static u8 * format_policer_type (u8 * s, va_list * va)
2530 u32 i = va_arg (*va, u32);
2532 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2533 s = format (s, "1r2c");
2534 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2535 s = format (s, "1r3c");
2536 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2537 s = format (s, "2r3c-2698");
2538 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2539 s = format (s, "2r3c-4115");
2540 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2541 s = format (s, "2r3c-mef5cf1");
2543 s = format (s, "ILLEGAL");
2547 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2549 u32 i = va_arg (*va, u32);
2551 if (i == SSE2_QOS_RATE_KBPS)
2552 s = format (s, "kbps");
2553 else if (i == SSE2_QOS_RATE_PPS)
2554 s = format(s, "pps");
2556 s = format (s, "ILLEGAL");
2560 static u8 * format_policer_round_type (u8 * s, va_list * va)
2562 u32 i = va_arg (*va, u32);
2564 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2565 s = format(s, "closest");
2566 else if (i == SSE2_QOS_ROUND_TO_UP)
2567 s = format (s, "up");
2568 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2569 s = format (s, "down");
2571 s = format (s, "ILLEGAL");
2575 static u8 * format_policer_action_type (u8 * s, va_list * va)
2577 u32 i = va_arg (*va, u32);
2579 if (i == SSE2_QOS_ACTION_DROP)
2580 s = format (s, "drop");
2581 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2582 s = format (s, "transmit");
2583 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2584 s = format (s, "mark-and-transmit");
2586 s = format (s, "ILLEGAL");
2590 static u8 * format_dscp (u8 * s, va_list * va)
2592 u32 i = va_arg (*va, u32);
2596 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2600 return format (s, "ILLEGAL");
2602 s = format (s, "%s", t);
2606 static void vl_api_policer_details_t_handler
2607 (vl_api_policer_details_t * mp)
2609 vat_main_t * vam = &vat_main;
2610 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2612 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2613 conform_dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2615 conform_dscp_str = format(0, "");
2617 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2618 exceed_dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2620 exceed_dscp_str = format(0, "");
2622 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2623 violate_dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2625 violate_dscp_str = format(0, "");
2627 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2628 "rate type %U, round type %U, %s rate, %s color-aware, "
2629 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2630 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2631 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2633 format_policer_type, mp->type,
2636 clib_net_to_host_u64(mp->cb),
2637 clib_net_to_host_u64(mp->eb),
2638 format_policer_rate_type, mp->rate_type,
2639 format_policer_round_type, mp->round_type,
2640 mp->single_rate ? "single" : "dual",
2641 mp->color_aware ? "is" : "not",
2642 ntohl(mp->cir_tokens_per_period),
2643 ntohl(mp->pir_tokens_per_period),
2645 ntohl(mp->current_limit),
2646 ntohl(mp->current_bucket),
2647 ntohl(mp->extended_limit),
2648 ntohl(mp->extended_bucket),
2649 clib_net_to_host_u64(mp->last_update_time),
2650 format_policer_action_type, mp->conform_action_type,
2652 format_policer_action_type, mp->exceed_action_type,
2654 format_policer_action_type, mp->violate_action_type,
2657 vec_free(conform_dscp_str);
2658 vec_free(exceed_dscp_str);
2659 vec_free(violate_dscp_str);
2662 static void vl_api_policer_details_t_handler_json
2663 (vl_api_policer_details_t * mp)
2665 vat_main_t * vam = &vat_main;
2666 vat_json_node_t *node;
2667 u8 *rate_type_str, *round_type_str, *type_str;
2668 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2670 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2671 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2672 type_str = format(0, "%U", format_policer_type, mp->type);
2673 conform_action_str = format(0, "%U", format_policer_action_type,
2674 mp->conform_action_type);
2675 exceed_action_str = format(0, "%U", format_policer_action_type,
2676 mp->exceed_action_type);
2677 violate_action_str = format(0, "%U", format_policer_action_type,
2678 mp->violate_action_type);
2680 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2681 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2682 vat_json_init_array(&vam->json_tree);
2684 node = vat_json_array_add(&vam->json_tree);
2686 vat_json_init_object(node);
2687 vat_json_object_add_string_copy(node, "name", mp->name);
2688 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2689 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2690 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2691 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2692 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2693 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2694 vat_json_object_add_string_copy(node, "type", type_str);
2695 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2696 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2697 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2698 vat_json_object_add_uint(node, "cir_tokens_per_period",
2699 ntohl(mp->cir_tokens_per_period));
2700 vat_json_object_add_uint(node, "eir_tokens_per_period",
2701 ntohl(mp->pir_tokens_per_period));
2702 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2703 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2704 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2705 vat_json_object_add_uint(node, "extended_bucket",
2706 ntohl(mp->extended_bucket));
2707 vat_json_object_add_uint(node, "last_update_time",
2708 ntohl(mp->last_update_time));
2709 vat_json_object_add_string_copy(node, "conform_action", conform_action_str);
2710 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2711 u8 *dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2712 vat_json_object_add_string_copy(node, "conform_dscp", dscp_str);
2715 vat_json_object_add_string_copy(node, "exceed_action", exceed_action_str);
2716 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2717 u8 *dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2718 vat_json_object_add_string_copy(node, "exceed_dscp", dscp_str);
2721 vat_json_object_add_string_copy(node, "violate_action", violate_action_str);
2722 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2723 u8 *dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2724 vat_json_object_add_string_copy(node, "violate_dscp", dscp_str);
2728 vec_free(rate_type_str);
2729 vec_free(round_type_str);
2731 vec_free(conform_action_str);
2732 vec_free(exceed_action_str);
2733 vec_free(violate_action_str);
2736 static void vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * mp)
2738 vat_main_t * vam = &vat_main;
2739 int i, count = ntohl(mp->count);
2742 fformat (vam->ofp, "classify table ids (%d) : ", count);
2743 for (i = 0; i < count; i++)
2745 fformat (vam->ofp, "%d", ntohl(mp->ids[i]));
2746 fformat (vam->ofp, (i<count-1)?",":"\n");
2748 vam->retval = ntohl(mp->retval);
2749 vam->result_ready = 1;
2752 static void vl_api_classify_table_ids_reply_t_handler_json (vl_api_classify_table_ids_reply_t * mp)
2754 vat_main_t * vam = &vat_main;
2755 int i, count = ntohl(mp->count);
2758 vat_json_node_t node;
2760 vat_json_init_object(&node);
2761 for (i = 0; i < count; i++)
2763 vat_json_object_add_uint(&node, "table_id", ntohl(mp->ids[i]));
2765 vat_json_print(vam->ofp, &node);
2766 vat_json_free(&node);
2768 vam->retval = ntohl(mp->retval);
2769 vam->result_ready = 1;
2772 static void vl_api_classify_table_by_interface_reply_t_handler (vl_api_classify_table_by_interface_reply_t * mp)
2774 vat_main_t * vam = &vat_main;
2777 table_id = ntohl(mp->l2_table_id);
2779 fformat (vam->ofp, "l2 table id : %d\n", table_id);
2781 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
2782 table_id = ntohl(mp->ip4_table_id);
2784 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
2786 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
2787 table_id = ntohl(mp->ip6_table_id);
2789 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
2791 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
2792 vam->retval = ntohl(mp->retval);
2793 vam->result_ready = 1;
2796 static void vl_api_classify_table_by_interface_reply_t_handler_json (vl_api_classify_table_by_interface_reply_t * mp)
2798 vat_main_t * vam = &vat_main;
2799 vat_json_node_t node;
2801 vat_json_init_object(&node);
2803 vat_json_object_add_int(&node, "l2_table_id", ntohl(mp->l2_table_id));
2804 vat_json_object_add_int(&node, "ip4_table_id", ntohl(mp->ip4_table_id));
2805 vat_json_object_add_int(&node, "ip6_table_id", ntohl(mp->ip6_table_id));
2807 vat_json_print(vam->ofp, &node);
2808 vat_json_free(&node);
2810 vam->retval = ntohl(mp->retval);
2811 vam->result_ready = 1;
2814 static void vl_api_policer_add_del_reply_t_handler
2815 (vl_api_policer_add_del_reply_t * mp)
2817 vat_main_t * vam = &vat_main;
2818 i32 retval = ntohl(mp->retval);
2819 if (vam->async_mode) {
2820 vam->async_errors += (retval < 0);
2822 vam->retval = retval;
2823 vam->result_ready = 1;
2824 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2826 * Note: this is just barely thread-safe, depends on
2827 * the main thread spinning waiting for an answer...
2829 errmsg ("policer index %d\n", ntohl(mp->policer_index));
2833 static void vl_api_policer_add_del_reply_t_handler_json
2834 (vl_api_policer_add_del_reply_t * mp)
2836 vat_main_t * vam = &vat_main;
2837 vat_json_node_t node;
2839 vat_json_init_object(&node);
2840 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
2841 vat_json_object_add_uint(&node, "policer_index", ntohl(mp->policer_index));
2843 vat_json_print(vam->ofp, &node);
2844 vat_json_free(&node);
2846 vam->retval = ntohl(mp->retval);
2847 vam->result_ready = 1;
2850 /* Format hex dump. */
2851 u8 * format_hex_bytes (u8 * s, va_list * va)
2853 u8 * bytes = va_arg (*va, u8 *);
2854 int n_bytes = va_arg (*va, int);
2857 /* Print short or long form depending on byte count. */
2858 uword short_form = n_bytes <= 32;
2859 uword indent = format_get_indent (s);
2864 for (i = 0; i < n_bytes; i++)
2866 if (! short_form && (i % 32) == 0)
2867 s = format (s, "%08x: ", i);
2868 s = format (s, "%02x", bytes[i]);
2869 if (! short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2870 s = format (s, "\n%U", format_white_space, indent);
2876 static void vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t * mp)
2878 vat_main_t * vam = &vat_main;
2879 i32 retval = ntohl(mp->retval);
2881 fformat (vam->ofp, "classify table info :\n");
2882 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n", ntohl(mp->active_sessions), ntohl(mp->next_table_index), ntohl(mp->miss_next_index));
2883 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n", ntohl(mp->nbuckets), ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
2884 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask, ntohl(mp->mask_length));
2886 vam->retval = retval;
2887 vam->result_ready = 1;
2890 static void vl_api_classify_table_info_reply_t_handler_json (vl_api_classify_table_info_reply_t * mp)
2892 vat_main_t * vam = &vat_main;
2893 vat_json_node_t node;
2895 i32 retval = ntohl(mp->retval);
2897 vat_json_init_object(&node);
2899 vat_json_object_add_int(&node, "sessions", ntohl(mp->active_sessions));
2900 vat_json_object_add_int(&node, "nexttbl", ntohl(mp->next_table_index));
2901 vat_json_object_add_int(&node, "nextnode", ntohl(mp->miss_next_index));
2902 vat_json_object_add_int(&node, "nbuckets", ntohl(mp->nbuckets));
2903 vat_json_object_add_int(&node, "skip", ntohl(mp->skip_n_vectors));
2904 vat_json_object_add_int(&node, "match", ntohl(mp->match_n_vectors));
2905 u8 * s = format (0, "%U%c",format_hex_bytes, mp->mask, ntohl(mp->mask_length), 0);
2906 vat_json_object_add_string_copy(&node, "mask", s);
2908 vat_json_print(vam->ofp, &node);
2909 vat_json_free(&node);
2911 vam->retval = ntohl(mp->retval);
2912 vam->result_ready = 1;
2915 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
2917 vat_main_t * vam = &vat_main;
2919 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ", ntohl(mp->hit_next_index), ntohl(mp->advance), ntohl(mp->opaque_index));
2920 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match, ntohl(mp->match_length));
2923 static void vl_api_classify_session_details_t_handler_json (vl_api_classify_session_details_t * mp)
2925 vat_main_t * vam = &vat_main;
2926 vat_json_node_t *node = NULL;
2928 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2929 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2930 vat_json_init_array(&vam->json_tree);
2932 node = vat_json_array_add(&vam->json_tree);
2934 vat_json_init_object(node);
2935 vat_json_object_add_int(node, "next_index", ntohl(mp->hit_next_index));
2936 vat_json_object_add_int(node, "advance", ntohl(mp->advance));
2937 vat_json_object_add_int(node, "opaque", ntohl(mp->opaque_index));
2938 u8 * s = format (0, "%U%c",format_hex_bytes, mp->match, ntohl(mp->match_length), 0);
2939 vat_json_object_add_string_copy(node, "match", s);
2942 static void vl_api_pg_create_interface_reply_t_handler
2943 (vl_api_pg_create_interface_reply_t * mp)
2945 vat_main_t * vam = &vat_main;
2947 vam->retval = ntohl(mp->retval);
2948 vam->result_ready = 1;
2951 static void vl_api_pg_create_interface_reply_t_handler_json
2952 (vl_api_pg_create_interface_reply_t * mp)
2954 vat_main_t * vam = &vat_main;
2955 vat_json_node_t node;
2957 i32 retval = ntohl(mp->retval);
2959 vat_json_init_object(&node);
2961 vat_json_object_add_int(&node, "sw_if_index", ntohl(mp->sw_if_index));
2963 vat_json_print(vam->ofp, &node);
2964 vat_json_free(&node);
2966 vam->retval = ntohl(mp->retval);
2967 vam->result_ready = 1;
2970 static void vl_api_policer_classify_details_t_handler
2971 (vl_api_policer_classify_details_t * mp)
2973 vat_main_t * vam = &vat_main;
2975 fformat (vam->ofp, "%10d%20d\n", ntohl(mp->sw_if_index),
2976 ntohl(mp->table_index));
2979 static void vl_api_policer_classify_details_t_handler_json
2980 (vl_api_policer_classify_details_t * mp)
2982 vat_main_t * vam = &vat_main;
2983 vat_json_node_t * node;
2985 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2986 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2987 vat_json_init_array(&vam->json_tree);
2989 node = vat_json_array_add(&vam->json_tree);
2991 vat_json_init_object(node);
2992 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
2993 vat_json_object_add_uint(node, "table_index", ntohl(mp->table_index));
2997 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2998 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2999 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
3000 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
3003 * Generate boilerplate reply handlers, which
3004 * dig the return value out of the xxx_reply_t API message,
3005 * stick it into vam->retval, and set vam->result_ready
3007 * Could also do this by pointing N message decode slots at
3008 * a single function, but that could break in subtle ways.
3011 #define foreach_standard_reply_retval_handler \
3012 _(sw_interface_set_flags_reply) \
3013 _(sw_interface_add_del_address_reply) \
3014 _(sw_interface_set_table_reply) \
3015 _(sw_interface_set_vpath_reply) \
3016 _(sw_interface_set_l2_bridge_reply) \
3017 _(bridge_domain_add_del_reply) \
3018 _(sw_interface_set_l2_xconnect_reply) \
3019 _(l2fib_add_del_reply) \
3020 _(ip_add_del_route_reply) \
3021 _(proxy_arp_add_del_reply) \
3022 _(proxy_arp_intfc_enable_disable_reply) \
3023 _(mpls_add_del_encap_reply) \
3024 _(mpls_add_del_decap_reply) \
3025 _(mpls_ethernet_add_del_tunnel_2_reply) \
3026 _(sw_interface_set_unnumbered_reply) \
3027 _(ip_neighbor_add_del_reply) \
3028 _(reset_vrf_reply) \
3029 _(oam_add_del_reply) \
3030 _(reset_fib_reply) \
3031 _(dhcp_proxy_config_reply) \
3032 _(dhcp_proxy_config_2_reply) \
3033 _(dhcp_proxy_set_vss_reply) \
3034 _(dhcp_client_config_reply) \
3035 _(set_ip_flow_hash_reply) \
3036 _(sw_interface_ip6_enable_disable_reply) \
3037 _(sw_interface_ip6_set_link_local_address_reply) \
3038 _(sw_interface_ip6nd_ra_prefix_reply) \
3039 _(sw_interface_ip6nd_ra_config_reply) \
3040 _(set_arp_neighbor_limit_reply) \
3041 _(l2_patch_add_del_reply) \
3042 _(sr_tunnel_add_del_reply) \
3043 _(sr_policy_add_del_reply) \
3044 _(sr_multicast_map_add_del_reply) \
3045 _(classify_add_del_session_reply) \
3046 _(classify_set_interface_ip_table_reply) \
3047 _(classify_set_interface_l2_tables_reply) \
3048 _(l2tpv3_set_tunnel_cookies_reply) \
3049 _(l2tpv3_interface_enable_disable_reply) \
3050 _(l2tpv3_set_lookup_key_reply) \
3051 _(l2_fib_clear_table_reply) \
3052 _(l2_interface_efp_filter_reply) \
3053 _(l2_interface_vlan_tag_rewrite_reply) \
3054 _(modify_vhost_user_if_reply) \
3055 _(delete_vhost_user_if_reply) \
3056 _(want_ip4_arp_events_reply) \
3057 _(input_acl_set_interface_reply) \
3058 _(ipsec_spd_add_del_reply) \
3059 _(ipsec_interface_add_del_spd_reply) \
3060 _(ipsec_spd_add_del_entry_reply) \
3061 _(ipsec_sad_add_del_entry_reply) \
3062 _(ipsec_sa_set_key_reply) \
3063 _(ikev2_profile_add_del_reply) \
3064 _(ikev2_profile_set_auth_reply) \
3065 _(ikev2_profile_set_id_reply) \
3066 _(ikev2_profile_set_ts_reply) \
3067 _(ikev2_set_local_key_reply) \
3068 _(delete_loopback_reply) \
3069 _(bd_ip_mac_add_del_reply) \
3070 _(map_del_domain_reply) \
3071 _(map_add_del_rule_reply) \
3072 _(want_interface_events_reply) \
3073 _(want_stats_reply) \
3074 _(cop_interface_enable_disable_reply) \
3075 _(cop_whitelist_enable_disable_reply) \
3076 _(sw_interface_clear_stats_reply) \
3077 _(trace_profile_add_reply) \
3078 _(trace_profile_apply_reply) \
3079 _(trace_profile_del_reply) \
3080 _(lisp_add_del_locator_set_reply) \
3081 _(lisp_add_del_locator_reply) \
3082 _(lisp_add_del_local_eid_reply) \
3083 _(lisp_add_del_remote_mapping_reply) \
3084 _(lisp_add_del_adjacency_reply) \
3085 _(lisp_gpe_add_del_fwd_entry_reply) \
3086 _(lisp_add_del_map_resolver_reply) \
3087 _(lisp_gpe_enable_disable_reply) \
3088 _(lisp_gpe_add_del_iface_reply) \
3089 _(lisp_enable_disable_reply) \
3090 _(lisp_pitr_set_locator_set_reply) \
3091 _(lisp_add_del_map_request_itr_rlocs_reply) \
3092 _(lisp_eid_table_add_del_map_reply) \
3093 _(vxlan_gpe_add_del_tunnel_reply) \
3094 _(af_packet_delete_reply) \
3095 _(policer_classify_set_interface_reply) \
3096 _(netmap_create_reply) \
3097 _(netmap_delete_reply) \
3098 _(ipfix_enable_reply) \
3099 _(pg_capture_reply) \
3100 _(pg_enable_disable_reply)
3103 static void vl_api_##n##_t_handler \
3104 (vl_api_##n##_t * mp) \
3106 vat_main_t * vam = &vat_main; \
3107 i32 retval = ntohl(mp->retval); \
3108 if (vam->async_mode) { \
3109 vam->async_errors += (retval < 0); \
3111 vam->retval = retval; \
3112 vam->result_ready = 1; \
3115 foreach_standard_reply_retval_handler;
3119 static void vl_api_##n##_t_handler_json \
3120 (vl_api_##n##_t * mp) \
3122 vat_main_t * vam = &vat_main; \
3123 vat_json_node_t node; \
3124 vat_json_init_object(&node); \
3125 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3126 vat_json_print(vam->ofp, &node); \
3127 vam->retval = ntohl(mp->retval); \
3128 vam->result_ready = 1; \
3130 foreach_standard_reply_retval_handler;
3134 * Table of message reply handlers, must include boilerplate handlers
3138 #define foreach_vpe_api_reply_msg \
3139 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3140 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3141 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3142 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3143 _(CONTROL_PING_REPLY, control_ping_reply) \
3144 _(NOPRINT_CONTROL_PING_REPLY, noprint_control_ping_reply) \
3145 _(CLI_REPLY, cli_reply) \
3146 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3147 sw_interface_add_del_address_reply) \
3148 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3149 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3150 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3151 sw_interface_set_l2_xconnect_reply) \
3152 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3153 sw_interface_set_l2_bridge_reply) \
3154 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3155 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3156 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3157 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3158 _(L2_FLAGS_REPLY, l2_flags_reply) \
3159 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3160 _(TAP_CONNECT_REPLY, tap_connect_reply) \
3161 _(TAP_MODIFY_REPLY, tap_modify_reply) \
3162 _(TAP_DELETE_REPLY, tap_delete_reply) \
3163 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3164 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3165 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3166 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3167 proxy_arp_intfc_enable_disable_reply) \
3168 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3169 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3170 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3171 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3172 mpls_ethernet_add_del_tunnel_reply) \
3173 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3174 mpls_ethernet_add_del_tunnel_2_reply) \
3175 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3176 sw_interface_set_unnumbered_reply) \
3177 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3178 _(RESET_VRF_REPLY, reset_vrf_reply) \
3179 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3180 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3181 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3182 _(RESET_FIB_REPLY, reset_fib_reply) \
3183 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3184 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3185 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3186 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3187 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3188 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3189 sw_interface_ip6_enable_disable_reply) \
3190 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3191 sw_interface_ip6_set_link_local_address_reply) \
3192 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3193 sw_interface_ip6nd_ra_prefix_reply) \
3194 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3195 sw_interface_ip6nd_ra_config_reply) \
3196 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3197 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3198 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
3199 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3200 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
3201 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3202 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3203 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3204 classify_set_interface_ip_table_reply) \
3205 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3206 classify_set_interface_l2_tables_reply) \
3207 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3208 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3209 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3210 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3211 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3212 l2tpv3_interface_enable_disable_reply) \
3213 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3214 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3215 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3216 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3217 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3218 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
3219 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3220 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3221 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3222 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3223 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3224 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3225 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3226 _(SHOW_VERSION_REPLY, show_version_reply) \
3227 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
3228 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3229 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3230 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3231 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3232 _(IP4_ARP_EVENT, ip4_arp_event) \
3233 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3234 _(IP_ADDRESS_DETAILS, ip_address_details) \
3235 _(IP_DETAILS, ip_details) \
3236 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3237 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3238 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3239 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3240 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
3241 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3242 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3243 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3244 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3245 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
3246 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3247 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3248 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
3249 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3250 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3251 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3252 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3253 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
3254 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
3255 _(MAP_DOMAIN_DETAILS, map_domain_details) \
3256 _(MAP_RULE_DETAILS, map_rule_details) \
3257 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3258 _(WANT_STATS_REPLY, want_stats_reply) \
3259 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3260 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3261 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3262 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3263 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3264 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
3265 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
3266 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
3267 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3268 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3269 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
3270 _(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3271 _(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
3272 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3273 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
3274 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
3275 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
3276 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
3277 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
3278 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3279 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
3280 _(LISP_LOCATOR_DETAILS, lisp_locator_details) \
3281 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
3282 _(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
3283 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
3284 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
3285 _(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
3286 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3287 lisp_add_del_map_request_itr_rlocs_reply) \
3288 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3289 lisp_get_map_request_itr_rlocs_reply) \
3290 _(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
3291 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3292 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3293 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3294 _(POLICER_DETAILS, policer_details) \
3295 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3296 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3297 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
3298 _(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3299 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3300 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3301 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
3302 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3303 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3304 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3305 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3306 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3307 _(IPFIX_ENABLE_REPLY, ipfix_enable_reply) \
3308 _(IPFIX_DETAILS, ipfix_details) \
3309 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3310 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3311 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3312 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply)
3314 /* M: construct, but don't yet send a message */
3318 vam->result_ready = 0; \
3319 mp = vl_msg_api_alloc(sizeof(*mp)); \
3320 memset (mp, 0, sizeof (*mp)); \
3321 mp->_vl_msg_id = ntohs (VL_API_##T); \
3322 mp->client_index = vam->my_client_index; \
3327 vam->result_ready = 0; \
3328 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3329 memset (mp, 0, sizeof (*mp)); \
3330 mp->_vl_msg_id = ntohs (VL_API_##T); \
3331 mp->client_index = vam->my_client_index; \
3335 /* S: send a message */
3336 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3338 /* W: wait for results, with timeout */
3341 timeout = vat_time_now (vam) + 1.0; \
3343 while (vat_time_now (vam) < timeout) { \
3344 if (vam->result_ready == 1) { \
3345 return (vam->retval); \
3351 /* W2: wait for results, with timeout */
3354 timeout = vat_time_now (vam) + 1.0; \
3356 while (vat_time_now (vam) < timeout) { \
3357 if (vam->result_ready == 1) { \
3359 return (vam->retval); \
3365 /* W_L: wait for results, with timeout */
3368 timeout = vat_time_now (vam) + 1.0; \
3370 while (vat_time_now (vam) < timeout) { \
3371 if (vam->result_ready == 1) { \
3373 return (vam->retval); \
3376 vam->noprint_msg = 0; \
3386 #define STR_VTR_OP_CASE(op) \
3387 case L2_VTR_ ## op: \
3390 static const char *str_vtr_op(u32 vtr_op)
3393 STR_VTR_OP_CASE(DISABLED);
3394 STR_VTR_OP_CASE(PUSH_1);
3395 STR_VTR_OP_CASE(PUSH_2);
3396 STR_VTR_OP_CASE(POP_1);
3397 STR_VTR_OP_CASE(POP_2);
3398 STR_VTR_OP_CASE(TRANSLATE_1_1);
3399 STR_VTR_OP_CASE(TRANSLATE_1_2);
3400 STR_VTR_OP_CASE(TRANSLATE_2_1);
3401 STR_VTR_OP_CASE(TRANSLATE_2_2);
3407 static int dump_sub_interface_table (vat_main_t * vam)
3409 const sw_interface_subif_t * sub = NULL;
3411 if (vam->json_output) {
3412 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3417 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3418 "Interface", "sw_if_index",
3419 "sub id", "dot1ad", "tags", "outer id",
3420 "inner id", "exact", "default",
3421 "outer any", "inner any");
3423 vec_foreach (sub, vam->sw_if_subif_table) {
3425 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3426 sub->interface_name,
3428 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3429 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3430 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3431 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3432 if (sub->vtr_op != L2_VTR_DISABLED) {
3434 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3435 "tag1: %d tag2: %d ]\n",
3436 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
3437 sub->vtr_tag1, sub->vtr_tag2);
3444 static int name_sort_cmp (void * a1, void * a2)
3446 name_sort_t * n1 = a1;
3447 name_sort_t * n2 = a2;
3449 return strcmp ((char *)n1->name, (char *)n2->name);
3452 static int dump_interface_table (vat_main_t * vam)
3455 name_sort_t * nses = 0, * ns;
3457 if (vam->json_output) {
3458 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3462 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3464 vec_add2 (nses, ns, 1);
3465 ns->name = (u8 *)(p->key);
3466 ns->value = (u32) p->value[0];
3469 vec_sort_with_function (nses, name_sort_cmp);
3471 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3472 vec_foreach (ns, nses) {
3473 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3479 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
3481 const ip_details_t * det = NULL;
3482 const ip_address_details_t * address = NULL;
3493 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
3495 if (!det->present) {
3503 "Address", "Prefix length");
3507 vec_foreach (address, det->addr) {
3510 is_ipv6 ? format_ip6_address : format_ip4_address,
3512 address->prefix_length);
3519 static int dump_ipv4_table (vat_main_t * vam)
3521 if (vam->json_output) {
3522 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3526 return dump_ip_table (vam, 0);
3529 static int dump_ipv6_table (vat_main_t * vam)
3531 if (vam->json_output) {
3532 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3536 return dump_ip_table (vam, 1);
3539 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
3542 switch(counter_type) {
3543 case VNET_INTERFACE_COUNTER_DROP:
3545 case VNET_INTERFACE_COUNTER_PUNT:
3547 case VNET_INTERFACE_COUNTER_IP4:
3549 case VNET_INTERFACE_COUNTER_IP6:
3551 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3553 case VNET_INTERFACE_COUNTER_RX_MISS:
3555 case VNET_INTERFACE_COUNTER_RX_ERROR:
3557 case VNET_INTERFACE_COUNTER_TX_ERROR:
3560 return "INVALID-COUNTER-TYPE";
3563 switch(counter_type) {
3564 case VNET_INTERFACE_COUNTER_RX:
3566 case VNET_INTERFACE_COUNTER_TX:
3569 return "INVALID-COUNTER-TYPE";
3574 static int dump_stats_table (vat_main_t * vam)
3576 vat_json_node_t node;
3577 vat_json_node_t *msg_array;
3578 vat_json_node_t *msg;
3579 vat_json_node_t *counter_array;
3580 vat_json_node_t *counter;
3581 interface_counter_t c;
3583 ip4_fib_counter_t *c4;
3584 ip6_fib_counter_t *c6;
3587 if (!vam->json_output) {
3588 clib_warning ("dump_stats_table supported only in JSON format");
3592 vat_json_init_object(&node);
3594 /* interface counters */
3595 msg_array = vat_json_object_add(&node, "interface_counters");
3596 vat_json_init_array(msg_array);
3597 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
3598 msg = vat_json_array_add(msg_array);
3599 vat_json_init_object(msg);
3600 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3601 (u8*)counter_type_to_str(i, 0));
3602 vat_json_object_add_int(msg, "is_combined", 0);
3603 counter_array = vat_json_object_add(msg, "data");
3604 vat_json_init_array(counter_array);
3605 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
3606 packets = vam->simple_interface_counters[i][j];
3607 vat_json_array_add_uint(counter_array, packets);
3610 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
3611 msg = vat_json_array_add(msg_array);
3612 vat_json_init_object(msg);
3613 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3614 (u8*)counter_type_to_str(i, 1));
3615 vat_json_object_add_int(msg, "is_combined", 1);
3616 counter_array = vat_json_object_add(msg, "data");
3617 vat_json_init_array(counter_array);
3618 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
3619 c = vam->combined_interface_counters[i][j];
3620 counter = vat_json_array_add(counter_array);
3621 vat_json_init_object(counter);
3622 vat_json_object_add_uint(counter, "packets", c.packets);
3623 vat_json_object_add_uint(counter, "bytes", c.bytes);
3627 /* ip4 fib counters */
3628 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
3629 vat_json_init_array(msg_array);
3630 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
3631 msg = vat_json_array_add(msg_array);
3632 vat_json_init_object(msg);
3633 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
3634 counter_array = vat_json_object_add(msg, "c");
3635 vat_json_init_array(counter_array);
3636 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
3637 counter = vat_json_array_add(counter_array);
3638 vat_json_init_object(counter);
3639 c4 = &vam->ip4_fib_counters[i][j];
3640 vat_json_object_add_ip4(counter, "address", c4->address);
3641 vat_json_object_add_uint(counter, "address_length", c4->address_length);
3642 vat_json_object_add_uint(counter, "packets", c4->packets);
3643 vat_json_object_add_uint(counter, "bytes", c4->bytes);
3647 /* ip6 fib counters */
3648 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
3649 vat_json_init_array(msg_array);
3650 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
3651 msg = vat_json_array_add(msg_array);
3652 vat_json_init_object(msg);
3653 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
3654 counter_array = vat_json_object_add(msg, "c");
3655 vat_json_init_array(counter_array);
3656 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
3657 counter = vat_json_array_add(counter_array);
3658 vat_json_init_object(counter);
3659 c6 = &vam->ip6_fib_counters[i][j];
3660 vat_json_object_add_ip6(counter, "address", c6->address);
3661 vat_json_object_add_uint(counter, "address_length", c6->address_length);
3662 vat_json_object_add_uint(counter, "packets", c6->packets);
3663 vat_json_object_add_uint(counter, "bytes", c6->bytes);
3667 vat_json_print(vam->ofp, &node);
3668 vat_json_free(&node);
3673 int exec (vat_main_t * vam)
3675 api_main_t * am = &api_main;
3676 vl_api_cli_request_t *mp;
3680 unformat_input_t * i = vam->input;
3682 if (vec_len(i->buffer) == 0)
3685 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3689 if (vam->exec_mode == 1 &&
3690 (unformat (i, "exit") || unformat (i, "quit"))) {
3696 M(CLI_REQUEST, cli_request);
3699 * Copy cmd into shared memory.
3700 * In order for the CLI command to work, it
3701 * must be a vector ending in \n, not a C-string ending
3704 pthread_mutex_lock (&am->vlib_rp->mutex);
3705 oldheap = svm_push_data_heap (am->vlib_rp);
3707 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3708 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3710 svm_pop_heap (oldheap);
3711 pthread_mutex_unlock (&am->vlib_rp->mutex);
3713 mp->cmd_in_shmem = (u64) cmd;
3715 timeout = vat_time_now (vam) + 10.0;
3717 while (vat_time_now (vam) < timeout) {
3718 if (vam->result_ready == 1) {
3720 if (vam->shmem_result != NULL)
3721 fformat (vam->ofp, "%s", vam->shmem_result);
3722 pthread_mutex_lock (&am->vlib_rp->mutex);
3723 oldheap = svm_push_data_heap (am->vlib_rp);
3725 free_me = (u8 *)vam->shmem_result;
3728 svm_pop_heap (oldheap);
3729 pthread_mutex_unlock (&am->vlib_rp->mutex);
3736 static int api_create_loopback (vat_main_t * vam)
3738 unformat_input_t * i = vam->input;
3739 vl_api_create_loopback_t *mp;
3744 memset (mac_address, 0, sizeof (mac_address));
3746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3748 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3754 /* Construct the API message */
3755 M(CREATE_LOOPBACK, create_loopback);
3757 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3762 static int api_delete_loopback (vat_main_t * vam)
3764 unformat_input_t * i = vam->input;
3765 vl_api_delete_loopback_t *mp;
3767 u32 sw_if_index = ~0;
3769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3771 if (unformat (i, "sw_if_index %d", &sw_if_index))
3777 if (sw_if_index == ~0)
3779 errmsg ("missing sw_if_index\n");
3783 /* Construct the API message */
3784 M(DELETE_LOOPBACK, delete_loopback);
3785 mp->sw_if_index = ntohl (sw_if_index);
3790 static int api_want_stats (vat_main_t * vam)
3792 unformat_input_t * i = vam->input;
3793 vl_api_want_stats_t * mp;
3797 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3799 if (unformat (i, "enable"))
3801 else if (unformat (i, "disable"))
3809 errmsg ("missing enable|disable\n");
3813 M(WANT_STATS, want_stats);
3814 mp->enable_disable = enable;
3819 static int api_want_interface_events (vat_main_t * vam)
3821 unformat_input_t * i = vam->input;
3822 vl_api_want_interface_events_t * mp;
3826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3828 if (unformat (i, "enable"))
3830 else if (unformat (i, "disable"))
3838 errmsg ("missing enable|disable\n");
3842 M(WANT_INTERFACE_EVENTS, want_interface_events);
3843 mp->enable_disable = enable;
3845 vam->interface_event_display = enable;
3851 /* Note: non-static, called once to set up the initial intfc table */
3852 int api_sw_interface_dump (vat_main_t * vam)
3854 vl_api_sw_interface_dump_t *mp;
3857 name_sort_t * nses = 0, * ns;
3858 sw_interface_subif_t * sub = NULL;
3860 /* Toss the old name table */
3861 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3863 vec_add2 (nses, ns, 1);
3864 ns->name = (u8 *)(p->key);
3865 ns->value = (u32) p->value[0];
3868 hash_free (vam->sw_if_index_by_interface_name);
3870 vec_foreach (ns, nses)
3871 vec_free (ns->name);
3875 vec_foreach (sub, vam->sw_if_subif_table) {
3876 vec_free (sub->interface_name);
3878 vec_free (vam->sw_if_subif_table);
3880 /* recreate the interface name hash table */
3881 vam->sw_if_index_by_interface_name
3882 = hash_create_string (0, sizeof(uword));
3884 /* Get list of ethernets */
3885 M(SW_INTERFACE_DUMP, sw_interface_dump);
3886 mp->name_filter_valid = 1;
3887 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3890 /* and local / loopback interfaces */
3891 M(SW_INTERFACE_DUMP, sw_interface_dump);
3892 mp->name_filter_valid = 1;
3893 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3897 /* and vxlan-gpe tunnel interfaces */
3898 M(SW_INTERFACE_DUMP, sw_interface_dump);
3899 mp->name_filter_valid = 1;
3900 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3903 /* and vxlan tunnel interfaces */
3904 M(SW_INTERFACE_DUMP, sw_interface_dump);
3905 mp->name_filter_valid = 1;
3906 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3909 /* and host (af_packet) interfaces */
3910 M(SW_INTERFACE_DUMP, sw_interface_dump);
3911 mp->name_filter_valid = 1;
3912 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3915 /* and l2tpv3 tunnel interfaces */
3916 M(SW_INTERFACE_DUMP, sw_interface_dump);
3917 mp->name_filter_valid = 1;
3918 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3921 /* and GRE tunnel interfaces */
3922 M(SW_INTERFACE_DUMP, sw_interface_dump);
3923 mp->name_filter_valid = 1;
3924 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3927 /* Use a control ping for synchronization */
3929 vl_api_control_ping_t * mp;
3930 M(CONTROL_PING, control_ping);
3936 static int api_sw_interface_set_flags (vat_main_t * vam)
3938 unformat_input_t * i = vam->input;
3939 vl_api_sw_interface_set_flags_t *mp;
3942 u8 sw_if_index_set = 0;
3943 u8 admin_up = 0, link_up = 0;
3945 /* Parse args required to build the message */
3946 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3947 if (unformat (i, "admin-up"))
3949 else if (unformat (i, "admin-down"))
3951 else if (unformat (i, "link-up"))
3953 else if (unformat (i, "link-down"))
3955 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3956 sw_if_index_set = 1;
3957 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3958 sw_if_index_set = 1;
3963 if (sw_if_index_set == 0) {
3964 errmsg ("missing interface name or sw_if_index\n");
3968 /* Construct the API message */
3969 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3970 mp->sw_if_index = ntohl (sw_if_index);
3971 mp->admin_up_down = admin_up;
3972 mp->link_up_down = link_up;
3977 /* Wait for a reply, return the good/bad news... */
3981 static int api_sw_interface_clear_stats (vat_main_t * vam)
3983 unformat_input_t * i = vam->input;
3984 vl_api_sw_interface_clear_stats_t *mp;
3987 u8 sw_if_index_set = 0;
3989 /* Parse args required to build the message */
3990 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3991 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3992 sw_if_index_set = 1;
3993 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3994 sw_if_index_set = 1;
3999 /* Construct the API message */
4000 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
4002 if (sw_if_index_set == 1)
4003 mp->sw_if_index = ntohl (sw_if_index);
4005 mp->sw_if_index = ~0;
4010 /* Wait for a reply, return the good/bad news... */
4014 static int api_sw_interface_add_del_address (vat_main_t * vam)
4016 unformat_input_t * i = vam->input;
4017 vl_api_sw_interface_add_del_address_t *mp;
4020 u8 sw_if_index_set = 0;
4021 u8 is_add = 1, del_all = 0;
4022 u32 address_length = 0;
4023 u8 v4_address_set = 0;
4024 u8 v6_address_set = 0;
4025 ip4_address_t v4address;
4026 ip6_address_t v6address;
4028 /* Parse args required to build the message */
4029 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4030 if (unformat (i, "del-all"))
4032 else if (unformat (i, "del"))
4034 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4035 sw_if_index_set = 1;
4036 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4037 sw_if_index_set = 1;
4038 else if (unformat (i, "%U/%d",
4039 unformat_ip4_address, &v4address,
4042 else if (unformat (i, "%U/%d",
4043 unformat_ip6_address, &v6address,
4050 if (sw_if_index_set == 0) {
4051 errmsg ("missing interface name or sw_if_index\n");
4054 if (v4_address_set && v6_address_set) {
4055 errmsg ("both v4 and v6 addresses set\n");
4058 if (!v4_address_set && !v6_address_set && !del_all) {
4059 errmsg ("no addresses set\n");
4063 /* Construct the API message */
4064 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4066 mp->sw_if_index = ntohl (sw_if_index);
4067 mp->is_add = is_add;
4068 mp->del_all = del_all;
4069 if (v6_address_set) {
4071 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4073 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4075 mp->address_length = address_length;
4080 /* Wait for a reply, return good/bad news */
4084 static int api_sw_interface_set_table (vat_main_t * vam)
4086 unformat_input_t * i = vam->input;
4087 vl_api_sw_interface_set_table_t *mp;
4089 u32 sw_if_index, vrf_id = 0;
4090 u8 sw_if_index_set = 0;
4093 /* Parse args required to build the message */
4094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4095 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4096 sw_if_index_set = 1;
4097 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4098 sw_if_index_set = 1;
4099 else if (unformat (i, "vrf %d", &vrf_id))
4101 else if (unformat (i, "ipv6"))
4107 if (sw_if_index_set == 0) {
4108 errmsg ("missing interface name or sw_if_index\n");
4112 /* Construct the API message */
4113 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4115 mp->sw_if_index = ntohl (sw_if_index);
4116 mp->is_ipv6 = is_ipv6;
4117 mp->vrf_id = ntohl (vrf_id);
4122 /* Wait for a reply... */
4126 static int api_sw_interface_set_vpath (vat_main_t * vam)
4128 unformat_input_t * i = vam->input;
4129 vl_api_sw_interface_set_vpath_t *mp;
4131 u32 sw_if_index = 0;
4132 u8 sw_if_index_set = 0;
4135 /* Parse args required to build the message */
4136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4137 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4138 sw_if_index_set = 1;
4139 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4140 sw_if_index_set = 1;
4141 else if (unformat (i, "enable"))
4143 else if (unformat (i, "disable"))
4149 if (sw_if_index_set == 0) {
4150 errmsg ("missing interface name or sw_if_index\n");
4154 /* Construct the API message */
4155 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4157 mp->sw_if_index = ntohl (sw_if_index);
4158 mp->enable = is_enable;
4163 /* Wait for a reply... */
4167 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4169 unformat_input_t * i = vam->input;
4170 vl_api_sw_interface_set_l2_xconnect_t *mp;
4173 u8 rx_sw_if_index_set = 0;
4175 u8 tx_sw_if_index_set = 0;
4178 /* Parse args required to build the message */
4179 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4180 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4181 rx_sw_if_index_set = 1;
4182 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4183 tx_sw_if_index_set = 1;
4184 else if (unformat (i, "rx")) {
4185 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4186 if (unformat (i, "%U", unformat_sw_if_index, vam,
4188 rx_sw_if_index_set = 1;
4191 } else if (unformat (i, "tx")) {
4192 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4193 if (unformat (i, "%U", unformat_sw_if_index, vam,
4195 tx_sw_if_index_set = 1;
4198 } else if (unformat (i, "enable"))
4200 else if (unformat (i, "disable"))
4206 if (rx_sw_if_index_set == 0) {
4207 errmsg ("missing rx interface name or rx_sw_if_index\n");
4211 if (enable && (tx_sw_if_index_set == 0)) {
4212 errmsg ("missing tx interface name or tx_sw_if_index\n");
4216 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
4218 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4219 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4220 mp->enable = enable;
4227 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
4229 unformat_input_t * i = vam->input;
4230 vl_api_sw_interface_set_l2_bridge_t *mp;
4233 u8 rx_sw_if_index_set = 0;
4240 /* Parse args required to build the message */
4241 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4242 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4243 rx_sw_if_index_set = 1;
4244 else if (unformat (i, "bd_id %d", &bd_id))
4246 else if (unformat (i, "%U", unformat_sw_if_index, vam,
4248 rx_sw_if_index_set = 1;
4249 else if (unformat (i, "shg %d", &shg))
4251 else if (unformat (i, "bvi"))
4253 else if (unformat (i, "enable"))
4255 else if (unformat (i, "disable"))
4261 if (rx_sw_if_index_set == 0) {
4262 errmsg ("missing rx interface name or sw_if_index\n");
4266 if (enable && (bd_id_set == 0)) {
4267 errmsg ("missing bridge domain\n");
4271 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
4273 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4274 mp->bd_id = ntohl(bd_id);
4277 mp->enable = enable;
4284 static int api_bridge_domain_dump (vat_main_t * vam)
4286 unformat_input_t * i = vam->input;
4287 vl_api_bridge_domain_dump_t *mp;
4291 /* Parse args required to build the message */
4292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4293 if (unformat (i, "bd_id %d", &bd_id))
4299 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
4300 mp->bd_id = ntohl(bd_id);
4303 /* Use a control ping for synchronization */
4305 vl_api_control_ping_t * mp;
4306 M(CONTROL_PING, control_ping);
4315 static int api_bridge_domain_add_del (vat_main_t * vam)
4317 unformat_input_t * i = vam->input;
4318 vl_api_bridge_domain_add_del_t *mp;
4322 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4324 /* Parse args required to build the message */
4325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4326 if (unformat (i, "bd_id %d", &bd_id))
4328 else if (unformat (i, "flood %d", &flood))
4330 else if (unformat (i, "uu-flood %d", &uu_flood))
4332 else if (unformat (i, "forward %d", &forward))
4334 else if (unformat (i, "learn %d", &learn))
4336 else if (unformat (i, "arp-term %d", &arp_term))
4338 else if (unformat (i, "del")) {
4340 flood = uu_flood = forward = learn = 0;
4347 errmsg ("missing bridge domain\n");
4351 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
4353 mp->bd_id = ntohl(bd_id);
4355 mp->uu_flood = uu_flood;
4356 mp->forward = forward;
4358 mp->arp_term = arp_term;
4359 mp->is_add = is_add;
4366 static int api_l2fib_add_del (vat_main_t * vam)
4368 unformat_input_t * i = vam->input;
4369 vl_api_l2fib_add_del_t *mp;
4376 u8 sw_if_index_set = 0;
4385 /* Parse args required to build the message */
4386 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4387 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
4389 else if (unformat (i, "bd_id %d", &bd_id))
4391 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4392 sw_if_index_set = 1;
4393 else if (unformat (i, "sw_if")) {
4394 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4395 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4396 sw_if_index_set = 1;
4399 } else if (unformat (i, "static"))
4401 else if (unformat (i, "filter")) {
4404 } else if (unformat (i, "bvi")) {
4407 } else if (unformat (i, "del"))
4409 else if (unformat (i, "count %d", &count))
4416 errmsg ("missing mac address\n");
4420 if (bd_id_set == 0) {
4421 errmsg ("missing bridge domain\n");
4425 if (is_add && (sw_if_index_set == 0)) {
4426 errmsg ("missing interface name or sw_if_index\n");
4431 /* Turn on async mode */
4432 vam->async_mode = 1;
4433 vam->async_errors = 0;
4434 before = vat_time_now(vam);
4437 for (j = 0; j < count; j++) {
4438 M(L2FIB_ADD_DEL, l2fib_add_del);
4441 mp->bd_id = ntohl(bd_id);
4442 mp->is_add = is_add;
4445 mp->sw_if_index = ntohl(sw_if_index);
4446 mp->static_mac = static_mac;
4447 mp->filter_mac = filter_mac;
4448 mp->bvi_mac = bvi_mac;
4450 increment_mac_address (&mac);
4456 vl_api_control_ping_t * mp;
4459 /* Shut off async mode */
4460 vam->async_mode = 0;
4462 M(CONTROL_PING, control_ping);
4465 timeout = vat_time_now(vam) + 1.0;
4466 while (vat_time_now (vam) < timeout)
4467 if (vam->result_ready == 1)
4472 if (vam->retval == -99)
4473 errmsg ("timeout\n");
4475 if (vam->async_errors > 0) {
4476 errmsg ("%d asynchronous errors\n", vam->async_errors);
4479 vam->async_errors = 0;
4480 after = vat_time_now(vam);
4482 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4483 count, after - before, count / (after - before));
4485 /* Wait for a reply... */
4488 /* Return the good/bad news */
4489 return (vam->retval);
4492 static int api_l2_flags (vat_main_t * vam)
4494 unformat_input_t * i = vam->input;
4495 vl_api_l2_flags_t *mp;
4498 u32 feature_bitmap = 0;
4499 u8 sw_if_index_set = 0;
4501 /* Parse args required to build the message */
4502 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4503 if (unformat (i, "sw_if_index %d", &sw_if_index))
4504 sw_if_index_set = 1;
4505 else if (unformat (i, "sw_if")) {
4506 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4507 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4508 sw_if_index_set = 1;
4511 } else if (unformat (i, "learn"))
4512 feature_bitmap |= L2INPUT_FEAT_LEARN;
4513 else if (unformat (i, "forward"))
4514 feature_bitmap |= L2INPUT_FEAT_FWD;
4515 else if (unformat (i, "flood"))
4516 feature_bitmap |= L2INPUT_FEAT_FLOOD;
4517 else if (unformat (i, "uu-flood"))
4518 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
4523 if (sw_if_index_set == 0) {
4524 errmsg ("missing interface name or sw_if_index\n");
4528 M(L2_FLAGS, l2_flags);
4530 mp->sw_if_index = ntohl(sw_if_index);
4531 mp->feature_bitmap = ntohl(feature_bitmap);
4538 static int api_bridge_flags (vat_main_t * vam)
4540 unformat_input_t * i = vam->input;
4541 vl_api_bridge_flags_t *mp;
4548 /* Parse args required to build the message */
4549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4550 if (unformat (i, "bd_id %d", &bd_id))
4552 else if (unformat (i, "learn"))
4554 else if (unformat (i, "forward"))
4556 else if (unformat (i, "flood"))
4558 else if (unformat (i, "uu-flood"))
4559 flags |= L2_UU_FLOOD;
4560 else if (unformat (i, "arp-term"))
4561 flags |= L2_ARP_TERM;
4562 else if (unformat (i, "off"))
4564 else if (unformat (i, "disable"))
4570 if (bd_id_set == 0) {
4571 errmsg ("missing bridge domain\n");
4575 M(BRIDGE_FLAGS, bridge_flags);
4577 mp->bd_id = ntohl(bd_id);
4578 mp->feature_bitmap = ntohl(flags);
4579 mp->is_set = is_set;
4586 static int api_bd_ip_mac_add_del (vat_main_t * vam)
4588 unformat_input_t * i = vam->input;
4589 vl_api_bd_ip_mac_add_del_t *mp;
4597 ip4_address_t v4addr;
4598 ip6_address_t v6addr;
4602 /* Parse args required to build the message */
4603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4604 if (unformat (i, "bd_id %d", &bd_id)) {
4606 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
4608 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
4611 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
4613 } else if (unformat (i, "del"))
4619 if (bd_id_set == 0) {
4620 errmsg ("missing bridge domain\n");
4622 } else if (ip_set == 0) {
4623 errmsg ("missing IP address\n");
4625 } else if (mac_set == 0) {
4626 errmsg ("missing MAC address\n");
4630 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
4632 mp->bd_id = ntohl(bd_id);
4633 mp->is_ipv6 = is_ipv6;
4634 mp->is_add = is_add;
4636 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
4637 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
4638 clib_memcpy (mp->mac_address, macaddr, 6);
4644 static int api_tap_connect (vat_main_t * vam)
4646 unformat_input_t * i = vam->input;
4647 vl_api_tap_connect_t *mp;
4654 memset (mac_address, 0, sizeof (mac_address));
4656 /* Parse args required to build the message */
4657 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4658 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4661 else if (unformat (i, "random-mac"))
4663 else if (unformat (i, "tapname %s", &tap_name))
4669 if (name_set == 0) {
4670 errmsg ("missing tap name\n");
4673 if (vec_len (tap_name) > 63) {
4674 errmsg ("tap name too long\n");
4676 vec_add1 (tap_name, 0);
4678 /* Construct the API message */
4679 M(TAP_CONNECT, tap_connect);
4681 mp->use_random_mac = random_mac;
4682 clib_memcpy (mp->mac_address, mac_address, 6);
4683 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4684 vec_free (tap_name);
4689 /* Wait for a reply... */
4693 static int api_tap_modify (vat_main_t * vam)
4695 unformat_input_t * i = vam->input;
4696 vl_api_tap_modify_t *mp;
4702 u32 sw_if_index = ~0;
4703 u8 sw_if_index_set = 0;
4705 memset (mac_address, 0, sizeof (mac_address));
4707 /* Parse args required to build the message */
4708 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4709 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4710 sw_if_index_set = 1;
4711 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4712 sw_if_index_set = 1;
4713 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4716 else if (unformat (i, "random-mac"))
4718 else if (unformat (i, "tapname %s", &tap_name))
4724 if (sw_if_index_set == 0) {
4725 errmsg ("missing vpp interface name");
4728 if (name_set == 0) {
4729 errmsg ("missing tap name\n");
4732 if (vec_len (tap_name) > 63) {
4733 errmsg ("tap name too long\n");
4735 vec_add1 (tap_name, 0);
4737 /* Construct the API message */
4738 M(TAP_MODIFY, tap_modify);
4740 mp->use_random_mac = random_mac;
4741 mp->sw_if_index = ntohl(sw_if_index);
4742 clib_memcpy (mp->mac_address, mac_address, 6);
4743 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4744 vec_free (tap_name);
4749 /* Wait for a reply... */
4753 static int api_tap_delete (vat_main_t * vam)
4755 unformat_input_t * i = vam->input;
4756 vl_api_tap_delete_t *mp;
4758 u32 sw_if_index = ~0;
4759 u8 sw_if_index_set = 0;
4761 /* Parse args required to build the message */
4762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4763 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4764 sw_if_index_set = 1;
4765 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4766 sw_if_index_set = 1;
4771 if (sw_if_index_set == 0) {
4772 errmsg ("missing vpp interface name");
4776 /* Construct the API message */
4777 M(TAP_DELETE, tap_delete);
4779 mp->sw_if_index = ntohl(sw_if_index);
4784 /* Wait for a reply... */
4788 static int api_ip_add_del_route (vat_main_t * vam)
4790 unformat_input_t * i = vam->input;
4791 vl_api_ip_add_del_route_t *mp;
4793 u32 sw_if_index = ~0, vrf_id = 0;
4794 u8 sw_if_index_set = 0;
4796 u8 is_local = 0, is_drop = 0;
4797 u8 create_vrf_if_needed = 0;
4799 u8 next_hop_weight = 1;
4801 u8 is_multipath = 0;
4803 u8 address_length_set = 0;
4804 u32 lookup_in_vrf = 0;
4805 u32 resolve_attempts = 0;
4806 u32 dst_address_length = 0;
4807 u8 next_hop_set = 0;
4808 ip4_address_t v4_dst_address, v4_next_hop_address;
4809 ip6_address_t v6_dst_address, v6_next_hop_address;
4813 u32 random_add_del = 0;
4814 u32 * random_vector = 0;
4815 uword * random_hash;
4816 u32 random_seed = 0xdeaddabe;
4817 u32 classify_table_index = ~0;
4820 /* Parse args required to build the message */
4821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4822 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4823 sw_if_index_set = 1;
4824 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4825 sw_if_index_set = 1;
4826 else if (unformat (i, "%U", unformat_ip4_address,
4831 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4835 else if (unformat (i, "/%d", &dst_address_length)) {
4836 address_length_set = 1;
4839 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4840 &v4_next_hop_address)) {
4843 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4844 &v6_next_hop_address)) {
4847 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4849 else if (unformat (i, "weight %d", &next_hop_weight))
4851 else if (unformat (i, "drop")) {
4853 } else if (unformat (i, "local")) {
4855 } else if (unformat (i, "classify %d", &classify_table_index)) {
4857 } else if (unformat (i, "del"))
4859 else if (unformat (i, "add"))
4861 else if (unformat (i, "not-last"))
4863 else if (unformat (i, "multipath"))
4865 else if (unformat (i, "vrf %d", &vrf_id))
4867 else if (unformat (i, "create-vrf"))
4868 create_vrf_if_needed = 1;
4869 else if (unformat (i, "count %d", &count))
4871 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4873 else if (unformat (i, "random"))
4875 else if (unformat (i, "seed %d", &random_seed))
4878 clib_warning ("parse error '%U'", format_unformat_error, i);
4883 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4884 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4888 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4889 errmsg ("next hop / local / drop / classify not set\n");
4893 if (address_set == 0) {
4894 errmsg ("missing addresses\n");
4898 if (address_length_set == 0) {
4899 errmsg ("missing address length\n");
4903 /* Generate a pile of unique, random routes */
4904 if (random_add_del) {
4905 u32 this_random_address;
4906 random_hash = hash_create (count, sizeof(uword));
4908 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4909 for (j = 0; j <= count; j++) {
4911 this_random_address = random_u32 (&random_seed);
4912 this_random_address =
4913 clib_host_to_net_u32 (this_random_address);
4914 } while (hash_get (random_hash, this_random_address));
4915 vec_add1 (random_vector, this_random_address);
4916 hash_set (random_hash, this_random_address, 1);
4918 hash_free (random_hash);
4919 v4_dst_address.as_u32 = random_vector[0];
4923 /* Turn on async mode */
4924 vam->async_mode = 1;
4925 vam->async_errors = 0;
4926 before = vat_time_now(vam);
4929 for (j = 0; j < count; j++) {
4930 /* Construct the API message */
4931 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4933 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4934 mp->vrf_id = ntohl (vrf_id);
4935 if (resolve_attempts > 0) {
4936 mp->resolve_attempts = ntohl (resolve_attempts);
4937 mp->resolve_if_needed = 1;
4939 mp->create_vrf_if_needed = create_vrf_if_needed;
4941 mp->is_add = is_add;
4942 mp->is_drop = is_drop;
4943 mp->is_ipv6 = is_ipv6;
4944 mp->is_local = is_local;
4945 mp->is_classify = is_classify;
4946 mp->is_multipath = is_multipath;
4947 mp->not_last = not_last;
4948 mp->next_hop_weight = next_hop_weight;
4949 mp->dst_address_length = dst_address_length;
4950 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4951 mp->classify_table_index = ntohl(classify_table_index);
4954 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4956 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4957 sizeof (v6_next_hop_address));
4958 increment_v6_address (&v6_dst_address);
4960 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4962 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4963 sizeof (v4_next_hop_address));
4965 v4_dst_address.as_u32 = random_vector[j+1];
4967 increment_v4_address (&v4_dst_address);
4973 /* When testing multiple add/del ops, use a control-ping to sync */
4975 vl_api_control_ping_t * mp;
4978 /* Shut off async mode */
4979 vam->async_mode = 0;
4981 M(CONTROL_PING, control_ping);
4984 timeout = vat_time_now(vam) + 1.0;
4985 while (vat_time_now (vam) < timeout)
4986 if (vam->result_ready == 1)
4991 if (vam->retval == -99)
4992 errmsg ("timeout\n");
4994 if (vam->async_errors > 0) {
4995 errmsg ("%d asynchronous errors\n", vam->async_errors);
4998 vam->async_errors = 0;
4999 after = vat_time_now(vam);
5001 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
5002 count, after - before, count / (after - before));
5004 /* Wait for a reply... */
5008 /* Return the good/bad news */
5009 return (vam->retval);
5012 static int api_proxy_arp_add_del (vat_main_t * vam)
5014 unformat_input_t * i = vam->input;
5015 vl_api_proxy_arp_add_del_t *mp;
5019 ip4_address_t lo, hi;
5022 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5023 if (unformat (i, "vrf %d", &vrf_id))
5025 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
5026 unformat_ip4_address, &hi))
5028 else if (unformat (i, "del"))
5031 clib_warning ("parse error '%U'", format_unformat_error, i);
5036 if (range_set == 0) {
5037 errmsg ("address range not set\n");
5041 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
5043 mp->vrf_id = ntohl(vrf_id);
5044 mp->is_add = is_add;
5045 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
5046 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
5053 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
5055 unformat_input_t * i = vam->input;
5056 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5060 u8 sw_if_index_set = 0;
5062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5063 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5064 sw_if_index_set = 1;
5065 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5066 sw_if_index_set = 1;
5067 else if (unformat (i, "enable"))
5069 else if (unformat (i, "disable"))
5072 clib_warning ("parse error '%U'", format_unformat_error, i);
5077 if (sw_if_index_set == 0) {
5078 errmsg ("missing interface name or sw_if_index\n");
5082 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
5084 mp->sw_if_index = ntohl(sw_if_index);
5085 mp->enable_disable = enable;
5092 static int api_mpls_add_del_decap (vat_main_t * vam)
5094 unformat_input_t * i = vam->input;
5095 vl_api_mpls_add_del_decap_t *mp;
5104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5105 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5107 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5109 else if (unformat (i, "label %d", &label))
5111 else if (unformat (i, "next-index %d", &next_index))
5113 else if (unformat (i, "del"))
5115 else if (unformat (i, "s-bit-clear"))
5118 clib_warning ("parse error '%U'", format_unformat_error, i);
5123 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
5125 mp->rx_vrf_id = ntohl(rx_vrf_id);
5126 mp->tx_vrf_id = ntohl(tx_vrf_id);
5127 mp->label = ntohl(label);
5128 mp->next_index = ntohl(next_index);
5130 mp->is_add = is_add;
5137 static int api_mpls_add_del_encap (vat_main_t * vam)
5139 unformat_input_t * i = vam->input;
5140 vl_api_mpls_add_del_encap_t *mp;
5145 ip4_address_t dst_address;
5148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5149 if (unformat (i, "vrf %d", &vrf_id))
5151 else if (unformat (i, "label %d", &label))
5152 vec_add1 (labels, ntohl(label));
5153 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5155 else if (unformat (i, "del"))
5158 clib_warning ("parse error '%U'", format_unformat_error, i);
5163 if (vec_len (labels) == 0) {
5164 errmsg ("missing encap label stack\n");
5168 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
5169 sizeof (u32) * vec_len (labels));
5171 mp->vrf_id = ntohl(vrf_id);
5172 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5173 mp->is_add = is_add;
5174 mp->nlabels = vec_len (labels);
5175 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
5184 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
5186 unformat_input_t * i = vam->input;
5187 vl_api_mpls_gre_add_del_tunnel_t *mp;
5189 u32 inner_vrf_id = 0;
5190 u32 outer_vrf_id = 0;
5191 ip4_address_t src_address;
5192 ip4_address_t dst_address;
5193 ip4_address_t intfc_address;
5195 u8 intfc_address_length = 0;
5199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5200 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5202 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5204 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
5206 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5208 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5209 &intfc_address, &tmp))
5210 intfc_address_length = tmp;
5211 else if (unformat (i, "l2-only"))
5213 else if (unformat (i, "del"))
5216 clib_warning ("parse error '%U'", format_unformat_error, i);
5221 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
5223 mp->inner_vrf_id = ntohl(inner_vrf_id);
5224 mp->outer_vrf_id = ntohl(outer_vrf_id);
5225 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
5226 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5227 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
5228 mp->intfc_address_length = intfc_address_length;
5229 mp->l2_only = l2_only;
5230 mp->is_add = is_add;
5237 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
5239 unformat_input_t * i = vam->input;
5240 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
5242 u32 inner_vrf_id = 0;
5243 ip4_address_t intfc_address;
5244 u8 dst_mac_address[6];
5247 u8 intfc_address_length = 0;
5251 int tx_sw_if_index_set = 0;
5253 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5254 if (unformat (i, "vrf %d", &inner_vrf_id))
5256 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5257 &intfc_address, &tmp))
5258 intfc_address_length = tmp;
5259 else if (unformat (i, "%U",
5260 unformat_sw_if_index, vam, &tx_sw_if_index))
5261 tx_sw_if_index_set = 1;
5262 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5263 tx_sw_if_index_set = 1;
5264 else if (unformat (i, "dst %U", unformat_ethernet_address,
5267 else if (unformat (i, "l2-only"))
5269 else if (unformat (i, "del"))
5272 clib_warning ("parse error '%U'", format_unformat_error, i);
5278 errmsg ("dst (mac address) not set\n");
5281 if (!tx_sw_if_index_set) {
5282 errmsg ("tx-intfc not set\n");
5286 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
5288 mp->vrf_id = ntohl(inner_vrf_id);
5289 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
5290 mp->adj_address_length = intfc_address_length;
5291 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
5292 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5293 mp->l2_only = l2_only;
5294 mp->is_add = is_add;
5301 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
5303 unformat_input_t * i = vam->input;
5304 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
5306 u32 inner_vrf_id = 0;
5307 u32 outer_vrf_id = 0;
5308 ip4_address_t adj_address;
5309 int adj_address_set = 0;
5310 ip4_address_t next_hop_address;
5311 int next_hop_address_set = 0;
5313 u8 adj_address_length = 0;
5316 u32 resolve_attempts = 5;
5317 u8 resolve_if_needed = 1;
5319 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5320 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5322 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5324 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5325 &adj_address, &tmp)) {
5326 adj_address_length = tmp;
5327 adj_address_set = 1;
5329 else if (unformat (i, "next-hop %U", unformat_ip4_address,
5331 next_hop_address_set = 1;
5332 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5334 else if (unformat (i, "resolve-if-needed %d", &tmp))
5335 resolve_if_needed = tmp;
5336 else if (unformat (i, "l2-only"))
5338 else if (unformat (i, "del"))
5341 clib_warning ("parse error '%U'", format_unformat_error, i);
5346 if (!adj_address_set) {
5347 errmsg ("adjacency address/mask not set\n");
5350 if (!next_hop_address_set) {
5351 errmsg ("ip4 next hop address (in outer fib) not set\n");
5355 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
5357 mp->inner_vrf_id = ntohl(inner_vrf_id);
5358 mp->outer_vrf_id = ntohl(outer_vrf_id);
5359 mp->resolve_attempts = ntohl(resolve_attempts);
5360 mp->resolve_if_needed = resolve_if_needed;
5361 mp->is_add = is_add;
5362 mp->l2_only = l2_only;
5363 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
5364 mp->adj_address_length = adj_address_length;
5365 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
5366 sizeof (next_hop_address));
5373 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
5375 unformat_input_t * i = vam->input;
5376 vl_api_sw_interface_set_unnumbered_t *mp;
5381 u8 sw_if_index_set = 0;
5383 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5384 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5385 sw_if_index_set = 1;
5386 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5387 sw_if_index_set = 1;
5388 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5390 else if (unformat (i, "del"))
5393 clib_warning ("parse error '%U'", format_unformat_error, i);
5398 if (sw_if_index_set == 0) {
5399 errmsg ("missing interface name or sw_if_index\n");
5403 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
5405 mp->sw_if_index = ntohl(sw_if_index);
5406 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
5407 mp->is_add = is_add;
5414 static int api_ip_neighbor_add_del (vat_main_t * vam)
5416 unformat_input_t * i = vam->input;
5417 vl_api_ip_neighbor_add_del_t *mp;
5420 u8 sw_if_index_set = 0;
5426 u8 v4_address_set = 0;
5427 u8 v6_address_set = 0;
5428 ip4_address_t v4address;
5429 ip6_address_t v6address;
5431 memset (mac_address, 0, sizeof (mac_address));
5433 /* Parse args required to build the message */
5434 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5435 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
5438 else if (unformat (i, "del"))
5440 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5441 sw_if_index_set = 1;
5442 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5443 sw_if_index_set = 1;
5444 else if (unformat (i, "is_static"))
5446 else if (unformat (i, "vrf %d", &vrf_id))
5448 else if (unformat (i, "dst %U",
5449 unformat_ip4_address, &v4address))
5451 else if (unformat (i, "dst %U",
5452 unformat_ip6_address, &v6address))
5455 clib_warning ("parse error '%U'", format_unformat_error, i);
5460 if (sw_if_index_set == 0) {
5461 errmsg ("missing interface name or sw_if_index\n");
5464 if (v4_address_set && v6_address_set) {
5465 errmsg ("both v4 and v6 addresses set\n");
5468 if (!v4_address_set && !v6_address_set) {
5469 errmsg ("no address set\n");
5473 /* Construct the API message */
5474 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
5476 mp->sw_if_index = ntohl (sw_if_index);
5477 mp->is_add = is_add;
5478 mp->vrf_id = ntohl (vrf_id);
5479 mp->is_static = is_static;
5481 clib_memcpy (mp->mac_address, mac_address, 6);
5482 if (v6_address_set) {
5484 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
5486 /* mp->is_ipv6 = 0; via memset in M macro above */
5487 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
5493 /* Wait for a reply, return good/bad news */
5500 static int api_reset_vrf (vat_main_t * vam)
5502 unformat_input_t * i = vam->input;
5503 vl_api_reset_vrf_t *mp;
5509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5510 if (unformat (i, "vrf %d", &vrf_id))
5512 else if (unformat (i, "ipv6"))
5515 clib_warning ("parse error '%U'", format_unformat_error, i);
5520 if (vrf_id_set == 0) {
5521 errmsg ("missing vrf id\n");
5525 M(RESET_VRF, reset_vrf);
5527 mp->vrf_id = ntohl(vrf_id);
5528 mp->is_ipv6 = is_ipv6;
5535 static int api_create_vlan_subif (vat_main_t * vam)
5537 unformat_input_t * i = vam->input;
5538 vl_api_create_vlan_subif_t *mp;
5541 u8 sw_if_index_set = 0;
5545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5546 if (unformat (i, "sw_if_index %d", &sw_if_index))
5547 sw_if_index_set = 1;
5548 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5549 sw_if_index_set = 1;
5550 else if (unformat (i, "vlan %d", &vlan_id))
5553 clib_warning ("parse error '%U'", format_unformat_error, i);
5558 if (sw_if_index_set == 0) {
5559 errmsg ("missing interface name or sw_if_index\n");
5563 if (vlan_id_set == 0) {
5564 errmsg ("missing vlan_id\n");
5567 M(CREATE_VLAN_SUBIF, create_vlan_subif);
5569 mp->sw_if_index = ntohl(sw_if_index);
5570 mp->vlan_id = ntohl(vlan_id);
5577 #define foreach_create_subif_bit \
5584 _(outer_vlan_id_any) \
5585 _(inner_vlan_id_any)
5587 static int api_create_subif (vat_main_t * vam)
5589 unformat_input_t * i = vam->input;
5590 vl_api_create_subif_t *mp;
5593 u8 sw_if_index_set = 0;
5600 u32 exact_match = 0;
5601 u32 default_sub = 0;
5602 u32 outer_vlan_id_any = 0;
5603 u32 inner_vlan_id_any = 0;
5605 u16 outer_vlan_id = 0;
5606 u16 inner_vlan_id = 0;
5608 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5609 if (unformat (i, "sw_if_index %d", &sw_if_index))
5610 sw_if_index_set = 1;
5611 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5612 sw_if_index_set = 1;
5613 else if (unformat (i, "sub_id %d", &sub_id))
5615 else if (unformat (i, "outer_vlan_id %d", &tmp))
5616 outer_vlan_id = tmp;
5617 else if (unformat (i, "inner_vlan_id %d", &tmp))
5618 inner_vlan_id = tmp;
5620 #define _(a) else if (unformat (i, #a)) a = 1 ;
5621 foreach_create_subif_bit
5625 clib_warning ("parse error '%U'", format_unformat_error, i);
5630 if (sw_if_index_set == 0) {
5631 errmsg ("missing interface name or sw_if_index\n");
5635 if (sub_id_set == 0) {
5636 errmsg ("missing sub_id\n");
5639 M(CREATE_SUBIF, create_subif);
5641 mp->sw_if_index = ntohl(sw_if_index);
5642 mp->sub_id = ntohl(sub_id);
5644 #define _(a) mp->a = a;
5645 foreach_create_subif_bit;
5648 mp->outer_vlan_id = ntohs (outer_vlan_id);
5649 mp->inner_vlan_id = ntohs (inner_vlan_id);
5656 static int api_oam_add_del (vat_main_t * vam)
5658 unformat_input_t * i = vam->input;
5659 vl_api_oam_add_del_t *mp;
5663 ip4_address_t src, dst;
5667 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5668 if (unformat (i, "vrf %d", &vrf_id))
5670 else if (unformat (i, "src %U", unformat_ip4_address, &src))
5672 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
5674 else if (unformat (i, "del"))
5677 clib_warning ("parse error '%U'", format_unformat_error, i);
5683 errmsg ("missing src addr\n");
5688 errmsg ("missing dst addr\n");
5692 M(OAM_ADD_DEL, oam_add_del);
5694 mp->vrf_id = ntohl(vrf_id);
5695 mp->is_add = is_add;
5696 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
5697 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
5704 static int api_reset_fib (vat_main_t * vam)
5706 unformat_input_t * i = vam->input;
5707 vl_api_reset_fib_t *mp;
5713 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5714 if (unformat (i, "vrf %d", &vrf_id))
5716 else if (unformat (i, "ipv6"))
5719 clib_warning ("parse error '%U'", format_unformat_error, i);
5724 if (vrf_id_set == 0) {
5725 errmsg ("missing vrf id\n");
5729 M(RESET_FIB, reset_fib);
5731 mp->vrf_id = ntohl(vrf_id);
5732 mp->is_ipv6 = is_ipv6;
5739 static int api_dhcp_proxy_config (vat_main_t * vam)
5741 unformat_input_t * i = vam->input;
5742 vl_api_dhcp_proxy_config_t *mp;
5747 u8 v4_address_set = 0;
5748 u8 v6_address_set = 0;
5749 ip4_address_t v4address;
5750 ip6_address_t v6address;
5751 u8 v4_src_address_set = 0;
5752 u8 v6_src_address_set = 0;
5753 ip4_address_t v4srcaddress;
5754 ip6_address_t v6srcaddress;
5756 /* Parse args required to build the message */
5757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5758 if (unformat (i, "del"))
5760 else if (unformat (i, "vrf %d", &vrf_id))
5762 else if (unformat (i, "insert-cid %d", &insert_cid))
5764 else if (unformat (i, "svr %U",
5765 unformat_ip4_address, &v4address))
5767 else if (unformat (i, "svr %U",
5768 unformat_ip6_address, &v6address))
5770 else if (unformat (i, "src %U",
5771 unformat_ip4_address, &v4srcaddress))
5772 v4_src_address_set = 1;
5773 else if (unformat (i, "src %U",
5774 unformat_ip6_address, &v6srcaddress))
5775 v6_src_address_set = 1;
5780 if (v4_address_set && v6_address_set) {
5781 errmsg ("both v4 and v6 server addresses set\n");
5784 if (!v4_address_set && !v6_address_set) {
5785 errmsg ("no server addresses set\n");
5789 if (v4_src_address_set && v6_src_address_set) {
5790 errmsg ("both v4 and v6 src addresses set\n");
5793 if (!v4_src_address_set && !v6_src_address_set) {
5794 errmsg ("no src addresses set\n");
5798 if (!(v4_src_address_set && v4_address_set) &&
5799 !(v6_src_address_set && v6_address_set)) {
5800 errmsg ("no matching server and src addresses set\n");
5804 /* Construct the API message */
5805 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5807 mp->insert_circuit_id = insert_cid;
5808 mp->is_add = is_add;
5809 mp->vrf_id = ntohl (vrf_id);
5810 if (v6_address_set) {
5812 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5813 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5815 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5816 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5822 /* Wait for a reply, return good/bad news */
5828 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5830 unformat_input_t * i = vam->input;
5831 vl_api_dhcp_proxy_config_2_t *mp;
5834 u32 server_vrf_id = 0;
5837 u8 v4_address_set = 0;
5838 u8 v6_address_set = 0;
5839 ip4_address_t v4address;
5840 ip6_address_t v6address;
5841 u8 v4_src_address_set = 0;
5842 u8 v6_src_address_set = 0;
5843 ip4_address_t v4srcaddress;
5844 ip6_address_t v6srcaddress;
5846 /* Parse args required to build the message */
5847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5848 if (unformat (i, "del"))
5850 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5852 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5854 else if (unformat (i, "insert-cid %d", &insert_cid))
5856 else if (unformat (i, "svr %U",
5857 unformat_ip4_address, &v4address))
5859 else if (unformat (i, "svr %U",
5860 unformat_ip6_address, &v6address))
5862 else if (unformat (i, "src %U",
5863 unformat_ip4_address, &v4srcaddress))
5864 v4_src_address_set = 1;
5865 else if (unformat (i, "src %U",
5866 unformat_ip6_address, &v6srcaddress))
5867 v6_src_address_set = 1;
5872 if (v4_address_set && v6_address_set) {
5873 errmsg ("both v4 and v6 server addresses set\n");
5876 if (!v4_address_set && !v6_address_set) {
5877 errmsg ("no server addresses set\n");
5881 if (v4_src_address_set && v6_src_address_set) {
5882 errmsg ("both v4 and v6 src addresses set\n");
5885 if (!v4_src_address_set && !v6_src_address_set) {
5886 errmsg ("no src addresses set\n");
5890 if (!(v4_src_address_set && v4_address_set) &&
5891 !(v6_src_address_set && v6_address_set)) {
5892 errmsg ("no matching server and src addresses set\n");
5896 /* Construct the API message */
5897 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5899 mp->insert_circuit_id = insert_cid;
5900 mp->is_add = is_add;
5901 mp->rx_vrf_id = ntohl (rx_vrf_id);
5902 mp->server_vrf_id = ntohl (server_vrf_id);
5903 if (v6_address_set) {
5905 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5906 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5908 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5909 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5915 /* Wait for a reply, return good/bad news */
5921 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5923 unformat_input_t * i = vam->input;
5924 vl_api_dhcp_proxy_set_vss_t *mp;
5935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5936 if (unformat (i, "tbl_id %d", &tbl_id))
5938 if (unformat (i, "fib_id %d", &fib_id))
5940 if (unformat (i, "oui %d", &oui))
5942 else if (unformat (i, "ipv6"))
5944 else if (unformat (i, "del"))
5947 clib_warning ("parse error '%U'", format_unformat_error, i);
5952 if (tbl_id_set == 0) {
5953 errmsg ("missing tbl id\n");
5957 if (fib_id_set == 0) {
5958 errmsg ("missing fib id\n");
5962 errmsg ("missing oui\n");
5966 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5967 mp->tbl_id = ntohl(tbl_id);
5968 mp->fib_id = ntohl(fib_id);
5969 mp->oui = ntohl(oui);
5970 mp->is_ipv6 = is_ipv6;
5971 mp->is_add = is_add;
5978 static int api_dhcp_client_config (vat_main_t * vam)
5980 unformat_input_t * i = vam->input;
5981 vl_api_dhcp_client_config_t *mp;
5984 u8 sw_if_index_set = 0;
5987 u8 disable_event = 0;
5989 /* Parse args required to build the message */
5990 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5991 if (unformat (i, "del"))
5993 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5994 sw_if_index_set = 1;
5995 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5996 sw_if_index_set = 1;
5997 else if (unformat (i, "hostname %s", &hostname))
5999 else if (unformat (i, "disable_event"))
6005 if (sw_if_index_set == 0) {
6006 errmsg ("missing interface name or sw_if_index\n");
6010 if (vec_len (hostname) > 63) {
6011 errmsg ("hostname too long\n");
6013 vec_add1 (hostname, 0);
6015 /* Construct the API message */
6016 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
6018 mp->sw_if_index = ntohl (sw_if_index);
6019 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
6020 vec_free (hostname);
6021 mp->is_add = is_add;
6022 mp->want_dhcp_event = disable_event ? 0 : 1;
6028 /* Wait for a reply, return good/bad news */
6034 static int api_set_ip_flow_hash (vat_main_t * vam)
6036 unformat_input_t * i = vam->input;
6037 vl_api_set_ip_flow_hash_t *mp;
6049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6050 if (unformat (i, "vrf %d", &vrf_id))
6052 else if (unformat (i, "ipv6"))
6054 else if (unformat (i, "src"))
6056 else if (unformat (i, "dst"))
6058 else if (unformat (i, "sport"))
6060 else if (unformat (i, "dport"))
6062 else if (unformat (i, "proto"))
6064 else if (unformat (i, "reverse"))
6068 clib_warning ("parse error '%U'", format_unformat_error, i);
6073 if (vrf_id_set == 0) {
6074 errmsg ("missing vrf id\n");
6078 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
6084 mp->reverse = reverse;
6085 mp->vrf_id = ntohl(vrf_id);
6086 mp->is_ipv6 = is_ipv6;
6093 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6095 unformat_input_t * i = vam->input;
6096 vl_api_sw_interface_ip6_enable_disable_t *mp;
6099 u8 sw_if_index_set = 0;
6102 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6103 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6104 sw_if_index_set = 1;
6105 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6106 sw_if_index_set = 1;
6107 else if (unformat (i, "enable"))
6109 else if (unformat (i, "disable"))
6112 clib_warning ("parse error '%U'", format_unformat_error, i);
6117 if (sw_if_index_set == 0) {
6118 errmsg ("missing interface name or sw_if_index\n");
6122 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
6124 mp->sw_if_index = ntohl(sw_if_index);
6125 mp->enable = enable;
6132 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
6134 unformat_input_t * i = vam->input;
6135 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
6138 u8 sw_if_index_set = 0;
6139 u32 address_length = 0;
6140 u8 v6_address_set = 0;
6141 ip6_address_t v6address;
6143 /* Parse args required to build the message */
6144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6145 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6146 sw_if_index_set = 1;
6147 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6148 sw_if_index_set = 1;
6149 else if (unformat (i, "%U/%d",
6150 unformat_ip6_address, &v6address,
6157 if (sw_if_index_set == 0) {
6158 errmsg ("missing interface name or sw_if_index\n");
6161 if (!v6_address_set) {
6162 errmsg ("no address set\n");
6166 /* Construct the API message */
6167 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
6168 sw_interface_ip6_set_link_local_address);
6170 mp->sw_if_index = ntohl (sw_if_index);
6171 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6172 mp->address_length = address_length;
6177 /* Wait for a reply, return good/bad news */
6185 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
6187 unformat_input_t * i = vam->input;
6188 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
6191 u8 sw_if_index_set = 0;
6192 u32 address_length = 0;
6193 u8 v6_address_set = 0;
6194 ip6_address_t v6address;
6196 u8 no_advertise = 0;
6198 u8 no_autoconfig = 0;
6201 u32 val_lifetime = 0;
6202 u32 pref_lifetime = 0;
6204 /* Parse args required to build the message */
6205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6206 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6207 sw_if_index_set = 1;
6208 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6209 sw_if_index_set = 1;
6210 else if (unformat (i, "%U/%d",
6211 unformat_ip6_address, &v6address,
6214 else if (unformat (i, "val_life %d", &val_lifetime))
6216 else if (unformat (i, "pref_life %d", &pref_lifetime))
6218 else if (unformat (i, "def"))
6220 else if (unformat (i, "noadv"))
6222 else if (unformat (i, "offl"))
6224 else if (unformat (i, "noauto"))
6226 else if (unformat (i, "nolink"))
6228 else if (unformat (i, "isno"))
6231 clib_warning ("parse error '%U'", format_unformat_error, i);
6236 if (sw_if_index_set == 0) {
6237 errmsg ("missing interface name or sw_if_index\n");
6240 if (!v6_address_set) {
6241 errmsg ("no address set\n");
6245 /* Construct the API message */
6246 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
6248 mp->sw_if_index = ntohl (sw_if_index);
6249 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6250 mp->address_length = address_length;
6251 mp->use_default = use_default;
6252 mp->no_advertise = no_advertise;
6253 mp->off_link = off_link;
6254 mp->no_autoconfig = no_autoconfig;
6255 mp->no_onlink = no_onlink;
6257 mp->val_lifetime = ntohl(val_lifetime);
6258 mp->pref_lifetime = ntohl(pref_lifetime);
6263 /* Wait for a reply, return good/bad news */
6270 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
6272 unformat_input_t * i = vam->input;
6273 vl_api_sw_interface_ip6nd_ra_config_t *mp;
6276 u8 sw_if_index_set = 0;
6281 u8 send_unicast = 0;
6284 u8 default_router = 0;
6285 u32 max_interval = 0;
6286 u32 min_interval = 0;
6288 u32 initial_count = 0;
6289 u32 initial_interval = 0;
6292 /* Parse args required to build the message */
6293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6294 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6295 sw_if_index_set = 1;
6296 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6297 sw_if_index_set = 1;
6298 else if (unformat (i, "maxint %d", &max_interval))
6300 else if (unformat (i, "minint %d", &min_interval))
6302 else if (unformat (i, "life %d", &lifetime))
6304 else if (unformat (i, "count %d", &initial_count))
6306 else if (unformat (i, "interval %d", &initial_interval))
6308 else if (unformat (i, "suppress") || unformat (i, "surpress"))
6310 else if (unformat (i, "managed"))
6312 else if (unformat (i, "other"))
6314 else if (unformat (i, "ll"))
6316 else if (unformat (i, "send"))
6318 else if (unformat (i, "cease"))
6320 else if (unformat (i, "isno"))
6322 else if (unformat (i, "def"))
6325 clib_warning ("parse error '%U'", format_unformat_error, i);
6330 if (sw_if_index_set == 0) {
6331 errmsg ("missing interface name or sw_if_index\n");
6335 /* Construct the API message */
6336 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
6338 mp->sw_if_index = ntohl (sw_if_index);
6339 mp->max_interval = ntohl(max_interval);
6340 mp->min_interval = ntohl(min_interval);
6341 mp->lifetime = ntohl(lifetime);
6342 mp->initial_count = ntohl(initial_count);
6343 mp->initial_interval = ntohl(initial_interval);
6344 mp->suppress = suppress;
6345 mp->managed = managed;
6347 mp->ll_option = ll_option;
6348 mp->send_unicast = send_unicast;
6351 mp->default_router = default_router;
6356 /* Wait for a reply, return good/bad news */
6363 static int api_set_arp_neighbor_limit (vat_main_t * vam)
6365 unformat_input_t * i = vam->input;
6366 vl_api_set_arp_neighbor_limit_t *mp;
6372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6373 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
6375 else if (unformat (i, "ipv6"))
6378 clib_warning ("parse error '%U'", format_unformat_error, i);
6383 if (limit_set == 0) {
6384 errmsg ("missing limit value\n");
6388 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
6390 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
6391 mp->is_ipv6 = is_ipv6;
6398 static int api_l2_patch_add_del (vat_main_t * vam)
6400 unformat_input_t * i = vam->input;
6401 vl_api_l2_patch_add_del_t *mp;
6404 u8 rx_sw_if_index_set = 0;
6406 u8 tx_sw_if_index_set = 0;
6409 /* Parse args required to build the message */
6410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6411 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6412 rx_sw_if_index_set = 1;
6413 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6414 tx_sw_if_index_set = 1;
6415 else if (unformat (i, "rx")) {
6416 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6417 if (unformat (i, "%U", unformat_sw_if_index, vam,
6419 rx_sw_if_index_set = 1;
6422 } else if (unformat (i, "tx")) {
6423 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6424 if (unformat (i, "%U", unformat_sw_if_index, vam,
6426 tx_sw_if_index_set = 1;
6429 } else if (unformat (i, "del"))
6435 if (rx_sw_if_index_set == 0) {
6436 errmsg ("missing rx interface name or rx_sw_if_index\n");
6440 if (tx_sw_if_index_set == 0) {
6441 errmsg ("missing tx interface name or tx_sw_if_index\n");
6445 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
6447 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
6448 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
6449 mp->is_add = is_add;
6455 static int api_trace_profile_add (vat_main_t *vam)
6457 unformat_input_t * input = vam->input;
6458 vl_api_trace_profile_add_t *mp;
6461 u32 trace_option_elts = 0;
6462 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
6463 int has_pow_option = 0;
6464 int has_ppc_option = 0;
6466 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6468 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
6469 "trace-tsp %d node-id 0x%x app-data 0x%x",
6470 &id, &trace_type, &trace_option_elts, &trace_tsp,
6471 &node_id, &app_data))
6473 else if (unformat (input, "pow"))
6475 else if (unformat (input, "ppc encap"))
6476 has_ppc_option = PPC_ENCAP;
6477 else if (unformat (input, "ppc decap"))
6478 has_ppc_option = PPC_DECAP;
6479 else if (unformat (input, "ppc none"))
6480 has_ppc_option = PPC_NONE;
6484 M(TRACE_PROFILE_ADD, trace_profile_add);
6486 mp->trace_type = trace_type;
6487 mp->trace_num_elt = trace_option_elts;
6488 mp->trace_ppc = has_ppc_option;
6489 mp->trace_app_data = htonl(app_data);
6490 mp->pow_enable = has_pow_option;
6491 mp->trace_tsp = trace_tsp;
6492 mp->node_id = htonl(node_id);
6499 static int api_trace_profile_apply (vat_main_t *vam)
6501 unformat_input_t * input = vam->input;
6502 vl_api_trace_profile_apply_t *mp;
6505 u32 mask_width = ~0;
6512 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6514 if (unformat (input, "%U/%d",
6515 unformat_ip6_address, &addr, &mask_width))
6517 else if (unformat (input, "id %d", &id))
6519 else if (unformat (input, "vrf-id %d", &vrf_id))
6521 else if (unformat (input, "add"))
6523 else if (unformat (input, "pop"))
6525 else if (unformat (input, "none"))
6531 if ((is_add + is_pop + is_none) != 1) {
6532 errmsg("One of (add, pop, none) required");
6535 if (mask_width == ~0) {
6536 errmsg("<address>/<mask-width> required");
6539 M(TRACE_PROFILE_APPLY, trace_profile_apply);
6540 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
6542 mp->prefix_length = htonl(mask_width);
6543 mp->vrf_id = htonl(vrf_id);
6545 mp->trace_op = IOAM_HBYH_ADD;
6547 mp->trace_op = IOAM_HBYH_POP;
6549 mp->trace_op = IOAM_HBYH_MOD;
6561 static int api_trace_profile_del (vat_main_t *vam)
6563 vl_api_trace_profile_del_t *mp;
6566 M(TRACE_PROFILE_DEL, trace_profile_del);
6571 static int api_sr_tunnel_add_del (vat_main_t * vam)
6573 unformat_input_t * i = vam->input;
6574 vl_api_sr_tunnel_add_del_t *mp;
6578 ip6_address_t src_address;
6579 int src_address_set = 0;
6580 ip6_address_t dst_address;
6582 int dst_address_set = 0;
6584 u32 rx_table_id = 0;
6585 u32 tx_table_id = 0;
6586 ip6_address_t * segments = 0;
6587 ip6_address_t * this_seg;
6588 ip6_address_t * tags = 0;
6589 ip6_address_t * this_tag;
6590 ip6_address_t next_address, tag;
6592 u8 * policy_name = 0;
6594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6596 if (unformat (i, "del"))
6598 else if (unformat (i, "name %s", &name))
6600 else if (unformat (i, "policy %s", &policy_name))
6602 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
6604 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
6606 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
6607 src_address_set = 1;
6608 else if (unformat (i, "dst %U/%d",
6609 unformat_ip6_address, &dst_address,
6611 dst_address_set = 1;
6612 else if (unformat (i, "next %U", unformat_ip6_address,
6615 vec_add2 (segments, this_seg, 1);
6616 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
6618 else if (unformat (i, "tag %U", unformat_ip6_address,
6621 vec_add2 (tags, this_tag, 1);
6622 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
6624 else if (unformat (i, "clean"))
6625 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
6626 else if (unformat (i, "protected"))
6627 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
6628 else if (unformat (i, "InPE %d", &pl_index))
6630 if (pl_index <= 0 || pl_index > 4)
6632 pl_index_range_error:
6633 errmsg ("pl index %d out of range\n", pl_index);
6636 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
6638 else if (unformat (i, "EgPE %d", &pl_index))
6640 if (pl_index <= 0 || pl_index > 4)
6641 goto pl_index_range_error;
6642 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
6644 else if (unformat (i, "OrgSrc %d", &pl_index))
6646 if (pl_index <= 0 || pl_index > 4)
6647 goto pl_index_range_error;
6648 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
6654 if (!src_address_set)
6656 errmsg ("src address required\n");
6660 if (!dst_address_set)
6662 errmsg ("dst address required\n");
6668 errmsg ("at least one sr segment required\n");
6672 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
6673 vec_len(segments) * sizeof (ip6_address_t)
6674 + vec_len(tags) * sizeof (ip6_address_t));
6676 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
6677 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
6678 mp->dst_mask_width = dst_mask_width;
6679 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
6680 mp->n_segments = vec_len (segments);
6681 mp->n_tags = vec_len (tags);
6682 mp->is_add = is_del == 0;
6683 clib_memcpy (mp->segs_and_tags, segments,
6684 vec_len(segments)* sizeof (ip6_address_t));
6685 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
6686 tags, vec_len(tags)* sizeof (ip6_address_t));
6688 mp->outer_vrf_id = ntohl (rx_table_id);
6689 mp->inner_vrf_id = ntohl (tx_table_id);
6690 memcpy (mp->name, name, vec_len(name));
6691 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6693 vec_free (segments);
6700 static int api_sr_policy_add_del (vat_main_t * vam)
6702 unformat_input_t * input = vam->input;
6703 vl_api_sr_policy_add_del_t *mp;
6707 u8 * tunnel_name = 0;
6708 u8 ** tunnel_names = 0;
6713 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
6714 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
6716 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6718 if (unformat (input, "del"))
6720 else if (unformat (input, "name %s", &name))
6722 else if (unformat (input, "tunnel %s", &tunnel_name))
6726 vec_add1 (tunnel_names, tunnel_name);
6728 - length = #bytes to store in serial vector
6729 - +1 = byte to store that length
6731 tunnel_names_length += (vec_len (tunnel_name) + 1);
6742 errmsg ("policy name required\n");
6746 if ((!tunnel_set) && (!is_del))
6748 errmsg ("tunnel name required\n");
6752 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6756 mp->is_add = !is_del;
6758 memcpy (mp->name, name, vec_len(name));
6759 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6760 u8 * serial_orig = 0;
6761 vec_validate (serial_orig, tunnel_names_length);
6762 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6763 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6765 for (j=0; j < vec_len(tunnel_names); j++)
6767 tun_name_len = vec_len (tunnel_names[j]);
6768 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6769 serial_orig += 1; // Move along one byte to store the actual tunnel name
6770 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6771 serial_orig += tun_name_len; // Advance past the copy
6773 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6775 vec_free (tunnel_names);
6776 vec_free (tunnel_name);
6782 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6784 unformat_input_t * input = vam->input;
6785 vl_api_sr_multicast_map_add_del_t *mp;
6788 ip6_address_t multicast_address;
6789 u8 * policy_name = 0;
6790 int multicast_address_set = 0;
6792 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6794 if (unformat (input, "del"))
6796 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6797 multicast_address_set = 1;
6798 else if (unformat (input, "sr-policy %s", &policy_name))
6804 if (!is_del && !policy_name)
6806 errmsg ("sr-policy name required\n");
6811 if (!multicast_address_set)
6813 errmsg ("address required\n");
6817 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6819 mp->is_add = !is_del;
6820 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6821 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6824 vec_free (policy_name);
6831 #define foreach_ip4_proto_field \
6841 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6843 u8 ** maskp = va_arg (*args, u8 **);
6845 u8 found_something = 0;
6848 #define _(a) u8 a=0;
6849 foreach_ip4_proto_field;
6855 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6857 if (unformat (input, "version"))
6859 else if (unformat (input, "hdr_length"))
6861 else if (unformat (input, "src"))
6863 else if (unformat (input, "dst"))
6865 else if (unformat (input, "proto"))
6868 #define _(a) else if (unformat (input, #a)) a=1;
6869 foreach_ip4_proto_field
6875 #define _(a) found_something += a;
6876 foreach_ip4_proto_field;
6879 if (found_something == 0)
6882 vec_validate (mask, sizeof (*ip) - 1);
6884 ip = (ip4_header_t *) mask;
6886 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6887 foreach_ip4_proto_field;
6890 ip->ip_version_and_header_length = 0;
6893 ip->ip_version_and_header_length |= 0xF0;
6896 ip->ip_version_and_header_length |= 0x0F;
6902 #define foreach_ip6_proto_field \
6909 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6911 u8 ** maskp = va_arg (*args, u8 **);
6913 u8 found_something = 0;
6915 u32 ip_version_traffic_class_and_flow_label;
6917 #define _(a) u8 a=0;
6918 foreach_ip6_proto_field;
6921 u8 traffic_class = 0;
6924 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6926 if (unformat (input, "version"))
6928 else if (unformat (input, "traffic-class"))
6930 else if (unformat (input, "flow-label"))
6932 else if (unformat (input, "src"))
6934 else if (unformat (input, "dst"))
6936 else if (unformat (input, "proto"))
6939 #define _(a) else if (unformat (input, #a)) a=1;
6940 foreach_ip6_proto_field
6946 #define _(a) found_something += a;
6947 foreach_ip6_proto_field;
6950 if (found_something == 0)
6953 vec_validate (mask, sizeof (*ip) - 1);
6955 ip = (ip6_header_t *) mask;
6957 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6958 foreach_ip6_proto_field;
6961 ip_version_traffic_class_and_flow_label = 0;
6964 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6967 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6970 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6972 ip->ip_version_traffic_class_and_flow_label =
6973 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6979 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6981 u8 ** maskp = va_arg (*args, u8 **);
6983 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6984 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6986 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6994 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6996 u8 ** maskp = va_arg (*args, u8 **);
7011 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7012 if (unformat (input, "src"))
7014 else if (unformat (input, "dst"))
7016 else if (unformat (input, "proto"))
7018 else if (unformat (input, "tag1"))
7020 else if (unformat (input, "tag2"))
7022 else if (unformat (input, "ignore-tag1"))
7024 else if (unformat (input, "ignore-tag2"))
7026 else if (unformat (input, "cos1"))
7028 else if (unformat (input, "cos2"))
7030 else if (unformat (input, "dot1q"))
7032 else if (unformat (input, "dot1ad"))
7037 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7038 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7041 if (tag1 || ignore_tag1 || cos1 || dot1q)
7043 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7046 vec_validate (mask, len-1);
7049 memset (mask, 0xff, 6);
7052 memset (mask + 6, 0xff, 6);
7056 /* inner vlan tag */
7065 mask[21] = mask [20] = 0xff;
7086 mask[16] = mask [17] = 0xff;
7096 mask[12] = mask [13] = 0xff;
7102 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
7104 u8 ** maskp = va_arg (*args, u8 **);
7105 u32 * skipp = va_arg (*args, u32 *);
7106 u32 * matchp = va_arg (*args, u32 *);
7113 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7114 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7116 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7118 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7124 if (mask || l2 || l3)
7128 /* "With a free Ethernet header in every package" */
7130 vec_validate (l2, 13);
7132 vec_append (mask, l3);
7136 /* Scan forward looking for the first significant mask octet */
7137 for (i = 0; i < vec_len (mask); i++)
7141 /* compute (skip, match) params */
7142 *skipp = i / sizeof(u32x4);
7143 vec_delete (mask, *skipp * sizeof(u32x4), 0);
7145 /* Pad mask to an even multiple of the vector size */
7146 while (vec_len (mask) % sizeof (u32x4))
7149 match = vec_len (mask) / sizeof (u32x4);
7151 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
7153 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
7154 if (*tmp || *(tmp+1))
7159 clib_warning ("BUG: match 0");
7161 _vec_len (mask) = match * sizeof(u32x4);
7172 #define foreach_l2_next \
7174 _(ethernet, ETHERNET_INPUT) \
7178 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
7180 u32 * miss_next_indexp = va_arg (*args, u32 *);
7185 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
7189 if (unformat (input, "%d", &tmp))
7198 *miss_next_indexp = next_index;
7202 #define foreach_ip_next \
7208 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
7210 u32 * miss_next_indexp = va_arg (*args, u32 *);
7215 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7219 if (unformat (input, "%d", &tmp))
7228 *miss_next_indexp = next_index;
7232 #define foreach_acl_next \
7235 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
7237 u32 * miss_next_indexp = va_arg (*args, u32 *);
7242 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7246 if (unformat (input, "permit"))
7251 else if (unformat (input, "%d", &tmp))
7260 *miss_next_indexp = next_index;
7264 uword unformat_policer_precolor (unformat_input_t * input, va_list * args)
7266 u32 * r = va_arg (*args, u32 *);
7268 if (unformat (input, "conform-color"))
7269 *r = POLICE_CONFORM;
7270 else if (unformat (input, "exceed-color"))
7278 static int api_classify_add_del_table (vat_main_t * vam)
7280 unformat_input_t * i = vam->input;
7281 vl_api_classify_add_del_table_t *mp;
7287 u32 table_index = ~0;
7288 u32 next_table_index = ~0;
7289 u32 miss_next_index = ~0;
7290 u32 memory_size = 32<<20;
7294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7295 if (unformat (i, "del"))
7297 else if (unformat (i, "buckets %d", &nbuckets))
7299 else if (unformat (i, "memory_size %d", &memory_size))
7301 else if (unformat (i, "skip %d", &skip))
7303 else if (unformat (i, "match %d", &match))
7305 else if (unformat (i, "table %d", &table_index))
7307 else if (unformat (i, "mask %U", unformat_classify_mask,
7308 &mask, &skip, &match))
7310 else if (unformat (i, "next-table %d", &next_table_index))
7312 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
7315 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
7318 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
7325 if (is_add && mask == 0) {
7326 errmsg ("Mask required\n");
7330 if (is_add && skip == ~0) {
7331 errmsg ("skip count required\n");
7335 if (is_add && match == ~0) {
7336 errmsg ("match count required\n");
7340 if (!is_add && table_index == ~0) {
7341 errmsg ("table index required for delete\n");
7345 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
7348 mp->is_add = is_add;
7349 mp->table_index = ntohl(table_index);
7350 mp->nbuckets = ntohl(nbuckets);
7351 mp->memory_size = ntohl(memory_size);
7352 mp->skip_n_vectors = ntohl(skip);
7353 mp->match_n_vectors = ntohl(match);
7354 mp->next_table_index = ntohl(next_table_index);
7355 mp->miss_next_index = ntohl(miss_next_index);
7356 clib_memcpy (mp->mask, mask, vec_len(mask));
7364 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
7366 u8 ** matchp = va_arg (*args, u8 **);
7373 int src = 0, dst = 0;
7374 ip4_address_t src_val, dst_val;
7381 int fragment_id = 0;
7382 u32 fragment_id_val;
7388 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7390 if (unformat (input, "version %d", &version_val))
7392 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7394 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7396 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7398 else if (unformat (input, "proto %d", &proto_val))
7400 else if (unformat (input, "tos %d", &tos_val))
7402 else if (unformat (input, "length %d", &length_val))
7404 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7406 else if (unformat (input, "ttl %d", &ttl_val))
7408 else if (unformat (input, "checksum %d", &checksum_val))
7414 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7415 + ttl + checksum == 0)
7419 * Aligned because we use the real comparison functions
7421 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7423 ip = (ip4_header_t *) match;
7425 /* These are realistically matched in practice */
7427 ip->src_address.as_u32 = src_val.as_u32;
7430 ip->dst_address.as_u32 = dst_val.as_u32;
7433 ip->protocol = proto_val;
7436 /* These are not, but they're included for completeness */
7438 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
7441 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7447 ip->length = length_val;
7453 ip->checksum = checksum_val;
7459 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
7461 u8 ** matchp = va_arg (*args, u8 **);
7467 u32 traffic_class_val;
7470 int src = 0, dst = 0;
7471 ip6_address_t src_val, dst_val;
7474 int payload_length = 0;
7475 u32 payload_length_val;
7478 u32 ip_version_traffic_class_and_flow_label;
7480 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7482 if (unformat (input, "version %d", &version_val))
7484 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7486 else if (unformat (input, "flow_label %d", &flow_label_val))
7488 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7490 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7492 else if (unformat (input, "proto %d", &proto_val))
7494 else if (unformat (input, "payload_length %d", &payload_length_val))
7496 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7502 if (version + traffic_class + flow_label + src + dst + proto +
7503 payload_length + hop_limit == 0)
7507 * Aligned because we use the real comparison functions
7509 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7511 ip = (ip6_header_t *) match;
7514 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7517 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7520 ip->protocol = proto_val;
7522 ip_version_traffic_class_and_flow_label = 0;
7525 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7528 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
7531 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7533 ip->ip_version_traffic_class_and_flow_label =
7534 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7537 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7540 ip->hop_limit = hop_limit_val;
7546 uword unformat_l3_match (unformat_input_t * input, va_list * args)
7548 u8 ** matchp = va_arg (*args, u8 **);
7550 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7551 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7553 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7561 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
7563 u8 * tagp = va_arg (*args, u8 *);
7566 if (unformat(input, "%d", &tag))
7568 tagp[0] = (tag>>8) & 0x0F;
7569 tagp[1] = tag & 0xFF;
7576 uword unformat_l2_match (unformat_input_t * input, va_list * args)
7578 u8 ** matchp = va_arg (*args, u8 **);
7598 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7599 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7601 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7603 else if (unformat (input, "proto %U",
7604 unformat_ethernet_type_host_byte_order, &proto_val))
7606 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7608 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7610 else if (unformat (input, "ignore-tag1"))
7612 else if (unformat (input, "ignore-tag2"))
7614 else if (unformat (input, "cos1 %d", &cos1_val))
7616 else if (unformat (input, "cos2 %d", &cos2_val))
7621 if ((src + dst + proto + tag1 + tag2 +
7622 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7625 if (tag1 || ignore_tag1 || cos1)
7627 if (tag2 || ignore_tag2 || cos2)
7630 vec_validate_aligned (match, len-1, sizeof(u32x4));
7633 clib_memcpy (match, dst_val, 6);
7636 clib_memcpy (match + 6, src_val, 6);
7640 /* inner vlan tag */
7641 match[19] = tag2_val[1];
7642 match[18] = tag2_val[0];
7644 match [18] |= (cos2_val & 0x7) << 5;
7647 match[21] = proto_val & 0xff;
7648 match[20] = proto_val >> 8;
7652 match [15] = tag1_val[1];
7653 match [14] = tag1_val[0];
7656 match [14] |= (cos1_val & 0x7) << 5;
7662 match [15] = tag1_val[1];
7663 match [14] = tag1_val[0];
7666 match[17] = proto_val & 0xff;
7667 match[16] = proto_val >> 8;
7670 match [14] |= (cos1_val & 0x7) << 5;
7676 match [18] |= (cos2_val & 0x7) << 5;
7678 match [14] |= (cos1_val & 0x7) << 5;
7681 match[13] = proto_val & 0xff;
7682 match[12] = proto_val >> 8;
7690 uword unformat_classify_match (unformat_input_t * input, va_list * args)
7692 u8 ** matchp = va_arg (*args, u8 **);
7693 u32 skip_n_vectors = va_arg (*args, u32);
7694 u32 match_n_vectors = va_arg (*args, u32);
7700 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7701 if (unformat (input, "hex %U", unformat_hex_string, &match))
7703 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7705 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7711 if (match || l2 || l3)
7715 /* "Win a free Ethernet header in every packet" */
7717 vec_validate_aligned (l2, 13, sizeof(u32x4));
7719 vec_append_aligned (match, l3, sizeof(u32x4));
7723 /* Make sure the vector is big enough even if key is all 0's */
7724 vec_validate_aligned
7725 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
7728 /* Set size, include skipped vectors*/
7729 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
7739 static int api_classify_add_del_session (vat_main_t * vam)
7741 unformat_input_t * i = vam->input;
7742 vl_api_classify_add_del_session_t *mp;
7744 u32 table_index = ~0;
7745 u32 hit_next_index = ~0;
7746 u32 opaque_index = ~0;
7750 u32 skip_n_vectors = 0;
7751 u32 match_n_vectors = 0;
7754 * Warning: you have to supply skip_n and match_n
7755 * because the API client cant simply look at the classify
7759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7760 if (unformat (i, "del"))
7762 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7765 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7768 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7771 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
7773 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
7775 else if (unformat (i, "opaque-index %d", &opaque_index))
7777 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7779 else if (unformat (i, "match_n %d", &match_n_vectors))
7781 else if (unformat (i, "match %U", unformat_classify_match,
7782 &match, skip_n_vectors, match_n_vectors))
7784 else if (unformat (i, "advance %d", &advance))
7786 else if (unformat (i, "table-index %d", &table_index))
7792 if (table_index == ~0) {
7793 errmsg ("Table index required\n");
7797 if (is_add && match == 0) {
7798 errmsg ("Match value required\n");
7802 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7805 mp->is_add = is_add;
7806 mp->table_index = ntohl(table_index);
7807 mp->hit_next_index = ntohl(hit_next_index);
7808 mp->opaque_index = ntohl(opaque_index);
7809 mp->advance = ntohl(advance);
7810 clib_memcpy (mp->match, match, vec_len(match));
7817 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7819 unformat_input_t * i = vam->input;
7820 vl_api_classify_set_interface_ip_table_t *mp;
7823 int sw_if_index_set;
7824 u32 table_index = ~0;
7827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7828 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7829 sw_if_index_set = 1;
7830 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7831 sw_if_index_set = 1;
7832 else if (unformat (i, "table %d", &table_index))
7835 clib_warning ("parse error '%U'", format_unformat_error, i);
7840 if (sw_if_index_set == 0) {
7841 errmsg ("missing interface name or sw_if_index\n");
7846 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7848 mp->sw_if_index = ntohl(sw_if_index);
7849 mp->table_index = ntohl(table_index);
7850 mp->is_ipv6 = is_ipv6;
7857 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7859 unformat_input_t * i = vam->input;
7860 vl_api_classify_set_interface_l2_tables_t *mp;
7863 int sw_if_index_set;
7864 u32 ip4_table_index = ~0;
7865 u32 ip6_table_index = ~0;
7866 u32 other_table_index = ~0;
7868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7869 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7870 sw_if_index_set = 1;
7871 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7872 sw_if_index_set = 1;
7873 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7875 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7877 else if (unformat (i, "other-table %d", &other_table_index))
7880 clib_warning ("parse error '%U'", format_unformat_error, i);
7885 if (sw_if_index_set == 0) {
7886 errmsg ("missing interface name or sw_if_index\n");
7891 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7893 mp->sw_if_index = ntohl(sw_if_index);
7894 mp->ip4_table_index = ntohl(ip4_table_index);
7895 mp->ip6_table_index = ntohl(ip6_table_index);
7896 mp->other_table_index = ntohl(other_table_index);
7904 static int api_ipfix_enable (vat_main_t * vam)
7906 unformat_input_t * i = vam->input;
7907 vl_api_ipfix_enable_t *mp;
7908 ip4_address_t collector_address;
7909 u8 collector_address_set = 0;
7910 u32 collector_port = ~0;
7911 ip4_address_t src_address;
7912 u8 src_address_set = 0;
7915 u32 template_interval = ~0;
7918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7919 if (unformat (i, "collector_address %U", unformat_ip4_address,
7920 &collector_address))
7921 collector_address_set = 1;
7922 else if (unformat (i, "collector_port %d", &collector_port))
7924 else if (unformat (i, "src_address %U", unformat_ip4_address,
7926 src_address_set = 1;
7927 else if (unformat (i, "vrf_id %d", &vrf_id))
7929 else if (unformat (i, "path_mtu %d", &path_mtu))
7931 else if (unformat (i, "template_interval %d", &template_interval))
7937 if (collector_address_set == 0) {
7938 errmsg ("collector_address required\n");
7942 if (src_address_set == 0) {
7943 errmsg ("src_address required\n");
7947 M (IPFIX_ENABLE, ipfix_enable);
7949 memcpy(mp->collector_address, collector_address.data,
7950 sizeof(collector_address.data));
7951 mp->collector_port = htons((u16)collector_port);
7952 memcpy(mp->src_address, src_address.data,
7953 sizeof(src_address.data));
7954 mp->vrf_id = htonl(vrf_id);
7955 mp->path_mtu = htonl(path_mtu);
7956 mp->template_interval = htonl(template_interval);
7962 static int api_get_node_index (vat_main_t * vam)
7964 unformat_input_t * i = vam->input;
7965 vl_api_get_node_index_t * mp;
7969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7970 if (unformat (i, "node %s", &name))
7976 errmsg ("node name required\n");
7979 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7980 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7984 M(GET_NODE_INDEX, get_node_index);
7985 clib_memcpy (mp->node_name, name, vec_len(name));
7993 static int api_get_next_index (vat_main_t * vam)
7995 unformat_input_t * i = vam->input;
7996 vl_api_get_next_index_t * mp;
7998 u8 * node_name = 0, * next_node_name = 0;
8000 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8001 if (unformat (i, "node-name %s", &node_name))
8003 else if (unformat (i, "next-node-name %s", &next_node_name))
8007 if (node_name == 0) {
8008 errmsg ("node name required\n");
8011 if (vec_len (node_name) >= ARRAY_LEN(mp->node_name)) {
8012 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
8016 if (next_node_name == 0) {
8017 errmsg ("next node name required\n");
8020 if (vec_len (next_node_name) >= ARRAY_LEN(mp->next_name)) {
8021 errmsg ("next node name too long, max %d\n", ARRAY_LEN(mp->next_name));
8025 M(GET_NEXT_INDEX, get_next_index);
8026 clib_memcpy (mp->node_name, node_name, vec_len(node_name));
8027 clib_memcpy (mp->next_name, next_node_name, vec_len(next_node_name));
8028 vec_free(node_name);
8029 vec_free(next_node_name);
8036 static int api_add_node_next (vat_main_t * vam)
8038 unformat_input_t * i = vam->input;
8039 vl_api_add_node_next_t * mp;
8044 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8045 if (unformat (i, "node %s", &name))
8047 else if (unformat (i, "next %s", &next))
8053 errmsg ("node name required\n");
8056 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
8057 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
8061 errmsg ("next node required\n");
8064 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
8065 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
8069 M(ADD_NODE_NEXT, add_node_next);
8070 clib_memcpy (mp->node_name, name, vec_len(name));
8071 clib_memcpy (mp->next_name, next, vec_len(next));
8080 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
8082 unformat_input_t * i = vam->input;
8083 ip6_address_t client_address, our_address;
8084 int client_address_set = 0;
8085 int our_address_set = 0;
8086 u32 local_session_id = 0;
8087 u32 remote_session_id = 0;
8088 u64 local_cookie = 0;
8089 u64 remote_cookie = 0;
8090 u8 l2_sublayer_present = 0;
8091 vl_api_l2tpv3_create_tunnel_t * mp;
8094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8095 if (unformat (i, "client_address %U", unformat_ip6_address,
8097 client_address_set = 1;
8098 else if (unformat (i, "our_address %U", unformat_ip6_address,
8100 our_address_set = 1;
8101 else if (unformat (i, "local_session_id %d", &local_session_id))
8103 else if (unformat (i, "remote_session_id %d", &remote_session_id))
8105 else if (unformat (i, "local_cookie %lld", &local_cookie))
8107 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
8109 else if (unformat (i, "l2-sublayer-present"))
8110 l2_sublayer_present = 1;
8115 if (client_address_set == 0) {
8116 errmsg ("client_address required\n");
8120 if (our_address_set == 0) {
8121 errmsg ("our_address required\n");
8125 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
8127 clib_memcpy (mp->client_address, client_address.as_u8,
8128 sizeof (mp->client_address));
8130 clib_memcpy (mp->our_address, our_address.as_u8,
8131 sizeof (mp->our_address));
8133 mp->local_session_id = ntohl (local_session_id);
8134 mp->remote_session_id = ntohl (remote_session_id);
8135 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
8136 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
8137 mp->l2_sublayer_present = l2_sublayer_present;
8145 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
8147 unformat_input_t * i = vam->input;
8149 u8 sw_if_index_set = 0;
8150 u64 new_local_cookie = 0;
8151 u64 new_remote_cookie = 0;
8152 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
8155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8156 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8157 sw_if_index_set = 1;
8158 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8159 sw_if_index_set = 1;
8160 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
8162 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
8168 if (sw_if_index_set == 0) {
8169 errmsg ("missing interface name or sw_if_index\n");
8173 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
8175 mp->sw_if_index = ntohl(sw_if_index);
8176 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
8177 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
8184 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
8186 unformat_input_t * i = vam->input;
8187 vl_api_l2tpv3_interface_enable_disable_t *mp;
8190 u8 sw_if_index_set = 0;
8191 u8 enable_disable = 1;
8193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8194 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8195 sw_if_index_set = 1;
8196 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8197 sw_if_index_set = 1;
8198 else if (unformat (i, "enable"))
8200 else if (unformat (i, "disable"))
8206 if (sw_if_index_set == 0) {
8207 errmsg ("missing interface name or sw_if_index\n");
8211 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
8213 mp->sw_if_index = ntohl(sw_if_index);
8214 mp->enable_disable = enable_disable;
8221 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
8223 unformat_input_t * i = vam->input;
8224 vl_api_l2tpv3_set_lookup_key_t * mp;
8228 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8229 if (unformat (i, "lookup_v6_src"))
8230 key = L2T_LOOKUP_SRC_ADDRESS;
8231 else if (unformat (i, "lookup_v6_dst"))
8232 key = L2T_LOOKUP_DST_ADDRESS;
8233 else if (unformat (i, "lookup_session_id"))
8234 key = L2T_LOOKUP_SESSION_ID;
8239 if (key == (u8) ~0) {
8240 errmsg ("l2tp session lookup key unset\n");
8244 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
8253 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
8254 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8256 vat_main_t * vam = &vat_main;
8258 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
8259 format_ip6_address, mp->our_address,
8260 format_ip6_address, mp->client_address,
8261 clib_net_to_host_u32(mp->sw_if_index));
8263 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
8264 clib_net_to_host_u64 (mp->local_cookie[0]),
8265 clib_net_to_host_u64 (mp->local_cookie[1]),
8266 clib_net_to_host_u64 (mp->remote_cookie));
8268 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
8269 clib_net_to_host_u32 (mp->local_session_id),
8270 clib_net_to_host_u32 (mp->remote_session_id));
8272 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
8273 mp->l2_sublayer_present ? "preset" : "absent");
8277 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
8278 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8280 vat_main_t * vam = &vat_main;
8281 vat_json_node_t *node = NULL;
8282 struct in6_addr addr;
8284 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8285 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8286 vat_json_init_array(&vam->json_tree);
8288 node = vat_json_array_add(&vam->json_tree);
8290 vat_json_init_object(node);
8292 clib_memcpy(&addr, mp->our_address, sizeof(addr));
8293 vat_json_object_add_ip6(node, "our_address", addr);
8294 clib_memcpy(&addr, mp->client_address, sizeof(addr));
8295 vat_json_object_add_ip6(node, "client_address", addr);
8297 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
8298 vat_json_init_array(lc);
8299 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
8300 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
8301 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
8303 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
8304 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
8305 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
8306 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
8307 (u8*)"present" : (u8*)"absent");
8310 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
8312 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
8315 /* Get list of l2tpv3-tunnel interfaces */
8316 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
8319 /* Use a control ping for synchronization */
8321 vl_api_control_ping_t * mp;
8322 M(CONTROL_PING, control_ping);
8329 static void vl_api_sw_interface_tap_details_t_handler
8330 (vl_api_sw_interface_tap_details_t * mp)
8332 vat_main_t * vam = &vat_main;
8334 fformat(vam->ofp, "%-16s %d\n",
8336 clib_net_to_host_u32(mp->sw_if_index));
8339 static void vl_api_sw_interface_tap_details_t_handler_json
8340 (vl_api_sw_interface_tap_details_t * mp)
8342 vat_main_t * vam = &vat_main;
8343 vat_json_node_t *node = NULL;
8345 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8346 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8347 vat_json_init_array(&vam->json_tree);
8349 node = vat_json_array_add(&vam->json_tree);
8351 vat_json_init_object(node);
8352 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8353 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
8356 static int api_sw_interface_tap_dump (vat_main_t * vam)
8358 vl_api_sw_interface_tap_dump_t *mp;
8361 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
8362 /* Get list of tap interfaces */
8363 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
8366 /* Use a control ping for synchronization */
8368 vl_api_control_ping_t * mp;
8369 M(CONTROL_PING, control_ping);
8375 static uword unformat_vxlan_decap_next
8376 (unformat_input_t * input, va_list * args)
8378 u32 * result = va_arg (*args, u32 *);
8381 if (unformat (input, "drop"))
8382 *result = VXLAN_INPUT_NEXT_DROP;
8383 else if (unformat (input, "ip4"))
8384 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
8385 else if (unformat (input, "ip6"))
8386 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
8387 else if (unformat (input, "l2"))
8388 *result = VXLAN_INPUT_NEXT_L2_INPUT;
8389 else if (unformat (input, "%d", &tmp))
8396 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
8398 unformat_input_t * line_input = vam->input;
8399 vl_api_vxlan_add_del_tunnel_t *mp;
8401 ip4_address_t src4, dst4;
8402 ip6_address_t src6, dst6;
8404 u8 ipv4_set = 0, ipv6_set = 0;
8407 u32 encap_vrf_id = 0;
8408 u32 decap_next_index = ~0;
8411 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8412 if (unformat (line_input, "del"))
8414 else if (unformat (line_input, "src %U",
8415 unformat_ip4_address, &src4))
8420 else if (unformat (line_input, "dst %U",
8421 unformat_ip4_address, &dst4))
8426 else if (unformat (line_input, "src %U",
8427 unformat_ip6_address, &src6))
8432 else if (unformat (line_input, "dst %U",
8433 unformat_ip6_address, &dst6))
8438 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8440 else if (unformat (line_input, "decap-next %U",
8441 unformat_vxlan_decap_next, &decap_next_index))
8443 else if (unformat (line_input, "vni %d", &vni))
8446 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8452 errmsg ("tunnel src address not specified\n");
8456 errmsg ("tunnel dst address not specified\n");
8460 if (ipv4_set && ipv6_set) {
8461 errmsg ("both IPv4 and IPv6 addresses specified");
8465 if ((vni == 0) || (vni>>24)) {
8466 errmsg ("vni not specified or out of range\n");
8470 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
8473 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
8474 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
8476 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8477 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8479 mp->encap_vrf_id = ntohl(encap_vrf_id);
8480 mp->decap_next_index = ntohl(decap_next_index);
8481 mp->vni = ntohl(vni);
8482 mp->is_add = is_add;
8483 mp->is_ipv6 = ipv6_set;
8490 static void vl_api_vxlan_tunnel_details_t_handler
8491 (vl_api_vxlan_tunnel_details_t * mp)
8493 vat_main_t * vam = &vat_main;
8495 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
8496 ntohl(mp->sw_if_index),
8497 format_ip46_address, &(mp->src_address[0]),
8499 format_ip46_address, &(mp->dst_address[0]),
8501 ntohl(mp->encap_vrf_id),
8502 ntohl(mp->decap_next_index),
8506 static void vl_api_vxlan_tunnel_details_t_handler_json
8507 (vl_api_vxlan_tunnel_details_t * mp)
8509 vat_main_t * vam = &vat_main;
8510 vat_json_node_t *node = NULL;
8512 struct in6_addr ip6;
8514 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8515 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8516 vat_json_init_array(&vam->json_tree);
8518 node = vat_json_array_add(&vam->json_tree);
8520 vat_json_init_object(node);
8521 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8523 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
8524 vat_json_object_add_ip6(node, "src_address", ip6);
8525 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
8526 vat_json_object_add_ip6(node, "dst_address", ip6);
8528 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
8529 vat_json_object_add_ip4(node, "src_address", ip4);
8530 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
8531 vat_json_object_add_ip4(node, "dst_address", ip4);
8533 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8534 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
8535 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8536 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8539 static int api_vxlan_tunnel_dump (vat_main_t * vam)
8541 unformat_input_t * i = vam->input;
8542 vl_api_vxlan_tunnel_dump_t *mp;
8545 u8 sw_if_index_set = 0;
8547 /* Parse args required to build the message */
8548 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8549 if (unformat (i, "sw_if_index %d", &sw_if_index))
8550 sw_if_index_set = 1;
8555 if (sw_if_index_set == 0) {
8559 if (!vam->json_output) {
8560 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
8561 "sw_if_index", "src_address", "dst_address",
8562 "encap_vrf_id", "decap_next_index", "vni");
8565 /* Get list of vxlan-tunnel interfaces */
8566 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
8568 mp->sw_if_index = htonl(sw_if_index);
8572 /* Use a control ping for synchronization */
8574 vl_api_control_ping_t * mp;
8575 M(CONTROL_PING, control_ping);
8581 static int api_gre_add_del_tunnel (vat_main_t * vam)
8583 unformat_input_t * line_input = vam->input;
8584 vl_api_gre_add_del_tunnel_t *mp;
8586 ip4_address_t src4, dst4;
8590 u32 outer_fib_id = 0;
8592 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8593 if (unformat (line_input, "del"))
8595 else if (unformat (line_input, "src %U",
8596 unformat_ip4_address, &src4))
8598 else if (unformat (line_input, "dst %U",
8599 unformat_ip4_address, &dst4))
8601 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
8604 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8610 errmsg ("tunnel src address not specified\n");
8614 errmsg ("tunnel dst address not specified\n");
8619 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
8621 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8622 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8623 mp->outer_fib_id = ntohl(outer_fib_id);
8624 mp->is_add = is_add;
8631 static void vl_api_gre_tunnel_details_t_handler
8632 (vl_api_gre_tunnel_details_t * mp)
8634 vat_main_t * vam = &vat_main;
8636 fformat(vam->ofp, "%11d%15U%15U%14d\n",
8637 ntohl(mp->sw_if_index),
8638 format_ip4_address, &mp->src_address,
8639 format_ip4_address, &mp->dst_address,
8640 ntohl(mp->outer_fib_id));
8643 static void vl_api_gre_tunnel_details_t_handler_json
8644 (vl_api_gre_tunnel_details_t * mp)
8646 vat_main_t * vam = &vat_main;
8647 vat_json_node_t *node = NULL;
8650 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8651 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8652 vat_json_init_array(&vam->json_tree);
8654 node = vat_json_array_add(&vam->json_tree);
8656 vat_json_init_object(node);
8657 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8658 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
8659 vat_json_object_add_ip4(node, "src_address", ip4);
8660 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
8661 vat_json_object_add_ip4(node, "dst_address", ip4);
8662 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_fib_id));
8665 static int api_gre_tunnel_dump (vat_main_t * vam)
8667 unformat_input_t * i = vam->input;
8668 vl_api_gre_tunnel_dump_t *mp;
8671 u8 sw_if_index_set = 0;
8673 /* Parse args required to build the message */
8674 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8675 if (unformat (i, "sw_if_index %d", &sw_if_index))
8676 sw_if_index_set = 1;
8681 if (sw_if_index_set == 0) {
8685 if (!vam->json_output) {
8686 fformat(vam->ofp, "%11s%15s%15s%14s\n",
8687 "sw_if_index", "src_address", "dst_address",
8691 /* Get list of gre-tunnel interfaces */
8692 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
8694 mp->sw_if_index = htonl(sw_if_index);
8698 /* Use a control ping for synchronization */
8700 vl_api_control_ping_t * mp;
8701 M(CONTROL_PING, control_ping);
8707 static int api_l2_fib_clear_table (vat_main_t * vam)
8709 // unformat_input_t * i = vam->input;
8710 vl_api_l2_fib_clear_table_t *mp;
8713 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
8720 static int api_l2_interface_efp_filter (vat_main_t * vam)
8722 unformat_input_t * i = vam->input;
8723 vl_api_l2_interface_efp_filter_t *mp;
8727 u8 sw_if_index_set = 0;
8729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8730 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8731 sw_if_index_set = 1;
8732 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8733 sw_if_index_set = 1;
8734 else if (unformat (i, "enable"))
8736 else if (unformat (i, "disable"))
8739 clib_warning ("parse error '%U'", format_unformat_error, i);
8744 if (sw_if_index_set == 0) {
8745 errmsg ("missing sw_if_index\n");
8749 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
8751 mp->sw_if_index = ntohl(sw_if_index);
8752 mp->enable_disable = enable;
8759 #define foreach_vtr_op \
8760 _("disable", L2_VTR_DISABLED) \
8761 _("push-1", L2_VTR_PUSH_1) \
8762 _("push-2", L2_VTR_PUSH_2) \
8763 _("pop-1", L2_VTR_POP_1) \
8764 _("pop-2", L2_VTR_POP_2) \
8765 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8766 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8767 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8768 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8770 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8772 unformat_input_t * i = vam->input;
8773 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8776 u8 sw_if_index_set = 0;
8783 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8784 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8785 sw_if_index_set = 1;
8786 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8787 sw_if_index_set = 1;
8788 else if (unformat (i, "vtr_op %d", &vtr_op))
8790 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8794 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8796 else if (unformat (i, "tag1 %d", &tag1))
8798 else if (unformat (i, "tag2 %d", &tag2))
8801 clib_warning ("parse error '%U'", format_unformat_error, i);
8806 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
8807 errmsg ("missing vtr operation or sw_if_index\n");
8811 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
8813 mp->sw_if_index = ntohl(sw_if_index);
8814 mp->vtr_op = ntohl(vtr_op);
8815 mp->push_dot1q = ntohl(push_dot1q);
8816 mp->tag1 = ntohl(tag1);
8817 mp->tag2 = ntohl(tag2);
8824 static int api_create_vhost_user_if (vat_main_t * vam)
8826 unformat_input_t * i = vam->input;
8827 vl_api_create_vhost_user_if_t *mp;
8831 u8 file_name_set = 0;
8832 u32 custom_dev_instance = ~0;
8834 u8 use_custom_mac = 0;
8836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8837 if (unformat (i, "socket %s", &file_name)) {
8840 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8842 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8844 else if (unformat (i, "server"))
8850 if (file_name_set == 0) {
8851 errmsg ("missing socket file name\n");
8855 if (vec_len (file_name) > 255) {
8856 errmsg ("socket file name too long\n");
8859 vec_add1 (file_name, 0);
8861 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8863 mp->is_server = is_server;
8864 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8865 vec_free(file_name);
8866 if (custom_dev_instance != ~0) {
8868 mp->custom_dev_instance = ntohl(custom_dev_instance);
8870 mp->use_custom_mac = use_custom_mac;
8871 clib_memcpy(mp->mac_address, hwaddr, 6);
8878 static int api_modify_vhost_user_if (vat_main_t * vam)
8880 unformat_input_t * i = vam->input;
8881 vl_api_modify_vhost_user_if_t *mp;
8885 u8 file_name_set = 0;
8886 u32 custom_dev_instance = ~0;
8887 u8 sw_if_index_set = 0;
8888 u32 sw_if_index = (u32)~0;
8890 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8891 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8892 sw_if_index_set = 1;
8893 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8894 sw_if_index_set = 1;
8895 else if (unformat (i, "socket %s", &file_name)) {
8898 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8900 else if (unformat (i, "server"))
8906 if (sw_if_index_set == 0) {
8907 errmsg ("missing sw_if_index or interface name\n");
8911 if (file_name_set == 0) {
8912 errmsg ("missing socket file name\n");
8916 if (vec_len (file_name) > 255) {
8917 errmsg ("socket file name too long\n");
8920 vec_add1 (file_name, 0);
8922 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8924 mp->sw_if_index = ntohl(sw_if_index);
8925 mp->is_server = is_server;
8926 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8927 vec_free(file_name);
8928 if (custom_dev_instance != ~0) {
8930 mp->custom_dev_instance = ntohl(custom_dev_instance);
8938 static int api_delete_vhost_user_if (vat_main_t * vam)
8940 unformat_input_t * i = vam->input;
8941 vl_api_delete_vhost_user_if_t *mp;
8943 u32 sw_if_index = ~0;
8944 u8 sw_if_index_set = 0;
8946 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8947 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8948 sw_if_index_set = 1;
8949 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8950 sw_if_index_set = 1;
8955 if (sw_if_index_set == 0) {
8956 errmsg ("missing sw_if_index or interface name\n");
8961 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8963 mp->sw_if_index = ntohl(sw_if_index);
8970 static void vl_api_sw_interface_vhost_user_details_t_handler
8971 (vl_api_sw_interface_vhost_user_details_t * mp)
8973 vat_main_t * vam = &vat_main;
8975 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8976 (char *)mp->interface_name,
8977 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8978 clib_net_to_host_u64(mp->features), mp->is_server,
8979 ntohl(mp->num_regions), (char *)mp->sock_filename);
8980 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8983 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8984 (vl_api_sw_interface_vhost_user_details_t * mp)
8986 vat_main_t * vam = &vat_main;
8987 vat_json_node_t *node = NULL;
8989 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8990 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8991 vat_json_init_array(&vam->json_tree);
8993 node = vat_json_array_add(&vam->json_tree);
8995 vat_json_init_object(node);
8996 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8997 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8998 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8999 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
9000 vat_json_object_add_uint(node, "is_server", mp->is_server);
9001 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
9002 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
9003 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
9006 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
9008 vl_api_sw_interface_vhost_user_dump_t *mp;
9010 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
9012 /* Get list of vhost-user interfaces */
9013 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
9016 /* Use a control ping for synchronization */
9018 vl_api_control_ping_t * mp;
9019 M(CONTROL_PING, control_ping);
9025 static int api_show_version (vat_main_t * vam)
9027 vl_api_show_version_t *mp;
9030 M(SHOW_VERSION, show_version);
9038 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
9040 unformat_input_t * line_input = vam->input;
9041 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
9043 ip4_address_t local4, remote4;
9044 ip6_address_t local6, remote6;
9046 u8 ipv4_set = 0, ipv6_set = 0;
9049 u32 encap_vrf_id = 0;
9050 u32 decap_vrf_id = 0;
9055 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9056 if (unformat (line_input, "del"))
9058 else if (unformat (line_input, "local %U",
9059 unformat_ip4_address, &local4))
9064 else if (unformat (line_input, "remote %U",
9065 unformat_ip4_address, &remote4))
9070 else if (unformat (line_input, "local %U",
9071 unformat_ip6_address, &local6))
9076 else if (unformat (line_input, "remote %U",
9077 unformat_ip6_address, &remote6))
9082 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9084 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
9086 else if (unformat (line_input, "vni %d", &vni))
9088 else if (unformat(line_input, "next-ip4"))
9090 else if (unformat(line_input, "next-ip6"))
9092 else if (unformat(line_input, "next-ethernet"))
9094 else if (unformat(line_input, "next-nsh"))
9097 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9102 if (local_set == 0) {
9103 errmsg ("tunnel local address not specified\n");
9106 if (remote_set == 0) {
9107 errmsg ("tunnel remote address not specified\n");
9110 if (ipv4_set && ipv6_set) {
9111 errmsg ("both IPv4 and IPv6 addresses specified");
9116 errmsg ("vni not specified\n");
9120 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
9124 clib_memcpy(&mp->local, &local6, sizeof(local6));
9125 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
9127 clib_memcpy(&mp->local, &local4, sizeof(local4));
9128 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
9131 mp->encap_vrf_id = ntohl(encap_vrf_id);
9132 mp->decap_vrf_id = ntohl(decap_vrf_id);
9133 mp->protocol = ntohl(protocol);
9134 mp->vni = ntohl(vni);
9135 mp->is_add = is_add;
9136 mp->is_ipv6 = ipv6_set;
9143 static void vl_api_vxlan_gpe_tunnel_details_t_handler
9144 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9146 vat_main_t * vam = &vat_main;
9148 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
9149 ntohl(mp->sw_if_index),
9150 format_ip46_address, &(mp->local[0]),
9151 format_ip46_address, &(mp->remote[0]),
9153 ntohl(mp->protocol),
9154 ntohl(mp->encap_vrf_id),
9155 ntohl(mp->decap_vrf_id));
9158 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
9159 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9161 vat_main_t * vam = &vat_main;
9162 vat_json_node_t *node = NULL;
9164 struct in6_addr ip6;
9166 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9167 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9168 vat_json_init_array(&vam->json_tree);
9170 node = vat_json_array_add(&vam->json_tree);
9172 vat_json_init_object(node);
9173 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9175 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
9176 vat_json_object_add_ip6(node, "local", ip6);
9177 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
9178 vat_json_object_add_ip6(node, "remote", ip6);
9180 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
9181 vat_json_object_add_ip4(node, "local", ip4);
9182 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
9183 vat_json_object_add_ip4(node, "remote", ip4);
9185 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
9186 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
9187 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
9188 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
9189 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
9192 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
9194 unformat_input_t * i = vam->input;
9195 vl_api_vxlan_gpe_tunnel_dump_t *mp;
9198 u8 sw_if_index_set = 0;
9200 /* Parse args required to build the message */
9201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9202 if (unformat (i, "sw_if_index %d", &sw_if_index))
9203 sw_if_index_set = 1;
9208 if (sw_if_index_set == 0) {
9212 if (!vam->json_output) {
9213 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
9214 "sw_if_index", "local", "remote", "vni",
9215 "protocol","encap_vrf_id", "decap_vrf_id");
9218 /* Get list of vxlan-tunnel interfaces */
9219 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
9221 mp->sw_if_index = htonl(sw_if_index);
9225 /* Use a control ping for synchronization */
9227 vl_api_control_ping_t * mp;
9228 M(CONTROL_PING, control_ping);
9234 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
9236 u8 * a = va_arg (*args, u8 *);
9238 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
9239 a[2], a[3], a[4], a[5], a[6], a[7]);
9242 static void vl_api_l2_fib_table_entry_t_handler
9243 (vl_api_l2_fib_table_entry_t * mp)
9245 vat_main_t * vam = &vat_main;
9247 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
9249 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
9250 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
9254 static void vl_api_l2_fib_table_entry_t_handler_json
9255 (vl_api_l2_fib_table_entry_t * mp)
9257 vat_main_t * vam = &vat_main;
9258 vat_json_node_t *node = NULL;
9260 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9261 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9262 vat_json_init_array(&vam->json_tree);
9264 node = vat_json_array_add(&vam->json_tree);
9266 vat_json_init_object(node);
9267 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
9268 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
9269 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9270 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
9271 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
9272 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
9275 static int api_l2_fib_table_dump (vat_main_t * vam)
9277 unformat_input_t * i = vam->input;
9278 vl_api_l2_fib_table_dump_t *mp;
9283 /* Parse args required to build the message */
9284 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9285 if (unformat (i, "bd_id %d", &bd_id))
9291 if (bd_id_set == 0) {
9292 errmsg ("missing bridge domain\n");
9296 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
9298 /* Get list of l2 fib entries */
9299 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
9301 mp->bd_id = ntohl(bd_id);
9304 /* Use a control ping for synchronization */
9306 vl_api_control_ping_t * mp;
9307 M(CONTROL_PING, control_ping);
9315 api_interface_name_renumber (vat_main_t * vam)
9317 unformat_input_t * line_input = vam->input;
9318 vl_api_interface_name_renumber_t *mp;
9319 u32 sw_if_index = ~0;
9321 u32 new_show_dev_instance = ~0;
9323 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9324 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
9327 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9329 else if (unformat (line_input, "new_show_dev_instance %d",
9330 &new_show_dev_instance))
9336 if (sw_if_index == ~0) {
9337 errmsg ("missing interface name or sw_if_index\n");
9341 if (new_show_dev_instance == ~0) {
9342 errmsg ("missing new_show_dev_instance\n");
9346 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
9348 mp->sw_if_index = ntohl (sw_if_index);
9349 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
9355 api_want_ip4_arp_events (vat_main_t * vam)
9357 unformat_input_t * line_input = vam->input;
9358 vl_api_want_ip4_arp_events_t * mp;
9360 ip4_address_t address;
9361 int address_set = 0;
9362 u32 enable_disable = 1;
9364 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9365 if (unformat (line_input, "address %U",
9366 unformat_ip4_address, &address))
9368 else if (unformat (line_input, "del"))
9374 if (address_set == 0) {
9375 errmsg ("missing addresses\n");
9379 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
9380 mp->enable_disable = enable_disable;
9382 mp->address = address.as_u32;
9387 static int api_input_acl_set_interface (vat_main_t * vam)
9389 unformat_input_t * i = vam->input;
9390 vl_api_input_acl_set_interface_t *mp;
9393 int sw_if_index_set;
9394 u32 ip4_table_index = ~0;
9395 u32 ip6_table_index = ~0;
9396 u32 l2_table_index = ~0;
9399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9400 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9401 sw_if_index_set = 1;
9402 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9403 sw_if_index_set = 1;
9404 else if (unformat (i, "del"))
9406 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9408 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9410 else if (unformat (i, "l2-table %d", &l2_table_index))
9413 clib_warning ("parse error '%U'", format_unformat_error, i);
9418 if (sw_if_index_set == 0) {
9419 errmsg ("missing interface name or sw_if_index\n");
9423 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
9425 mp->sw_if_index = ntohl(sw_if_index);
9426 mp->ip4_table_index = ntohl(ip4_table_index);
9427 mp->ip6_table_index = ntohl(ip6_table_index);
9428 mp->l2_table_index = ntohl(l2_table_index);
9429 mp->is_add = is_add;
9437 api_ip_address_dump (vat_main_t * vam)
9439 unformat_input_t * i = vam->input;
9440 vl_api_ip_address_dump_t * mp;
9441 u32 sw_if_index = ~0;
9442 u8 sw_if_index_set = 0;
9447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9448 if (unformat (i, "sw_if_index %d", &sw_if_index))
9449 sw_if_index_set = 1;
9450 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9451 sw_if_index_set = 1;
9452 else if (unformat (i, "ipv4"))
9454 else if (unformat (i, "ipv6"))
9460 if (ipv4_set && ipv6_set) {
9461 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9465 if ((!ipv4_set) && (!ipv6_set)) {
9466 errmsg ("no ipv4 nor ipv6 flag set\n");
9470 if (sw_if_index_set == 0) {
9471 errmsg ("missing interface name or sw_if_index\n");
9475 vam->current_sw_if_index = sw_if_index;
9476 vam->is_ipv6 = ipv6_set;
9478 M(IP_ADDRESS_DUMP, ip_address_dump);
9479 mp->sw_if_index = ntohl(sw_if_index);
9480 mp->is_ipv6 = ipv6_set;
9483 /* Use a control ping for synchronization */
9485 vl_api_control_ping_t * mp;
9486 M(CONTROL_PING, control_ping);
9493 api_ip_dump (vat_main_t * vam)
9495 vl_api_ip_dump_t * mp;
9496 unformat_input_t * in = vam->input;
9503 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
9504 if (unformat (in, "ipv4"))
9506 else if (unformat (in, "ipv6"))
9512 if (ipv4_set && ipv6_set) {
9513 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9517 if ((!ipv4_set) && (!ipv6_set)) {
9518 errmsg ("no ipv4 nor ipv6 flag set\n");
9523 vam->is_ipv6 = is_ipv6;
9526 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
9527 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9529 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
9531 M(IP_DUMP, ip_dump);
9532 mp->is_ipv6 = ipv6_set;
9535 /* Use a control ping for synchronization */
9537 vl_api_control_ping_t * mp;
9538 M(CONTROL_PING, control_ping);
9545 api_ipsec_spd_add_del (vat_main_t * vam)
9548 unformat_input_t * i = vam->input;
9549 vl_api_ipsec_spd_add_del_t *mp;
9554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9555 if (unformat (i, "spd_id %d", &spd_id))
9557 else if (unformat (i, "del"))
9560 clib_warning ("parse error '%U'", format_unformat_error, i);
9565 errmsg ("spd_id must be set\n");
9569 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
9571 mp->spd_id = ntohl(spd_id);
9572 mp->is_add = is_add;
9578 clib_warning ("unsupported (no dpdk)");
9584 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9587 unformat_input_t * i = vam->input;
9588 vl_api_ipsec_interface_add_del_spd_t *mp;
9591 u8 sw_if_index_set = 0;
9592 u32 spd_id = (u32) ~0;
9595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9596 if (unformat (i, "del"))
9598 else if (unformat (i, "spd_id %d", &spd_id))
9600 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9601 sw_if_index_set = 1;
9602 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9603 sw_if_index_set = 1;
9605 clib_warning ("parse error '%U'", format_unformat_error, i);
9611 if (spd_id == (u32) ~0) {
9612 errmsg ("spd_id must be set\n");
9616 if (sw_if_index_set == 0) {
9617 errmsg ("missing interface name or sw_if_index\n");
9621 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
9623 mp->spd_id = ntohl(spd_id);
9624 mp->sw_if_index = ntohl (sw_if_index);
9625 mp->is_add = is_add;
9631 clib_warning ("unsupported (no dpdk)");
9637 api_ipsec_spd_add_del_entry (vat_main_t * vam)
9640 unformat_input_t * i = vam->input;
9641 vl_api_ipsec_spd_add_del_entry_t *mp;
9643 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
9644 u32 spd_id, sa_id, protocol = 0, policy = 0;
9646 u32 rport_start = 0, rport_stop = (u32) ~0;
9647 u32 lport_start = 0, lport_stop = (u32) ~0;
9648 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
9649 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
9651 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
9652 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
9653 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
9654 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
9655 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
9656 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
9658 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9659 if (unformat (i, "del"))
9661 if (unformat (i, "outbound"))
9663 if (unformat (i, "inbound"))
9665 else if (unformat (i, "spd_id %d", &spd_id))
9667 else if (unformat (i, "sa_id %d", &sa_id))
9669 else if (unformat (i, "priority %d", &priority))
9671 else if (unformat (i, "protocol %d", &protocol))
9673 else if (unformat (i, "lport_start %d", &lport_start))
9675 else if (unformat (i, "lport_stop %d", &lport_stop))
9677 else if (unformat (i, "rport_start %d", &rport_start))
9679 else if (unformat (i, "rport_stop %d", &rport_stop))
9681 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
9686 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
9691 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
9696 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
9701 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
9706 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
9711 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
9716 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
9721 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9723 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
9724 clib_warning ("unsupported action: 'resolve'");
9729 clib_warning ("parse error '%U'", format_unformat_error, i);
9735 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
9737 mp->spd_id = ntohl(spd_id);
9738 mp->priority = ntohl(priority);
9739 mp->is_outbound = is_outbound;
9741 mp->is_ipv6 = is_ipv6;
9742 if (is_ipv6 || is_ip_any) {
9743 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
9744 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
9745 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
9746 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
9748 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
9749 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
9750 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
9751 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
9753 mp->protocol = (u8) protocol;
9754 mp->local_port_start = ntohs((u16) lport_start);
9755 mp->local_port_stop = ntohs((u16) lport_stop);
9756 mp->remote_port_start = ntohs((u16) rport_start);
9757 mp->remote_port_stop = ntohs((u16) rport_stop);
9758 mp->policy = (u8) policy;
9759 mp->sa_id = ntohl(sa_id);
9760 mp->is_add = is_add;
9761 mp->is_ip_any = is_ip_any;
9766 clib_warning ("unsupported (no dpdk)");
9772 api_ipsec_sad_add_del_entry (vat_main_t * vam)
9775 unformat_input_t * i = vam->input;
9776 vl_api_ipsec_sad_add_del_entry_t *mp;
9779 u8 * ck = 0, * ik = 0;
9782 u8 protocol = IPSEC_PROTOCOL_AH;
9783 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
9784 u32 crypto_alg = 0, integ_alg = 0;
9785 ip4_address_t tun_src4;
9786 ip4_address_t tun_dst4;
9787 ip6_address_t tun_src6;
9788 ip6_address_t tun_dst6;
9790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9791 if (unformat (i, "del"))
9793 else if (unformat (i, "sad_id %d", &sad_id))
9795 else if (unformat (i, "spi %d", &spi))
9797 else if (unformat (i, "esp"))
9798 protocol = IPSEC_PROTOCOL_ESP;
9799 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
9803 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
9807 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
9811 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
9815 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
9816 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
9817 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9818 clib_warning ("unsupported crypto-alg: '%U'",
9819 format_ipsec_crypto_alg, crypto_alg);
9823 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9825 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
9826 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
9827 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9828 clib_warning ("unsupported integ-alg: '%U'",
9829 format_ipsec_integ_alg, integ_alg);
9833 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9836 clib_warning ("parse error '%U'", format_unformat_error, i);
9842 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
9844 mp->sad_id = ntohl(sad_id);
9845 mp->is_add = is_add;
9846 mp->protocol = protocol;
9847 mp->spi = ntohl(spi);
9848 mp->is_tunnel = is_tunnel;
9849 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
9850 mp->crypto_algorithm = crypto_alg;
9851 mp->integrity_algorithm = integ_alg;
9852 mp->crypto_key_length = vec_len(ck);
9853 mp->integrity_key_length = vec_len(ik);
9855 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9856 mp->crypto_key_length = sizeof(mp->crypto_key);
9858 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9859 mp->integrity_key_length = sizeof(mp->integrity_key);
9861 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9862 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9865 if (is_tunnel_ipv6) {
9866 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9867 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9869 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9870 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9878 clib_warning ("unsupported (no dpdk)");
9884 api_ipsec_sa_set_key (vat_main_t * vam)
9887 unformat_input_t * i = vam->input;
9888 vl_api_ipsec_sa_set_key_t *mp;
9891 u8 * ck = 0, * ik = 0;
9893 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9894 if (unformat (i, "sa_id %d", &sa_id))
9896 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9898 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9901 clib_warning ("parse error '%U'", format_unformat_error, i);
9906 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9908 mp->sa_id = ntohl(sa_id);
9909 mp->crypto_key_length = vec_len(ck);
9910 mp->integrity_key_length = vec_len(ik);
9912 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9913 mp->crypto_key_length = sizeof(mp->crypto_key);
9915 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9916 mp->integrity_key_length = sizeof(mp->integrity_key);
9918 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9919 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9925 clib_warning ("unsupported (no dpdk)");
9931 api_ikev2_profile_add_del (vat_main_t * vam)
9934 unformat_input_t * i = vam->input;
9935 vl_api_ikev2_profile_add_del_t * mp;
9940 const char * valid_chars = "a-zA-Z0-9_";
9942 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9943 if (unformat (i, "del"))
9945 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9948 errmsg ("parse error '%U'", format_unformat_error, i);
9953 if (!vec_len (name)) {
9954 errmsg ("profile name must be specified");
9958 if (vec_len (name) > 64) {
9959 errmsg ("profile name too long");
9963 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9965 clib_memcpy(mp->name, name, vec_len (name));
9966 mp->is_add = is_add;
9973 clib_warning ("unsupported (no dpdk)");
9979 api_ikev2_profile_set_auth (vat_main_t * vam)
9982 unformat_input_t * i = vam->input;
9983 vl_api_ikev2_profile_set_auth_t * mp;
9987 u32 auth_method = 0;
9990 const char * valid_chars = "a-zA-Z0-9_";
9992 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9993 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9995 else if (unformat (i, "auth_method %U",
9996 unformat_ikev2_auth_method, &auth_method))
9998 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
10000 else if (unformat (i, "auth_data %v", &data))
10003 errmsg ("parse error '%U'", format_unformat_error, i);
10008 if (!vec_len (name)) {
10009 errmsg ("profile name must be specified");
10013 if (vec_len (name) > 64) {
10014 errmsg ("profile name too long");
10018 if (!vec_len(data)) {
10019 errmsg ("auth_data must be specified");
10023 if (!auth_method) {
10024 errmsg ("auth_method must be specified");
10028 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
10030 mp->is_hex = is_hex;
10031 mp->auth_method = (u8) auth_method;
10032 mp->data_len = vec_len (data);
10033 clib_memcpy (mp->name, name, vec_len (name));
10034 clib_memcpy (mp->data, data, vec_len (data));
10042 clib_warning ("unsupported (no dpdk)");
10048 api_ikev2_profile_set_id (vat_main_t * vam)
10051 unformat_input_t * i = vam->input;
10052 vl_api_ikev2_profile_set_id_t * mp;
10060 const char * valid_chars = "a-zA-Z0-9_";
10062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10063 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10064 vec_add1 (name, 0);
10065 else if (unformat (i, "id_type %U",
10066 unformat_ikev2_id_type, &id_type))
10068 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
10070 data = vec_new(u8, 4);
10071 clib_memcpy(data, ip4.as_u8, 4);
10073 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
10075 else if (unformat (i, "id_data %v", &data))
10077 else if (unformat (i, "local"))
10079 else if (unformat (i, "remote"))
10082 errmsg ("parse error '%U'", format_unformat_error, i);
10087 if (!vec_len (name)) {
10088 errmsg ("profile name must be specified");
10092 if (vec_len (name) > 64) {
10093 errmsg ("profile name too long");
10097 if (!vec_len(data)) {
10098 errmsg ("id_data must be specified");
10103 errmsg ("id_type must be specified");
10107 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
10109 mp->is_local = is_local;
10110 mp->id_type = (u8) id_type;
10111 mp->data_len = vec_len (data);
10112 clib_memcpy (mp->name, name, vec_len (name));
10113 clib_memcpy (mp->data, data, vec_len (data));
10121 clib_warning ("unsupported (no dpdk)");
10127 api_ikev2_profile_set_ts (vat_main_t * vam)
10130 unformat_input_t * i = vam->input;
10131 vl_api_ikev2_profile_set_ts_t * mp;
10135 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
10136 ip4_address_t start_addr, end_addr;
10138 const char * valid_chars = "a-zA-Z0-9_";
10140 start_addr.as_u32 = 0;
10141 end_addr.as_u32 = (u32) ~0;
10143 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10144 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10145 vec_add1 (name, 0);
10146 else if (unformat (i, "protocol %d", &proto))
10148 else if (unformat (i, "start_port %d", &start_port))
10150 else if (unformat (i, "end_port %d", &end_port))
10152 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
10154 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
10156 else if (unformat (i, "local"))
10158 else if (unformat (i, "remote"))
10161 errmsg ("parse error '%U'", format_unformat_error, i);
10166 if (!vec_len (name)) {
10167 errmsg ("profile name must be specified");
10171 if (vec_len (name) > 64) {
10172 errmsg ("profile name too long");
10176 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
10178 mp->is_local = is_local;
10179 mp->proto = (u8) proto;
10180 mp->start_port = (u16) start_port;
10181 mp->end_port = (u16) end_port;
10182 mp->start_addr = start_addr.as_u32;
10183 mp->end_addr = end_addr.as_u32;
10184 clib_memcpy (mp->name, name, vec_len (name));
10191 clib_warning ("unsupported (no dpdk)");
10197 api_ikev2_set_local_key (vat_main_t * vam)
10200 unformat_input_t * i = vam->input;
10201 vl_api_ikev2_set_local_key_t * mp;
10205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10206 if (unformat (i, "file %v", &file))
10207 vec_add1 (file, 0);
10209 errmsg ("parse error '%U'", format_unformat_error, i);
10214 if (!vec_len (file)) {
10215 errmsg ("RSA key file must be specified");
10219 if (vec_len (file) > 256) {
10220 errmsg ("file name too long");
10224 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
10226 clib_memcpy (mp->key_file, file, vec_len (file));
10233 clib_warning ("unsupported (no dpdk)");
10241 static int api_map_add_domain (vat_main_t * vam)
10243 unformat_input_t *i = vam->input;
10244 vl_api_map_add_domain_t *mp;
10247 ip4_address_t ip4_prefix;
10248 ip6_address_t ip6_prefix;
10249 ip6_address_t ip6_src;
10250 u32 num_m_args = 0;
10251 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
10253 u8 is_translation = 0;
10255 u8 ip6_src_len = 128;
10257 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10258 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
10259 &ip4_prefix, &ip4_prefix_len))
10261 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
10262 &ip6_prefix, &ip6_prefix_len))
10264 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
10266 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
10268 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
10270 else if (unformat (i, "psid-offset %d", &psid_offset))
10272 else if (unformat (i, "psid-len %d", &psid_length))
10274 else if (unformat (i, "mtu %d", &mtu))
10276 else if (unformat (i, "map-t"))
10277 is_translation = 1;
10279 clib_warning ("parse error '%U'", format_unformat_error, i);
10284 if (num_m_args != 6) {
10285 errmsg("mandatory argument(s) missing\n");
10289 /* Construct the API message */
10290 M(MAP_ADD_DOMAIN, map_add_domain);
10292 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
10293 mp->ip4_prefix_len = ip4_prefix_len;
10295 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
10296 mp->ip6_prefix_len = ip6_prefix_len;
10298 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
10299 mp->ip6_src_prefix_len = ip6_src_len;
10301 mp->ea_bits_len = ea_bits_len;
10302 mp->psid_offset = psid_offset;
10303 mp->psid_length = psid_length;
10304 mp->is_translation = is_translation;
10305 mp->mtu = htons(mtu);
10310 /* Wait for a reply, return good/bad news */
10314 static int api_map_del_domain (vat_main_t * vam)
10316 unformat_input_t *i = vam->input;
10317 vl_api_map_del_domain_t *mp;
10320 u32 num_m_args = 0;
10323 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10324 if (unformat (i, "index %d", &index))
10327 clib_warning ("parse error '%U'", format_unformat_error, i);
10332 if (num_m_args != 1) {
10333 errmsg("mandatory argument(s) missing\n");
10337 /* Construct the API message */
10338 M(MAP_DEL_DOMAIN, map_del_domain);
10340 mp->index = ntohl(index);
10345 /* Wait for a reply, return good/bad news */
10349 static int api_map_add_del_rule (vat_main_t * vam)
10351 unformat_input_t *i = vam->input;
10352 vl_api_map_add_del_rule_t *mp;
10355 ip6_address_t ip6_dst;
10356 u32 num_m_args = 0, index, psid;
10358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10359 if (unformat (i, "index %d", &index))
10361 else if (unformat (i, "psid %d", &psid))
10363 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
10365 else if (unformat (i, "del")) {
10368 clib_warning ("parse error '%U'", format_unformat_error, i);
10373 /* Construct the API message */
10374 M(MAP_ADD_DEL_RULE, map_add_del_rule);
10376 mp->index = ntohl(index);
10377 mp->is_add = is_add;
10378 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
10379 mp->psid = ntohs(psid);
10384 /* Wait for a reply, return good/bad news */
10388 static int api_map_domain_dump (vat_main_t * vam)
10390 vl_api_map_domain_dump_t *mp;
10393 /* Construct the API message */
10394 M(MAP_DOMAIN_DUMP, map_domain_dump);
10399 /* Use a control ping for synchronization */
10401 vl_api_control_ping_t * mp;
10402 M(CONTROL_PING, control_ping);
10408 static int api_map_rule_dump (vat_main_t * vam)
10410 unformat_input_t *i = vam->input;
10411 vl_api_map_rule_dump_t *mp;
10413 u32 domain_index = ~0;
10415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10416 if (unformat (i, "index %u", &domain_index))
10422 if (domain_index == ~0) {
10423 clib_warning("parse error: domain index expected");
10427 /* Construct the API message */
10428 M(MAP_RULE_DUMP, map_rule_dump);
10430 mp->domain_index = htonl(domain_index);
10435 /* Use a control ping for synchronization */
10437 vl_api_control_ping_t * mp;
10438 M(CONTROL_PING, control_ping);
10444 static void vl_api_map_add_domain_reply_t_handler
10445 (vl_api_map_add_domain_reply_t * mp)
10447 vat_main_t * vam = &vat_main;
10448 i32 retval = ntohl(mp->retval);
10450 if (vam->async_mode) {
10451 vam->async_errors += (retval < 0);
10453 vam->retval = retval;
10454 vam->result_ready = 1;
10458 static void vl_api_map_add_domain_reply_t_handler_json
10459 (vl_api_map_add_domain_reply_t * mp)
10461 vat_main_t * vam = &vat_main;
10462 vat_json_node_t node;
10464 vat_json_init_object(&node);
10465 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
10466 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
10468 vat_json_print(vam->ofp, &node);
10469 vat_json_free(&node);
10471 vam->retval = ntohl(mp->retval);
10472 vam->result_ready = 1;
10476 api_get_first_msg_id (vat_main_t * vam)
10478 vl_api_get_first_msg_id_t * mp;
10480 unformat_input_t * i = vam->input;
10484 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10485 if (unformat (i, "client %s", &name))
10491 if (name_set == 0) {
10492 errmsg ("missing client name\n");
10495 vec_add1 (name, 0);
10497 if (vec_len (name) > 63) {
10498 errmsg ("client name too long\n");
10502 M(GET_FIRST_MSG_ID, get_first_msg_id);
10503 clib_memcpy (mp->name, name, vec_len(name));
10509 static int api_cop_interface_enable_disable (vat_main_t * vam)
10511 unformat_input_t * line_input = vam->input;
10512 vl_api_cop_interface_enable_disable_t * mp;
10514 u32 sw_if_index = ~0;
10515 u8 enable_disable = 1;
10517 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10518 if (unformat (line_input, "disable"))
10519 enable_disable = 0;
10520 if (unformat (line_input, "enable"))
10521 enable_disable = 1;
10522 else if (unformat (line_input, "%U", unformat_sw_if_index,
10523 vam, &sw_if_index))
10525 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10531 if (sw_if_index == ~0) {
10532 errmsg ("missing interface name or sw_if_index\n");
10536 /* Construct the API message */
10537 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
10538 mp->sw_if_index = ntohl(sw_if_index);
10539 mp->enable_disable = enable_disable;
10543 /* Wait for the reply */
10547 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
10549 unformat_input_t * line_input = vam->input;
10550 vl_api_cop_whitelist_enable_disable_t * mp;
10552 u32 sw_if_index = ~0;
10553 u8 ip4=0, ip6=0, default_cop=0;
10556 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10557 if (unformat (line_input, "ip4"))
10559 else if (unformat (line_input, "ip6"))
10561 else if (unformat (line_input, "default"))
10563 else if (unformat (line_input, "%U", unformat_sw_if_index,
10564 vam, &sw_if_index))
10566 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10568 else if (unformat (line_input, "fib-id %d", &fib_id))
10574 if (sw_if_index == ~0) {
10575 errmsg ("missing interface name or sw_if_index\n");
10579 /* Construct the API message */
10580 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
10581 mp->sw_if_index = ntohl(sw_if_index);
10582 mp->fib_id = ntohl(fib_id);
10585 mp->default_cop = default_cop;
10589 /* Wait for the reply */
10593 static int api_get_node_graph (vat_main_t * vam)
10595 vl_api_get_node_graph_t * mp;
10598 M(GET_NODE_GRAPH, get_node_graph);
10602 /* Wait for the reply */
10606 /** Used for transferring locators via VPP API */
10607 typedef CLIB_PACKED(struct
10609 u32 sw_if_index; /**< locator sw_if_index */
10610 u8 priority; /**< locator priority */
10611 u8 weight; /**< locator weight */
10615 api_lisp_add_del_locator_set(vat_main_t * vam)
10617 unformat_input_t * input = vam->input;
10618 vl_api_lisp_add_del_locator_set_t *mp;
10621 u8 *locator_set_name = NULL;
10622 u8 locator_set_name_set = 0;
10623 ls_locator_t locator, * locators = 0;
10624 u32 sw_if_index, priority, weight;
10626 /* Parse args required to build the message */
10627 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10628 if (unformat(input, "del")) {
10630 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10631 locator_set_name_set = 1;
10632 } else if (unformat(input, "sw_if_index %u p %u w %u",
10633 &sw_if_index, &priority, &weight)) {
10634 locator.sw_if_index = htonl(sw_if_index);
10635 locator.priority = priority;
10636 locator.weight = weight;
10637 vec_add1(locators, locator);
10638 } else if (unformat(input, "iface %U p %u w %u", unformat_sw_if_index,
10639 vam, &sw_if_index, &priority, &weight)) {
10640 locator.sw_if_index = htonl(sw_if_index);
10641 locator.priority = priority;
10642 locator.weight = weight;
10643 vec_add1(locators, locator);
10648 if (locator_set_name_set == 0) {
10649 errmsg ("missing locator-set name");
10650 vec_free(locators);
10654 if (vec_len(locator_set_name) > 64) {
10655 errmsg ("locator-set name too long\n");
10656 vec_free(locator_set_name);
10657 vec_free(locators);
10660 vec_add1(locator_set_name, 0);
10662 /* Construct the API message */
10663 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
10665 mp->is_add = is_add;
10666 clib_memcpy(mp->locator_set_name, locator_set_name,
10667 vec_len(locator_set_name));
10668 vec_free(locator_set_name);
10670 mp->locator_num = vec_len (locators);
10671 clib_memcpy (mp->locators, locators,
10672 (sizeof (ls_locator_t) * vec_len (locators)));
10673 vec_free (locators);
10678 /* Wait for a reply... */
10686 api_lisp_add_del_locator(vat_main_t * vam)
10688 unformat_input_t * input = vam->input;
10689 vl_api_lisp_add_del_locator_t *mp;
10691 u32 tmp_if_index = ~0;
10692 u32 sw_if_index = ~0;
10693 u8 sw_if_index_set = 0;
10694 u8 sw_if_index_if_name_set = 0;
10696 u8 priority_set = 0;
10700 u8 *locator_set_name = NULL;
10701 u8 locator_set_name_set = 0;
10703 /* Parse args required to build the message */
10704 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10705 if (unformat(input, "del")) {
10707 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10708 locator_set_name_set = 1;
10709 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
10711 sw_if_index_if_name_set = 1;
10712 sw_if_index = tmp_if_index;
10713 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
10714 sw_if_index_set = 1;
10715 sw_if_index = tmp_if_index;
10716 } else if (unformat(input, "p %d", &priority)) {
10718 } else if (unformat(input, "w %d", &weight)) {
10724 if (locator_set_name_set == 0) {
10725 errmsg ("missing locator-set name");
10729 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
10730 errmsg ("missing sw_if_index");
10731 vec_free(locator_set_name);
10735 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
10736 errmsg ("cannot use both params interface name and sw_if_index");
10737 vec_free(locator_set_name);
10741 if (priority_set == 0) {
10742 errmsg ("missing locator-set priority\n");
10743 vec_free(locator_set_name);
10747 if (weight_set == 0) {
10748 errmsg ("missing locator-set weight\n");
10749 vec_free(locator_set_name);
10753 if (vec_len(locator_set_name) > 64) {
10754 errmsg ("locator-set name too long\n");
10755 vec_free(locator_set_name);
10758 vec_add1(locator_set_name, 0);
10760 /* Construct the API message */
10761 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
10763 mp->is_add = is_add;
10764 mp->sw_if_index = ntohl(sw_if_index);
10765 mp->priority = priority;
10766 mp->weight = weight;
10767 clib_memcpy(mp->locator_set_name, locator_set_name,
10768 vec_len(locator_set_name));
10769 vec_free(locator_set_name);
10774 /* Wait for a reply... */
10782 api_lisp_add_del_local_eid(vat_main_t * vam)
10784 unformat_input_t * input = vam->input;
10785 vl_api_lisp_add_del_local_eid_t *mp;
10790 u8 eid_type = (u8)~0;
10791 ip4_address_t eidv4;
10792 ip6_address_t eidv6;
10794 u32 tmp_eid_lenght = ~0;
10795 u8 eid_lenght = ~0;
10796 u8 *locator_set_name = NULL;
10797 u8 locator_set_name_set = 0;
10800 /* Parse args required to build the message */
10801 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10802 if (unformat(input, "del")) {
10804 } else if (unformat(input, "vni %d", &vni)) {
10806 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10807 &eidv4, &tmp_eid_lenght)) {
10808 eid_lenght = tmp_eid_lenght;
10810 eid_type = 0; /* ipv4 type */
10811 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10812 &eidv6, &tmp_eid_lenght)) {
10813 eid_lenght = tmp_eid_lenght;
10815 eid_type = 1; /* ipv6 type */
10816 } else if (unformat(input, "eid %U", unformat_ethernet_address, mac)) {
10817 eid_type = 2; /* mac type */
10818 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10819 locator_set_name_set = 1;
10824 if (locator_set_name_set == 0) {
10825 errmsg ("missing locator-set name\n");
10829 if ((u8)~0 == eid_type) {
10830 errmsg ("EID address not set!");
10831 vec_free(locator_set_name);
10835 if (vec_len(locator_set_name) > 64) {
10836 errmsg ("locator-set name too long\n");
10837 vec_free(locator_set_name);
10840 vec_add1(locator_set_name, 0);
10842 if (eidv4_set && eidv6_set) {
10843 errmsg ("both eid v4 and v6 addresses set\n");
10844 vec_free(locator_set_name);
10848 if (eidv4_set && eid_lenght > 32) {
10849 errmsg ("eid prefix to big\n");
10850 vec_free(locator_set_name);
10854 if (eidv6_set && eid_lenght > 128) {
10855 errmsg ("eid prefix to big\n");
10856 vec_free(locator_set_name);
10860 /* Construct the API message */
10861 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
10863 mp->is_add = is_add;
10864 switch (eid_type) {
10866 clib_memcpy (mp->eid, &eidv4, sizeof(eidv4));
10869 clib_memcpy (mp->eid, &eidv6, sizeof(eidv6));
10872 clib_memcpy (mp->eid, mac, 6);
10875 mp->eid_type = eid_type;
10876 mp->prefix_len = eid_lenght;
10877 mp->vni = clib_host_to_net_u32(vni);
10878 clib_memcpy(mp->locator_set_name, locator_set_name,
10879 vec_len(locator_set_name));
10880 vec_free(locator_set_name);
10885 /* Wait for a reply... */
10893 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
10895 unformat_input_t * input = vam->input;
10896 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10899 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
10900 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
10901 ip4_address_t eidv4, slocv4, dlocv4;
10902 ip6_address_t eidv6, slocv6, dlocv6;
10903 u32 tmp_eid_lenght = ~0;
10904 u8 eid_lenght = ~0;
10906 /* Parse args required to build the message */
10907 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10908 if (unformat(input, "del")) {
10910 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10911 &eidv4, &tmp_eid_lenght)) {
10912 eid_lenght = tmp_eid_lenght;
10914 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10915 &eidv6, &tmp_eid_lenght)) {
10916 eid_lenght = tmp_eid_lenght;
10918 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10920 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10922 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10924 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10930 if (eidv4_set && eidv6_set) {
10931 errmsg ("both eid v4 and v6 addresses set\n");
10935 if (!eidv4_set && !eidv6_set) {
10936 errmsg ("eid addresses not set\n");
10940 if (slocv4_set && slocv6_set) {
10941 errmsg ("both source v4 and v6 addresses set\n");
10945 if (!slocv4_set && !slocv6_set) {
10946 errmsg ("source addresses not set\n");
10950 if (dlocv4_set && dlocv6_set) {
10951 errmsg ("both destination v4 and v6 addresses set\n");
10955 if (dlocv4_set && dlocv6_set) {
10956 errmsg ("destination addresses not set\n");
10960 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10961 errmsg ("mixing type of source and destination address\n");
10965 /* Construct the API message */
10966 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10968 mp->is_add = is_add;
10970 mp->eid_is_ipv6 = 1;
10971 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10973 mp->eid_is_ipv6 = 0;
10974 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10976 mp->eid_prefix_len = eid_lenght;
10978 mp->address_is_ipv6 = 1;
10979 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10980 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10982 mp->address_is_ipv6 = 0;
10983 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10984 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10990 /* Wait for a reply... */
10998 api_lisp_add_del_map_resolver(vat_main_t * vam)
11000 unformat_input_t * input = vam->input;
11001 vl_api_lisp_add_del_map_resolver_t *mp;
11006 ip4_address_t ipv4;
11007 ip6_address_t ipv6;
11009 /* Parse args required to build the message */
11010 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11011 if (unformat(input, "del")) {
11013 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
11015 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
11021 if (ipv4_set && ipv6_set) {
11022 errmsg ("both eid v4 and v6 addresses set\n");
11026 if (!ipv4_set && !ipv6_set) {
11027 errmsg ("eid addresses not set\n");
11031 /* Construct the API message */
11032 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
11034 mp->is_add = is_add;
11037 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
11040 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
11046 /* Wait for a reply... */
11054 api_lisp_gpe_enable_disable (vat_main_t * vam)
11056 unformat_input_t * input = vam->input;
11057 vl_api_lisp_gpe_enable_disable_t *mp;
11062 /* Parse args required to build the message */
11063 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11064 if (unformat(input, "enable")) {
11067 } else if (unformat(input, "disable")) {
11075 errmsg("Value not set\n");
11079 /* Construct the API message */
11080 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
11087 /* Wait for a reply... */
11095 api_lisp_enable_disable (vat_main_t * vam)
11097 unformat_input_t * input = vam->input;
11098 vl_api_lisp_enable_disable_t *mp;
11103 /* Parse args required to build the message */
11104 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11106 if (unformat (input, "enable"))
11111 else if (unformat (input, "disable"))
11121 errmsg ("Value not set\n");
11125 /* Construct the API message */
11126 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
11133 /* Wait for a reply... */
11140 /** Used for transferring locators via VPP API */
11141 typedef CLIB_PACKED(struct
11143 u8 is_ip4; /**< is locator an IPv4 address? */
11144 u8 priority; /**< locator priority */
11145 u8 weight; /**< locator weight */
11146 u8 addr[16]; /**< IPv4/IPv6 address */
11150 * Enable/disable LISP proxy ITR.
11152 * @param vam vpp API test context
11153 * @return return code
11156 api_lisp_pitr_set_locator_set (vat_main_t * vam)
11159 u8 ls_name_set = 0;
11160 unformat_input_t * input = vam->input;
11161 vl_api_lisp_pitr_set_locator_set_t * mp;
11165 /* Parse args required to build the message */
11166 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11168 if (unformat (input, "del"))
11170 else if (unformat (input, "locator-set %s", &ls_name))
11174 errmsg ("parse error '%U'", format_unformat_error, input);
11181 errmsg ("locator-set name not set!");
11185 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
11187 mp->is_add = is_add;
11188 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
11189 vec_free (ls_name);
11194 /* wait for reply */
11202 api_show_lisp_pitr (vat_main_t * vam)
11204 vl_api_show_lisp_pitr_t *mp;
11207 if (!vam->json_output) {
11208 fformat(vam->ofp, "%=20s\n",
11212 M(SHOW_LISP_PITR, show_lisp_pitr);
11216 /* Wait for a reply... */
11224 * Add/delete mapping between vni and vrf
11227 api_lisp_eid_table_add_del_map (vat_main_t * vam)
11230 unformat_input_t * input = vam->input;
11231 vl_api_lisp_eid_table_add_del_map_t *mp;
11232 u8 is_add = 1, vni_set = 0, vrf_set = 0;
11235 /* Parse args required to build the message */
11236 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11238 if (unformat (input, "del"))
11240 else if (unformat(input, "vrf %d", &vrf))
11242 else if (unformat(input, "vni %d", &vni))
11248 if (!vni_set || !vrf_set)
11250 errmsg ("missing arguments!");
11254 M(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
11256 mp->is_add = is_add;
11257 mp->vni = htonl (vni);
11258 mp->vrf = htonl (vrf);
11263 /* wait for reply */
11271 * Add/del remote mapping to/from LISP control plane
11273 * @param vam vpp API test context
11274 * @return return code
11277 api_lisp_add_del_remote_mapping (vat_main_t * vam)
11279 unformat_input_t * input = vam->input;
11280 vl_api_lisp_add_del_remote_mapping_t *mp;
11283 ip4_address_t seid4, deid4, rloc4;
11284 ip6_address_t seid6, deid6, rloc6;
11285 u8 deid_mac[6] = {0};
11286 u8 seid_mac[6] = {0};
11287 u8 deid_type, seid_type;
11288 u32 seid_len = 0, deid_len = 0, len;
11289 u8 is_add = 1, del_all = 0;
11290 u32 action = ~0, p, w;
11291 rloc_t * rlocs = 0, rloc, * curr_rloc = 0;
11293 seid_type = deid_type = (u8)~0;
11295 /* Parse args required to build the message */
11296 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11297 if (unformat(input, "del-all")) {
11299 } else if (unformat(input, "del")) {
11301 } else if (unformat(input, "add")) {
11303 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
11305 deid_type = 0; /* ipv4 */
11307 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
11309 deid_type = 1; /* ipv6 */
11311 } else if (unformat(input, "deid %U", unformat_ethernet_address,
11313 deid_type = 2; /* mac */
11314 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
11316 seid_type = 0; /* ipv4 */
11318 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11320 seid_type = 1; /* ipv6 */
11322 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11324 seid_type = 2; /* mac */
11325 } else if (unformat(input, "vni %d", &vni)) {
11327 } else if (unformat(input, "p %d w %d", &p, &w)) {
11329 errmsg ("No RLOC configured for setting priority/weight!");
11332 curr_rloc->priority = p;
11333 curr_rloc->weight = w;
11334 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
11336 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
11337 vec_add1 (rlocs, rloc);
11338 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11339 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
11341 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
11342 vec_add1 (rlocs, rloc);
11343 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11344 } else if (unformat(input, "action %d", &action)) {
11347 clib_warning ("parse error '%U'", format_unformat_error, input);
11352 if ((u8)~0 == deid_type) {
11353 errmsg ("missing params!");
11357 if (seid_type != deid_type) {
11358 errmsg ("source and destination EIDs are of different types!");
11362 if (is_add && (~0 == action)
11363 && 0 == vec_len (rlocs)) {
11364 errmsg ("no action set for negative map-reply!");
11368 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
11369 mp->is_add = is_add;
11370 mp->vni = htonl (vni);
11371 mp->seid_len = seid_len;
11372 mp->action = (u8) action;
11373 mp->deid_len = deid_len;
11374 mp->del_all = del_all;
11375 mp->eid_type = deid_type;
11377 switch (mp->eid_type) {
11379 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
11380 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
11383 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
11384 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
11387 clib_memcpy (mp->seid, seid_mac, 6);
11388 clib_memcpy (mp->deid, deid_mac, 6);
11391 errmsg ("unknown EID type %d!", mp->eid_type);
11395 mp->rloc_num = vec_len (rlocs);
11396 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
11402 /* Wait for a reply... */
11410 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
11411 * forwarding entries in data-plane accordingly.
11413 * @param vam vpp API test context
11414 * @return return code
11417 api_lisp_add_del_adjacency (vat_main_t * vam)
11419 unformat_input_t * input = vam->input;
11420 vl_api_lisp_add_del_adjacency_t *mp;
11423 ip4_address_t seid4, deid4;
11424 ip6_address_t seid6, deid6;
11425 u8 deid_mac[6] = {0};
11426 u8 seid_mac[6] = {0};
11427 u8 deid_type, seid_type;
11428 u32 seid_len = 0, deid_len = 0, len;
11431 seid_type = deid_type = (u8)~0;
11433 /* Parse args required to build the message */
11434 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11435 if (unformat(input, "del")) {
11437 } else if (unformat(input, "add")) {
11439 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
11441 deid_type = 0; /* ipv4 */
11443 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
11445 deid_type = 1; /* ipv6 */
11447 } else if (unformat(input, "deid %U", unformat_ethernet_address,
11449 deid_type = 2; /* mac */
11450 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
11452 seid_type = 0; /* ipv4 */
11454 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11456 seid_type = 1; /* ipv6 */
11458 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11460 seid_type = 2; /* mac */
11461 } else if (unformat(input, "vni %d", &vni)) {
11464 errmsg ("parse error '%U'", format_unformat_error, input);
11469 if ((u8)~0 == deid_type) {
11470 errmsg ("missing params!");
11474 if (seid_type != deid_type) {
11475 errmsg ("source and destination EIDs are of different types!");
11479 M(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
11480 mp->is_add = is_add;
11481 mp->vni = htonl (vni);
11482 mp->seid_len = seid_len;
11483 mp->deid_len = deid_len;
11484 mp->eid_type = deid_type;
11486 switch (mp->eid_type) {
11488 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
11489 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
11492 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
11493 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
11496 clib_memcpy (mp->seid, seid_mac, 6);
11497 clib_memcpy (mp->deid, deid_mac, 6);
11500 errmsg ("unknown EID type %d!", mp->eid_type);
11507 /* Wait for a reply... */
11515 api_lisp_gpe_add_del_iface(vat_main_t * vam)
11517 unformat_input_t * input = vam->input;
11518 vl_api_lisp_gpe_add_del_iface_t *mp;
11524 /* Parse args required to build the message */
11525 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11526 if (unformat(input, "up")) {
11529 } else if (unformat(input, "down")) {
11532 } else if (unformat(input, "table_id %d", &table_id)) {
11534 } else if (unformat(input, "vni %d", &vni)) {
11541 errmsg("Value not set\n");
11545 /* Construct the API message */
11546 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
11548 mp->is_add = is_add;
11549 mp->table_id = table_id;
11555 /* Wait for a reply... */
11563 * Add/del map request itr rlocs from LISP control plane and updates
11565 * @param vam vpp API test context
11566 * @return return code
11569 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
11571 unformat_input_t * input = vam->input;
11572 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
11574 u8 *locator_set_name = 0;
11575 u8 locator_set_name_set = 0;
11578 /* Parse args required to build the message */
11579 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11580 if (unformat(input, "del")) {
11582 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
11583 locator_set_name_set = 1;
11585 clib_warning ("parse error '%U'", format_unformat_error, input);
11590 if (is_add && !locator_set_name_set) {
11591 errmsg ("itr-rloc is not set!");
11595 if (is_add && vec_len(locator_set_name) > 64) {
11596 errmsg ("itr-rloc locator-set name too long\n");
11597 vec_free(locator_set_name);
11601 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
11602 mp->is_add = is_add;
11604 clib_memcpy (mp->locator_set_name , locator_set_name,
11605 vec_len(locator_set_name));
11607 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
11609 vec_free (locator_set_name);
11614 /* Wait for a reply... */
11622 lisp_locator_dump_send_msg(vat_main_t * vam, u32 locator_set_index, u8 filter)
11624 vl_api_lisp_locator_dump_t *mp;
11627 M(LISP_LOCATOR_DUMP, lisp_locator_dump);
11629 mp->locator_set_index = htonl(locator_set_index);
11630 mp->filter = filter;
11635 /* Use a control ping for synchronization */
11637 vl_api_noprint_control_ping_t * mp;
11638 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11641 /* Wait for a reply... */
11646 print_locator_in_locator_set(vat_main_t * vam, u8 filter)
11648 locator_set_msg_t * ls;
11649 locator_msg_t * loc;
11651 int i = 0, ret = 0;
11653 vec_foreach(ls, vam->locator_set_msg) {
11654 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11656 vec_free(ls->locator_set_name);
11657 vec_free(vam->locator_msg);
11658 vec_free(vam->locator_set_msg);
11662 tmp_str = format(0, "%=20s%=16d%s", ls->locator_set_name,
11663 ls->locator_set_index,
11664 vec_len(vam->locator_msg) ? "" : "\n");
11666 vec_foreach(loc, vam->locator_msg) {
11668 tmp_str = format(tmp_str, "%=37s", " ");
11671 tmp_str = format(tmp_str, "%=16d%=16d%=16d\n",
11676 tmp_str = format(tmp_str, "%=16U%=16d%=16d\n",
11677 loc->is_ipv6 ? format_ip6_address :
11678 format_ip4_address,
11686 fformat(vam->ofp, "%s", tmp_str);
11688 vec_free(ls->locator_set_name);
11689 vec_free(vam->locator_msg);
11692 vec_free(vam->locator_set_msg);
11698 json_locator_in_locator_set(vat_main_t * vam, u8 filter)
11700 locator_set_msg_t * ls;
11701 locator_msg_t * loc;
11702 vat_json_node_t * node = NULL;
11703 vat_json_node_t * locator_array;
11704 vat_json_node_t * locator;
11705 struct in6_addr ip6;
11706 struct in_addr ip4;
11709 if (!vec_len(vam->locator_set_msg)) {
11710 /* just print [] */
11711 vat_json_init_array(&vam->json_tree);
11712 vat_json_print(vam->ofp, &vam->json_tree);
11713 vam->json_tree.type = VAT_JSON_NONE;
11717 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11718 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11719 vat_json_init_array(&vam->json_tree);
11722 vec_foreach(ls, vam->locator_set_msg) {
11723 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11725 vec_free(ls->locator_set_name);
11726 vec_free(vam->locator_msg);
11727 vec_free(vam->locator_set_msg);
11728 vat_json_free(&vam->json_tree);
11729 vam->json_tree.type = VAT_JSON_NONE;
11733 node = vat_json_array_add(&vam->json_tree);
11734 vat_json_init_object(node);
11736 vat_json_object_add_uint(node, "locator-set-index",
11737 ls->locator_set_index);
11738 vat_json_object_add_string_copy(node, "locator-set",
11739 ls->locator_set_name);
11740 locator_array = vat_json_object_add_list(node, "locator");
11741 vec_foreach(loc, vam->locator_msg) {
11742 locator = vat_json_array_add(locator_array);
11743 vat_json_init_object(locator);
11745 vat_json_object_add_uint(locator, "locator-index",
11748 if (loc->is_ipv6) {
11749 clib_memcpy(&ip6, loc->ip_address, sizeof(ip6));
11750 vat_json_object_add_ip6(locator, "locator", ip6);
11752 clib_memcpy(&ip4, loc->ip_address, sizeof(ip4));
11753 vat_json_object_add_ip4(locator, "locator", ip4);
11756 vat_json_object_add_uint(locator, "priority", loc->priority);
11757 vat_json_object_add_uint(locator, "weight", loc->weight);
11760 vec_free(ls->locator_set_name);
11761 vec_free(vam->locator_msg);
11764 vat_json_print(vam->ofp, &vam->json_tree);
11765 vat_json_free(&vam->json_tree);
11766 vam->json_tree.type = VAT_JSON_NONE;
11768 vec_free(vam->locator_set_msg);
11774 get_locator_set_index_from_msg(vat_main_t * vam, u8 * locator_set,
11775 u32 * locator_set_index)
11777 locator_set_msg_t * ls;
11780 * locator_set_index = ~0;
11782 if (!vec_len(vam->locator_set_msg)) {
11786 vec_foreach(ls, vam->locator_set_msg) {
11787 if (!strcmp((char *) locator_set, (char *) ls->locator_set_name)) {
11788 * locator_set_index = ls->locator_set_index;
11789 vec_free(vam->locator_set_msg);
11794 vec_free(vam->locator_set_msg);
11800 get_locator_set_index(vat_main_t * vam, u8 * locator_set,
11801 u32 * locator_set_index)
11803 vl_api_lisp_locator_set_dump_t *mp;
11806 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11810 /* Use a control ping for synchronization */
11812 vl_api_noprint_control_ping_t * mp;
11813 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11817 vam->noprint_msg = 1;
11818 /* Wait for a reply... */
11820 get_locator_set_index_from_msg(vam, locator_set, locator_set_index);
11821 vam->noprint_msg = 0;
11829 lisp_locator_dump(vat_main_t * vam, u32 locator_set_index, u8 * locator_set,
11836 if (!vam->json_output) {
11837 fformat(vam->ofp, "%=20s%=16s%=16s\n",
11838 "locator", "priority", "weight");
11842 ret = get_locator_set_index(vam, locator_set, &locator_set_index);
11845 if (!ret && ~0 == locator_set_index) {
11849 ret = lisp_locator_dump_send_msg(vam, locator_set_index, filter);
11855 lisp_locator_set_dump(vat_main_t * vam, u8 filter)
11857 vl_api_lisp_locator_set_dump_t *mp;
11860 if (!vam->json_output) {
11861 fformat(vam->ofp, "%=20s%=16s%=16s%=16s%=16s\n",
11862 "locator-set", "locator-set-index", "locator", "priority",
11866 vam->noprint_msg = 1;
11868 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11870 mp->filter = filter;
11875 /* Use a control ping for synchronization */
11877 vl_api_noprint_control_ping_t * mp;
11878 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11882 /* Wait for a reply... */
11884 if (vam->noprint_msg) {
11885 if (!vam->json_output) {
11886 print_locator_in_locator_set(vam, filter);
11888 json_locator_in_locator_set(vam, filter);
11892 vam->noprint_msg = 0;
11900 api_lisp_locator_set_dump(vat_main_t *vam)
11902 unformat_input_t * input = vam->input;
11903 vam->noprint_msg = 0;
11904 u32 locator_set_index = ~0;
11905 u8 locator_set_index_set = 0;
11906 u8 * locator_set = 0;
11907 u8 locator_set_set = 0;
11911 /* Parse args required to build the message */
11912 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11913 if (unformat(input, "locator-set-index %u", &locator_set_index)) {
11914 locator_set_index_set = 1;
11915 } else if (unformat(input, "locator-set %s", &locator_set)) {
11916 locator_set_set = 1;
11917 } else if (unformat(input, "local")) {
11919 } else if (unformat(input, "remote")) {
11926 if (locator_set_index_set && locator_set_set) {
11927 errmsg ("use only input parameter!\n");
11931 if (locator_set_index_set || locator_set_set) {
11932 ret = lisp_locator_dump(vam, locator_set_index, locator_set, filter);
11934 ret = lisp_locator_set_dump(vam, filter);
11937 vec_free(locator_set);
11943 api_lisp_eid_table_map_dump(vat_main_t *vam)
11945 vl_api_lisp_eid_table_map_dump_t *mp;
11948 if (!vam->json_output) {
11949 fformat (vam->ofp, "%=10s%=10s\n", "VNI", "VRF");
11952 M(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
11957 /* Use a control ping for synchronization */
11959 vl_api_control_ping_t * mp;
11960 M(CONTROL_PING, control_ping);
11963 /* Wait for a reply... */
11971 api_lisp_local_eid_table_dump(vat_main_t *vam)
11973 unformat_input_t * i = vam->input;
11974 vl_api_lisp_local_eid_table_dump_t *mp;
11976 struct in_addr ip4;
11977 struct in6_addr ip6;
11979 u8 eid_type = ~0, eid_set = 0;
11980 u32 prefix_length = ~0, t, vni = 0;
11982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11983 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t)) {
11987 } else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t)) {
11991 } else if (unformat (i, "eid %U", unformat_ethernet_address, mac)) {
11994 } else if (unformat (i, "vni %d", &t))
11997 errmsg ("parse error '%U'", format_unformat_error, i);
12002 if (!vam->json_output) {
12003 fformat(vam->ofp, "%=20s%=30s\n",
12004 "Locator-set", "Eid");
12007 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
12011 mp->vni = htonl (vni);
12012 mp->eid_type = eid_type;
12013 switch (eid_type) {
12015 mp->prefix_length = prefix_length;
12016 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
12019 mp->prefix_length = prefix_length;
12020 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
12023 clib_memcpy (mp->eid, mac, sizeof (mac));
12026 errmsg ("unknown EID type %d!", eid_type);
12034 /* Use a control ping for synchronization */
12036 vl_api_control_ping_t * mp;
12037 M(CONTROL_PING, control_ping);
12040 /* Wait for a reply... */
12048 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
12050 vl_api_lisp_gpe_tunnel_dump_t *mp;
12053 if (!vam->json_output) {
12054 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
12055 "%=16s%=16s%=16s%=16s%=16s\n",
12056 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
12057 "Decap next", "Lisp version", "Flags", "Next protocol",
12058 "ver_res", "res", "iid");
12061 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
12065 /* Use a control ping for synchronization */
12067 vl_api_control_ping_t * mp;
12068 M(CONTROL_PING, control_ping);
12071 /* Wait for a reply... */
12079 api_lisp_map_resolver_dump(vat_main_t *vam)
12081 vl_api_lisp_map_resolver_dump_t *mp;
12084 if (!vam->json_output) {
12085 fformat(vam->ofp, "%=20s\n",
12089 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
12093 /* Use a control ping for synchronization */
12095 vl_api_control_ping_t * mp;
12096 M(CONTROL_PING, control_ping);
12099 /* Wait for a reply... */
12107 api_show_lisp_status(vat_main_t *vam)
12109 vl_api_show_lisp_status_t *mp;
12112 if (!vam->json_output) {
12113 fformat(vam->ofp, "%-20s%-16s\n",
12114 "lisp status", "locator-set");
12117 M(SHOW_LISP_STATUS, show_lisp_status);
12120 /* Wait for a reply... */
12128 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
12130 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
12133 if (!vam->json_output) {
12134 fformat(vam->ofp, "%=20s\n",
12138 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
12141 /* Wait for a reply... */
12149 api_af_packet_create (vat_main_t * vam)
12151 unformat_input_t * i = vam->input;
12152 vl_api_af_packet_create_t * mp;
12154 u8 * host_if_name = 0;
12156 u8 random_hw_addr = 1;
12158 memset (hw_addr, 0, sizeof (hw_addr));
12160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12161 if (unformat (i, "name %s", &host_if_name))
12162 vec_add1 (host_if_name, 0);
12163 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12164 random_hw_addr = 0;
12169 if (!vec_len (host_if_name)) {
12170 errmsg ("host-interface name must be specified");
12174 if (vec_len (host_if_name) > 64) {
12175 errmsg ("host-interface name too long");
12179 M(AF_PACKET_CREATE, af_packet_create);
12181 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12182 clib_memcpy (mp->hw_addr, hw_addr, 6);
12183 mp->use_random_hw_addr = random_hw_addr;
12184 vec_free (host_if_name);
12186 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
12192 api_af_packet_delete (vat_main_t * vam)
12194 unformat_input_t * i = vam->input;
12195 vl_api_af_packet_delete_t * mp;
12197 u8 * host_if_name = 0;
12199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12200 if (unformat (i, "name %s", &host_if_name))
12201 vec_add1 (host_if_name, 0);
12206 if (!vec_len (host_if_name)) {
12207 errmsg ("host-interface name must be specified");
12211 if (vec_len (host_if_name) > 64) {
12212 errmsg ("host-interface name too long");
12216 M(AF_PACKET_DELETE, af_packet_delete);
12218 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12219 vec_free (host_if_name);
12227 api_policer_add_del (vat_main_t * vam)
12229 unformat_input_t * i = vam->input;
12230 vl_api_policer_add_del_t * mp;
12241 u8 color_aware = 0;
12242 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
12244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12245 if (unformat (i, "del"))
12247 else if (unformat (i, "name %s", &name))
12248 vec_add1 (name, 0);
12249 else if (unformat (i, "cir %u", &cir))
12251 else if (unformat (i, "eir %u", &eir))
12253 else if (unformat (i, "cb %u", &cb))
12255 else if (unformat (i, "eb %u", &eb))
12257 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
12260 else if (unformat (i, "round_type %U", unformat_policer_round_type,
12263 else if (unformat (i, "type %U", unformat_policer_type, &type))
12265 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
12268 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
12271 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
12274 else if (unformat (i, "color-aware"))
12280 if (!vec_len (name)) {
12281 errmsg ("policer name must be specified");
12285 if (vec_len (name) > 64) {
12286 errmsg ("policer name too long");
12290 M(POLICER_ADD_DEL, policer_add_del);
12292 clib_memcpy (mp->name, name, vec_len (name));
12294 mp->is_add = is_add;
12299 mp->rate_type = rate_type;
12300 mp->round_type = round_type;
12302 mp->conform_action_type = conform_action.action_type;
12303 mp->conform_dscp = conform_action.dscp;
12304 mp->exceed_action_type = exceed_action.action_type;
12305 mp->exceed_dscp = exceed_action.dscp;
12306 mp->violate_action_type = violate_action.action_type;
12307 mp->violate_dscp = violate_action.dscp;
12308 mp->color_aware = color_aware;
12316 api_policer_dump(vat_main_t *vam)
12318 unformat_input_t * i = vam->input;
12319 vl_api_policer_dump_t *mp;
12321 u8 *match_name = 0;
12322 u8 match_name_valid = 0;
12324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12325 if (unformat (i, "name %s", &match_name)) {
12326 vec_add1 (match_name, 0);
12327 match_name_valid = 1;
12332 M(POLICER_DUMP, policer_dump);
12333 mp->match_name_valid = match_name_valid;
12334 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
12335 vec_free (match_name);
12339 /* Use a control ping for synchronization */
12341 vl_api_control_ping_t * mp;
12342 M(CONTROL_PING, control_ping);
12345 /* Wait for a reply... */
12353 api_policer_classify_set_interface (vat_main_t * vam)
12355 unformat_input_t * i = vam->input;
12356 vl_api_policer_classify_set_interface_t *mp;
12359 int sw_if_index_set;
12360 u32 ip4_table_index = ~0;
12361 u32 ip6_table_index = ~0;
12362 u32 l2_table_index = ~0;
12365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12366 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
12367 sw_if_index_set = 1;
12368 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12369 sw_if_index_set = 1;
12370 else if (unformat (i, "del"))
12372 else if (unformat (i, "ip4-table %d", &ip4_table_index))
12374 else if (unformat (i, "ip6-table %d", &ip6_table_index))
12376 else if (unformat (i, "l2-table %d", &l2_table_index))
12379 clib_warning ("parse error '%U'", format_unformat_error, i);
12384 if (sw_if_index_set == 0) {
12385 errmsg ("missing interface name or sw_if_index\n");
12389 M(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
12391 mp->sw_if_index = ntohl(sw_if_index);
12392 mp->ip4_table_index = ntohl(ip4_table_index);
12393 mp->ip6_table_index = ntohl(ip6_table_index);
12394 mp->l2_table_index = ntohl(l2_table_index);
12395 mp->is_add = is_add;
12403 api_policer_classify_dump(vat_main_t *vam)
12405 unformat_input_t * i = vam->input;
12406 vl_api_policer_classify_dump_t *mp;
12408 u8 type = POLICER_CLASSIFY_N_TABLES;
12410 if (unformat (i, "type %U", unformat_classify_table_type, &type))
12413 errmsg ("classify table type must be specified\n");
12417 if (!vam->json_output) {
12418 fformat(vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
12421 M(POLICER_CLASSIFY_DUMP, policer_classify_dump);
12426 /* Use a control ping for synchronization */
12428 vl_api_control_ping_t * mp;
12429 M(CONTROL_PING, control_ping);
12432 /* Wait for a reply... */
12440 api_netmap_create (vat_main_t * vam)
12442 unformat_input_t * i = vam->input;
12443 vl_api_netmap_create_t * mp;
12447 u8 random_hw_addr = 1;
12451 memset (hw_addr, 0, sizeof (hw_addr));
12453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12454 if (unformat (i, "name %s", &if_name))
12455 vec_add1 (if_name, 0);
12456 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12457 random_hw_addr = 0;
12458 else if (unformat (i, "pipe"))
12460 else if (unformat (i, "master"))
12462 else if (unformat (i, "slave"))
12468 if (!vec_len (if_name)) {
12469 errmsg ("interface name must be specified");
12473 if (vec_len (if_name) > 64) {
12474 errmsg ("interface name too long");
12478 M(NETMAP_CREATE, netmap_create);
12480 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12481 clib_memcpy (mp->hw_addr, hw_addr, 6);
12482 mp->use_random_hw_addr = random_hw_addr;
12483 mp->is_pipe = is_pipe;
12484 mp->is_master = is_master;
12485 vec_free (if_name);
12493 api_netmap_delete (vat_main_t * vam)
12495 unformat_input_t * i = vam->input;
12496 vl_api_netmap_delete_t * mp;
12500 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12501 if (unformat (i, "name %s", &if_name))
12502 vec_add1 (if_name, 0);
12507 if (!vec_len (if_name)) {
12508 errmsg ("interface name must be specified");
12512 if (vec_len (if_name) > 64) {
12513 errmsg ("interface name too long");
12517 M(NETMAP_DELETE, netmap_delete);
12519 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12520 vec_free (if_name);
12527 static void vl_api_mpls_gre_tunnel_details_t_handler
12528 (vl_api_mpls_gre_tunnel_details_t * mp)
12530 vat_main_t * vam = &vat_main;
12532 i32 len = ntohl(mp->nlabels);
12534 if (mp->l2_only == 0) {
12535 fformat(vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
12536 ntohl(mp->tunnel_index),
12537 format_ip4_address, &mp->tunnel_src,
12538 format_ip4_address, &mp->tunnel_dst,
12539 format_ip4_address, &mp->intfc_address,
12540 ntohl(mp->mask_width));
12541 for (i = 0; i < len; i++) {
12542 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12544 fformat(vam->ofp, "\n");
12545 fformat(vam->ofp, " inner fib index %d, outer fib index %d\n",
12546 ntohl(mp->inner_fib_index), ntohl(mp->outer_fib_index));
12548 fformat(vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
12549 ntohl(mp->tunnel_index),
12550 format_ip4_address, &mp->tunnel_src,
12551 format_ip4_address, &mp->tunnel_dst,
12552 format_ip4_address, &mp->intfc_address);
12553 for (i = 0; i < len; i++) {
12554 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12556 fformat(vam->ofp, "\n");
12557 fformat(vam->ofp, " l2 interface %d, outer fib index %d\n",
12558 ntohl(mp->hw_if_index), ntohl(mp->outer_fib_index));
12562 static void vl_api_mpls_gre_tunnel_details_t_handler_json
12563 (vl_api_mpls_gre_tunnel_details_t * mp)
12565 vat_main_t * vam = &vat_main;
12566 vat_json_node_t *node = NULL;
12567 struct in_addr ip4;
12569 i32 len = ntohl(mp->nlabels);
12571 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12572 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12573 vat_json_init_array(&vam->json_tree);
12575 node = vat_json_array_add(&vam->json_tree);
12577 vat_json_init_object(node);
12578 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
12579 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
12580 vat_json_object_add_ip4(node, "intfc_address", ip4);
12581 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
12582 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
12583 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
12584 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
12585 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
12586 clib_memcpy(&ip4, &(mp->tunnel_src), sizeof(ip4));
12587 vat_json_object_add_ip4(node, "tunnel_src", ip4);
12588 clib_memcpy(&ip4, &(mp->tunnel_dst), sizeof(ip4));
12589 vat_json_object_add_ip4(node, "tunnel_dst", ip4);
12590 vat_json_object_add_uint(node, "outer_fib_index", ntohl(mp->outer_fib_index));
12591 vat_json_object_add_uint(node, "label_count", len);
12592 for (i = 0; i < len; i++) {
12593 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
12597 static int api_mpls_gre_tunnel_dump (vat_main_t * vam)
12599 vl_api_mpls_gre_tunnel_dump_t *mp;
12603 /* Parse args required to build the message */
12604 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
12605 if (!unformat (vam->input, "tunnel_index %d", &index)) {
12611 fformat(vam->ofp, " tunnel_index %d\n", index);
12613 M(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
12614 mp->tunnel_index = htonl(index);
12617 /* Use a control ping for synchronization */
12619 vl_api_control_ping_t * mp;
12620 M(CONTROL_PING, control_ping);
12626 static void vl_api_mpls_eth_tunnel_details_t_handler
12627 (vl_api_mpls_eth_tunnel_details_t * mp)
12629 vat_main_t * vam = &vat_main;
12631 i32 len = ntohl(mp->nlabels);
12633 fformat(vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
12634 ntohl(mp->tunnel_index),
12635 format_ethernet_address, &mp->tunnel_dst_mac,
12636 format_ip4_address, &mp->intfc_address,
12637 ntohl(mp->mask_width));
12638 for (i = 0; i < len; i++) {
12639 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12641 fformat(vam->ofp, "\n");
12642 fformat(vam->ofp, " tx on %d, rx fib index %d\n",
12643 ntohl(mp->tx_sw_if_index),
12644 ntohl(mp->inner_fib_index));
12647 static void vl_api_mpls_eth_tunnel_details_t_handler_json
12648 (vl_api_mpls_eth_tunnel_details_t * mp)
12650 vat_main_t * vam = &vat_main;
12651 vat_json_node_t *node = NULL;
12652 struct in_addr ip4;
12654 i32 len = ntohl(mp->nlabels);
12656 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12657 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12658 vat_json_init_array(&vam->json_tree);
12660 node = vat_json_array_add(&vam->json_tree);
12662 vat_json_init_object(node);
12663 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
12664 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
12665 vat_json_object_add_ip4(node, "intfc_address", ip4);
12666 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
12667 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
12668 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
12669 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
12670 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
12671 vat_json_object_add_string_copy(node, "tunnel_dst_mac",
12672 format(0, "%U", format_ethernet_address, &mp->tunnel_dst_mac));
12673 vat_json_object_add_uint(node, "tx_sw_if_index", ntohl(mp->tx_sw_if_index));
12674 vat_json_object_add_uint(node, "label_count", len);
12675 for (i = 0; i < len; i++) {
12676 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
12680 static int api_mpls_eth_tunnel_dump (vat_main_t * vam)
12682 vl_api_mpls_eth_tunnel_dump_t *mp;
12686 /* Parse args required to build the message */
12687 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
12688 if (!unformat (vam->input, "tunnel_index %d", &index)) {
12694 fformat(vam->ofp, " tunnel_index %d\n", index);
12696 M(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
12697 mp->tunnel_index = htonl(index);
12700 /* Use a control ping for synchronization */
12702 vl_api_control_ping_t * mp;
12703 M(CONTROL_PING, control_ping);
12709 static void vl_api_mpls_fib_encap_details_t_handler
12710 (vl_api_mpls_fib_encap_details_t * mp)
12712 vat_main_t * vam = &vat_main;
12714 i32 len = ntohl(mp->nlabels);
12716 fformat(vam->ofp, "table %d, dest %U, label ",
12717 ntohl(mp->fib_index),
12718 format_ip4_address, &mp->dest,
12720 for (i = 0; i < len; i++) {
12721 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12723 fformat(vam->ofp, "\n");
12726 static void vl_api_mpls_fib_encap_details_t_handler_json
12727 (vl_api_mpls_fib_encap_details_t * mp)
12729 vat_main_t * vam = &vat_main;
12730 vat_json_node_t *node = NULL;
12732 i32 len = ntohl(mp->nlabels);
12733 struct in_addr ip4;
12735 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12736 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12737 vat_json_init_array(&vam->json_tree);
12739 node = vat_json_array_add(&vam->json_tree);
12741 vat_json_init_object(node);
12742 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
12743 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
12744 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
12745 vat_json_object_add_ip4(node, "dest", ip4);
12746 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
12747 vat_json_object_add_uint(node, "label_count", len);
12748 for (i = 0; i < len; i++) {
12749 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
12753 static int api_mpls_fib_encap_dump (vat_main_t * vam)
12755 vl_api_mpls_fib_encap_dump_t *mp;
12758 M(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
12761 /* Use a control ping for synchronization */
12763 vl_api_control_ping_t * mp;
12764 M(CONTROL_PING, control_ping);
12770 static void vl_api_mpls_fib_decap_details_t_handler
12771 (vl_api_mpls_fib_decap_details_t * mp)
12773 vat_main_t * vam = &vat_main;
12775 fformat(vam->ofp, "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
12776 ntohl(mp->rx_table_id),
12777 ntohl(mp->tx_table_id),
12783 static void vl_api_mpls_fib_decap_details_t_handler_json
12784 (vl_api_mpls_fib_decap_details_t * mp)
12786 vat_main_t * vam = &vat_main;
12787 vat_json_node_t *node = NULL;
12788 struct in_addr ip4;
12790 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12791 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12792 vat_json_init_array(&vam->json_tree);
12794 node = vat_json_array_add(&vam->json_tree);
12796 vat_json_init_object(node);
12797 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
12798 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
12799 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
12800 vat_json_object_add_ip4(node, "dest", ip4);
12801 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
12802 vat_json_object_add_uint(node, "label", ntohl(mp->label));
12803 vat_json_object_add_uint(node, "rx_table_id", ntohl(mp->rx_table_id));
12804 vat_json_object_add_uint(node, "tx_table_id", ntohl(mp->tx_table_id));
12805 vat_json_object_add_string_copy(node, "swif_tag", mp->swif_tag);
12808 static int api_mpls_fib_decap_dump (vat_main_t * vam)
12810 vl_api_mpls_fib_decap_dump_t *mp;
12813 M(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
12816 /* Use a control ping for synchronization */
12818 vl_api_control_ping_t * mp;
12819 M(CONTROL_PING, control_ping);
12825 int api_classify_table_ids (vat_main_t *vam)
12827 vl_api_classify_table_ids_t *mp;
12830 /* Construct the API message */
12831 M(CLASSIFY_TABLE_IDS, classify_table_ids);
12839 int api_classify_table_by_interface (vat_main_t *vam)
12841 unformat_input_t * input = vam->input;
12842 vl_api_classify_table_by_interface_t *mp;
12845 u32 sw_if_index = ~0;
12846 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12847 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
12849 else if (unformat (input, "sw_if_index %d", &sw_if_index))
12854 if (sw_if_index == ~0) {
12855 errmsg ("missing interface name or sw_if_index\n");
12859 /* Construct the API message */
12860 M(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
12862 mp->sw_if_index = ntohl(sw_if_index);
12869 int api_classify_table_info (vat_main_t *vam)
12871 unformat_input_t * input = vam->input;
12872 vl_api_classify_table_info_t *mp;
12876 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12877 if (unformat (input, "table_id %d", &table_id))
12882 if (table_id == ~0) {
12883 errmsg ("missing table id\n");
12887 /* Construct the API message */
12888 M(CLASSIFY_TABLE_INFO, classify_table_info);
12890 mp->table_id = ntohl(table_id);
12897 int api_classify_session_dump (vat_main_t *vam)
12899 unformat_input_t * input = vam->input;
12900 vl_api_classify_session_dump_t *mp;
12904 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12905 if (unformat (input, "table_id %d", &table_id))
12910 if (table_id == ~0) {
12911 errmsg ("missing table id\n");
12915 /* Construct the API message */
12916 M(CLASSIFY_SESSION_DUMP, classify_session_dump);
12918 mp->table_id = ntohl(table_id);
12921 /* Use a control ping for synchronization */
12923 vl_api_control_ping_t * mp;
12924 M(CONTROL_PING, control_ping);
12932 static void vl_api_ipfix_details_t_handler (vl_api_ipfix_details_t * mp)
12934 vat_main_t * vam = &vat_main;
12936 fformat(vam->ofp, "collector_address %U, collector_port %d, "
12937 "src_address %U, fib_index %u, path_mtu %u, "
12938 "template_interval %u\n",
12939 format_ip4_address, mp->collector_address,
12940 ntohs(mp->collector_port),
12941 format_ip4_address, mp->src_address,
12942 ntohl(mp->fib_index),
12943 ntohl(mp->path_mtu),
12944 ntohl(mp->template_interval));
12947 vam->result_ready = 1;
12950 static void vl_api_ipfix_details_t_handler_json
12951 (vl_api_ipfix_details_t * mp)
12953 vat_main_t * vam = &vat_main;
12954 vat_json_node_t node;
12955 struct in_addr collector_address;
12956 struct in_addr src_address;
12958 vat_json_init_object(&node);
12959 clib_memcpy(&collector_address, &mp->collector_address,
12960 sizeof(collector_address));
12961 vat_json_object_add_ip4(&node, "collector_address", collector_address);
12962 vat_json_object_add_uint(&node, "collector_port",
12963 ntohs(mp->collector_port));
12964 clib_memcpy(&src_address, &mp->src_address, sizeof(src_address));
12965 vat_json_object_add_ip4(&node, "src_address", src_address);
12966 vat_json_object_add_uint(&node, "fib_index", ntohl(mp->fib_index));
12967 vat_json_object_add_uint(&node, "path_mtu", ntohl(mp->path_mtu));
12968 vat_json_object_add_uint(&node, "template_interval",
12969 ntohl(mp->template_interval));
12971 vat_json_print(vam->ofp, &node);
12972 vat_json_free(&node);
12974 vam->result_ready = 1;
12977 int api_ipfix_dump (vat_main_t *vam)
12979 vl_api_ipfix_dump_t *mp;
12982 /* Construct the API message */
12983 M(IPFIX_DUMP, ipfix_dump);
12991 int api_pg_create_interface (vat_main_t *vam)
12993 unformat_input_t * input = vam->input;
12994 vl_api_pg_create_interface_t *mp;
12998 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
12999 if (unformat (input, "if_id %d", &if_id))
13005 errmsg ("missing pg interface index\n");
13009 /* Construct the API message */
13010 M(PG_CREATE_INTERFACE, pg_create_interface);
13012 mp->interface_id = ntohl(if_id);
13019 int api_pg_capture (vat_main_t *vam)
13021 unformat_input_t * input = vam->input;
13022 vl_api_pg_capture_t *mp;
13028 u8 pcap_file_set = 0;
13029 u8 * pcap_file = 0;
13030 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13031 if (unformat (input, "if_id %d", &if_id))
13033 else if (unformat (input, "pcap %s", &pcap_file))
13035 else if (unformat (input, "count %d", &count))
13037 else if (unformat (input, "disable"))
13043 errmsg ("missing pg interface index\n");
13046 if (pcap_file_set>0) {
13047 if (vec_len (pcap_file) > 255) {
13048 errmsg ("pcap file name is too long\n");
13053 u32 name_len = vec_len(pcap_file);
13054 /* Construct the API message */
13055 M(PG_CAPTURE, pg_capture);
13057 mp->interface_id = ntohl(if_id);
13058 mp->is_enabled = enable;
13059 mp->count = ntohl(count);
13060 mp->pcap_name_length = ntohl(name_len);
13061 if (pcap_file_set != 0) {
13062 clib_memcpy(mp->pcap_file_name, pcap_file, name_len);
13064 vec_free(pcap_file);
13071 int api_pg_enable_disable (vat_main_t *vam)
13073 unformat_input_t * input = vam->input;
13074 vl_api_pg_enable_disable_t *mp;
13078 u8 stream_name_set = 0;
13079 u8 * stream_name = 0;
13080 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13081 if (unformat (input, "stream %s", &stream_name))
13082 stream_name_set = 1;
13083 else if (unformat (input, "disable"))
13089 if (stream_name_set>0) {
13090 if (vec_len (stream_name) > 255) {
13091 errmsg ("stream name too long\n");
13096 u32 name_len = vec_len(stream_name);
13097 /* Construct the API message */
13098 M(PG_ENABLE_DISABLE, pg_enable_disable);
13100 mp->is_enabled = enable;
13101 if (stream_name_set != 0) {
13102 mp->stream_name_length = ntohl(name_len);
13103 clib_memcpy(mp->stream_name, stream_name, name_len);
13105 vec_free(stream_name);
13112 static int q_or_quit (vat_main_t * vam)
13114 longjmp (vam->jump_buf, 1);
13115 return 0; /* not so much */
13117 static int q (vat_main_t * vam) {return q_or_quit (vam);}
13118 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
13120 static int comment (vat_main_t * vam)
13125 static int cmd_cmp (void * a1, void * a2)
13130 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
13133 static int help (vat_main_t * vam)
13138 unformat_input_t * i = vam->input;
13141 if (unformat (i, "%s", &name)) {
13146 hs = hash_get_mem (vam->help_by_name, name);
13148 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
13150 fformat (vam->ofp, "No such msg / command '%s'\n", name);
13155 fformat(vam->ofp, "Help is available for the following:\n");
13157 hash_foreach_pair (p, vam->function_by_name,
13159 vec_add1 (cmds, (u8 *)(p->key));
13162 vec_sort_with_function (cmds, cmd_cmp);
13164 for (j = 0; j < vec_len(cmds); j++)
13165 fformat (vam->ofp, "%s\n", cmds[j]);
13171 static int set (vat_main_t * vam)
13173 u8 * name = 0, * value = 0;
13174 unformat_input_t * i = vam->input;
13176 if (unformat (i, "%s", &name)) {
13177 /* The input buffer is a vector, not a string. */
13178 value = vec_dup (i->buffer);
13179 vec_delete (value, i->index, 0);
13180 /* Almost certainly has a trailing newline */
13181 if (value[vec_len(value)-1] == '\n')
13182 value[vec_len(value)-1] = 0;
13183 /* Make sure it's a proper string, one way or the other */
13184 vec_add1 (value, 0);
13185 (void) clib_macro_set_value (&vam->macro_main,
13186 (char *)name, (char *)value);
13189 errmsg ("usage: set <name> <value>\n");
13196 static int unset (vat_main_t * vam)
13200 if (unformat (vam->input, "%s", &name))
13201 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
13202 errmsg ("unset: %s wasn't set\n", name);
13213 static int macro_sort_cmp (void * a1, void * a2)
13215 macro_sort_t * s1 = a1;
13216 macro_sort_t * s2 = a2;
13218 return strcmp ((char *)(s1->name), (char *)(s2->name));
13221 static int dump_macro_table (vat_main_t * vam)
13223 macro_sort_t * sort_me = 0, * sm;
13227 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
13229 vec_add2 (sort_me, sm, 1);
13230 sm->name = (u8 *)(p->key);
13231 sm->value = (u8 *) (p->value[0]);
13234 vec_sort_with_function (sort_me, macro_sort_cmp);
13236 if (vec_len(sort_me))
13237 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
13239 fformat (vam->ofp, "The macro table is empty...\n");
13241 for (i = 0; i < vec_len (sort_me); i++)
13242 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
13247 static int dump_node_table (vat_main_t * vam)
13250 vlib_node_t * node, * next_node;
13252 if (vec_len (vam->graph_nodes) == 0) {
13253 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13257 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
13258 node = vam->graph_nodes[i];
13259 fformat (vam->ofp, "[%d] %s\n", i, node->name);
13260 for (j = 0; j < vec_len (node->next_nodes); j++) {
13261 if (node->next_nodes[j] != ~0) {
13262 next_node = vam->graph_nodes[node->next_nodes[j]];
13263 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13270 static int search_node_table (vat_main_t * vam)
13272 unformat_input_t * line_input = vam->input;
13275 vlib_node_t * node, * next_node;
13278 if (vam->graph_node_index_by_name == 0) {
13279 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13283 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
13284 if (unformat (line_input, "%s", &node_to_find)) {
13285 vec_add1 (node_to_find, 0);
13286 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
13288 fformat (vam->ofp, "%s not found...\n", node_to_find);
13291 node = vam->graph_nodes[p[0]];
13292 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
13293 for (j = 0; j < vec_len (node->next_nodes); j++) {
13294 if (node->next_nodes[j] != ~0) {
13295 next_node = vam->graph_nodes[node->next_nodes[j]];
13296 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13302 clib_warning ("parse error '%U'", format_unformat_error,
13308 vec_free(node_to_find);
13316 static int script (vat_main_t * vam)
13319 char * save_current_file;
13320 unformat_input_t save_input;
13321 jmp_buf save_jump_buf;
13322 u32 save_line_number;
13324 FILE * new_fp, * save_ifp;
13326 if (unformat (vam->input, "%s", &s)) {
13327 new_fp = fopen ((char *)s, "r");
13329 errmsg ("Couldn't open script file %s\n", s);
13334 errmsg ("Missing script name\n");
13338 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
13339 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
13340 save_ifp = vam->ifp;
13341 save_line_number = vam->input_line_number;
13342 save_current_file = (char *) vam->current_file;
13344 vam->input_line_number = 0;
13346 vam->current_file = s;
13349 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
13350 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
13351 vam->ifp = save_ifp;
13352 vam->input_line_number = save_line_number;
13353 vam->current_file = (u8 *) save_current_file;
13359 static int echo (vat_main_t * vam)
13361 fformat (vam->ofp, "%v", vam->input->buffer);
13365 /* List of API message constructors, CLI names map to api_xxx */
13366 #define foreach_vpe_api_msg \
13367 _(create_loopback,"[mac <mac-addr>]") \
13368 _(sw_interface_dump,"") \
13369 _(sw_interface_set_flags, \
13370 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
13371 _(sw_interface_add_del_address, \
13372 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
13373 _(sw_interface_set_table, \
13374 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
13375 _(sw_interface_set_vpath, \
13376 "<intfc> | sw_if_index <id> enable | disable") \
13377 _(sw_interface_set_l2_xconnect, \
13378 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13379 "enable | disable") \
13380 _(sw_interface_set_l2_bridge, \
13381 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
13382 "[shg <split-horizon-group>] [bvi]\n" \
13383 "enable | disable") \
13384 _(bridge_domain_add_del, \
13385 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
13386 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
13388 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
13390 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
13392 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
13394 "tapname <name> mac <mac-addr> | random-mac") \
13396 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
13398 "<vpp-if-name> | sw_if_index <id>") \
13399 _(sw_interface_tap_dump, "") \
13400 _(ip_add_del_route, \
13401 "<addr>/<mask> via <addr> [vrf <n>]\n" \
13402 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
13403 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
13404 "[multipath] [count <n>]") \
13405 _(proxy_arp_add_del, \
13406 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
13407 _(proxy_arp_intfc_enable_disable, \
13408 "<intfc> | sw_if_index <id> enable | disable") \
13409 _(mpls_add_del_encap, \
13410 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
13411 _(mpls_add_del_decap, \
13412 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
13413 _(mpls_gre_add_del_tunnel, \
13414 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
13415 "adj <ip4-address>/<mask-width> [del]") \
13416 _(sw_interface_set_unnumbered, \
13417 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
13418 _(ip_neighbor_add_del, \
13419 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
13420 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
13421 _(reset_vrf, "vrf <id> [ipv6]") \
13422 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
13423 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
13424 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
13425 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
13426 "[outer_vlan_id_any][inner_vlan_id_any]") \
13427 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
13428 _(reset_fib, "vrf <n> [ipv6]") \
13429 _(dhcp_proxy_config, \
13430 "svr <v46-address> src <v46-address>\n" \
13431 "insert-cid <n> [del]") \
13432 _(dhcp_proxy_config_2, \
13433 "svr <v46-address> src <v46-address>\n" \
13434 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
13435 _(dhcp_proxy_set_vss, \
13436 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
13437 _(dhcp_client_config, \
13438 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
13439 _(set_ip_flow_hash, \
13440 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
13441 _(sw_interface_ip6_enable_disable, \
13442 "<intfc> | sw_if_index <id> enable | disable") \
13443 _(sw_interface_ip6_set_link_local_address, \
13444 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
13445 _(sw_interface_ip6nd_ra_prefix, \
13446 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
13447 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
13448 "[nolink] [isno]") \
13449 _(sw_interface_ip6nd_ra_config, \
13450 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
13451 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
13452 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
13453 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
13454 _(l2_patch_add_del, \
13455 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13456 "enable | disable") \
13457 _(mpls_ethernet_add_del_tunnel, \
13458 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
13459 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
13460 _(mpls_ethernet_add_del_tunnel_2, \
13461 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
13462 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
13463 _(sr_tunnel_add_del, \
13464 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
13465 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
13466 "[policy <policy_name>]") \
13467 _(sr_policy_add_del, \
13468 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
13469 _(sr_multicast_map_add_del, \
13470 "address [ip6 multicast address] sr-policy [policy name] [del]") \
13471 _(classify_add_del_table, \
13472 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
13473 "[del] mask <mask-value>\n" \
13474 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
13475 _(classify_add_del_session, \
13476 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
13477 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
13478 " [l3 [ip4|ip6]]") \
13479 _(classify_set_interface_ip_table, \
13480 "<intfc> | sw_if_index <nn> table <nn>") \
13481 _(classify_set_interface_l2_tables, \
13482 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13483 " [other-table <nn>]") \
13484 _(get_node_index, "node <node-name") \
13485 _(add_node_next, "node <node-name> next <next-node-name>") \
13486 _(l2tpv3_create_tunnel, \
13487 "client_address <ip6-addr> our_address <ip6-addr>\n" \
13488 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
13489 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
13490 _(l2tpv3_set_tunnel_cookies, \
13491 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
13492 "[new_remote_cookie <nn>]\n") \
13493 _(l2tpv3_interface_enable_disable, \
13494 "<intfc> | sw_if_index <nn> enable | disable") \
13495 _(l2tpv3_set_lookup_key, \
13496 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
13497 _(sw_if_l2tpv3_tunnel_dump, "") \
13498 _(vxlan_add_del_tunnel, \
13499 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
13500 " [decap-next l2|ip4|ip6] [del]") \
13501 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13502 _(gre_add_del_tunnel, \
13503 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
13504 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13505 _(l2_fib_clear_table, "") \
13506 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
13507 _(l2_interface_vlan_tag_rewrite, \
13508 "<intfc> | sw_if_index <nn> \n" \
13509 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
13510 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
13511 _(create_vhost_user_if, \
13512 "socket <filename> [server] [renumber <dev_instance>] " \
13513 "[mac <mac_address>]") \
13514 _(modify_vhost_user_if, \
13515 "<intfc> | sw_if_index <nn> socket <filename>\n" \
13516 "[server] [renumber <dev_instance>]") \
13517 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
13518 _(sw_interface_vhost_user_dump, "") \
13519 _(show_version, "") \
13520 _(vxlan_gpe_add_del_tunnel, \
13521 "local <addr> remote <addr> vni <nn>\n" \
13522 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
13523 "[next-ethernet] [next-nsh]\n") \
13524 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13525 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
13526 _(interface_name_renumber, \
13527 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
13528 _(input_acl_set_interface, \
13529 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13530 " [l2-table <nn>] [del]") \
13531 _(want_ip4_arp_events, "address <ip4-address> [del]") \
13532 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
13533 _(ip_dump, "ipv4 | ipv6") \
13534 _(ipsec_spd_add_del, "spd_id <n> [del]") \
13535 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
13537 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
13538 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
13539 " integ_alg <alg> integ_key <hex>") \
13540 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
13541 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
13542 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
13543 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
13544 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
13545 _(ikev2_profile_add_del, "name <profile_name> [del]") \
13546 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
13547 "(auth_data 0x<data> | auth_data <data>)") \
13548 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
13549 "(id_data 0x<data> | id_data <data>) (local|remote)") \
13550 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
13551 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
13552 "(local|remote)") \
13553 _(ikev2_set_local_key, "file <absolute_file_path>") \
13554 _(delete_loopback,"sw_if_index <nn>") \
13555 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
13556 _(map_add_domain, \
13557 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
13558 "ip6-src <ip6addr> " \
13559 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
13560 _(map_del_domain, "index <n>") \
13561 _(map_add_del_rule, \
13562 "index <n> psid <n> dst <ip6addr> [del]") \
13563 _(map_domain_dump, "") \
13564 _(map_rule_dump, "index <map-domain>") \
13565 _(want_interface_events, "enable|disable") \
13566 _(want_stats,"enable|disable") \
13567 _(get_first_msg_id, "client <name>") \
13568 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
13569 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
13570 "fib-id <nn> [ip4][ip6][default]") \
13571 _(get_node_graph, " ") \
13572 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
13573 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
13574 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
13575 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
13576 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
13577 " vrf_id <nn> add | pop | none") \
13578 _(trace_profile_del, "") \
13579 _(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
13580 " sw_if_index <sw_if_index> p <priority> " \
13581 "w <weight>] [del]") \
13582 _(lisp_add_del_locator, "locator-set <locator_name> " \
13583 "iface <intf> | sw_if_index <sw_if_index> " \
13584 "p <priority> w <weight> [del]") \
13585 _(lisp_add_del_local_eid,"vni <vni> eid " \
13586 "<ipv4|ipv6>/<prefix> | <L2 address> " \
13587 "locator-set <locator_name> [del]") \
13588 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
13589 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
13590 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
13591 _(lisp_gpe_enable_disable, "enable|disable") \
13592 _(lisp_enable_disable, "enable|disable") \
13593 _(lisp_gpe_add_del_iface, "up|down") \
13594 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> seid" \
13595 " <src-eid> rloc <locator> p <prio> " \
13596 "w <weight> [rloc <loc> ... ] " \
13597 "action <action>") \
13598 _(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid " \
13599 "<src-eid> rloc <locator> p <prio> w <weight>"\
13600 "[rloc <loc> ... ] action <action>") \
13601 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
13602 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
13603 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
13604 _(lisp_locator_set_dump, "[locator-set-index <ls-index> | " \
13605 "locator-set <loc-set-name>] [local | remote]")\
13606 _(lisp_local_eid_table_dump, "") \
13607 _(lisp_eid_table_map_dump, "") \
13608 _(lisp_gpe_tunnel_dump, "") \
13609 _(lisp_map_resolver_dump, "") \
13610 _(show_lisp_status, "") \
13611 _(lisp_get_map_request_itr_rlocs, "") \
13612 _(show_lisp_pitr, "") \
13613 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
13614 _(af_packet_delete, "name <host interface name>") \
13615 _(policer_add_del, "name <policer name> <params> [del]") \
13616 _(policer_dump, "[name <policer name>]") \
13617 _(policer_classify_set_interface, \
13618 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13619 " [l2-table <nn>] [del]") \
13620 _(policer_classify_dump, "type [ip4|ip6|l2]") \
13621 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
13622 "[master|slave]") \
13623 _(netmap_delete, "name <interface name>") \
13624 _(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
13625 _(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
13626 _(mpls_fib_encap_dump, "") \
13627 _(mpls_fib_decap_dump, "") \
13628 _(classify_table_ids, "") \
13629 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
13630 _(classify_table_info, "table_id <nn>") \
13631 _(classify_session_dump, "table_id <nn>") \
13632 _(ipfix_enable, "collector_address <ip4> [collector_port <nn>] " \
13633 "src_address <ip4> [fib_id <nn>] [path_mtu <nn>] " \
13634 "[template_interval <nn>]") \
13635 _(ipfix_dump, "") \
13636 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
13637 _(pg_create_interface, "if_id <nn>") \
13638 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
13639 _(pg_enable_disable, "[stream <id>] disable")
13641 /* List of command functions, CLI names map directly to functions */
13642 #define foreach_cli_function \
13643 _(comment, "usage: comment <ignore-rest-of-line>") \
13644 _(dump_interface_table, "usage: dump_interface_table") \
13645 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
13646 _(dump_ipv4_table, "usage: dump_ipv4_table") \
13647 _(dump_ipv6_table, "usage: dump_ipv6_table") \
13648 _(dump_stats_table, "usage: dump_stats_table") \
13649 _(dump_macro_table, "usage: dump_macro_table ") \
13650 _(dump_node_table, "usage: dump_node_table") \
13651 _(echo, "usage: echo <message>") \
13652 _(exec, "usage: exec <vpe-debug-CLI-command>") \
13653 _(help, "usage: help") \
13654 _(q, "usage: quit") \
13655 _(quit, "usage: quit") \
13656 _(search_node_table, "usage: search_node_table <name>...") \
13657 _(set, "usage: set <variable-name> <value>") \
13658 _(script, "usage: script <file-name>") \
13659 _(unset, "usage: unset <variable-name>")
13662 static void vl_api_##n##_t_handler_uni \
13663 (vl_api_##n##_t * mp) \
13665 vat_main_t * vam = &vat_main; \
13666 if (vam->json_output) { \
13667 vl_api_##n##_t_handler_json(mp); \
13669 vl_api_##n##_t_handler(mp); \
13672 foreach_vpe_api_reply_msg;
13675 void vat_api_hookup (vat_main_t *vam)
13678 vl_msg_api_set_handlers(VL_API_##N, #n, \
13679 vl_api_##n##_t_handler_uni, \
13681 vl_api_##n##_t_endian, \
13682 vl_api_##n##_t_print, \
13683 sizeof(vl_api_##n##_t), 1);
13684 foreach_vpe_api_reply_msg;
13687 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
13689 vam->sw_if_index_by_interface_name =
13690 hash_create_string (0, sizeof (uword));
13692 vam->function_by_name =
13693 hash_create_string (0, sizeof(uword));
13695 vam->help_by_name =
13696 hash_create_string (0, sizeof(uword));
13698 /* API messages we can send */
13699 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
13700 foreach_vpe_api_msg;
13704 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13705 foreach_vpe_api_msg;
13708 /* CLI functions */
13709 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
13710 foreach_cli_function;
13714 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
13715 foreach_cli_function;
13719 #undef vl_api_version
13720 #define vl_api_version(n,v) static u32 vpe_api_version = v;
13721 #include <vpp-api/vpe.api.h>
13722 #undef vl_api_version
13724 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
13727 * Send the main API signature in slot 0. This bit of code must
13728 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
13730 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);