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_eid_table_details_t_handler (
2171 vl_api_lisp_eid_table_details_t * mp)
2173 vat_main_t *vam = &vat_main;
2174 eid_table_t eid_table;
2176 memset(&eid_table, 0, sizeof(eid_table));
2177 eid_table.is_local = mp->is_local;
2178 eid_table.locator_set_index = mp->locator_set_index;
2179 eid_table.eid_type = mp->eid_type;
2180 eid_table.vni = mp->vni;
2181 eid_table.eid_prefix_len = mp->eid_prefix_len;
2182 eid_table.ttl = mp->ttl;
2183 eid_table.authoritative = mp->authoritative;
2184 clib_memcpy(eid_table.eid, mp->eid, sizeof(eid_table.eid));
2185 vec_add1(vam->eid_tables, eid_table);
2189 vl_api_lisp_eid_table_details_t_handler_json (
2190 vl_api_lisp_eid_table_details_t * mp)
2192 vat_main_t *vam = &vat_main;
2193 eid_table_t eid_table;
2195 memset(&eid_table, 0, sizeof(eid_table));
2196 eid_table.is_local = mp->is_local;
2197 eid_table.locator_set_index = mp->locator_set_index;
2198 eid_table.eid_type = mp->eid_type;
2199 eid_table.vni = mp->vni;
2200 eid_table.eid_prefix_len = mp->eid_prefix_len;
2201 eid_table.ttl = mp->ttl;
2202 eid_table.authoritative = mp->authoritative;
2203 clib_memcpy(eid_table.eid, mp->eid, sizeof(eid_table.eid));
2204 vec_add1(vam->eid_tables, eid_table);
2208 vl_api_lisp_eid_table_map_details_t_handler (
2209 vl_api_lisp_eid_table_map_details_t *mp)
2211 vat_main_t *vam = &vat_main;
2213 u8 * line = format(0, "%=10d%=10d",
2214 clib_net_to_host_u32 (mp->vni),
2215 clib_net_to_host_u32 (mp->vrf));
2216 fformat(vam->ofp, "%v\n", line);
2221 vl_api_lisp_eid_table_map_details_t_handler_json (
2222 vl_api_lisp_eid_table_map_details_t *mp)
2224 vat_main_t *vam = &vat_main;
2225 vat_json_node_t *node = NULL;
2227 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2228 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2229 vat_json_init_array(&vam->json_tree);
2231 node = vat_json_array_add(&vam->json_tree);
2232 vat_json_init_object(node);
2233 vat_json_object_add_uint(node, "vrf", clib_net_to_host_u32 (mp->vrf));
2234 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2240 format_decap_next (u8 * s, va_list * args)
2242 u32 next_index = va_arg (*args, u32);
2246 case LISP_GPE_INPUT_NEXT_DROP:
2247 return format (s, "drop");
2248 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2249 return format (s, "ip4");
2250 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2251 return format (s, "ip6");
2253 return format (s, "unknown %d", next_index);
2259 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2261 vat_main_t *vam = &vat_main;
2263 u8 *flag_str = NULL;
2265 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2267 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2268 foreach_lisp_gpe_flag_bit;
2271 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2272 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2274 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2276 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2278 ntohl(mp->encap_fib_id),
2279 ntohl(mp->decap_fib_id),
2280 format_decap_next, ntohl(mp->dcap_next),
2292 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2293 vl_api_lisp_gpe_tunnel_details_t *mp)
2295 vat_main_t *vam = &vat_main;
2296 vat_json_node_t *node = NULL;
2297 struct in6_addr ip6;
2301 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2303 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2304 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2305 vat_json_init_array(&vam->json_tree);
2307 node = vat_json_array_add(&vam->json_tree);
2309 vat_json_init_object(node);
2310 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2312 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2313 vat_json_object_add_ip6(node, "source address", ip6);
2314 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2315 vat_json_object_add_ip6(node, "destination address", ip6);
2317 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2318 vat_json_object_add_ip4(node, "source address", ip4);
2319 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2320 vat_json_object_add_ip4(node, "destination address", ip4);
2322 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2323 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2324 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2325 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2326 vat_json_object_add_uint(node, "flags", mp->flags);
2327 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2328 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2329 vat_json_object_add_uint(node, "res", mp->res);
2330 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2332 vec_free(next_decap_str);
2336 vl_api_lisp_map_resolver_details_t_handler (
2337 vl_api_lisp_map_resolver_details_t *mp)
2339 vat_main_t *vam = &vat_main;
2341 fformat(vam->ofp, "%=20U\n",
2342 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2347 vl_api_lisp_map_resolver_details_t_handler_json (
2348 vl_api_lisp_map_resolver_details_t *mp)
2350 vat_main_t *vam = &vat_main;
2351 vat_json_node_t *node = NULL;
2352 struct in6_addr ip6;
2355 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2356 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2357 vat_json_init_array(&vam->json_tree);
2359 node = vat_json_array_add(&vam->json_tree);
2361 vat_json_init_object(node);
2363 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2364 vat_json_object_add_ip6(node, "map resolver", ip6);
2366 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2367 vat_json_object_add_ip4(node, "map resolver", ip4);
2372 vl_api_show_lisp_status_reply_t_handler
2373 (vl_api_show_lisp_status_reply_t * mp)
2375 vat_main_t *vam = &vat_main;
2376 i32 retval = ntohl(mp->retval);
2379 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2380 mp->feature_status ? "enabled" : "disabled",
2381 mp->gpe_status ? "enabled" : "disabled");
2384 vam->retval = retval;
2385 vam->result_ready = 1;
2389 vl_api_show_lisp_status_reply_t_handler_json
2390 (vl_api_show_lisp_status_reply_t *mp)
2392 vat_main_t *vam = &vat_main;
2393 vat_json_node_t node;
2394 u8 * gpe_status = NULL;
2395 u8 * feature_status = NULL;
2397 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2398 feature_status = format (0, "%s",
2399 mp->feature_status ? "enabled" : "disabled");
2400 vec_add1 (gpe_status, 0);
2401 vec_add1 (feature_status, 0);
2403 vat_json_init_object(&node);
2404 vat_json_object_add_string_copy(&node, "gpe_status", gpe_status);
2405 vat_json_object_add_string_copy(&node, "feature_status", feature_status);
2407 vec_free (gpe_status);
2408 vec_free (feature_status);
2410 vat_json_print(vam->ofp, &node);
2411 vat_json_free(&node);
2413 vam->retval = ntohl(mp->retval);
2414 vam->result_ready = 1;
2418 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2419 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2421 vat_main_t * vam = &vat_main;
2422 i32 retval = ntohl(mp->retval);
2425 fformat(vam->ofp, "%=20s\n",
2426 mp->locator_set_name);
2429 vam->retval = retval;
2430 vam->result_ready = 1;
2434 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2435 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2437 vat_main_t * vam = &vat_main;
2438 vat_json_node_t * node = NULL;
2440 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2441 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2442 vat_json_init_array(&vam->json_tree);
2444 node = vat_json_array_add(&vam->json_tree);
2446 vat_json_init_object(node);
2447 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2449 vat_json_print(vam->ofp, node);
2450 vat_json_free(node);
2452 vam->retval = ntohl(mp->retval);
2453 vam->result_ready = 1;
2457 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2459 vat_main_t *vam = &vat_main;
2460 i32 retval = ntohl(mp->retval);
2463 fformat(vam->ofp, "%-20s%-16s\n",
2464 mp->status ? "enabled" : "disabled",
2465 mp->status ? (char *) mp->locator_set_name : "");
2468 vam->retval = retval;
2469 vam->result_ready = 1;
2473 vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t * mp)
2475 vat_main_t *vam = &vat_main;
2476 vat_json_node_t node;
2479 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2480 vec_add1 (status, 0);
2482 vat_json_init_object(&node);
2483 vat_json_object_add_string_copy(&node, "status", status);
2485 vat_json_object_add_string_copy(&node, "locator_set", mp->locator_set_name);
2490 vat_json_print(vam->ofp, &node);
2491 vat_json_free(&node);
2493 vam->retval = ntohl(mp->retval);
2494 vam->result_ready = 1;
2497 static u8 * format_policer_type (u8 * s, va_list * va)
2499 u32 i = va_arg (*va, u32);
2501 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2502 s = format (s, "1r2c");
2503 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2504 s = format (s, "1r3c");
2505 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2506 s = format (s, "2r3c-2698");
2507 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2508 s = format (s, "2r3c-4115");
2509 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2510 s = format (s, "2r3c-mef5cf1");
2512 s = format (s, "ILLEGAL");
2516 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2518 u32 i = va_arg (*va, u32);
2520 if (i == SSE2_QOS_RATE_KBPS)
2521 s = format (s, "kbps");
2522 else if (i == SSE2_QOS_RATE_PPS)
2523 s = format(s, "pps");
2525 s = format (s, "ILLEGAL");
2529 static u8 * format_policer_round_type (u8 * s, va_list * va)
2531 u32 i = va_arg (*va, u32);
2533 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2534 s = format(s, "closest");
2535 else if (i == SSE2_QOS_ROUND_TO_UP)
2536 s = format (s, "up");
2537 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2538 s = format (s, "down");
2540 s = format (s, "ILLEGAL");
2544 static u8 * format_policer_action_type (u8 * s, va_list * va)
2546 u32 i = va_arg (*va, u32);
2548 if (i == SSE2_QOS_ACTION_DROP)
2549 s = format (s, "drop");
2550 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2551 s = format (s, "transmit");
2552 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2553 s = format (s, "mark-and-transmit");
2555 s = format (s, "ILLEGAL");
2559 static u8 * format_dscp (u8 * s, va_list * va)
2561 u32 i = va_arg (*va, u32);
2565 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2569 return format (s, "ILLEGAL");
2571 s = format (s, "%s", t);
2575 static void vl_api_policer_details_t_handler
2576 (vl_api_policer_details_t * mp)
2578 vat_main_t * vam = &vat_main;
2579 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2581 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2582 conform_dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2584 conform_dscp_str = format(0, "");
2586 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2587 exceed_dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2589 exceed_dscp_str = format(0, "");
2591 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2592 violate_dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2594 violate_dscp_str = format(0, "");
2596 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2597 "rate type %U, round type %U, %s rate, %s color-aware, "
2598 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2599 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2600 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2602 format_policer_type, mp->type,
2605 clib_net_to_host_u64(mp->cb),
2606 clib_net_to_host_u64(mp->eb),
2607 format_policer_rate_type, mp->rate_type,
2608 format_policer_round_type, mp->round_type,
2609 mp->single_rate ? "single" : "dual",
2610 mp->color_aware ? "is" : "not",
2611 ntohl(mp->cir_tokens_per_period),
2612 ntohl(mp->pir_tokens_per_period),
2614 ntohl(mp->current_limit),
2615 ntohl(mp->current_bucket),
2616 ntohl(mp->extended_limit),
2617 ntohl(mp->extended_bucket),
2618 clib_net_to_host_u64(mp->last_update_time),
2619 format_policer_action_type, mp->conform_action_type,
2621 format_policer_action_type, mp->exceed_action_type,
2623 format_policer_action_type, mp->violate_action_type,
2626 vec_free(conform_dscp_str);
2627 vec_free(exceed_dscp_str);
2628 vec_free(violate_dscp_str);
2631 static void vl_api_policer_details_t_handler_json
2632 (vl_api_policer_details_t * mp)
2634 vat_main_t * vam = &vat_main;
2635 vat_json_node_t *node;
2636 u8 *rate_type_str, *round_type_str, *type_str;
2637 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2639 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2640 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2641 type_str = format(0, "%U", format_policer_type, mp->type);
2642 conform_action_str = format(0, "%U", format_policer_action_type,
2643 mp->conform_action_type);
2644 exceed_action_str = format(0, "%U", format_policer_action_type,
2645 mp->exceed_action_type);
2646 violate_action_str = format(0, "%U", format_policer_action_type,
2647 mp->violate_action_type);
2649 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2650 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2651 vat_json_init_array(&vam->json_tree);
2653 node = vat_json_array_add(&vam->json_tree);
2655 vat_json_init_object(node);
2656 vat_json_object_add_string_copy(node, "name", mp->name);
2657 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2658 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2659 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2660 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2661 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2662 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2663 vat_json_object_add_string_copy(node, "type", type_str);
2664 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2665 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2666 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2667 vat_json_object_add_uint(node, "cir_tokens_per_period",
2668 ntohl(mp->cir_tokens_per_period));
2669 vat_json_object_add_uint(node, "eir_tokens_per_period",
2670 ntohl(mp->pir_tokens_per_period));
2671 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2672 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2673 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2674 vat_json_object_add_uint(node, "extended_bucket",
2675 ntohl(mp->extended_bucket));
2676 vat_json_object_add_uint(node, "last_update_time",
2677 ntohl(mp->last_update_time));
2678 vat_json_object_add_string_copy(node, "conform_action", conform_action_str);
2679 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2680 u8 *dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2681 vat_json_object_add_string_copy(node, "conform_dscp", dscp_str);
2684 vat_json_object_add_string_copy(node, "exceed_action", exceed_action_str);
2685 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2686 u8 *dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2687 vat_json_object_add_string_copy(node, "exceed_dscp", dscp_str);
2690 vat_json_object_add_string_copy(node, "violate_action", violate_action_str);
2691 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2692 u8 *dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2693 vat_json_object_add_string_copy(node, "violate_dscp", dscp_str);
2697 vec_free(rate_type_str);
2698 vec_free(round_type_str);
2700 vec_free(conform_action_str);
2701 vec_free(exceed_action_str);
2702 vec_free(violate_action_str);
2705 static void vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * mp)
2707 vat_main_t * vam = &vat_main;
2708 int i, count = ntohl(mp->count);
2711 fformat (vam->ofp, "classify table ids (%d) : ", count);
2712 for (i = 0; i < count; i++)
2714 fformat (vam->ofp, "%d", ntohl(mp->ids[i]));
2715 fformat (vam->ofp, (i<count-1)?",":"\n");
2717 vam->retval = ntohl(mp->retval);
2718 vam->result_ready = 1;
2721 static void vl_api_classify_table_ids_reply_t_handler_json (vl_api_classify_table_ids_reply_t * mp)
2723 vat_main_t * vam = &vat_main;
2724 int i, count = ntohl(mp->count);
2727 vat_json_node_t node;
2729 vat_json_init_object(&node);
2730 for (i = 0; i < count; i++)
2732 vat_json_object_add_uint(&node, "table_id", ntohl(mp->ids[i]));
2734 vat_json_print(vam->ofp, &node);
2735 vat_json_free(&node);
2737 vam->retval = ntohl(mp->retval);
2738 vam->result_ready = 1;
2741 static void vl_api_classify_table_by_interface_reply_t_handler (vl_api_classify_table_by_interface_reply_t * mp)
2743 vat_main_t * vam = &vat_main;
2746 table_id = ntohl(mp->l2_table_id);
2748 fformat (vam->ofp, "l2 table id : %d\n", table_id);
2750 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
2751 table_id = ntohl(mp->ip4_table_id);
2753 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
2755 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
2756 table_id = ntohl(mp->ip6_table_id);
2758 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
2760 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
2761 vam->retval = ntohl(mp->retval);
2762 vam->result_ready = 1;
2765 static void vl_api_classify_table_by_interface_reply_t_handler_json (vl_api_classify_table_by_interface_reply_t * mp)
2767 vat_main_t * vam = &vat_main;
2768 vat_json_node_t node;
2770 vat_json_init_object(&node);
2772 vat_json_object_add_int(&node, "l2_table_id", ntohl(mp->l2_table_id));
2773 vat_json_object_add_int(&node, "ip4_table_id", ntohl(mp->ip4_table_id));
2774 vat_json_object_add_int(&node, "ip6_table_id", ntohl(mp->ip6_table_id));
2776 vat_json_print(vam->ofp, &node);
2777 vat_json_free(&node);
2779 vam->retval = ntohl(mp->retval);
2780 vam->result_ready = 1;
2783 static void vl_api_policer_add_del_reply_t_handler
2784 (vl_api_policer_add_del_reply_t * mp)
2786 vat_main_t * vam = &vat_main;
2787 i32 retval = ntohl(mp->retval);
2788 if (vam->async_mode) {
2789 vam->async_errors += (retval < 0);
2791 vam->retval = retval;
2792 vam->result_ready = 1;
2793 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2795 * Note: this is just barely thread-safe, depends on
2796 * the main thread spinning waiting for an answer...
2798 errmsg ("policer index %d\n", ntohl(mp->policer_index));
2802 static void vl_api_policer_add_del_reply_t_handler_json
2803 (vl_api_policer_add_del_reply_t * mp)
2805 vat_main_t * vam = &vat_main;
2806 vat_json_node_t node;
2808 vat_json_init_object(&node);
2809 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
2810 vat_json_object_add_uint(&node, "policer_index", ntohl(mp->policer_index));
2812 vat_json_print(vam->ofp, &node);
2813 vat_json_free(&node);
2815 vam->retval = ntohl(mp->retval);
2816 vam->result_ready = 1;
2819 /* Format hex dump. */
2820 u8 * format_hex_bytes (u8 * s, va_list * va)
2822 u8 * bytes = va_arg (*va, u8 *);
2823 int n_bytes = va_arg (*va, int);
2826 /* Print short or long form depending on byte count. */
2827 uword short_form = n_bytes <= 32;
2828 uword indent = format_get_indent (s);
2833 for (i = 0; i < n_bytes; i++)
2835 if (! short_form && (i % 32) == 0)
2836 s = format (s, "%08x: ", i);
2837 s = format (s, "%02x", bytes[i]);
2838 if (! short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2839 s = format (s, "\n%U", format_white_space, indent);
2845 static void vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t * mp)
2847 vat_main_t * vam = &vat_main;
2848 i32 retval = ntohl(mp->retval);
2850 fformat (vam->ofp, "classify table info :\n");
2851 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n", ntohl(mp->active_sessions), ntohl(mp->next_table_index), ntohl(mp->miss_next_index));
2852 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n", ntohl(mp->nbuckets), ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
2853 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask, ntohl(mp->mask_length));
2855 vam->retval = retval;
2856 vam->result_ready = 1;
2859 static void vl_api_classify_table_info_reply_t_handler_json (vl_api_classify_table_info_reply_t * mp)
2861 vat_main_t * vam = &vat_main;
2862 vat_json_node_t node;
2864 i32 retval = ntohl(mp->retval);
2866 vat_json_init_object(&node);
2868 vat_json_object_add_int(&node, "sessions", ntohl(mp->active_sessions));
2869 vat_json_object_add_int(&node, "nexttbl", ntohl(mp->next_table_index));
2870 vat_json_object_add_int(&node, "nextnode", ntohl(mp->miss_next_index));
2871 vat_json_object_add_int(&node, "nbuckets", ntohl(mp->nbuckets));
2872 vat_json_object_add_int(&node, "skip", ntohl(mp->skip_n_vectors));
2873 vat_json_object_add_int(&node, "match", ntohl(mp->match_n_vectors));
2874 u8 * s = format (0, "%U%c",format_hex_bytes, mp->mask, ntohl(mp->mask_length), 0);
2875 vat_json_object_add_string_copy(&node, "mask", s);
2877 vat_json_print(vam->ofp, &node);
2878 vat_json_free(&node);
2880 vam->retval = ntohl(mp->retval);
2881 vam->result_ready = 1;
2884 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
2886 vat_main_t * vam = &vat_main;
2888 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ", ntohl(mp->hit_next_index), ntohl(mp->advance), ntohl(mp->opaque_index));
2889 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match, ntohl(mp->match_length));
2892 static void vl_api_classify_session_details_t_handler_json (vl_api_classify_session_details_t * mp)
2894 vat_main_t * vam = &vat_main;
2895 vat_json_node_t *node = NULL;
2897 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2898 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2899 vat_json_init_array(&vam->json_tree);
2901 node = vat_json_array_add(&vam->json_tree);
2903 vat_json_init_object(node);
2904 vat_json_object_add_int(node, "next_index", ntohl(mp->hit_next_index));
2905 vat_json_object_add_int(node, "advance", ntohl(mp->advance));
2906 vat_json_object_add_int(node, "opaque", ntohl(mp->opaque_index));
2907 u8 * s = format (0, "%U%c",format_hex_bytes, mp->match, ntohl(mp->match_length), 0);
2908 vat_json_object_add_string_copy(node, "match", s);
2911 static void vl_api_pg_create_interface_reply_t_handler
2912 (vl_api_pg_create_interface_reply_t * mp)
2914 vat_main_t * vam = &vat_main;
2916 vam->retval = ntohl(mp->retval);
2917 vam->result_ready = 1;
2920 static void vl_api_pg_create_interface_reply_t_handler_json
2921 (vl_api_pg_create_interface_reply_t * mp)
2923 vat_main_t * vam = &vat_main;
2924 vat_json_node_t node;
2926 i32 retval = ntohl(mp->retval);
2928 vat_json_init_object(&node);
2930 vat_json_object_add_int(&node, "sw_if_index", ntohl(mp->sw_if_index));
2932 vat_json_print(vam->ofp, &node);
2933 vat_json_free(&node);
2935 vam->retval = ntohl(mp->retval);
2936 vam->result_ready = 1;
2939 static void vl_api_policer_classify_details_t_handler
2940 (vl_api_policer_classify_details_t * mp)
2942 vat_main_t * vam = &vat_main;
2944 fformat (vam->ofp, "%10d%20d\n", ntohl(mp->sw_if_index),
2945 ntohl(mp->table_index));
2948 static void vl_api_policer_classify_details_t_handler_json
2949 (vl_api_policer_classify_details_t * mp)
2951 vat_main_t * vam = &vat_main;
2952 vat_json_node_t * node;
2954 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2955 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2956 vat_json_init_array(&vam->json_tree);
2958 node = vat_json_array_add(&vam->json_tree);
2960 vat_json_init_object(node);
2961 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
2962 vat_json_object_add_uint(node, "table_index", ntohl(mp->table_index));
2966 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2967 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2968 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2969 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2972 * Generate boilerplate reply handlers, which
2973 * dig the return value out of the xxx_reply_t API message,
2974 * stick it into vam->retval, and set vam->result_ready
2976 * Could also do this by pointing N message decode slots at
2977 * a single function, but that could break in subtle ways.
2980 #define foreach_standard_reply_retval_handler \
2981 _(sw_interface_set_flags_reply) \
2982 _(sw_interface_add_del_address_reply) \
2983 _(sw_interface_set_table_reply) \
2984 _(sw_interface_set_vpath_reply) \
2985 _(sw_interface_set_l2_bridge_reply) \
2986 _(bridge_domain_add_del_reply) \
2987 _(sw_interface_set_l2_xconnect_reply) \
2988 _(l2fib_add_del_reply) \
2989 _(ip_add_del_route_reply) \
2990 _(proxy_arp_add_del_reply) \
2991 _(proxy_arp_intfc_enable_disable_reply) \
2992 _(mpls_add_del_encap_reply) \
2993 _(mpls_add_del_decap_reply) \
2994 _(mpls_ethernet_add_del_tunnel_2_reply) \
2995 _(sw_interface_set_unnumbered_reply) \
2996 _(ip_neighbor_add_del_reply) \
2997 _(reset_vrf_reply) \
2998 _(oam_add_del_reply) \
2999 _(reset_fib_reply) \
3000 _(dhcp_proxy_config_reply) \
3001 _(dhcp_proxy_config_2_reply) \
3002 _(dhcp_proxy_set_vss_reply) \
3003 _(dhcp_client_config_reply) \
3004 _(set_ip_flow_hash_reply) \
3005 _(sw_interface_ip6_enable_disable_reply) \
3006 _(sw_interface_ip6_set_link_local_address_reply) \
3007 _(sw_interface_ip6nd_ra_prefix_reply) \
3008 _(sw_interface_ip6nd_ra_config_reply) \
3009 _(set_arp_neighbor_limit_reply) \
3010 _(l2_patch_add_del_reply) \
3011 _(sr_tunnel_add_del_reply) \
3012 _(sr_policy_add_del_reply) \
3013 _(sr_multicast_map_add_del_reply) \
3014 _(classify_add_del_session_reply) \
3015 _(classify_set_interface_ip_table_reply) \
3016 _(classify_set_interface_l2_tables_reply) \
3017 _(l2tpv3_set_tunnel_cookies_reply) \
3018 _(l2tpv3_interface_enable_disable_reply) \
3019 _(l2tpv3_set_lookup_key_reply) \
3020 _(l2_fib_clear_table_reply) \
3021 _(l2_interface_efp_filter_reply) \
3022 _(l2_interface_vlan_tag_rewrite_reply) \
3023 _(modify_vhost_user_if_reply) \
3024 _(delete_vhost_user_if_reply) \
3025 _(want_ip4_arp_events_reply) \
3026 _(input_acl_set_interface_reply) \
3027 _(ipsec_spd_add_del_reply) \
3028 _(ipsec_interface_add_del_spd_reply) \
3029 _(ipsec_spd_add_del_entry_reply) \
3030 _(ipsec_sad_add_del_entry_reply) \
3031 _(ipsec_sa_set_key_reply) \
3032 _(ikev2_profile_add_del_reply) \
3033 _(ikev2_profile_set_auth_reply) \
3034 _(ikev2_profile_set_id_reply) \
3035 _(ikev2_profile_set_ts_reply) \
3036 _(ikev2_set_local_key_reply) \
3037 _(delete_loopback_reply) \
3038 _(bd_ip_mac_add_del_reply) \
3039 _(map_del_domain_reply) \
3040 _(map_add_del_rule_reply) \
3041 _(want_interface_events_reply) \
3042 _(want_stats_reply) \
3043 _(cop_interface_enable_disable_reply) \
3044 _(cop_whitelist_enable_disable_reply) \
3045 _(sw_interface_clear_stats_reply) \
3046 _(trace_profile_add_reply) \
3047 _(trace_profile_apply_reply) \
3048 _(trace_profile_del_reply) \
3049 _(lisp_add_del_locator_set_reply) \
3050 _(lisp_add_del_locator_reply) \
3051 _(lisp_add_del_local_eid_reply) \
3052 _(lisp_add_del_remote_mapping_reply) \
3053 _(lisp_add_del_adjacency_reply) \
3054 _(lisp_gpe_add_del_fwd_entry_reply) \
3055 _(lisp_add_del_map_resolver_reply) \
3056 _(lisp_gpe_enable_disable_reply) \
3057 _(lisp_gpe_add_del_iface_reply) \
3058 _(lisp_enable_disable_reply) \
3059 _(lisp_pitr_set_locator_set_reply) \
3060 _(lisp_add_del_map_request_itr_rlocs_reply) \
3061 _(lisp_eid_table_add_del_map_reply) \
3062 _(vxlan_gpe_add_del_tunnel_reply) \
3063 _(af_packet_delete_reply) \
3064 _(policer_classify_set_interface_reply) \
3065 _(netmap_create_reply) \
3066 _(netmap_delete_reply) \
3067 _(ipfix_enable_reply) \
3068 _(pg_capture_reply) \
3069 _(pg_enable_disable_reply)
3072 static void vl_api_##n##_t_handler \
3073 (vl_api_##n##_t * mp) \
3075 vat_main_t * vam = &vat_main; \
3076 i32 retval = ntohl(mp->retval); \
3077 if (vam->async_mode) { \
3078 vam->async_errors += (retval < 0); \
3080 vam->retval = retval; \
3081 vam->result_ready = 1; \
3084 foreach_standard_reply_retval_handler;
3088 static void vl_api_##n##_t_handler_json \
3089 (vl_api_##n##_t * mp) \
3091 vat_main_t * vam = &vat_main; \
3092 vat_json_node_t node; \
3093 vat_json_init_object(&node); \
3094 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3095 vat_json_print(vam->ofp, &node); \
3096 vam->retval = ntohl(mp->retval); \
3097 vam->result_ready = 1; \
3099 foreach_standard_reply_retval_handler;
3103 * Table of message reply handlers, must include boilerplate handlers
3107 #define foreach_vpe_api_reply_msg \
3108 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3109 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3110 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3111 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3112 _(CONTROL_PING_REPLY, control_ping_reply) \
3113 _(NOPRINT_CONTROL_PING_REPLY, noprint_control_ping_reply) \
3114 _(CLI_REPLY, cli_reply) \
3115 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3116 sw_interface_add_del_address_reply) \
3117 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3118 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3119 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3120 sw_interface_set_l2_xconnect_reply) \
3121 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3122 sw_interface_set_l2_bridge_reply) \
3123 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3124 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3125 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3126 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3127 _(L2_FLAGS_REPLY, l2_flags_reply) \
3128 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3129 _(TAP_CONNECT_REPLY, tap_connect_reply) \
3130 _(TAP_MODIFY_REPLY, tap_modify_reply) \
3131 _(TAP_DELETE_REPLY, tap_delete_reply) \
3132 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3133 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3134 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3135 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3136 proxy_arp_intfc_enable_disable_reply) \
3137 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3138 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3139 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3140 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3141 mpls_ethernet_add_del_tunnel_reply) \
3142 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3143 mpls_ethernet_add_del_tunnel_2_reply) \
3144 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3145 sw_interface_set_unnumbered_reply) \
3146 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3147 _(RESET_VRF_REPLY, reset_vrf_reply) \
3148 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3149 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3150 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3151 _(RESET_FIB_REPLY, reset_fib_reply) \
3152 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3153 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3154 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3155 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3156 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3157 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3158 sw_interface_ip6_enable_disable_reply) \
3159 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3160 sw_interface_ip6_set_link_local_address_reply) \
3161 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3162 sw_interface_ip6nd_ra_prefix_reply) \
3163 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3164 sw_interface_ip6nd_ra_config_reply) \
3165 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3166 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3167 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
3168 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3169 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
3170 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3171 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3172 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3173 classify_set_interface_ip_table_reply) \
3174 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3175 classify_set_interface_l2_tables_reply) \
3176 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3177 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3178 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3179 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3180 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3181 l2tpv3_interface_enable_disable_reply) \
3182 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3183 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3184 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3185 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3186 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3187 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
3188 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3189 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3190 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3191 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3192 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3193 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3194 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3195 _(SHOW_VERSION_REPLY, show_version_reply) \
3196 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
3197 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3198 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3199 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3200 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3201 _(IP4_ARP_EVENT, ip4_arp_event) \
3202 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3203 _(IP_ADDRESS_DETAILS, ip_address_details) \
3204 _(IP_DETAILS, ip_details) \
3205 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3206 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3207 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3208 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3209 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
3210 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3211 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3212 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3213 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3214 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
3215 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3216 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3217 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
3218 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3219 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3220 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3221 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3222 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
3223 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
3224 _(MAP_DOMAIN_DETAILS, map_domain_details) \
3225 _(MAP_RULE_DETAILS, map_rule_details) \
3226 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3227 _(WANT_STATS_REPLY, want_stats_reply) \
3228 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3229 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3230 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3231 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3232 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3233 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
3234 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
3235 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
3236 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3237 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3238 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
3239 _(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3240 _(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
3241 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3242 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
3243 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
3244 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
3245 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
3246 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
3247 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3248 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
3249 _(LISP_LOCATOR_DETAILS, lisp_locator_details) \
3250 _(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
3251 _(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
3252 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
3253 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
3254 _(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
3255 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3256 lisp_add_del_map_request_itr_rlocs_reply) \
3257 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3258 lisp_get_map_request_itr_rlocs_reply) \
3259 _(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
3260 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3261 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3262 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3263 _(POLICER_DETAILS, policer_details) \
3264 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3265 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3266 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
3267 _(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3268 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3269 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3270 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
3271 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3272 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3273 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3274 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3275 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3276 _(IPFIX_ENABLE_REPLY, ipfix_enable_reply) \
3277 _(IPFIX_DETAILS, ipfix_details) \
3278 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3279 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3280 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3281 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply)
3283 /* M: construct, but don't yet send a message */
3287 vam->result_ready = 0; \
3288 mp = vl_msg_api_alloc(sizeof(*mp)); \
3289 memset (mp, 0, sizeof (*mp)); \
3290 mp->_vl_msg_id = ntohs (VL_API_##T); \
3291 mp->client_index = vam->my_client_index; \
3296 vam->result_ready = 0; \
3297 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3298 memset (mp, 0, sizeof (*mp)); \
3299 mp->_vl_msg_id = ntohs (VL_API_##T); \
3300 mp->client_index = vam->my_client_index; \
3304 /* S: send a message */
3305 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3307 /* W: wait for results, with timeout */
3310 timeout = vat_time_now (vam) + 1.0; \
3312 while (vat_time_now (vam) < timeout) { \
3313 if (vam->result_ready == 1) { \
3314 return (vam->retval); \
3320 /* W2: wait for results, with timeout */
3323 timeout = vat_time_now (vam) + 1.0; \
3325 while (vat_time_now (vam) < timeout) { \
3326 if (vam->result_ready == 1) { \
3328 return (vam->retval); \
3334 /* W_L: wait for results, with timeout */
3337 timeout = vat_time_now (vam) + 1.0; \
3339 while (vat_time_now (vam) < timeout) { \
3340 if (vam->result_ready == 1) { \
3342 return (vam->retval); \
3345 vam->noprint_msg = 0; \
3355 #define STR_VTR_OP_CASE(op) \
3356 case L2_VTR_ ## op: \
3359 static const char *str_vtr_op(u32 vtr_op)
3362 STR_VTR_OP_CASE(DISABLED);
3363 STR_VTR_OP_CASE(PUSH_1);
3364 STR_VTR_OP_CASE(PUSH_2);
3365 STR_VTR_OP_CASE(POP_1);
3366 STR_VTR_OP_CASE(POP_2);
3367 STR_VTR_OP_CASE(TRANSLATE_1_1);
3368 STR_VTR_OP_CASE(TRANSLATE_1_2);
3369 STR_VTR_OP_CASE(TRANSLATE_2_1);
3370 STR_VTR_OP_CASE(TRANSLATE_2_2);
3376 static int dump_sub_interface_table (vat_main_t * vam)
3378 const sw_interface_subif_t * sub = NULL;
3380 if (vam->json_output) {
3381 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3386 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3387 "Interface", "sw_if_index",
3388 "sub id", "dot1ad", "tags", "outer id",
3389 "inner id", "exact", "default",
3390 "outer any", "inner any");
3392 vec_foreach (sub, vam->sw_if_subif_table) {
3394 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3395 sub->interface_name,
3397 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3398 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3399 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3400 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3401 if (sub->vtr_op != L2_VTR_DISABLED) {
3403 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3404 "tag1: %d tag2: %d ]\n",
3405 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
3406 sub->vtr_tag1, sub->vtr_tag2);
3413 static int name_sort_cmp (void * a1, void * a2)
3415 name_sort_t * n1 = a1;
3416 name_sort_t * n2 = a2;
3418 return strcmp ((char *)n1->name, (char *)n2->name);
3421 static int dump_interface_table (vat_main_t * vam)
3424 name_sort_t * nses = 0, * ns;
3426 if (vam->json_output) {
3427 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3431 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3433 vec_add2 (nses, ns, 1);
3434 ns->name = (u8 *)(p->key);
3435 ns->value = (u32) p->value[0];
3438 vec_sort_with_function (nses, name_sort_cmp);
3440 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3441 vec_foreach (ns, nses) {
3442 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3448 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
3450 const ip_details_t * det = NULL;
3451 const ip_address_details_t * address = NULL;
3462 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
3464 if (!det->present) {
3472 "Address", "Prefix length");
3476 vec_foreach (address, det->addr) {
3479 is_ipv6 ? format_ip6_address : format_ip4_address,
3481 address->prefix_length);
3488 static int dump_ipv4_table (vat_main_t * vam)
3490 if (vam->json_output) {
3491 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3495 return dump_ip_table (vam, 0);
3498 static int dump_ipv6_table (vat_main_t * vam)
3500 if (vam->json_output) {
3501 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3505 return dump_ip_table (vam, 1);
3508 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
3511 switch(counter_type) {
3512 case VNET_INTERFACE_COUNTER_DROP:
3514 case VNET_INTERFACE_COUNTER_PUNT:
3516 case VNET_INTERFACE_COUNTER_IP4:
3518 case VNET_INTERFACE_COUNTER_IP6:
3520 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3522 case VNET_INTERFACE_COUNTER_RX_MISS:
3524 case VNET_INTERFACE_COUNTER_RX_ERROR:
3526 case VNET_INTERFACE_COUNTER_TX_ERROR:
3529 return "INVALID-COUNTER-TYPE";
3532 switch(counter_type) {
3533 case VNET_INTERFACE_COUNTER_RX:
3535 case VNET_INTERFACE_COUNTER_TX:
3538 return "INVALID-COUNTER-TYPE";
3543 static int dump_stats_table (vat_main_t * vam)
3545 vat_json_node_t node;
3546 vat_json_node_t *msg_array;
3547 vat_json_node_t *msg;
3548 vat_json_node_t *counter_array;
3549 vat_json_node_t *counter;
3550 interface_counter_t c;
3552 ip4_fib_counter_t *c4;
3553 ip6_fib_counter_t *c6;
3556 if (!vam->json_output) {
3557 clib_warning ("dump_stats_table supported only in JSON format");
3561 vat_json_init_object(&node);
3563 /* interface counters */
3564 msg_array = vat_json_object_add(&node, "interface_counters");
3565 vat_json_init_array(msg_array);
3566 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
3567 msg = vat_json_array_add(msg_array);
3568 vat_json_init_object(msg);
3569 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3570 (u8*)counter_type_to_str(i, 0));
3571 vat_json_object_add_int(msg, "is_combined", 0);
3572 counter_array = vat_json_object_add(msg, "data");
3573 vat_json_init_array(counter_array);
3574 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
3575 packets = vam->simple_interface_counters[i][j];
3576 vat_json_array_add_uint(counter_array, packets);
3579 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
3580 msg = vat_json_array_add(msg_array);
3581 vat_json_init_object(msg);
3582 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3583 (u8*)counter_type_to_str(i, 1));
3584 vat_json_object_add_int(msg, "is_combined", 1);
3585 counter_array = vat_json_object_add(msg, "data");
3586 vat_json_init_array(counter_array);
3587 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
3588 c = vam->combined_interface_counters[i][j];
3589 counter = vat_json_array_add(counter_array);
3590 vat_json_init_object(counter);
3591 vat_json_object_add_uint(counter, "packets", c.packets);
3592 vat_json_object_add_uint(counter, "bytes", c.bytes);
3596 /* ip4 fib counters */
3597 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
3598 vat_json_init_array(msg_array);
3599 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
3600 msg = vat_json_array_add(msg_array);
3601 vat_json_init_object(msg);
3602 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
3603 counter_array = vat_json_object_add(msg, "c");
3604 vat_json_init_array(counter_array);
3605 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
3606 counter = vat_json_array_add(counter_array);
3607 vat_json_init_object(counter);
3608 c4 = &vam->ip4_fib_counters[i][j];
3609 vat_json_object_add_ip4(counter, "address", c4->address);
3610 vat_json_object_add_uint(counter, "address_length", c4->address_length);
3611 vat_json_object_add_uint(counter, "packets", c4->packets);
3612 vat_json_object_add_uint(counter, "bytes", c4->bytes);
3616 /* ip6 fib counters */
3617 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
3618 vat_json_init_array(msg_array);
3619 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
3620 msg = vat_json_array_add(msg_array);
3621 vat_json_init_object(msg);
3622 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
3623 counter_array = vat_json_object_add(msg, "c");
3624 vat_json_init_array(counter_array);
3625 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
3626 counter = vat_json_array_add(counter_array);
3627 vat_json_init_object(counter);
3628 c6 = &vam->ip6_fib_counters[i][j];
3629 vat_json_object_add_ip6(counter, "address", c6->address);
3630 vat_json_object_add_uint(counter, "address_length", c6->address_length);
3631 vat_json_object_add_uint(counter, "packets", c6->packets);
3632 vat_json_object_add_uint(counter, "bytes", c6->bytes);
3636 vat_json_print(vam->ofp, &node);
3637 vat_json_free(&node);
3642 int exec (vat_main_t * vam)
3644 api_main_t * am = &api_main;
3645 vl_api_cli_request_t *mp;
3649 unformat_input_t * i = vam->input;
3651 if (vec_len(i->buffer) == 0)
3654 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3658 if (vam->exec_mode == 1 &&
3659 (unformat (i, "exit") || unformat (i, "quit"))) {
3665 M(CLI_REQUEST, cli_request);
3668 * Copy cmd into shared memory.
3669 * In order for the CLI command to work, it
3670 * must be a vector ending in \n, not a C-string ending
3673 pthread_mutex_lock (&am->vlib_rp->mutex);
3674 oldheap = svm_push_data_heap (am->vlib_rp);
3676 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3677 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3679 svm_pop_heap (oldheap);
3680 pthread_mutex_unlock (&am->vlib_rp->mutex);
3682 mp->cmd_in_shmem = (u64) cmd;
3684 timeout = vat_time_now (vam) + 10.0;
3686 while (vat_time_now (vam) < timeout) {
3687 if (vam->result_ready == 1) {
3689 if (vam->shmem_result != NULL)
3690 fformat (vam->ofp, "%s", vam->shmem_result);
3691 pthread_mutex_lock (&am->vlib_rp->mutex);
3692 oldheap = svm_push_data_heap (am->vlib_rp);
3694 free_me = (u8 *)vam->shmem_result;
3697 svm_pop_heap (oldheap);
3698 pthread_mutex_unlock (&am->vlib_rp->mutex);
3705 static int api_create_loopback (vat_main_t * vam)
3707 unformat_input_t * i = vam->input;
3708 vl_api_create_loopback_t *mp;
3713 memset (mac_address, 0, sizeof (mac_address));
3715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3717 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3723 /* Construct the API message */
3724 M(CREATE_LOOPBACK, create_loopback);
3726 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3731 static int api_delete_loopback (vat_main_t * vam)
3733 unformat_input_t * i = vam->input;
3734 vl_api_delete_loopback_t *mp;
3736 u32 sw_if_index = ~0;
3738 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3740 if (unformat (i, "sw_if_index %d", &sw_if_index))
3746 if (sw_if_index == ~0)
3748 errmsg ("missing sw_if_index\n");
3752 /* Construct the API message */
3753 M(DELETE_LOOPBACK, delete_loopback);
3754 mp->sw_if_index = ntohl (sw_if_index);
3759 static int api_want_stats (vat_main_t * vam)
3761 unformat_input_t * i = vam->input;
3762 vl_api_want_stats_t * mp;
3766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3768 if (unformat (i, "enable"))
3770 else if (unformat (i, "disable"))
3778 errmsg ("missing enable|disable\n");
3782 M(WANT_STATS, want_stats);
3783 mp->enable_disable = enable;
3788 static int api_want_interface_events (vat_main_t * vam)
3790 unformat_input_t * i = vam->input;
3791 vl_api_want_interface_events_t * mp;
3795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3797 if (unformat (i, "enable"))
3799 else if (unformat (i, "disable"))
3807 errmsg ("missing enable|disable\n");
3811 M(WANT_INTERFACE_EVENTS, want_interface_events);
3812 mp->enable_disable = enable;
3814 vam->interface_event_display = enable;
3820 /* Note: non-static, called once to set up the initial intfc table */
3821 int api_sw_interface_dump (vat_main_t * vam)
3823 vl_api_sw_interface_dump_t *mp;
3826 name_sort_t * nses = 0, * ns;
3827 sw_interface_subif_t * sub = NULL;
3829 /* Toss the old name table */
3830 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3832 vec_add2 (nses, ns, 1);
3833 ns->name = (u8 *)(p->key);
3834 ns->value = (u32) p->value[0];
3837 hash_free (vam->sw_if_index_by_interface_name);
3839 vec_foreach (ns, nses)
3840 vec_free (ns->name);
3844 vec_foreach (sub, vam->sw_if_subif_table) {
3845 vec_free (sub->interface_name);
3847 vec_free (vam->sw_if_subif_table);
3849 /* recreate the interface name hash table */
3850 vam->sw_if_index_by_interface_name
3851 = hash_create_string (0, sizeof(uword));
3853 /* Get list of ethernets */
3854 M(SW_INTERFACE_DUMP, sw_interface_dump);
3855 mp->name_filter_valid = 1;
3856 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3859 /* and local / loopback interfaces */
3860 M(SW_INTERFACE_DUMP, sw_interface_dump);
3861 mp->name_filter_valid = 1;
3862 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3866 /* and vxlan-gpe tunnel interfaces */
3867 M(SW_INTERFACE_DUMP, sw_interface_dump);
3868 mp->name_filter_valid = 1;
3869 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3872 /* and vxlan tunnel interfaces */
3873 M(SW_INTERFACE_DUMP, sw_interface_dump);
3874 mp->name_filter_valid = 1;
3875 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3878 /* and host (af_packet) interfaces */
3879 M(SW_INTERFACE_DUMP, sw_interface_dump);
3880 mp->name_filter_valid = 1;
3881 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3884 /* and l2tpv3 tunnel interfaces */
3885 M(SW_INTERFACE_DUMP, sw_interface_dump);
3886 mp->name_filter_valid = 1;
3887 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3890 /* and GRE tunnel interfaces */
3891 M(SW_INTERFACE_DUMP, sw_interface_dump);
3892 mp->name_filter_valid = 1;
3893 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3896 /* Use a control ping for synchronization */
3898 vl_api_control_ping_t * mp;
3899 M(CONTROL_PING, control_ping);
3905 static int api_sw_interface_set_flags (vat_main_t * vam)
3907 unformat_input_t * i = vam->input;
3908 vl_api_sw_interface_set_flags_t *mp;
3911 u8 sw_if_index_set = 0;
3912 u8 admin_up = 0, link_up = 0;
3914 /* Parse args required to build the message */
3915 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3916 if (unformat (i, "admin-up"))
3918 else if (unformat (i, "admin-down"))
3920 else if (unformat (i, "link-up"))
3922 else if (unformat (i, "link-down"))
3924 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3925 sw_if_index_set = 1;
3926 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3927 sw_if_index_set = 1;
3932 if (sw_if_index_set == 0) {
3933 errmsg ("missing interface name or sw_if_index\n");
3937 /* Construct the API message */
3938 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3939 mp->sw_if_index = ntohl (sw_if_index);
3940 mp->admin_up_down = admin_up;
3941 mp->link_up_down = link_up;
3946 /* Wait for a reply, return the good/bad news... */
3950 static int api_sw_interface_clear_stats (vat_main_t * vam)
3952 unformat_input_t * i = vam->input;
3953 vl_api_sw_interface_clear_stats_t *mp;
3956 u8 sw_if_index_set = 0;
3958 /* Parse args required to build the message */
3959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3960 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3961 sw_if_index_set = 1;
3962 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3963 sw_if_index_set = 1;
3968 /* Construct the API message */
3969 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3971 if (sw_if_index_set == 1)
3972 mp->sw_if_index = ntohl (sw_if_index);
3974 mp->sw_if_index = ~0;
3979 /* Wait for a reply, return the good/bad news... */
3983 static int api_sw_interface_add_del_address (vat_main_t * vam)
3985 unformat_input_t * i = vam->input;
3986 vl_api_sw_interface_add_del_address_t *mp;
3989 u8 sw_if_index_set = 0;
3990 u8 is_add = 1, del_all = 0;
3991 u32 address_length = 0;
3992 u8 v4_address_set = 0;
3993 u8 v6_address_set = 0;
3994 ip4_address_t v4address;
3995 ip6_address_t v6address;
3997 /* Parse args required to build the message */
3998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3999 if (unformat (i, "del-all"))
4001 else if (unformat (i, "del"))
4003 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4004 sw_if_index_set = 1;
4005 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4006 sw_if_index_set = 1;
4007 else if (unformat (i, "%U/%d",
4008 unformat_ip4_address, &v4address,
4011 else if (unformat (i, "%U/%d",
4012 unformat_ip6_address, &v6address,
4019 if (sw_if_index_set == 0) {
4020 errmsg ("missing interface name or sw_if_index\n");
4023 if (v4_address_set && v6_address_set) {
4024 errmsg ("both v4 and v6 addresses set\n");
4027 if (!v4_address_set && !v6_address_set && !del_all) {
4028 errmsg ("no addresses set\n");
4032 /* Construct the API message */
4033 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4035 mp->sw_if_index = ntohl (sw_if_index);
4036 mp->is_add = is_add;
4037 mp->del_all = del_all;
4038 if (v6_address_set) {
4040 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4042 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4044 mp->address_length = address_length;
4049 /* Wait for a reply, return good/bad news */
4053 static int api_sw_interface_set_table (vat_main_t * vam)
4055 unformat_input_t * i = vam->input;
4056 vl_api_sw_interface_set_table_t *mp;
4058 u32 sw_if_index, vrf_id = 0;
4059 u8 sw_if_index_set = 0;
4062 /* Parse args required to build the message */
4063 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4064 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4065 sw_if_index_set = 1;
4066 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4067 sw_if_index_set = 1;
4068 else if (unformat (i, "vrf %d", &vrf_id))
4070 else if (unformat (i, "ipv6"))
4076 if (sw_if_index_set == 0) {
4077 errmsg ("missing interface name or sw_if_index\n");
4081 /* Construct the API message */
4082 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4084 mp->sw_if_index = ntohl (sw_if_index);
4085 mp->is_ipv6 = is_ipv6;
4086 mp->vrf_id = ntohl (vrf_id);
4091 /* Wait for a reply... */
4095 static int api_sw_interface_set_vpath (vat_main_t * vam)
4097 unformat_input_t * i = vam->input;
4098 vl_api_sw_interface_set_vpath_t *mp;
4100 u32 sw_if_index = 0;
4101 u8 sw_if_index_set = 0;
4104 /* Parse args required to build the message */
4105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4106 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4107 sw_if_index_set = 1;
4108 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4109 sw_if_index_set = 1;
4110 else if (unformat (i, "enable"))
4112 else if (unformat (i, "disable"))
4118 if (sw_if_index_set == 0) {
4119 errmsg ("missing interface name or sw_if_index\n");
4123 /* Construct the API message */
4124 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4126 mp->sw_if_index = ntohl (sw_if_index);
4127 mp->enable = is_enable;
4132 /* Wait for a reply... */
4136 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4138 unformat_input_t * i = vam->input;
4139 vl_api_sw_interface_set_l2_xconnect_t *mp;
4142 u8 rx_sw_if_index_set = 0;
4144 u8 tx_sw_if_index_set = 0;
4147 /* Parse args required to build the message */
4148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4149 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4150 rx_sw_if_index_set = 1;
4151 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4152 tx_sw_if_index_set = 1;
4153 else if (unformat (i, "rx")) {
4154 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4155 if (unformat (i, "%U", unformat_sw_if_index, vam,
4157 rx_sw_if_index_set = 1;
4160 } else if (unformat (i, "tx")) {
4161 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4162 if (unformat (i, "%U", unformat_sw_if_index, vam,
4164 tx_sw_if_index_set = 1;
4167 } else if (unformat (i, "enable"))
4169 else if (unformat (i, "disable"))
4175 if (rx_sw_if_index_set == 0) {
4176 errmsg ("missing rx interface name or rx_sw_if_index\n");
4180 if (enable && (tx_sw_if_index_set == 0)) {
4181 errmsg ("missing tx interface name or tx_sw_if_index\n");
4185 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
4187 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4188 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4189 mp->enable = enable;
4196 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
4198 unformat_input_t * i = vam->input;
4199 vl_api_sw_interface_set_l2_bridge_t *mp;
4202 u8 rx_sw_if_index_set = 0;
4209 /* Parse args required to build the message */
4210 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4211 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4212 rx_sw_if_index_set = 1;
4213 else if (unformat (i, "bd_id %d", &bd_id))
4215 else if (unformat (i, "%U", unformat_sw_if_index, vam,
4217 rx_sw_if_index_set = 1;
4218 else if (unformat (i, "shg %d", &shg))
4220 else if (unformat (i, "bvi"))
4222 else if (unformat (i, "enable"))
4224 else if (unformat (i, "disable"))
4230 if (rx_sw_if_index_set == 0) {
4231 errmsg ("missing rx interface name or sw_if_index\n");
4235 if (enable && (bd_id_set == 0)) {
4236 errmsg ("missing bridge domain\n");
4240 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
4242 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4243 mp->bd_id = ntohl(bd_id);
4246 mp->enable = enable;
4253 static int api_bridge_domain_dump (vat_main_t * vam)
4255 unformat_input_t * i = vam->input;
4256 vl_api_bridge_domain_dump_t *mp;
4260 /* Parse args required to build the message */
4261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4262 if (unformat (i, "bd_id %d", &bd_id))
4268 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
4269 mp->bd_id = ntohl(bd_id);
4272 /* Use a control ping for synchronization */
4274 vl_api_control_ping_t * mp;
4275 M(CONTROL_PING, control_ping);
4284 static int api_bridge_domain_add_del (vat_main_t * vam)
4286 unformat_input_t * i = vam->input;
4287 vl_api_bridge_domain_add_del_t *mp;
4291 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4293 /* Parse args required to build the message */
4294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4295 if (unformat (i, "bd_id %d", &bd_id))
4297 else if (unformat (i, "flood %d", &flood))
4299 else if (unformat (i, "uu-flood %d", &uu_flood))
4301 else if (unformat (i, "forward %d", &forward))
4303 else if (unformat (i, "learn %d", &learn))
4305 else if (unformat (i, "arp-term %d", &arp_term))
4307 else if (unformat (i, "del")) {
4309 flood = uu_flood = forward = learn = 0;
4316 errmsg ("missing bridge domain\n");
4320 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
4322 mp->bd_id = ntohl(bd_id);
4324 mp->uu_flood = uu_flood;
4325 mp->forward = forward;
4327 mp->arp_term = arp_term;
4328 mp->is_add = is_add;
4335 static int api_l2fib_add_del (vat_main_t * vam)
4337 unformat_input_t * i = vam->input;
4338 vl_api_l2fib_add_del_t *mp;
4345 u8 sw_if_index_set = 0;
4354 /* Parse args required to build the message */
4355 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4356 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
4358 else if (unformat (i, "bd_id %d", &bd_id))
4360 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4361 sw_if_index_set = 1;
4362 else if (unformat (i, "sw_if")) {
4363 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4364 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4365 sw_if_index_set = 1;
4368 } else if (unformat (i, "static"))
4370 else if (unformat (i, "filter")) {
4373 } else if (unformat (i, "bvi")) {
4376 } else if (unformat (i, "del"))
4378 else if (unformat (i, "count %d", &count))
4385 errmsg ("missing mac address\n");
4389 if (bd_id_set == 0) {
4390 errmsg ("missing bridge domain\n");
4394 if (is_add && (sw_if_index_set == 0)) {
4395 errmsg ("missing interface name or sw_if_index\n");
4400 /* Turn on async mode */
4401 vam->async_mode = 1;
4402 vam->async_errors = 0;
4403 before = vat_time_now(vam);
4406 for (j = 0; j < count; j++) {
4407 M(L2FIB_ADD_DEL, l2fib_add_del);
4410 mp->bd_id = ntohl(bd_id);
4411 mp->is_add = is_add;
4414 mp->sw_if_index = ntohl(sw_if_index);
4415 mp->static_mac = static_mac;
4416 mp->filter_mac = filter_mac;
4417 mp->bvi_mac = bvi_mac;
4419 increment_mac_address (&mac);
4425 vl_api_control_ping_t * mp;
4428 /* Shut off async mode */
4429 vam->async_mode = 0;
4431 M(CONTROL_PING, control_ping);
4434 timeout = vat_time_now(vam) + 1.0;
4435 while (vat_time_now (vam) < timeout)
4436 if (vam->result_ready == 1)
4441 if (vam->retval == -99)
4442 errmsg ("timeout\n");
4444 if (vam->async_errors > 0) {
4445 errmsg ("%d asynchronous errors\n", vam->async_errors);
4448 vam->async_errors = 0;
4449 after = vat_time_now(vam);
4451 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4452 count, after - before, count / (after - before));
4454 /* Wait for a reply... */
4457 /* Return the good/bad news */
4458 return (vam->retval);
4461 static int api_l2_flags (vat_main_t * vam)
4463 unformat_input_t * i = vam->input;
4464 vl_api_l2_flags_t *mp;
4467 u32 feature_bitmap = 0;
4468 u8 sw_if_index_set = 0;
4470 /* Parse args required to build the message */
4471 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4472 if (unformat (i, "sw_if_index %d", &sw_if_index))
4473 sw_if_index_set = 1;
4474 else if (unformat (i, "sw_if")) {
4475 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4476 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4477 sw_if_index_set = 1;
4480 } else if (unformat (i, "learn"))
4481 feature_bitmap |= L2INPUT_FEAT_LEARN;
4482 else if (unformat (i, "forward"))
4483 feature_bitmap |= L2INPUT_FEAT_FWD;
4484 else if (unformat (i, "flood"))
4485 feature_bitmap |= L2INPUT_FEAT_FLOOD;
4486 else if (unformat (i, "uu-flood"))
4487 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
4492 if (sw_if_index_set == 0) {
4493 errmsg ("missing interface name or sw_if_index\n");
4497 M(L2_FLAGS, l2_flags);
4499 mp->sw_if_index = ntohl(sw_if_index);
4500 mp->feature_bitmap = ntohl(feature_bitmap);
4507 static int api_bridge_flags (vat_main_t * vam)
4509 unformat_input_t * i = vam->input;
4510 vl_api_bridge_flags_t *mp;
4517 /* Parse args required to build the message */
4518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4519 if (unformat (i, "bd_id %d", &bd_id))
4521 else if (unformat (i, "learn"))
4523 else if (unformat (i, "forward"))
4525 else if (unformat (i, "flood"))
4527 else if (unformat (i, "uu-flood"))
4528 flags |= L2_UU_FLOOD;
4529 else if (unformat (i, "arp-term"))
4530 flags |= L2_ARP_TERM;
4531 else if (unformat (i, "off"))
4533 else if (unformat (i, "disable"))
4539 if (bd_id_set == 0) {
4540 errmsg ("missing bridge domain\n");
4544 M(BRIDGE_FLAGS, bridge_flags);
4546 mp->bd_id = ntohl(bd_id);
4547 mp->feature_bitmap = ntohl(flags);
4548 mp->is_set = is_set;
4555 static int api_bd_ip_mac_add_del (vat_main_t * vam)
4557 unformat_input_t * i = vam->input;
4558 vl_api_bd_ip_mac_add_del_t *mp;
4566 ip4_address_t v4addr;
4567 ip6_address_t v6addr;
4571 /* Parse args required to build the message */
4572 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4573 if (unformat (i, "bd_id %d", &bd_id)) {
4575 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
4577 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
4580 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
4582 } else if (unformat (i, "del"))
4588 if (bd_id_set == 0) {
4589 errmsg ("missing bridge domain\n");
4591 } else if (ip_set == 0) {
4592 errmsg ("missing IP address\n");
4594 } else if (mac_set == 0) {
4595 errmsg ("missing MAC address\n");
4599 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
4601 mp->bd_id = ntohl(bd_id);
4602 mp->is_ipv6 = is_ipv6;
4603 mp->is_add = is_add;
4605 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
4606 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
4607 clib_memcpy (mp->mac_address, macaddr, 6);
4613 static int api_tap_connect (vat_main_t * vam)
4615 unformat_input_t * i = vam->input;
4616 vl_api_tap_connect_t *mp;
4623 memset (mac_address, 0, sizeof (mac_address));
4625 /* Parse args required to build the message */
4626 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4627 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4630 else if (unformat (i, "random-mac"))
4632 else if (unformat (i, "tapname %s", &tap_name))
4638 if (name_set == 0) {
4639 errmsg ("missing tap name\n");
4642 if (vec_len (tap_name) > 63) {
4643 errmsg ("tap name too long\n");
4645 vec_add1 (tap_name, 0);
4647 /* Construct the API message */
4648 M(TAP_CONNECT, tap_connect);
4650 mp->use_random_mac = random_mac;
4651 clib_memcpy (mp->mac_address, mac_address, 6);
4652 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4653 vec_free (tap_name);
4658 /* Wait for a reply... */
4662 static int api_tap_modify (vat_main_t * vam)
4664 unformat_input_t * i = vam->input;
4665 vl_api_tap_modify_t *mp;
4671 u32 sw_if_index = ~0;
4672 u8 sw_if_index_set = 0;
4674 memset (mac_address, 0, sizeof (mac_address));
4676 /* Parse args required to build the message */
4677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4678 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4679 sw_if_index_set = 1;
4680 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4681 sw_if_index_set = 1;
4682 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4685 else if (unformat (i, "random-mac"))
4687 else if (unformat (i, "tapname %s", &tap_name))
4693 if (sw_if_index_set == 0) {
4694 errmsg ("missing vpp interface name");
4697 if (name_set == 0) {
4698 errmsg ("missing tap name\n");
4701 if (vec_len (tap_name) > 63) {
4702 errmsg ("tap name too long\n");
4704 vec_add1 (tap_name, 0);
4706 /* Construct the API message */
4707 M(TAP_MODIFY, tap_modify);
4709 mp->use_random_mac = random_mac;
4710 mp->sw_if_index = ntohl(sw_if_index);
4711 clib_memcpy (mp->mac_address, mac_address, 6);
4712 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4713 vec_free (tap_name);
4718 /* Wait for a reply... */
4722 static int api_tap_delete (vat_main_t * vam)
4724 unformat_input_t * i = vam->input;
4725 vl_api_tap_delete_t *mp;
4727 u32 sw_if_index = ~0;
4728 u8 sw_if_index_set = 0;
4730 /* Parse args required to build the message */
4731 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4732 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4733 sw_if_index_set = 1;
4734 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4735 sw_if_index_set = 1;
4740 if (sw_if_index_set == 0) {
4741 errmsg ("missing vpp interface name");
4745 /* Construct the API message */
4746 M(TAP_DELETE, tap_delete);
4748 mp->sw_if_index = ntohl(sw_if_index);
4753 /* Wait for a reply... */
4757 static int api_ip_add_del_route (vat_main_t * vam)
4759 unformat_input_t * i = vam->input;
4760 vl_api_ip_add_del_route_t *mp;
4762 u32 sw_if_index = ~0, vrf_id = 0;
4763 u8 sw_if_index_set = 0;
4765 u8 is_local = 0, is_drop = 0;
4766 u8 create_vrf_if_needed = 0;
4768 u8 next_hop_weight = 1;
4770 u8 is_multipath = 0;
4772 u8 address_length_set = 0;
4773 u32 lookup_in_vrf = 0;
4774 u32 resolve_attempts = 0;
4775 u32 dst_address_length = 0;
4776 u8 next_hop_set = 0;
4777 ip4_address_t v4_dst_address, v4_next_hop_address;
4778 ip6_address_t v6_dst_address, v6_next_hop_address;
4782 u32 random_add_del = 0;
4783 u32 * random_vector = 0;
4784 uword * random_hash;
4785 u32 random_seed = 0xdeaddabe;
4786 u32 classify_table_index = ~0;
4789 /* Parse args required to build the message */
4790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4791 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4792 sw_if_index_set = 1;
4793 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4794 sw_if_index_set = 1;
4795 else if (unformat (i, "%U", unformat_ip4_address,
4800 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4804 else if (unformat (i, "/%d", &dst_address_length)) {
4805 address_length_set = 1;
4808 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4809 &v4_next_hop_address)) {
4812 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4813 &v6_next_hop_address)) {
4816 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4818 else if (unformat (i, "weight %d", &next_hop_weight))
4820 else if (unformat (i, "drop")) {
4822 } else if (unformat (i, "local")) {
4824 } else if (unformat (i, "classify %d", &classify_table_index)) {
4826 } else if (unformat (i, "del"))
4828 else if (unformat (i, "add"))
4830 else if (unformat (i, "not-last"))
4832 else if (unformat (i, "multipath"))
4834 else if (unformat (i, "vrf %d", &vrf_id))
4836 else if (unformat (i, "create-vrf"))
4837 create_vrf_if_needed = 1;
4838 else if (unformat (i, "count %d", &count))
4840 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4842 else if (unformat (i, "random"))
4844 else if (unformat (i, "seed %d", &random_seed))
4847 clib_warning ("parse error '%U'", format_unformat_error, i);
4852 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4853 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4857 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4858 errmsg ("next hop / local / drop / classify not set\n");
4862 if (address_set == 0) {
4863 errmsg ("missing addresses\n");
4867 if (address_length_set == 0) {
4868 errmsg ("missing address length\n");
4872 /* Generate a pile of unique, random routes */
4873 if (random_add_del) {
4874 u32 this_random_address;
4875 random_hash = hash_create (count, sizeof(uword));
4877 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4878 for (j = 0; j <= count; j++) {
4880 this_random_address = random_u32 (&random_seed);
4881 this_random_address =
4882 clib_host_to_net_u32 (this_random_address);
4883 } while (hash_get (random_hash, this_random_address));
4884 vec_add1 (random_vector, this_random_address);
4885 hash_set (random_hash, this_random_address, 1);
4887 hash_free (random_hash);
4888 v4_dst_address.as_u32 = random_vector[0];
4892 /* Turn on async mode */
4893 vam->async_mode = 1;
4894 vam->async_errors = 0;
4895 before = vat_time_now(vam);
4898 for (j = 0; j < count; j++) {
4899 /* Construct the API message */
4900 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4902 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4903 mp->vrf_id = ntohl (vrf_id);
4904 if (resolve_attempts > 0) {
4905 mp->resolve_attempts = ntohl (resolve_attempts);
4906 mp->resolve_if_needed = 1;
4908 mp->create_vrf_if_needed = create_vrf_if_needed;
4910 mp->is_add = is_add;
4911 mp->is_drop = is_drop;
4912 mp->is_ipv6 = is_ipv6;
4913 mp->is_local = is_local;
4914 mp->is_classify = is_classify;
4915 mp->is_multipath = is_multipath;
4916 mp->not_last = not_last;
4917 mp->next_hop_weight = next_hop_weight;
4918 mp->dst_address_length = dst_address_length;
4919 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4920 mp->classify_table_index = ntohl(classify_table_index);
4923 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4925 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4926 sizeof (v6_next_hop_address));
4927 increment_v6_address (&v6_dst_address);
4929 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4931 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4932 sizeof (v4_next_hop_address));
4934 v4_dst_address.as_u32 = random_vector[j+1];
4936 increment_v4_address (&v4_dst_address);
4942 /* When testing multiple add/del ops, use a control-ping to sync */
4944 vl_api_control_ping_t * mp;
4947 /* Shut off async mode */
4948 vam->async_mode = 0;
4950 M(CONTROL_PING, control_ping);
4953 timeout = vat_time_now(vam) + 1.0;
4954 while (vat_time_now (vam) < timeout)
4955 if (vam->result_ready == 1)
4960 if (vam->retval == -99)
4961 errmsg ("timeout\n");
4963 if (vam->async_errors > 0) {
4964 errmsg ("%d asynchronous errors\n", vam->async_errors);
4967 vam->async_errors = 0;
4968 after = vat_time_now(vam);
4970 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4971 count, after - before, count / (after - before));
4973 /* Wait for a reply... */
4977 /* Return the good/bad news */
4978 return (vam->retval);
4981 static int api_proxy_arp_add_del (vat_main_t * vam)
4983 unformat_input_t * i = vam->input;
4984 vl_api_proxy_arp_add_del_t *mp;
4988 ip4_address_t lo, hi;
4991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4992 if (unformat (i, "vrf %d", &vrf_id))
4994 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4995 unformat_ip4_address, &hi))
4997 else if (unformat (i, "del"))
5000 clib_warning ("parse error '%U'", format_unformat_error, i);
5005 if (range_set == 0) {
5006 errmsg ("address range not set\n");
5010 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
5012 mp->vrf_id = ntohl(vrf_id);
5013 mp->is_add = is_add;
5014 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
5015 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
5022 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
5024 unformat_input_t * i = vam->input;
5025 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5029 u8 sw_if_index_set = 0;
5031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5032 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5033 sw_if_index_set = 1;
5034 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5035 sw_if_index_set = 1;
5036 else if (unformat (i, "enable"))
5038 else if (unformat (i, "disable"))
5041 clib_warning ("parse error '%U'", format_unformat_error, i);
5046 if (sw_if_index_set == 0) {
5047 errmsg ("missing interface name or sw_if_index\n");
5051 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
5053 mp->sw_if_index = ntohl(sw_if_index);
5054 mp->enable_disable = enable;
5061 static int api_mpls_add_del_decap (vat_main_t * vam)
5063 unformat_input_t * i = vam->input;
5064 vl_api_mpls_add_del_decap_t *mp;
5073 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5074 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5076 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5078 else if (unformat (i, "label %d", &label))
5080 else if (unformat (i, "next-index %d", &next_index))
5082 else if (unformat (i, "del"))
5084 else if (unformat (i, "s-bit-clear"))
5087 clib_warning ("parse error '%U'", format_unformat_error, i);
5092 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
5094 mp->rx_vrf_id = ntohl(rx_vrf_id);
5095 mp->tx_vrf_id = ntohl(tx_vrf_id);
5096 mp->label = ntohl(label);
5097 mp->next_index = ntohl(next_index);
5099 mp->is_add = is_add;
5106 static int api_mpls_add_del_encap (vat_main_t * vam)
5108 unformat_input_t * i = vam->input;
5109 vl_api_mpls_add_del_encap_t *mp;
5114 ip4_address_t dst_address;
5117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5118 if (unformat (i, "vrf %d", &vrf_id))
5120 else if (unformat (i, "label %d", &label))
5121 vec_add1 (labels, ntohl(label));
5122 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5124 else if (unformat (i, "del"))
5127 clib_warning ("parse error '%U'", format_unformat_error, i);
5132 if (vec_len (labels) == 0) {
5133 errmsg ("missing encap label stack\n");
5137 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
5138 sizeof (u32) * vec_len (labels));
5140 mp->vrf_id = ntohl(vrf_id);
5141 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5142 mp->is_add = is_add;
5143 mp->nlabels = vec_len (labels);
5144 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
5153 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
5155 unformat_input_t * i = vam->input;
5156 vl_api_mpls_gre_add_del_tunnel_t *mp;
5158 u32 inner_vrf_id = 0;
5159 u32 outer_vrf_id = 0;
5160 ip4_address_t src_address;
5161 ip4_address_t dst_address;
5162 ip4_address_t intfc_address;
5164 u8 intfc_address_length = 0;
5168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5169 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5171 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5173 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
5175 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5177 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5178 &intfc_address, &tmp))
5179 intfc_address_length = tmp;
5180 else if (unformat (i, "l2-only"))
5182 else if (unformat (i, "del"))
5185 clib_warning ("parse error '%U'", format_unformat_error, i);
5190 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
5192 mp->inner_vrf_id = ntohl(inner_vrf_id);
5193 mp->outer_vrf_id = ntohl(outer_vrf_id);
5194 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
5195 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5196 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
5197 mp->intfc_address_length = intfc_address_length;
5198 mp->l2_only = l2_only;
5199 mp->is_add = is_add;
5206 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
5208 unformat_input_t * i = vam->input;
5209 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
5211 u32 inner_vrf_id = 0;
5212 ip4_address_t intfc_address;
5213 u8 dst_mac_address[6];
5216 u8 intfc_address_length = 0;
5220 int tx_sw_if_index_set = 0;
5222 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5223 if (unformat (i, "vrf %d", &inner_vrf_id))
5225 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5226 &intfc_address, &tmp))
5227 intfc_address_length = tmp;
5228 else if (unformat (i, "%U",
5229 unformat_sw_if_index, vam, &tx_sw_if_index))
5230 tx_sw_if_index_set = 1;
5231 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5232 tx_sw_if_index_set = 1;
5233 else if (unformat (i, "dst %U", unformat_ethernet_address,
5236 else if (unformat (i, "l2-only"))
5238 else if (unformat (i, "del"))
5241 clib_warning ("parse error '%U'", format_unformat_error, i);
5247 errmsg ("dst (mac address) not set\n");
5250 if (!tx_sw_if_index_set) {
5251 errmsg ("tx-intfc not set\n");
5255 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
5257 mp->vrf_id = ntohl(inner_vrf_id);
5258 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
5259 mp->adj_address_length = intfc_address_length;
5260 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
5261 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5262 mp->l2_only = l2_only;
5263 mp->is_add = is_add;
5270 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
5272 unformat_input_t * i = vam->input;
5273 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
5275 u32 inner_vrf_id = 0;
5276 u32 outer_vrf_id = 0;
5277 ip4_address_t adj_address;
5278 int adj_address_set = 0;
5279 ip4_address_t next_hop_address;
5280 int next_hop_address_set = 0;
5282 u8 adj_address_length = 0;
5285 u32 resolve_attempts = 5;
5286 u8 resolve_if_needed = 1;
5288 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5289 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5291 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5293 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5294 &adj_address, &tmp)) {
5295 adj_address_length = tmp;
5296 adj_address_set = 1;
5298 else if (unformat (i, "next-hop %U", unformat_ip4_address,
5300 next_hop_address_set = 1;
5301 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5303 else if (unformat (i, "resolve-if-needed %d", &tmp))
5304 resolve_if_needed = tmp;
5305 else if (unformat (i, "l2-only"))
5307 else if (unformat (i, "del"))
5310 clib_warning ("parse error '%U'", format_unformat_error, i);
5315 if (!adj_address_set) {
5316 errmsg ("adjacency address/mask not set\n");
5319 if (!next_hop_address_set) {
5320 errmsg ("ip4 next hop address (in outer fib) not set\n");
5324 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
5326 mp->inner_vrf_id = ntohl(inner_vrf_id);
5327 mp->outer_vrf_id = ntohl(outer_vrf_id);
5328 mp->resolve_attempts = ntohl(resolve_attempts);
5329 mp->resolve_if_needed = resolve_if_needed;
5330 mp->is_add = is_add;
5331 mp->l2_only = l2_only;
5332 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
5333 mp->adj_address_length = adj_address_length;
5334 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
5335 sizeof (next_hop_address));
5342 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
5344 unformat_input_t * i = vam->input;
5345 vl_api_sw_interface_set_unnumbered_t *mp;
5350 u8 sw_if_index_set = 0;
5352 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5353 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5354 sw_if_index_set = 1;
5355 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5356 sw_if_index_set = 1;
5357 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5359 else if (unformat (i, "del"))
5362 clib_warning ("parse error '%U'", format_unformat_error, i);
5367 if (sw_if_index_set == 0) {
5368 errmsg ("missing interface name or sw_if_index\n");
5372 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
5374 mp->sw_if_index = ntohl(sw_if_index);
5375 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
5376 mp->is_add = is_add;
5383 static int api_ip_neighbor_add_del (vat_main_t * vam)
5385 unformat_input_t * i = vam->input;
5386 vl_api_ip_neighbor_add_del_t *mp;
5389 u8 sw_if_index_set = 0;
5395 u8 v4_address_set = 0;
5396 u8 v6_address_set = 0;
5397 ip4_address_t v4address;
5398 ip6_address_t v6address;
5400 memset (mac_address, 0, sizeof (mac_address));
5402 /* Parse args required to build the message */
5403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5404 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
5407 else if (unformat (i, "del"))
5409 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5410 sw_if_index_set = 1;
5411 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5412 sw_if_index_set = 1;
5413 else if (unformat (i, "is_static"))
5415 else if (unformat (i, "vrf %d", &vrf_id))
5417 else if (unformat (i, "dst %U",
5418 unformat_ip4_address, &v4address))
5420 else if (unformat (i, "dst %U",
5421 unformat_ip6_address, &v6address))
5424 clib_warning ("parse error '%U'", format_unformat_error, i);
5429 if (sw_if_index_set == 0) {
5430 errmsg ("missing interface name or sw_if_index\n");
5433 if (v4_address_set && v6_address_set) {
5434 errmsg ("both v4 and v6 addresses set\n");
5437 if (!v4_address_set && !v6_address_set) {
5438 errmsg ("no address set\n");
5442 /* Construct the API message */
5443 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
5445 mp->sw_if_index = ntohl (sw_if_index);
5446 mp->is_add = is_add;
5447 mp->vrf_id = ntohl (vrf_id);
5448 mp->is_static = is_static;
5450 clib_memcpy (mp->mac_address, mac_address, 6);
5451 if (v6_address_set) {
5453 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
5455 /* mp->is_ipv6 = 0; via memset in M macro above */
5456 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
5462 /* Wait for a reply, return good/bad news */
5469 static int api_reset_vrf (vat_main_t * vam)
5471 unformat_input_t * i = vam->input;
5472 vl_api_reset_vrf_t *mp;
5478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5479 if (unformat (i, "vrf %d", &vrf_id))
5481 else if (unformat (i, "ipv6"))
5484 clib_warning ("parse error '%U'", format_unformat_error, i);
5489 if (vrf_id_set == 0) {
5490 errmsg ("missing vrf id\n");
5494 M(RESET_VRF, reset_vrf);
5496 mp->vrf_id = ntohl(vrf_id);
5497 mp->is_ipv6 = is_ipv6;
5504 static int api_create_vlan_subif (vat_main_t * vam)
5506 unformat_input_t * i = vam->input;
5507 vl_api_create_vlan_subif_t *mp;
5510 u8 sw_if_index_set = 0;
5514 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5515 if (unformat (i, "sw_if_index %d", &sw_if_index))
5516 sw_if_index_set = 1;
5517 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5518 sw_if_index_set = 1;
5519 else if (unformat (i, "vlan %d", &vlan_id))
5522 clib_warning ("parse error '%U'", format_unformat_error, i);
5527 if (sw_if_index_set == 0) {
5528 errmsg ("missing interface name or sw_if_index\n");
5532 if (vlan_id_set == 0) {
5533 errmsg ("missing vlan_id\n");
5536 M(CREATE_VLAN_SUBIF, create_vlan_subif);
5538 mp->sw_if_index = ntohl(sw_if_index);
5539 mp->vlan_id = ntohl(vlan_id);
5546 #define foreach_create_subif_bit \
5553 _(outer_vlan_id_any) \
5554 _(inner_vlan_id_any)
5556 static int api_create_subif (vat_main_t * vam)
5558 unformat_input_t * i = vam->input;
5559 vl_api_create_subif_t *mp;
5562 u8 sw_if_index_set = 0;
5569 u32 exact_match = 0;
5570 u32 default_sub = 0;
5571 u32 outer_vlan_id_any = 0;
5572 u32 inner_vlan_id_any = 0;
5574 u16 outer_vlan_id = 0;
5575 u16 inner_vlan_id = 0;
5577 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5578 if (unformat (i, "sw_if_index %d", &sw_if_index))
5579 sw_if_index_set = 1;
5580 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5581 sw_if_index_set = 1;
5582 else if (unformat (i, "sub_id %d", &sub_id))
5584 else if (unformat (i, "outer_vlan_id %d", &tmp))
5585 outer_vlan_id = tmp;
5586 else if (unformat (i, "inner_vlan_id %d", &tmp))
5587 inner_vlan_id = tmp;
5589 #define _(a) else if (unformat (i, #a)) a = 1 ;
5590 foreach_create_subif_bit
5594 clib_warning ("parse error '%U'", format_unformat_error, i);
5599 if (sw_if_index_set == 0) {
5600 errmsg ("missing interface name or sw_if_index\n");
5604 if (sub_id_set == 0) {
5605 errmsg ("missing sub_id\n");
5608 M(CREATE_SUBIF, create_subif);
5610 mp->sw_if_index = ntohl(sw_if_index);
5611 mp->sub_id = ntohl(sub_id);
5613 #define _(a) mp->a = a;
5614 foreach_create_subif_bit;
5617 mp->outer_vlan_id = ntohs (outer_vlan_id);
5618 mp->inner_vlan_id = ntohs (inner_vlan_id);
5625 static int api_oam_add_del (vat_main_t * vam)
5627 unformat_input_t * i = vam->input;
5628 vl_api_oam_add_del_t *mp;
5632 ip4_address_t src, dst;
5636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5637 if (unformat (i, "vrf %d", &vrf_id))
5639 else if (unformat (i, "src %U", unformat_ip4_address, &src))
5641 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
5643 else if (unformat (i, "del"))
5646 clib_warning ("parse error '%U'", format_unformat_error, i);
5652 errmsg ("missing src addr\n");
5657 errmsg ("missing dst addr\n");
5661 M(OAM_ADD_DEL, oam_add_del);
5663 mp->vrf_id = ntohl(vrf_id);
5664 mp->is_add = is_add;
5665 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
5666 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
5673 static int api_reset_fib (vat_main_t * vam)
5675 unformat_input_t * i = vam->input;
5676 vl_api_reset_fib_t *mp;
5682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5683 if (unformat (i, "vrf %d", &vrf_id))
5685 else if (unformat (i, "ipv6"))
5688 clib_warning ("parse error '%U'", format_unformat_error, i);
5693 if (vrf_id_set == 0) {
5694 errmsg ("missing vrf id\n");
5698 M(RESET_FIB, reset_fib);
5700 mp->vrf_id = ntohl(vrf_id);
5701 mp->is_ipv6 = is_ipv6;
5708 static int api_dhcp_proxy_config (vat_main_t * vam)
5710 unformat_input_t * i = vam->input;
5711 vl_api_dhcp_proxy_config_t *mp;
5716 u8 v4_address_set = 0;
5717 u8 v6_address_set = 0;
5718 ip4_address_t v4address;
5719 ip6_address_t v6address;
5720 u8 v4_src_address_set = 0;
5721 u8 v6_src_address_set = 0;
5722 ip4_address_t v4srcaddress;
5723 ip6_address_t v6srcaddress;
5725 /* Parse args required to build the message */
5726 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5727 if (unformat (i, "del"))
5729 else if (unformat (i, "vrf %d", &vrf_id))
5731 else if (unformat (i, "insert-cid %d", &insert_cid))
5733 else if (unformat (i, "svr %U",
5734 unformat_ip4_address, &v4address))
5736 else if (unformat (i, "svr %U",
5737 unformat_ip6_address, &v6address))
5739 else if (unformat (i, "src %U",
5740 unformat_ip4_address, &v4srcaddress))
5741 v4_src_address_set = 1;
5742 else if (unformat (i, "src %U",
5743 unformat_ip6_address, &v6srcaddress))
5744 v6_src_address_set = 1;
5749 if (v4_address_set && v6_address_set) {
5750 errmsg ("both v4 and v6 server addresses set\n");
5753 if (!v4_address_set && !v6_address_set) {
5754 errmsg ("no server addresses set\n");
5758 if (v4_src_address_set && v6_src_address_set) {
5759 errmsg ("both v4 and v6 src addresses set\n");
5762 if (!v4_src_address_set && !v6_src_address_set) {
5763 errmsg ("no src addresses set\n");
5767 if (!(v4_src_address_set && v4_address_set) &&
5768 !(v6_src_address_set && v6_address_set)) {
5769 errmsg ("no matching server and src addresses set\n");
5773 /* Construct the API message */
5774 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5776 mp->insert_circuit_id = insert_cid;
5777 mp->is_add = is_add;
5778 mp->vrf_id = ntohl (vrf_id);
5779 if (v6_address_set) {
5781 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5782 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5784 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5785 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5791 /* Wait for a reply, return good/bad news */
5797 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5799 unformat_input_t * i = vam->input;
5800 vl_api_dhcp_proxy_config_2_t *mp;
5803 u32 server_vrf_id = 0;
5806 u8 v4_address_set = 0;
5807 u8 v6_address_set = 0;
5808 ip4_address_t v4address;
5809 ip6_address_t v6address;
5810 u8 v4_src_address_set = 0;
5811 u8 v6_src_address_set = 0;
5812 ip4_address_t v4srcaddress;
5813 ip6_address_t v6srcaddress;
5815 /* Parse args required to build the message */
5816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5817 if (unformat (i, "del"))
5819 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5821 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5823 else if (unformat (i, "insert-cid %d", &insert_cid))
5825 else if (unformat (i, "svr %U",
5826 unformat_ip4_address, &v4address))
5828 else if (unformat (i, "svr %U",
5829 unformat_ip6_address, &v6address))
5831 else if (unformat (i, "src %U",
5832 unformat_ip4_address, &v4srcaddress))
5833 v4_src_address_set = 1;
5834 else if (unformat (i, "src %U",
5835 unformat_ip6_address, &v6srcaddress))
5836 v6_src_address_set = 1;
5841 if (v4_address_set && v6_address_set) {
5842 errmsg ("both v4 and v6 server addresses set\n");
5845 if (!v4_address_set && !v6_address_set) {
5846 errmsg ("no server addresses set\n");
5850 if (v4_src_address_set && v6_src_address_set) {
5851 errmsg ("both v4 and v6 src addresses set\n");
5854 if (!v4_src_address_set && !v6_src_address_set) {
5855 errmsg ("no src addresses set\n");
5859 if (!(v4_src_address_set && v4_address_set) &&
5860 !(v6_src_address_set && v6_address_set)) {
5861 errmsg ("no matching server and src addresses set\n");
5865 /* Construct the API message */
5866 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5868 mp->insert_circuit_id = insert_cid;
5869 mp->is_add = is_add;
5870 mp->rx_vrf_id = ntohl (rx_vrf_id);
5871 mp->server_vrf_id = ntohl (server_vrf_id);
5872 if (v6_address_set) {
5874 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5875 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5877 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5878 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5884 /* Wait for a reply, return good/bad news */
5890 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5892 unformat_input_t * i = vam->input;
5893 vl_api_dhcp_proxy_set_vss_t *mp;
5904 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5905 if (unformat (i, "tbl_id %d", &tbl_id))
5907 if (unformat (i, "fib_id %d", &fib_id))
5909 if (unformat (i, "oui %d", &oui))
5911 else if (unformat (i, "ipv6"))
5913 else if (unformat (i, "del"))
5916 clib_warning ("parse error '%U'", format_unformat_error, i);
5921 if (tbl_id_set == 0) {
5922 errmsg ("missing tbl id\n");
5926 if (fib_id_set == 0) {
5927 errmsg ("missing fib id\n");
5931 errmsg ("missing oui\n");
5935 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5936 mp->tbl_id = ntohl(tbl_id);
5937 mp->fib_id = ntohl(fib_id);
5938 mp->oui = ntohl(oui);
5939 mp->is_ipv6 = is_ipv6;
5940 mp->is_add = is_add;
5947 static int api_dhcp_client_config (vat_main_t * vam)
5949 unformat_input_t * i = vam->input;
5950 vl_api_dhcp_client_config_t *mp;
5953 u8 sw_if_index_set = 0;
5956 u8 disable_event = 0;
5958 /* Parse args required to build the message */
5959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5960 if (unformat (i, "del"))
5962 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5963 sw_if_index_set = 1;
5964 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5965 sw_if_index_set = 1;
5966 else if (unformat (i, "hostname %s", &hostname))
5968 else if (unformat (i, "disable_event"))
5974 if (sw_if_index_set == 0) {
5975 errmsg ("missing interface name or sw_if_index\n");
5979 if (vec_len (hostname) > 63) {
5980 errmsg ("hostname too long\n");
5982 vec_add1 (hostname, 0);
5984 /* Construct the API message */
5985 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5987 mp->sw_if_index = ntohl (sw_if_index);
5988 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5989 vec_free (hostname);
5990 mp->is_add = is_add;
5991 mp->want_dhcp_event = disable_event ? 0 : 1;
5997 /* Wait for a reply, return good/bad news */
6003 static int api_set_ip_flow_hash (vat_main_t * vam)
6005 unformat_input_t * i = vam->input;
6006 vl_api_set_ip_flow_hash_t *mp;
6018 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6019 if (unformat (i, "vrf %d", &vrf_id))
6021 else if (unformat (i, "ipv6"))
6023 else if (unformat (i, "src"))
6025 else if (unformat (i, "dst"))
6027 else if (unformat (i, "sport"))
6029 else if (unformat (i, "dport"))
6031 else if (unformat (i, "proto"))
6033 else if (unformat (i, "reverse"))
6037 clib_warning ("parse error '%U'", format_unformat_error, i);
6042 if (vrf_id_set == 0) {
6043 errmsg ("missing vrf id\n");
6047 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
6053 mp->reverse = reverse;
6054 mp->vrf_id = ntohl(vrf_id);
6055 mp->is_ipv6 = is_ipv6;
6062 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6064 unformat_input_t * i = vam->input;
6065 vl_api_sw_interface_ip6_enable_disable_t *mp;
6068 u8 sw_if_index_set = 0;
6071 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6072 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6073 sw_if_index_set = 1;
6074 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6075 sw_if_index_set = 1;
6076 else if (unformat (i, "enable"))
6078 else if (unformat (i, "disable"))
6081 clib_warning ("parse error '%U'", format_unformat_error, i);
6086 if (sw_if_index_set == 0) {
6087 errmsg ("missing interface name or sw_if_index\n");
6091 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
6093 mp->sw_if_index = ntohl(sw_if_index);
6094 mp->enable = enable;
6101 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
6103 unformat_input_t * i = vam->input;
6104 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
6107 u8 sw_if_index_set = 0;
6108 u32 address_length = 0;
6109 u8 v6_address_set = 0;
6110 ip6_address_t v6address;
6112 /* Parse args required to build the message */
6113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6114 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6115 sw_if_index_set = 1;
6116 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6117 sw_if_index_set = 1;
6118 else if (unformat (i, "%U/%d",
6119 unformat_ip6_address, &v6address,
6126 if (sw_if_index_set == 0) {
6127 errmsg ("missing interface name or sw_if_index\n");
6130 if (!v6_address_set) {
6131 errmsg ("no address set\n");
6135 /* Construct the API message */
6136 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
6137 sw_interface_ip6_set_link_local_address);
6139 mp->sw_if_index = ntohl (sw_if_index);
6140 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6141 mp->address_length = address_length;
6146 /* Wait for a reply, return good/bad news */
6154 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
6156 unformat_input_t * i = vam->input;
6157 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
6160 u8 sw_if_index_set = 0;
6161 u32 address_length = 0;
6162 u8 v6_address_set = 0;
6163 ip6_address_t v6address;
6165 u8 no_advertise = 0;
6167 u8 no_autoconfig = 0;
6170 u32 val_lifetime = 0;
6171 u32 pref_lifetime = 0;
6173 /* Parse args required to build the message */
6174 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6175 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6176 sw_if_index_set = 1;
6177 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6178 sw_if_index_set = 1;
6179 else if (unformat (i, "%U/%d",
6180 unformat_ip6_address, &v6address,
6183 else if (unformat (i, "val_life %d", &val_lifetime))
6185 else if (unformat (i, "pref_life %d", &pref_lifetime))
6187 else if (unformat (i, "def"))
6189 else if (unformat (i, "noadv"))
6191 else if (unformat (i, "offl"))
6193 else if (unformat (i, "noauto"))
6195 else if (unformat (i, "nolink"))
6197 else if (unformat (i, "isno"))
6200 clib_warning ("parse error '%U'", format_unformat_error, i);
6205 if (sw_if_index_set == 0) {
6206 errmsg ("missing interface name or sw_if_index\n");
6209 if (!v6_address_set) {
6210 errmsg ("no address set\n");
6214 /* Construct the API message */
6215 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
6217 mp->sw_if_index = ntohl (sw_if_index);
6218 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6219 mp->address_length = address_length;
6220 mp->use_default = use_default;
6221 mp->no_advertise = no_advertise;
6222 mp->off_link = off_link;
6223 mp->no_autoconfig = no_autoconfig;
6224 mp->no_onlink = no_onlink;
6226 mp->val_lifetime = ntohl(val_lifetime);
6227 mp->pref_lifetime = ntohl(pref_lifetime);
6232 /* Wait for a reply, return good/bad news */
6239 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
6241 unformat_input_t * i = vam->input;
6242 vl_api_sw_interface_ip6nd_ra_config_t *mp;
6245 u8 sw_if_index_set = 0;
6250 u8 send_unicast = 0;
6253 u8 default_router = 0;
6254 u32 max_interval = 0;
6255 u32 min_interval = 0;
6257 u32 initial_count = 0;
6258 u32 initial_interval = 0;
6261 /* Parse args required to build the message */
6262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6263 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6264 sw_if_index_set = 1;
6265 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6266 sw_if_index_set = 1;
6267 else if (unformat (i, "maxint %d", &max_interval))
6269 else if (unformat (i, "minint %d", &min_interval))
6271 else if (unformat (i, "life %d", &lifetime))
6273 else if (unformat (i, "count %d", &initial_count))
6275 else if (unformat (i, "interval %d", &initial_interval))
6277 else if (unformat (i, "suppress") || unformat (i, "surpress"))
6279 else if (unformat (i, "managed"))
6281 else if (unformat (i, "other"))
6283 else if (unformat (i, "ll"))
6285 else if (unformat (i, "send"))
6287 else if (unformat (i, "cease"))
6289 else if (unformat (i, "isno"))
6291 else if (unformat (i, "def"))
6294 clib_warning ("parse error '%U'", format_unformat_error, i);
6299 if (sw_if_index_set == 0) {
6300 errmsg ("missing interface name or sw_if_index\n");
6304 /* Construct the API message */
6305 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
6307 mp->sw_if_index = ntohl (sw_if_index);
6308 mp->max_interval = ntohl(max_interval);
6309 mp->min_interval = ntohl(min_interval);
6310 mp->lifetime = ntohl(lifetime);
6311 mp->initial_count = ntohl(initial_count);
6312 mp->initial_interval = ntohl(initial_interval);
6313 mp->suppress = suppress;
6314 mp->managed = managed;
6316 mp->ll_option = ll_option;
6317 mp->send_unicast = send_unicast;
6320 mp->default_router = default_router;
6325 /* Wait for a reply, return good/bad news */
6332 static int api_set_arp_neighbor_limit (vat_main_t * vam)
6334 unformat_input_t * i = vam->input;
6335 vl_api_set_arp_neighbor_limit_t *mp;
6341 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6342 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
6344 else if (unformat (i, "ipv6"))
6347 clib_warning ("parse error '%U'", format_unformat_error, i);
6352 if (limit_set == 0) {
6353 errmsg ("missing limit value\n");
6357 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
6359 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
6360 mp->is_ipv6 = is_ipv6;
6367 static int api_l2_patch_add_del (vat_main_t * vam)
6369 unformat_input_t * i = vam->input;
6370 vl_api_l2_patch_add_del_t *mp;
6373 u8 rx_sw_if_index_set = 0;
6375 u8 tx_sw_if_index_set = 0;
6378 /* Parse args required to build the message */
6379 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6380 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6381 rx_sw_if_index_set = 1;
6382 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6383 tx_sw_if_index_set = 1;
6384 else if (unformat (i, "rx")) {
6385 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6386 if (unformat (i, "%U", unformat_sw_if_index, vam,
6388 rx_sw_if_index_set = 1;
6391 } else if (unformat (i, "tx")) {
6392 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6393 if (unformat (i, "%U", unformat_sw_if_index, vam,
6395 tx_sw_if_index_set = 1;
6398 } else if (unformat (i, "del"))
6404 if (rx_sw_if_index_set == 0) {
6405 errmsg ("missing rx interface name or rx_sw_if_index\n");
6409 if (tx_sw_if_index_set == 0) {
6410 errmsg ("missing tx interface name or tx_sw_if_index\n");
6414 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
6416 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
6417 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
6418 mp->is_add = is_add;
6424 static int api_trace_profile_add (vat_main_t *vam)
6426 unformat_input_t * input = vam->input;
6427 vl_api_trace_profile_add_t *mp;
6430 u32 trace_option_elts = 0;
6431 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
6432 int has_pow_option = 0;
6433 int has_ppc_option = 0;
6435 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6437 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
6438 "trace-tsp %d node-id 0x%x app-data 0x%x",
6439 &id, &trace_type, &trace_option_elts, &trace_tsp,
6440 &node_id, &app_data))
6442 else if (unformat (input, "pow"))
6444 else if (unformat (input, "ppc encap"))
6445 has_ppc_option = PPC_ENCAP;
6446 else if (unformat (input, "ppc decap"))
6447 has_ppc_option = PPC_DECAP;
6448 else if (unformat (input, "ppc none"))
6449 has_ppc_option = PPC_NONE;
6453 M(TRACE_PROFILE_ADD, trace_profile_add);
6455 mp->trace_type = trace_type;
6456 mp->trace_num_elt = trace_option_elts;
6457 mp->trace_ppc = has_ppc_option;
6458 mp->trace_app_data = htonl(app_data);
6459 mp->pow_enable = has_pow_option;
6460 mp->trace_tsp = trace_tsp;
6461 mp->node_id = htonl(node_id);
6468 static int api_trace_profile_apply (vat_main_t *vam)
6470 unformat_input_t * input = vam->input;
6471 vl_api_trace_profile_apply_t *mp;
6474 u32 mask_width = ~0;
6481 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6483 if (unformat (input, "%U/%d",
6484 unformat_ip6_address, &addr, &mask_width))
6486 else if (unformat (input, "id %d", &id))
6488 else if (unformat (input, "vrf-id %d", &vrf_id))
6490 else if (unformat (input, "add"))
6492 else if (unformat (input, "pop"))
6494 else if (unformat (input, "none"))
6500 if ((is_add + is_pop + is_none) != 1) {
6501 errmsg("One of (add, pop, none) required");
6504 if (mask_width == ~0) {
6505 errmsg("<address>/<mask-width> required");
6508 M(TRACE_PROFILE_APPLY, trace_profile_apply);
6509 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
6511 mp->prefix_length = htonl(mask_width);
6512 mp->vrf_id = htonl(vrf_id);
6514 mp->trace_op = IOAM_HBYH_ADD;
6516 mp->trace_op = IOAM_HBYH_POP;
6518 mp->trace_op = IOAM_HBYH_MOD;
6530 static int api_trace_profile_del (vat_main_t *vam)
6532 vl_api_trace_profile_del_t *mp;
6535 M(TRACE_PROFILE_DEL, trace_profile_del);
6540 static int api_sr_tunnel_add_del (vat_main_t * vam)
6542 unformat_input_t * i = vam->input;
6543 vl_api_sr_tunnel_add_del_t *mp;
6547 ip6_address_t src_address;
6548 int src_address_set = 0;
6549 ip6_address_t dst_address;
6551 int dst_address_set = 0;
6553 u32 rx_table_id = 0;
6554 u32 tx_table_id = 0;
6555 ip6_address_t * segments = 0;
6556 ip6_address_t * this_seg;
6557 ip6_address_t * tags = 0;
6558 ip6_address_t * this_tag;
6559 ip6_address_t next_address, tag;
6561 u8 * policy_name = 0;
6563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6565 if (unformat (i, "del"))
6567 else if (unformat (i, "name %s", &name))
6569 else if (unformat (i, "policy %s", &policy_name))
6571 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
6573 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
6575 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
6576 src_address_set = 1;
6577 else if (unformat (i, "dst %U/%d",
6578 unformat_ip6_address, &dst_address,
6580 dst_address_set = 1;
6581 else if (unformat (i, "next %U", unformat_ip6_address,
6584 vec_add2 (segments, this_seg, 1);
6585 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
6587 else if (unformat (i, "tag %U", unformat_ip6_address,
6590 vec_add2 (tags, this_tag, 1);
6591 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
6593 else if (unformat (i, "clean"))
6594 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
6595 else if (unformat (i, "protected"))
6596 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
6597 else if (unformat (i, "InPE %d", &pl_index))
6599 if (pl_index <= 0 || pl_index > 4)
6601 pl_index_range_error:
6602 errmsg ("pl index %d out of range\n", pl_index);
6605 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
6607 else if (unformat (i, "EgPE %d", &pl_index))
6609 if (pl_index <= 0 || pl_index > 4)
6610 goto pl_index_range_error;
6611 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
6613 else if (unformat (i, "OrgSrc %d", &pl_index))
6615 if (pl_index <= 0 || pl_index > 4)
6616 goto pl_index_range_error;
6617 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
6623 if (!src_address_set)
6625 errmsg ("src address required\n");
6629 if (!dst_address_set)
6631 errmsg ("dst address required\n");
6637 errmsg ("at least one sr segment required\n");
6641 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
6642 vec_len(segments) * sizeof (ip6_address_t)
6643 + vec_len(tags) * sizeof (ip6_address_t));
6645 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
6646 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
6647 mp->dst_mask_width = dst_mask_width;
6648 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
6649 mp->n_segments = vec_len (segments);
6650 mp->n_tags = vec_len (tags);
6651 mp->is_add = is_del == 0;
6652 clib_memcpy (mp->segs_and_tags, segments,
6653 vec_len(segments)* sizeof (ip6_address_t));
6654 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
6655 tags, vec_len(tags)* sizeof (ip6_address_t));
6657 mp->outer_vrf_id = ntohl (rx_table_id);
6658 mp->inner_vrf_id = ntohl (tx_table_id);
6659 memcpy (mp->name, name, vec_len(name));
6660 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6662 vec_free (segments);
6669 static int api_sr_policy_add_del (vat_main_t * vam)
6671 unformat_input_t * input = vam->input;
6672 vl_api_sr_policy_add_del_t *mp;
6676 u8 * tunnel_name = 0;
6677 u8 ** tunnel_names = 0;
6682 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
6683 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
6685 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6687 if (unformat (input, "del"))
6689 else if (unformat (input, "name %s", &name))
6691 else if (unformat (input, "tunnel %s", &tunnel_name))
6695 vec_add1 (tunnel_names, tunnel_name);
6697 - length = #bytes to store in serial vector
6698 - +1 = byte to store that length
6700 tunnel_names_length += (vec_len (tunnel_name) + 1);
6711 errmsg ("policy name required\n");
6715 if ((!tunnel_set) && (!is_del))
6717 errmsg ("tunnel name required\n");
6721 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6725 mp->is_add = !is_del;
6727 memcpy (mp->name, name, vec_len(name));
6728 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6729 u8 * serial_orig = 0;
6730 vec_validate (serial_orig, tunnel_names_length);
6731 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6732 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6734 for (j=0; j < vec_len(tunnel_names); j++)
6736 tun_name_len = vec_len (tunnel_names[j]);
6737 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6738 serial_orig += 1; // Move along one byte to store the actual tunnel name
6739 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6740 serial_orig += tun_name_len; // Advance past the copy
6742 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6744 vec_free (tunnel_names);
6745 vec_free (tunnel_name);
6751 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6753 unformat_input_t * input = vam->input;
6754 vl_api_sr_multicast_map_add_del_t *mp;
6757 ip6_address_t multicast_address;
6758 u8 * policy_name = 0;
6759 int multicast_address_set = 0;
6761 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6763 if (unformat (input, "del"))
6765 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6766 multicast_address_set = 1;
6767 else if (unformat (input, "sr-policy %s", &policy_name))
6773 if (!is_del && !policy_name)
6775 errmsg ("sr-policy name required\n");
6780 if (!multicast_address_set)
6782 errmsg ("address required\n");
6786 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6788 mp->is_add = !is_del;
6789 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6790 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6793 vec_free (policy_name);
6800 #define foreach_ip4_proto_field \
6810 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6812 u8 ** maskp = va_arg (*args, u8 **);
6814 u8 found_something = 0;
6817 #define _(a) u8 a=0;
6818 foreach_ip4_proto_field;
6824 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6826 if (unformat (input, "version"))
6828 else if (unformat (input, "hdr_length"))
6830 else if (unformat (input, "src"))
6832 else if (unformat (input, "dst"))
6834 else if (unformat (input, "proto"))
6837 #define _(a) else if (unformat (input, #a)) a=1;
6838 foreach_ip4_proto_field
6844 #define _(a) found_something += a;
6845 foreach_ip4_proto_field;
6848 if (found_something == 0)
6851 vec_validate (mask, sizeof (*ip) - 1);
6853 ip = (ip4_header_t *) mask;
6855 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6856 foreach_ip4_proto_field;
6859 ip->ip_version_and_header_length = 0;
6862 ip->ip_version_and_header_length |= 0xF0;
6865 ip->ip_version_and_header_length |= 0x0F;
6871 #define foreach_ip6_proto_field \
6878 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6880 u8 ** maskp = va_arg (*args, u8 **);
6882 u8 found_something = 0;
6884 u32 ip_version_traffic_class_and_flow_label;
6886 #define _(a) u8 a=0;
6887 foreach_ip6_proto_field;
6890 u8 traffic_class = 0;
6893 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6895 if (unformat (input, "version"))
6897 else if (unformat (input, "traffic-class"))
6899 else if (unformat (input, "flow-label"))
6901 else if (unformat (input, "src"))
6903 else if (unformat (input, "dst"))
6905 else if (unformat (input, "proto"))
6908 #define _(a) else if (unformat (input, #a)) a=1;
6909 foreach_ip6_proto_field
6915 #define _(a) found_something += a;
6916 foreach_ip6_proto_field;
6919 if (found_something == 0)
6922 vec_validate (mask, sizeof (*ip) - 1);
6924 ip = (ip6_header_t *) mask;
6926 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6927 foreach_ip6_proto_field;
6930 ip_version_traffic_class_and_flow_label = 0;
6933 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6936 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6939 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6941 ip->ip_version_traffic_class_and_flow_label =
6942 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6948 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6950 u8 ** maskp = va_arg (*args, u8 **);
6952 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6953 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6955 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6963 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6965 u8 ** maskp = va_arg (*args, u8 **);
6980 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6981 if (unformat (input, "src"))
6983 else if (unformat (input, "dst"))
6985 else if (unformat (input, "proto"))
6987 else if (unformat (input, "tag1"))
6989 else if (unformat (input, "tag2"))
6991 else if (unformat (input, "ignore-tag1"))
6993 else if (unformat (input, "ignore-tag2"))
6995 else if (unformat (input, "cos1"))
6997 else if (unformat (input, "cos2"))
6999 else if (unformat (input, "dot1q"))
7001 else if (unformat (input, "dot1ad"))
7006 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7007 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7010 if (tag1 || ignore_tag1 || cos1 || dot1q)
7012 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7015 vec_validate (mask, len-1);
7018 memset (mask, 0xff, 6);
7021 memset (mask + 6, 0xff, 6);
7025 /* inner vlan tag */
7034 mask[21] = mask [20] = 0xff;
7055 mask[16] = mask [17] = 0xff;
7065 mask[12] = mask [13] = 0xff;
7071 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
7073 u8 ** maskp = va_arg (*args, u8 **);
7074 u32 * skipp = va_arg (*args, u32 *);
7075 u32 * matchp = va_arg (*args, u32 *);
7082 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7083 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7085 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7087 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7093 if (mask || l2 || l3)
7097 /* "With a free Ethernet header in every package" */
7099 vec_validate (l2, 13);
7101 vec_append (mask, l3);
7105 /* Scan forward looking for the first significant mask octet */
7106 for (i = 0; i < vec_len (mask); i++)
7110 /* compute (skip, match) params */
7111 *skipp = i / sizeof(u32x4);
7112 vec_delete (mask, *skipp * sizeof(u32x4), 0);
7114 /* Pad mask to an even multiple of the vector size */
7115 while (vec_len (mask) % sizeof (u32x4))
7118 match = vec_len (mask) / sizeof (u32x4);
7120 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
7122 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
7123 if (*tmp || *(tmp+1))
7128 clib_warning ("BUG: match 0");
7130 _vec_len (mask) = match * sizeof(u32x4);
7141 #define foreach_l2_next \
7143 _(ethernet, ETHERNET_INPUT) \
7147 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
7149 u32 * miss_next_indexp = va_arg (*args, u32 *);
7154 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
7158 if (unformat (input, "%d", &tmp))
7167 *miss_next_indexp = next_index;
7171 #define foreach_ip_next \
7177 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
7179 u32 * miss_next_indexp = va_arg (*args, u32 *);
7184 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7188 if (unformat (input, "%d", &tmp))
7197 *miss_next_indexp = next_index;
7201 #define foreach_acl_next \
7204 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
7206 u32 * miss_next_indexp = va_arg (*args, u32 *);
7211 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7215 if (unformat (input, "permit"))
7220 else if (unformat (input, "%d", &tmp))
7229 *miss_next_indexp = next_index;
7233 uword unformat_policer_precolor (unformat_input_t * input, va_list * args)
7235 u32 * r = va_arg (*args, u32 *);
7237 if (unformat (input, "conform-color"))
7238 *r = POLICE_CONFORM;
7239 else if (unformat (input, "exceed-color"))
7247 static int api_classify_add_del_table (vat_main_t * vam)
7249 unformat_input_t * i = vam->input;
7250 vl_api_classify_add_del_table_t *mp;
7256 u32 table_index = ~0;
7257 u32 next_table_index = ~0;
7258 u32 miss_next_index = ~0;
7259 u32 memory_size = 32<<20;
7263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7264 if (unformat (i, "del"))
7266 else if (unformat (i, "buckets %d", &nbuckets))
7268 else if (unformat (i, "memory_size %d", &memory_size))
7270 else if (unformat (i, "skip %d", &skip))
7272 else if (unformat (i, "match %d", &match))
7274 else if (unformat (i, "table %d", &table_index))
7276 else if (unformat (i, "mask %U", unformat_classify_mask,
7277 &mask, &skip, &match))
7279 else if (unformat (i, "next-table %d", &next_table_index))
7281 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
7284 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
7287 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
7294 if (is_add && mask == 0) {
7295 errmsg ("Mask required\n");
7299 if (is_add && skip == ~0) {
7300 errmsg ("skip count required\n");
7304 if (is_add && match == ~0) {
7305 errmsg ("match count required\n");
7309 if (!is_add && table_index == ~0) {
7310 errmsg ("table index required for delete\n");
7314 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
7317 mp->is_add = is_add;
7318 mp->table_index = ntohl(table_index);
7319 mp->nbuckets = ntohl(nbuckets);
7320 mp->memory_size = ntohl(memory_size);
7321 mp->skip_n_vectors = ntohl(skip);
7322 mp->match_n_vectors = ntohl(match);
7323 mp->next_table_index = ntohl(next_table_index);
7324 mp->miss_next_index = ntohl(miss_next_index);
7325 clib_memcpy (mp->mask, mask, vec_len(mask));
7333 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
7335 u8 ** matchp = va_arg (*args, u8 **);
7342 int src = 0, dst = 0;
7343 ip4_address_t src_val, dst_val;
7350 int fragment_id = 0;
7351 u32 fragment_id_val;
7357 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7359 if (unformat (input, "version %d", &version_val))
7361 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7363 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7365 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7367 else if (unformat (input, "proto %d", &proto_val))
7369 else if (unformat (input, "tos %d", &tos_val))
7371 else if (unformat (input, "length %d", &length_val))
7373 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7375 else if (unformat (input, "ttl %d", &ttl_val))
7377 else if (unformat (input, "checksum %d", &checksum_val))
7383 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7384 + ttl + checksum == 0)
7388 * Aligned because we use the real comparison functions
7390 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7392 ip = (ip4_header_t *) match;
7394 /* These are realistically matched in practice */
7396 ip->src_address.as_u32 = src_val.as_u32;
7399 ip->dst_address.as_u32 = dst_val.as_u32;
7402 ip->protocol = proto_val;
7405 /* These are not, but they're included for completeness */
7407 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
7410 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7416 ip->length = length_val;
7422 ip->checksum = checksum_val;
7428 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
7430 u8 ** matchp = va_arg (*args, u8 **);
7436 u32 traffic_class_val;
7439 int src = 0, dst = 0;
7440 ip6_address_t src_val, dst_val;
7443 int payload_length = 0;
7444 u32 payload_length_val;
7447 u32 ip_version_traffic_class_and_flow_label;
7449 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7451 if (unformat (input, "version %d", &version_val))
7453 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7455 else if (unformat (input, "flow_label %d", &flow_label_val))
7457 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7459 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7461 else if (unformat (input, "proto %d", &proto_val))
7463 else if (unformat (input, "payload_length %d", &payload_length_val))
7465 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7471 if (version + traffic_class + flow_label + src + dst + proto +
7472 payload_length + hop_limit == 0)
7476 * Aligned because we use the real comparison functions
7478 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7480 ip = (ip6_header_t *) match;
7483 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7486 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7489 ip->protocol = proto_val;
7491 ip_version_traffic_class_and_flow_label = 0;
7494 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7497 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
7500 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7502 ip->ip_version_traffic_class_and_flow_label =
7503 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7506 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7509 ip->hop_limit = hop_limit_val;
7515 uword unformat_l3_match (unformat_input_t * input, va_list * args)
7517 u8 ** matchp = va_arg (*args, u8 **);
7519 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7520 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7522 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7530 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
7532 u8 * tagp = va_arg (*args, u8 *);
7535 if (unformat(input, "%d", &tag))
7537 tagp[0] = (tag>>8) & 0x0F;
7538 tagp[1] = tag & 0xFF;
7545 uword unformat_l2_match (unformat_input_t * input, va_list * args)
7547 u8 ** matchp = va_arg (*args, u8 **);
7567 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7568 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7570 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7572 else if (unformat (input, "proto %U",
7573 unformat_ethernet_type_host_byte_order, &proto_val))
7575 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7577 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7579 else if (unformat (input, "ignore-tag1"))
7581 else if (unformat (input, "ignore-tag2"))
7583 else if (unformat (input, "cos1 %d", &cos1_val))
7585 else if (unformat (input, "cos2 %d", &cos2_val))
7590 if ((src + dst + proto + tag1 + tag2 +
7591 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7594 if (tag1 || ignore_tag1 || cos1)
7596 if (tag2 || ignore_tag2 || cos2)
7599 vec_validate_aligned (match, len-1, sizeof(u32x4));
7602 clib_memcpy (match, dst_val, 6);
7605 clib_memcpy (match + 6, src_val, 6);
7609 /* inner vlan tag */
7610 match[19] = tag2_val[1];
7611 match[18] = tag2_val[0];
7613 match [18] |= (cos2_val & 0x7) << 5;
7616 match[21] = proto_val & 0xff;
7617 match[20] = proto_val >> 8;
7621 match [15] = tag1_val[1];
7622 match [14] = tag1_val[0];
7625 match [14] |= (cos1_val & 0x7) << 5;
7631 match [15] = tag1_val[1];
7632 match [14] = tag1_val[0];
7635 match[17] = proto_val & 0xff;
7636 match[16] = proto_val >> 8;
7639 match [14] |= (cos1_val & 0x7) << 5;
7645 match [18] |= (cos2_val & 0x7) << 5;
7647 match [14] |= (cos1_val & 0x7) << 5;
7650 match[13] = proto_val & 0xff;
7651 match[12] = proto_val >> 8;
7659 uword unformat_classify_match (unformat_input_t * input, va_list * args)
7661 u8 ** matchp = va_arg (*args, u8 **);
7662 u32 skip_n_vectors = va_arg (*args, u32);
7663 u32 match_n_vectors = va_arg (*args, u32);
7669 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7670 if (unformat (input, "hex %U", unformat_hex_string, &match))
7672 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7674 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7680 if (match || l2 || l3)
7684 /* "Win a free Ethernet header in every packet" */
7686 vec_validate_aligned (l2, 13, sizeof(u32x4));
7688 vec_append_aligned (match, l3, sizeof(u32x4));
7692 /* Make sure the vector is big enough even if key is all 0's */
7693 vec_validate_aligned
7694 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
7697 /* Set size, include skipped vectors*/
7698 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
7708 static int api_classify_add_del_session (vat_main_t * vam)
7710 unformat_input_t * i = vam->input;
7711 vl_api_classify_add_del_session_t *mp;
7713 u32 table_index = ~0;
7714 u32 hit_next_index = ~0;
7715 u32 opaque_index = ~0;
7719 u32 skip_n_vectors = 0;
7720 u32 match_n_vectors = 0;
7723 * Warning: you have to supply skip_n and match_n
7724 * because the API client cant simply look at the classify
7728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7729 if (unformat (i, "del"))
7731 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7734 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7737 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7740 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
7742 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
7744 else if (unformat (i, "opaque-index %d", &opaque_index))
7746 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7748 else if (unformat (i, "match_n %d", &match_n_vectors))
7750 else if (unformat (i, "match %U", unformat_classify_match,
7751 &match, skip_n_vectors, match_n_vectors))
7753 else if (unformat (i, "advance %d", &advance))
7755 else if (unformat (i, "table-index %d", &table_index))
7761 if (table_index == ~0) {
7762 errmsg ("Table index required\n");
7766 if (is_add && match == 0) {
7767 errmsg ("Match value required\n");
7771 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7774 mp->is_add = is_add;
7775 mp->table_index = ntohl(table_index);
7776 mp->hit_next_index = ntohl(hit_next_index);
7777 mp->opaque_index = ntohl(opaque_index);
7778 mp->advance = ntohl(advance);
7779 clib_memcpy (mp->match, match, vec_len(match));
7786 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7788 unformat_input_t * i = vam->input;
7789 vl_api_classify_set_interface_ip_table_t *mp;
7792 int sw_if_index_set;
7793 u32 table_index = ~0;
7796 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7797 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7798 sw_if_index_set = 1;
7799 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7800 sw_if_index_set = 1;
7801 else if (unformat (i, "table %d", &table_index))
7804 clib_warning ("parse error '%U'", format_unformat_error, i);
7809 if (sw_if_index_set == 0) {
7810 errmsg ("missing interface name or sw_if_index\n");
7815 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7817 mp->sw_if_index = ntohl(sw_if_index);
7818 mp->table_index = ntohl(table_index);
7819 mp->is_ipv6 = is_ipv6;
7826 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7828 unformat_input_t * i = vam->input;
7829 vl_api_classify_set_interface_l2_tables_t *mp;
7832 int sw_if_index_set;
7833 u32 ip4_table_index = ~0;
7834 u32 ip6_table_index = ~0;
7835 u32 other_table_index = ~0;
7837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7838 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7839 sw_if_index_set = 1;
7840 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7841 sw_if_index_set = 1;
7842 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7844 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7846 else if (unformat (i, "other-table %d", &other_table_index))
7849 clib_warning ("parse error '%U'", format_unformat_error, i);
7854 if (sw_if_index_set == 0) {
7855 errmsg ("missing interface name or sw_if_index\n");
7860 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7862 mp->sw_if_index = ntohl(sw_if_index);
7863 mp->ip4_table_index = ntohl(ip4_table_index);
7864 mp->ip6_table_index = ntohl(ip6_table_index);
7865 mp->other_table_index = ntohl(other_table_index);
7873 static int api_ipfix_enable (vat_main_t * vam)
7875 unformat_input_t * i = vam->input;
7876 vl_api_ipfix_enable_t *mp;
7877 ip4_address_t collector_address;
7878 u8 collector_address_set = 0;
7879 u32 collector_port = ~0;
7880 ip4_address_t src_address;
7881 u8 src_address_set = 0;
7884 u32 template_interval = ~0;
7887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7888 if (unformat (i, "collector_address %U", unformat_ip4_address,
7889 &collector_address))
7890 collector_address_set = 1;
7891 else if (unformat (i, "collector_port %d", &collector_port))
7893 else if (unformat (i, "src_address %U", unformat_ip4_address,
7895 src_address_set = 1;
7896 else if (unformat (i, "vrf_id %d", &vrf_id))
7898 else if (unformat (i, "path_mtu %d", &path_mtu))
7900 else if (unformat (i, "template_interval %d", &template_interval))
7906 if (collector_address_set == 0) {
7907 errmsg ("collector_address required\n");
7911 if (src_address_set == 0) {
7912 errmsg ("src_address required\n");
7916 M (IPFIX_ENABLE, ipfix_enable);
7918 memcpy(mp->collector_address, collector_address.data,
7919 sizeof(collector_address.data));
7920 mp->collector_port = htons((u16)collector_port);
7921 memcpy(mp->src_address, src_address.data,
7922 sizeof(src_address.data));
7923 mp->vrf_id = htonl(vrf_id);
7924 mp->path_mtu = htonl(path_mtu);
7925 mp->template_interval = htonl(template_interval);
7931 static int api_get_node_index (vat_main_t * vam)
7933 unformat_input_t * i = vam->input;
7934 vl_api_get_node_index_t * mp;
7938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7939 if (unformat (i, "node %s", &name))
7945 errmsg ("node name required\n");
7948 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7949 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7953 M(GET_NODE_INDEX, get_node_index);
7954 clib_memcpy (mp->node_name, name, vec_len(name));
7962 static int api_get_next_index (vat_main_t * vam)
7964 unformat_input_t * i = vam->input;
7965 vl_api_get_next_index_t * mp;
7967 u8 * node_name = 0, * next_node_name = 0;
7969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7970 if (unformat (i, "node-name %s", &node_name))
7972 else if (unformat (i, "next-node-name %s", &next_node_name))
7976 if (node_name == 0) {
7977 errmsg ("node name required\n");
7980 if (vec_len (node_name) >= ARRAY_LEN(mp->node_name)) {
7981 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7985 if (next_node_name == 0) {
7986 errmsg ("next node name required\n");
7989 if (vec_len (next_node_name) >= ARRAY_LEN(mp->next_name)) {
7990 errmsg ("next node name too long, max %d\n", ARRAY_LEN(mp->next_name));
7994 M(GET_NEXT_INDEX, get_next_index);
7995 clib_memcpy (mp->node_name, node_name, vec_len(node_name));
7996 clib_memcpy (mp->next_name, next_node_name, vec_len(next_node_name));
7997 vec_free(node_name);
7998 vec_free(next_node_name);
8005 static int api_add_node_next (vat_main_t * vam)
8007 unformat_input_t * i = vam->input;
8008 vl_api_add_node_next_t * mp;
8013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8014 if (unformat (i, "node %s", &name))
8016 else if (unformat (i, "next %s", &next))
8022 errmsg ("node name required\n");
8025 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
8026 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
8030 errmsg ("next node required\n");
8033 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
8034 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
8038 M(ADD_NODE_NEXT, add_node_next);
8039 clib_memcpy (mp->node_name, name, vec_len(name));
8040 clib_memcpy (mp->next_name, next, vec_len(next));
8049 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
8051 unformat_input_t * i = vam->input;
8052 ip6_address_t client_address, our_address;
8053 int client_address_set = 0;
8054 int our_address_set = 0;
8055 u32 local_session_id = 0;
8056 u32 remote_session_id = 0;
8057 u64 local_cookie = 0;
8058 u64 remote_cookie = 0;
8059 u8 l2_sublayer_present = 0;
8060 vl_api_l2tpv3_create_tunnel_t * mp;
8063 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8064 if (unformat (i, "client_address %U", unformat_ip6_address,
8066 client_address_set = 1;
8067 else if (unformat (i, "our_address %U", unformat_ip6_address,
8069 our_address_set = 1;
8070 else if (unformat (i, "local_session_id %d", &local_session_id))
8072 else if (unformat (i, "remote_session_id %d", &remote_session_id))
8074 else if (unformat (i, "local_cookie %lld", &local_cookie))
8076 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
8078 else if (unformat (i, "l2-sublayer-present"))
8079 l2_sublayer_present = 1;
8084 if (client_address_set == 0) {
8085 errmsg ("client_address required\n");
8089 if (our_address_set == 0) {
8090 errmsg ("our_address required\n");
8094 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
8096 clib_memcpy (mp->client_address, client_address.as_u8,
8097 sizeof (mp->client_address));
8099 clib_memcpy (mp->our_address, our_address.as_u8,
8100 sizeof (mp->our_address));
8102 mp->local_session_id = ntohl (local_session_id);
8103 mp->remote_session_id = ntohl (remote_session_id);
8104 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
8105 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
8106 mp->l2_sublayer_present = l2_sublayer_present;
8114 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
8116 unformat_input_t * i = vam->input;
8118 u8 sw_if_index_set = 0;
8119 u64 new_local_cookie = 0;
8120 u64 new_remote_cookie = 0;
8121 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
8124 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8125 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8126 sw_if_index_set = 1;
8127 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8128 sw_if_index_set = 1;
8129 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
8131 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
8137 if (sw_if_index_set == 0) {
8138 errmsg ("missing interface name or sw_if_index\n");
8142 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
8144 mp->sw_if_index = ntohl(sw_if_index);
8145 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
8146 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
8153 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
8155 unformat_input_t * i = vam->input;
8156 vl_api_l2tpv3_interface_enable_disable_t *mp;
8159 u8 sw_if_index_set = 0;
8160 u8 enable_disable = 1;
8162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8163 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8164 sw_if_index_set = 1;
8165 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8166 sw_if_index_set = 1;
8167 else if (unformat (i, "enable"))
8169 else if (unformat (i, "disable"))
8175 if (sw_if_index_set == 0) {
8176 errmsg ("missing interface name or sw_if_index\n");
8180 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
8182 mp->sw_if_index = ntohl(sw_if_index);
8183 mp->enable_disable = enable_disable;
8190 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
8192 unformat_input_t * i = vam->input;
8193 vl_api_l2tpv3_set_lookup_key_t * mp;
8197 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8198 if (unformat (i, "lookup_v6_src"))
8199 key = L2T_LOOKUP_SRC_ADDRESS;
8200 else if (unformat (i, "lookup_v6_dst"))
8201 key = L2T_LOOKUP_DST_ADDRESS;
8202 else if (unformat (i, "lookup_session_id"))
8203 key = L2T_LOOKUP_SESSION_ID;
8208 if (key == (u8) ~0) {
8209 errmsg ("l2tp session lookup key unset\n");
8213 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
8222 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
8223 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8225 vat_main_t * vam = &vat_main;
8227 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
8228 format_ip6_address, mp->our_address,
8229 format_ip6_address, mp->client_address,
8230 clib_net_to_host_u32(mp->sw_if_index));
8232 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
8233 clib_net_to_host_u64 (mp->local_cookie[0]),
8234 clib_net_to_host_u64 (mp->local_cookie[1]),
8235 clib_net_to_host_u64 (mp->remote_cookie));
8237 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
8238 clib_net_to_host_u32 (mp->local_session_id),
8239 clib_net_to_host_u32 (mp->remote_session_id));
8241 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
8242 mp->l2_sublayer_present ? "preset" : "absent");
8246 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
8247 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8249 vat_main_t * vam = &vat_main;
8250 vat_json_node_t *node = NULL;
8251 struct in6_addr addr;
8253 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8254 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8255 vat_json_init_array(&vam->json_tree);
8257 node = vat_json_array_add(&vam->json_tree);
8259 vat_json_init_object(node);
8261 clib_memcpy(&addr, mp->our_address, sizeof(addr));
8262 vat_json_object_add_ip6(node, "our_address", addr);
8263 clib_memcpy(&addr, mp->client_address, sizeof(addr));
8264 vat_json_object_add_ip6(node, "client_address", addr);
8266 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
8267 vat_json_init_array(lc);
8268 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
8269 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
8270 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
8272 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
8273 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
8274 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
8275 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
8276 (u8*)"present" : (u8*)"absent");
8279 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
8281 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
8284 /* Get list of l2tpv3-tunnel interfaces */
8285 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
8288 /* Use a control ping for synchronization */
8290 vl_api_control_ping_t * mp;
8291 M(CONTROL_PING, control_ping);
8298 static void vl_api_sw_interface_tap_details_t_handler
8299 (vl_api_sw_interface_tap_details_t * mp)
8301 vat_main_t * vam = &vat_main;
8303 fformat(vam->ofp, "%-16s %d\n",
8305 clib_net_to_host_u32(mp->sw_if_index));
8308 static void vl_api_sw_interface_tap_details_t_handler_json
8309 (vl_api_sw_interface_tap_details_t * mp)
8311 vat_main_t * vam = &vat_main;
8312 vat_json_node_t *node = NULL;
8314 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8315 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8316 vat_json_init_array(&vam->json_tree);
8318 node = vat_json_array_add(&vam->json_tree);
8320 vat_json_init_object(node);
8321 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8322 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
8325 static int api_sw_interface_tap_dump (vat_main_t * vam)
8327 vl_api_sw_interface_tap_dump_t *mp;
8330 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
8331 /* Get list of tap interfaces */
8332 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
8335 /* Use a control ping for synchronization */
8337 vl_api_control_ping_t * mp;
8338 M(CONTROL_PING, control_ping);
8344 static uword unformat_vxlan_decap_next
8345 (unformat_input_t * input, va_list * args)
8347 u32 * result = va_arg (*args, u32 *);
8350 if (unformat (input, "drop"))
8351 *result = VXLAN_INPUT_NEXT_DROP;
8352 else if (unformat (input, "ip4"))
8353 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
8354 else if (unformat (input, "ip6"))
8355 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
8356 else if (unformat (input, "l2"))
8357 *result = VXLAN_INPUT_NEXT_L2_INPUT;
8358 else if (unformat (input, "%d", &tmp))
8365 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
8367 unformat_input_t * line_input = vam->input;
8368 vl_api_vxlan_add_del_tunnel_t *mp;
8370 ip4_address_t src4, dst4;
8371 ip6_address_t src6, dst6;
8373 u8 ipv4_set = 0, ipv6_set = 0;
8376 u32 encap_vrf_id = 0;
8377 u32 decap_next_index = ~0;
8380 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8381 if (unformat (line_input, "del"))
8383 else if (unformat (line_input, "src %U",
8384 unformat_ip4_address, &src4))
8389 else if (unformat (line_input, "dst %U",
8390 unformat_ip4_address, &dst4))
8395 else if (unformat (line_input, "src %U",
8396 unformat_ip6_address, &src6))
8401 else if (unformat (line_input, "dst %U",
8402 unformat_ip6_address, &dst6))
8407 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8409 else if (unformat (line_input, "decap-next %U",
8410 unformat_vxlan_decap_next, &decap_next_index))
8412 else if (unformat (line_input, "vni %d", &vni))
8415 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8421 errmsg ("tunnel src address not specified\n");
8425 errmsg ("tunnel dst address not specified\n");
8429 if (ipv4_set && ipv6_set) {
8430 errmsg ("both IPv4 and IPv6 addresses specified");
8434 if ((vni == 0) || (vni>>24)) {
8435 errmsg ("vni not specified or out of range\n");
8439 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
8442 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
8443 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
8445 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8446 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8448 mp->encap_vrf_id = ntohl(encap_vrf_id);
8449 mp->decap_next_index = ntohl(decap_next_index);
8450 mp->vni = ntohl(vni);
8451 mp->is_add = is_add;
8452 mp->is_ipv6 = ipv6_set;
8459 static void vl_api_vxlan_tunnel_details_t_handler
8460 (vl_api_vxlan_tunnel_details_t * mp)
8462 vat_main_t * vam = &vat_main;
8464 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
8465 ntohl(mp->sw_if_index),
8466 format_ip46_address, &(mp->src_address[0]),
8468 format_ip46_address, &(mp->dst_address[0]),
8470 ntohl(mp->encap_vrf_id),
8471 ntohl(mp->decap_next_index),
8475 static void vl_api_vxlan_tunnel_details_t_handler_json
8476 (vl_api_vxlan_tunnel_details_t * mp)
8478 vat_main_t * vam = &vat_main;
8479 vat_json_node_t *node = NULL;
8481 struct in6_addr ip6;
8483 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8484 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8485 vat_json_init_array(&vam->json_tree);
8487 node = vat_json_array_add(&vam->json_tree);
8489 vat_json_init_object(node);
8490 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8492 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
8493 vat_json_object_add_ip6(node, "src_address", ip6);
8494 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
8495 vat_json_object_add_ip6(node, "dst_address", ip6);
8497 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
8498 vat_json_object_add_ip4(node, "src_address", ip4);
8499 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
8500 vat_json_object_add_ip4(node, "dst_address", ip4);
8502 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8503 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
8504 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8505 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8508 static int api_vxlan_tunnel_dump (vat_main_t * vam)
8510 unformat_input_t * i = vam->input;
8511 vl_api_vxlan_tunnel_dump_t *mp;
8514 u8 sw_if_index_set = 0;
8516 /* Parse args required to build the message */
8517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8518 if (unformat (i, "sw_if_index %d", &sw_if_index))
8519 sw_if_index_set = 1;
8524 if (sw_if_index_set == 0) {
8528 if (!vam->json_output) {
8529 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
8530 "sw_if_index", "src_address", "dst_address",
8531 "encap_vrf_id", "decap_next_index", "vni");
8534 /* Get list of vxlan-tunnel interfaces */
8535 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
8537 mp->sw_if_index = htonl(sw_if_index);
8541 /* Use a control ping for synchronization */
8543 vl_api_control_ping_t * mp;
8544 M(CONTROL_PING, control_ping);
8550 static int api_gre_add_del_tunnel (vat_main_t * vam)
8552 unformat_input_t * line_input = vam->input;
8553 vl_api_gre_add_del_tunnel_t *mp;
8555 ip4_address_t src4, dst4;
8559 u32 outer_fib_id = 0;
8561 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8562 if (unformat (line_input, "del"))
8564 else if (unformat (line_input, "src %U",
8565 unformat_ip4_address, &src4))
8567 else if (unformat (line_input, "dst %U",
8568 unformat_ip4_address, &dst4))
8570 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
8573 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8579 errmsg ("tunnel src address not specified\n");
8583 errmsg ("tunnel dst address not specified\n");
8588 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
8590 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8591 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8592 mp->outer_fib_id = ntohl(outer_fib_id);
8593 mp->is_add = is_add;
8600 static void vl_api_gre_tunnel_details_t_handler
8601 (vl_api_gre_tunnel_details_t * mp)
8603 vat_main_t * vam = &vat_main;
8605 fformat(vam->ofp, "%11d%15U%15U%14d\n",
8606 ntohl(mp->sw_if_index),
8607 format_ip4_address, &mp->src_address,
8608 format_ip4_address, &mp->dst_address,
8609 ntohl(mp->outer_fib_id));
8612 static void vl_api_gre_tunnel_details_t_handler_json
8613 (vl_api_gre_tunnel_details_t * mp)
8615 vat_main_t * vam = &vat_main;
8616 vat_json_node_t *node = NULL;
8619 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8620 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8621 vat_json_init_array(&vam->json_tree);
8623 node = vat_json_array_add(&vam->json_tree);
8625 vat_json_init_object(node);
8626 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8627 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
8628 vat_json_object_add_ip4(node, "src_address", ip4);
8629 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
8630 vat_json_object_add_ip4(node, "dst_address", ip4);
8631 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_fib_id));
8634 static int api_gre_tunnel_dump (vat_main_t * vam)
8636 unformat_input_t * i = vam->input;
8637 vl_api_gre_tunnel_dump_t *mp;
8640 u8 sw_if_index_set = 0;
8642 /* Parse args required to build the message */
8643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8644 if (unformat (i, "sw_if_index %d", &sw_if_index))
8645 sw_if_index_set = 1;
8650 if (sw_if_index_set == 0) {
8654 if (!vam->json_output) {
8655 fformat(vam->ofp, "%11s%15s%15s%14s\n",
8656 "sw_if_index", "src_address", "dst_address",
8660 /* Get list of gre-tunnel interfaces */
8661 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
8663 mp->sw_if_index = htonl(sw_if_index);
8667 /* Use a control ping for synchronization */
8669 vl_api_control_ping_t * mp;
8670 M(CONTROL_PING, control_ping);
8676 static int api_l2_fib_clear_table (vat_main_t * vam)
8678 // unformat_input_t * i = vam->input;
8679 vl_api_l2_fib_clear_table_t *mp;
8682 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
8689 static int api_l2_interface_efp_filter (vat_main_t * vam)
8691 unformat_input_t * i = vam->input;
8692 vl_api_l2_interface_efp_filter_t *mp;
8696 u8 sw_if_index_set = 0;
8698 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8699 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8700 sw_if_index_set = 1;
8701 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8702 sw_if_index_set = 1;
8703 else if (unformat (i, "enable"))
8705 else if (unformat (i, "disable"))
8708 clib_warning ("parse error '%U'", format_unformat_error, i);
8713 if (sw_if_index_set == 0) {
8714 errmsg ("missing sw_if_index\n");
8718 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
8720 mp->sw_if_index = ntohl(sw_if_index);
8721 mp->enable_disable = enable;
8728 #define foreach_vtr_op \
8729 _("disable", L2_VTR_DISABLED) \
8730 _("push-1", L2_VTR_PUSH_1) \
8731 _("push-2", L2_VTR_PUSH_2) \
8732 _("pop-1", L2_VTR_POP_1) \
8733 _("pop-2", L2_VTR_POP_2) \
8734 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8735 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8736 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8737 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8739 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8741 unformat_input_t * i = vam->input;
8742 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8745 u8 sw_if_index_set = 0;
8752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8753 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8754 sw_if_index_set = 1;
8755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8756 sw_if_index_set = 1;
8757 else if (unformat (i, "vtr_op %d", &vtr_op))
8759 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8763 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8765 else if (unformat (i, "tag1 %d", &tag1))
8767 else if (unformat (i, "tag2 %d", &tag2))
8770 clib_warning ("parse error '%U'", format_unformat_error, i);
8775 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
8776 errmsg ("missing vtr operation or sw_if_index\n");
8780 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
8782 mp->sw_if_index = ntohl(sw_if_index);
8783 mp->vtr_op = ntohl(vtr_op);
8784 mp->push_dot1q = ntohl(push_dot1q);
8785 mp->tag1 = ntohl(tag1);
8786 mp->tag2 = ntohl(tag2);
8793 static int api_create_vhost_user_if (vat_main_t * vam)
8795 unformat_input_t * i = vam->input;
8796 vl_api_create_vhost_user_if_t *mp;
8800 u8 file_name_set = 0;
8801 u32 custom_dev_instance = ~0;
8803 u8 use_custom_mac = 0;
8805 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8806 if (unformat (i, "socket %s", &file_name)) {
8809 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8811 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8813 else if (unformat (i, "server"))
8819 if (file_name_set == 0) {
8820 errmsg ("missing socket file name\n");
8824 if (vec_len (file_name) > 255) {
8825 errmsg ("socket file name too long\n");
8828 vec_add1 (file_name, 0);
8830 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8832 mp->is_server = is_server;
8833 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8834 vec_free(file_name);
8835 if (custom_dev_instance != ~0) {
8837 mp->custom_dev_instance = ntohl(custom_dev_instance);
8839 mp->use_custom_mac = use_custom_mac;
8840 clib_memcpy(mp->mac_address, hwaddr, 6);
8847 static int api_modify_vhost_user_if (vat_main_t * vam)
8849 unformat_input_t * i = vam->input;
8850 vl_api_modify_vhost_user_if_t *mp;
8854 u8 file_name_set = 0;
8855 u32 custom_dev_instance = ~0;
8856 u8 sw_if_index_set = 0;
8857 u32 sw_if_index = (u32)~0;
8859 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8860 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8861 sw_if_index_set = 1;
8862 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8863 sw_if_index_set = 1;
8864 else if (unformat (i, "socket %s", &file_name)) {
8867 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8869 else if (unformat (i, "server"))
8875 if (sw_if_index_set == 0) {
8876 errmsg ("missing sw_if_index or interface name\n");
8880 if (file_name_set == 0) {
8881 errmsg ("missing socket file name\n");
8885 if (vec_len (file_name) > 255) {
8886 errmsg ("socket file name too long\n");
8889 vec_add1 (file_name, 0);
8891 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8893 mp->sw_if_index = ntohl(sw_if_index);
8894 mp->is_server = is_server;
8895 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8896 vec_free(file_name);
8897 if (custom_dev_instance != ~0) {
8899 mp->custom_dev_instance = ntohl(custom_dev_instance);
8907 static int api_delete_vhost_user_if (vat_main_t * vam)
8909 unformat_input_t * i = vam->input;
8910 vl_api_delete_vhost_user_if_t *mp;
8912 u32 sw_if_index = ~0;
8913 u8 sw_if_index_set = 0;
8915 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8916 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8917 sw_if_index_set = 1;
8918 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8919 sw_if_index_set = 1;
8924 if (sw_if_index_set == 0) {
8925 errmsg ("missing sw_if_index or interface name\n");
8930 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8932 mp->sw_if_index = ntohl(sw_if_index);
8939 static void vl_api_sw_interface_vhost_user_details_t_handler
8940 (vl_api_sw_interface_vhost_user_details_t * mp)
8942 vat_main_t * vam = &vat_main;
8944 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8945 (char *)mp->interface_name,
8946 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8947 clib_net_to_host_u64(mp->features), mp->is_server,
8948 ntohl(mp->num_regions), (char *)mp->sock_filename);
8949 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8952 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8953 (vl_api_sw_interface_vhost_user_details_t * mp)
8955 vat_main_t * vam = &vat_main;
8956 vat_json_node_t *node = NULL;
8958 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8959 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8960 vat_json_init_array(&vam->json_tree);
8962 node = vat_json_array_add(&vam->json_tree);
8964 vat_json_init_object(node);
8965 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8966 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8967 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8968 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8969 vat_json_object_add_uint(node, "is_server", mp->is_server);
8970 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8971 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8972 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8975 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8977 vl_api_sw_interface_vhost_user_dump_t *mp;
8979 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8981 /* Get list of vhost-user interfaces */
8982 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8985 /* Use a control ping for synchronization */
8987 vl_api_control_ping_t * mp;
8988 M(CONTROL_PING, control_ping);
8994 static int api_show_version (vat_main_t * vam)
8996 vl_api_show_version_t *mp;
8999 M(SHOW_VERSION, show_version);
9007 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
9009 unformat_input_t * line_input = vam->input;
9010 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
9012 ip4_address_t local4, remote4;
9013 ip6_address_t local6, remote6;
9015 u8 ipv4_set = 0, ipv6_set = 0;
9018 u32 encap_vrf_id = 0;
9019 u32 decap_vrf_id = 0;
9024 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9025 if (unformat (line_input, "del"))
9027 else if (unformat (line_input, "local %U",
9028 unformat_ip4_address, &local4))
9033 else if (unformat (line_input, "remote %U",
9034 unformat_ip4_address, &remote4))
9039 else if (unformat (line_input, "local %U",
9040 unformat_ip6_address, &local6))
9045 else if (unformat (line_input, "remote %U",
9046 unformat_ip6_address, &remote6))
9051 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9053 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
9055 else if (unformat (line_input, "vni %d", &vni))
9057 else if (unformat(line_input, "next-ip4"))
9059 else if (unformat(line_input, "next-ip6"))
9061 else if (unformat(line_input, "next-ethernet"))
9063 else if (unformat(line_input, "next-nsh"))
9066 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9071 if (local_set == 0) {
9072 errmsg ("tunnel local address not specified\n");
9075 if (remote_set == 0) {
9076 errmsg ("tunnel remote address not specified\n");
9079 if (ipv4_set && ipv6_set) {
9080 errmsg ("both IPv4 and IPv6 addresses specified");
9085 errmsg ("vni not specified\n");
9089 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
9093 clib_memcpy(&mp->local, &local6, sizeof(local6));
9094 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
9096 clib_memcpy(&mp->local, &local4, sizeof(local4));
9097 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
9100 mp->encap_vrf_id = ntohl(encap_vrf_id);
9101 mp->decap_vrf_id = ntohl(decap_vrf_id);
9102 mp->protocol = ntohl(protocol);
9103 mp->vni = ntohl(vni);
9104 mp->is_add = is_add;
9105 mp->is_ipv6 = ipv6_set;
9112 static void vl_api_vxlan_gpe_tunnel_details_t_handler
9113 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9115 vat_main_t * vam = &vat_main;
9117 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
9118 ntohl(mp->sw_if_index),
9119 format_ip46_address, &(mp->local[0]),
9120 format_ip46_address, &(mp->remote[0]),
9122 ntohl(mp->protocol),
9123 ntohl(mp->encap_vrf_id),
9124 ntohl(mp->decap_vrf_id));
9127 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
9128 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9130 vat_main_t * vam = &vat_main;
9131 vat_json_node_t *node = NULL;
9133 struct in6_addr ip6;
9135 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9136 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9137 vat_json_init_array(&vam->json_tree);
9139 node = vat_json_array_add(&vam->json_tree);
9141 vat_json_init_object(node);
9142 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9144 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
9145 vat_json_object_add_ip6(node, "local", ip6);
9146 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
9147 vat_json_object_add_ip6(node, "remote", ip6);
9149 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
9150 vat_json_object_add_ip4(node, "local", ip4);
9151 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
9152 vat_json_object_add_ip4(node, "remote", ip4);
9154 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
9155 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
9156 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
9157 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
9158 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
9161 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
9163 unformat_input_t * i = vam->input;
9164 vl_api_vxlan_gpe_tunnel_dump_t *mp;
9167 u8 sw_if_index_set = 0;
9169 /* Parse args required to build the message */
9170 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9171 if (unformat (i, "sw_if_index %d", &sw_if_index))
9172 sw_if_index_set = 1;
9177 if (sw_if_index_set == 0) {
9181 if (!vam->json_output) {
9182 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
9183 "sw_if_index", "local", "remote", "vni",
9184 "protocol","encap_vrf_id", "decap_vrf_id");
9187 /* Get list of vxlan-tunnel interfaces */
9188 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
9190 mp->sw_if_index = htonl(sw_if_index);
9194 /* Use a control ping for synchronization */
9196 vl_api_control_ping_t * mp;
9197 M(CONTROL_PING, control_ping);
9203 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
9205 u8 * a = va_arg (*args, u8 *);
9207 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
9208 a[2], a[3], a[4], a[5], a[6], a[7]);
9211 static void vl_api_l2_fib_table_entry_t_handler
9212 (vl_api_l2_fib_table_entry_t * mp)
9214 vat_main_t * vam = &vat_main;
9216 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
9218 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
9219 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
9223 static void vl_api_l2_fib_table_entry_t_handler_json
9224 (vl_api_l2_fib_table_entry_t * mp)
9226 vat_main_t * vam = &vat_main;
9227 vat_json_node_t *node = NULL;
9229 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9230 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9231 vat_json_init_array(&vam->json_tree);
9233 node = vat_json_array_add(&vam->json_tree);
9235 vat_json_init_object(node);
9236 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
9237 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
9238 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9239 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
9240 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
9241 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
9244 static int api_l2_fib_table_dump (vat_main_t * vam)
9246 unformat_input_t * i = vam->input;
9247 vl_api_l2_fib_table_dump_t *mp;
9252 /* Parse args required to build the message */
9253 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9254 if (unformat (i, "bd_id %d", &bd_id))
9260 if (bd_id_set == 0) {
9261 errmsg ("missing bridge domain\n");
9265 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
9267 /* Get list of l2 fib entries */
9268 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
9270 mp->bd_id = ntohl(bd_id);
9273 /* Use a control ping for synchronization */
9275 vl_api_control_ping_t * mp;
9276 M(CONTROL_PING, control_ping);
9284 api_interface_name_renumber (vat_main_t * vam)
9286 unformat_input_t * line_input = vam->input;
9287 vl_api_interface_name_renumber_t *mp;
9288 u32 sw_if_index = ~0;
9290 u32 new_show_dev_instance = ~0;
9292 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9293 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
9296 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9298 else if (unformat (line_input, "new_show_dev_instance %d",
9299 &new_show_dev_instance))
9305 if (sw_if_index == ~0) {
9306 errmsg ("missing interface name or sw_if_index\n");
9310 if (new_show_dev_instance == ~0) {
9311 errmsg ("missing new_show_dev_instance\n");
9315 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
9317 mp->sw_if_index = ntohl (sw_if_index);
9318 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
9324 api_want_ip4_arp_events (vat_main_t * vam)
9326 unformat_input_t * line_input = vam->input;
9327 vl_api_want_ip4_arp_events_t * mp;
9329 ip4_address_t address;
9330 int address_set = 0;
9331 u32 enable_disable = 1;
9333 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9334 if (unformat (line_input, "address %U",
9335 unformat_ip4_address, &address))
9337 else if (unformat (line_input, "del"))
9343 if (address_set == 0) {
9344 errmsg ("missing addresses\n");
9348 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
9349 mp->enable_disable = enable_disable;
9351 mp->address = address.as_u32;
9356 static int api_input_acl_set_interface (vat_main_t * vam)
9358 unformat_input_t * i = vam->input;
9359 vl_api_input_acl_set_interface_t *mp;
9362 int sw_if_index_set;
9363 u32 ip4_table_index = ~0;
9364 u32 ip6_table_index = ~0;
9365 u32 l2_table_index = ~0;
9368 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9369 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9370 sw_if_index_set = 1;
9371 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9372 sw_if_index_set = 1;
9373 else if (unformat (i, "del"))
9375 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9377 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9379 else if (unformat (i, "l2-table %d", &l2_table_index))
9382 clib_warning ("parse error '%U'", format_unformat_error, i);
9387 if (sw_if_index_set == 0) {
9388 errmsg ("missing interface name or sw_if_index\n");
9392 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
9394 mp->sw_if_index = ntohl(sw_if_index);
9395 mp->ip4_table_index = ntohl(ip4_table_index);
9396 mp->ip6_table_index = ntohl(ip6_table_index);
9397 mp->l2_table_index = ntohl(l2_table_index);
9398 mp->is_add = is_add;
9406 api_ip_address_dump (vat_main_t * vam)
9408 unformat_input_t * i = vam->input;
9409 vl_api_ip_address_dump_t * mp;
9410 u32 sw_if_index = ~0;
9411 u8 sw_if_index_set = 0;
9416 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9417 if (unformat (i, "sw_if_index %d", &sw_if_index))
9418 sw_if_index_set = 1;
9419 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9420 sw_if_index_set = 1;
9421 else if (unformat (i, "ipv4"))
9423 else if (unformat (i, "ipv6"))
9429 if (ipv4_set && ipv6_set) {
9430 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9434 if ((!ipv4_set) && (!ipv6_set)) {
9435 errmsg ("no ipv4 nor ipv6 flag set\n");
9439 if (sw_if_index_set == 0) {
9440 errmsg ("missing interface name or sw_if_index\n");
9444 vam->current_sw_if_index = sw_if_index;
9445 vam->is_ipv6 = ipv6_set;
9447 M(IP_ADDRESS_DUMP, ip_address_dump);
9448 mp->sw_if_index = ntohl(sw_if_index);
9449 mp->is_ipv6 = ipv6_set;
9452 /* Use a control ping for synchronization */
9454 vl_api_control_ping_t * mp;
9455 M(CONTROL_PING, control_ping);
9462 api_ip_dump (vat_main_t * vam)
9464 vl_api_ip_dump_t * mp;
9465 unformat_input_t * in = vam->input;
9472 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
9473 if (unformat (in, "ipv4"))
9475 else if (unformat (in, "ipv6"))
9481 if (ipv4_set && ipv6_set) {
9482 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9486 if ((!ipv4_set) && (!ipv6_set)) {
9487 errmsg ("no ipv4 nor ipv6 flag set\n");
9492 vam->is_ipv6 = is_ipv6;
9495 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
9496 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9498 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
9500 M(IP_DUMP, ip_dump);
9501 mp->is_ipv6 = ipv6_set;
9504 /* Use a control ping for synchronization */
9506 vl_api_control_ping_t * mp;
9507 M(CONTROL_PING, control_ping);
9514 api_ipsec_spd_add_del (vat_main_t * vam)
9517 unformat_input_t * i = vam->input;
9518 vl_api_ipsec_spd_add_del_t *mp;
9523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9524 if (unformat (i, "spd_id %d", &spd_id))
9526 else if (unformat (i, "del"))
9529 clib_warning ("parse error '%U'", format_unformat_error, i);
9534 errmsg ("spd_id must be set\n");
9538 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
9540 mp->spd_id = ntohl(spd_id);
9541 mp->is_add = is_add;
9547 clib_warning ("unsupported (no dpdk)");
9553 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9556 unformat_input_t * i = vam->input;
9557 vl_api_ipsec_interface_add_del_spd_t *mp;
9560 u8 sw_if_index_set = 0;
9561 u32 spd_id = (u32) ~0;
9564 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9565 if (unformat (i, "del"))
9567 else if (unformat (i, "spd_id %d", &spd_id))
9569 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9570 sw_if_index_set = 1;
9571 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9572 sw_if_index_set = 1;
9574 clib_warning ("parse error '%U'", format_unformat_error, i);
9580 if (spd_id == (u32) ~0) {
9581 errmsg ("spd_id must be set\n");
9585 if (sw_if_index_set == 0) {
9586 errmsg ("missing interface name or sw_if_index\n");
9590 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
9592 mp->spd_id = ntohl(spd_id);
9593 mp->sw_if_index = ntohl (sw_if_index);
9594 mp->is_add = is_add;
9600 clib_warning ("unsupported (no dpdk)");
9606 api_ipsec_spd_add_del_entry (vat_main_t * vam)
9609 unformat_input_t * i = vam->input;
9610 vl_api_ipsec_spd_add_del_entry_t *mp;
9612 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
9613 u32 spd_id, sa_id, protocol = 0, policy = 0;
9615 u32 rport_start = 0, rport_stop = (u32) ~0;
9616 u32 lport_start = 0, lport_stop = (u32) ~0;
9617 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
9618 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
9620 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
9621 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
9622 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
9623 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
9624 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
9625 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
9627 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9628 if (unformat (i, "del"))
9630 if (unformat (i, "outbound"))
9632 if (unformat (i, "inbound"))
9634 else if (unformat (i, "spd_id %d", &spd_id))
9636 else if (unformat (i, "sa_id %d", &sa_id))
9638 else if (unformat (i, "priority %d", &priority))
9640 else if (unformat (i, "protocol %d", &protocol))
9642 else if (unformat (i, "lport_start %d", &lport_start))
9644 else if (unformat (i, "lport_stop %d", &lport_stop))
9646 else if (unformat (i, "rport_start %d", &rport_start))
9648 else if (unformat (i, "rport_stop %d", &rport_stop))
9650 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
9655 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
9660 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
9665 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
9670 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
9675 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
9680 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
9685 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
9690 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9692 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
9693 clib_warning ("unsupported action: 'resolve'");
9698 clib_warning ("parse error '%U'", format_unformat_error, i);
9704 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
9706 mp->spd_id = ntohl(spd_id);
9707 mp->priority = ntohl(priority);
9708 mp->is_outbound = is_outbound;
9710 mp->is_ipv6 = is_ipv6;
9711 if (is_ipv6 || is_ip_any) {
9712 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
9713 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
9714 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
9715 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
9717 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
9718 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
9719 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
9720 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
9722 mp->protocol = (u8) protocol;
9723 mp->local_port_start = ntohs((u16) lport_start);
9724 mp->local_port_stop = ntohs((u16) lport_stop);
9725 mp->remote_port_start = ntohs((u16) rport_start);
9726 mp->remote_port_stop = ntohs((u16) rport_stop);
9727 mp->policy = (u8) policy;
9728 mp->sa_id = ntohl(sa_id);
9729 mp->is_add = is_add;
9730 mp->is_ip_any = is_ip_any;
9735 clib_warning ("unsupported (no dpdk)");
9741 api_ipsec_sad_add_del_entry (vat_main_t * vam)
9744 unformat_input_t * i = vam->input;
9745 vl_api_ipsec_sad_add_del_entry_t *mp;
9748 u8 * ck = 0, * ik = 0;
9751 u8 protocol = IPSEC_PROTOCOL_AH;
9752 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
9753 u32 crypto_alg = 0, integ_alg = 0;
9754 ip4_address_t tun_src4;
9755 ip4_address_t tun_dst4;
9756 ip6_address_t tun_src6;
9757 ip6_address_t tun_dst6;
9759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9760 if (unformat (i, "del"))
9762 else if (unformat (i, "sad_id %d", &sad_id))
9764 else if (unformat (i, "spi %d", &spi))
9766 else if (unformat (i, "esp"))
9767 protocol = IPSEC_PROTOCOL_ESP;
9768 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
9772 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
9776 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
9780 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
9784 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
9785 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
9786 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9787 clib_warning ("unsupported crypto-alg: '%U'",
9788 format_ipsec_crypto_alg, crypto_alg);
9792 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9794 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
9795 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
9796 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9797 clib_warning ("unsupported integ-alg: '%U'",
9798 format_ipsec_integ_alg, integ_alg);
9802 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9805 clib_warning ("parse error '%U'", format_unformat_error, i);
9811 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
9813 mp->sad_id = ntohl(sad_id);
9814 mp->is_add = is_add;
9815 mp->protocol = protocol;
9816 mp->spi = ntohl(spi);
9817 mp->is_tunnel = is_tunnel;
9818 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
9819 mp->crypto_algorithm = crypto_alg;
9820 mp->integrity_algorithm = integ_alg;
9821 mp->crypto_key_length = vec_len(ck);
9822 mp->integrity_key_length = vec_len(ik);
9824 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9825 mp->crypto_key_length = sizeof(mp->crypto_key);
9827 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9828 mp->integrity_key_length = sizeof(mp->integrity_key);
9830 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9831 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9834 if (is_tunnel_ipv6) {
9835 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9836 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9838 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9839 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9847 clib_warning ("unsupported (no dpdk)");
9853 api_ipsec_sa_set_key (vat_main_t * vam)
9856 unformat_input_t * i = vam->input;
9857 vl_api_ipsec_sa_set_key_t *mp;
9860 u8 * ck = 0, * ik = 0;
9862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9863 if (unformat (i, "sa_id %d", &sa_id))
9865 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9867 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9870 clib_warning ("parse error '%U'", format_unformat_error, i);
9875 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9877 mp->sa_id = ntohl(sa_id);
9878 mp->crypto_key_length = vec_len(ck);
9879 mp->integrity_key_length = vec_len(ik);
9881 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9882 mp->crypto_key_length = sizeof(mp->crypto_key);
9884 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9885 mp->integrity_key_length = sizeof(mp->integrity_key);
9887 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9888 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9894 clib_warning ("unsupported (no dpdk)");
9900 api_ikev2_profile_add_del (vat_main_t * vam)
9903 unformat_input_t * i = vam->input;
9904 vl_api_ikev2_profile_add_del_t * mp;
9909 const char * valid_chars = "a-zA-Z0-9_";
9911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9912 if (unformat (i, "del"))
9914 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9917 errmsg ("parse error '%U'", format_unformat_error, i);
9922 if (!vec_len (name)) {
9923 errmsg ("profile name must be specified");
9927 if (vec_len (name) > 64) {
9928 errmsg ("profile name too long");
9932 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9934 clib_memcpy(mp->name, name, vec_len (name));
9935 mp->is_add = is_add;
9942 clib_warning ("unsupported (no dpdk)");
9948 api_ikev2_profile_set_auth (vat_main_t * vam)
9951 unformat_input_t * i = vam->input;
9952 vl_api_ikev2_profile_set_auth_t * mp;
9956 u32 auth_method = 0;
9959 const char * valid_chars = "a-zA-Z0-9_";
9961 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9962 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9964 else if (unformat (i, "auth_method %U",
9965 unformat_ikev2_auth_method, &auth_method))
9967 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9969 else if (unformat (i, "auth_data %v", &data))
9972 errmsg ("parse error '%U'", format_unformat_error, i);
9977 if (!vec_len (name)) {
9978 errmsg ("profile name must be specified");
9982 if (vec_len (name) > 64) {
9983 errmsg ("profile name too long");
9987 if (!vec_len(data)) {
9988 errmsg ("auth_data must be specified");
9993 errmsg ("auth_method must be specified");
9997 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9999 mp->is_hex = is_hex;
10000 mp->auth_method = (u8) auth_method;
10001 mp->data_len = vec_len (data);
10002 clib_memcpy (mp->name, name, vec_len (name));
10003 clib_memcpy (mp->data, data, vec_len (data));
10011 clib_warning ("unsupported (no dpdk)");
10017 api_ikev2_profile_set_id (vat_main_t * vam)
10020 unformat_input_t * i = vam->input;
10021 vl_api_ikev2_profile_set_id_t * mp;
10029 const char * valid_chars = "a-zA-Z0-9_";
10031 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10032 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10033 vec_add1 (name, 0);
10034 else if (unformat (i, "id_type %U",
10035 unformat_ikev2_id_type, &id_type))
10037 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
10039 data = vec_new(u8, 4);
10040 clib_memcpy(data, ip4.as_u8, 4);
10042 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
10044 else if (unformat (i, "id_data %v", &data))
10046 else if (unformat (i, "local"))
10048 else if (unformat (i, "remote"))
10051 errmsg ("parse error '%U'", format_unformat_error, i);
10056 if (!vec_len (name)) {
10057 errmsg ("profile name must be specified");
10061 if (vec_len (name) > 64) {
10062 errmsg ("profile name too long");
10066 if (!vec_len(data)) {
10067 errmsg ("id_data must be specified");
10072 errmsg ("id_type must be specified");
10076 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
10078 mp->is_local = is_local;
10079 mp->id_type = (u8) id_type;
10080 mp->data_len = vec_len (data);
10081 clib_memcpy (mp->name, name, vec_len (name));
10082 clib_memcpy (mp->data, data, vec_len (data));
10090 clib_warning ("unsupported (no dpdk)");
10096 api_ikev2_profile_set_ts (vat_main_t * vam)
10099 unformat_input_t * i = vam->input;
10100 vl_api_ikev2_profile_set_ts_t * mp;
10104 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
10105 ip4_address_t start_addr, end_addr;
10107 const char * valid_chars = "a-zA-Z0-9_";
10109 start_addr.as_u32 = 0;
10110 end_addr.as_u32 = (u32) ~0;
10112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10113 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10114 vec_add1 (name, 0);
10115 else if (unformat (i, "protocol %d", &proto))
10117 else if (unformat (i, "start_port %d", &start_port))
10119 else if (unformat (i, "end_port %d", &end_port))
10121 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
10123 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
10125 else if (unformat (i, "local"))
10127 else if (unformat (i, "remote"))
10130 errmsg ("parse error '%U'", format_unformat_error, i);
10135 if (!vec_len (name)) {
10136 errmsg ("profile name must be specified");
10140 if (vec_len (name) > 64) {
10141 errmsg ("profile name too long");
10145 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
10147 mp->is_local = is_local;
10148 mp->proto = (u8) proto;
10149 mp->start_port = (u16) start_port;
10150 mp->end_port = (u16) end_port;
10151 mp->start_addr = start_addr.as_u32;
10152 mp->end_addr = end_addr.as_u32;
10153 clib_memcpy (mp->name, name, vec_len (name));
10160 clib_warning ("unsupported (no dpdk)");
10166 api_ikev2_set_local_key (vat_main_t * vam)
10169 unformat_input_t * i = vam->input;
10170 vl_api_ikev2_set_local_key_t * mp;
10174 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10175 if (unformat (i, "file %v", &file))
10176 vec_add1 (file, 0);
10178 errmsg ("parse error '%U'", format_unformat_error, i);
10183 if (!vec_len (file)) {
10184 errmsg ("RSA key file must be specified");
10188 if (vec_len (file) > 256) {
10189 errmsg ("file name too long");
10193 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
10195 clib_memcpy (mp->key_file, file, vec_len (file));
10202 clib_warning ("unsupported (no dpdk)");
10210 static int api_map_add_domain (vat_main_t * vam)
10212 unformat_input_t *i = vam->input;
10213 vl_api_map_add_domain_t *mp;
10216 ip4_address_t ip4_prefix;
10217 ip6_address_t ip6_prefix;
10218 ip6_address_t ip6_src;
10219 u32 num_m_args = 0;
10220 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
10222 u8 is_translation = 0;
10224 u8 ip6_src_len = 128;
10226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10227 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
10228 &ip4_prefix, &ip4_prefix_len))
10230 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
10231 &ip6_prefix, &ip6_prefix_len))
10233 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
10235 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
10237 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
10239 else if (unformat (i, "psid-offset %d", &psid_offset))
10241 else if (unformat (i, "psid-len %d", &psid_length))
10243 else if (unformat (i, "mtu %d", &mtu))
10245 else if (unformat (i, "map-t"))
10246 is_translation = 1;
10248 clib_warning ("parse error '%U'", format_unformat_error, i);
10253 if (num_m_args != 6) {
10254 errmsg("mandatory argument(s) missing\n");
10258 /* Construct the API message */
10259 M(MAP_ADD_DOMAIN, map_add_domain);
10261 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
10262 mp->ip4_prefix_len = ip4_prefix_len;
10264 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
10265 mp->ip6_prefix_len = ip6_prefix_len;
10267 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
10268 mp->ip6_src_prefix_len = ip6_src_len;
10270 mp->ea_bits_len = ea_bits_len;
10271 mp->psid_offset = psid_offset;
10272 mp->psid_length = psid_length;
10273 mp->is_translation = is_translation;
10274 mp->mtu = htons(mtu);
10279 /* Wait for a reply, return good/bad news */
10283 static int api_map_del_domain (vat_main_t * vam)
10285 unformat_input_t *i = vam->input;
10286 vl_api_map_del_domain_t *mp;
10289 u32 num_m_args = 0;
10292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10293 if (unformat (i, "index %d", &index))
10296 clib_warning ("parse error '%U'", format_unformat_error, i);
10301 if (num_m_args != 1) {
10302 errmsg("mandatory argument(s) missing\n");
10306 /* Construct the API message */
10307 M(MAP_DEL_DOMAIN, map_del_domain);
10309 mp->index = ntohl(index);
10314 /* Wait for a reply, return good/bad news */
10318 static int api_map_add_del_rule (vat_main_t * vam)
10320 unformat_input_t *i = vam->input;
10321 vl_api_map_add_del_rule_t *mp;
10324 ip6_address_t ip6_dst;
10325 u32 num_m_args = 0, index, psid;
10327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10328 if (unformat (i, "index %d", &index))
10330 else if (unformat (i, "psid %d", &psid))
10332 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
10334 else if (unformat (i, "del")) {
10337 clib_warning ("parse error '%U'", format_unformat_error, i);
10342 /* Construct the API message */
10343 M(MAP_ADD_DEL_RULE, map_add_del_rule);
10345 mp->index = ntohl(index);
10346 mp->is_add = is_add;
10347 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
10348 mp->psid = ntohs(psid);
10353 /* Wait for a reply, return good/bad news */
10357 static int api_map_domain_dump (vat_main_t * vam)
10359 vl_api_map_domain_dump_t *mp;
10362 /* Construct the API message */
10363 M(MAP_DOMAIN_DUMP, map_domain_dump);
10368 /* Use a control ping for synchronization */
10370 vl_api_control_ping_t * mp;
10371 M(CONTROL_PING, control_ping);
10377 static int api_map_rule_dump (vat_main_t * vam)
10379 unformat_input_t *i = vam->input;
10380 vl_api_map_rule_dump_t *mp;
10382 u32 domain_index = ~0;
10384 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10385 if (unformat (i, "index %u", &domain_index))
10391 if (domain_index == ~0) {
10392 clib_warning("parse error: domain index expected");
10396 /* Construct the API message */
10397 M(MAP_RULE_DUMP, map_rule_dump);
10399 mp->domain_index = htonl(domain_index);
10404 /* Use a control ping for synchronization */
10406 vl_api_control_ping_t * mp;
10407 M(CONTROL_PING, control_ping);
10413 static void vl_api_map_add_domain_reply_t_handler
10414 (vl_api_map_add_domain_reply_t * mp)
10416 vat_main_t * vam = &vat_main;
10417 i32 retval = ntohl(mp->retval);
10419 if (vam->async_mode) {
10420 vam->async_errors += (retval < 0);
10422 vam->retval = retval;
10423 vam->result_ready = 1;
10427 static void vl_api_map_add_domain_reply_t_handler_json
10428 (vl_api_map_add_domain_reply_t * mp)
10430 vat_main_t * vam = &vat_main;
10431 vat_json_node_t node;
10433 vat_json_init_object(&node);
10434 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
10435 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
10437 vat_json_print(vam->ofp, &node);
10438 vat_json_free(&node);
10440 vam->retval = ntohl(mp->retval);
10441 vam->result_ready = 1;
10445 api_get_first_msg_id (vat_main_t * vam)
10447 vl_api_get_first_msg_id_t * mp;
10449 unformat_input_t * i = vam->input;
10453 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10454 if (unformat (i, "client %s", &name))
10460 if (name_set == 0) {
10461 errmsg ("missing client name\n");
10464 vec_add1 (name, 0);
10466 if (vec_len (name) > 63) {
10467 errmsg ("client name too long\n");
10471 M(GET_FIRST_MSG_ID, get_first_msg_id);
10472 clib_memcpy (mp->name, name, vec_len(name));
10478 static int api_cop_interface_enable_disable (vat_main_t * vam)
10480 unformat_input_t * line_input = vam->input;
10481 vl_api_cop_interface_enable_disable_t * mp;
10483 u32 sw_if_index = ~0;
10484 u8 enable_disable = 1;
10486 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10487 if (unformat (line_input, "disable"))
10488 enable_disable = 0;
10489 if (unformat (line_input, "enable"))
10490 enable_disable = 1;
10491 else if (unformat (line_input, "%U", unformat_sw_if_index,
10492 vam, &sw_if_index))
10494 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10500 if (sw_if_index == ~0) {
10501 errmsg ("missing interface name or sw_if_index\n");
10505 /* Construct the API message */
10506 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
10507 mp->sw_if_index = ntohl(sw_if_index);
10508 mp->enable_disable = enable_disable;
10512 /* Wait for the reply */
10516 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
10518 unformat_input_t * line_input = vam->input;
10519 vl_api_cop_whitelist_enable_disable_t * mp;
10521 u32 sw_if_index = ~0;
10522 u8 ip4=0, ip6=0, default_cop=0;
10525 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10526 if (unformat (line_input, "ip4"))
10528 else if (unformat (line_input, "ip6"))
10530 else if (unformat (line_input, "default"))
10532 else if (unformat (line_input, "%U", unformat_sw_if_index,
10533 vam, &sw_if_index))
10535 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10537 else if (unformat (line_input, "fib-id %d", &fib_id))
10543 if (sw_if_index == ~0) {
10544 errmsg ("missing interface name or sw_if_index\n");
10548 /* Construct the API message */
10549 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
10550 mp->sw_if_index = ntohl(sw_if_index);
10551 mp->fib_id = ntohl(fib_id);
10554 mp->default_cop = default_cop;
10558 /* Wait for the reply */
10562 static int api_get_node_graph (vat_main_t * vam)
10564 vl_api_get_node_graph_t * mp;
10567 M(GET_NODE_GRAPH, get_node_graph);
10571 /* Wait for the reply */
10575 /** Used for transferring locators via VPP API */
10576 typedef CLIB_PACKED(struct
10578 u32 sw_if_index; /**< locator sw_if_index */
10579 u8 priority; /**< locator priority */
10580 u8 weight; /**< locator weight */
10584 api_lisp_add_del_locator_set(vat_main_t * vam)
10586 unformat_input_t * input = vam->input;
10587 vl_api_lisp_add_del_locator_set_t *mp;
10590 u8 *locator_set_name = NULL;
10591 u8 locator_set_name_set = 0;
10592 ls_locator_t locator, * locators = 0;
10593 u32 sw_if_index, priority, weight;
10595 /* Parse args required to build the message */
10596 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10597 if (unformat(input, "del")) {
10599 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10600 locator_set_name_set = 1;
10601 } else if (unformat(input, "sw_if_index %u p %u w %u",
10602 &sw_if_index, &priority, &weight)) {
10603 locator.sw_if_index = htonl(sw_if_index);
10604 locator.priority = priority;
10605 locator.weight = weight;
10606 vec_add1(locators, locator);
10607 } else if (unformat(input, "iface %U p %u w %u", unformat_sw_if_index,
10608 vam, &sw_if_index, &priority, &weight)) {
10609 locator.sw_if_index = htonl(sw_if_index);
10610 locator.priority = priority;
10611 locator.weight = weight;
10612 vec_add1(locators, locator);
10617 if (locator_set_name_set == 0) {
10618 errmsg ("missing locator-set name");
10619 vec_free(locators);
10623 if (vec_len(locator_set_name) > 64) {
10624 errmsg ("locator-set name too long\n");
10625 vec_free(locator_set_name);
10626 vec_free(locators);
10629 vec_add1(locator_set_name, 0);
10631 /* Construct the API message */
10632 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
10634 mp->is_add = is_add;
10635 clib_memcpy(mp->locator_set_name, locator_set_name,
10636 vec_len(locator_set_name));
10637 vec_free(locator_set_name);
10639 mp->locator_num = vec_len (locators);
10640 clib_memcpy (mp->locators, locators,
10641 (sizeof (ls_locator_t) * vec_len (locators)));
10642 vec_free (locators);
10647 /* Wait for a reply... */
10655 api_lisp_add_del_locator(vat_main_t * vam)
10657 unformat_input_t * input = vam->input;
10658 vl_api_lisp_add_del_locator_t *mp;
10660 u32 tmp_if_index = ~0;
10661 u32 sw_if_index = ~0;
10662 u8 sw_if_index_set = 0;
10663 u8 sw_if_index_if_name_set = 0;
10665 u8 priority_set = 0;
10669 u8 *locator_set_name = NULL;
10670 u8 locator_set_name_set = 0;
10672 /* Parse args required to build the message */
10673 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10674 if (unformat(input, "del")) {
10676 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10677 locator_set_name_set = 1;
10678 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
10680 sw_if_index_if_name_set = 1;
10681 sw_if_index = tmp_if_index;
10682 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
10683 sw_if_index_set = 1;
10684 sw_if_index = tmp_if_index;
10685 } else if (unformat(input, "p %d", &priority)) {
10687 } else if (unformat(input, "w %d", &weight)) {
10693 if (locator_set_name_set == 0) {
10694 errmsg ("missing locator-set name");
10698 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
10699 errmsg ("missing sw_if_index");
10700 vec_free(locator_set_name);
10704 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
10705 errmsg ("cannot use both params interface name and sw_if_index");
10706 vec_free(locator_set_name);
10710 if (priority_set == 0) {
10711 errmsg ("missing locator-set priority\n");
10712 vec_free(locator_set_name);
10716 if (weight_set == 0) {
10717 errmsg ("missing locator-set weight\n");
10718 vec_free(locator_set_name);
10722 if (vec_len(locator_set_name) > 64) {
10723 errmsg ("locator-set name too long\n");
10724 vec_free(locator_set_name);
10727 vec_add1(locator_set_name, 0);
10729 /* Construct the API message */
10730 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
10732 mp->is_add = is_add;
10733 mp->sw_if_index = ntohl(sw_if_index);
10734 mp->priority = priority;
10735 mp->weight = weight;
10736 clib_memcpy(mp->locator_set_name, locator_set_name,
10737 vec_len(locator_set_name));
10738 vec_free(locator_set_name);
10743 /* Wait for a reply... */
10751 api_lisp_add_del_local_eid(vat_main_t * vam)
10753 unformat_input_t * input = vam->input;
10754 vl_api_lisp_add_del_local_eid_t *mp;
10759 u8 eid_type = (u8)~0;
10760 ip4_address_t eidv4;
10761 ip6_address_t eidv6;
10763 u32 tmp_eid_lenght = ~0;
10764 u8 eid_lenght = ~0;
10765 u8 *locator_set_name = NULL;
10766 u8 locator_set_name_set = 0;
10769 /* Parse args required to build the message */
10770 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10771 if (unformat(input, "del")) {
10773 } else if (unformat(input, "vni %d", &vni)) {
10775 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10776 &eidv4, &tmp_eid_lenght)) {
10777 eid_lenght = tmp_eid_lenght;
10779 eid_type = 0; /* ipv4 type */
10780 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10781 &eidv6, &tmp_eid_lenght)) {
10782 eid_lenght = tmp_eid_lenght;
10784 eid_type = 1; /* ipv6 type */
10785 } else if (unformat(input, "eid %U", unformat_ethernet_address, mac)) {
10786 eid_type = 2; /* mac type */
10787 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10788 locator_set_name_set = 1;
10793 if (locator_set_name_set == 0) {
10794 errmsg ("missing locator-set name\n");
10798 if ((u8)~0 == eid_type) {
10799 errmsg ("EID address not set!");
10800 vec_free(locator_set_name);
10804 if (vec_len(locator_set_name) > 64) {
10805 errmsg ("locator-set name too long\n");
10806 vec_free(locator_set_name);
10809 vec_add1(locator_set_name, 0);
10811 if (eidv4_set && eidv6_set) {
10812 errmsg ("both eid v4 and v6 addresses set\n");
10813 vec_free(locator_set_name);
10817 if (eidv4_set && eid_lenght > 32) {
10818 errmsg ("eid prefix to big\n");
10819 vec_free(locator_set_name);
10823 if (eidv6_set && eid_lenght > 128) {
10824 errmsg ("eid prefix to big\n");
10825 vec_free(locator_set_name);
10829 /* Construct the API message */
10830 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
10832 mp->is_add = is_add;
10833 switch (eid_type) {
10835 clib_memcpy (mp->eid, &eidv4, sizeof(eidv4));
10838 clib_memcpy (mp->eid, &eidv6, sizeof(eidv6));
10841 clib_memcpy (mp->eid, mac, 6);
10844 mp->eid_type = eid_type;
10845 mp->prefix_len = eid_lenght;
10846 mp->vni = clib_host_to_net_u32(vni);
10847 clib_memcpy(mp->locator_set_name, locator_set_name,
10848 vec_len(locator_set_name));
10849 vec_free(locator_set_name);
10854 /* Wait for a reply... */
10862 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
10864 unformat_input_t * input = vam->input;
10865 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10868 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
10869 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
10870 ip4_address_t eidv4, slocv4, dlocv4;
10871 ip6_address_t eidv6, slocv6, dlocv6;
10872 u32 tmp_eid_lenght = ~0;
10873 u8 eid_lenght = ~0;
10875 /* Parse args required to build the message */
10876 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10877 if (unformat(input, "del")) {
10879 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10880 &eidv4, &tmp_eid_lenght)) {
10881 eid_lenght = tmp_eid_lenght;
10883 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10884 &eidv6, &tmp_eid_lenght)) {
10885 eid_lenght = tmp_eid_lenght;
10887 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10889 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10891 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10893 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10899 if (eidv4_set && eidv6_set) {
10900 errmsg ("both eid v4 and v6 addresses set\n");
10904 if (!eidv4_set && !eidv6_set) {
10905 errmsg ("eid addresses not set\n");
10909 if (slocv4_set && slocv6_set) {
10910 errmsg ("both source v4 and v6 addresses set\n");
10914 if (!slocv4_set && !slocv6_set) {
10915 errmsg ("source addresses not set\n");
10919 if (dlocv4_set && dlocv6_set) {
10920 errmsg ("both destination v4 and v6 addresses set\n");
10924 if (dlocv4_set && dlocv6_set) {
10925 errmsg ("destination addresses not set\n");
10929 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10930 errmsg ("mixing type of source and destination address\n");
10934 /* Construct the API message */
10935 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10937 mp->is_add = is_add;
10939 mp->eid_is_ipv6 = 1;
10940 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10942 mp->eid_is_ipv6 = 0;
10943 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10945 mp->eid_prefix_len = eid_lenght;
10947 mp->address_is_ipv6 = 1;
10948 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10949 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10951 mp->address_is_ipv6 = 0;
10952 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10953 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10959 /* Wait for a reply... */
10967 api_lisp_add_del_map_resolver(vat_main_t * vam)
10969 unformat_input_t * input = vam->input;
10970 vl_api_lisp_add_del_map_resolver_t *mp;
10975 ip4_address_t ipv4;
10976 ip6_address_t ipv6;
10978 /* Parse args required to build the message */
10979 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10980 if (unformat(input, "del")) {
10982 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10984 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10990 if (ipv4_set && ipv6_set) {
10991 errmsg ("both eid v4 and v6 addresses set\n");
10995 if (!ipv4_set && !ipv6_set) {
10996 errmsg ("eid addresses not set\n");
11000 /* Construct the API message */
11001 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
11003 mp->is_add = is_add;
11006 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
11009 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
11015 /* Wait for a reply... */
11023 api_lisp_gpe_enable_disable (vat_main_t * vam)
11025 unformat_input_t * input = vam->input;
11026 vl_api_lisp_gpe_enable_disable_t *mp;
11031 /* Parse args required to build the message */
11032 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11033 if (unformat(input, "enable")) {
11036 } else if (unformat(input, "disable")) {
11044 errmsg("Value not set\n");
11048 /* Construct the API message */
11049 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
11056 /* Wait for a reply... */
11064 api_lisp_enable_disable (vat_main_t * vam)
11066 unformat_input_t * input = vam->input;
11067 vl_api_lisp_enable_disable_t *mp;
11072 /* Parse args required to build the message */
11073 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11075 if (unformat (input, "enable"))
11080 else if (unformat (input, "disable"))
11090 errmsg ("Value not set\n");
11094 /* Construct the API message */
11095 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
11102 /* Wait for a reply... */
11109 /** Used for transferring locators via VPP API */
11110 typedef CLIB_PACKED(struct
11112 u8 is_ip4; /**< is locator an IPv4 address? */
11113 u8 priority; /**< locator priority */
11114 u8 weight; /**< locator weight */
11115 u8 addr[16]; /**< IPv4/IPv6 address */
11119 * Enable/disable LISP proxy ITR.
11121 * @param vam vpp API test context
11122 * @return return code
11125 api_lisp_pitr_set_locator_set (vat_main_t * vam)
11128 u8 ls_name_set = 0;
11129 unformat_input_t * input = vam->input;
11130 vl_api_lisp_pitr_set_locator_set_t * mp;
11134 /* Parse args required to build the message */
11135 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11137 if (unformat (input, "del"))
11139 else if (unformat (input, "locator-set %s", &ls_name))
11143 errmsg ("parse error '%U'", format_unformat_error, input);
11150 errmsg ("locator-set name not set!");
11154 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
11156 mp->is_add = is_add;
11157 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
11158 vec_free (ls_name);
11163 /* wait for reply */
11171 api_show_lisp_pitr (vat_main_t * vam)
11173 vl_api_show_lisp_pitr_t *mp;
11176 if (!vam->json_output) {
11177 fformat(vam->ofp, "%=20s\n",
11181 M(SHOW_LISP_PITR, show_lisp_pitr);
11185 /* Wait for a reply... */
11193 * Add/delete mapping between vni and vrf
11196 api_lisp_eid_table_add_del_map (vat_main_t * vam)
11199 unformat_input_t * input = vam->input;
11200 vl_api_lisp_eid_table_add_del_map_t *mp;
11201 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
11202 u32 vni, vrf, bd_index;
11204 /* Parse args required to build the message */
11205 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11207 if (unformat (input, "del"))
11209 else if (unformat(input, "vrf %d", &vrf))
11211 else if (unformat(input, "bd_index %d", &bd_index))
11213 else if (unformat(input, "vni %d", &vni))
11219 if (!vni_set || (!vrf_set && !bd_index_set))
11221 errmsg ("missing arguments!");
11225 M(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
11227 mp->is_add = is_add;
11228 mp->vni = htonl (vni);
11229 mp->dp_table = htonl (vrf);
11230 mp->is_l2 = bd_index_set;
11235 /* wait for reply */
11243 * Add/del remote mapping to/from LISP control plane
11245 * @param vam vpp API test context
11246 * @return return code
11249 api_lisp_add_del_remote_mapping (vat_main_t * vam)
11251 unformat_input_t * input = vam->input;
11252 vl_api_lisp_add_del_remote_mapping_t *mp;
11255 //TODO: seid need remove
11256 ip4_address_t seid4, eid4, rloc4;
11257 ip6_address_t seid6, eid6, rloc6;
11258 u8 eid_mac[6] = {0};
11259 u8 seid_mac[6] = {0};
11261 u32 eid_len = 0, len;
11262 u8 is_add = 1, del_all = 0;
11263 u32 action = ~0, p, w;
11264 rloc_t * rlocs = 0, rloc, * curr_rloc = 0;
11268 /* Parse args required to build the message */
11269 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11270 if (unformat(input, "del-all")) {
11272 } else if (unformat(input, "del")) {
11274 } else if (unformat(input, "add")) {
11276 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
11278 eid_type = 0; /* ipv4 */
11280 clib_warning ("Deid prefix length to big, %d!", len);
11284 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
11286 eid_type = 1; /* ipv6 */
11288 clib_warning ("Deid prefix length to big, %d!", len);
11292 } else if (unformat(input, "deid %U", unformat_ethernet_address,
11294 eid_type = 2; /* mac */
11295 //TODO: Need remove, but first must be remove from CSIT test
11296 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
11298 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11301 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11304 } else if (unformat(input, "vni %d", &vni)) {
11306 } else if (unformat(input, "p %d w %d", &p, &w)) {
11308 errmsg ("No RLOC configured for setting priority/weight!");
11311 curr_rloc->priority = p;
11312 curr_rloc->weight = w;
11313 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
11315 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
11316 vec_add1 (rlocs, rloc);
11317 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11318 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
11320 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
11321 vec_add1 (rlocs, rloc);
11322 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11323 } else if (unformat(input, "action %d", &action)) {
11326 clib_warning ("parse error '%U'", format_unformat_error, input);
11331 if ((u8)~0 == eid_type) {
11332 errmsg ("missing params!");
11336 if (is_add && (~0 == action)
11337 && 0 == vec_len (rlocs)) {
11338 errmsg ("no action set for negative map-reply!");
11342 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
11343 mp->is_add = is_add;
11344 mp->vni = htonl (vni);
11345 mp->action = (u8) action;
11346 mp->eid_len = eid_len;
11347 mp->del_all = del_all;
11348 mp->eid_type = eid_type;
11350 switch (mp->eid_type) {
11352 clib_memcpy (mp->eid, &eid4, sizeof (eid4));
11355 clib_memcpy (mp->eid, &eid6, sizeof (eid6));
11358 clib_memcpy (mp->eid, eid_mac, 6);
11361 errmsg ("unknown EID type %d!", mp->eid_type);
11365 mp->rloc_num = vec_len (rlocs);
11366 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
11372 /* Wait for a reply... */
11380 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
11381 * forwarding entries in data-plane accordingly.
11383 * @param vam vpp API test context
11384 * @return return code
11387 api_lisp_add_del_adjacency (vat_main_t * vam)
11389 unformat_input_t * input = vam->input;
11390 vl_api_lisp_add_del_adjacency_t *mp;
11393 ip4_address_t seid4, deid4;
11394 ip6_address_t seid6, deid6;
11395 u8 deid_mac[6] = {0};
11396 u8 seid_mac[6] = {0};
11397 u8 deid_type, seid_type;
11398 u32 seid_len = 0, deid_len = 0, len;
11401 seid_type = deid_type = (u8)~0;
11403 /* Parse args required to build the message */
11404 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11405 if (unformat(input, "del")) {
11407 } else if (unformat(input, "add")) {
11409 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
11411 deid_type = 0; /* ipv4 */
11413 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
11415 deid_type = 1; /* ipv6 */
11417 } else if (unformat(input, "deid %U", unformat_ethernet_address,
11419 deid_type = 2; /* mac */
11420 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
11422 seid_type = 0; /* ipv4 */
11424 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11426 seid_type = 1; /* ipv6 */
11428 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11430 seid_type = 2; /* mac */
11431 } else if (unformat(input, "vni %d", &vni)) {
11434 errmsg ("parse error '%U'", format_unformat_error, input);
11439 if ((u8)~0 == deid_type) {
11440 errmsg ("missing params!");
11444 if (seid_type != deid_type) {
11445 errmsg ("source and destination EIDs are of different types!");
11449 M(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
11450 mp->is_add = is_add;
11451 mp->vni = htonl (vni);
11452 mp->seid_len = seid_len;
11453 mp->deid_len = deid_len;
11454 mp->eid_type = deid_type;
11456 switch (mp->eid_type) {
11458 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
11459 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
11462 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
11463 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
11466 clib_memcpy (mp->seid, seid_mac, 6);
11467 clib_memcpy (mp->deid, deid_mac, 6);
11470 errmsg ("unknown EID type %d!", mp->eid_type);
11477 /* Wait for a reply... */
11485 api_lisp_gpe_add_del_iface(vat_main_t * vam)
11487 unformat_input_t * input = vam->input;
11488 vl_api_lisp_gpe_add_del_iface_t *mp;
11494 /* Parse args required to build the message */
11495 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11496 if (unformat(input, "up")) {
11499 } else if (unformat(input, "down")) {
11502 } else if (unformat(input, "table_id %d", &table_id)) {
11504 } else if (unformat(input, "vni %d", &vni)) {
11511 errmsg("Value not set\n");
11515 /* Construct the API message */
11516 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
11518 mp->is_add = is_add;
11519 mp->table_id = table_id;
11525 /* Wait for a reply... */
11533 * Add/del map request itr rlocs from LISP control plane and updates
11535 * @param vam vpp API test context
11536 * @return return code
11539 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
11541 unformat_input_t * input = vam->input;
11542 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
11544 u8 *locator_set_name = 0;
11545 u8 locator_set_name_set = 0;
11548 /* Parse args required to build the message */
11549 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11550 if (unformat(input, "del")) {
11552 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
11553 locator_set_name_set = 1;
11555 clib_warning ("parse error '%U'", format_unformat_error, input);
11560 if (is_add && !locator_set_name_set) {
11561 errmsg ("itr-rloc is not set!");
11565 if (is_add && vec_len(locator_set_name) > 64) {
11566 errmsg ("itr-rloc locator-set name too long\n");
11567 vec_free(locator_set_name);
11571 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
11572 mp->is_add = is_add;
11574 clib_memcpy (mp->locator_set_name , locator_set_name,
11575 vec_len(locator_set_name));
11577 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
11579 vec_free (locator_set_name);
11584 /* Wait for a reply... */
11592 lisp_locator_dump_send_msg(vat_main_t * vam, u32 locator_set_index, u8 filter)
11594 vl_api_lisp_locator_dump_t *mp;
11597 M(LISP_LOCATOR_DUMP, lisp_locator_dump);
11599 mp->locator_set_index = htonl(locator_set_index);
11600 mp->filter = filter;
11605 /* Use a control ping for synchronization */
11607 vl_api_noprint_control_ping_t * mp;
11608 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11611 /* Wait for a reply... */
11616 clean_locator_set_message(vat_main_t * vam)
11618 locator_set_msg_t * ls = 0;
11620 vec_foreach (ls, vam->locator_set_msg) {
11621 vec_free(ls->locator_set_name);
11624 vec_free(vam->locator_set_msg);
11628 print_locator_in_locator_set(vat_main_t * vam, u8 filter)
11630 locator_set_msg_t * ls;
11631 locator_msg_t * loc;
11633 int i = 0, ret = 0;
11635 vec_foreach(ls, vam->locator_set_msg) {
11636 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11638 vec_free(vam->locator_msg);
11639 clean_locator_set_message(vam);
11643 tmp_str = format(0, "%=20s%=16d%s", ls->locator_set_name,
11644 ls->locator_set_index,
11645 vec_len(vam->locator_msg) ? "" : "\n");
11647 vec_foreach(loc, vam->locator_msg) {
11649 tmp_str = format(tmp_str, "%=37s", " ");
11652 tmp_str = format(tmp_str, "%=16d%=16d%=16d\n",
11657 tmp_str = format(tmp_str, "%=16U%=16d%=16d\n",
11658 loc->is_ipv6 ? format_ip6_address :
11659 format_ip4_address,
11667 fformat(vam->ofp, "%s", tmp_str);
11669 vec_free(vam->locator_msg);
11672 clean_locator_set_message(vam);
11678 json_locator_in_locator_set(vat_main_t * vam, u8 filter)
11680 locator_set_msg_t * ls;
11681 locator_msg_t * loc;
11682 vat_json_node_t * node = NULL;
11683 vat_json_node_t * locator_array;
11684 vat_json_node_t * locator;
11685 struct in6_addr ip6;
11686 struct in_addr ip4;
11689 if (!vec_len(vam->locator_set_msg)) {
11690 /* just print [] */
11691 vat_json_init_array(&vam->json_tree);
11692 vat_json_print(vam->ofp, &vam->json_tree);
11693 vam->json_tree.type = VAT_JSON_NONE;
11697 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11698 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11699 vat_json_init_array(&vam->json_tree);
11702 vec_foreach(ls, vam->locator_set_msg) {
11703 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11705 vec_free(ls->locator_set_name);
11706 vec_free(vam->locator_msg);
11707 vec_free(vam->locator_set_msg);
11708 vat_json_free(&vam->json_tree);
11709 vam->json_tree.type = VAT_JSON_NONE;
11713 node = vat_json_array_add(&vam->json_tree);
11714 vat_json_init_object(node);
11716 vat_json_object_add_uint(node, "locator-set-index",
11717 ls->locator_set_index);
11718 vat_json_object_add_string_copy(node, "locator-set",
11719 ls->locator_set_name);
11720 locator_array = vat_json_object_add_list(node, "locator");
11721 vec_foreach(loc, vam->locator_msg) {
11722 locator = vat_json_array_add(locator_array);
11723 vat_json_init_object(locator);
11725 vat_json_object_add_uint(locator, "locator-index",
11728 if (loc->is_ipv6) {
11729 clib_memcpy(&ip6, loc->ip_address, sizeof(ip6));
11730 vat_json_object_add_ip6(locator, "locator", ip6);
11732 clib_memcpy(&ip4, loc->ip_address, sizeof(ip4));
11733 vat_json_object_add_ip4(locator, "locator", ip4);
11736 vat_json_object_add_uint(locator, "priority", loc->priority);
11737 vat_json_object_add_uint(locator, "weight", loc->weight);
11740 vec_free(ls->locator_set_name);
11741 vec_free(vam->locator_msg);
11744 vat_json_print(vam->ofp, &vam->json_tree);
11745 vat_json_free(&vam->json_tree);
11746 vam->json_tree.type = VAT_JSON_NONE;
11748 vec_free(vam->locator_set_msg);
11754 get_locator_set_index_from_msg(vat_main_t * vam, u8 * locator_set,
11755 u32 * locator_set_index)
11757 locator_set_msg_t * ls;
11760 * locator_set_index = ~0;
11762 if (!vec_len(vam->locator_set_msg)) {
11766 vec_foreach(ls, vam->locator_set_msg) {
11767 if (!strcmp((char *) locator_set, (char *) ls->locator_set_name)) {
11768 * locator_set_index = ls->locator_set_index;
11769 vec_free(vam->locator_set_msg);
11774 vec_free(vam->locator_set_msg);
11780 get_locator_set_index(vat_main_t * vam, u8 * locator_set,
11781 u32 * locator_set_index)
11783 vl_api_lisp_locator_set_dump_t *mp;
11786 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11790 /* Use a control ping for synchronization */
11792 vl_api_noprint_control_ping_t * mp;
11793 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11797 vam->noprint_msg = 1;
11798 /* Wait for a reply... */
11800 get_locator_set_index_from_msg(vam, locator_set, locator_set_index);
11801 vam->noprint_msg = 0;
11809 lisp_locator_dump(vat_main_t * vam, u32 locator_set_index, u8 * locator_set,
11816 if (!vam->json_output) {
11817 fformat(vam->ofp, "%=20s%=16s%=16s\n",
11818 "locator", "priority", "weight");
11822 ret = get_locator_set_index(vam, locator_set, &locator_set_index);
11825 if (!ret && ~0 == locator_set_index) {
11829 ret = lisp_locator_dump_send_msg(vam, locator_set_index, filter);
11835 lisp_locator_set_dump(vat_main_t * vam, u8 filter)
11837 vl_api_lisp_locator_set_dump_t *mp;
11840 if (!vam->json_output) {
11841 fformat(vam->ofp, "%=20s%=16s%=16s%=16s%=16s\n",
11842 "locator-set", "locator-set-index", "locator", "priority",
11846 vam->noprint_msg = 1;
11848 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11850 mp->filter = filter;
11855 /* Use a control ping for synchronization */
11857 vl_api_noprint_control_ping_t * mp;
11858 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11862 /* Wait for a reply... */
11864 if (vam->noprint_msg) {
11865 if (!vam->json_output) {
11866 print_locator_in_locator_set(vam, filter);
11868 json_locator_in_locator_set(vam, filter);
11872 vam->noprint_msg = 0;
11880 api_lisp_locator_set_dump(vat_main_t *vam)
11882 unformat_input_t * input = vam->input;
11883 vam->noprint_msg = 0;
11884 u32 locator_set_index = ~0;
11885 u8 locator_set_index_set = 0;
11886 u8 * locator_set = 0;
11887 u8 locator_set_set = 0;
11891 /* Parse args required to build the message */
11892 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11893 if (unformat(input, "locator-set-index %u", &locator_set_index)) {
11894 locator_set_index_set = 1;
11895 } else if (unformat(input, "locator-set %s", &locator_set)) {
11896 locator_set_set = 1;
11897 } else if (unformat(input, "local")) {
11899 } else if (unformat(input, "remote")) {
11906 if (locator_set_index_set && locator_set_set) {
11907 errmsg ("use only input parameter!\n");
11911 if (locator_set_index_set || locator_set_set) {
11912 ret = lisp_locator_dump(vam, locator_set_index, locator_set, filter);
11914 ret = lisp_locator_set_dump(vam, filter);
11917 vec_free(locator_set);
11923 api_lisp_eid_table_map_dump(vat_main_t *vam)
11925 vl_api_lisp_eid_table_map_dump_t *mp;
11928 if (!vam->json_output) {
11929 fformat (vam->ofp, "%=10s%=10s\n", "VNI", "VRF");
11932 M(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
11937 /* Use a control ping for synchronization */
11939 vl_api_control_ping_t * mp;
11940 M(CONTROL_PING, control_ping);
11943 /* Wait for a reply... */
11951 get_locator_set(vat_main_t * vam)
11953 vl_api_lisp_locator_set_dump_t *mp;
11956 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11960 /* Use a control ping for synchronization */
11962 vl_api_noprint_control_ping_t * mp;
11963 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11967 /* Wait for a reply... */
11975 format_eid_for_eid_table(vat_main_t *vam, u8 * str, eid_table_t * eid_table,
11978 u8 * (*format_eid)(u8 *, va_list *) = 0;
11980 ASSERT(vam != NULL);
11981 ASSERT(eid_table != NULL);
11987 switch (eid_table->eid_type)
11991 format_eid = (eid_table->eid_type ? format_ip6_address :
11992 format_ip4_address);
11993 str = format(0, "[%d] %U/%d",
11994 clib_net_to_host_u32 (eid_table->vni),
11995 format_eid, eid_table->eid, eid_table->eid_prefix_len);
11998 str = format(0, "[%d] %U",
11999 clib_net_to_host_u32 (eid_table->vni),
12000 format_ethernet_address, eid_table->eid);
12003 errmsg ("unknown EID type %d!", eid_table->eid_type);
12014 format_locator_set_for_eid_table(vat_main_t * vam, u8 * str,
12015 eid_table_t * eid_table)
12017 locator_set_msg_t * ls = 0;
12019 ASSERT(vam != NULL);
12020 ASSERT(eid_table != NULL);
12022 if (eid_table->is_local) {
12023 vec_foreach (ls, vam->locator_set_msg) {
12024 if (ls->locator_set_index == eid_table->locator_set_index) {
12025 str = format(0, "local(%s)", ls->locator_set_name);
12030 str = format(0, "local(N/A)");
12032 str = format(0, "remote");
12039 format_locator_for_eid_table(vat_main_t * vam, u8 * str,
12040 eid_table_t * eid_table)
12042 locator_msg_t * loc = 0;
12043 int first_line = 1;
12045 ASSERT(vam != NULL);
12046 ASSERT(eid_table != NULL);
12048 vec_foreach(loc, vam->locator_msg) {
12051 str = format(str, "%-55s%-d\n", " ", loc->sw_if_index);
12053 str = format(str, "%=55s%-U\n", " ",
12054 loc->is_ipv6 ? format_ip6_address :
12055 format_ip4_address,
12063 str = format(str, "%-30d%-20u%-u\n", loc->sw_if_index,
12064 eid_table->ttl, eid_table->authoritative);
12066 str = format(str, "%-30U%-20u%-u\n",
12067 loc->is_ipv6 ? format_ip6_address :
12068 format_ip4_address,
12069 loc->ip_address, eid_table->ttl,
12070 eid_table->authoritative);
12079 print_lisp_eid_table_dump(vat_main_t * vam)
12081 eid_table_t * eid_table = 0;
12082 u8 * tmp_str = 0, * tmp_str2 = 0;
12085 ASSERT(vam != NULL);
12087 ret = get_locator_set(vam);
12089 vec_free(vam->eid_tables);
12093 fformat(vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type", "locators",
12094 "ttl", "authoritative");
12096 vec_foreach(eid_table, vam->eid_tables) {
12097 ret = lisp_locator_dump_send_msg(vam, eid_table->locator_set_index, 0);
12099 vec_free(vam->locator_msg);
12100 clean_locator_set_message(vam);
12101 vec_free(vam->eid_tables);
12105 tmp_str2 = format_eid_for_eid_table(vam, tmp_str2, eid_table, &ret);
12107 vec_free(vam->locator_msg);
12108 clean_locator_set_message(vam);
12109 vec_free(vam->eid_tables);
12113 tmp_str = format(0, "%-35s", tmp_str2);
12114 vec_free(tmp_str2);
12116 tmp_str2 = format_locator_set_for_eid_table(vam, tmp_str2, eid_table);
12117 tmp_str = format(tmp_str, "%-20s", tmp_str2);
12118 vec_free(tmp_str2);
12120 tmp_str2 = format_locator_for_eid_table(vam, tmp_str2, eid_table);
12121 tmp_str = format(tmp_str, "%-s", tmp_str2);
12122 vec_free(tmp_str2);
12124 fformat(vam->ofp, "%s", tmp_str);
12126 vec_free(vam->locator_msg);
12129 clean_locator_set_message(vam);
12130 vec_free(vam->eid_tables);
12136 json_locator_set_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12137 eid_table_t * eid_table)
12139 locator_set_msg_t * ls = 0;
12142 ASSERT(vam != NULL);
12143 ASSERT(node != NULL);
12144 ASSERT(eid_table != NULL);
12146 if (eid_table->is_local) {
12147 vec_foreach (ls, vam->locator_set_msg) {
12148 if (ls->locator_set_index == eid_table->locator_set_index) {
12149 vat_json_object_add_string_copy(node, "locator-set",
12150 ls->locator_set_name);
12155 s = format(0, "N/A");
12157 vat_json_object_add_string_copy(node, "locator-set", s);
12160 s = format(0, "remote");
12162 vat_json_object_add_string_copy(node, "locator-set", s);
12168 json_eid_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12169 eid_table_t * eid_table)
12172 struct in6_addr ip6;
12173 struct in_addr ip4;
12175 ASSERT(vam != NULL);
12176 ASSERT(node != NULL);
12177 ASSERT(eid_table != NULL);
12179 switch (eid_table->eid_type)
12182 clib_memcpy(&ip4, eid_table->eid, sizeof(ip4));
12183 vat_json_object_add_ip4(node, "eid", ip4);
12184 vat_json_object_add_uint(node, "eid-prefix-len",
12185 eid_table->eid_prefix_len);
12188 clib_memcpy(&ip6, eid_table->eid, sizeof(ip6));
12189 vat_json_object_add_ip6(node, "eid", ip6);
12190 vat_json_object_add_uint(node, "eid-prefix-len",
12191 eid_table->eid_prefix_len);
12194 s = format (0, "%U", format_ethernet_address, eid_table->eid);
12196 vat_json_object_add_string_copy(node, "eid", s);
12200 errmsg ("unknown EID type %d!", eid_table->eid_type);
12208 json_locator_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12209 eid_table_t * eid_table)
12211 locator_msg_t * loc = 0;
12212 vat_json_node_t * locator_array = 0;
12213 vat_json_node_t * locator = 0;
12214 struct in6_addr ip6;
12215 struct in_addr ip4;
12217 ASSERT(vam != NULL);
12218 ASSERT(node != NULL);
12219 ASSERT(eid_table != NULL);
12221 locator_array = vat_json_object_add_list(node, "locator");
12222 vec_foreach(loc, vam->locator_msg) {
12223 locator = vat_json_array_add(locator_array);
12224 vat_json_init_object(locator);
12226 vat_json_object_add_uint(locator, "locator-index",
12229 if (loc->is_ipv6) {
12230 clib_memcpy(&ip6, loc->ip_address, sizeof(ip6));
12231 vat_json_object_add_ip6(locator, "locator", ip6);
12233 clib_memcpy(&ip4, loc->ip_address, sizeof(ip4));
12234 vat_json_object_add_ip4(locator, "locator", ip4);
12241 json_lisp_eid_table_dump(vat_main_t * vam)
12243 eid_table_t * eid_table;
12244 vat_json_node_t * node = 0;
12247 ASSERT(vam != NULL);
12249 ret = get_locator_set(vam);
12251 vec_free(vam->eid_tables);
12255 if (!vec_len(vam->eid_tables)) {
12256 /* just print [] */
12257 vat_json_init_array(&vam->json_tree);
12258 vat_json_print(vam->ofp, &vam->json_tree);
12259 vam->json_tree.type = VAT_JSON_NONE;
12263 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12264 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12265 vat_json_init_array(&vam->json_tree);
12268 vec_foreach(eid_table, vam->eid_tables) {
12269 ret = lisp_locator_dump_send_msg(vam, eid_table->locator_set_index, 0);
12271 vec_free(vam->locator_msg);
12272 vec_free(vam->eid_tables);
12273 clean_locator_set_message(vam);
12274 vat_json_free(&vam->json_tree);
12275 vam->json_tree.type = VAT_JSON_NONE;
12279 node = vat_json_array_add(&vam->json_tree);
12280 vat_json_init_object(node);
12282 vat_json_object_add_uint(node, "vni", eid_table->vni);
12284 json_locator_set_for_eid_table(vam, node, eid_table);
12285 ret = json_eid_for_eid_table(vam, node, eid_table);
12287 vec_free(vam->locator_msg);
12288 vec_free(vam->eid_tables);
12289 clean_locator_set_message(vam);
12290 vat_json_free(&vam->json_tree);
12291 vam->json_tree.type = VAT_JSON_NONE;
12295 json_locator_for_eid_table(vam, node, eid_table);
12297 vat_json_object_add_uint(node, "ttl", eid_table->ttl);
12298 vat_json_object_add_uint(node, "authoritative",
12299 eid_table->authoritative);
12301 vec_free(vam->locator_msg);
12304 vat_json_print(vam->ofp, &vam->json_tree);
12305 vat_json_free(&vam->json_tree);
12306 vam->json_tree.type = VAT_JSON_NONE;
12308 clean_locator_set_message(vam);
12309 vec_free(vam->eid_tables);
12315 api_lisp_eid_table_dump(vat_main_t *vam)
12317 unformat_input_t * i = vam->input;
12318 vl_api_lisp_eid_table_dump_t *mp;
12320 struct in_addr ip4;
12321 struct in6_addr ip6;
12323 u8 eid_type = ~0, eid_set = 0;
12324 u32 prefix_length = ~0, t, vni = 0;
12327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12328 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t)) {
12332 } else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t)) {
12336 } else if (unformat (i, "eid %U", unformat_ethernet_address, mac)) {
12339 } else if (unformat (i, "vni %d", &t)) {
12341 } else if (unformat (i, "local")) {
12343 } else if (unformat (i, "remote")) {
12346 errmsg ("parse error '%U'", format_unformat_error, i);
12351 M(LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
12353 mp->filter = filter;
12356 mp->vni = htonl (vni);
12357 mp->eid_type = eid_type;
12358 switch (eid_type) {
12360 mp->prefix_length = prefix_length;
12361 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
12364 mp->prefix_length = prefix_length;
12365 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
12368 clib_memcpy (mp->eid, mac, sizeof (mac));
12371 errmsg ("unknown EID type %d!", eid_type);
12376 vam->noprint_msg = 1;
12381 /* Use a control ping for synchronization */
12383 vl_api_noprint_control_ping_t * mp;
12384 M(NOPRINT_CONTROL_PING, noprint_control_ping);
12388 /* Wait for a reply... */
12390 if (vam->noprint_msg) {
12391 if (!vam->json_output) {
12392 vam->retval = print_lisp_eid_table_dump(vam);
12394 vam->retval = json_lisp_eid_table_dump(vam);
12398 vam->noprint_msg = 0;
12406 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
12408 vl_api_lisp_gpe_tunnel_dump_t *mp;
12411 if (!vam->json_output) {
12412 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
12413 "%=16s%=16s%=16s%=16s%=16s\n",
12414 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
12415 "Decap next", "Lisp version", "Flags", "Next protocol",
12416 "ver_res", "res", "iid");
12419 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
12423 /* Use a control ping for synchronization */
12425 vl_api_control_ping_t * mp;
12426 M(CONTROL_PING, control_ping);
12429 /* Wait for a reply... */
12437 api_lisp_map_resolver_dump(vat_main_t *vam)
12439 vl_api_lisp_map_resolver_dump_t *mp;
12442 if (!vam->json_output) {
12443 fformat(vam->ofp, "%=20s\n",
12447 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
12451 /* Use a control ping for synchronization */
12453 vl_api_control_ping_t * mp;
12454 M(CONTROL_PING, control_ping);
12457 /* Wait for a reply... */
12465 api_show_lisp_status(vat_main_t *vam)
12467 vl_api_show_lisp_status_t *mp;
12470 if (!vam->json_output) {
12471 fformat(vam->ofp, "%-20s%-16s\n",
12472 "lisp status", "locator-set");
12475 M(SHOW_LISP_STATUS, show_lisp_status);
12478 /* Wait for a reply... */
12486 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
12488 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
12491 if (!vam->json_output) {
12492 fformat(vam->ofp, "%=20s\n",
12496 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
12499 /* Wait for a reply... */
12507 api_af_packet_create (vat_main_t * vam)
12509 unformat_input_t * i = vam->input;
12510 vl_api_af_packet_create_t * mp;
12512 u8 * host_if_name = 0;
12514 u8 random_hw_addr = 1;
12516 memset (hw_addr, 0, sizeof (hw_addr));
12518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12519 if (unformat (i, "name %s", &host_if_name))
12520 vec_add1 (host_if_name, 0);
12521 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12522 random_hw_addr = 0;
12527 if (!vec_len (host_if_name)) {
12528 errmsg ("host-interface name must be specified");
12532 if (vec_len (host_if_name) > 64) {
12533 errmsg ("host-interface name too long");
12537 M(AF_PACKET_CREATE, af_packet_create);
12539 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12540 clib_memcpy (mp->hw_addr, hw_addr, 6);
12541 mp->use_random_hw_addr = random_hw_addr;
12542 vec_free (host_if_name);
12544 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
12550 api_af_packet_delete (vat_main_t * vam)
12552 unformat_input_t * i = vam->input;
12553 vl_api_af_packet_delete_t * mp;
12555 u8 * host_if_name = 0;
12557 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12558 if (unformat (i, "name %s", &host_if_name))
12559 vec_add1 (host_if_name, 0);
12564 if (!vec_len (host_if_name)) {
12565 errmsg ("host-interface name must be specified");
12569 if (vec_len (host_if_name) > 64) {
12570 errmsg ("host-interface name too long");
12574 M(AF_PACKET_DELETE, af_packet_delete);
12576 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12577 vec_free (host_if_name);
12585 api_policer_add_del (vat_main_t * vam)
12587 unformat_input_t * i = vam->input;
12588 vl_api_policer_add_del_t * mp;
12599 u8 color_aware = 0;
12600 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
12602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12603 if (unformat (i, "del"))
12605 else if (unformat (i, "name %s", &name))
12606 vec_add1 (name, 0);
12607 else if (unformat (i, "cir %u", &cir))
12609 else if (unformat (i, "eir %u", &eir))
12611 else if (unformat (i, "cb %u", &cb))
12613 else if (unformat (i, "eb %u", &eb))
12615 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
12618 else if (unformat (i, "round_type %U", unformat_policer_round_type,
12621 else if (unformat (i, "type %U", unformat_policer_type, &type))
12623 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
12626 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
12629 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
12632 else if (unformat (i, "color-aware"))
12638 if (!vec_len (name)) {
12639 errmsg ("policer name must be specified");
12643 if (vec_len (name) > 64) {
12644 errmsg ("policer name too long");
12648 M(POLICER_ADD_DEL, policer_add_del);
12650 clib_memcpy (mp->name, name, vec_len (name));
12652 mp->is_add = is_add;
12657 mp->rate_type = rate_type;
12658 mp->round_type = round_type;
12660 mp->conform_action_type = conform_action.action_type;
12661 mp->conform_dscp = conform_action.dscp;
12662 mp->exceed_action_type = exceed_action.action_type;
12663 mp->exceed_dscp = exceed_action.dscp;
12664 mp->violate_action_type = violate_action.action_type;
12665 mp->violate_dscp = violate_action.dscp;
12666 mp->color_aware = color_aware;
12674 api_policer_dump(vat_main_t *vam)
12676 unformat_input_t * i = vam->input;
12677 vl_api_policer_dump_t *mp;
12679 u8 *match_name = 0;
12680 u8 match_name_valid = 0;
12682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12683 if (unformat (i, "name %s", &match_name)) {
12684 vec_add1 (match_name, 0);
12685 match_name_valid = 1;
12690 M(POLICER_DUMP, policer_dump);
12691 mp->match_name_valid = match_name_valid;
12692 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
12693 vec_free (match_name);
12697 /* Use a control ping for synchronization */
12699 vl_api_control_ping_t * mp;
12700 M(CONTROL_PING, control_ping);
12703 /* Wait for a reply... */
12711 api_policer_classify_set_interface (vat_main_t * vam)
12713 unformat_input_t * i = vam->input;
12714 vl_api_policer_classify_set_interface_t *mp;
12717 int sw_if_index_set;
12718 u32 ip4_table_index = ~0;
12719 u32 ip6_table_index = ~0;
12720 u32 l2_table_index = ~0;
12723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12724 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
12725 sw_if_index_set = 1;
12726 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12727 sw_if_index_set = 1;
12728 else if (unformat (i, "del"))
12730 else if (unformat (i, "ip4-table %d", &ip4_table_index))
12732 else if (unformat (i, "ip6-table %d", &ip6_table_index))
12734 else if (unformat (i, "l2-table %d", &l2_table_index))
12737 clib_warning ("parse error '%U'", format_unformat_error, i);
12742 if (sw_if_index_set == 0) {
12743 errmsg ("missing interface name or sw_if_index\n");
12747 M(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
12749 mp->sw_if_index = ntohl(sw_if_index);
12750 mp->ip4_table_index = ntohl(ip4_table_index);
12751 mp->ip6_table_index = ntohl(ip6_table_index);
12752 mp->l2_table_index = ntohl(l2_table_index);
12753 mp->is_add = is_add;
12761 api_policer_classify_dump(vat_main_t *vam)
12763 unformat_input_t * i = vam->input;
12764 vl_api_policer_classify_dump_t *mp;
12766 u8 type = POLICER_CLASSIFY_N_TABLES;
12768 if (unformat (i, "type %U", unformat_classify_table_type, &type))
12771 errmsg ("classify table type must be specified\n");
12775 if (!vam->json_output) {
12776 fformat(vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
12779 M(POLICER_CLASSIFY_DUMP, policer_classify_dump);
12784 /* Use a control ping for synchronization */
12786 vl_api_control_ping_t * mp;
12787 M(CONTROL_PING, control_ping);
12790 /* Wait for a reply... */
12798 api_netmap_create (vat_main_t * vam)
12800 unformat_input_t * i = vam->input;
12801 vl_api_netmap_create_t * mp;
12805 u8 random_hw_addr = 1;
12809 memset (hw_addr, 0, sizeof (hw_addr));
12811 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12812 if (unformat (i, "name %s", &if_name))
12813 vec_add1 (if_name, 0);
12814 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12815 random_hw_addr = 0;
12816 else if (unformat (i, "pipe"))
12818 else if (unformat (i, "master"))
12820 else if (unformat (i, "slave"))
12826 if (!vec_len (if_name)) {
12827 errmsg ("interface name must be specified");
12831 if (vec_len (if_name) > 64) {
12832 errmsg ("interface name too long");
12836 M(NETMAP_CREATE, netmap_create);
12838 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12839 clib_memcpy (mp->hw_addr, hw_addr, 6);
12840 mp->use_random_hw_addr = random_hw_addr;
12841 mp->is_pipe = is_pipe;
12842 mp->is_master = is_master;
12843 vec_free (if_name);
12851 api_netmap_delete (vat_main_t * vam)
12853 unformat_input_t * i = vam->input;
12854 vl_api_netmap_delete_t * mp;
12858 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12859 if (unformat (i, "name %s", &if_name))
12860 vec_add1 (if_name, 0);
12865 if (!vec_len (if_name)) {
12866 errmsg ("interface name must be specified");
12870 if (vec_len (if_name) > 64) {
12871 errmsg ("interface name too long");
12875 M(NETMAP_DELETE, netmap_delete);
12877 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12878 vec_free (if_name);
12885 static void vl_api_mpls_gre_tunnel_details_t_handler
12886 (vl_api_mpls_gre_tunnel_details_t * mp)
12888 vat_main_t * vam = &vat_main;
12890 i32 len = ntohl(mp->nlabels);
12892 if (mp->l2_only == 0) {
12893 fformat(vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
12894 ntohl(mp->tunnel_index),
12895 format_ip4_address, &mp->tunnel_src,
12896 format_ip4_address, &mp->tunnel_dst,
12897 format_ip4_address, &mp->intfc_address,
12898 ntohl(mp->mask_width));
12899 for (i = 0; i < len; i++) {
12900 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12902 fformat(vam->ofp, "\n");
12903 fformat(vam->ofp, " inner fib index %d, outer fib index %d\n",
12904 ntohl(mp->inner_fib_index), ntohl(mp->outer_fib_index));
12906 fformat(vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
12907 ntohl(mp->tunnel_index),
12908 format_ip4_address, &mp->tunnel_src,
12909 format_ip4_address, &mp->tunnel_dst,
12910 format_ip4_address, &mp->intfc_address);
12911 for (i = 0; i < len; i++) {
12912 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12914 fformat(vam->ofp, "\n");
12915 fformat(vam->ofp, " l2 interface %d, outer fib index %d\n",
12916 ntohl(mp->hw_if_index), ntohl(mp->outer_fib_index));
12920 static void vl_api_mpls_gre_tunnel_details_t_handler_json
12921 (vl_api_mpls_gre_tunnel_details_t * mp)
12923 vat_main_t * vam = &vat_main;
12924 vat_json_node_t *node = NULL;
12925 struct in_addr ip4;
12927 i32 len = ntohl(mp->nlabels);
12929 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12930 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12931 vat_json_init_array(&vam->json_tree);
12933 node = vat_json_array_add(&vam->json_tree);
12935 vat_json_init_object(node);
12936 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
12937 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
12938 vat_json_object_add_ip4(node, "intfc_address", ip4);
12939 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
12940 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
12941 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
12942 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
12943 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
12944 clib_memcpy(&ip4, &(mp->tunnel_src), sizeof(ip4));
12945 vat_json_object_add_ip4(node, "tunnel_src", ip4);
12946 clib_memcpy(&ip4, &(mp->tunnel_dst), sizeof(ip4));
12947 vat_json_object_add_ip4(node, "tunnel_dst", ip4);
12948 vat_json_object_add_uint(node, "outer_fib_index", ntohl(mp->outer_fib_index));
12949 vat_json_object_add_uint(node, "label_count", len);
12950 for (i = 0; i < len; i++) {
12951 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
12955 static int api_mpls_gre_tunnel_dump (vat_main_t * vam)
12957 vl_api_mpls_gre_tunnel_dump_t *mp;
12961 /* Parse args required to build the message */
12962 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
12963 if (!unformat (vam->input, "tunnel_index %d", &index)) {
12969 fformat(vam->ofp, " tunnel_index %d\n", index);
12971 M(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
12972 mp->tunnel_index = htonl(index);
12975 /* Use a control ping for synchronization */
12977 vl_api_control_ping_t * mp;
12978 M(CONTROL_PING, control_ping);
12984 static void vl_api_mpls_eth_tunnel_details_t_handler
12985 (vl_api_mpls_eth_tunnel_details_t * mp)
12987 vat_main_t * vam = &vat_main;
12989 i32 len = ntohl(mp->nlabels);
12991 fformat(vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
12992 ntohl(mp->tunnel_index),
12993 format_ethernet_address, &mp->tunnel_dst_mac,
12994 format_ip4_address, &mp->intfc_address,
12995 ntohl(mp->mask_width));
12996 for (i = 0; i < len; i++) {
12997 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12999 fformat(vam->ofp, "\n");
13000 fformat(vam->ofp, " tx on %d, rx fib index %d\n",
13001 ntohl(mp->tx_sw_if_index),
13002 ntohl(mp->inner_fib_index));
13005 static void vl_api_mpls_eth_tunnel_details_t_handler_json
13006 (vl_api_mpls_eth_tunnel_details_t * mp)
13008 vat_main_t * vam = &vat_main;
13009 vat_json_node_t *node = NULL;
13010 struct in_addr ip4;
13012 i32 len = ntohl(mp->nlabels);
13014 if (VAT_JSON_ARRAY != vam->json_tree.type) {
13015 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
13016 vat_json_init_array(&vam->json_tree);
13018 node = vat_json_array_add(&vam->json_tree);
13020 vat_json_init_object(node);
13021 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
13022 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
13023 vat_json_object_add_ip4(node, "intfc_address", ip4);
13024 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
13025 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
13026 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
13027 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
13028 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
13029 vat_json_object_add_string_copy(node, "tunnel_dst_mac",
13030 format(0, "%U", format_ethernet_address, &mp->tunnel_dst_mac));
13031 vat_json_object_add_uint(node, "tx_sw_if_index", ntohl(mp->tx_sw_if_index));
13032 vat_json_object_add_uint(node, "label_count", len);
13033 for (i = 0; i < len; i++) {
13034 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
13038 static int api_mpls_eth_tunnel_dump (vat_main_t * vam)
13040 vl_api_mpls_eth_tunnel_dump_t *mp;
13044 /* Parse args required to build the message */
13045 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
13046 if (!unformat (vam->input, "tunnel_index %d", &index)) {
13052 fformat(vam->ofp, " tunnel_index %d\n", index);
13054 M(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
13055 mp->tunnel_index = htonl(index);
13058 /* Use a control ping for synchronization */
13060 vl_api_control_ping_t * mp;
13061 M(CONTROL_PING, control_ping);
13067 static void vl_api_mpls_fib_encap_details_t_handler
13068 (vl_api_mpls_fib_encap_details_t * mp)
13070 vat_main_t * vam = &vat_main;
13072 i32 len = ntohl(mp->nlabels);
13074 fformat(vam->ofp, "table %d, dest %U, label ",
13075 ntohl(mp->fib_index),
13076 format_ip4_address, &mp->dest,
13078 for (i = 0; i < len; i++) {
13079 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
13081 fformat(vam->ofp, "\n");
13084 static void vl_api_mpls_fib_encap_details_t_handler_json
13085 (vl_api_mpls_fib_encap_details_t * mp)
13087 vat_main_t * vam = &vat_main;
13088 vat_json_node_t *node = NULL;
13090 i32 len = ntohl(mp->nlabels);
13091 struct in_addr ip4;
13093 if (VAT_JSON_ARRAY != vam->json_tree.type) {
13094 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
13095 vat_json_init_array(&vam->json_tree);
13097 node = vat_json_array_add(&vam->json_tree);
13099 vat_json_init_object(node);
13100 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
13101 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
13102 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
13103 vat_json_object_add_ip4(node, "dest", ip4);
13104 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
13105 vat_json_object_add_uint(node, "label_count", len);
13106 for (i = 0; i < len; i++) {
13107 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
13111 static int api_mpls_fib_encap_dump (vat_main_t * vam)
13113 vl_api_mpls_fib_encap_dump_t *mp;
13116 M(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
13119 /* Use a control ping for synchronization */
13121 vl_api_control_ping_t * mp;
13122 M(CONTROL_PING, control_ping);
13128 static void vl_api_mpls_fib_decap_details_t_handler
13129 (vl_api_mpls_fib_decap_details_t * mp)
13131 vat_main_t * vam = &vat_main;
13133 fformat(vam->ofp, "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
13134 ntohl(mp->rx_table_id),
13135 ntohl(mp->tx_table_id),
13141 static void vl_api_mpls_fib_decap_details_t_handler_json
13142 (vl_api_mpls_fib_decap_details_t * mp)
13144 vat_main_t * vam = &vat_main;
13145 vat_json_node_t *node = NULL;
13146 struct in_addr ip4;
13148 if (VAT_JSON_ARRAY != vam->json_tree.type) {
13149 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
13150 vat_json_init_array(&vam->json_tree);
13152 node = vat_json_array_add(&vam->json_tree);
13154 vat_json_init_object(node);
13155 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
13156 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
13157 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
13158 vat_json_object_add_ip4(node, "dest", ip4);
13159 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
13160 vat_json_object_add_uint(node, "label", ntohl(mp->label));
13161 vat_json_object_add_uint(node, "rx_table_id", ntohl(mp->rx_table_id));
13162 vat_json_object_add_uint(node, "tx_table_id", ntohl(mp->tx_table_id));
13163 vat_json_object_add_string_copy(node, "swif_tag", mp->swif_tag);
13166 static int api_mpls_fib_decap_dump (vat_main_t * vam)
13168 vl_api_mpls_fib_decap_dump_t *mp;
13171 M(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
13174 /* Use a control ping for synchronization */
13176 vl_api_control_ping_t * mp;
13177 M(CONTROL_PING, control_ping);
13183 int api_classify_table_ids (vat_main_t *vam)
13185 vl_api_classify_table_ids_t *mp;
13188 /* Construct the API message */
13189 M(CLASSIFY_TABLE_IDS, classify_table_ids);
13197 int api_classify_table_by_interface (vat_main_t *vam)
13199 unformat_input_t * input = vam->input;
13200 vl_api_classify_table_by_interface_t *mp;
13203 u32 sw_if_index = ~0;
13204 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13205 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
13207 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13212 if (sw_if_index == ~0) {
13213 errmsg ("missing interface name or sw_if_index\n");
13217 /* Construct the API message */
13218 M(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
13220 mp->sw_if_index = ntohl(sw_if_index);
13227 int api_classify_table_info (vat_main_t *vam)
13229 unformat_input_t * input = vam->input;
13230 vl_api_classify_table_info_t *mp;
13234 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13235 if (unformat (input, "table_id %d", &table_id))
13240 if (table_id == ~0) {
13241 errmsg ("missing table id\n");
13245 /* Construct the API message */
13246 M(CLASSIFY_TABLE_INFO, classify_table_info);
13248 mp->table_id = ntohl(table_id);
13255 int api_classify_session_dump (vat_main_t *vam)
13257 unformat_input_t * input = vam->input;
13258 vl_api_classify_session_dump_t *mp;
13262 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13263 if (unformat (input, "table_id %d", &table_id))
13268 if (table_id == ~0) {
13269 errmsg ("missing table id\n");
13273 /* Construct the API message */
13274 M(CLASSIFY_SESSION_DUMP, classify_session_dump);
13276 mp->table_id = ntohl(table_id);
13279 /* Use a control ping for synchronization */
13281 vl_api_control_ping_t * mp;
13282 M(CONTROL_PING, control_ping);
13290 static void vl_api_ipfix_details_t_handler (vl_api_ipfix_details_t * mp)
13292 vat_main_t * vam = &vat_main;
13294 fformat(vam->ofp, "collector_address %U, collector_port %d, "
13295 "src_address %U, fib_index %u, path_mtu %u, "
13296 "template_interval %u\n",
13297 format_ip4_address, mp->collector_address,
13298 ntohs(mp->collector_port),
13299 format_ip4_address, mp->src_address,
13300 ntohl(mp->fib_index),
13301 ntohl(mp->path_mtu),
13302 ntohl(mp->template_interval));
13305 vam->result_ready = 1;
13308 static void vl_api_ipfix_details_t_handler_json
13309 (vl_api_ipfix_details_t * mp)
13311 vat_main_t * vam = &vat_main;
13312 vat_json_node_t node;
13313 struct in_addr collector_address;
13314 struct in_addr src_address;
13316 vat_json_init_object(&node);
13317 clib_memcpy(&collector_address, &mp->collector_address,
13318 sizeof(collector_address));
13319 vat_json_object_add_ip4(&node, "collector_address", collector_address);
13320 vat_json_object_add_uint(&node, "collector_port",
13321 ntohs(mp->collector_port));
13322 clib_memcpy(&src_address, &mp->src_address, sizeof(src_address));
13323 vat_json_object_add_ip4(&node, "src_address", src_address);
13324 vat_json_object_add_uint(&node, "fib_index", ntohl(mp->fib_index));
13325 vat_json_object_add_uint(&node, "path_mtu", ntohl(mp->path_mtu));
13326 vat_json_object_add_uint(&node, "template_interval",
13327 ntohl(mp->template_interval));
13329 vat_json_print(vam->ofp, &node);
13330 vat_json_free(&node);
13332 vam->result_ready = 1;
13335 int api_ipfix_dump (vat_main_t *vam)
13337 vl_api_ipfix_dump_t *mp;
13340 /* Construct the API message */
13341 M(IPFIX_DUMP, ipfix_dump);
13349 int api_pg_create_interface (vat_main_t *vam)
13351 unformat_input_t * input = vam->input;
13352 vl_api_pg_create_interface_t *mp;
13356 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13357 if (unformat (input, "if_id %d", &if_id))
13363 errmsg ("missing pg interface index\n");
13367 /* Construct the API message */
13368 M(PG_CREATE_INTERFACE, pg_create_interface);
13370 mp->interface_id = ntohl(if_id);
13377 int api_pg_capture (vat_main_t *vam)
13379 unformat_input_t * input = vam->input;
13380 vl_api_pg_capture_t *mp;
13386 u8 pcap_file_set = 0;
13387 u8 * pcap_file = 0;
13388 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13389 if (unformat (input, "if_id %d", &if_id))
13391 else if (unformat (input, "pcap %s", &pcap_file))
13393 else if (unformat (input, "count %d", &count))
13395 else if (unformat (input, "disable"))
13401 errmsg ("missing pg interface index\n");
13404 if (pcap_file_set>0) {
13405 if (vec_len (pcap_file) > 255) {
13406 errmsg ("pcap file name is too long\n");
13411 u32 name_len = vec_len(pcap_file);
13412 /* Construct the API message */
13413 M(PG_CAPTURE, pg_capture);
13415 mp->interface_id = ntohl(if_id);
13416 mp->is_enabled = enable;
13417 mp->count = ntohl(count);
13418 mp->pcap_name_length = ntohl(name_len);
13419 if (pcap_file_set != 0) {
13420 clib_memcpy(mp->pcap_file_name, pcap_file, name_len);
13422 vec_free(pcap_file);
13429 int api_pg_enable_disable (vat_main_t *vam)
13431 unformat_input_t * input = vam->input;
13432 vl_api_pg_enable_disable_t *mp;
13436 u8 stream_name_set = 0;
13437 u8 * stream_name = 0;
13438 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13439 if (unformat (input, "stream %s", &stream_name))
13440 stream_name_set = 1;
13441 else if (unformat (input, "disable"))
13447 if (stream_name_set>0) {
13448 if (vec_len (stream_name) > 255) {
13449 errmsg ("stream name too long\n");
13454 u32 name_len = vec_len(stream_name);
13455 /* Construct the API message */
13456 M(PG_ENABLE_DISABLE, pg_enable_disable);
13458 mp->is_enabled = enable;
13459 if (stream_name_set != 0) {
13460 mp->stream_name_length = ntohl(name_len);
13461 clib_memcpy(mp->stream_name, stream_name, name_len);
13463 vec_free(stream_name);
13470 static int q_or_quit (vat_main_t * vam)
13472 longjmp (vam->jump_buf, 1);
13473 return 0; /* not so much */
13475 static int q (vat_main_t * vam) {return q_or_quit (vam);}
13476 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
13478 static int comment (vat_main_t * vam)
13483 static int cmd_cmp (void * a1, void * a2)
13488 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
13491 static int help (vat_main_t * vam)
13496 unformat_input_t * i = vam->input;
13499 if (unformat (i, "%s", &name)) {
13504 hs = hash_get_mem (vam->help_by_name, name);
13506 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
13508 fformat (vam->ofp, "No such msg / command '%s'\n", name);
13513 fformat(vam->ofp, "Help is available for the following:\n");
13515 hash_foreach_pair (p, vam->function_by_name,
13517 vec_add1 (cmds, (u8 *)(p->key));
13520 vec_sort_with_function (cmds, cmd_cmp);
13522 for (j = 0; j < vec_len(cmds); j++)
13523 fformat (vam->ofp, "%s\n", cmds[j]);
13529 static int set (vat_main_t * vam)
13531 u8 * name = 0, * value = 0;
13532 unformat_input_t * i = vam->input;
13534 if (unformat (i, "%s", &name)) {
13535 /* The input buffer is a vector, not a string. */
13536 value = vec_dup (i->buffer);
13537 vec_delete (value, i->index, 0);
13538 /* Almost certainly has a trailing newline */
13539 if (value[vec_len(value)-1] == '\n')
13540 value[vec_len(value)-1] = 0;
13541 /* Make sure it's a proper string, one way or the other */
13542 vec_add1 (value, 0);
13543 (void) clib_macro_set_value (&vam->macro_main,
13544 (char *)name, (char *)value);
13547 errmsg ("usage: set <name> <value>\n");
13554 static int unset (vat_main_t * vam)
13558 if (unformat (vam->input, "%s", &name))
13559 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
13560 errmsg ("unset: %s wasn't set\n", name);
13571 static int macro_sort_cmp (void * a1, void * a2)
13573 macro_sort_t * s1 = a1;
13574 macro_sort_t * s2 = a2;
13576 return strcmp ((char *)(s1->name), (char *)(s2->name));
13579 static int dump_macro_table (vat_main_t * vam)
13581 macro_sort_t * sort_me = 0, * sm;
13585 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
13587 vec_add2 (sort_me, sm, 1);
13588 sm->name = (u8 *)(p->key);
13589 sm->value = (u8 *) (p->value[0]);
13592 vec_sort_with_function (sort_me, macro_sort_cmp);
13594 if (vec_len(sort_me))
13595 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
13597 fformat (vam->ofp, "The macro table is empty...\n");
13599 for (i = 0; i < vec_len (sort_me); i++)
13600 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
13605 static int dump_node_table (vat_main_t * vam)
13608 vlib_node_t * node, * next_node;
13610 if (vec_len (vam->graph_nodes) == 0) {
13611 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13615 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
13616 node = vam->graph_nodes[i];
13617 fformat (vam->ofp, "[%d] %s\n", i, node->name);
13618 for (j = 0; j < vec_len (node->next_nodes); j++) {
13619 if (node->next_nodes[j] != ~0) {
13620 next_node = vam->graph_nodes[node->next_nodes[j]];
13621 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13628 static int search_node_table (vat_main_t * vam)
13630 unformat_input_t * line_input = vam->input;
13633 vlib_node_t * node, * next_node;
13636 if (vam->graph_node_index_by_name == 0) {
13637 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13641 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
13642 if (unformat (line_input, "%s", &node_to_find)) {
13643 vec_add1 (node_to_find, 0);
13644 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
13646 fformat (vam->ofp, "%s not found...\n", node_to_find);
13649 node = vam->graph_nodes[p[0]];
13650 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
13651 for (j = 0; j < vec_len (node->next_nodes); j++) {
13652 if (node->next_nodes[j] != ~0) {
13653 next_node = vam->graph_nodes[node->next_nodes[j]];
13654 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13660 clib_warning ("parse error '%U'", format_unformat_error,
13666 vec_free(node_to_find);
13674 static int script (vat_main_t * vam)
13677 char * save_current_file;
13678 unformat_input_t save_input;
13679 jmp_buf save_jump_buf;
13680 u32 save_line_number;
13682 FILE * new_fp, * save_ifp;
13684 if (unformat (vam->input, "%s", &s)) {
13685 new_fp = fopen ((char *)s, "r");
13687 errmsg ("Couldn't open script file %s\n", s);
13692 errmsg ("Missing script name\n");
13696 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
13697 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
13698 save_ifp = vam->ifp;
13699 save_line_number = vam->input_line_number;
13700 save_current_file = (char *) vam->current_file;
13702 vam->input_line_number = 0;
13704 vam->current_file = s;
13707 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
13708 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
13709 vam->ifp = save_ifp;
13710 vam->input_line_number = save_line_number;
13711 vam->current_file = (u8 *) save_current_file;
13717 static int echo (vat_main_t * vam)
13719 fformat (vam->ofp, "%v", vam->input->buffer);
13723 /* List of API message constructors, CLI names map to api_xxx */
13724 #define foreach_vpe_api_msg \
13725 _(create_loopback,"[mac <mac-addr>]") \
13726 _(sw_interface_dump,"") \
13727 _(sw_interface_set_flags, \
13728 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
13729 _(sw_interface_add_del_address, \
13730 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
13731 _(sw_interface_set_table, \
13732 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
13733 _(sw_interface_set_vpath, \
13734 "<intfc> | sw_if_index <id> enable | disable") \
13735 _(sw_interface_set_l2_xconnect, \
13736 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13737 "enable | disable") \
13738 _(sw_interface_set_l2_bridge, \
13739 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
13740 "[shg <split-horizon-group>] [bvi]\n" \
13741 "enable | disable") \
13742 _(bridge_domain_add_del, \
13743 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
13744 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
13746 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
13748 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
13750 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
13752 "tapname <name> mac <mac-addr> | random-mac") \
13754 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
13756 "<vpp-if-name> | sw_if_index <id>") \
13757 _(sw_interface_tap_dump, "") \
13758 _(ip_add_del_route, \
13759 "<addr>/<mask> via <addr> [vrf <n>]\n" \
13760 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
13761 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
13762 "[multipath] [count <n>]") \
13763 _(proxy_arp_add_del, \
13764 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
13765 _(proxy_arp_intfc_enable_disable, \
13766 "<intfc> | sw_if_index <id> enable | disable") \
13767 _(mpls_add_del_encap, \
13768 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
13769 _(mpls_add_del_decap, \
13770 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
13771 _(mpls_gre_add_del_tunnel, \
13772 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
13773 "adj <ip4-address>/<mask-width> [del]") \
13774 _(sw_interface_set_unnumbered, \
13775 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
13776 _(ip_neighbor_add_del, \
13777 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
13778 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
13779 _(reset_vrf, "vrf <id> [ipv6]") \
13780 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
13781 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
13782 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
13783 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
13784 "[outer_vlan_id_any][inner_vlan_id_any]") \
13785 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
13786 _(reset_fib, "vrf <n> [ipv6]") \
13787 _(dhcp_proxy_config, \
13788 "svr <v46-address> src <v46-address>\n" \
13789 "insert-cid <n> [del]") \
13790 _(dhcp_proxy_config_2, \
13791 "svr <v46-address> src <v46-address>\n" \
13792 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
13793 _(dhcp_proxy_set_vss, \
13794 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
13795 _(dhcp_client_config, \
13796 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
13797 _(set_ip_flow_hash, \
13798 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
13799 _(sw_interface_ip6_enable_disable, \
13800 "<intfc> | sw_if_index <id> enable | disable") \
13801 _(sw_interface_ip6_set_link_local_address, \
13802 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
13803 _(sw_interface_ip6nd_ra_prefix, \
13804 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
13805 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
13806 "[nolink] [isno]") \
13807 _(sw_interface_ip6nd_ra_config, \
13808 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
13809 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
13810 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
13811 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
13812 _(l2_patch_add_del, \
13813 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13814 "enable | disable") \
13815 _(mpls_ethernet_add_del_tunnel, \
13816 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
13817 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
13818 _(mpls_ethernet_add_del_tunnel_2, \
13819 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
13820 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
13821 _(sr_tunnel_add_del, \
13822 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
13823 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
13824 "[policy <policy_name>]") \
13825 _(sr_policy_add_del, \
13826 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
13827 _(sr_multicast_map_add_del, \
13828 "address [ip6 multicast address] sr-policy [policy name] [del]") \
13829 _(classify_add_del_table, \
13830 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
13831 "[del] mask <mask-value>\n" \
13832 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
13833 _(classify_add_del_session, \
13834 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
13835 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
13836 " [l3 [ip4|ip6]]") \
13837 _(classify_set_interface_ip_table, \
13838 "<intfc> | sw_if_index <nn> table <nn>") \
13839 _(classify_set_interface_l2_tables, \
13840 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13841 " [other-table <nn>]") \
13842 _(get_node_index, "node <node-name") \
13843 _(add_node_next, "node <node-name> next <next-node-name>") \
13844 _(l2tpv3_create_tunnel, \
13845 "client_address <ip6-addr> our_address <ip6-addr>\n" \
13846 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
13847 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
13848 _(l2tpv3_set_tunnel_cookies, \
13849 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
13850 "[new_remote_cookie <nn>]\n") \
13851 _(l2tpv3_interface_enable_disable, \
13852 "<intfc> | sw_if_index <nn> enable | disable") \
13853 _(l2tpv3_set_lookup_key, \
13854 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
13855 _(sw_if_l2tpv3_tunnel_dump, "") \
13856 _(vxlan_add_del_tunnel, \
13857 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
13858 " [decap-next l2|ip4|ip6] [del]") \
13859 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13860 _(gre_add_del_tunnel, \
13861 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
13862 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13863 _(l2_fib_clear_table, "") \
13864 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
13865 _(l2_interface_vlan_tag_rewrite, \
13866 "<intfc> | sw_if_index <nn> \n" \
13867 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
13868 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
13869 _(create_vhost_user_if, \
13870 "socket <filename> [server] [renumber <dev_instance>] " \
13871 "[mac <mac_address>]") \
13872 _(modify_vhost_user_if, \
13873 "<intfc> | sw_if_index <nn> socket <filename>\n" \
13874 "[server] [renumber <dev_instance>]") \
13875 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
13876 _(sw_interface_vhost_user_dump, "") \
13877 _(show_version, "") \
13878 _(vxlan_gpe_add_del_tunnel, \
13879 "local <addr> remote <addr> vni <nn>\n" \
13880 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
13881 "[next-ethernet] [next-nsh]\n") \
13882 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13883 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
13884 _(interface_name_renumber, \
13885 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
13886 _(input_acl_set_interface, \
13887 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13888 " [l2-table <nn>] [del]") \
13889 _(want_ip4_arp_events, "address <ip4-address> [del]") \
13890 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
13891 _(ip_dump, "ipv4 | ipv6") \
13892 _(ipsec_spd_add_del, "spd_id <n> [del]") \
13893 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
13895 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
13896 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
13897 " integ_alg <alg> integ_key <hex>") \
13898 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
13899 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
13900 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
13901 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
13902 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
13903 _(ikev2_profile_add_del, "name <profile_name> [del]") \
13904 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
13905 "(auth_data 0x<data> | auth_data <data>)") \
13906 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
13907 "(id_data 0x<data> | id_data <data>) (local|remote)") \
13908 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
13909 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
13910 "(local|remote)") \
13911 _(ikev2_set_local_key, "file <absolute_file_path>") \
13912 _(delete_loopback,"sw_if_index <nn>") \
13913 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
13914 _(map_add_domain, \
13915 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
13916 "ip6-src <ip6addr> " \
13917 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
13918 _(map_del_domain, "index <n>") \
13919 _(map_add_del_rule, \
13920 "index <n> psid <n> dst <ip6addr> [del]") \
13921 _(map_domain_dump, "") \
13922 _(map_rule_dump, "index <map-domain>") \
13923 _(want_interface_events, "enable|disable") \
13924 _(want_stats,"enable|disable") \
13925 _(get_first_msg_id, "client <name>") \
13926 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
13927 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
13928 "fib-id <nn> [ip4][ip6][default]") \
13929 _(get_node_graph, " ") \
13930 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
13931 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
13932 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
13933 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
13934 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
13935 " vrf_id <nn> add | pop | none") \
13936 _(trace_profile_del, "") \
13937 _(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
13938 " sw_if_index <sw_if_index> p <priority> " \
13939 "w <weight>] [del]") \
13940 _(lisp_add_del_locator, "locator-set <locator_name> " \
13941 "iface <intf> | sw_if_index <sw_if_index> " \
13942 "p <priority> w <weight> [del]") \
13943 _(lisp_add_del_local_eid,"vni <vni> eid " \
13944 "<ipv4|ipv6>/<prefix> | <L2 address> " \
13945 "locator-set <locator_name> [del]") \
13946 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
13947 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
13948 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
13949 _(lisp_gpe_enable_disable, "enable|disable") \
13950 _(lisp_enable_disable, "enable|disable") \
13951 _(lisp_gpe_add_del_iface, "up|down") \
13952 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> " \
13953 "rloc <locator> p <prio> " \
13954 "w <weight> [rloc <loc> ... ] " \
13955 "action <action> [del-all]") \
13956 _(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid " \
13957 "<src-eid> rloc <locator> p <prio> w <weight>"\
13958 "[rloc <loc> ... ] action <action>") \
13959 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
13960 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
13961 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
13962 _(lisp_locator_set_dump, "[locator-set-index <ls-index> | " \
13963 "locator-set <loc-set-name>] [local | remote]")\
13964 _(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
13965 "[local] | [remote]") \
13966 _(lisp_eid_table_map_dump, "") \
13967 _(lisp_gpe_tunnel_dump, "") \
13968 _(lisp_map_resolver_dump, "") \
13969 _(show_lisp_status, "") \
13970 _(lisp_get_map_request_itr_rlocs, "") \
13971 _(show_lisp_pitr, "") \
13972 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
13973 _(af_packet_delete, "name <host interface name>") \
13974 _(policer_add_del, "name <policer name> <params> [del]") \
13975 _(policer_dump, "[name <policer name>]") \
13976 _(policer_classify_set_interface, \
13977 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13978 " [l2-table <nn>] [del]") \
13979 _(policer_classify_dump, "type [ip4|ip6|l2]") \
13980 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
13981 "[master|slave]") \
13982 _(netmap_delete, "name <interface name>") \
13983 _(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
13984 _(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
13985 _(mpls_fib_encap_dump, "") \
13986 _(mpls_fib_decap_dump, "") \
13987 _(classify_table_ids, "") \
13988 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
13989 _(classify_table_info, "table_id <nn>") \
13990 _(classify_session_dump, "table_id <nn>") \
13991 _(ipfix_enable, "collector_address <ip4> [collector_port <nn>] " \
13992 "src_address <ip4> [fib_id <nn>] [path_mtu <nn>] " \
13993 "[template_interval <nn>]") \
13994 _(ipfix_dump, "") \
13995 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
13996 _(pg_create_interface, "if_id <nn>") \
13997 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
13998 _(pg_enable_disable, "[stream <id>] disable")
14000 /* List of command functions, CLI names map directly to functions */
14001 #define foreach_cli_function \
14002 _(comment, "usage: comment <ignore-rest-of-line>") \
14003 _(dump_interface_table, "usage: dump_interface_table") \
14004 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
14005 _(dump_ipv4_table, "usage: dump_ipv4_table") \
14006 _(dump_ipv6_table, "usage: dump_ipv6_table") \
14007 _(dump_stats_table, "usage: dump_stats_table") \
14008 _(dump_macro_table, "usage: dump_macro_table ") \
14009 _(dump_node_table, "usage: dump_node_table") \
14010 _(echo, "usage: echo <message>") \
14011 _(exec, "usage: exec <vpe-debug-CLI-command>") \
14012 _(help, "usage: help") \
14013 _(q, "usage: quit") \
14014 _(quit, "usage: quit") \
14015 _(search_node_table, "usage: search_node_table <name>...") \
14016 _(set, "usage: set <variable-name> <value>") \
14017 _(script, "usage: script <file-name>") \
14018 _(unset, "usage: unset <variable-name>")
14021 static void vl_api_##n##_t_handler_uni \
14022 (vl_api_##n##_t * mp) \
14024 vat_main_t * vam = &vat_main; \
14025 if (vam->json_output) { \
14026 vl_api_##n##_t_handler_json(mp); \
14028 vl_api_##n##_t_handler(mp); \
14031 foreach_vpe_api_reply_msg;
14034 void vat_api_hookup (vat_main_t *vam)
14037 vl_msg_api_set_handlers(VL_API_##N, #n, \
14038 vl_api_##n##_t_handler_uni, \
14040 vl_api_##n##_t_endian, \
14041 vl_api_##n##_t_print, \
14042 sizeof(vl_api_##n##_t), 1);
14043 foreach_vpe_api_reply_msg;
14046 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
14048 vam->sw_if_index_by_interface_name =
14049 hash_create_string (0, sizeof (uword));
14051 vam->function_by_name =
14052 hash_create_string (0, sizeof(uword));
14054 vam->help_by_name =
14055 hash_create_string (0, sizeof(uword));
14057 /* API messages we can send */
14058 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
14059 foreach_vpe_api_msg;
14063 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
14064 foreach_vpe_api_msg;
14067 /* CLI functions */
14068 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
14069 foreach_cli_function;
14073 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
14074 foreach_cli_function;
14078 #undef vl_api_version
14079 #define vl_api_version(n,v) static u32 vpe_api_version = v;
14080 #include <vpp-api/vpe.api.h>
14081 #undef vl_api_version
14083 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
14086 * Send the main API signature in slot 0. This bit of code must
14087 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
14089 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);